diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f65ca4b3..831c8964 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,52 +15,13 @@ - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -81,12 +42,12 @@ - + - - + + - + @@ -95,8 +56,8 @@ - - + + @@ -105,46 +66,19 @@ - + - - - - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -152,29 +86,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -214,9 +125,9 @@ InAppWebViewOnProgressChangedTest nextTest clear - InAppWebViewOnScrollChangedTest InAppWebViewOnConsoleMessageTest Change: + InAppWebViewOnScrollChangedTest activity.getPreferences(0) @@ -234,12 +145,10 @@ @@ -355,13 +266,7 @@ - - - - - - - + @@ -535,7 +440,7 @@ - + @@ -557,7 +462,7 @@ - + @@ -587,37 +492,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -642,13 +516,6 @@ - - - - - - - @@ -680,19 +547,7 @@ - - - - - - - - - - - - - + @@ -900,25 +755,6 @@ - - - - - - - - - - - - - - - - - - - @@ -963,29 +799,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -996,6 +809,16 @@ + + + + + + + + + + @@ -1016,16 +839,108 @@ - + - - + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java index 2213fc5c..75866330 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java @@ -36,14 +36,12 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { public final MethodChannel channel; public final Registrar registrar; - public FlutterWebView(Registrar registrar, int id, HashMap params, View containerView) { - + public FlutterWebView(Registrar registrar, final Context context, int id, HashMap params, View containerView) { this.registrar = registrar; this.activity = registrar.activity(); DisplayListenerProxy displayListenerProxy = new DisplayListenerProxy(); - DisplayManager displayManager = - (DisplayManager) this.registrar.context().getSystemService(Context.DISPLAY_SERVICE); + DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); displayListenerProxy.onPreWebViewInitialization(displayManager); String initialUrl = (String) params.get("initialUrl"); @@ -55,7 +53,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { InAppWebViewOptions options = new InAppWebViewOptions(); options.parse(initialOptions); - webView = new InAppWebView(registrar, this, id, options, containerView); + webView = new InAppWebView(registrar, context, this, id, options, containerView); displayListenerProxy.onPostWebViewInitialization(displayManager); webView.prepare(); diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java index a365e89f..2a9a1eb3 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebViewFactory.java @@ -23,7 +23,7 @@ public class FlutterWebViewFactory extends PlatformViewFactory { @Override public PlatformView create(Context context, int id, Object args) { HashMap params = (HashMap) args; - return new FlutterWebView(registrar, id, params, containerView); + return new FlutterWebView(registrar, context, id, params, containerView); } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java index 76e6b1a8..71f5bfd6 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java @@ -508,8 +508,8 @@ final public class InAppWebView extends InputAwareWebView { super(context, attrs, defaultStyle); } - public InAppWebView(PluginRegistry.Registrar registrar, Object obj, int id, InAppWebViewOptions options, View containerView) { - super(registrar.activeContext(), containerView); + public InAppWebView(PluginRegistry.Registrar registrar, Context context, Object obj, int id, InAppWebViewOptions options, View containerView) { + super(context, containerView); this.registrar = registrar; if (obj instanceof InAppBrowserActivity) this.inAppBrowserActivity = (InAppBrowserActivity) obj; diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index c341e856..567e88f8 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -16,17 +16,6 @@ class InAppWebViewExampleScreen extends StatefulWidget { new _InAppWebViewExampleScreenState(); } -class Foo { - String bar; - String baz; - - Foo({this.bar, this.baz}); - - Map toJson() { - return {'bar': this.bar, 'baz': this.baz}; - } -} - class _InAppWebViewExampleScreenState extends State { InAppWebViewController webView; String url = ""; @@ -48,24 +37,6 @@ class _InAppWebViewExampleScreenState extends State { @override Widget build(BuildContext context) { -// HttpAuthCredentialDatabase.instance().clearAllAuthCredentials(); -// -// HttpAuthCredentialDatabase.instance().getHttpAuthCredentials(ProtectionSpace(host: "192.168.1.20", protocol: "http", realm: "Node", port: 8081)).then((credentials) { -// for (var credential in credentials ) -// print("\n\nCREDENTIAL: ${credential.username} ${credential.password}\n\n"); -// }); -// HttpAuthCredentialDatabase.instance().getAllAuthCredentials().then((result) { -// for (var r in result) { -// ProtectionSpace protectionSpace = r["protectionSpace"]; -// print("\n\nProtectionSpace: ${protectionSpace.protocol} ${protectionSpace.host}:"); -// List credentials = r["credentials"]; -// for (var credential in credentials) -// print("\tCREDENTIAL: ${credential.username} ${credential.password}"); -// } -// }); -// HttpAuthCredentialDatabase.instance().setHttpAuthCredential(ProtectionSpace(host: "192.168.1.20", protocol: "http", realm: "Node", port: 8081), HttpAuthCredential(username: "user 1", password: "password 1")); -// HttpAuthCredentialDatabase.instance().setHttpAuthCredential(ProtectionSpace(host: "192.168.1.20", protocol: "http", realm: "Node", port: 8081), HttpAuthCredential(username: "user 2", password: "password 2")); - return Scaffold( appBar: AppBar( title: Text( @@ -104,488 +75,80 @@ class _InAppWebViewExampleScreenState extends State { ), body: Container( child: Column(children: [ - Container( - padding: EdgeInsets.all(20.0), - child: Text( - "CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"), - ), - Container( - padding: EdgeInsets.all(10.0), - child: progress < 1.0 - ? LinearProgressIndicator(value: progress) - : Container()), - Expanded( - child: Container( - margin: const EdgeInsets.all(10.0), - decoration: - BoxDecoration(border: Border.all(color: Colors.blueAccent)), - child: InAppWebView( - //initialUrl: "https://www.youtube.com/embed/M7lc1UVf-VE?playsinline=1", - //initialUrl: "https://github.com", - //initialUrl: "chrome://safe-browsing/match?type=malware", - //initialUrl: "http://192.168.1.20:8081/", - //initialUrl: "https://192.168.1.20:4433/", - //initialFile: "assets/index.html", - initialUrl: "https://flutter.dev/", - initialHeaders: {}, - initialOptions: InAppWebViewWidgetOptions( - inAppWebViewOptions: InAppWebViewOptions( - //disableVerticalScroll: false, - //disableHorizontalScroll: false, - debuggingEnabled: true, - clearCache: true, - //useShouldOverrideUrlLoading: true, - useOnTargetBlank: true, - useOnLoadResource: true, - //useOnDownloadStart: true, - //useShouldInterceptAjaxRequest: true, - //useShouldInterceptFetchRequest: true, - //preferredContentMode: InAppWebViewUserPreferredContentMode.DESKTOP, - resourceCustomSchemes: [ - "my-special-custom-scheme" - ], - contentBlockers: [ - ContentBlocker( - trigger: ContentBlockerTrigger( - urlFilter: ".*", - resourceType: [ - ContentBlockerTriggerResourceType.IMAGE, - ContentBlockerTriggerResourceType.STYLE_SHEET - ], - ifTopUrl: [ - "https://flutter.dev/" - ]), - action: ContentBlockerAction( - type: ContentBlockerActionType.BLOCK)) - ]), - androidInAppWebViewOptions: AndroidInAppWebViewOptions( - databaseEnabled: true, - domStorageEnabled: true, - geolocationEnabled: true, - safeBrowsingEnabled: true, - //blockNetworkImage: true, + Container( + padding: EdgeInsets.all(20.0), + child: Text( + "CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"), + ), + Container( + padding: EdgeInsets.all(10.0), + child: progress < 1.0 + ? LinearProgressIndicator(value: progress) + : Container()), + Expanded( + child: Container( + margin: const EdgeInsets.all(10.0), + decoration: + BoxDecoration(border: Border.all(color: Colors.blueAccent)), + child: InAppWebView( + initialUrl: "https://flutter.dev/", + initialHeaders: {}, + initialOptions: InAppWebViewWidgetOptions( + inAppWebViewOptions: InAppWebViewOptions( + debuggingEnabled: true, + clearCache: true + ) + ), + onWebViewCreated: (InAppWebViewController controller) { + webView = controller; + }, + onLoadStart: (InAppWebViewController controller, String url) { + setState(() { + this.url = url; + }); + }, + onLoadStop: (InAppWebViewController controller, String url) async { + setState(() { + this.url = url; + }); + }, + onProgressChanged: (InAppWebViewController controller, int progress) { + setState(() { + this.progress = progress / 100; + }); + }, ), ), - onWebViewCreated: (InAppWebViewController controller) { - webView = controller; - - if (Platform.isAndroid) webView.startSafeBrowsing(); - - webView.addJavaScriptHandler( - handlerName: 'handlerFoo', - callback: (args) { - return new Foo(bar: 'bar_value', baz: 'baz_value'); - }); - - webView.addJavaScriptHandler( - handlerName: 'handlerFooWithArgs', - callback: (args) { - print(args); - return [ - args[0] + 5, - !args[1], - args[2][0], - args[3]['foo'] - ]; - }); - }, - onLoadStart: (InAppWebViewController controller, String url) { - print("started $url"); - setState(() { - this.url = url; - }); - }, - onLoadStop: (InAppWebViewController controller, String url) async { - print("stopped $url"); - - if (Platform.isAndroid) { - controller.clearSslPreferences(); - controller.clearClientCertPreferences(); - } - //controller.findAllAsync(find: "InAppWebView"); - //controller.findAllAsync(find: "InAppWebViewInitialFileTest"); - print(await controller.getFavicons()); - print(await CookieManager.instance().getCookies(url: url)); - //await CookieManager.instance().setCookie(url: url, name: "myCookie", value: "myValue"); - //print(await CookieManager.instance().getCookies(url: url)); - //await Future.delayed(const Duration(milliseconds: 2000)); - //controller.scrollTo(x: 0, y: 500); - //await Future.delayed(const Duration(milliseconds: 2000)); - //controller.scrollBy(x: 0, y: 150); - }, - onScrollChanged: (InAppWebViewController controller, int x, int y) { - //print("\nSCROLLED\n"); - }, - onLoadError: (InAppWebViewController controller, String url, - int code, String message) async { - print("error $url: $code, $message"); - - var tRexHtml = await controller.getTRexRunnerHtml(); - var tRexCss = await controller.getTRexRunnerCss(); - - controller.loadData(data: """ - - - - - - - - $tRexHtml -

- URL $url failed to load. -

-

- Error: $code, $message -

- - - """); - }, - onLoadHttpError: (InAppWebViewController controller, String url, - int statusCode, String description) async { - print("HTTP error $url: $statusCode, $description"); - }, - onProgressChanged: - (InAppWebViewController controller, int progress) { - setState(() { - this.progress = progress / 100; - }); - }, - shouldOverrideUrlLoading: - (InAppWebViewController controller, String url) { - print("override $url"); - controller.loadUrl(url: url); - }, - onLoadResource: (InAppWebViewController controller, - LoadedResource response) { - print("Resource type: '" + - response.initiatorType + - "' started at: " + - response.startTime.toString() + - "ms ---> duration: " + - response.duration.toString() + - "ms " + - response.url); - }, - onConsoleMessage: (InAppWebViewController controller, - ConsoleMessage consoleMessage) { - print(""" - console output: - message: ${consoleMessage.message} - messageLevel: ${consoleMessage.messageLevel.toString()} - """); - }, - onDownloadStart: - (InAppWebViewController controller, String url) async { - // final taskId = await FlutterDownloader.enqueue( - // url: url, - // savedDir: await _findLocalPath(), - // showNotification: true, // show download progress in status bar (for Android) - // openFileFromNotification: true, // click on notification to open downloaded file (for Android) - // ); - }, - onLoadResourceCustomScheme: (InAppWebViewController controller, - String scheme, String url) async { - if (scheme == "my-special-custom-scheme") { - var bytes = await rootBundle.load("assets/" + - url.replaceFirst("my-special-custom-scheme://", "", 0)); - var response = new CustomSchemeResponse( - data: bytes.buffer.asUint8List(), - contentType: "image/svg+xml", - contentEnconding: "utf-8"); - return response; - } - return null; - }, - onTargetBlank: (InAppWebViewController controller, String url) { - print("target _blank: " + url); - controller.loadUrl(url: url); - }, - onGeolocationPermissionsShowPrompt: - (InAppWebViewController controller, String origin) async { - GeolocationPermissionShowPromptResponse response; - - await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: Text("Permission Geolocation API"), - content: Text("Can we use Geolocation API?"), - actions: [ - FlatButton( - child: Text("Close"), - onPressed: () { - response = - new GeolocationPermissionShowPromptResponse( - origin: origin, - allow: false, - retain: false); - Navigator.of(context).pop(); - }, - ), - FlatButton( - child: Text("Accept"), - onPressed: () { - response = - new GeolocationPermissionShowPromptResponse( - origin: origin, - allow: true, - retain: true); - Navigator.of(context).pop(); - }, - ), - ], - ); + ), + ButtonBar( + alignment: MainAxisAlignment.center, + children: [ + RaisedButton( + child: Icon(Icons.arrow_back), + onPressed: () { + if (webView != null) { + webView.goBack(); + } }, - ); - - return response; - }, - onJsAlert: - (InAppWebViewController controller, String message) async { - JsAlertResponseAction action = - await createAlertDialog(context, message); - return new JsAlertResponse( - handledByClient: true, action: action); - }, - onJsConfirm: - (InAppWebViewController controller, String message) async { - JsConfirmResponseAction action = - await createConfirmDialog(context, message); - return new JsConfirmResponse( - handledByClient: true, action: action); - }, - onJsPrompt: (InAppWebViewController controller, String message, - String defaultValue) async { - _textFieldController.text = defaultValue; - JsPromptResponseAction action = - await createPromptDialog(context, message); - return new JsPromptResponse( - handledByClient: true, - action: action, - value: _textFieldController.text); - }, - onSafeBrowsingHit: (InAppWebViewController controller, - String url, SafeBrowsingThreat threatType) async { - SafeBrowsingResponseAction action = - SafeBrowsingResponseAction.SHOW_INTERSTITIAL; - return new SafeBrowsingResponse(report: true, action: action); - }, - onReceivedHttpAuthRequest: (InAppWebViewController controller, - HttpAuthChallenge challenge) async { - print( - "HTTP AUTH REQUEST: ${challenge.protectionSpace.host}, realm: ${challenge.protectionSpace.realm}, previous failure count: ${challenge.previousFailureCount.toString()}"); - - return new HttpAuthResponse( - username: "USERNAME", - password: "PASSWORD", - action: HttpAuthResponseAction - .PROCEED, - permanentPersistence: true); - }, - onReceivedServerTrustAuthRequest: - (InAppWebViewController controller, - ServerTrustChallenge challenge) async { - print( - "SERVER TRUST AUTH REQUEST: ${challenge.protectionSpace.host}, SSL ERROR CODE: ${challenge.error.toString()}, MESSAGE: ${challenge.message}"); - - return new ServerTrustAuthResponse( - action: ServerTrustAuthResponseAction.PROCEED); - }, - onReceivedClientCertRequest: (InAppWebViewController controller, - ClientCertChallenge challenge) async { - print( - "CLIENT CERT REQUEST: ${challenge.protectionSpace.host}"); - - return new ClientCertResponse( - certificatePath: "assets/certificate.pfx", - certificatePassword: "", - androidKeyStoreType: "PKCS12", - action: ClientCertResponseAction.PROCEED); - }, - onFindResultReceived: (InAppWebViewController controller, - int activeMatchOrdinal, - int numberOfMatches, - bool isDoneCounting) async { - print( - "Current highlighted: $activeMatchOrdinal, Number of matches found: $numberOfMatches, find operation completed: $isDoneCounting"); - }, - shouldInterceptAjaxRequest: (InAppWebViewController controller, - AjaxRequest ajaxRequest) async { - print( - "AJAX REQUEST: ${ajaxRequest.method} - ${ajaxRequest.url}, DATA: ${ajaxRequest.data}, headers: ${ajaxRequest.headers}"); - if (ajaxRequest.url == - "http://192.168.1.20:8082/test-ajax-post") { - ajaxRequest.responseType = 'json'; - ajaxRequest.data = "firstname=Lorenzo&lastname=Pichilli"; - } - // ajaxRequest.method = "GET"; - // ajaxRequest.url = "http://192.168.1.20:8082/test-download-file"; - // ajaxRequest.headers = { - // "Custom-Header": "Custom-Value" - // }; - // return ajaxRequest; - return ajaxRequest; - }, - onAjaxReadyStateChange: (InAppWebViewController controller, - AjaxRequest ajaxRequest) async { - print( - "AJAX READY STATE CHANGE: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.status}, ${ajaxRequest.readyState}, ${ajaxRequest.responseType}, ${ajaxRequest.responseText}, ${ajaxRequest.response}, ${ajaxRequest.responseHeaders}"); - return AjaxRequestAction.PROCEED; - }, - onAjaxProgress: (InAppWebViewController controller, - AjaxRequest ajaxRequest) async { - print( - "AJAX EVENT: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.event.type}, LOADED: ${ajaxRequest.event.loaded}, ${ajaxRequest.responseHeaders}"); - return AjaxRequestAction.PROCEED; - }, - shouldInterceptFetchRequest: (InAppWebViewController controller, - FetchRequest fetchRequest) async { - print( - "FETCH REQUEST: ${fetchRequest.method} - ${fetchRequest.url}, headers: ${fetchRequest.headers}"); - fetchRequest.action = FetchRequestAction.ABORT; - print(fetchRequest.body); - return fetchRequest; - }, - onNavigationStateChange: - (InAppWebViewController controller, String url) async { - print("NAVIGATION STATE CHANGE: $url"); - setState(() { - this.url = url; - }); - }, + ), + RaisedButton( + child: Icon(Icons.arrow_forward), + onPressed: () { + if (webView != null) { + webView.goForward(); + } + }, + ), + RaisedButton( + child: Icon(Icons.refresh), + onPressed: () { + if (webView != null) { + webView.reload(); + } + }, + ), + ], ), - ), - ), - ButtonBar( - alignment: MainAxisAlignment.center, - children: [ - RaisedButton( - child: Icon(Icons.arrow_back), - onPressed: () { - if (webView != null) { - webView.goBack(); - } - }, - ), - RaisedButton( - child: Icon(Icons.arrow_forward), - onPressed: () { - if (webView != null) { - webView.goForward(); - } - }, - ), - RaisedButton( - child: Icon(Icons.refresh), - onPressed: () { - if (webView != null) { - webView.reload(); - } - }, - ), - ], - ), ]))); } - - Future createAlertDialog( - BuildContext context, String message) async { - JsAlertResponseAction action; - - await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - content: Text(message), - actions: [ - FlatButton( - child: Text("Ok"), - onPressed: () { - action = JsAlertResponseAction.CONFIRM; - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - - return action; - } - - Future createConfirmDialog( - BuildContext context, String message) async { - JsConfirmResponseAction action; - - await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - content: Text(message), - actions: [ - FlatButton( - child: Text("Cancel"), - onPressed: () { - action = JsConfirmResponseAction.CANCEL; - Navigator.of(context).pop(); - }, - ), - FlatButton( - child: Text("Ok"), - onPressed: () { - action = JsConfirmResponseAction.CONFIRM; - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - - return action; - } - - Future createPromptDialog( - BuildContext context, String message) async { - JsPromptResponseAction action; - - await showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: Text(message), - content: TextField( - controller: _textFieldController, - ), - actions: [ - FlatButton( - child: Text("Cancel"), - onPressed: () { - action = JsPromptResponseAction.CANCEL; - Navigator.of(context).pop(); - }, - ), - FlatButton( - child: Text("Ok"), - onPressed: () { - action = JsPromptResponseAction.CONFIRM; - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - - return action; - } - - Future _findLocalPath() async { - final directory = Platform.isAndroid - ? await getExternalStorageDirectory() - : await getApplicationDocumentsDirectory(); - return directory.path; - } } diff --git a/example/lib/test.dart b/example/lib/test.dart deleted file mode 100644 index 48e9ed9b..00000000 --- a/example/lib/test.dart +++ /dev/null @@ -1,473 +0,0 @@ -//import 'dart:async'; -//import 'dart:convert'; -//import 'package:flutter/material.dart'; -//import 'package:flutter_inappbrowser/flutter_inappbrowser.dart'; -// -//class MyInAppBrowser extends InAppBrowser { -// @override -// Future onBrowserCreated() async { -// print("\n\nBrowser Ready!\n\n"); -// } -// -// @override -// Future onLoadStart(String url) async { -// print("\n\nStarted $url\n\n"); -//// print("\n\n ${await this.isHidden()} \n\n"); -//// print(await this.webViewController.canGoBack()); -//// print(await this.webViewController.canGoForward()); -// } -// -// @override -// Future onLoadStop(String url) async { -// print("\n\nStopped $url\n\n"); -// -//// print(base64.encode(await this.webViewController.getFavicon())); -//// WebHistory history = await this.webViewController.getCopyBackForwardList(); -//// print(history.list.length); -//// print(history.currentIndex); -//// print(history.list[history.currentIndex].url); -//// for(WebHistoryItem item in history.list) { -//// print(item.title); -//// } -// -//// -//// print(await this.webViewController.canGoBackOrForward(1)); -//// if (await this.webViewController.canGoBackOrForward(-2)) { -//// this.webViewController.goTo(history.list[0]); -//// } -// -//// await this.webViewController.goBackOrForward(-1); -// -//// print(await this.webViewController.canGoBack()); -//// print(await this.webViewController.canGoForward()); -// -//// var screenshot = await this.webViewController.takeScreenshot(); -//// await this.webViewController.injectScriptCode(""" -//// document.body.innerHTML = ''; -//// """); -// -//// var options = await this.getOptions(); -//// if (options["javaScriptEnabled"]) { -//// await this.setOptions({ -//// //"progressBar": true, -//// //"useOnLoadResource": true, -//// //"hidden": true, -//// //"toolbarTopFixedTitle": "Fixed title A", -//// //"useShouldOverrideUrlLoading": true -//// //"hideUrlBar": true, -//// "javaScriptEnabled": false, -//// "toolbarTop": true, -//// "toolbarBottom": false -//// }); -//// } -//// else { -//// await this.setOptions({ -//// //"progressBar": false, -//// //"useOnLoadResource": false, -//// //"hidden": true, -//// //"toolbarTopFixedTitle": "Fixed title B", -//// //"useShouldOverrideUrlLoading": true -//// //"hideUrlBar": false, -//// "javaScriptEnabled": true, -//// "toolbarTop": false, -//// "toolbarBottom": true -//// }); -//// } -// -//// print("\n\n ${await this.isHidden()} \n\n"); -//// -//// await this.webViewController.injectScriptCode("window.flutter_inappbrowser.callHandler('handlerTest', 1, 5,'string', {'key': 5}, [4,6,8]);"); -//// await this.webViewController.injectScriptCode("window.flutter_inappbrowser.callHandler('handlerTest2', false, null, undefined);"); -//// await this.webViewController.injectScriptCode("setTimeout(function(){window.flutter_inappbrowser.callHandler('handlerTest', 'anotherString');}, 1000);"); -// -//// await this.webViewController.injectScriptCode("console.log({'testObject': 5});"); -//// await this.webViewController.injectScriptCode("console.warn('testWarn',null);"); -//// await this.webViewController.injectScriptCode("console.log('testObjectStringify', JSON.stringify({'asd': 5}));"); -//// await this.webViewController.injectScriptCode("console.info('testInfo', 6);"); -//// await this.webViewController.injectScriptCode("console.error('testError', false);"); -//// await this.webViewController.injectScriptCode("console.debug('testDebug', true);"); -//// -//// print(await this.webViewController.injectScriptCode("document.cookie")); -//// -//// print(""); -//// print(await CookieManager.getCookies(url)); -//// print(""); -//// print(await CookieManager.getCookie(url, "my_cookie2")); -//// print(""); -//// await CookieManager.deleteCookie(url, "my_cookie2"); -//// await CookieManager.deleteCookie(url, "_gid", domain: ".googleblog.com"); -//// print(""); -//// print(await CookieManager.getCookies(url)); -//// print(""); -//// await CookieManager.deleteCookies(url); -//// print(""); -//// print(await CookieManager.getCookies(url)); -//// print(""); -//// await CookieManager.deleteAllCookies(); -//// print(""); -//// print(await CookieManager.getCookies(url)); -//// print(""); -//// -//// print(await this.webViewController.injectScriptCode("null")); -//// print(await this.webViewController.injectScriptCode("undefined")); -//// print(await this.webViewController.injectScriptCode("3")); -//// print(await this.webViewController.injectScriptCode(""" -//// function asd (a,b) { -//// return a+b; -//// }; -//// asd(3,5); -//// """)); -//// print(await this.webViewController.injectScriptCode(""" -//// ["3",56,"sdf"]; -//// """)); -//// print(await this.webViewController.injectScriptCode(""" -//// var x = {"as":4, "dfdfg": 6}; -//// x; -//// """)); -//// -//// await this.webViewController.injectScriptFile("https://code.jquery.com/jquery-3.3.1.min.js"); -//// this.webViewController.injectScriptCode(""" -//// \$( "body" ).html( "Next Step..." ) -//// """); -//// -//// // add custom css -//// this.webViewController.injectStyleCode(""" -//// body { -//// background-color: #3c3c3c !important; -//// } -//// """); -//// this.webViewController.injectStyleFile("https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"); -// } -// -// @override -// Future onScrollChanged(int x, int y) async { -//// print(x.toString() + " " + y.toString()); -// } -// -// @override -// void onLoadError(String url, int code, String message) { -// print("\n\nCan't load $url.. Error: $message\n\n"); -// } -// -// @override -// void onProgressChanged(int progress) { -//// print("Progress: $progress"); -// } -// -// @override -// void onExit() { -// print("\n\nBrowser closed!\n\n"); -// } -// -// @override -// void shouldOverrideUrlLoading(String url) { -// print("\n\n override $url\n\n"); -// this.webViewController.loadUrl(url); -// -//// var postData = "username=my_username&password=my_password"; -//// inAppBrowserFallback.webViewController.postUrl("http://localhost:8080", utf8.encode(postData)); -// -//// var htmlData = """ -//// -//// -//// -//// -//// -//// -//// Document -//// -//// -//// -//// -//// -////
-////
-//// dart logo -////
-////
-//// One of three columns -////
-////
-//// One of three columns -////
-////
-//// One of three columns -////
-////
-////
-//// -////
-//// -//// -//// """; -//// inAppBrowserFallback.webViewController.loadData(htmlData); -// } -// -// @override -// void onLoadResource( -// WebResourceResponse response, WebResourceRequest request) { -// print("Started at: " + -// response.startTime.toString() + -// "ms ---> duration: " + -// response.duration.toString() + -// "ms " + -// response.url); -//// if (response.headers["content-length"] != null) -//// print(response.headers["content-length"] + " length"); -// } -// -// @override -// void onConsoleMessage(ConsoleMessage consoleMessage) { -// print(consoleMessage.message); -//// print(""" -//// console output: -//// sourceURL: ${consoleMessage.sourceURL} -//// lineNumber: ${consoleMessage.lineNumber} -//// message: ${consoleMessage.message} -//// messageLevel: ${consoleMessage.messageLevel} -//// """); -// } -//} -// -//MyInAppBrowser inAppBrowserFallback = new MyInAppBrowser(); -// -//class MyChromeSafariBrowser extends ChromeSafariBrowser { -// MyChromeSafariBrowser(browserFallback) : super(browserFallback); -// -// @override -// void onOpened() { -// print("ChromeSafari browser opened"); -// } -// -// @override -// void onLoaded() { -// print("ChromeSafari browser loaded"); -// } -// -// @override -// void onClosed() { -// print("ChromeSafari browser closed"); -// } -//} -// -//// adding a webview fallback -//MyChromeSafariBrowser chromeSafariBrowser = -// new MyChromeSafariBrowser(inAppBrowserFallback); -//InAppLocalhostServer localhostServer = new InAppLocalhostServer(); -// -//Future main() async { -//// await localhostServer.start(); -// runApp(new MyApp()); -//} -// -//class MyApp extends StatefulWidget { -// @override -// _MyAppState createState() => new _MyAppState(); -//} -// -//class _MyAppState extends State { -// @override -// void initState() { -// super.initState(); -//// int indexTest = inAppBrowserFallback.webViewController.addJavaScriptHandler("handlerTest", -//// (arguments) async { -//// print("handlerTest arguments"); -//// print(arguments); -//// }); -//// int indexTest2 = inAppBrowserFallback.webViewController.addJavaScriptHandler("test2", (arguments) async { -//// print("handlerTest2 arguments"); -//// print(arguments); -//// inAppBrowserFallback.webViewController.removeJavaScriptHandler("test", indexTest); -//// }); -// } -// -// @override -// Widget build(BuildContext context) { -// return new MaterialApp( -// home: new Scaffold( -// appBar: new AppBar( -// title: const Text('Flutter InAppBrowser Plugin example app'), -// ), -// body: new Center( -// child: new RaisedButton( -// onPressed: () async { -//// await chromeSafariBrowser.open("https://flutter.io/"); -//// -//// await InAppBrowser.openWithSystemBrowser("https://flutter.io/"); -//// -//// await inAppBrowserFallback.open(url: "http://localhost:8080/assets/index.html", options: { -//// "useOnLoadResource": true, -//// //"hidden": true, -//// //"toolbarTopFixedTitle": "Fixed title", -//// //"useShouldOverrideUrlLoading": true -//// //"hideUrlBar": true, -//// //"toolbarTop": false, -//// "toolbarBottom": false -//// }); -//// -//// await inAppBrowserFallback.openFile("assets/index.html", options: { -//// "useOnLoadResource": true, -//// //"hidden": true, -//// //"useShouldOverrideUrlLoading": true -//// //"hideUrlBar": true, -//// //"toolbarTop": false, -//// //"toolbarBottom": false -//// }); -//// -//// await CookieManager.setCookie("https://flutter.io/", "my_cookie2", "cookieValue2", domain: "flutter.io", expiresDate: 1540838864611); -//// await CookieManager.setCookie("https://flutter.io/", "my_cookie", "cookieValue", domain: "flutter.io", expiresDate: 1540838864611); -// -//// await inAppBrowserFallback.openData("Data example

This is a \"p\" tag

", options: {}); -// -// await inAppBrowserFallback.open(url: "https://flutter.io/", options: { -// //"useOnLoadResource": true, -// //"hidden": true, -// //"toolbarTopFixedTitle": "Fixed title", -// "useShouldOverrideUrlLoading": true, -// //"hideUrlBar": true, -// //"toolbarTop": false, -// //"toolbarBottom": false -// }); -// -// }, -// child: Text("Open InAppBrowser") -// ), -// ), -// ), -// ); -// } -//} - - -// Inline WebView Example - -import 'dart:async'; -import 'package:flutter/material.dart'; -import 'package:flutter_inappbrowser/flutter_inappbrowser.dart'; - -Future main() async { - runApp(new MyApp()); -} - -class MyApp extends StatefulWidget { - @override - _MyAppState createState() => new _MyAppState(); -} - -class _MyAppState extends State { - - InAppWebViewController webView; - String url = ""; - double progress = 0; - - @override - void initState() { - super.initState(); - } - - @override - void dispose() { - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Scaffold( - appBar: AppBar( - title: const Text('Inline WebView example app'), - ), - body: Container( - child: Column( - children: [ - Container( - padding: EdgeInsets.all(20.0), - child: Text("CURRENT URL\n${ (url.length > 50) ? url.substring(0, 50) + "..." : url }"), - ), - (progress != 1.0) ? LinearProgressIndicator(value: progress) : null, - Expanded( - child: Container( - margin: const EdgeInsets.all(10.0), - decoration: BoxDecoration( - border: Border.all(color: Colors.blueAccent) - ), - child: InAppWebView( - initialUrl: "https://flutter.io/", - //initialData: InAppWebViewInitialData("Data example

This is a \"p\" tag

"), - initialHeaders: { - - }, - initialOptions: InAppWebViewWidgetOptions(), - onWebViewCreated: (InAppWebViewController controller) { - webView = controller; - }, - onLoadStart: (InAppWebViewController controller, String url) { - print("started $url"); - setState(() { - this.url = url; - }); - }, - onProgressChanged: (InAppWebViewController controller, int progress) { - setState(() { - this.progress = progress/100; - }); - }, - ), - ), - ), - ButtonBar( - alignment: MainAxisAlignment.center, - children: [ - RaisedButton( - child: Icon(Icons.arrow_back), - onPressed: () { - if (webView != null) { - webView.goBack(); - } - }, - ), - RaisedButton( - child: Icon(Icons.arrow_forward), - onPressed: () { - if (webView != null) { - webView.goForward(); - } - }, - ), - RaisedButton( - child: Icon(Icons.refresh), - onPressed: () { - if (webView != null) { - webView.reload(); - } - }, - ), - ], - ), - ].where((Object o) => o != null).toList(), - ), - ), - bottomNavigationBar: BottomNavigationBar( - currentIndex: 0, - items: [ - BottomNavigationBarItem( - icon: Icon(Icons.home), - title: Text('Home'), - ), - BottomNavigationBarItem( - icon: Icon(Icons.mail), - title: Text('Item 2'), - ), - BottomNavigationBarItem( - icon: Icon(Icons.person), - title: Text('Item 3') - ) - ], - ), - ), - ); - } -} diff --git a/lib/src/in_app_webview.dart b/lib/src/in_app_webview.dart index 5e7ac100..287d7813 100755 --- a/lib/src/in_app_webview.dart +++ b/lib/src/in_app_webview.dart @@ -1284,7 +1284,7 @@ class InAppWebViewController { ///This should not be called if Safe Browsing has been disabled by manifest tag ///or [AndroidInAppWebViewOptions.safeBrowsingEnabled]. This prepares resources used for Safe Browsing. /// - ///**NOTE**: available only for Android. + ///**NOTE**: available on Android 27+. Future startSafeBrowsing() async { Map args = {}; if (_inAppBrowserUuid != null && _inAppBrowser != null) { @@ -1308,7 +1308,7 @@ class InAppWebViewController { /// ///[hosts] represents the list of hosts. This value must never be null. /// - ///**NOTE**: available only for Android. + ///**NOTE**: available on Android 27+. Future setSafeBrowsingWhitelist({@required List hosts}) async { assert(hosts != null); Map args = {}; @@ -1322,7 +1322,7 @@ class InAppWebViewController { ///Returns a URL pointing to the privacy policy for Safe Browsing reporting. This value will never be `null`. /// - ///**NOTE**: available only for Android. + ///**NOTE**: available on Android 27+. Future getSafeBrowsingPrivacyPolicyUrl() async { Map args = {}; if (_inAppBrowserUuid != null && _inAppBrowser != null) { @@ -1344,7 +1344,7 @@ class InAppWebViewController { ///Clears the SSL preferences table stored in response to proceeding with SSL certificate errors. /// - ///**NOTE**: available only for Android. + ///**NOTE**: available only on Android. Future clearSslPreferences() async { Map args = {}; if (_inAppBrowserUuid != null && _inAppBrowser != null) { @@ -1360,7 +1360,7 @@ class InAppWebViewController { /// ///**NOTE**: On iOS certificate-based credentials are never stored permanently. /// - ///**NOTE**: available only for Android. + ///**NOTE**: available on Android 21+. Future clearClientCertPreferences() async { Map args = {}; if (_inAppBrowserUuid != null && _inAppBrowser != null) {