added shouldOverrideUrlLoading method
This commit is contained in:
parent
5978aba78f
commit
aa583ad68a
|
@ -11,11 +11,11 @@
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
|
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
<change beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" />
|
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java" />
|
||||||
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" />
|
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java" />
|
||||||
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/WebViewActivity.java" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" afterPath="$PROJECT_DIR$/example/lib/main.dart" />
|
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" afterPath="$PROJECT_DIR$/example/lib/main.dart" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserOptions.swift" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserOptions.swift" />
|
||||||
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" />
|
<change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" />
|
||||||
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" />
|
<change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" />
|
||||||
<change beforePath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" afterPath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
|
<change beforePath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" afterPath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
|
||||||
|
@ -38,8 +38,8 @@
|
||||||
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
|
<file leaf-file-name="flutter_inappbrowser.dart" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="570">
|
<state relative-caret-position="397">
|
||||||
<caret line="213" column="67" lean-forward="false" selection-start-line="213" selection-start-column="67" selection-end-line="213" selection-end-column="67" />
|
<caret line="53" column="36" lean-forward="false" selection-start-line="53" selection-start-column="12" selection-end-line="53" selection-end-column="36" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#814#834#0" expanded="true" />
|
<element signature="e#814#834#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -50,8 +50,8 @@
|
||||||
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
|
<file leaf-file-name="main.dart" pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="330">
|
<state relative-caret-position="523">
|
||||||
<caret line="30" column="6" lean-forward="false" selection-start-line="30" selection-start-column="6" selection-end-line="30" selection-end-column="6" />
|
<caret line="95" column="12" lean-forward="false" selection-start-line="95" selection-start-column="12" selection-end-line="95" selection-end-column="12" />
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -139,8 +139,8 @@
|
||||||
<option value="$PROJECT_DIR$/android/build.gradle" />
|
<option value="$PROJECT_DIR$/android/build.gradle" />
|
||||||
<option value="$PROJECT_DIR$/pubspec.yaml" />
|
<option value="$PROJECT_DIR$/pubspec.yaml" />
|
||||||
<option value="$PROJECT_DIR$/README.md" />
|
<option value="$PROJECT_DIR$/README.md" />
|
||||||
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
|
|
||||||
<option value="$PROJECT_DIR$/example/lib/main.dart" />
|
<option value="$PROJECT_DIR$/example/lib/main.dart" />
|
||||||
|
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
@ -176,53 +176,6 @@
|
||||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
||||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
||||||
</path>
|
</path>
|
||||||
<path>
|
|
||||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
|
||||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="android" type="462c0819:PsiDirectoryNode" />
|
|
||||||
</path>
|
|
||||||
<path>
|
|
||||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
|
||||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="android" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="main" 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="android" 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="android" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="app" 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="android" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name=".gradle" type="462c0819:PsiDirectoryNode" />
|
|
||||||
</path>
|
|
||||||
<path>
|
|
||||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
|
||||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="ios" type="462c0819:PsiDirectoryNode" />
|
|
||||||
</path>
|
|
||||||
<path>
|
|
||||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
|
||||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="ios" type="462c0819:PsiDirectoryNode" />
|
|
||||||
<item name="Classes" type="462c0819:PsiDirectoryNode" />
|
|
||||||
</path>
|
|
||||||
<path>
|
<path>
|
||||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
||||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
||||||
|
@ -444,7 +397,7 @@
|
||||||
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.36208734" sideWeight="0.4973545" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.36208734" sideWeight="0.4973545" order="2" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
|
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Terminal" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3258786" sideWeight="0.4973545" order="10" side_tool="false" content_ui="tabs" />
|
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3258786" sideWeight="0.4973545" order="10" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Captures" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32936507" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
<window_info id="Captures" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32936507" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.17798743" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.17798743" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||||
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3290735" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3290735" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
|
@ -862,8 +815,8 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="570">
|
<state relative-caret-position="397">
|
||||||
<caret line="213" column="67" lean-forward="false" selection-start-line="213" selection-start-column="67" selection-end-line="213" selection-end-column="67" />
|
<caret line="53" column="36" lean-forward="false" selection-start-line="53" selection-start-column="12" selection-end-line="53" selection-end-column="36" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#814#834#0" expanded="true" />
|
<element signature="e#814#834#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
|
@ -872,8 +825,8 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="330">
|
<state relative-caret-position="523">
|
||||||
<caret line="30" column="6" lean-forward="false" selection-start-line="30" selection-start-column="6" selection-end-line="30" selection-end-column="6" />
|
<caret line="95" column="12" lean-forward="false" selection-start-line="95" selection-start-column="12" selection-end-line="95" selection-end-column="12" />
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -78,7 +78,6 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
|
||||||
channel.setMethodCallHandler(new InAppBrowserFlutterPlugin(registrar, registrar.activity()));
|
channel.setMethodCallHandler(new InAppBrowserFlutterPlugin(registrar, registrar.activity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
||||||
@Override
|
@Override
|
||||||
public void onMethodCall(MethodCall call, final Result result) {
|
public void onMethodCall(MethodCall call, final Result result) {
|
||||||
String source;
|
String source;
|
||||||
|
@ -443,7 +442,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
Map<String, Object> obj = new HashMap<>();
|
Map<String, Object> obj = new HashMap<>();
|
||||||
channel.invokeMethod("exit", obj);
|
channel.invokeMethod("onExit", obj);
|
||||||
|
|
||||||
// The JS protects against multiple calls, so this should happen only when
|
// The JS protects against multiple calls, so this should happen only when
|
||||||
// close() is called by other native code.
|
// close() is called by other native code.
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class InAppBrowserOptions {
|
||||||
boolean domStorageEnabled = true;
|
boolean domStorageEnabled = true;
|
||||||
boolean useWideViewPort = true;
|
boolean useWideViewPort = true;
|
||||||
boolean safeBrowsingEnabled = true;
|
boolean safeBrowsingEnabled = true;
|
||||||
|
boolean useShouldOverrideUrlLoading = false;
|
||||||
|
|
||||||
public void parse(HashMap<String, Object> options) {
|
public void parse(HashMap<String, Object> options) {
|
||||||
Iterator it = options.entrySet().iterator();
|
Iterator it = options.entrySet().iterator();
|
||||||
|
|
|
@ -28,7 +28,12 @@ public class InAppBrowserWebViewClient extends WebViewClient {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
|
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
|
||||||
|
|
||||||
//return true;
|
if (activity.options.useShouldOverrideUrlLoading) {
|
||||||
|
Map<String, Object> obj = new HashMap<>();
|
||||||
|
obj.put("url", url);
|
||||||
|
InAppBrowserFlutterPlugin.channel.invokeMethod("shouldOverrideUrlLoading", obj);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (url.startsWith(WebView.SCHEME_TEL)) {
|
if (url.startsWith(WebView.SCHEME_TEL)) {
|
||||||
try {
|
try {
|
||||||
|
@ -81,11 +86,9 @@ public class InAppBrowserWebViewClient extends WebViewClient {
|
||||||
Log.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
|
Log.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return super.shouldOverrideUrlLoading(webView, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return super.shouldOverrideUrlLoading(webView, url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,7 +111,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
Map<String, Object> obj = new HashMap<>();
|
Map<String, Object> obj = new HashMap<>();
|
||||||
obj.put("url", url);
|
obj.put("url", url);
|
||||||
InAppBrowserFlutterPlugin.channel.invokeMethod("loadstart", obj);
|
InAppBrowserFlutterPlugin.channel.invokeMethod("onLoadStart", obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +134,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
Map<String, Object> obj = new HashMap<>();
|
Map<String, Object> obj = new HashMap<>();
|
||||||
obj.put("url", url);
|
obj.put("url", url);
|
||||||
InAppBrowserFlutterPlugin.channel.invokeMethod("loadstop", obj);
|
InAppBrowserFlutterPlugin.channel.invokeMethod("onLoadStop", obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||||
|
@ -143,7 +146,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
|
||||||
obj.put("url", failingUrl);
|
obj.put("url", failingUrl);
|
||||||
obj.put("code", errorCode);
|
obj.put("code", errorCode);
|
||||||
obj.put("message", description);
|
obj.put("message", description);
|
||||||
InAppBrowserFlutterPlugin.channel.invokeMethod("loaderror", obj);
|
InAppBrowserFlutterPlugin.channel.invokeMethod("onLoadError", obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
|
||||||
|
@ -175,7 +178,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
obj.put("message", "SslError: " + message);
|
obj.put("message", "SslError: " + message);
|
||||||
InAppBrowserFlutterPlugin.channel.invokeMethod("loaderror", obj);
|
InAppBrowserFlutterPlugin.channel.invokeMethod("onLoadError", obj);
|
||||||
|
|
||||||
handler.cancel();
|
handler.cancel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,11 @@ class MyInAppBrowser extends InAppBrowser {
|
||||||
print("\n\nBrowser closed!\n\n");
|
print("\n\nBrowser closed!\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void shouldOverrideUrlLoading(String url) {
|
||||||
|
print("\n\n override $url\n\n");
|
||||||
|
this.loadUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyInAppBrowser inAppBrowser = new MyInAppBrowser();
|
MyInAppBrowser inAppBrowser = new MyInAppBrowser();
|
||||||
|
@ -80,8 +85,9 @@ class _MyAppState extends State<MyApp> {
|
||||||
body: new Center(
|
body: new Center(
|
||||||
child: new RaisedButton(onPressed: () {
|
child: new RaisedButton(onPressed: () {
|
||||||
inAppBrowser.open("https://flutter.io/", options: {
|
inAppBrowser.open("https://flutter.io/", options: {
|
||||||
//"hidden": true
|
//"hidden": true,
|
||||||
//"toolbarTopFixedTitle": "Fixed title",
|
//"toolbarTopFixedTitle": "Fixed title",
|
||||||
|
"useShouldOverrideUrlLoading": true
|
||||||
//"hideUrlBar": true,
|
//"hideUrlBar": true,
|
||||||
//"toolbarTop": false,
|
//"toolbarTop": false,
|
||||||
//"toolbarBottom": false
|
//"toolbarBottom": false
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class InAppBrowserOptions: NSObject {
|
||||||
var allowsPictureInPictureMediaPlayback = true
|
var allowsPictureInPictureMediaPlayback = true
|
||||||
var javaScriptCanOpenWindowsAutomatically = false
|
var javaScriptCanOpenWindowsAutomatically = false
|
||||||
var javaScriptEnabled = true
|
var javaScriptEnabled = true
|
||||||
|
var useShouldOverrideUrlLoading = false
|
||||||
|
|
||||||
override init(){
|
override init(){
|
||||||
super.init()
|
super.init()
|
||||||
|
@ -45,7 +46,7 @@ public class InAppBrowserOptions: NSObject {
|
||||||
|
|
||||||
public func parse(options: [String: Any]) {
|
public func parse(options: [String: Any]) {
|
||||||
for (key, value) in options {
|
for (key, value) in options {
|
||||||
if self.value(forKey: key) != nil {
|
if self.responds(to: Selector(key)) {
|
||||||
self.setValue(value, forKey: key)
|
self.setValue(value, forKey: key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,6 +426,12 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
|
||||||
|
|
||||||
let url = navigationAction.request.url
|
let url = navigationAction.request.url
|
||||||
|
|
||||||
|
if (url != nil && navigationAction.navigationType == .linkActivated && (browserOptions?.useShouldOverrideUrlLoading)!) {
|
||||||
|
navigationDelegate?.shouldOverrideUrlLoading(webView, url: url!)
|
||||||
|
decisionHandler(.cancel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if url != nil && (navigationAction.navigationType == .linkActivated || navigationAction.navigationType == .backForward) {
|
if url != nil && (navigationAction.navigationType == .linkActivated || navigationAction.navigationType == .backForward) {
|
||||||
currentURL = url
|
currentURL = url
|
||||||
updateUrlTextField(url: (url?.absoluteString)!)
|
updateUrlTextField(url: (url?.absoluteString)!)
|
||||||
|
@ -477,7 +483,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
|
||||||
spinner.startAnimating()
|
spinner.startAnimating()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (navigationDelegate?.webViewDidStartLoad(webView))!
|
return (navigationDelegate?.onLoadStart(webView))!
|
||||||
}
|
}
|
||||||
|
|
||||||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
||||||
|
@ -487,7 +493,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
|
||||||
backButton.isEnabled = webView.canGoBack
|
backButton.isEnabled = webView.canGoBack
|
||||||
forwardButton.isEnabled = webView.canGoForward
|
forwardButton.isEnabled = webView.canGoForward
|
||||||
spinner.stopAnimating()
|
spinner.stopAnimating()
|
||||||
navigationDelegate?.webViewDidFinishLoad(webView)
|
navigationDelegate?.onLoadStop(webView)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func webView(_ webView: WKWebView,
|
// func webView(_ webView: WKWebView,
|
||||||
|
@ -505,6 +511,6 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
|
||||||
backButton.isEnabled = webView.canGoBack
|
backButton.isEnabled = webView.canGoBack
|
||||||
forwardButton.isEnabled = webView.canGoForward
|
forwardButton.isEnabled = webView.canGoForward
|
||||||
spinner.stopAnimating()
|
spinner.stopAnimating()
|
||||||
navigationDelegate?.webViewDidFailLoadWithError(webView, error: error)
|
navigationDelegate?.onLoadError(webView, error: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,25 +339,29 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
|
||||||
injectDeferredObject(arguments["urlFile"] as! String, withWrapper: jsWrapper, result: result)
|
injectDeferredObject(arguments["urlFile"] as! String, withWrapper: jsWrapper, result: result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func webViewDidStartLoad(_ webView: WKWebView) {
|
func onLoadStart(_ webView: WKWebView) {
|
||||||
let url: String = webViewController!.currentURL!.absoluteString
|
let url: String = webViewController!.currentURL!.absoluteString
|
||||||
channel.invokeMethod("loadstart", arguments: ["url": url])
|
channel.invokeMethod("onLoadStart", arguments: ["url": url])
|
||||||
}
|
}
|
||||||
|
|
||||||
func webViewDidFinishLoad(_ webView: WKWebView) {
|
func onLoadStop(_ webView: WKWebView) {
|
||||||
let url: String = webViewController!.currentURL!.absoluteString
|
let url: String = webViewController!.currentURL!.absoluteString
|
||||||
channel.invokeMethod("loadstop", arguments: ["url": url])
|
channel.invokeMethod("onLoadStop", arguments: ["url": url])
|
||||||
}
|
}
|
||||||
|
|
||||||
func webViewDidFailLoadWithError(_ webView: WKWebView, error: Error) {
|
func onLoadError(_ webView: WKWebView, error: Error) {
|
||||||
let url: String = webViewController!.currentURL!.absoluteString
|
let url: String = webViewController!.currentURL!.absoluteString
|
||||||
let arguments = ["url": url, "code": error._code, "message": error.localizedDescription] as [String : Any]
|
let arguments = ["url": url, "code": error._code, "message": error.localizedDescription] as [String : Any]
|
||||||
channel.invokeMethod("loaderror", arguments: arguments)
|
channel.invokeMethod("onLoadError", arguments: arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldOverrideUrlLoading(_ webView: WKWebView, url: URL) {
|
||||||
|
channel.invokeMethod("shouldOverrideUrlLoading", arguments: ["url": url.absoluteString])
|
||||||
}
|
}
|
||||||
|
|
||||||
func browserExit() {
|
func browserExit() {
|
||||||
|
|
||||||
channel.invokeMethod("exit", arguments: [])
|
channel.invokeMethod("onExit", arguments: [])
|
||||||
|
|
||||||
// Set navigationDelegate to nil to ensure no callbacks are received from it.
|
// Set navigationDelegate to nil to ensure no callbacks are received from it.
|
||||||
webViewController?.navigationDelegate = nil
|
webViewController?.navigationDelegate = nil
|
||||||
|
|
|
@ -34,23 +34,27 @@ class InAppBrowser {
|
||||||
|
|
||||||
Future<dynamic> _handleMethod(MethodCall call) async {
|
Future<dynamic> _handleMethod(MethodCall call) async {
|
||||||
switch(call.method) {
|
switch(call.method) {
|
||||||
case "loadstart":
|
case "onLoadStart":
|
||||||
String url = call.arguments["url"];
|
String url = call.arguments["url"];
|
||||||
onLoadStart(url);
|
onLoadStart(url);
|
||||||
break;
|
break;
|
||||||
case "loadstop":
|
case "onLoadStop":
|
||||||
String url = call.arguments["url"];
|
String url = call.arguments["url"];
|
||||||
onLoadStop(url);
|
onLoadStop(url);
|
||||||
break;
|
break;
|
||||||
case "loaderror":
|
case "onLoadError":
|
||||||
String url = call.arguments["url"];
|
String url = call.arguments["url"];
|
||||||
int code = call.arguments["code"];
|
int code = call.arguments["code"];
|
||||||
String message = call.arguments["message"];
|
String message = call.arguments["message"];
|
||||||
onLoadError(url, code, message);
|
onLoadError(url, code, message);
|
||||||
break;
|
break;
|
||||||
case "exit":
|
case "onExit":
|
||||||
onExit();
|
onExit();
|
||||||
break;
|
break;
|
||||||
|
case "shouldOverrideUrlLoading":
|
||||||
|
String url = call.arguments["url"];
|
||||||
|
shouldOverrideUrlLoading(url);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return new Future.value("");
|
return new Future.value("");
|
||||||
}
|
}
|
||||||
|
@ -226,4 +230,8 @@ class InAppBrowser {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shouldOverrideUrlLoading(String url) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue