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 @@ ...@@ -25,7 +25,7 @@
- Added `clearCache()` method - Added `clearCache()` method
- Added `HttpAuthCredentialDatabase` class - Added `HttpAuthCredentialDatabase` class
- Added `onReceivedServerTrustAuthRequest` and `onReceivedClientCertRequest` events to manage SSL requests - Added `onReceivedServerTrustAuthRequest` and `onReceivedClientCertRequest` events to manage SSL requests
- Added `onFindResultReceived` event, `findAllAsync`, `findNext` and `clearMatches` methods
### BREAKING CHANGES ### BREAKING CHANGES
- Deleted `WebResourceRequest` class - Deleted `WebResourceRequest` class
......
...@@ -94,8 +94,6 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -94,8 +94,6 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
@Override @Override
public void onMethodCall(MethodCall call, final Result result) { public void onMethodCall(MethodCall call, final Result result) {
String source;
String urlFile;
switch (call.method) { switch (call.method) {
case "getUrl": case "getUrl":
result.success((webView != null) ? webView.getUrl() : null); result.success((webView != null) ? webView.getUrl() : null);
...@@ -108,22 +106,22 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -108,22 +106,22 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
break; break;
case "loadUrl": case "loadUrl":
if (webView != null) 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 else
result.success(false); result.success(false);
break; break;
case "postUrl": case "postUrl":
if (webView != null) 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 else
result.success(false); result.success(false);
break; break;
case "loadData": case "loadData":
{ {
String data = call.argument("data").toString(); String data = (String) call.argument("data");
String mimeType = call.argument("mimeType").toString(); String mimeType = (String) call.argument("mimeType");
String encoding = call.argument("encoding").toString(); String encoding = (String) call.argument("encoding");
String baseUrl = call.argument("baseUrl").toString(); String baseUrl = (String) call.argument("baseUrl");
if (webView != null) if (webView != null)
webView.loadData(data, mimeType, encoding, baseUrl, result); webView.loadData(data, mimeType, encoding, baseUrl, result);
...@@ -133,13 +131,13 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -133,13 +131,13 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
break; break;
case "loadFile": case "loadFile":
if (webView != null) 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 else
result.success(false); result.success(false);
break; break;
case "injectScriptCode": case "injectScriptCode":
if (webView != null) { if (webView != null) {
source = call.argument("source").toString(); String source = (String) call.argument("source");
webView.injectScriptCode(source, result); webView.injectScriptCode(source, result);
} }
else { else {
...@@ -148,21 +146,21 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -148,21 +146,21 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
break; break;
case "injectScriptFile": case "injectScriptFile":
if (webView != null) { if (webView != null) {
urlFile = call.argument("urlFile").toString(); String urlFile = (String) call.argument("urlFile");
webView.injectScriptFile(urlFile); webView.injectScriptFile(urlFile);
} }
result.success(true); result.success(true);
break; break;
case "injectStyleCode": case "injectStyleCode":
if (webView != null) { if (webView != null) {
source = call.argument("source").toString(); String source = (String) call.argument("source");
webView.injectStyleCode(source); webView.injectStyleCode(source);
} }
result.success(true); result.success(true);
break; break;
case "injectStyleFile": case "injectStyleFile":
if (webView != null) { if (webView != null) {
urlFile = call.argument("urlFile").toString(); String urlFile = (String) call.argument("urlFile");
webView.injectStyleFile(urlFile); webView.injectStyleFile(urlFile);
} }
result.success(true); result.success(true);
...@@ -267,6 +265,30 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { ...@@ -267,6 +265,30 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
result.success(false); result.success(false);
} }
break; 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": case "dispose":
dispose(); dispose();
result.success(true); result.success(true);
......
...@@ -499,4 +499,27 @@ public class InAppBrowserActivity extends AppCompatActivity { ...@@ -499,4 +499,27 @@ public class InAppBrowserActivity extends AppCompatActivity {
else else
result.success(false); 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 { ...@@ -103,7 +103,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "open": case "open":
boolean isData = (boolean) call.argument("isData"); boolean isData = (boolean) call.argument("isData");
if (!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"); final boolean useChromeSafariBrowser = (boolean) call.argument("useChromeSafariBrowser");
...@@ -174,10 +174,10 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -174,10 +174,10 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
@Override @Override
public void run() { public void run() {
HashMap<String, Object> options = (HashMap<String, Object>) call.argument("options"); HashMap<String, Object> options = (HashMap<String, Object>) call.argument("options");
String data = call.argument("data").toString(); String data = (String) call.argument("data");
String mimeType = call.argument("mimeType").toString(); String mimeType = (String) call.argument("mimeType");
String encoding = call.argument("encoding").toString(); String encoding = (String) call.argument("encoding");
String baseUrl = call.argument("baseUrl").toString(); String baseUrl = (String) call.argument("baseUrl");
openData(activity, uuid, options, data, mimeType, encoding, baseUrl); openData(activity, uuid, options, data, mimeType, encoding, baseUrl);
result.success(true); result.success(true);
} }
...@@ -194,42 +194,42 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -194,42 +194,42 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
result.success(getProgress(uuid)); result.success(getProgress(uuid));
break; break;
case "loadUrl": 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; break;
case "postUrl": 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; break;
case "loadData": case "loadData":
{ {
String data = call.argument("data").toString(); String data = (String) call.argument("data");
String mimeType = call.argument("mimeType").toString(); String mimeType = (String) call.argument("mimeType");
String encoding = call.argument("encoding").toString(); String encoding = (String) call.argument("encoding");
String baseUrl = call.argument("baseUrl").toString(); String baseUrl = (String) call.argument("baseUrl");
loadData(uuid, data, mimeType, encoding, baseUrl, result); loadData(uuid, data, mimeType, encoding, baseUrl, result);
} }
break; break;
case "loadFile": 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; break;
case "close": case "close":
close(activity, uuid, result); close(activity, uuid, result);
break; break;
case "injectScriptCode": case "injectScriptCode":
source = call.argument("source").toString(); source = (String) call.argument("source");
injectScriptCode(uuid, source, result); injectScriptCode(uuid, source, result);
break; break;
case "injectScriptFile": case "injectScriptFile":
urlFile = call.argument("urlFile").toString(); urlFile = (String) call.argument("urlFile");
injectScriptFile(uuid, urlFile); injectScriptFile(uuid, urlFile);
result.success(true); result.success(true);
break; break;
case "injectStyleCode": case "injectStyleCode":
source = call.argument("source").toString(); source = (String) call.argument("source");
injectStyleCode(uuid, source); injectStyleCode(uuid, source);
result.success(true); result.success(true);
break; break;
case "injectStyleFile": case "injectStyleFile":
urlFile = call.argument("urlFile").toString(); urlFile = (String) call.argument("urlFile");
injectStyleFile(uuid, urlFile); injectStyleFile(uuid, urlFile);
result.success(true); result.success(true);
break; break;
...@@ -318,6 +318,18 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -318,6 +318,18 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
case "clearClientCertPreferences": case "clearClientCertPreferences":
clearClientCertPreferences(uuid, result); clearClientCertPreferences(uuid, result);
break; 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: default:
result.notImplemented(); result.notImplemented();
} }
...@@ -713,10 +725,30 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler { ...@@ -713,10 +725,30 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
inAppBrowserActivity.clearSslPreferences(); inAppBrowserActivity.clearSslPreferences();
} }
private void clearClientCertPreferences(String uuid, Result result) { public void clearClientCertPreferences(String uuid, Result result) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid); InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null) if (inAppBrowserActivity != null)
inAppBrowserActivity.clearClientCertPreferences(result); inAppBrowserActivity.clearClientCertPreferences(result);
result.success(false); 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 { ...@@ -242,6 +242,19 @@ final public class InAppWebView extends InputAwareWebView {
ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action")); ContentBlockerAction action = ContentBlockerAction.fromMap(contentBlocker.get("action"));
contentBlockerHandler.getRuleList().add(new ContentBlocker(trigger, 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) { public void loadUrl(String url, MethodChannel.Result result) {
......
import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.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 { ...@@ -239,6 +239,18 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
case "getCopyBackForwardList": case "getCopyBackForwardList":
result(self.getCopyBackForwardList(uuid: uuid)) result(self.getCopyBackForwardList(uuid: uuid))
break 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": case "clearCache":
self.clearCache(uuid: uuid) self.clearCache(uuid: uuid)
result(true) result(true)
...@@ -752,6 +764,40 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin { ...@@ -752,6 +764,40 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
return nil 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) { func clearCache(uuid: String) {
if let webViewController = self.webViewControllers[uuid] { if let webViewController = self.webViewControllers[uuid] {
webViewController!.webView.clearCache() webViewController!.webView.clearCache()
......
import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
......
import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
///Manages the cookies used by WebView instances. ///Manages the cookies used by WebView instances.
......
import 'dart:async';
import 'types.dart'; import 'types.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
......
...@@ -4,7 +4,6 @@ import 'dart:collection'; ...@@ -4,7 +4,6 @@ import 'dart:collection';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_inappbrowser/src/webview_options.dart'; import 'package:flutter_inappbrowser/src/webview_options.dart';
import 'http_auth_credentials_database.dart';
import 'types.dart'; import 'types.dart';
import 'channel_manager.dart'; import 'channel_manager.dart';
import 'in_app_webview.dart' show InAppWebViewController; import 'in_app_webview.dart' show InAppWebViewController;
...@@ -424,6 +423,18 @@ class InAppBrowser { ...@@ -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 = ''}) { void throwIsAlreadyOpened({String message = ''}) {
if (this.isOpened()) { if (this.isOpened()) {
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']); 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 'dart:typed_data';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
...@@ -411,6 +412,20 @@ class ClientCertChallenge { ...@@ -411,6 +412,20 @@ class ClientCertChallenge {
ClientCertChallenge({@required this.protectionSpace}): assert(protectionSpace != null); 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 { class AndroidInAppWebViewCacheMode {
final int _value; final int _value;
...@@ -546,24 +561,3 @@ class iOSSafariOptionsDismissButtonStyle { ...@@ -546,24 +561,3 @@ class iOSSafariOptionsDismissButtonStyle {
static const CLOSE = const iOSSafariOptionsDismissButtonStyle._internal(1); static const CLOSE = const iOSSafariOptionsDismissButtonStyle._internal(1);
static const CANCEL = const iOSSafariOptionsDismissButtonStyle._internal(2); 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