added onNavigationStateChange, updated onAjaxProgress and onAjaxReadyStateChange return type

This commit is contained in:
Lorenzo Pichilli 2019-11-06 00:23:24 +01:00
parent 18919576e0
commit 16de8b199d
10 changed files with 270 additions and 149 deletions

200
.idea/workspace.xml generated
View File

@ -15,33 +15,16 @@
</component>
<component name="ChangeListManager">
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
<change afterPath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/assets/flutter_logo.svg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/runConfigurations/example_lib_main_dart.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/runConfigurations/example_lib_main_dart.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ContentBlocker/ContentBlockerHandler.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/FlutterWebView.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowser.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserActivity.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewClient.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/JavaScriptBridgeInterface.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/JavaScriptBridgeInterface.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/assets/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/example/assets/index.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/Flutter/flutter_export_environment.sh" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Flutter/flutter_export_environment.sh" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/project.pbxproj" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/project.pbxproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/inline_example.screen.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/inline_example.screen.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/FlutterWebViewController.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/FlutterWebViewController.swift" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppWebView.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppWebView.swift" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppWebViewOptions.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppWebViewOptions.swift" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" beforeDir="false" afterPath="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/in_app_browser.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/in_app_browser.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/in_app_webview.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/in_app_webview.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/types.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/types.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/src/webview_options.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/src/webview_options.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/package-lock.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/package.json" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
<ignored path="$PROJECT_DIR$/.idea/" />
@ -64,8 +47,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/in_app_webview.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="429">
<caret line="628" column="43" selection-start-line="628" selection-start-column="16" selection-end-line="628" selection-end-column="43" />
<state relative-caret-position="257">
<caret line="194" column="34" lean-forward="true" selection-start-line="189" selection-start-column="2" selection-end-line="194" selection-end-column="34" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
@ -73,11 +56,23 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/src/in_app_browser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="217">
<caret line="510" column="34" selection-start-line="510" selection-start-column="34" selection-end-line="510" selection-end-column="34" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-319">
<caret line="776" column="32" selection-start-line="776" selection-start-column="32" selection-end-line="776" selection-end-column="32" />
<state relative-caret-position="13">
<caret line="709" column="3" selection-start-line="709" selection-start-column="3" selection-end-line="709" selection-end-column="3" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -100,26 +95,17 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="423">
<caret line="80" column="26" selection-start-line="78" selection-start-column="12" selection-end-line="80" selection-end-column="26" />
<state relative-caret-position="185">
<caret line="35" column="52" selection-start-line="35" selection-start-column="52" selection-end-line="36" selection-end-column="15" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/index.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-11">
<caret line="61" selection-start-line="61" selection-end-line="61" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="164">
<caret line="89" column="55" selection-start-line="89" selection-start-column="55" selection-end-line="89" selection-end-column="55" />
<state relative-caret-position="177">
<caret line="313" column="35" selection-start-line="313" selection-start-column="12" selection-end-line="313" selection-end-column="35" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
@ -130,17 +116,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="29" selection-start-line="29" selection-end-line="29" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/pubspec.yaml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="116">
<caret line="23" column="28" selection-start-line="23" selection-start-column="28" selection-end-line="23" selection-end-column="28" />
<state relative-caret-position="450">
<caret line="30" column="39" selection-start-line="30" selection-start-column="39" selection-end-line="30" selection-end-column="39" />
</state>
</provider>
</entry>
@ -157,10 +134,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>initialOpti</find>
<find>Platform</find>
<find>Platform.i</find>
<find>getOption</find>
<find>.toValue</find>
<find>fromValue(</find>
<find>?.toMap());</find>
@ -187,6 +160,10 @@
<find>onAjaxEvent</find>
<find>shouldInterceptAjaxRequest</find>
<find>shouldInterceptFetchRequest</find>
<find>onAjaxProgress</find>
<find>onAjaxReady</find>
<find>NAVIGATION</find>
<find>onNavigationStateChange</find>
</findStrings>
<replaceStrings>
<replace>activity.getPreferences(0)</replace>
@ -251,18 +228,18 @@
<option value="$PROJECT_DIR$/example/lib/test.dart" />
<option value="$PROJECT_DIR$/example/lib/webview_example.screen.dart" />
<option value="$PROJECT_DIR$/lib/src/content_blocker.dart" />
<option value="$PROJECT_DIR$/lib/src/in_app_browser.dart" />
<option value="$PROJECT_DIR$/lib/src/chrome_safari_browser.dart" />
<option value="$PROJECT_DIR$/example/lib/chrome_safari_example.screen.dart" />
<option value="$PROJECT_DIR$/example/pubspec.yaml" />
<option value="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" />
<option value="$PROJECT_DIR$/lib/src/types.dart" />
<option value="$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/index.js" />
<option value="$PROJECT_DIR$/lib/src/in_app_webview.dart" />
<option value="$PROJECT_DIR$/example/assets/index.html" />
<option value="$PROJECT_DIR$/lib/src/webview_options.dart" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
<option value="$PROJECT_DIR$/lib/src/types.dart" />
<option value="$PROJECT_DIR$/example/lib/inline_example.screen.dart" />
<option value="$PROJECT_DIR$/CHANGELOG.md" />
<option value="$PROJECT_DIR$/example/assets/index.html" />
<option value="$PROJECT_DIR$/lib/src/in_app_webview.dart" />
<option value="$PROJECT_DIR$/lib/src/in_app_browser.dart" />
</list>
</option>
</component>
@ -284,17 +261,6 @@
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
<item name="example" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
<item name="example" type="462c0819:PsiDirectoryNode" />
<item name="assets" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
@ -337,17 +303,6 @@
</subPane>
</pane>
<pane id="PackagesPane" />
<pane id="Scope">
<subPane subId="Project Files">
<expand>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="flutter_inappbrowser" type="cbb8eebc:String" user="flutter_inappbrowser" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="AndroidView">
<subPane>
<expand>
@ -377,6 +332,17 @@
<select />
</subPane>
</pane>
<pane id="Scope">
<subPane subId="Project Files">
<expand>
<path>
<item name="Root" type="cbb8eebc:String" user="Root" />
<item name="flutter_inappbrowser" type="cbb8eebc:String" user="flutter_inappbrowser" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
@ -541,7 +507,7 @@
<window_info id="Resources Explorer" order="8" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32642487" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49574015" weight="0.5181347" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49574015" visible="true" weight="0.5792746" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.34196892" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -549,7 +515,7 @@
<window_info anchor="bottom" id="Android Profiler" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Event Log" order="8" sideWeight="0.50692225" side_tool="true" weight="0.38445595" />
<window_info anchor="bottom" id="Version Control" order="9" weight="0.32953367" />
<window_info active="true" anchor="bottom" id="Terminal" order="10" sideWeight="0.49533224" visible="true" weight="0.37823835" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.49533224" weight="0.37823835" />
<window_info anchor="bottom" id="Logcat" order="11" weight="0.32953367" />
<window_info anchor="bottom" id="Messages" order="12" weight="0.3253886" />
<window_info anchor="bottom" id="Dependency Viewer" order="13" weight="0.32800853" />
@ -766,13 +732,10 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_browser.dart">
<entry file="file://$PROJECT_DIR$/ios/flutter_inappbrowser.podspec">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="896">
<caret line="287" column="5" selection-start-line="276" selection-start-column="4" selection-end-line="287" selection-end-column="5" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
<state relative-caret-position="300">
<caret line="20" column="25" selection-start-line="20" selection-start-column="25" selection-end-line="20" selection-end-column="25" />
</state>
</provider>
</entry>
@ -783,43 +746,22 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/ios/flutter_inappbrowser.podspec">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300">
<caret line="20" column="25" selection-start-line="20" selection-start-column="25" selection-end-line="20" selection-end-column="25" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/index.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-11">
<caret line="61" selection-start-line="61" selection-end-line="61" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="423">
<caret line="80" column="26" selection-start-line="78" selection-start-column="12" selection-end-line="80" selection-end-column="26" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-319">
<caret line="776" column="32" selection-start-line="776" selection-start-column="32" selection-end-line="776" selection-end-column="32" />
<state relative-caret-position="13">
<caret line="709" column="3" selection-start-line="709" selection-start-column="3" selection-end-line="709" selection-end-column="3" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_webview.dart">
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="429">
<caret line="628" column="43" selection-start-line="628" selection-start-column="16" selection-end-line="628" selection-end-column="43" />
<state relative-caret-position="177">
<caret line="313" column="35" selection-start-line="313" selection-start-column="12" selection-end-line="313" selection-end-column="35" />
<folding>
<element signature="e#0#17#0" expanded="true" />
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
@ -836,15 +778,39 @@
</entry>
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="29" selection-start-line="29" selection-end-line="29" />
<state relative-caret-position="450">
<caret line="30" column="39" selection-start-line="30" selection-start-column="39" selection-end-line="30" selection-end-column="39" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
<entry file="file://$PROJECT_DIR$/nodejs_server_test_auth_basic_and_ssl/index.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="164">
<caret line="89" column="55" selection-start-line="89" selection-start-column="55" selection-end-line="89" selection-end-column="55" />
<state relative-caret-position="15">
<caret line="61" selection-start-line="61" selection-end-line="61" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="185">
<caret line="35" column="52" selection-start-line="35" selection-start-column="52" selection-end-line="36" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_webview.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="257">
<caret line="194" column="34" lean-forward="true" selection-start-line="189" selection-start-column="2" selection-end-line="194" selection-end-column="34" />
<folding>
<element signature="e#0#17#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/src/in_app_browser.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="217">
<caret line="510" column="34" selection-start-line="510" selection-start-column="34" selection-end-line="510" selection-end-column="34" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>

View File

@ -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

View File

@ -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;" +

View File

@ -49,9 +49,9 @@ public class InAppWebViewClient extends WebViewClient {
private FlutterWebView flutterWebView;
private InAppBrowserActivity inAppBrowserActivity;
Map<Integer, String> statusCodeMapping = new HashMap<Integer, String>();
long startPageTime = 0;
private static int previousAuthRequestFailureCount = 0;
private static List<Credential> 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<String, Object> 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);

View File

@ -31,6 +31,9 @@
<option value="1">option 1</option>
<option value="2">option 2</option>
</select>
<button onclick="testHistoryPush1()">History Push 1</button>
<button onclick="testHistoryPush2()">History Push 2</button>
<button onclick="testLocationHref()">Location Href</button>
<p>
<img src="https://via.placeholder.com/100x50" alt="placeholder 100x50">
</p>
@ -51,6 +54,27 @@
</div>
<script>
var state = { 'page_id': 1, 'user_id': 5 };
function testHistoryPush1() {
var randomNumber = 100 * Math.random();
var title = 'Hello World ' + randomNumber;
var url = 'hello-foo-' + randomNumber + '.html';
history.pushState(state, title, url);
}
function testHistoryPush2() {
var randomNumber = 100 * Math.random();
var title = 'Hello World ' + randomNumber;
var url = 'hello-bar-' + randomNumber + '.html';
history.replaceState(state, title, url);
}
function testLocationHref() {
var randomNumber = 100 * Math.random();
window.location = "#foo-" + randomNumber;
}
window.addEventListener("flutterInAppBrowserPlatformReady", function(event) {
console.log("ready");

View File

@ -300,17 +300,23 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
},
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}");
return null;
return AjaxRequestAction.ABORT;
},
onAjaxProgressEvent: (InAppWebViewController controller, AjaxRequest ajaxRequest) async {
onAjaxProgress: (InAppWebViewController controller, AjaxRequest ajaxRequest) async {
print("AJAX EVENT: ${ajaxRequest.method} - ${ajaxRequest.url}, ${ajaxRequest.event.type}, LOADED: ${ajaxRequest.event.loaded}, ${ajaxRequest.responseHeaders}");
return null;
return AjaxRequestAction.ABORT;
},
shouldInterceptFetchRequest: (InAppWebViewController controller, FetchRequest fetchRequest) async {
print("FETCH REQUEST: ${fetchRequest.method} - ${fetchRequest.url}");
fetchRequest.action = FetchRequestAction.ABORT;
return fetchRequest;
},
onNavigationStateChange: (InAppWebViewController controller, String url) async {
print("NAVIGATION STATE CHANGE: ${url}");
setState(() {
this.url = url;
});
},
),
),
),

View File

@ -124,7 +124,7 @@ function wkwebview_FindAllAsyncForElement(element, keyword) {
value.substr(idx + keyword.length)
);
window.webkit.messageHandlers["findResultReceived"].postMessage(
window.webkit.messageHandlers["onFindResultReceived"].postMessage(
JSON.stringify({
activeMatchOrdinal: wkwebview_CurrentHighlight,
numberOfMatches: wkwebview_SearchResultCount,
@ -154,7 +154,7 @@ function wkwebview_FindAllAsync(keyword) {
wkwebview_ClearMatches();
wkwebview_FindAllAsyncForElement(document.body, keyword.toLowerCase());
wkwebview_IsDoneCounting = true;
window.webkit.messageHandlers["findResultReceived"].postMessage(
window.webkit.messageHandlers["onFindResultReceived"].postMessage(
JSON.stringify({
activeMatchOrdinal: wkwebview_CurrentHighlight,
numberOfMatches: wkwebview_SearchResultCount,
@ -221,7 +221,7 @@ function wkwebview_FindNext(forward) {
block: "center"
});
window.webkit.messageHandlers["findResultReceived"].postMessage(
window.webkit.messageHandlers["onFindResultReceived"].postMessage(
JSON.stringify({
activeMatchOrdinal: wkwebview_CurrentHighlight,
numberOfMatches: wkwebview_SearchResultCount,
@ -291,9 +291,9 @@ let interceptAjaxRequestsJS = """
lengthComputable: e.lengthComputable
}
};
window.\(JAVASCRIPT_BRIDGE_NAME).callHandler('onAjaxProgressEvent', ajaxRequest).then(function(result) {
window.\(JAVASCRIPT_BRIDGE_NAME).callHandler('onAjaxProgress', ajaxRequest).then(function(result) {
if (result != null) {
switch (result.action) {
switch (result) {
case 0:
self.abort();
return;
@ -334,7 +334,7 @@ let interceptAjaxRequestsJS = """
};
window.\(JAVASCRIPT_BRIDGE_NAME).callHandler('onAjaxReadyStateChange', ajaxRequest).then(function(result) {
if (result != null) {
switch (result.action) {
switch (result) {
case 0:
self.abort();
return;
@ -457,6 +457,35 @@ let interceptFetchRequestsJS = """
})(window.fetch);
"""
let interceptNavigationStateChangeJS = """
(function(window, document, history) {
history.pushState = (function(f) {
return function pushState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('pushstate'));
window.dispatchEvent(new Event('locationchange'));
return ret;
};
})(history.pushState);
history.replaceState = ( function(f) {
return function replaceState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('replacestate'));
window.dispatchEvent(new Event('locationchange'));
return ret;
};
})(history.replaceState);
window.addEventListener('popstate',function() {
window.dispatchEvent(new Event('locationchange'));
});
window.addEventListener('locationchange', function() {
window.webkit.messageHandlers["onNavigationStateChange"].postMessage(JSON.stringify({
url: document.location.href
}));
});
})(window, window.document, window.history);
"""
public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler {
var IABController: InAppBrowserWebViewController?
@ -539,7 +568,12 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
let findTextHighlightJSScript = WKUserScript(source: findTextHighlightJS, injectionTime: .atDocumentStart, forMainFrameOnly: false)
configuration.userContentController.addUserScript(findTextHighlightJSScript)
configuration.userContentController.add(self, name: "findResultReceived")
configuration.userContentController.add(self, name: "onFindResultReceived")
let interceptNavigationStateChangeJSScript = WKUserScript(source: interceptNavigationStateChangeJS, injectionTime: .atDocumentStart, forMainFrameOnly: false)
configuration.userContentController.addUserScript(interceptNavigationStateChangeJSScript)
configuration.userContentController.add(self, name: "onNavigationStateChange")
if (options?.useShouldInterceptAjaxRequest)! {
let interceptAjaxRequestsJSScript = WKUserScript(source: interceptAjaxRequestsJS, injectionTime: .atDocumentStart, forMainFrameOnly: false)
@ -659,7 +693,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
override public func observeValue(forKeyPath keyPath: String?, of object: Any?,
change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
if keyPath == #keyPath(WKWebView.estimatedProgress) {
let progress = Int(estimatedProgress * 100)
onProgressChanged(progress: progress)
}
@ -1595,6 +1629,18 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
}
}
public func onNavigationStateChange(url: String) {
var arguments: [String : Any] = [
"url": url
]
if IABController != nil {
arguments["uuid"] = IABController!.uuid
}
if let channel = getChannel() {
channel.invokeMethod("onNavigationStateChange", arguments: arguments)
}
}
public func onScrollChanged(x: Int, y: Int) {
var arguments: [String: Any] = ["x": x, "y": y]
if IABController != nil {
@ -1800,7 +1846,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
let _callHandlerID = body["_callHandlerID"] as! Int64
let args = body["args"] as! String
onCallJsHandler(handlerName: handlerName, _callHandlerID: _callHandlerID, args: args)
} else if message.name == "findResultReceived" {
} else if message.name == "onFindResultReceived" {
if let resource = convertToDictionary(text: message.body as! String) {
let activeMatchOrdinal = resource["activeMatchOrdinal"] as! Int
let numberOfMatches = resource["numberOfMatches"] as! Int
@ -1808,6 +1854,13 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
self.onFindResultReceived(activeMatchOrdinal: activeMatchOrdinal, numberOfMatches: numberOfMatches, isDoneCounting: isDoneCounting)
}
} else if message.name == "onNavigationStateChange" {
if let resource = convertToDictionary(text: message.body as! String) {
let url = resource["url"] as! String
self.onNavigationStateChange(url: url)
}
}
}

View File

@ -483,6 +483,36 @@ class InAppBrowser {
}
///
Future<AjaxRequest> shouldInterceptAjaxRequest(AjaxRequest ajaxRequest) {
}
///
Future<AjaxRequestAction> onAjaxReadyStateChange(AjaxRequest ajaxRequest) {
}
///
Future<AjaxRequestAction> onAjaxProgress(AjaxRequest ajaxRequest) {
}
///
Future<FetchRequest> shouldInterceptFetchRequest(FetchRequest fetchRequest) {
}
///Event fired when the navigation state of the [InAppWebView] changes throught the usage of
///javascript **[History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API)** functions (`pushState()`, `replaceState()`) and `onpopstate` event.
///
///Also, the event is fired when the javascript `window.location` changes without reloading the webview (for example appending or modifying an hash to the url).
///
///[url] represents the new url.
void onNavigationStateChange(String url) {
}
void throwIsAlreadyOpened({String message = ''}) {
if (this.isOpened()) {
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']);

View File

@ -179,14 +179,22 @@ class InAppWebView extends StatefulWidget {
final Future<AjaxRequest> Function(InAppWebViewController controller, AjaxRequest ajaxRequest) shouldInterceptAjaxRequest;
///
final Future<AjaxRequest> Function(InAppWebViewController controller, AjaxRequest ajaxRequest) onAjaxReadyStateChange;
final Future<AjaxRequestAction> Function(InAppWebViewController controller, AjaxRequest ajaxRequest) onAjaxReadyStateChange;
///
final Future<AjaxRequest> Function(InAppWebViewController controller, AjaxRequest ajaxRequest) onAjaxProgressEvent;
final Future<AjaxRequestAction> Function(InAppWebViewController controller, AjaxRequest ajaxRequest) onAjaxProgress;
///
final Future<FetchRequest> Function(InAppWebViewController controller, FetchRequest fetchRequest) shouldInterceptFetchRequest;
///Event fired when the navigation state of the [InAppWebView] changes throught the usage of
///javascript **[History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API)** functions (`pushState()`, `replaceState()`) and `onpopstate` event.
///
///Also, the event is fired when the javascript `window.location` changes without reloading the webview (for example appending or modifying an hash to the url).
///
///[url] represents the new url.
final void Function(InAppWebViewController controller, String url) onNavigationStateChange;
///Initial url that will be loaded.
final String initialUrl;
///Initial asset file that will be loaded. See [InAppWebView.loadFile()] for explanation.
@ -236,8 +244,9 @@ class InAppWebView extends StatefulWidget {
this.onFindResultReceived,
this.shouldInterceptAjaxRequest,
this.onAjaxReadyStateChange,
this.onAjaxProgressEvent,
this.onAjaxProgress,
this.shouldInterceptFetchRequest,
this.onNavigationStateChange,
this.gestureRecognizers,
}) : super(key: key);
@ -531,6 +540,13 @@ class InAppWebViewController {
else if (_inAppBrowser != null)
_inAppBrowser.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting);
break;
case "onNavigationStateChange":
String url = call.arguments["url"];
if (_widget != null && _widget.onNavigationStateChange != null)
_widget.onNavigationStateChange(this, url);
else if (_inAppBrowser != null)
_inAppBrowser.onNavigationStateChange(url);
break;
case "onCallJsHandler":
String handlerName = call.arguments["handlerName"];
// decode args to json
@ -566,8 +582,8 @@ class InAppWebViewController {
if (_widget != null && _widget.shouldInterceptAjaxRequest != null)
return jsonEncode(await _widget.shouldInterceptAjaxRequest(this, request));
//else if (_inAppBrowser != null)
// return jsonEncode(await _inAppBrowser.shouldInterceptAjaxRequest(request));
else if (_inAppBrowser != null)
return jsonEncode(await _inAppBrowser.shouldInterceptAjaxRequest(request));
return null;
case "onAjaxReadyStateChange":
Map<dynamic, dynamic> argMap = args[0];
@ -593,10 +609,10 @@ class InAppWebViewController {
if (_widget != null && _widget.onAjaxReadyStateChange != null)
return jsonEncode(await _widget.onAjaxReadyStateChange(this, request));
//else if (_inAppBrowser != null)
// return jsonEncode(await _inAppBrowser.onAjaxReadyStateChange(request));
else if (_inAppBrowser != null)
return jsonEncode(await _inAppBrowser.onAjaxReadyStateChange(request));
return null;
case "onAjaxProgressEvent":
case "onAjaxProgress":
Map<dynamic, dynamic> argMap = args[0];
dynamic data = argMap["data"];
String method = argMap["method"];
@ -621,10 +637,10 @@ class InAppWebViewController {
withCredentials: withCredentials, headers: headers, readyState: AjaxRequestReadyState.fromValue(readyState), status: status, responseURL: responseURL,
responseType: responseType, responseText: responseText, statusText: statusText, responseHeaders: responseHeaders, event: event);
if (_widget != null && _widget.onAjaxProgressEvent != null)
return jsonEncode(await _widget.onAjaxProgressEvent(this, request));
//else if (_inAppBrowser != null)
// return jsonEncode(await _inAppBrowser.onAjaxProgressEvent(request));
if (_widget != null && _widget.onAjaxProgress != null)
return jsonEncode(await _widget.onAjaxProgress(this, request));
else if (_inAppBrowser != null)
return jsonEncode(await _inAppBrowser.onAjaxProgress(request));
return null;
case "shouldInterceptFetchRequest":
Map<dynamic, dynamic> argMap = args[0];
@ -646,8 +662,8 @@ class InAppWebViewController {
if (_widget != null && _widget.shouldInterceptFetchRequest != null)
return jsonEncode(await _widget.shouldInterceptFetchRequest(this, request));
//else if (_inAppBrowser != null)
// return jsonEncode(await _inAppBrowser.shouldInterceptFetchRequest(request));
else if (_inAppBrowser != null)
return jsonEncode(await _inAppBrowser.shouldInterceptFetchRequest(request));
return null;
}

View File

@ -702,6 +702,16 @@ class AjaxRequestAction {
static const ABORT = const AjaxRequestAction._internal(0);
static const PROCEED = const AjaxRequestAction._internal(1);
Map<String, dynamic> toMap() {
return {
"action": _value,
};
}
Map<String, dynamic> toJson() {
return this.toMap();
}
}
///