From bb0e7f70c7f5c1c3844bab3f6acfd08c80cfb06d Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Sun, 10 Nov 2019 11:50:01 +0100 Subject: [PATCH] fixed InAppWebViewOptions error, fixed javascript error for ajax requests --- .idea/workspace.xml | 253 ++++++++++-------- .../InAppWebView/InAppWebView.java | 2 +- .../InAppWebView/InAppWebViewOptions.java | 41 +-- example/lib/inline_example.screen.dart | 6 +- ios/Classes/InAppWebView.swift | 2 +- lib/src/content_blocker.dart | 6 + 6 files changed, 169 insertions(+), 141 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e1189688..3c7217bd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -16,14 +16,10 @@ - - - - + + - - @@ -43,11 +39,11 @@ - + - - + + @@ -55,22 +51,10 @@ - - - - - - - - - - - - - + @@ -82,8 +66,29 @@ - - + + + + + + + + + + + + + + + + + + + + + + + @@ -91,7 +96,7 @@ - + @@ -100,10 +105,22 @@ + + + + + + + + + + + + - + @@ -124,10 +141,6 @@ - mediaPlaybackRequiresUserGesture - onDow - toolbarTopFixedTitle - resourceCustomSchemes JsAlertResponse JsConfirmResponse InAppWebViewUserPreferredContentMode @@ -152,8 +165,12 @@ method AjaxRequestEvent withCredentials - FetchRequest current + FetchRequest + my-special-custom-scheme + should + resourceCustomSchemes + shouldInterceptAjaxRequest activity.getPreferences(0) @@ -217,19 +234,19 @@ @@ -244,6 +261,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -475,7 +492,7 @@ - + @@ -486,7 +503,7 @@ - + @@ -494,7 +511,7 @@ - + @@ -688,13 +705,6 @@ - - - - - - - @@ -712,33 +722,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -746,9 +729,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -758,7 +768,7 @@ - + @@ -766,10 +776,27 @@ - + - - + + + + + + + + + + + + + + + + + + + @@ -778,24 +805,14 @@ - - + + - - - - - - - - - - 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 d9620dd4..bb441d24 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 @@ -161,7 +161,7 @@ final public class InAppWebView extends InputAwareWebView { " event: {" + " type: e.type," + " loaded: e.loaded," + - " lengthComputable: e.lengthComputable" + + " lengthComputable: e.lengthComputable," + " total: e.total" + " }" + " };" + diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java index cf2942fb..63b86029 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java @@ -84,17 +84,20 @@ public class InAppWebViewOptions extends Options { @Override public Object onParse(Map.Entry pair) { if (pair.getKey().equals("layoutAlgorithm")) { - switch ((String) pair.getValue()) { - case "NORMAL": - pair.setValue(NORMAL); - return pair; - case "TEXT_AUTOSIZING": - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - return pair.setValue(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); - } else { + String value = (String) pair.getValue(); + if (value != null) { + switch (value) { + case "NORMAL": pair.setValue(NORMAL); - } - return pair; + return pair; + case "TEXT_AUTOSIZING": + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + return pair.setValue(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); + } else { + pair.setValue(NORMAL); + } + return pair; + } } } return super.onParse(pair); @@ -105,14 +108,16 @@ public class InAppWebViewOptions extends Options { if (field.getName().equals("layoutAlgorithm")) { try { WebSettings.LayoutAlgorithm value = (WebSettings.LayoutAlgorithm) field.get(this); - switch (value) { - case NORMAL: - return "NORMAL"; - default: - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && value.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { - return "TEXT_AUTOSIZING"; - } - return "NORMAL"; + if (value != null) { + switch (value) { + case NORMAL: + return "NORMAL"; + default: + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && value.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) { + return "TEXT_AUTOSIZING"; + } + return "NORMAL"; + } } } catch (IllegalAccessException e) { Log.d(LOG_TAG, e.getMessage()); diff --git a/example/lib/inline_example.screen.dart b/example/lib/inline_example.screen.dart index 2454cb3f..b6a69baa 100755 --- a/example/lib/inline_example.screen.dart +++ b/example/lib/inline_example.screen.dart @@ -288,7 +288,7 @@ class _InlineExampleScreenState extends State { 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}"); + print("AJAX REQUEST: ${ajaxRequest.method} - ${ajaxRequest.url}, DATA: ${ajaxRequest.data}"); // ajaxRequest.method = "GET"; // ajaxRequest.url = "http://192.168.1.20:8082/test-download-file"; // ajaxRequest.headers = { @@ -298,11 +298,11 @@ class _InlineExampleScreenState extends State { return null; }, onAjaxReadyStateChange: (InAppWebViewController controller, AjaxRequest ajaxRequest) async { - //print("AJAX READY STATE CHANGE: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.status}, ${ajaxRequest.readyState}, ${ajaxRequest.responseType}, ${ajaxRequest.responseText}, ${ajaxRequest.responseHeaders}"); + print("AJAX READY STATE CHANGE: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.status}, ${ajaxRequest.readyState}, ${ajaxRequest.responseType}, ${ajaxRequest.responseText}, ${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}"); + 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 { diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift index 8c69a0f3..e56b1a6b 100755 --- a/ios/Classes/InAppWebView.swift +++ b/ios/Classes/InAppWebView.swift @@ -311,7 +311,7 @@ let interceptAjaxRequestsJS = """ event: { type: e.type, loaded: e.loaded, - lengthComputable: e.lengthComputable + lengthComputable: e.lengthComputable, total: e.total } }; diff --git a/lib/src/content_blocker.dart b/lib/src/content_blocker.dart index 5f667a42..3075f320 100644 --- a/lib/src/content_blocker.dart +++ b/lib/src/content_blocker.dart @@ -1,3 +1,4 @@ +/// class ContentBlocker { ContentBlockerTrigger trigger; ContentBlockerAction action; @@ -23,6 +24,7 @@ class ContentBlocker { } } +/// class ContentBlockerTriggerResourceType { final String _value; const ContentBlockerTriggerResourceType._internal(this._value); @@ -42,6 +44,7 @@ class ContentBlockerTriggerResourceType { static const RAW = const ContentBlockerTriggerResourceType._internal('raw'); } +/// class ContentBlockerTriggerLoadType { final String _value; const ContentBlockerTriggerLoadType._internal(this._value); @@ -54,6 +57,7 @@ class ContentBlockerTriggerLoadType { static const THIRD_PARTY = const ContentBlockerTriggerLoadType._internal('third-party'); } +/// class ContentBlockerTrigger { String urlFilter; bool urlFilterIsCaseSensitive; @@ -136,6 +140,7 @@ class ContentBlockerTrigger { } } +/// class ContentBlockerActionType { final String _value; const ContentBlockerActionType._internal(this._value); @@ -149,6 +154,7 @@ class ContentBlockerActionType { static const MAKE_HTTPS = const ContentBlockerActionType._internal('make-https'); } +/// class ContentBlockerAction { ContentBlockerActionType type; String selector;