From 18919576e0153f29e5534ec1ed0c77911390757b Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Tue, 5 Nov 2019 03:44:22 +0100 Subject: [PATCH 1/5] Added shouldInterceptAjaxRequest, onAjaxReadyStateChange, onAjaxProgressEvent and shouldInterceptFetchRequest events, added useShouldInterceptAjaxRequest and useShouldInterceptFetchRequest webview options, updated node.js server test, added injectJavascriptFileFromAsset and injectCSSFileFromAsset methods, renamed some methods --- .../example_lib_main_dart.xml | 1 - .idea/workspace.xml | 413 ++++++++++-------- CHANGELOG.md | 7 +- .../ContentBlocker/ContentBlockerHandler.java | 3 +- .../flutter_inappbrowser/FlutterWebView.java | 29 +- .../flutter_inappbrowser/InAppBrowser.java | 32 +- .../InAppBrowserActivity.java | 16 +- .../InAppWebView/InAppWebView.java | 236 +++++++++- .../InAppWebView/InAppWebViewClient.java | 93 +--- .../InAppWebView/InAppWebViewOptions.java | 2 + .../JavaScriptBridgeInterface.java | 38 +- example/assets/index.html | 30 +- .../ios/Flutter/flutter_export_environment.sh | 3 +- example/ios/Runner.xcodeproj/project.pbxproj | 2 - example/lib/inline_example.screen.dart | 29 +- ios/Classes/FlutterWebViewController.swift | 16 +- ios/Classes/InAppWebView.swift | 305 +++++++++++-- ios/Classes/InAppWebViewOptions.swift | 2 + ios/Classes/SwiftFlutterPlugin.swift | 32 +- ios/flutter_inappbrowser.podspec | 1 - lib/src/in_app_webview.dart | 215 ++++++--- lib/src/types.dart | 180 ++++++++ lib/src/webview_options.dart | 9 +- .../assets/flutter_logo.png | Bin 0 -> 1900 bytes .../assets/flutter_logo.svg | 1 + .../index.js | 36 +- .../package-lock.json | 14 + .../package.json | 1 + 28 files changed, 1264 insertions(+), 482 deletions(-) create mode 100644 nodejs_server_test_auth_basic_and_ssl/assets/flutter_logo.png create mode 100644 nodejs_server_test_auth_basic_and_ssl/assets/flutter_logo.svg diff --git a/.idea/runConfigurations/example_lib_main_dart.xml b/.idea/runConfigurations/example_lib_main_dart.xml index 624f56a6..bac2c8a7 100644 --- a/.idea/runConfigurations/example_lib_main_dart.xml +++ b/.idea/runConfigurations/example_lib_main_dart.xml @@ -1,6 +1,5 @@ - diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c3f13ef6..638eec5d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,35 +15,33 @@ - - + + + + + + + - + - - - - - + - - - - - + + @@ -66,8 +64,8 @@ - - + + @@ -76,10 +74,10 @@ - + - - + + @@ -88,26 +86,65 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + + + + + + + + + + + + + + + + + + + @@ -120,23 +157,6 @@ - toggleErrorInformationPopup - error-information-popup-container - offline-spri - sprite - icon-offline - ICON - loadImages - RESOURCE_TEMPLATE_ID - adjustDimensions - outerContainerEl - ontouch - fromVa - ContentBlockerActionType - getOptions - iOS - Ios - initialOptions initialOpti Platform Platform.i @@ -150,6 +170,23 @@ List< debuggingEnabled initialOp + injectScriptFile + injectScriptUrlFile + [InAppWebView] window + javaScriptEnabled + onLoadRes + onLoadResource + onLoadResource" + javaScriptHandlersMap + javaScriptHandlers + onAjaxSend + Action + AjaxRequestEventType + onAjax + onAjaxReadyStateChange + onAjaxEvent + shouldInterceptAjaxRequest + shouldInterceptFetchRequest activity.getPreferences(0) @@ -160,6 +197,8 @@ ChannelManager Function ?.toMap() ?? {}); + javascriptEnabled + [InAppWebView]\ $PROJECT_DIR$/example/android @@ -199,31 +238,31 @@ @@ -238,6 +277,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -267,61 +377,6 @@ - - - - - - - - - - - - - @@ -377,6 +332,17 @@ + + @@ -541,7 +507,7 @@ - + @@ -549,7 +515,7 @@ - + @@ -766,13 +732,10 @@ - + - - - - - + + @@ -783,43 +746,22 @@ - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - + @@ -836,15 +778,39 @@ - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b884586..9169ec81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,8 @@ - Added `onReceivedServerTrustAuthRequest` and `onReceivedClientCertRequest` events to manage SSL requests - Added `onFindResultReceived` event, `findAllAsync`, `findNext` and `clearMatches` methods - Added `getHtml`, `injectJavascriptFileFromAsset` and `injectCSSFileFromAsset` methods -- Added `shouldInterceptAjaxRequest`, `onAjaxReadyStateChange`, `onAjaxProgressEvent` and `shouldInterceptFetchRequest` events with `useShouldInterceptAjaxRequest` and `useShouldInterceptFetchRequest` webview options +- Added `shouldInterceptAjaxRequest`, `onAjaxReadyStateChange`, `onAjaxProgress` and `shouldInterceptFetchRequest` events with `useShouldInterceptAjaxRequest` and `useShouldInterceptFetchRequest` webview options +- Added `onNavigationStateChange` event - Fun: added `getTRexRunnerHtml` and `getTRexRunnerCss` methods to get html (with javascript) and css to recreate the Chromium's t-rex runner game ### BREAKING CHANGES 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 c3b61968..4ae9bb68 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 @@ -154,9 +154,9 @@ final public class InAppWebView extends InputAwareWebView { " lengthComputable: e.lengthComputable" + " }" + " };" + - " window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxProgressEvent', ajaxRequest).then(function(result) {" + + " window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxProgress', ajaxRequest).then(function(result) {" + " if (result != null) {" + - " switch (result.action) {" + + " switch (result) {" + " case 0:" + " self.abort();" + " return;" + @@ -197,7 +197,7 @@ final public class InAppWebView extends InputAwareWebView { " };" + " window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxReadyStateChange', ajaxRequest).then(function(result) {" + " if (result != null) {" + - " switch (result.action) {" + + " switch (result) {" + " case 0:" + " self.abort();" + " return;" + diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java index ae397965..88b630ed 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java @@ -49,9 +49,9 @@ public class InAppWebViewClient extends WebViewClient { private FlutterWebView flutterWebView; private InAppBrowserActivity inAppBrowserActivity; Map statusCodeMapping = new HashMap(); - long startPageTime = 0; private static int previousAuthRequestFailureCount = 0; private static List credentialsProposed = null; + private String onPageStartedURL = ""; public InAppWebViewClient(Object obj) { super(); @@ -145,9 +145,9 @@ public class InAppWebViewClient extends WebViewClient { webView.loadUrl("javascript:" + InAppWebView.resourceObserverJS.replaceAll("[\r\n]+", "")); } + onPageStartedURL = url; super.onPageStarted(view, url, favicon); - startPageTime = System.currentTimeMillis(); webView.isLoading = true; if (inAppBrowserActivity != null && inAppBrowserActivity.searchView != null && !url.equals(inAppBrowserActivity.searchView.getQuery().toString())) { inAppBrowserActivity.searchView.setQuery(url, false); @@ -194,6 +194,21 @@ public class InAppWebViewClient extends WebViewClient { getChannel().invokeMethod("onLoadStop", obj); } + @Override + public void doUpdateVisitedHistory (WebView view, String url, boolean isReload) { + super.doUpdateVisitedHistory(view, url, isReload); + + if (!isReload && !url.equals(onPageStartedURL)) { + onPageStartedURL = ""; + Map obj = new HashMap<>(); + if (inAppBrowserActivity != null) + obj.put("uuid", inAppBrowserActivity.uuid); + obj.put("url", url); + getChannel().invokeMethod("onNavigationStateChange", obj); + } + } + + @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); diff --git a/example/assets/index.html b/example/assets/index.html index 4930ba70..5bcf2652 100644 --- a/example/assets/index.html +++ b/example/assets/index.html @@ -31,6 +31,9 @@ + + +

placeholder 100x50

@@ -51,6 +54,27 @@