Commit 6518697e authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

added onFindResultReceived event, added findAllAsync, findNext and clearMatches methods

parent 1f67e982
This diff is collapsed.
......@@ -25,7 +25,7 @@
- Added `clearCache()` method
- Added `HttpAuthCredentialDatabase` class
- Added `onReceivedServerTrustAuthRequest` and `onReceivedClientCertRequest` events to manage SSL requests
- Added `onFindResultReceived` event, `findAllAsync`, `findNext` and `clearMatches` methods
### BREAKING CHANGES
- Deleted `WebResourceRequest` class
......
......@@ -94,8 +94,6 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
@Override
public void onMethodCall(MethodCall call, final Result result) {
String source;
String urlFile;
switch (call.method) {
case "getUrl":
result.success((webView != null) ? webView.getUrl() : null);
......@@ -108,22 +106,22 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
break;
case "loadUrl":
if (webView != null)
webView.loadUrl(call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);
webView.loadUrl((String) call.argument("url"), (Map<String, String>) call.argument("headers"), result);
else
result.success(false);
break;
case "postUrl":
if (webView != null)
webView.postUrl(call.argument("url").toString(), (byte[]) call.argument("postData"), result);
webView.postUrl((String) call.argument("url"), (byte[]) call.argument("postData"), result);
else
result.success(false);
break;
case "loadData":
{
String data = call.argument("data").toString();
String mimeType = call.argument("mimeType").toString();
String encoding = call.argument("encoding").toString();
String baseUrl = call.argument("baseUrl").toString();
String data = (String) call.argument("data");
String mimeType = (String) call.argument("mimeType");
String encoding = (String) call.argument("encoding");
String baseUrl = (String) call.argument("baseUrl");
if (webView != null)
webView.loadData(data, mimeType, encoding, baseUrl, result);
......@@ -133,13 +131,13 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
break;
case "loadFile":
if (webView != null)
webView.loadFile(call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);
webView.loadFile((String) call.argument("url"), (Map<String, String>) call.argument("headers"), result);
else
result.success(false);
break;
case "injectScriptCode":
if (webView != null) {
source = call.argument("source").toString();
String source = (String) call.argument("source");
webView.injectScriptCode(source, result);
}
else {
......@@ -148,21 +146,21 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
break;
case "injectScriptFile":
if (webView != null) {
urlFile = call.argument("urlFile").toString();
String urlFile = (String) call.argument("urlFile");
webView.injectScriptFile(urlFile);
}
result.success(true);
break;
case "injectStyleCode":
if (webView != null) {
source = call.argument("source").toString();
String source = (String) call.argument("source");
webView.injectStyleCode(source);
}
result.success(true);
break;
case "injectStyleFile":
if (webView != null) {
urlFile = call.argument("urlFile").toString();
String urlFile = (String) call.argument("urlFile");
webView.injectStyleFile(urlFile);
}
result.success(true);
......@@ -267,6 +265,30 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
result.success(false);
}
break;
case "findAllAsync":
if (webView != null) {
String find = (String) call.argument("find");
webView.findAllAsync(find);
}
result.success(true);
break;
case "findNext":
if (webView != null) {
Boolean forward = (Boolean) call.argument("forward");
webView.findNext(forward);
result.success(true);
} else {
result.success(false);
}
break;
case "clearMatches":
if (webView != null) {
webView.clearMatches();
result.success(true);
} else {
result.success(false);
}
break;
case "dispose":
dispose();
result.success(true);
......
......@@ -499,4 +499,27 @@ public class InAppBrowserActivity extends AppCompatActivity {
else
result.success(false);
}
public void findAllAsync(String find) {
if (webView != null)
webView.findAllAsync(find);
}
public void findNext(Boolean forward, MethodChannel.Result result) {
if (webView != null) {
webView.findNext(forward);
result.success(true);
}
else
result.success(false);
}
public void clearMatches(MethodChannel.Result result) {
if (webView != null) {
webView.clearMatches();
result.success(true);
}
else
result.success(false);
}
}
......@@ -103,7 +103,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "open":
boolean isData = (boolean) call.argument("isData");
if (!isData) {
final String url_final = call.argument("url").toString();
final String url_final = (String) call.argument("url");
final boolean useChromeSafariBrowser = (boolean) call.argument("useChromeSafariBrowser");
......@@ -174,10 +174,10 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
@Override
public void run() {
HashMap<String, Object> options = (HashMap<String, Object>) call.argument("options");
String data = call.argument("data").toString();
String mimeType = call.argument("mimeType").toString();
String encoding = call.argument("encoding").toString();
String baseUrl = call.argument("baseUrl").toString();
String data = (String) call.argument("data");
String mimeType = (String) call.argument("mimeType");
String encoding = (String) call.argument("encoding");
String baseUrl = (String) call.argument("baseUrl");
openData(activity, uuid, options, data, mimeType, encoding, baseUrl);
result.success(true);
}
......@@ -194,42 +194,42 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
result.success(getProgress(uuid));
break;
case "loadUrl":
loadUrl(uuid, call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);
loadUrl(uuid, (String) call.argument("url"), (Map<String, String>) call.argument("headers"), result);
break;
case "postUrl":
postUrl(uuid, call.argument("url").toString(), (byte[]) call.argument("postData"), result);
postUrl(uuid, (String) call.argument("url"), (byte[]) call.argument("postData"), result);
break;
case "loadData":
{
String data = call.argument("data").toString();
String mimeType = call.argument("mimeType").toString();
String encoding = call.argument("encoding").toString();
String baseUrl = call.argument("baseUrl").toString();
String data = (String) call.argument("data");
String mimeType = (String) call.argument("mimeType");
String encoding = (String) call.argument("encoding");
String baseUrl = (String) call.argument("baseUrl");
loadData(uuid, data, mimeType, encoding, baseUrl, result);
}
break;
case "loadFile":
loadFile(uuid, call.argument("url").toString(), (Map<String, String>) call.argument("headers"), result);
loadFile(uuid, (String) call.argument("url"), (Map<String, String>) call.argument("headers"), result);
break;
case "close":
close(activity, uuid, result);
break;
case "injectScriptCode":
source = call.argument("source").toString();
source = (String) call.argument("source");
injectScriptCode(uuid, source, result);
break;
case "injectScriptFile":
urlFile = call.argument("urlFile").toString();
urlFile = (String) call.argument("urlFile");
injectScriptFile(uuid, urlFile);
result.success(true);
break;
case "injectStyleCode":
source = call.argument("source").toString();
source = (String) call.argument("source");
injectStyleCode(uuid, source);
result.success(true);
break;
case "injectStyleFile":
urlFile = call.argument("urlFile").toString();
urlFile = (String) call.argument("urlFile");
injectStyleFile(uuid, urlFile);
result.success(true);
break;
......@@ -318,6 +318,18 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "clearClientCertPreferences":
clearClientCertPreferences(uuid, result);
break;
case "findAllAsync":
String find = (String) call.argument("find");
findAllAsync(uuid, find);
result.success(true);
break;
case "findNext":
Boolean forward = (Boolean) call.argument("forward");
findNext(uuid, forward, result);
break;
case "clearMatches":
clearMatches(uuid, result);
break;
default:
result.notImplemented();
}
......@@ -713,10 +725,30 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
inAppBrowserActivity.clearSslPreferences();
}
private void clearClientCertPreferences(String uuid, Result result) {
public void clearClientCertPreferences(String uuid, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.clearClientCertPreferences(result);
result.success(false);
}
public void findAllAsync(String uuid, String find) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.findAllAsync(find);
}
public void findNext(String uuid, Boolean forward, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.findNext(forward, result);
result.success(false);
}
public void clearMatches(String uuid, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.clearMatches(result);
result.success(false);
}
}
......@@ -242,6 +242,19 @@ final public class InAppWebView extends InputAwareWebView {
ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action"));
contentBlockerHandler.getRuleList().add(new ContentBlocker(trigger, action));
}
setFindListener(new FindListener() {
@Override
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) {
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
obj.put("activeMatchOrdinal", activeMatchOrdinal);
obj.put("numberOfMatches", numberOfMatches);
obj.put("isDoneCounting", isDoneCounting);
getChannel().invokeMethod("onFindResultReceived", obj);
}
});
}
public void loadUrl(String url, MethodChannel.Result result) {
......
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -239,6 +239,18 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
case "getCopyBackForwardList":
result(self.getCopyBackForwardList(uuid: uuid))
break
case "findAllAsync":
let find = arguments!["find"] as! String
self.findAllAsync(uuid: uuid, find: find)
result(true)
break
case "findNext":
let forward = arguments!["forward"] as! Bool
self.findNext(uuid: uuid, forward: forward, result: result)
break
case "clearMatches":
self.clearMatches(uuid: uuid, result: result)
break
case "clearCache":
self.clearCache(uuid: uuid)
result(true)
......@@ -752,6 +764,40 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
return nil
}
func findAllAsync(uuid: String, find: String) {
if let webViewController = self.webViewControllers[uuid] {
webViewController!.webView.findAllAsync(find: find, completionHandler: nil)
}
}
func findNext(uuid: String, forward: Bool, result: @escaping FlutterResult) {
if let webViewController = self.webViewControllers[uuid] {
webViewController!.webView.findNext(forward: forward, completionHandler: {(value, error) in
if error != nil {
result(FlutterError(code: "FlutterWebViewController", message: error?.localizedDescription, details: nil))
return
}
result(true)
})
} else {
result(false)
}
}
func clearMatches(uuid: String, result: @escaping FlutterResult) {
if let webViewController = self.webViewControllers[uuid] {
webViewController!.webView.clearMatches(completionHandler: {(value, error) in
if error != nil {
result(FlutterError(code: "FlutterWebViewController", message: error?.localizedDescription, details: nil))
return
}
result(true)
})
} else {
result(false)
}
}
func clearCache(uuid: String) {
if let webViewController = self.webViewControllers[uuid] {
webViewController!.webView.clearCache()
......
import 'dart:async';
import 'dart:collection';
import 'package:flutter/services.dart';
......
import 'dart:async';
import 'package:flutter/services.dart';
///Manages the cookies used by WebView instances.
......
import 'dart:async';
import 'types.dart';
import 'package:flutter/services.dart';
......
......@@ -4,7 +4,6 @@ import 'dart:collection';
import 'package:flutter/services.dart';
import 'package:flutter_inappbrowser/src/webview_options.dart';
import 'http_auth_credentials_database.dart';
import 'types.dart';
import 'channel_manager.dart';
import 'in_app_webview.dart' show InAppWebViewController;
......@@ -424,6 +423,18 @@ class InAppBrowser {
}
///Event fired as find-on-page operations progress.
///The listener may be notified multiple times while the operation is underway, and the numberOfMatches value should not be considered final unless [isDoneCounting] is true.
///
///[activeMatchOrdinal] represents the zero-based ordinal of the currently selected match.
///
///[numberOfMatches] represents how many matches have been found.
///
///[isDoneCounting] whether the find operation has actually completed.
void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting) {
}
void throwIsAlreadyOpened({String message = ''}) {
if (this.isOpened()) {
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
import 'dart:async';
import 'dart:typed_data';
import 'package:uuid/uuid.dart';
......@@ -411,6 +412,20 @@ class ClientCertChallenge {
ClientCertChallenge({@required this.protectionSpace}): assert(protectionSpace != null);
}
///
class Favicon {
String url;
String rel;
int width;
int height;
Favicon({@required this.url, this.rel, this.width, this.height}): assert(url != null);
String toString() {
return "url: $url, rel: $rel, width: $width, height: $height";
}
}
///
class AndroidInAppWebViewCacheMode {
final int _value;
......@@ -546,24 +561,3 @@ class iOSSafariOptionsDismissButtonStyle {
static const CLOSE = const iOSSafariOptionsDismissButtonStyle._internal(1);
static const CANCEL = const iOSSafariOptionsDismissButtonStyle._internal(2);
}
typedef onWebViewCreatedCallback = void Function(InAppWebViewController controller);
typedef onWebViewLoadStartCallback = void Function(InAppWebViewController controller, String url);
typedef onWebViewLoadStopCallback = void Function(InAppWebViewController controller, String url);
typedef onWebViewLoadErrorCallback = void Function(InAppWebViewController controller, String url, int code, String message);
typedef onWebViewProgressChangedCallback = void Function(InAppWebViewController controller, int progress);
typedef onWebViewConsoleMessageCallback = void Function(InAppWebViewController controller, ConsoleMessage consoleMessage);
typedef shouldOverrideUrlLoadingCallback = void Function(InAppWebViewController controller, String url);
typedef onWebViewLoadResourceCallback = void Function(InAppWebViewController controller, WebResourceResponse response);
typedef onWebViewScrollChangedCallback = void Function(InAppWebViewController controller, int x, int y);
typedef onDownloadStartCallback = void Function(InAppWebViewController controller, String url);
typedef onLoadResourceCustomSchemeCallback = Future<CustomSchemeResponse> Function(InAppWebViewController controller, String scheme, String url);
typedef onTargetBlankCallback = void Function(InAppWebViewController controller, String url);
typedef onGeolocationPermissionsShowPromptCallback = Future<GeolocationPermissionShowPromptResponse> Function(InAppWebViewController controller, String origin);
typedef onJsAlertCallback = Future<JsAlertResponse> Function(InAppWebViewController controller, String message);
typedef onJsConfirmCallback = Future<JsConfirmResponse> Function(InAppWebViewController controller, String message);
typedef onJsPromptCallback = Future<JsPromptResponse> Function(InAppWebViewController controller, String message, String defaultValue);
typedef onSafeBrowsingHitCallback = Future<SafeBrowsingResponse> Function(InAppWebViewController controller, String url, SafeBrowsingThreat threatType);
typedef onReceivedHttpAuthRequestCallback = Future<HttpAuthResponse> Function(InAppWebViewController controller, HttpAuthChallenge challenge);
typedef onReceivedServerTrustAuthRequestCallback = Future<ServerTrustAuthResponse> Function(InAppWebViewController controller, ServerTrustChallenge challenge);
typedef onReceivedClientCertRequestCallback = Future<ClientCertResponse> Function(InAppWebViewController controller, ClientCertChallenge challenge);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment