added onDownloadStart event, onLoadResourceCustomScheme event and resourceCustomSchemes option, onTargetBlank event and useOnTargetBlank option, code refactoring
This commit is contained in:
parent
5fc1d405d3
commit
49983cfdaf
|
@ -15,17 +15,43 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/example/android/app/src/main/java/com/pichillilorenzo/flutterwebviewexample/MyApplication.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/channel_manager.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/chrome_safari_browser.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/cookie_manager.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/in_app_browser.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/in_app_localhost_server.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/in_app_webview.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/types.dart" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/lib/src/web_history.dart" 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$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/android/src/main/AndroidManifest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/AndroidManifest.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ChromeCustomTabs/ChromeCustomTabsActivity.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/ChromeCustomTabs/ChromeCustomTabsActivity.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/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/InAppBrowserFlutterPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.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/RequestPermissionHandler.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.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$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/Util.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/Util.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/example/android/app/src/main/AndroidManifest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/example/android/app/src/main/AndroidManifest.xml" 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/Runner.xcodeproj/project.pbxproj" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/project.pbxproj" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/example/ios/Runner/AppDelegate.swift" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/AppDelegate.swift" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/example/ios/Runner/Info.plist" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Info.plist" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/example/ios/Runner/Runner-Bridging-Header.h" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Runner-Bridging-Header.h" 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$/example/lib/main.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/main.dart" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/example/lib/webview_example.screen.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/webview_example.screen.dart" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/example/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.yaml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/flutter_inappbrowser.iml" beforeDir="false" afterPath="$PROJECT_DIR$/flutter_inappbrowser.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ios/Classes/FlutterWebViewFactory.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/FlutterWebViewFactory.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$/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.yaml" 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$/lib/flutter_inappbrowser.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" afterDir="false" />
|
||||
</list>
|
||||
<ignored path="$PROJECT_DIR$/.dart_tool/" />
|
||||
<ignored path="$PROJECT_DIR$/.idea/" />
|
||||
|
@ -48,42 +74,63 @@
|
|||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="15">
|
||||
<caret line="1" column="103" selection-start-line="1" selection-start-column="103" selection-end-line="1" selection-end-column="103" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/README.md">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="91" selection-start-line="9" selection-start-column="91" selection-end-line="9" selection-end-column="91" />
|
||||
<folding>
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
</folding>
|
||||
<state relative-caret-position="210">
|
||||
<caret line="14" column="16" selection-start-line="14" selection-start-column="16" selection-end-line="14" selection-end-column="16" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
|
||||
<entry file="file://$PROJECT_DIR$/example/pubspec.yaml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="267">
|
||||
<caret line="57" column="12" selection-start-line="57" selection-start-column="12" selection-end-line="57" selection-end-column="12" />
|
||||
<state relative-caret-position="299">
|
||||
<caret line="21" column="23" selection-start-line="21" selection-start-column="23" selection-end-line="21" selection-end-column="23" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<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="483">
|
||||
<caret line="35" column="55" selection-start-line="35" selection-start-column="55" selection-end-line="35" selection-end-column="55" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="180">
|
||||
<caret line="31" lean-forward="true" selection-start-line="31" selection-end-line="31" />
|
||||
<folding>
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
<element signature="e#0#812#0" />
|
||||
<element signature="e#845#869#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="120">
|
||||
<caret line="8" column="210" selection-start-line="8" selection-start-column="210" selection-end-line="8" selection-end-column="210" />
|
||||
<state relative-caret-position="169">
|
||||
<caret line="22" column="52" lean-forward="true" selection-start-line="22" selection-start-column="52" selection-end-line="22" selection-end-column="52" />
|
||||
<folding>
|
||||
<element signature="e#0#25#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="165">
|
||||
<caret line="11" column="11" lean-forward="true" selection-start-line="11" selection-start-column="11" selection-end-line="11" selection-end-column="11" />
|
||||
<folding>
|
||||
<element signature="e#0#22#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
|
@ -94,47 +141,50 @@
|
|||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Class" />
|
||||
<option value="Dart File" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="FindInProjectRecents">
|
||||
<findStrings>
|
||||
<find>File</find>
|
||||
<find>onExit</find>
|
||||
<find>_handleMethod</find>
|
||||
<find>javaScriptHandlersMap</find>
|
||||
<find>onConsoleM</find>
|
||||
<find>return this</find>
|
||||
<find>return await</find>
|
||||
<find>onCallJsHandler</find>
|
||||
<find>ListenerCallback</find>
|
||||
<find>jsonDecode</find>
|
||||
<find>CallBac</find>
|
||||
<find>dart</find>
|
||||
<find>```</find>
|
||||
<find>JavaScriptHandlerCallback</find>
|
||||
<find>addJavaScriptHandler</find>
|
||||
<find>indexTest</find>
|
||||
<find>removeJavaScriptHandler</find>
|
||||
<find>__safeBrowsingEnabled__</find>
|
||||
<find>__safe</find>
|
||||
<find>__textZoom</find>
|
||||
<find>hidden</find>
|
||||
<find>builtInZoomControls</find>
|
||||
<find>__builtInZoomControls__</find>
|
||||
<find>android.support.v4</find>
|
||||
<find>__transparentBackground__</find>
|
||||
<find>dispose</find>
|
||||
<find>_dispose</find>
|
||||
<find>UIImagePNGRepresentation</find>
|
||||
<find>png</find>
|
||||
<find>cordova</find>
|
||||
<find>onDownloadStart</find>
|
||||
<find>platfor</find>
|
||||
<find>DATAAAAAA</find>
|
||||
<find>defaultTargetPlatform</find>
|
||||
<find>test</find>
|
||||
<find>WebResourceResponse</find>
|
||||
<find>onCUstom</find>
|
||||
<find>CustomSchemeResponse</find>
|
||||
<find>initialUrl</find>
|
||||
<find>InAppBrowser</find>
|
||||
<find>onCustomScheme</find>
|
||||
<find>print</find>
|
||||
<find>onTargetBlank</find>
|
||||
<find>customSchemes</find>
|
||||
<find>customSchemes__</find>
|
||||
<find>toJson</find>
|
||||
<find>onCustom</find>
|
||||
<find>schemes</find>
|
||||
<find>schemes_</find>
|
||||
<find>onDownload</find>
|
||||
<find>resourceCustomSchemes</find>
|
||||
<find>onLoadResourceCustomScheme</find>
|
||||
<find>and return a [Cu</find>
|
||||
<find>encoded in `base64`</find>
|
||||
<find>_</find>
|
||||
<find>_throwIsNotOpened(</find>
|
||||
<find>_throwIsNotOpened</find>
|
||||
<find>_hand</find>
|
||||
<find>_ChannelManager</find>
|
||||
</findStrings>
|
||||
<replaceStrings>
|
||||
<replace>activity.getPreferences(0)</replace>
|
||||
<replace>Log.</replace>
|
||||
<replace>com.pichillilorenzo.flutter_inappbrowser</replace>
|
||||
<replace>flutter_inappbrowser</replace>
|
||||
<replace>throwIsNotOpened</replace>
|
||||
<replace>ChannelManager</replace>
|
||||
</replaceStrings>
|
||||
<dirStrings>
|
||||
<dir>$PROJECT_DIR$/example/android</dir>
|
||||
|
@ -173,25 +223,34 @@
|
|||
<option value="$PROJECT_DIR$/example/assets/page-3.html" />
|
||||
<option value="$PROJECT_DIR$/example/lib/chrome_safari_example.screen.dart" />
|
||||
<option value="$PROJECT_DIR$/example/lib/test.dart" />
|
||||
<option value="$PROJECT_DIR$/example/lib/main.dart" />
|
||||
<option value="$PROJECT_DIR$/example/assets/page-2.html" />
|
||||
<option value="$PROJECT_DIR$/example/assets/page-1.html" />
|
||||
<option value="$PROJECT_DIR$/example/assets/css/style.css" />
|
||||
<option value="$PROJECT_DIR$/lib/flutter_inappbrowser.dart" />
|
||||
<option value="$PROJECT_DIR$/example/pubspec.yaml" />
|
||||
<option value="$PROJECT_DIR$/example/assets/index.html" />
|
||||
<option value="$PROJECT_DIR$/example/lib/webview_example.screen.dart" />
|
||||
<option value="$PROJECT_DIR$/ios/Classes/InAppWebView.swift" />
|
||||
<option value="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" />
|
||||
<option value="$PROJECT_DIR$/pubspec.yaml" />
|
||||
<option value="$PROJECT_DIR$/README.md" />
|
||||
<option value="$PROJECT_DIR$/CHANGELOG.md" />
|
||||
<option value="$PROJECT_DIR$/android/src/main/AndroidManifest.xml" />
|
||||
<option value="$PROJECT_DIR$/pubspec.yaml" />
|
||||
<option value="$PROJECT_DIR$/example/lib/main.dart" />
|
||||
<option value="$PROJECT_DIR$/example/lib/webview_example.screen.dart" />
|
||||
<option value="$PROJECT_DIR$/example/assets/index.html" />
|
||||
<option value="$PROJECT_DIR$/example/lib/inline_example.screen.dart" />
|
||||
<option value="$PROJECT_DIR$/CHANGELOG.md" />
|
||||
<option value="$PROJECT_DIR$/lib/in_app_browser.dart" />
|
||||
<option value="$PROJECT_DIR$/lib/src/web_history.dart" />
|
||||
<option value="$PROJECT_DIR$/lib/src/in_app_localhost_server.dart" />
|
||||
<option value="$PROJECT_DIR$/lib/src/channel_manager.dart" />
|
||||
<option value="$PROJECT_DIR$/lib/src/in_app_webview.dart" />
|
||||
<option value="$PROJECT_DIR$/lib/src/cookie_manager.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$/lib/flutter_inappbrowser.dart" />
|
||||
<option value="$PROJECT_DIR$/lib/src/types.dart" />
|
||||
<option value="$PROJECT_DIR$/example/pubspec.yaml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds" extendedState="6">
|
||||
<component name="ProjectFrameBounds">
|
||||
<option name="y" value="23" />
|
||||
<option name="width" value="1920" />
|
||||
<option name="height" value="1057" />
|
||||
|
@ -202,33 +261,6 @@
|
|||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<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="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="lib" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="PackagesPane" />
|
||||
<pane id="Scope">
|
||||
<subPane subId="Project Files">
|
||||
|
@ -270,6 +302,39 @@
|
|||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<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="lib" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="lib" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="lib" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="src" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
|
@ -289,6 +354,13 @@
|
|||
<property name="show.migrate.to.gradle.popup" value="false" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/lib/src" />
|
||||
<recent name="$PROJECT_DIR$/lib/in_app_browser.dart" />
|
||||
<recent name="$PROJECT_DIR$/lib" />
|
||||
<recent name="$PROJECT_DIR$/example/assets/images" />
|
||||
<recent name="$PROJECT_DIR$/android/src/main/java" />
|
||||
</key>
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$" />
|
||||
<recent name="$PROJECT_DIR$/example" />
|
||||
|
@ -296,10 +368,6 @@
|
|||
<recent name="$PROJECT_DIR$/example/assets/images" />
|
||||
<recent name="$PROJECT_DIR$/android/libs" />
|
||||
</key>
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/example/assets/images" />
|
||||
<recent name="$PROJECT_DIR$/android/src/main/java" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
|
@ -420,8 +488,8 @@
|
|||
<frame x="0" y="23" width="1920" height="1057" extended-state="6" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.6114754" visible="true" weight="0.15867944" />
|
||||
<window_info id="Structure" order="1" sideWeight="0.3885246" side_tool="true" visible="true" weight="0.15867944" />
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.60991734" visible="true" weight="0.15867944" />
|
||||
<window_info id="Structure" order="1" sideWeight="0.39008266" side_tool="true" visible="true" weight="0.15867944" />
|
||||
<window_info id="Designer" order="2" />
|
||||
<window_info id="Build Variants" order="3" side_tool="true" />
|
||||
<window_info id="Captures" order="4" side_tool="true" weight="0.32936507" />
|
||||
|
@ -430,18 +498,18 @@
|
|||
<window_info id="Image Layers" order="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.32745314" />
|
||||
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49478307" visible="true" weight="0.36787564" />
|
||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.34288746" />
|
||||
<window_info anchor="bottom" id="Find" order="1" weight="0.32642487" />
|
||||
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49478307" visible="true" weight="0.373057" />
|
||||
<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" />
|
||||
<window_info anchor="bottom" id="TODO" order="6" weight="0.3284974" />
|
||||
<window_info anchor="bottom" id="Android Profiler" order="7" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Event Log" order="8" sideWeight="0.5052169" side_tool="true" weight="0.34068358" />
|
||||
<window_info anchor="bottom" id="Version Control" order="9" />
|
||||
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.49533224" weight="0.2911917" />
|
||||
<window_info anchor="bottom" id="Version Control" order="9" weight="0.32953367" />
|
||||
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.49533224" weight="0.34404144" />
|
||||
<window_info anchor="bottom" id="Logcat" order="11" weight="0.32953367" />
|
||||
<window_info anchor="bottom" id="Messages" order="12" visible="true" weight="0.226943" />
|
||||
<window_info anchor="bottom" id="Messages" order="12" weight="0.226943" />
|
||||
<window_info anchor="bottom" id="Dependency Viewer" order="13" weight="0.32800853" />
|
||||
<window_info anchor="bottom" id="Dart Analysis" order="14" weight="0.3253886" />
|
||||
<window_info anchor="bottom" id="Flutter Performance" order="15" side_tool="true" />
|
||||
|
@ -467,37 +535,6 @@
|
|||
</ignored-roots>
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/example/ios/Pods/Target Support Files/flutter_inappbrowser/flutter_inappbrowser-dummy.m">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/ios/Pods/Target Support Files/flutter_inappbrowser/flutter_inappbrowser.xcconfig">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/ios/Pods/Target Support Files/flutter_inappbrowser/flutter_inappbrowser-umbrella.h">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/ios/Pods/Target Support Files/flutter_inappbrowser/Info.plist" />
|
||||
<entry file="file://$PROJECT_DIR$/example/ios/Flutter/Generated.xcconfig">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="105">
|
||||
<caret line="7" column="69" selection-start-line="7" selection-start-column="69" selection-end-line="7" selection-end-column="69" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/README.md" />
|
||||
<entry file="file://$PROJECT_DIR$/pubspec.lock">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-1555">
|
||||
<caret line="2" selection-start-line="2" selection-end-line="2" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/android/local.properties">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/android/gradle/wrapper/gradle-wrapper.properties">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="75">
|
||||
|
@ -559,13 +596,6 @@
|
|||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/build/app/intermediates/incremental/mergeDebugResources/merged.dir/values-v28/values-v28.xml" />
|
||||
<entry file="file://$PROJECT_DIR$/example/android/app/build.gradle">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="603">
|
||||
<caret line="64" column="74" selection-start-line="64" selection-start-column="74" selection-end-line="64" selection-end-column="74" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/android/gradle.properties">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="45">
|
||||
|
@ -580,13 +610,6 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/android/build.gradle">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="13" column="16" selection-start-line="13" selection-start-column="16" selection-end-line="13" selection-end-column="16" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/chrome_safari_example.screen.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="435">
|
||||
|
@ -646,40 +669,6 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="495">
|
||||
<caret line="38" column="18" selection-start-line="38" selection-start-column="18" selection-end-line="38" selection-end-column="18" />
|
||||
<folding>
|
||||
<element signature="e#0#20#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="9990">
|
||||
<caret line="697" column="20" selection-start-line="697" selection-start-column="20" selection-end-line="697" selection-end-column="20" />
|
||||
<folding>
|
||||
<element signature="e#814#831#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/pubspec.yaml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="239">
|
||||
<caret line="17" selection-start-line="17" selection-end-line="17" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="15">
|
||||
<caret line="12" column="4" selection-start-line="12" selection-start-column="4" selection-end-line="54" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/assets/css/style.css">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="435">
|
||||
|
@ -687,13 +676,6 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/webview_example.screen.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="553">
|
||||
<caret line="92" column="44" selection-start-line="92" selection-start-column="44" selection-end-line="92" selection-end-column="44" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/ios/Runner/Base.lproj/Main.storyboard">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
|
@ -711,31 +693,6 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/README.md">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="91" selection-start-line="9" selection-start-column="91" selection-end-line="9" selection-end-column="91" />
|
||||
<folding>
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="15">
|
||||
<caret line="1" column="103" selection-start-line="1" selection-start-column="103" selection-end-line="1" selection-end-column="103" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="120">
|
||||
<caret line="8" column="210" selection-start-line="8" selection-start-column="210" selection-end-line="8" selection-end-column="210" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/android/src/main/AndroidManifest.xml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="180">
|
||||
|
@ -743,16 +700,182 @@
|
|||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
|
||||
<entry file="file://$PROJECT_DIR$/example/android/app/src/main/java/com/pichillilorenzo/flutterwebviewexample/MainActivity.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="267">
|
||||
<caret line="57" column="12" selection-start-line="57" selection-start-column="12" selection-end-line="57" selection-end-column="12" />
|
||||
<state relative-caret-position="60">
|
||||
<caret line="6" column="13" selection-start-line="6" selection-start-column="13" selection-end-line="6" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/android/app/build.gradle">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="960">
|
||||
<caret line="64" column="74" selection-start-line="64" selection-start-column="74" selection-end-line="64" selection-end-column="74" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/android/build.gradle">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="195">
|
||||
<caret line="13" column="16" selection-start-line="13" selection-start-column="16" selection-end-line="13" selection-end-column="16" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/README.md">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="91" selection-start-line="9" selection-start-column="91" selection-end-line="9" selection-end-column="91" />
|
||||
<folding>
|
||||
<element signature="e#0#20#0" expanded="true" />
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
<element signature="e#0#39#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="465">
|
||||
<caret line="31" column="11" selection-start-line="31" selection-start-column="11" selection-end-line="31" selection-end-column="11" />
|
||||
<folding>
|
||||
<element signature="e#0#20#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/webview_example.screen.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-1100">
|
||||
<caret line="3" column="64" selection-start-line="3" selection-start-column="64" selection-end-line="3" selection-end-column="64" />
|
||||
<folding>
|
||||
<element signature="e#0#20#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/CHANGELOG.md">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="135">
|
||||
<caret line="9" column="162" selection-start-line="9" selection-start-column="162" selection-end-line="9" selection-end-column="162" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/assets/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="483">
|
||||
<caret line="35" column="55" selection-start-line="35" selection-start-column="55" selection-end-line="35" selection-end-column="55" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/cookie_manager.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="338">
|
||||
<caret line="140" lean-forward="true" selection-start-line="140" selection-end-line="140" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/in_app_localhost_server.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="-741">
|
||||
<caret line="4" column="32" selection-start-line="4" selection-start-column="32" selection-end-line="4" selection-end-column="32" />
|
||||
<folding>
|
||||
<element signature="e#0#17#0" expanded="true" />
|
||||
</folding>
|
||||
</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="702">
|
||||
<caret line="269" column="24" lean-forward="true" selection-start-line="269" selection-start-column="24" selection-end-line="269" selection-end-column="24" />
|
||||
<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>
|
||||
<caret selection-end-line="7" selection-end-column="57" />
|
||||
<folding>
|
||||
<element signature="e#0#20#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/chrome_safari_browser.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="405">
|
||||
<caret line="27" column="25" selection-start-line="27" selection-start-column="25" selection-end-line="27" selection-end-column="25" />
|
||||
<folding>
|
||||
<element signature="e#0#20#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/channel_manager.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="90">
|
||||
<caret line="6" column="20" selection-start-line="6" selection-start-column="6" selection-end-line="6" selection-end-column="20" />
|
||||
<folding>
|
||||
<element signature="e#0#25#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="180">
|
||||
<caret line="31" lean-forward="true" selection-start-line="31" selection-end-line="31" />
|
||||
<folding>
|
||||
<element signature="e#0#812#0" />
|
||||
<element signature="e#845#869#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/web_history.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="105">
|
||||
<caret line="7" column="43" selection-start-line="7" selection-start-column="43" selection-end-line="7" selection-end-column="43" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/lib/src/types.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="169">
|
||||
<caret line="22" column="52" lean-forward="true" selection-start-line="22" selection-start-column="52" selection-end-line="22" selection-end-column="52" />
|
||||
<folding>
|
||||
<element signature="e#0#25#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="165">
|
||||
<caret line="11" column="11" lean-forward="true" selection-start-line="11" selection-start-column="11" selection-end-line="11" selection-end-column="11" />
|
||||
<folding>
|
||||
<element signature="e#0#22#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/pubspec.yaml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="210">
|
||||
<caret line="14" column="16" selection-start-line="14" selection-start-column="16" selection-end-line="14" selection-end-column="16" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/example/pubspec.yaml">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="299">
|
||||
<caret line="21" column="23" selection-start-line="21" selection-start-column="23" selection-end-line="21" selection-end-column="23" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
|
|
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,13 +1,17 @@
|
|||
## 1.3.0
|
||||
|
||||
- Merge
|
||||
- Merge
|
||||
- Merge
|
||||
- Merge
|
||||
- Merge
|
||||
- Merge
|
||||
- Merge "Avoid null pointer exception after webview is disposed" [#116](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/116) (thanks to [robsonfingo](https://github.com/robsonfingo))
|
||||
- Merge "Remove async call in close" [#119](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/119) (thanks to [benfingo](https://github.com/benfingo))
|
||||
- Merge "Android takeScreenshot does not work properly." [#122](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/122) (thanks to [PauloMelo](https://github.com/PauloMelo))
|
||||
- Merge "Resolving gradle error." [#144](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/144) (thanks to [Klingens13](https://github.com/Klingens13))
|
||||
- Merge "Create issue and pull request templates" [#150](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/150) (thanks to [deandreamatias](https://github.com/deandreamatias))
|
||||
- Merge "Fix abstract method error && swift version error" [#155](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/155) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
|
||||
- Merge "migrating to swift 5.0" [#162](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/162) (thanks to [fattiger00](https://github.com/fattiger00))
|
||||
- Merge "Update readme example" [#178](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/178) (thanks to [SebastienBtr](https://github.com/SebastienBtr))
|
||||
- Added `horizontalScrollBarEnabled` and `verticalScrollBarEnabled` options to enable/disable the corresponding scrollbar of the WebView [#165](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/165)
|
||||
|
||||
- Added `onDownloadStart` event: event fires when the WebView recognizes and starts a downloadable file.
|
||||
- Added `onLoadResourceCustomScheme` event and `resourceCustomSchemes` option to set custom schemes that WebView must handle to load resources
|
||||
- Added `onTargetBlank` event and `useOnTargetBlank` option to manage links with `target="_blank"`
|
||||
|
||||
## 1.2.1
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public class ChromeCustomTabsActivity extends Activity {
|
|||
options = new ChromeCustomTabsOptions();
|
||||
options.parse((HashMap<String, Object>) b.getSerializable("options"));
|
||||
|
||||
InAppBrowserFlutterPlugin.chromeCustomTabsActivities.put(uuid, this);
|
||||
InAppBrowserFlutterPlugin.instance.chromeCustomTabsActivities.put(uuid, this);
|
||||
|
||||
customTabActivityHelper = new CustomTabActivityHelper();
|
||||
builder = new CustomTabsIntent.Builder();
|
||||
|
@ -49,8 +49,8 @@ public class ChromeCustomTabsActivity extends Activity {
|
|||
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
obj.put("uuid", uuid);
|
||||
InAppBrowserFlutterPlugin.channel.invokeMethod("onChromeSafariBrowserOpened", obj);
|
||||
InAppBrowserFlutterPlugin.channel.invokeMethod("onChromeSafariBrowserLoaded", obj);
|
||||
InAppBrowserFlutterPlugin.instance.channel.invokeMethod("onChromeSafariBrowserOpened", obj);
|
||||
InAppBrowserFlutterPlugin.instance.channel.invokeMethod("onChromeSafariBrowserLoaded", obj);
|
||||
}
|
||||
|
||||
private void prepareCustomTabs() {
|
||||
|
@ -86,7 +86,7 @@ public class ChromeCustomTabsActivity extends Activity {
|
|||
finish();
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
obj.put("uuid", uuid);
|
||||
InAppBrowserFlutterPlugin.channel.invokeMethod("onChromeSafariBrowserClosed", obj);
|
||||
InAppBrowserFlutterPlugin.instance.channel.invokeMethod("onChromeSafariBrowserClosed", obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.pichillilorenzo.flutter_inappbrowser.InAppWebView.InAppWebViewOptions
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodCall;
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.pichillilorenzo.flutter_inappbrowser.InAppWebView.InAppWebViewOptions
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -67,7 +68,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
|
|||
webViewOptions.parse(optionsMap);
|
||||
webView.options = webViewOptions;
|
||||
|
||||
InAppBrowserFlutterPlugin.webViewActivities.put(uuid, this);
|
||||
InAppBrowserFlutterPlugin.instance.webViewActivities.put(uuid, this);
|
||||
|
||||
actionBar = getSupportActionBar();
|
||||
|
||||
|
@ -89,7 +90,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
|
|||
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
obj.put("uuid", uuid);
|
||||
InAppBrowserFlutterPlugin.channel.invokeMethod("onBrowserCreated", obj);
|
||||
InAppBrowserFlutterPlugin.instance.channel.invokeMethod("onBrowserCreated", obj);
|
||||
|
||||
}
|
||||
|
||||
|
@ -253,7 +254,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
|
|||
if (canGoBack())
|
||||
goBack();
|
||||
else if (options.closeOnCannotGoBack)
|
||||
InAppBrowserFlutterPlugin.close(this, uuid, null);
|
||||
InAppBrowserFlutterPlugin.instance.close(this, uuid, null);
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
|
@ -352,7 +353,7 @@ public class InAppBrowserActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public void closeButtonClicked(MenuItem item) {
|
||||
InAppBrowserFlutterPlugin.close(this, uuid, null);
|
||||
InAppBrowserFlutterPlugin.instance.close(this, uuid, null);
|
||||
}
|
||||
|
||||
public byte[] takeScreenshot() {
|
||||
|
|
|
@ -57,16 +57,18 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
|
|||
*/
|
||||
public class InAppBrowserFlutterPlugin implements MethodCallHandler {
|
||||
|
||||
public static InAppBrowserFlutterPlugin instance;
|
||||
public Registrar registrar;
|
||||
public static MethodChannel channel;
|
||||
public static Map<String, InAppBrowserActivity> webViewActivities = new HashMap<>();
|
||||
public static Map<String, ChromeCustomTabsActivity> chromeCustomTabsActivities = new HashMap<>();
|
||||
public MethodChannel channel;
|
||||
public Map<String, InAppBrowserActivity> webViewActivities = new HashMap<>();
|
||||
public Map<String, ChromeCustomTabsActivity> chromeCustomTabsActivities = new HashMap<>();
|
||||
|
||||
protected static final String LOG_TAG = "IABFlutterPlugin";
|
||||
|
||||
public InAppBrowserFlutterPlugin(Registrar r) {
|
||||
registrar = r;
|
||||
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser");
|
||||
channel.setMethodCallHandler(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,8 +79,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
|
|||
// registrar.activity() may return null because of Flutter's background execution feature
|
||||
// described here: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124
|
||||
if (activity != null) {
|
||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser");
|
||||
channel.setMethodCallHandler(new InAppBrowserFlutterPlugin(registrar));
|
||||
instance = new InAppBrowserFlutterPlugin(registrar);
|
||||
|
||||
new MyCookieManager(registrar);
|
||||
|
||||
|
@ -599,7 +600,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void close(Activity activity, final String uuid, final Result result) {
|
||||
public void close(Activity activity, final String uuid, final Result result) {
|
||||
final InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
|
||||
if (inAppBrowserActivity != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.BitmapFactory;
|
|||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.ValueCallback;
|
||||
|
@ -84,6 +85,19 @@ public class InAppWebChromeClient extends WebChromeClient {
|
|||
decorView.setSystemUiVisibility(3846 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
|
||||
{
|
||||
WebView.HitTestResult result = view.getHitTestResult();
|
||||
String data = result.getExtra();
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
if (inAppBrowserActivity != null)
|
||||
obj.put("uuid", inAppBrowserActivity.uuid);
|
||||
obj.put("url", data);
|
||||
getChannel().invokeMethod("onTargetBlank", obj);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
|
@ -190,6 +204,6 @@ public class InAppWebChromeClient extends WebChromeClient {
|
|||
}
|
||||
|
||||
private MethodChannel getChannel() {
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.channel : flutterWebView.channel;
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.instance.channel : flutterWebView.channel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,25 +2,17 @@ package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
|
|||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Picture;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonToken;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.DownloadListener;
|
||||
import android.webkit.URLUtil;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebBackForwardList;
|
||||
import android.webkit.WebHistoryItem;
|
||||
|
@ -47,8 +39,6 @@ import io.flutter.plugin.common.PluginRegistry;
|
|||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import static android.content.Context.DOWNLOAD_SERVICE;
|
||||
|
||||
public class InAppWebView extends WebView {
|
||||
|
||||
static final String LOG_TAG = "InAppWebView";
|
||||
|
@ -56,7 +46,7 @@ public class InAppWebView extends WebView {
|
|||
public PluginRegistry.Registrar registrar;
|
||||
public InAppBrowserActivity inAppBrowserActivity;
|
||||
public FlutterWebView flutterWebView;
|
||||
int id;
|
||||
public int id;
|
||||
InAppWebViewClient inAppWebViewClient;
|
||||
InAppWebChromeClient inAppWebChromeClient;
|
||||
public InAppWebViewOptions options;
|
||||
|
@ -137,39 +127,19 @@ public class InAppWebView extends WebView {
|
|||
inAppWebViewClient = new InAppWebViewClient((isFromInAppBrowserActivity) ? inAppBrowserActivity : flutterWebView);
|
||||
setWebViewClient(inAppWebViewClient);
|
||||
|
||||
activity.registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
|
||||
|
||||
setDownloadListener(new DownloadListener() {
|
||||
@Override
|
||||
public void onDownloadStart(final String url, final String userAgent,
|
||||
final String contentDisposition, final String mimetype,
|
||||
final long contentLength) {
|
||||
|
||||
RequestPermissionHandler.checkAndRun(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, RequestPermissionHandler.REQUEST_CODE_WRITE_EXTERNAL_STORAGE, new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
|
||||
Log.e(LOG_TAG, url);
|
||||
Log.e(LOG_TAG, contentDisposition);
|
||||
Log.e(LOG_TAG, mimetype);
|
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||
|
||||
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
|
||||
request.allowScanningByMediaScanner();
|
||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
|
||||
request.setVisibleInDownloadsUi(true);
|
||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
|
||||
DownloadManager dm = (DownloadManager) activity.getSystemService(DOWNLOAD_SERVICE);
|
||||
if (dm != null) {
|
||||
dm.enqueue(request);
|
||||
//Toast.makeText(getApplicationContext(), "Downloading File: " + filename, //To notify the Client that the file is being downloaded
|
||||
// Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
//Toast.makeText(getApplicationContext(), "Cannot Download File: " + filename, //To notify the Client that the file cannot be downloaded
|
||||
// Toast.LENGTH_LONG).show();
|
||||
}
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
if (inAppBrowserActivity != null)
|
||||
obj.put("uuid", inAppBrowserActivity.uuid);
|
||||
obj.put("url", url);
|
||||
getChannel().invokeMethod("onDownloadStart", obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -181,6 +151,7 @@ public class InAppWebView extends WebView {
|
|||
settings.setJavaScriptCanOpenWindowsAutomatically(options.javaScriptCanOpenWindowsAutomatically);
|
||||
settings.setBuiltInZoomControls(options.builtInZoomControls);
|
||||
settings.setDisplayZoomControls(options.displayZoomControls);
|
||||
settings.setSupportMultipleWindows(options.useOnTargetBlank);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
settings.setSafeBrowsingEnabled(options.safeBrowsingEnabled);
|
||||
|
@ -215,30 +186,21 @@ public class InAppWebView extends WebView {
|
|||
|
||||
if (!options.mixedContentMode.isEmpty()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (options.mixedContentMode.equals("MIXED_CONTENT_COMPATIBILITY_MODE")) {
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
|
||||
} else if (options.mixedContentMode.equals("MIXED_CONTENT_ALWAYS_ALLOW")) {
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
} else if (options.mixedContentMode.equals("MIXED_CONTENT_NEVER_ALLOW")) {
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
|
||||
switch (options.mixedContentMode) {
|
||||
case "MIXED_CONTENT_COMPATIBILITY_MODE":
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
|
||||
break;
|
||||
case "MIXED_CONTENT_ALWAYS_ALLOW":
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
break;
|
||||
case "MIXED_CONTENT_NEVER_ALLOW":
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver onDownloadComplete = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
//Fetching the download id received with the broadcast
|
||||
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
|
||||
//Checking if the received broadcast is for our enqueued download by matching download id
|
||||
if (1 == id) { // test
|
||||
//if (downloadID == id) {
|
||||
//Toast.makeText(MainActivity.this, "Download Completed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void loadUrl(String url, MethodChannel.Result result) {
|
||||
if (!url.isEmpty()) {
|
||||
loadUrl(url);
|
||||
|
@ -332,7 +294,7 @@ public class InAppWebView extends WebView {
|
|||
}
|
||||
|
||||
public byte[] takeScreenshot() {
|
||||
float scale = getScale();
|
||||
float scale = getResources().getDisplayMetrics().density; // getScale();
|
||||
int height = (int) (getContentHeight() * scale + 0.5);
|
||||
|
||||
Bitmap b = Bitmap.createBitmap( getWidth(),
|
||||
|
@ -384,7 +346,7 @@ public class InAppWebView extends WebView {
|
|||
if (newOptionsMap.get("domStorageEnabled") != null && options.domStorageEnabled != newOptions.domStorageEnabled)
|
||||
settings.setDomStorageEnabled(newOptions.domStorageEnabled);
|
||||
|
||||
if (newOptionsMap.get("userAgent") != null && options.userAgent != newOptions.userAgent && !newOptions.userAgent.isEmpty())
|
||||
if (newOptionsMap.get("userAgent") != null && !options.userAgent.equals(newOptions.userAgent) && !newOptions.userAgent.isEmpty())
|
||||
settings.setUserAgentString(newOptions.userAgent);
|
||||
|
||||
if (newOptionsMap.get("clearCache") != null && newOptions.clearCache)
|
||||
|
@ -415,18 +377,25 @@ public class InAppWebView extends WebView {
|
|||
}
|
||||
}
|
||||
|
||||
if (newOptionsMap.get("mixedContentMode") != null && options.mixedContentMode != newOptions.mixedContentMode) {
|
||||
if (newOptionsMap.get("mixedContentMode") != null && !options.mixedContentMode.equals(newOptions.mixedContentMode)) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (newOptions.mixedContentMode.equals("MIXED_CONTENT_COMPATIBILITY_MODE")) {
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
|
||||
} else if (newOptions.mixedContentMode.equals("MIXED_CONTENT_ALWAYS_ALLOW")) {
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
} else if (newOptions.mixedContentMode.equals("MIXED_CONTENT_NEVER_ALLOW")) {
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
|
||||
switch (newOptions.mixedContentMode) {
|
||||
case "MIXED_CONTENT_COMPATIBILITY_MODE":
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
|
||||
break;
|
||||
case "MIXED_CONTENT_ALWAYS_ALLOW":
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||
break;
|
||||
case "MIXED_CONTENT_NEVER_ALLOW":
|
||||
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newOptionsMap.get("useOnTargetBlank") != null && options.useOnTargetBlank != newOptions.useOnTargetBlank)
|
||||
settings.setSupportMultipleWindows(newOptions.useOnTargetBlank);
|
||||
|
||||
options = newOptions;
|
||||
}
|
||||
|
||||
|
@ -562,13 +531,11 @@ public class InAppWebView extends WebView {
|
|||
}
|
||||
|
||||
private MethodChannel getChannel() {
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.channel : flutterWebView.channel;
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.instance.channel : flutterWebView.channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
final Activity activity = (inAppBrowserActivity != null) ? inAppBrowserActivity : registrar.activity();
|
||||
activity.unregisterReceiver(onDownloadComplete);
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import androidx.annotation.RequiresApi;
|
|||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
|
@ -24,6 +25,7 @@ import com.pichillilorenzo.flutter_inappbrowser.FlutterWebView;
|
|||
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserActivity;
|
||||
import com.pichillilorenzo.flutter_inappbrowser.InAppBrowserFlutterPlugin;
|
||||
import com.pichillilorenzo.flutter_inappbrowser.JavaScriptBridgeInterface;
|
||||
import com.pichillilorenzo.flutter_inappbrowser.Util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -116,54 +118,56 @@ public class InAppWebViewClient extends WebViewClient {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (url.startsWith(WebView.SCHEME_TEL)) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse(url));
|
||||
((inAppBrowserActivity != null) ? inAppBrowserActivity : flutterWebView.activity).startActivity(intent);
|
||||
return true;
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
|
||||
if (url != null) {
|
||||
if (url.startsWith(WebView.SCHEME_TEL)) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse(url));
|
||||
((inAppBrowserActivity != null) ? inAppBrowserActivity : flutterWebView.activity).startActivity(intent);
|
||||
return true;
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
|
||||
}
|
||||
} else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:") || url.startsWith("intent:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
((inAppBrowserActivity != null) ? inAppBrowserActivity : flutterWebView.activity).startActivity(intent);
|
||||
return true;
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Error with " + url + ": " + e.toString());
|
||||
}
|
||||
}
|
||||
} else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:") || url.startsWith("intent:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
((inAppBrowserActivity != null) ? inAppBrowserActivity : flutterWebView.activity).startActivity(intent);
|
||||
return true;
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Error with " + url + ": " + e.toString());
|
||||
}
|
||||
}
|
||||
// If sms:5551212?body=This is the message
|
||||
else if (url.startsWith("sms:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
// If sms:5551212?body=This is the message
|
||||
else if (url.startsWith("sms:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
|
||||
// Get address
|
||||
String address;
|
||||
int parmIndex = url.indexOf('?');
|
||||
if (parmIndex == -1) {
|
||||
address = url.substring(4);
|
||||
} else {
|
||||
address = url.substring(4, parmIndex);
|
||||
// Get address
|
||||
String address;
|
||||
int parmIndex = url.indexOf('?');
|
||||
if (parmIndex == -1) {
|
||||
address = url.substring(4);
|
||||
} else {
|
||||
address = url.substring(4, parmIndex);
|
||||
|
||||
// If body, then set sms body
|
||||
Uri uri = Uri.parse(url);
|
||||
String query = uri.getQuery();
|
||||
if (query != null) {
|
||||
if (query.startsWith("body=")) {
|
||||
intent.putExtra("sms_body", query.substring(5));
|
||||
// If body, then set sms body
|
||||
Uri uri = Uri.parse(url);
|
||||
String query = uri.getQuery();
|
||||
if (query != null) {
|
||||
if (query.startsWith("body=")) {
|
||||
intent.putExtra("sms_body", query.substring(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
intent.setData(Uri.parse("sms:" + address));
|
||||
intent.putExtra("address", address);
|
||||
intent.setType("vnd.android-dir/mms-sms");
|
||||
((inAppBrowserActivity != null) ? inAppBrowserActivity : flutterWebView.activity).startActivity(intent);
|
||||
return true;
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
|
||||
}
|
||||
intent.setData(Uri.parse("sms:" + address));
|
||||
intent.putExtra("address", address);
|
||||
intent.setType("vnd.android-dir/mms-sms");
|
||||
((inAppBrowserActivity != null) ? inAppBrowserActivity : flutterWebView.activity).startActivity(intent);
|
||||
return true;
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,13 +304,36 @@ public class InAppWebViewClient extends WebViewClient {
|
|||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
|
||||
InAppWebView webView = (InAppWebView) view;
|
||||
|
||||
final String url = request.getUrl().toString();
|
||||
String scheme = request.getUrl().getScheme();
|
||||
|
||||
if (webView.options.resourceCustomSchemes != null && webView.options.resourceCustomSchemes.contains(scheme)) {
|
||||
final Map<String, Object> obj = new HashMap<>();
|
||||
if (inAppBrowserActivity != null)
|
||||
obj.put("uuid", inAppBrowserActivity.uuid);
|
||||
obj.put("url", url);
|
||||
obj.put("scheme", scheme);
|
||||
|
||||
Util.WaitFlutterResult flutterResult = Util.invokeMethodAndWait(getChannel(), "onLoadResourceCustomScheme", obj);
|
||||
|
||||
if (flutterResult.error != null) {
|
||||
Log.d(LOG_TAG, flutterResult.error);
|
||||
}
|
||||
else if (flutterResult.result != null) {
|
||||
Map<String, String> res = (Map<String, String>) flutterResult.result;
|
||||
byte[] data = Base64.decode(res.get("base64data"), Base64.DEFAULT);
|
||||
return new WebResourceResponse(res.get("content-type"), res.get("content-encoding"), new ByteArrayInputStream(data));
|
||||
}
|
||||
}
|
||||
|
||||
if (!request.getMethod().toLowerCase().equals("get") ||
|
||||
!(((inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView).options.useOnLoadResource)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String url = request.getUrl().toString();
|
||||
|
||||
try {
|
||||
Request mRequest = new Request.Builder().url(url).build();
|
||||
|
||||
|
@ -399,7 +426,7 @@ public class InAppWebViewClient extends WebViewClient {
|
|||
}
|
||||
|
||||
private MethodChannel getChannel() {
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.channel : flutterWebView.channel;
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.instance.channel : flutterWebView.channel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,16 @@ package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
|
|||
|
||||
import com.pichillilorenzo.flutter_inappbrowser.Options;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InAppWebViewOptions extends Options {
|
||||
|
||||
static final String LOG_TAG = "InAppWebViewOptions";
|
||||
|
||||
public boolean useShouldOverrideUrlLoading = false;
|
||||
public boolean useOnLoadResource = false;
|
||||
public boolean useOnTargetBlank = false;
|
||||
public boolean clearCache = false;
|
||||
public String userAgent = "";
|
||||
public boolean javaScriptEnabled = true;
|
||||
|
@ -16,6 +20,7 @@ public class InAppWebViewOptions extends Options {
|
|||
public int textZoom = 100;
|
||||
public boolean verticalScrollBarEnabled = true;
|
||||
public boolean horizontalScrollBarEnabled = true;
|
||||
public List<String> resourceCustomSchemes = new ArrayList<>();
|
||||
|
||||
public boolean clearSessionCache = false;
|
||||
public boolean builtInZoomControls = false;
|
||||
|
|
|
@ -51,15 +51,17 @@ public class JavaScriptBridgeInterface {
|
|||
getChannel().invokeMethod("onCallJsHandler", obj, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object json) {
|
||||
if (flutterWebView.webView == null) {
|
||||
InAppWebView webView = (inAppBrowserActivity != null) ? inAppBrowserActivity.webView : flutterWebView.webView;
|
||||
|
||||
if (webView == null) {
|
||||
// The webview has already been disposed, ignore.
|
||||
return;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
flutterWebView.webView.evaluateJavascript("window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];", null);
|
||||
webView.evaluateJavascript("window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];", null);
|
||||
}
|
||||
else {
|
||||
flutterWebView.webView.loadUrl("javascript:window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];");
|
||||
webView.loadUrl("javascript:window." + name + "[" + _callHandlerID + "](" + json + "); delete window." + name + "[" + _callHandlerID + "];");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,6 @@ public class JavaScriptBridgeInterface {
|
|||
}
|
||||
|
||||
private MethodChannel getChannel() {
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.channel : flutterWebView.channel;
|
||||
return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.instance.channel : flutterWebView.channel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package com.pichillilorenzo.flutter_inappbrowser;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
import io.flutter.plugin.common.PluginRegistry;
|
||||
|
||||
public class Util {
|
||||
|
@ -37,4 +44,53 @@ public class Util {
|
|||
return ANDROID_ASSET_URL + key;
|
||||
}
|
||||
|
||||
public static WaitFlutterResult invokeMethodAndWait(final MethodChannel channel, final String method, final Object arguments) {
|
||||
final Map<String, Object> flutterResultMap = new HashMap<>();
|
||||
flutterResultMap.put("result", null);
|
||||
flutterResultMap.put("error", null);
|
||||
flutterResultMap.put("isBlocking", true);
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
channel.invokeMethod(method, arguments, new MethodChannel.Result() {
|
||||
@Override
|
||||
public void success(Object result) {
|
||||
flutterResultMap.put("result", result);
|
||||
flutterResultMap.put("isBlocking", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String s, String s1, Object o) {
|
||||
flutterResultMap.put("error", "ERROR: " + s + " " + s1);
|
||||
flutterResultMap.put("result", o);
|
||||
flutterResultMap.put("isBlocking", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notImplemented() {
|
||||
flutterResultMap.put("isBlocking", false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
while((Boolean) flutterResultMap.get("isBlocking")) {
|
||||
// block until flutter side returns
|
||||
}
|
||||
|
||||
return new WaitFlutterResult(flutterResultMap.get("result"), (String) flutterResultMap.get("error"));
|
||||
}
|
||||
|
||||
public static class WaitFlutterResult {
|
||||
public Object result;
|
||||
public String error;
|
||||
|
||||
public WaitFlutterResult(Object r, String e) {
|
||||
result = r;
|
||||
error = e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||
|
@ -13,7 +15,7 @@
|
|||
additional functionality it is fine to subclass or reimplement
|
||||
FlutterApplication and put your custom class here. -->
|
||||
<application
|
||||
android:name="io.flutter.app.FlutterApplication"
|
||||
android:name="com.pichillilorenzo.flutterwebviewexample.MyApplication"
|
||||
android:label="flutter_inappbrowser_example"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
|
@ -35,5 +37,16 @@
|
|||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
|
||||
android:authorities="${applicationId}.flutter_downloader.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths"/>
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.pichillilorenzo.flutterwebviewexample;
|
||||
|
||||
import io.flutter.app.FlutterApplication;
|
||||
import io.flutter.plugin.common.PluginRegistry;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
|
||||
public class MyApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
|
||||
@Override
|
||||
public void registerWith(PluginRegistry registry) {
|
||||
GeneratedPluginRegistrant.registerWith(registry);
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
<main role="main" class="inner cover">
|
||||
<h1 class="cover-heading">Inline WebView</h1>
|
||||
<img src="images/flutter-logo.svg" alt="flutter logo">
|
||||
<img src="my-special-custom-scheme://images/flutter-logo.svg" alt="flutter logo">
|
||||
<p class="lead">Cover is a one-page template for building simple and beautiful home pages. Download, edit the text, and add your own fullscreen background photo to make it your own.</p>
|
||||
<p class="lead">
|
||||
<a href="#" class="btn btn-lg btn-secondary">Learn more</a>
|
||||
|
@ -33,7 +33,9 @@
|
|||
|
||||
<footer class="mastfoot mt-auto">
|
||||
<div class="inner">
|
||||
<p>Cover template for <a href="https://getbootstrap.com/">Bootstrap</a>, by <a href="https://twitter.com/mdo">@mdo</a>.</p>
|
||||
<p>Cover template for <a target="_blank" href="https://getbootstrap.com/">Bootstrap</a>, by <a href="https://twitter.com/mdo">@mdo</a>.</p>
|
||||
<p>Phone link example <a href="tel:1-408-555-5555">1-408-555-5555</a></p>
|
||||
<p>Email link example <a href="mailto:example@gmail.com">example@gmail.com</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
|
||||
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
|
||||
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
61FF730023634CA10069C557 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 61FF72FF23634CA10069C557 /* libsqlite3.tbd */; };
|
||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
|
||||
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
|
||||
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
|
@ -40,6 +41,8 @@
|
|||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
|
||||
61FF72FF23634CA10069C557 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
|
||||
61FF730123634DD10069C557 /* flutter_downloader.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = flutter_downloader.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
|
@ -61,6 +64,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
61FF730023634CA10069C557 /* libsqlite3.tbd in Frameworks */,
|
||||
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
|
||||
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
|
||||
25A517508F43E58C47090625 /* Pods_Runner.framework in Frameworks */,
|
||||
|
@ -73,6 +77,8 @@
|
|||
50BAF1DF19E018DDF2B149B9 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
61FF730123634DD10069C557 /* flutter_downloader.framework */,
|
||||
61FF72FF23634CA10069C557 /* libsqlite3.tbd */,
|
||||
E8D91E403808A7540F18B75D /* Pods_Runner.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
|
@ -180,6 +186,11 @@
|
|||
CreatedOnToolsVersion = 7.3.1;
|
||||
DevelopmentTeam = PFP8UV45Y6;
|
||||
LastSwiftMigration = 1020;
|
||||
SystemCapabilities = {
|
||||
com.apple.BackgroundModes = {
|
||||
enabled = 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -257,12 +268,16 @@
|
|||
inputPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
|
||||
"${PODS_ROOT}/../.symlinks/flutter/ios-release/Flutter.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_downloader/flutter_downloader.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/flutter_inappbrowser/flutter_inappbrowser.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_downloader.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_inappbrowser.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider.framework",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
import UIKit
|
||||
import Flutter
|
||||
import flutter_downloader
|
||||
|
||||
@UIApplicationMain
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
) -> Bool {
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
FlutterDownloaderPlugin.setPluginRegistrantCallback({(registry: FlutterPluginRegistry) in
|
||||
|
||||
})
|
||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
<dict>
|
||||
<key></key>
|
||||
<string></string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
|
@ -29,6 +24,16 @@
|
|||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsLocalNetworking</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>fetch</string>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
|
@ -46,9 +51,9 @@
|
|||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>io.flutter.embedded_views_preview</key>
|
||||
<true/>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>io.flutter.embedded_views_preview</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -1 +1 @@
|
|||
#import "GeneratedPluginRegistrant.h"
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
|
||||
class InlineExampleScreen extends StatefulWidget {
|
||||
@override
|
||||
|
@ -44,7 +51,7 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
|
|||
child: Text(
|
||||
"CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"),
|
||||
),
|
||||
Container(
|
||||
Container(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: progress < 1.0 ? LinearProgressIndicator(value: progress) : Container()
|
||||
),
|
||||
|
@ -55,13 +62,15 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
|
|||
BoxDecoration(border: Border.all(color: Colors.blueAccent)),
|
||||
child: InAppWebView(
|
||||
//initialUrl: "https://www.youtube.com/embed/M7lc1UVf-VE?playsinline=1",
|
||||
initialUrl: "https://flutter.dev/",
|
||||
//initialFile: "assets/index.html",
|
||||
//initialUrl: "https://flutter.dev/",
|
||||
initialFile: "assets/index.html",
|
||||
initialHeaders: {},
|
||||
initialOptions: {
|
||||
//"mediaPlaybackRequiresUserGesture": false,
|
||||
//"allowsInlineMediaPlayback": true,
|
||||
//"useShouldOverrideUrlLoading": true,
|
||||
"useShouldOverrideUrlLoading": true,
|
||||
"useOnTargetBlank": true,
|
||||
"resourceCustomSchemes": ["my-special-custom-scheme"],
|
||||
//"useOnLoadResource": true
|
||||
},
|
||||
onWebViewCreated: (InAppWebViewController controller) {
|
||||
|
@ -104,13 +113,34 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
|
|||
response.url);
|
||||
},
|
||||
onConsoleMessage: (InAppWebViewController controller, ConsoleMessage consoleMessage) {
|
||||
print("""
|
||||
console output:
|
||||
sourceURL: ${consoleMessage.sourceURL}
|
||||
lineNumber: ${consoleMessage.lineNumber}
|
||||
message: ${consoleMessage.message}
|
||||
messageLevel: ${consoleMessage.messageLevel}
|
||||
""");
|
||||
// print("""
|
||||
// console output:
|
||||
// sourceURL: ${consoleMessage.sourceURL}
|
||||
// lineNumber: ${consoleMessage.lineNumber}
|
||||
// message: ${consoleMessage.message}
|
||||
// messageLevel: ${consoleMessage.messageLevel}
|
||||
// """);
|
||||
},
|
||||
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 asBase64 = base64.encode(bytes.buffer.asUint8List());
|
||||
var response = new CustomSchemeResponse(asBase64, "image/svg+xml", "utf-8");
|
||||
return response;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onTargetBlank: (InAppWebViewController controller, String url) {
|
||||
print("target _blank: " + url);
|
||||
controller.loadUrl(url);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -146,4 +176,11 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
|
|||
),
|
||||
]));
|
||||
}
|
||||
|
||||
Future<String> _findLocalPath() async {
|
||||
final directory = Platform.isAndroid
|
||||
? await getExternalStorageDirectory()
|
||||
: await getApplicationDocumentsDirectory();
|
||||
return directory.path;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,13 @@ import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
|
|||
import 'package:flutter_inappbrowser_example/chrome_safari_example.screen.dart';
|
||||
import 'package:flutter_inappbrowser_example/inline_example.screen.dart';
|
||||
import 'package:flutter_inappbrowser_example/webview_example.screen.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
|
||||
// InAppLocalhostServer localhostServer = new InAppLocalhostServer();
|
||||
|
||||
Future main() async {
|
||||
// await localhostServer.start();
|
||||
await FlutterDownloader.initialize();
|
||||
runApp(new MyApp());
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,16 @@ class MyInappBrowser extends InAppBrowser {
|
|||
messageLevel: ${consoleMessage.messageLevel}
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void onDownloadStart(String url) {
|
||||
print("Download of " + url);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) async {
|
||||
print("custom scheme: " + scheme);
|
||||
}
|
||||
}
|
||||
|
||||
class WebviewExampleScreen extends StatefulWidget {
|
||||
|
@ -87,7 +96,7 @@ class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
|
|||
child: new RaisedButton(
|
||||
onPressed: () {
|
||||
widget.browser.open(
|
||||
url: "https://google.com",
|
||||
url: "https://www.google.com/",
|
||||
options: {
|
||||
"useShouldOverrideUrlLoading": true,
|
||||
"useOnLoadResource": true,
|
||||
|
|
|
@ -19,6 +19,8 @@ dependencies:
|
|||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
flutter_downloader: ^1.3.2
|
||||
path_provider: ^1.4.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_inappbrowser/example/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// CustomeSchemeHandler.swift
|
||||
// flutter_downloader
|
||||
//
|
||||
// Created by Lorenzo Pichilli on 25/10/2019.
|
||||
//
|
||||
|
||||
import Flutter
|
||||
import Foundation
|
||||
import WebKit
|
||||
|
||||
@available(iOS 11.0, *)
|
||||
class CustomeSchemeHandler : NSObject, WKURLSchemeHandler {
|
||||
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
||||
let inAppWebView = webView as! InAppWebView
|
||||
if let url = urlSchemeTask.request.url, let scheme = url.scheme {
|
||||
inAppWebView.onLoadResourceCustomScheme(scheme: scheme, url: url.absoluteString, result: {(result) -> Void in
|
||||
if result is FlutterError {
|
||||
print((result as! FlutterError).message)
|
||||
}
|
||||
else if (result as? NSObject) == FlutterMethodNotImplemented {}
|
||||
else {
|
||||
let json: [String: String]
|
||||
if let r = result {
|
||||
json = r as! [String: String]
|
||||
let urlResponse = URLResponse(url: url, mimeType: json["content-type"], expectedContentLength: -1, textEncodingName: json["content-encoding"])
|
||||
let data = Data(base64Encoded: json["base64data"]!, options: .ignoreUnknownCharacters)
|
||||
urlSchemeTask.didReceive(urlResponse)
|
||||
urlSchemeTask.didReceive(data!)
|
||||
urlSchemeTask.didFinish()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
||||
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import Flutter
|
|||
import Foundation
|
||||
|
||||
public class FlutterWebViewFactory: NSObject, FlutterPlatformViewFactory {
|
||||
private weak var registrar: FlutterPluginRegistrar?
|
||||
private var registrar: FlutterPluginRegistrar?
|
||||
|
||||
init(registrar: FlutterPluginRegistrar?) {
|
||||
super.init()
|
||||
|
@ -22,7 +22,10 @@ public class FlutterWebViewFactory: NSObject, FlutterPlatformViewFactory {
|
|||
|
||||
public func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
|
||||
let arguments = args as? NSDictionary
|
||||
let webviewController = FlutterWebViewController(registrar: registrar!, withFrame: frame, viewIdentifier: viewId, arguments: arguments!)
|
||||
let webviewController = FlutterWebViewController(registrar: registrar!,
|
||||
withFrame: frame,
|
||||
viewIdentifier: viewId,
|
||||
arguments: arguments!)
|
||||
return webviewController
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ window.\(JAVASCRIPT_BRIDGE_NAME).callHandler = function() {
|
|||
|
||||
let platformReadyJS = "window.dispatchEvent(new Event('flutterInAppBrowserPlatformReady'));";
|
||||
|
||||
public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, URLSessionDownloadDelegate {
|
||||
public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler {
|
||||
|
||||
var IABController: InAppBrowserWebViewController?
|
||||
var IAWController: FlutterWebViewController?
|
||||
|
@ -206,6 +206,16 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
|
||||
configuration.allowsInlineMediaPlayback = (options?.allowsInlineMediaPlayback)!
|
||||
|
||||
if #available(iOS 11.0, *) {
|
||||
if let schemes = options?.resourceCustomSchemes {
|
||||
for scheme in schemes {
|
||||
configuration.setURLSchemeHandler(CustomeSchemeHandler(), forURLScheme: scheme)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
}
|
||||
|
||||
return configuration
|
||||
}
|
||||
|
||||
|
@ -296,7 +306,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
}
|
||||
|
||||
public func loadFile(url: String, headers: [String: String]?) throws {
|
||||
let key = SwiftFlutterPlugin.registrar!.lookupKey(forAsset: url)
|
||||
let key = SwiftFlutterPlugin.instance!.registrar!.lookupKey(forAsset: url)
|
||||
let assetURL = Bundle.main.url(forResource: key, withExtension: nil)
|
||||
if assetURL == nil {
|
||||
throw NSError(domain: url + " asset file cannot be found!", code: 0)
|
||||
|
@ -524,7 +534,9 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
public func webView(_ webView: WKWebView,
|
||||
decidePolicyFor navigationAction: WKNavigationAction,
|
||||
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
||||
|
||||
|
||||
let app = UIApplication.shared
|
||||
|
||||
if let url = navigationAction.request.url {
|
||||
if url.absoluteString != url.absoluteString && (options?.useOnLoadResource)! {
|
||||
WKNavigationMap[url.absoluteString] = [
|
||||
|
@ -533,12 +545,32 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
]
|
||||
}
|
||||
|
||||
// Handle target="_blank"
|
||||
if navigationAction.targetFrame == nil && (options?.useOnTargetBlank)! {
|
||||
onTargetBlank(url: url)
|
||||
decisionHandler(.cancel)
|
||||
return
|
||||
}
|
||||
|
||||
if navigationAction.navigationType == .linkActivated && (options?.useShouldOverrideUrlLoading)! {
|
||||
shouldOverrideUrlLoading(url: url)
|
||||
decisionHandler(.cancel)
|
||||
return
|
||||
}
|
||||
|
||||
// Handle phone and email links
|
||||
if url.scheme == "tel" || url.scheme == "mailto" {
|
||||
if app.canOpenURL(url) {
|
||||
if #available(iOS 10.0, *) {
|
||||
app.open(url)
|
||||
} else {
|
||||
app.openURL(url)
|
||||
}
|
||||
}
|
||||
decisionHandler(.cancel)
|
||||
return
|
||||
}
|
||||
|
||||
if navigationAction.navigationType == .linkActivated || navigationAction.navigationType == .backForward {
|
||||
currentURL = url
|
||||
if IABController != nil {
|
||||
|
@ -568,9 +600,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
let mimeType = navigationResponse.response.mimeType
|
||||
if let url = navigationResponse.response.url {
|
||||
if mimeType != nil && !mimeType!.starts(with: "text/") {
|
||||
Downloader.load(delegate: self, url: url, completion: { (destinationUrl: URL) in
|
||||
print(destinationUrl)
|
||||
})
|
||||
onDownloadStart(url: url.absoluteString)
|
||||
decisionHandler(.cancel)
|
||||
return
|
||||
}
|
||||
|
@ -579,40 +609,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
decisionHandler(.allow)
|
||||
}
|
||||
|
||||
// func webView(_ webView: WKWebView,
|
||||
// decidePolicyFor navigationResponse: WKNavigationResponse,
|
||||
// decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
|
||||
// let mimeType = navigationResponse.response.mimeType
|
||||
// if mimeType != nil && !mimeType!.starts(with: "text/") {
|
||||
// download(url: webView.url)
|
||||
// decisionHandler(.cancel)
|
||||
// return
|
||||
// }
|
||||
// decisionHandler(.allow)
|
||||
// }
|
||||
//
|
||||
// func download (url: URL?) {
|
||||
// let filename = url?.lastPathComponent
|
||||
//
|
||||
// let destination: DownloadRequest.DownloadFileDestination = { _, _ in
|
||||
// let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
// let fileURL = documentsURL.appendingPathComponent(filename!)
|
||||
//
|
||||
// return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
|
||||
// }
|
||||
//
|
||||
// Alamofire.download((url?.absoluteString)!, to: destination).downloadProgress { progress in
|
||||
// print("Download Progress: \(progress.fractionCompleted)")
|
||||
// }.response { response in
|
||||
// if response.error == nil, let path = response.destinationURL?.path {
|
||||
// UIAlertView(title: nil, message: "File saved to " + path, delegate: nil, cancelButtonTitle: nil).show()
|
||||
// }
|
||||
// else {
|
||||
// UIAlertView(title: nil, message: "Cannot save " + filename!, delegate: nil, cancelButtonTitle: nil).show()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
|
||||
self.startPageTime = currentTimeInMilliSeconds()
|
||||
onLoadStart(url: (currentURL?.absoluteString)!)
|
||||
|
@ -667,20 +663,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
setNeedsLayout()
|
||||
}
|
||||
|
||||
public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
|
||||
|
||||
}
|
||||
|
||||
public func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
|
||||
guard
|
||||
let url = downloadTask.originalRequest?.url
|
||||
else {
|
||||
return
|
||||
}
|
||||
let progress = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite)
|
||||
let totalSize = ByteCountFormatter.string(fromByteCount: totalBytesExpectedToWrite, countStyle: .file)
|
||||
}
|
||||
|
||||
public func onLoadStart(url: String) {
|
||||
var arguments: [String: Any] = ["url": url]
|
||||
if IABController != nil {
|
||||
|
@ -761,6 +743,26 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
}
|
||||
}
|
||||
|
||||
public func onDownloadStart(url: String) {
|
||||
var arguments: [String: Any] = ["url": url]
|
||||
if IABController != nil {
|
||||
arguments["uuid"] = IABController!.uuid
|
||||
}
|
||||
if let channel = getChannel() {
|
||||
channel.invokeMethod("onDownloadStart", arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
public func onLoadResourceCustomScheme(scheme: String, url: String, result: FlutterResult?) {
|
||||
var arguments: [String: Any] = ["scheme": scheme, "url": url]
|
||||
if IABController != nil {
|
||||
arguments["uuid"] = IABController!.uuid
|
||||
}
|
||||
if let channel = getChannel() {
|
||||
channel.invokeMethod("onLoadResourceCustomScheme", arguments: arguments, result: result)
|
||||
}
|
||||
}
|
||||
|
||||
public func shouldOverrideUrlLoading(url: URL) {
|
||||
var arguments: [String: Any] = ["url": url.absoluteString]
|
||||
if IABController != nil {
|
||||
|
@ -771,6 +773,16 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
}
|
||||
}
|
||||
|
||||
public func onTargetBlank(url: URL) {
|
||||
var arguments: [String: Any] = ["url": url.absoluteString]
|
||||
if IABController != nil {
|
||||
arguments["uuid"] = IABController!.uuid
|
||||
}
|
||||
if let channel = getChannel() {
|
||||
channel.invokeMethod("onTargetBlank", arguments: arguments)
|
||||
}
|
||||
}
|
||||
|
||||
public func onConsoleMessage(sourceURL: String, lineNumber: Int, message: String, messageLevel: String) {
|
||||
var arguments: [String: Any] = ["sourceURL": sourceURL, "lineNumber": lineNumber, "message": message, "messageLevel": messageLevel]
|
||||
if IABController != nil {
|
||||
|
@ -870,50 +882,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
|
|||
}
|
||||
|
||||
private func getChannel() -> FlutterMethodChannel? {
|
||||
return (IABController != nil) ? SwiftFlutterPlugin.channel! : ((IAWController != nil) ? IAWController!.channel! : nil);
|
||||
}
|
||||
}
|
||||
|
||||
class Downloader {
|
||||
class func load(delegate: URLSessionDelegate, url: URL, completion: @escaping (_ destinationUrl: URL) -> ()) {
|
||||
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last as! URL
|
||||
let destinationUrl = documentsUrl.appendingPathComponent(url.lastPathComponent)
|
||||
|
||||
if FileManager.default.fileExists(atPath: destinationUrl.path) {
|
||||
print("file already exists [\(destinationUrl.path)]")
|
||||
//completion(path: destinationUrl.path!, error:nil)
|
||||
return
|
||||
}
|
||||
|
||||
let sessionConfig = URLSessionConfiguration.default
|
||||
let session = URLSession(configuration: sessionConfig, delegate: delegate, delegateQueue: nil)
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "GET"
|
||||
|
||||
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
|
||||
if let tempLocalUrl = tempLocalUrl, error == nil {
|
||||
// Success
|
||||
if let statusCode = (response as? HTTPURLResponse)?.statusCode {
|
||||
if statusCode == 200 {
|
||||
do {
|
||||
try FileManager.default.moveItem(at: tempLocalUrl, to: destinationUrl)
|
||||
completion(destinationUrl)
|
||||
} catch (let writeError) {
|
||||
print("error writing file \(destinationUrl) : \(writeError)")
|
||||
//completion(path: destinationUrl.path!, error:nil)
|
||||
}
|
||||
} else {
|
||||
//completion(path: destinationUrl.path!, error:nil)
|
||||
}
|
||||
} else {
|
||||
//completion(path: destinationUrl.path!, error:nil)
|
||||
}
|
||||
|
||||
} else {
|
||||
print("Failure: %@", error?.localizedDescription);
|
||||
//completion(path: destinationUrl.path!, error:nil)
|
||||
}
|
||||
}
|
||||
task.resume()
|
||||
return (IABController != nil) ? SwiftFlutterPlugin.instance!.channel! : ((IAWController != nil) ? IAWController!.channel! : nil);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ public class InAppWebViewOptions: Options {
|
|||
|
||||
var useShouldOverrideUrlLoading = false
|
||||
var useOnLoadResource = false
|
||||
var useOnTargetBlank = false
|
||||
var clearCache = false
|
||||
var userAgent = ""
|
||||
var javaScriptEnabled = true
|
||||
|
@ -19,6 +20,7 @@ public class InAppWebViewOptions: Options {
|
|||
var mediaPlaybackRequiresUserGesture = true
|
||||
var verticalScrollBarEnabled = true
|
||||
var horizontalScrollBarEnabled = true
|
||||
var resourceCustomSchemes: [String] = []
|
||||
|
||||
var disallowOverScroll = false
|
||||
var enableViewportScale = false
|
||||
|
|
|
@ -35,8 +35,9 @@ extension Dictionary where Key: ExpressibleByStringLiteral {
|
|||
|
||||
public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
|
||||
|
||||
static var registrar: FlutterPluginRegistrar?
|
||||
static var channel: FlutterMethodChannel?
|
||||
static var instance: SwiftFlutterPlugin?
|
||||
var registrar: FlutterPluginRegistrar?
|
||||
var channel: FlutterMethodChannel?
|
||||
|
||||
var webViewControllers: [String: InAppBrowserWebViewController?] = [:]
|
||||
var safariViewControllers: [String: Any?] = [:]
|
||||
|
@ -45,17 +46,14 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
|
|||
private var previousStatusBarStyle = -1
|
||||
|
||||
public init(with registrar: FlutterPluginRegistrar) {
|
||||
SwiftFlutterPlugin.channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser", binaryMessenger: registrar.messenger())
|
||||
super.init()
|
||||
self.registrar = registrar
|
||||
self.channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser", binaryMessenger: registrar.messenger())
|
||||
registrar.addMethodCallDelegate(self, channel: channel!)
|
||||
}
|
||||
|
||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||
|
||||
SwiftFlutterPlugin.registrar = registrar
|
||||
|
||||
let channel = FlutterMethodChannel(name: "com.pichillilorenzo/flutter_inappbrowser", binaryMessenger: registrar.messenger())
|
||||
let instance = SwiftFlutterPlugin(with: registrar)
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
|
||||
SwiftFlutterPlugin.instance = SwiftFlutterPlugin(with: registrar)
|
||||
registrar.register(FlutterWebViewFactory(registrar: registrar) as FlutterPlatformViewFactory, withId: "com.pichillilorenzo/flutter_inappwebview")
|
||||
|
||||
if #available(iOS 11.0, *) {
|
||||
|
@ -288,7 +286,7 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
|
|||
var openWithSystemBrowser = (arguments["openWithSystemBrowser"] as? Bool)!
|
||||
|
||||
if isLocalFile {
|
||||
let key = SwiftFlutterPlugin.registrar!.lookupKey(forAsset: url)
|
||||
let key = self.registrar!.lookupKey(forAsset: url)
|
||||
let assetURL = Bundle.main.url(forResource: key, withExtension: nil)
|
||||
if assetURL == nil {
|
||||
result(FlutterError(code: "InAppBrowserFlutterPlugin", message: url + " asset file cannot be found!", details: nil))
|
||||
|
@ -677,28 +675,28 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
|
|||
|
||||
func onBrowserCreated(uuid: String, webView: WKWebView) {
|
||||
if let webViewController = self.webViewControllers[uuid] {
|
||||
SwiftFlutterPlugin.channel!.invokeMethod("onBrowserCreated", arguments: ["uuid": uuid])
|
||||
self.channel!.invokeMethod("onBrowserCreated", arguments: ["uuid": uuid])
|
||||
}
|
||||
}
|
||||
|
||||
func onExit(uuid: String) {
|
||||
SwiftFlutterPlugin.channel!.invokeMethod("onExit", arguments: ["uuid": uuid])
|
||||
self.channel!.invokeMethod("onExit", arguments: ["uuid": uuid])
|
||||
}
|
||||
|
||||
func onChromeSafariBrowserOpened(uuid: String) {
|
||||
if self.safariViewControllers[uuid] != nil {
|
||||
SwiftFlutterPlugin.channel!.invokeMethod("onChromeSafariBrowserOpened", arguments: ["uuid": uuid])
|
||||
self.channel!.invokeMethod("onChromeSafariBrowserOpened", arguments: ["uuid": uuid])
|
||||
}
|
||||
}
|
||||
|
||||
func onChromeSafariBrowserLoaded(uuid: String) {
|
||||
if self.safariViewControllers[uuid] != nil {
|
||||
SwiftFlutterPlugin.channel!.invokeMethod("onChromeSafariBrowserLoaded", arguments: ["uuid": uuid])
|
||||
self.channel!.invokeMethod("onChromeSafariBrowserLoaded", arguments: ["uuid": uuid])
|
||||
}
|
||||
}
|
||||
|
||||
func onChromeSafariBrowserClosed(uuid: String) {
|
||||
SwiftFlutterPlugin.channel!.invokeMethod("onChromeSafariBrowserClosed", arguments: ["uuid": uuid])
|
||||
self.channel!.invokeMethod("onChromeSafariBrowserClosed", arguments: ["uuid": uuid])
|
||||
}
|
||||
|
||||
func safariExit(uuid: String) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'types.dart' show ListenerCallback;
|
||||
|
||||
class ChannelManager {
|
||||
static const MethodChannel channel = const MethodChannel('com.pichillilorenzo/flutter_inappbrowser');
|
||||
static bool initialized = false;
|
||||
static final listeners = HashMap<String, ListenerCallback>();
|
||||
|
||||
static Future<dynamic> _handleMethod(MethodCall call) async {
|
||||
String uuid = call.arguments["uuid"];
|
||||
return await listeners[uuid](call);
|
||||
}
|
||||
|
||||
static void addListener(String key, ListenerCallback callback) {
|
||||
if (!initialized)
|
||||
init();
|
||||
listeners.putIfAbsent(key, () => callback);
|
||||
}
|
||||
|
||||
static void init () {
|
||||
channel.setMethodCallHandler(_handleMethod);
|
||||
initialized = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'types.dart';
|
||||
import 'channel_manager.dart';
|
||||
import 'in_app_browser.dart';
|
||||
|
||||
///ChromeSafariBrowser class.
|
||||
///
|
||||
///This class uses native [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android
|
||||
///and [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS.
|
||||
///
|
||||
///[browserFallback] represents the [InAppBrowser] instance fallback in case [Chrome Custom Tabs]/[SFSafariViewController] is not available.
|
||||
class ChromeSafariBrowser {
|
||||
String uuid;
|
||||
InAppBrowser browserFallback;
|
||||
bool _isOpened = false;
|
||||
|
||||
///Initialize the [ChromeSafariBrowser] instance with an [InAppBrowser] fallback instance or `null`.
|
||||
ChromeSafariBrowser (bf) {
|
||||
uuid = uuidGenerator.v4();
|
||||
browserFallback = bf;
|
||||
ChannelManager.addListener(uuid, handleMethod);
|
||||
_isOpened = false;
|
||||
}
|
||||
|
||||
Future<dynamic> handleMethod(MethodCall call) async {
|
||||
switch(call.method) {
|
||||
case "onChromeSafariBrowserOpened":
|
||||
onOpened();
|
||||
break;
|
||||
case "onChromeSafariBrowserLoaded":
|
||||
onLoaded();
|
||||
break;
|
||||
case "onChromeSafariBrowserClosed":
|
||||
onClosed();
|
||||
this._isOpened = false;
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
}
|
||||
|
||||
///Opens an [url] in a new [ChromeSafariBrowser] instance.
|
||||
///
|
||||
///- [url]: The [url] to load. Call [encodeUriComponent()] on this if the [url] contains Unicode characters.
|
||||
///
|
||||
///- [options]: Options for the [ChromeSafariBrowser].
|
||||
///
|
||||
///- [headersFallback]: The additional header of the [InAppBrowser] instance fallback to be used in the HTTP request for this URL, specified as a map from name to value.
|
||||
///
|
||||
///- [optionsFallback]: Options used by the [InAppBrowser] instance fallback.
|
||||
///
|
||||
///**Android** supports these options:
|
||||
///
|
||||
///- __addShareButton__: Set to `false` if you don't want the default share button. The default value is `true`.
|
||||
///- __showTitle__: Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
|
||||
///- __toolbarBackgroundColor__: Set the custom background color of the toolbar.
|
||||
///- __enableUrlBarHiding__: Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
|
||||
///- __instantAppsEnabled__: Set to `true` to enable Instant Apps. The default value is `false`.
|
||||
///
|
||||
///**iOS** supports these options:
|
||||
///
|
||||
///- __entersReaderIfAvailable__: Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
|
||||
///- __barCollapsingEnabled__: Set to `true` to enable bar collapsing. The default value is `false`.
|
||||
///- __dismissButtonStyle__: Set the custom style for the dismiss button. The default value is `0 //done`. See [SFSafariViewController.DismissButtonStyle](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle) for all the available styles.
|
||||
///- __preferredBarTintColor__: Set the custom background color of the navigation bar and the toolbar.
|
||||
///- __preferredControlTintColor__: Set the custom color of the control buttons on the navigation bar and the toolbar.
|
||||
///- __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
|
||||
///- __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
|
||||
Future<void> open(String url, {Map<String, dynamic> options = const {}, Map<String, String> headersFallback = const {}, Map<String, dynamic> optionsFallback = const {}}) async {
|
||||
assert(url != null && url.isNotEmpty);
|
||||
this.throwIsAlreadyOpened(message: 'Cannot open $url!');
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
args.putIfAbsent('uuidFallback', () => (browserFallback != null) ? browserFallback.uuid : '');
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('headers', () => headersFallback);
|
||||
args.putIfAbsent('options', () => options);
|
||||
args.putIfAbsent('optionsFallback', () => optionsFallback);
|
||||
args.putIfAbsent('isData', () => false);
|
||||
args.putIfAbsent('useChromeSafariBrowser', () => true);
|
||||
await ChannelManager.channel.invokeMethod('open', args);
|
||||
this._isOpened = true;
|
||||
}
|
||||
|
||||
///Event fires when the [ChromeSafariBrowser] is opened.
|
||||
void onOpened() {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [ChromeSafariBrowser] is loaded.
|
||||
void onLoaded() {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [ChromeSafariBrowser] is closed.
|
||||
void onClosed() {
|
||||
|
||||
}
|
||||
|
||||
bool isOpened() {
|
||||
return this._isOpened;
|
||||
}
|
||||
|
||||
void throwIsAlreadyOpened({String message = ''}) {
|
||||
if (this.isOpened()) {
|
||||
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']);
|
||||
}
|
||||
}
|
||||
|
||||
void throwIsNotOpened({String message = ''}) {
|
||||
if (!this.isOpened()) {
|
||||
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is not opened.']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
import 'package:flutter/services.dart';
|
||||
|
||||
///Manages the cookies used by WebView instances.
|
||||
///
|
||||
///**NOTE for iOS**: available from iOS 11.0+.
|
||||
class CookieManager {
|
||||
static bool _initialized = false;
|
||||
static const MethodChannel _channel = const MethodChannel('com.pichillilorenzo/flutter_inappbrowser_cookiemanager');
|
||||
|
||||
static void _init () {
|
||||
_channel.setMethodCallHandler(handleMethod);
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
static Future<dynamic> handleMethod(MethodCall call) async {
|
||||
}
|
||||
|
||||
///Sets a cookie for the given [url]. Any existing cookie with the same [host], [path] and [name] will be replaced with the new cookie. The cookie being set will be ignored if it is expired.
|
||||
///
|
||||
///The default value of [path] is `"/"`.
|
||||
///If [domain] is `null`, its default value will be the domain name of [url].
|
||||
static Future<void> setCookie(String url, String name, String value,
|
||||
{ String domain,
|
||||
String path = "/",
|
||||
int expiresDate,
|
||||
int maxAge,
|
||||
bool isSecure }) async {
|
||||
if (!_initialized)
|
||||
_init();
|
||||
|
||||
if (domain == null)
|
||||
domain = getDomainName(url);
|
||||
|
||||
assert(url != null && url.isNotEmpty);
|
||||
assert(name != null && name.isNotEmpty);
|
||||
assert(value != null && value.isNotEmpty);
|
||||
assert(domain != null && domain.isNotEmpty);
|
||||
assert(path != null && path.isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('name', () => name);
|
||||
args.putIfAbsent('value', () => value);
|
||||
args.putIfAbsent('domain', () => domain);
|
||||
args.putIfAbsent('path', () => path);
|
||||
args.putIfAbsent('expiresDate', () => expiresDate?.toString());
|
||||
args.putIfAbsent('maxAge', () => maxAge);
|
||||
args.putIfAbsent('isSecure', () => isSecure);
|
||||
|
||||
await _channel.invokeMethod('setCookie', args);
|
||||
}
|
||||
|
||||
///Gets all the cookies for the given [url].
|
||||
static Future<List<Map<String, dynamic>>> getCookies(String url) async {
|
||||
if (!_initialized)
|
||||
_init();
|
||||
|
||||
assert(url != null && url.isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url);
|
||||
List<dynamic> cookies = await _channel.invokeMethod('getCookies', args);
|
||||
cookies = cookies.cast<Map<dynamic, dynamic>>();
|
||||
for(var i = 0; i < cookies.length; i++) {
|
||||
cookies[i] = cookies[i].cast<String, dynamic>();
|
||||
}
|
||||
cookies = cookies.cast<Map<String, dynamic>>();
|
||||
return cookies;
|
||||
}
|
||||
|
||||
///Gets a cookie by its [name] for the given [url].
|
||||
static Future<Map<String, dynamic>> getCookie(String url, String name) async {
|
||||
if (!_initialized)
|
||||
_init();
|
||||
|
||||
assert(url != null && url.isNotEmpty);
|
||||
assert(name != null && name.isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url);
|
||||
List<dynamic> cookies = await _channel.invokeMethod('getCookies', args);
|
||||
cookies = cookies.cast<Map<dynamic, dynamic>>();
|
||||
for(var i = 0; i < cookies.length; i++) {
|
||||
cookies[i] = cookies[i].cast<String, dynamic>();
|
||||
if (cookies[i]["name"] == name)
|
||||
return cookies[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
///Removes a cookie by its [name] for the given [url], [domain] and [path].
|
||||
///
|
||||
///The default value of [path] is `"/"`.
|
||||
///If [domain] is `null` or empty, its default value will be the domain name of [url].
|
||||
static Future<void> deleteCookie(String url, String name, {String domain = "", String path = "/"}) async {
|
||||
if (!_initialized)
|
||||
_init();
|
||||
|
||||
if (domain == null || domain.isEmpty)
|
||||
domain = getDomainName(url);
|
||||
|
||||
assert(url != null && url.isNotEmpty);
|
||||
assert(name != null && name.isNotEmpty);
|
||||
assert(domain != null && url.isNotEmpty);
|
||||
assert(path != null && url.isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('name', () => name);
|
||||
args.putIfAbsent('domain', () => domain);
|
||||
args.putIfAbsent('path', () => path);
|
||||
await _channel.invokeMethod('deleteCookie', args);
|
||||
}
|
||||
|
||||
///Removes all cookies for the given [url], [domain] and [path].
|
||||
///
|
||||
///The default value of [path] is `"/"`.
|
||||
///If [domain] is `null` or empty, its default value will be the domain name of [url].
|
||||
static Future<void> deleteCookies(String url, {String domain = "", String path = "/"}) async {
|
||||
if (!_initialized)
|
||||
_init();
|
||||
|
||||
if (domain == null || domain.isEmpty)
|
||||
domain = getDomainName(url);
|
||||
|
||||
assert(url != null && url.isNotEmpty);
|
||||
assert(domain != null && url.isNotEmpty);
|
||||
assert(path != null && url.isNotEmpty);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('domain', () => domain);
|
||||
args.putIfAbsent('path', () => path);
|
||||
await _channel.invokeMethod('deleteCookies', args);
|
||||
}
|
||||
|
||||
///Removes all cookies.
|
||||
static Future<void> deleteAllCookies() async {
|
||||
if (!_initialized)
|
||||
_init();
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await _channel.invokeMethod('deleteAllCookies', args);
|
||||
}
|
||||
|
||||
static String getDomainName(String url) {
|
||||
Uri uri = Uri.parse(url);
|
||||
String domain = uri.host;
|
||||
if (domain == null)
|
||||
return "";
|
||||
return domain.startsWith("www.") ? domain.substring(4) : domain;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,342 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'types.dart';
|
||||
import 'channel_manager.dart';
|
||||
import 'in_app_webview.dart' show InAppWebViewController;
|
||||
|
||||
///InAppBrowser class. [webViewController] can be used to access the [InAppWebView] API.
|
||||
///
|
||||
///This class uses the native WebView of the platform.
|
||||
class InAppBrowser {
|
||||
|
||||
String uuid;
|
||||
Map<String, JavaScriptHandlerCallback> javaScriptHandlersMap = HashMap<String, JavaScriptHandlerCallback>();
|
||||
bool _isOpened = false;
|
||||
/// WebView Controller that can be used to access the [InAppWebView] API.
|
||||
InAppWebViewController webViewController;
|
||||
|
||||
///
|
||||
InAppBrowser () {
|
||||
uuid = uuidGenerator.v4();
|
||||
ChannelManager.addListener(uuid, handleMethod);
|
||||
_isOpened = false;
|
||||
webViewController = new InAppWebViewController.fromInAppBrowser(uuid, ChannelManager.channel, this);
|
||||
}
|
||||
|
||||
Future<dynamic> handleMethod(MethodCall call) async {
|
||||
switch(call.method) {
|
||||
case "onBrowserCreated":
|
||||
this._isOpened = true;
|
||||
onBrowserCreated();
|
||||
break;
|
||||
case "onExit":
|
||||
this._isOpened = false;
|
||||
onExit();
|
||||
break;
|
||||
default:
|
||||
return webViewController.handleMethod(call);
|
||||
}
|
||||
}
|
||||
|
||||
///Opens an [url] in a new [InAppBrowser] instance.
|
||||
///
|
||||
///- [url]: The [url] to load. Call [encodeUriComponent()] on this if the [url] contains Unicode characters. The default value is `about:blank`.
|
||||
///
|
||||
///- [headers]: The additional headers to be used in the HTTP request for this URL, specified as a map from name to value.
|
||||
///
|
||||
///- [options]: Options for the [InAppBrowser].
|
||||
///
|
||||
/// - All platforms support:
|
||||
/// - __useShouldOverrideUrlLoading__: Set to `true` to be able to listen at the [shouldOverrideUrlLoading()] event. The default value is `false`.
|
||||
/// - __useOnLoadResource__: Set to `true` to be able to listen at the [onLoadResource()] event. The default value is `false`.
|
||||
/// - __useOnTargetBlank__: Set to `true` to be able to listen at the [onTargetBlank()] event. The default value is `false`.
|
||||
/// - __clearCache__: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
|
||||
/// - __userAgent__: Set the custom WebView's user-agent.
|
||||
/// - __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`.
|
||||
/// - __javaScriptCanOpenWindowsAutomatically__: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
|
||||
/// - __hidden__: Set to `true` to create the browser and load the page, but not show it. The `onLoadStop` event fires when loading is complete. Omit or set to `false` (default) to have the browser open and load normally.
|
||||
/// - __toolbarTop__: Set to `false` to hide the toolbar at the top of the WebView. The default value is `true`.
|
||||
/// - __toolbarTopBackgroundColor__: Set the custom background color of the toolbar at the top.
|
||||
/// - __hideUrlBar__: Set to `true` to hide the url bar on the toolbar at the top. The default value is `false`.
|
||||
/// - __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
|
||||
/// - __transparentBackground__: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
|
||||
/// - __resourceCustomSchemes__: List of custom schemes that [InAppBrowser] must handle. Use the [onLoadResourceCustomScheme()] event to intercept resource requests with custom scheme.
|
||||
///
|
||||
/// - **Android** supports these additional options:
|
||||
///
|
||||
/// - __hideTitleBar__: Set to `true` if you want the title should be displayed. The default value is `false`.
|
||||
/// - __closeOnCannotGoBack__: Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
|
||||
/// - __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
|
||||
/// - __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
|
||||
/// - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
|
||||
/// - __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
|
||||
/// - __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
|
||||
/// - __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
|
||||
/// - __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
|
||||
/// - __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
|
||||
/// - __progressBar__: Set to `false` to hide the progress bar at the bottom of the toolbar at the top. The default value is `true`.
|
||||
/// - __textZoom__: Set text scaling of the WebView. The default value is `100`.
|
||||
/// - __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
|
||||
///
|
||||
/// - **iOS** supports these additional options:
|
||||
///
|
||||
/// - __disallowOverScroll__: Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.
|
||||
/// - __toolbarBottom__: Set to `false` to hide the toolbar at the bottom of the WebView. The default value is `true`.
|
||||
/// - __toolbarBottomBackgroundColor__: Set the custom background color of the toolbar at the bottom.
|
||||
/// - __toolbarBottomTranslucent__: Set to `true` to set the toolbar at the bottom translucent. The default value is `true`.
|
||||
/// - __closeButtonCaption__: Set the custom text for the close button.
|
||||
/// - __closeButtonColor__: Set the custom color for the close button.
|
||||
/// - __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
|
||||
/// - __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
|
||||
/// - __enableViewportScale__: Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`.
|
||||
/// - __suppressesIncrementalRendering__: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory.. The default value is `false`.
|
||||
/// - __allowsAirPlayForMediaPlayback__: Set to `true` to allow AirPlay. The default value is `true`.
|
||||
/// - __allowsBackForwardNavigationGestures__: Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`.
|
||||
/// - __allowsLinkPreview__: Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`.
|
||||
/// - __ignoresViewportScaleLimits__: Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent. The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`.
|
||||
/// - __allowsInlineMediaPlayback__: Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the `webkit-playsinline` attribute to any `<video>` elements. The default value is `false`.
|
||||
/// - __allowsPictureInPictureMediaPlayback__: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
|
||||
/// - __spinner__: Set to `false` to hide the spinner when the WebView is loading a page. The default value is `true`.
|
||||
Future<void> open({String url = "about:blank", Map<String, String> headers = const {}, Map<String, dynamic> options = const {}}) async {
|
||||
assert(url != null && url.isNotEmpty);
|
||||
this.throwIsAlreadyOpened(message: 'Cannot open $url!');
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('headers', () => headers);
|
||||
args.putIfAbsent('options', () => options);
|
||||
args.putIfAbsent('openWithSystemBrowser', () => false);
|
||||
args.putIfAbsent('isLocalFile', () => false);
|
||||
args.putIfAbsent('isData', () => false);
|
||||
args.putIfAbsent('useChromeSafariBrowser', () => false);
|
||||
await ChannelManager.channel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
///Opens the given [assetFilePath] file in a new [InAppBrowser] instance. The other arguments are the same of [InAppBrowser.open()].
|
||||
///
|
||||
///To be able to load your local files (assets, js, css, etc.), you need to add them in the `assets` section of the `pubspec.yaml` file, otherwise they cannot be found!
|
||||
///
|
||||
///Example of a `pubspec.yaml` file:
|
||||
///```yaml
|
||||
///...
|
||||
///
|
||||
///# The following section is specific to Flutter.
|
||||
///flutter:
|
||||
///
|
||||
/// # The following line ensures that the Material Icons font is
|
||||
/// # included with your application, so that you can use the icons in
|
||||
/// # the material Icons class.
|
||||
/// uses-material-design: true
|
||||
///
|
||||
/// assets:
|
||||
/// - assets/index.html
|
||||
/// - assets/css/
|
||||
/// - assets/images/
|
||||
///
|
||||
///...
|
||||
///```
|
||||
///Example of a `main.dart` file:
|
||||
///```dart
|
||||
///...
|
||||
///inAppBrowser.openFile("assets/index.html");
|
||||
///...
|
||||
///```
|
||||
Future<void> openFile(String assetFilePath, {Map<String, String> headers = const {}, Map<String, dynamic> options = const {}}) async {
|
||||
assert(assetFilePath != null && assetFilePath.isNotEmpty);
|
||||
this.throwIsAlreadyOpened(message: 'Cannot open $assetFilePath!');
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
args.putIfAbsent('url', () => assetFilePath);
|
||||
args.putIfAbsent('headers', () => headers);
|
||||
args.putIfAbsent('options', () => options);
|
||||
args.putIfAbsent('openWithSystemBrowser', () => false);
|
||||
args.putIfAbsent('isLocalFile', () => true);
|
||||
args.putIfAbsent('isData', () => false);
|
||||
args.putIfAbsent('useChromeSafariBrowser', () => false);
|
||||
await ChannelManager.channel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
///Opens a new [InAppBrowser] instance with [data] as a content, using [baseUrl] as the base URL for it.
|
||||
///The [mimeType] parameter specifies the format of the data.
|
||||
///The [encoding] parameter specifies the encoding of the data.
|
||||
Future<void> openData(String data, {String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank", Map<String, dynamic> options = const {}}) async {
|
||||
assert(data != null);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
args.putIfAbsent('options', () => options);
|
||||
args.putIfAbsent('data', () => data);
|
||||
args.putIfAbsent('mimeType', () => mimeType);
|
||||
args.putIfAbsent('encoding', () => encoding);
|
||||
args.putIfAbsent('baseUrl', () => baseUrl);
|
||||
args.putIfAbsent('openWithSystemBrowser', () => false);
|
||||
args.putIfAbsent('isLocalFile', () => false);
|
||||
args.putIfAbsent('isData', () => true);
|
||||
args.putIfAbsent('useChromeSafariBrowser', () => false);
|
||||
await ChannelManager.channel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
///This is a static method that opens an [url] in the system browser. You wont be able to use the [InAppBrowser] methods here!
|
||||
static Future<void> openWithSystemBrowser(String url) async {
|
||||
assert(url != null && url.isNotEmpty);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => "");
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('headers', () => {});
|
||||
args.putIfAbsent('isLocalFile', () => false);
|
||||
args.putIfAbsent('isData', () => false);
|
||||
args.putIfAbsent('openWithSystemBrowser', () => true);
|
||||
args.putIfAbsent('useChromeSafariBrowser', () => false);
|
||||
args.putIfAbsent('options', () => {});
|
||||
return await ChannelManager.channel.invokeMethod('open', args);
|
||||
}
|
||||
|
||||
///Displays an [InAppBrowser] window that was opened hidden. Calling this has no effect if the [InAppBrowser] was already visible.
|
||||
Future<void> show() async {
|
||||
this.throwIsNotOpened();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
await ChannelManager.channel.invokeMethod('show', args);
|
||||
}
|
||||
|
||||
///Hides the [InAppBrowser] window. Calling this has no effect if the [InAppBrowser] was already hidden.
|
||||
Future<void> hide() async {
|
||||
this.throwIsNotOpened();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
await ChannelManager.channel.invokeMethod('hide', args);
|
||||
}
|
||||
|
||||
///Closes the [InAppBrowser] window.
|
||||
Future<void> close() async {
|
||||
this.throwIsNotOpened();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
await ChannelManager.channel.invokeMethod('close', args);
|
||||
}
|
||||
|
||||
///Check if the Web View of the [InAppBrowser] instance is hidden.
|
||||
Future<bool> isHidden() async {
|
||||
this.throwIsNotOpened();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
return await ChannelManager.channel.invokeMethod('isHidden', args);
|
||||
}
|
||||
|
||||
///Sets the [InAppBrowser] options with the new [options] and evaluates them.
|
||||
Future<void> setOptions(Map<String, dynamic> options) async {
|
||||
this.throwIsNotOpened();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
args.putIfAbsent('options', () => options);
|
||||
args.putIfAbsent('optionsType', () => "InAppBrowserOptions");
|
||||
await ChannelManager.channel.invokeMethod('setOptions', args);
|
||||
}
|
||||
|
||||
///Gets the current [InAppBrowser] options. Returns `null` if the options are not setted yet.
|
||||
Future<Map<String, dynamic>> getOptions() async {
|
||||
this.throwIsNotOpened();
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('uuid', () => uuid);
|
||||
args.putIfAbsent('optionsType', () => "InAppBrowserOptions");
|
||||
Map<dynamic, dynamic> options = await ChannelManager.channel.invokeMethod('getOptions', args);
|
||||
options = options.cast<String, dynamic>();
|
||||
return options;
|
||||
}
|
||||
|
||||
///Returns `true` if the [InAppBrowser] instance is opened, otherwise `false`.
|
||||
bool isOpened() {
|
||||
return this._isOpened;
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] is created.
|
||||
void onBrowserCreated() {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] starts to load an [url].
|
||||
void onLoadStart(String url) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] finishes loading an [url].
|
||||
void onLoadStop(String url) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] encounters an error loading an [url].
|
||||
void onLoadError(String url, int code, String message) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the current [progress] (range 0-100) of loading a page is changed.
|
||||
void onProgressChanged(int progress) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] window is closed.
|
||||
void onExit() {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] webview receives a [ConsoleMessage].
|
||||
void onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||
|
||||
}
|
||||
|
||||
///Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
|
||||
///
|
||||
///**NOTE**: In order to be able to listen this event, you need to set `useShouldOverrideUrlLoading` option to `true`.
|
||||
void shouldOverrideUrlLoading(String url) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] webview loads a resource.
|
||||
///
|
||||
///**NOTE**: In order to be able to listen this event, you need to set `useOnLoadResource` option to `true`.
|
||||
///
|
||||
///**NOTE only for iOS**: In some cases, the [response.data] of a [response] with `text/assets` encoding could be empty.
|
||||
void onLoadResource(WebResourceResponse response, WebResourceRequest request) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] webview scrolls.
|
||||
///[x] represents the current horizontal scroll origin in pixels.
|
||||
///[y] represents the current vertical scroll origin in pixels.
|
||||
void onScrollChanged(int x, int y) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when [InAppBrowser] recognizes and starts a downloadable file.
|
||||
///[url] represents the url of the file.
|
||||
void onDownloadStart(String url) {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] webview finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
|
||||
///[scheme] represents the scheme of the url.
|
||||
///[url] represents the url of the request.
|
||||
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) async {
|
||||
|
||||
}
|
||||
|
||||
///Event fires when the [InAppBrowser] webview tries to open a link with `target="_blank"`.
|
||||
///[url] represents the url of the link.
|
||||
void onTargetBlank(String url) {
|
||||
|
||||
}
|
||||
|
||||
void throwIsAlreadyOpened({String message = ''}) {
|
||||
if (this.isOpened()) {
|
||||
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is already opened.']);
|
||||
}
|
||||
}
|
||||
|
||||
void throwIsNotOpened({String message = ''}) {
|
||||
if (!this.isOpened()) {
|
||||
throw Exception(['Error: ${ (message.isEmpty) ? '' : message + ' '}The browser is not opened.']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
///InAppLocalhostServer class.
|
||||
///
|
||||
///This class allows you to create a simple server on `http://localhost:[port]/` in order to be able to load your assets file on a server. The default [port] value is `8080`.
|
||||
class InAppLocalhostServer {
|
||||
|
||||
HttpServer _server;
|
||||
int _port = 8080;
|
||||
|
||||
InAppLocalhostServer({int port = 8080}) {
|
||||
this._port = port;
|
||||
}
|
||||
|
||||
///Starts a server on http://localhost:[port]/.
|
||||
///
|
||||
///**NOTE for iOS**: For the iOS Platform, you need to add the `NSAllowsLocalNetworking` key with `true` in the `Info.plist` file (See [ATS Configuration Basics](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35)):
|
||||
///```xml
|
||||
///<key>NSAppTransportSecurity</key>
|
||||
///<dict>
|
||||
/// <key>NSAllowsLocalNetworking</key>
|
||||
/// <true/>
|
||||
///</dict>
|
||||
///```
|
||||
///The `NSAllowsLocalNetworking` key is available since **iOS 10**.
|
||||
Future<void> start() async {
|
||||
|
||||
if (this._server != null) {
|
||||
throw Exception('Server already started on http://localhost:$_port');
|
||||
}
|
||||
|
||||
var completer = new Completer();
|
||||
|
||||
runZoned(() {
|
||||
HttpServer.bind('127.0.0.1', _port).then((server) {
|
||||
print('Server running on http://localhost:' + _port.toString());
|
||||
|
||||
this._server = server;
|
||||
|
||||
server.listen((HttpRequest request) async {
|
||||
var body = List<int>();
|
||||
var path = request.requestedUri.path;
|
||||
path = (path.startsWith('/')) ? path.substring(1) : path;
|
||||
path += (path.endsWith('/')) ? 'index.html' : '';
|
||||
|
||||
try {
|
||||
body = (await rootBundle.load(path))
|
||||
.buffer.asUint8List();
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
request.response.close();
|
||||
return;
|
||||
}
|
||||
|
||||
var contentType = ['text', 'html'];
|
||||
if (!request.requestedUri.path.endsWith('/') && request.requestedUri.pathSegments.isNotEmpty) {
|
||||
var mimeType = lookupMimeType(request.requestedUri.path, headerBytes: body);
|
||||
if (mimeType != null) {
|
||||
contentType = mimeType.split('/');
|
||||
}
|
||||
}
|
||||
|
||||
request.response.headers.contentType = new ContentType(contentType[0], contentType[1], charset: 'utf-8');
|
||||
request.response.add(body);
|
||||
request.response.close();
|
||||
});
|
||||
|
||||
completer.complete();
|
||||
});
|
||||
}, onError: (e, stackTrace) => print('Error: $e $stackTrace'));
|
||||
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
///Closes the server.
|
||||
Future<void> close() async {
|
||||
if (this._server != null) {
|
||||
await this._server.close(force: true);
|
||||
print('Server running on http://localhost:$_port closed');
|
||||
this._server = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,819 @@
|
|||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
import 'types.dart';
|
||||
import 'in_app_browser.dart';
|
||||
import 'web_history.dart';
|
||||
import 'channel_manager.dart';
|
||||
|
||||
|
||||
///Initial [data] as a content for an [InAppWebView] instance, using [baseUrl] as the base URL for it.
|
||||
///The [mimeType] property specifies the format of the data.
|
||||
///The [encoding] property specifies the encoding of the data.
|
||||
class InAppWebViewInitialData {
|
||||
String data;
|
||||
String mimeType;
|
||||
String encoding;
|
||||
String baseUrl;
|
||||
|
||||
InAppWebViewInitialData(this.data, {this.mimeType = "text/html", this.encoding = "utf8", this.baseUrl = "about:blank"});
|
||||
|
||||
Map<String, String> toMap() {
|
||||
return {
|
||||
"data": data,
|
||||
"mimeType": mimeType,
|
||||
"encoding": encoding,
|
||||
"baseUrl": baseUrl
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
///InAppWebView Widget class.
|
||||
///
|
||||
///Flutter Widget for adding an **inline native WebView** integrated in the flutter widget tree.
|
||||
///
|
||||
///All platforms support these options:
|
||||
/// - __useShouldOverrideUrlLoading__: Set to `true` to be able to listen at the [InAppWebView.shouldOverrideUrlLoading()] event. The default value is `false`.
|
||||
/// - __useOnLoadResource__: Set to `true` to be able to listen at the [InAppWebView.onLoadResource()] event. The default value is `false`.
|
||||
/// - __useOnTargetBlank__: Set to `true` to be able to listen at the [InAppWebView.onTargetBlank()] event. The default value is `false`.
|
||||
/// - __clearCache__: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
|
||||
/// - __userAgent___: Set the custom WebView's user-agent.
|
||||
/// - __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`.
|
||||
/// - __javaScriptCanOpenWindowsAutomatically__: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
|
||||
/// - __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
|
||||
/// - __transparentBackground__: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
|
||||
/// - __resourceCustomSchemes__: List of custom schemes that [InAppWebView] must handle. Use the [InAppWebView.onLoadResourceCustomScheme()] event to intercept resource requests with custom scheme.
|
||||
///
|
||||
/// **Android** supports these additional options:
|
||||
///
|
||||
/// - __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
|
||||
/// - __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
|
||||
/// - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
|
||||
/// - __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
|
||||
/// - __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`.
|
||||
/// - __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`.
|
||||
/// - __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
|
||||
/// - __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`.
|
||||
/// - __textZoom__: Set text scaling of the WebView. The default value is `100`.
|
||||
/// - __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged.
|
||||
///
|
||||
/// **iOS** supports these additional options:
|
||||
///
|
||||
/// - __disallowOverScroll__: Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.
|
||||
/// - __enableViewportScale__: Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`.
|
||||
/// - __suppressesIncrementalRendering__: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory.. The default value is `false`.
|
||||
/// - __allowsAirPlayForMediaPlayback__: Set to `true` to allow AirPlay. The default value is `true`.
|
||||
/// - __allowsBackForwardNavigationGestures__: Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`.
|
||||
/// - __allowsLinkPreview__: Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`.
|
||||
/// - __ignoresViewportScaleLimits__: Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent. The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`.
|
||||
/// - __allowsInlineMediaPlayback__: Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the `webkit-playsinline` attribute to any `<video>` elements. The default value is `false`.
|
||||
/// - __allowsPictureInPictureMediaPlayback__: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
|
||||
class InAppWebView extends StatefulWidget {
|
||||
|
||||
///Event fires when the [InAppWebView] is created.
|
||||
final onWebViewCreatedCallback onWebViewCreated;
|
||||
|
||||
///Event fires when the [InAppWebView] starts to load an [url].
|
||||
final onWebViewLoadStartCallback onLoadStart;
|
||||
|
||||
///Event fires when the [InAppWebView] finishes loading an [url].
|
||||
final onWebViewLoadStopCallback onLoadStop;
|
||||
|
||||
///Event fires when the [InAppWebView] encounters an error loading an [url].
|
||||
final onWebViewLoadErrorCallback onLoadError;
|
||||
|
||||
///Event fires when the current [progress] of loading a page is changed.
|
||||
final onWebViewProgressChangedCallback onProgressChanged;
|
||||
|
||||
///Event fires when the [InAppWebView] receives a [ConsoleMessage].
|
||||
final onWebViewConsoleMessageCallback onConsoleMessage;
|
||||
|
||||
///Give the host application a chance to take control when a URL is about to be loaded in the current WebView.
|
||||
///
|
||||
///**NOTE**: In order to be able to listen this event, you need to set `useShouldOverrideUrlLoading` option to `true`.
|
||||
final shouldOverrideUrlLoadingCallback shouldOverrideUrlLoading;
|
||||
|
||||
///Event fires when the [InAppWebView] loads a resource.
|
||||
///
|
||||
///**NOTE**: In order to be able to listen this event, you need to set `useOnLoadResource` option to `true`.
|
||||
///
|
||||
///**NOTE only for iOS**: In some cases, the [response.data] of a [response] with `text/assets` encoding could be empty.
|
||||
final onWebViewLoadResourceCallback onLoadResource;
|
||||
|
||||
///Event fires when the [InAppWebView] scrolls.
|
||||
///[x] represents the current horizontal scroll origin in pixels.
|
||||
///[y] represents the current vertical scroll origin in pixels.
|
||||
final onWebViewScrollChangedCallback onScrollChanged;
|
||||
|
||||
///Event fires when [InAppWebView] recognizes and starts a downloadable file.
|
||||
///[url] represents the url of the file.
|
||||
final onDownloadStartCallback onDownloadStart;
|
||||
|
||||
///Event fires when the [InAppWebView] finds the `custom-scheme` while loading a resource. Here you can handle the url request and return a [CustomSchemeResponse] to load a specific resource encoded to `base64`.
|
||||
///[scheme] represents the scheme of the url.
|
||||
///[url] represents the url of the request.
|
||||
final onLoadResourceCustomSchemeCallback onLoadResourceCustomScheme;
|
||||
|
||||
///Event fires when the [InAppWebView] tries to open a link with `target="_blank"`.
|
||||
///[url] represents the url of the link.
|
||||
final onTargetBlankCallback onTargetBlank;
|
||||
|
||||
///Initial url that will be loaded.
|
||||
final String initialUrl;
|
||||
///Initial asset file that will be loaded. See [InAppWebView.loadFile()] for explanation.
|
||||
final String initialFile;
|
||||
///Initial [InAppWebViewInitialData] that will be loaded.
|
||||
final InAppWebViewInitialData initialData;
|
||||
///Initial headers that will be used.
|
||||
final Map<String, String> initialHeaders;
|
||||
///Initial options that will be used.
|
||||
final Map<String, dynamic> initialOptions;
|
||||
/// `gestureRecognizers` specifies which gestures should be consumed by the web view.
|
||||
/// It is possible for other gesture recognizers to be competing with the web view on pointer
|
||||
/// events, e.g if the web view is inside a [ListView] the [ListView] will want to handle
|
||||
/// vertical drags. The web view will claim gestures that are recognized by any of the
|
||||
/// recognizers on this list.
|
||||
/// When `gestureRecognizers` is empty or null, the web view will only handle pointer events for gestures that
|
||||
/// were not claimed by any other gesture recognizer.
|
||||
final Set<Factory<OneSequenceGestureRecognizer>> gestureRecognizers;
|
||||
|
||||
const InAppWebView({
|
||||
Key key,
|
||||
this.initialUrl = "about:blank",
|
||||
this.initialFile,
|
||||
this.initialData,
|
||||
this.initialHeaders = const {},
|
||||
this.initialOptions = const {},
|
||||
this.onWebViewCreated,
|
||||
this.onLoadStart,
|
||||
this.onLoadStop,
|
||||
this.onLoadError,
|
||||
this.onConsoleMessage,
|
||||
this.onProgressChanged,
|
||||
this.shouldOverrideUrlLoading,
|
||||
this.onLoadResource,
|
||||
this.onScrollChanged,
|
||||
this.onDownloadStart,
|
||||
this.onLoadResourceCustomScheme,
|
||||
this.onTargetBlank,
|
||||
this.gestureRecognizers,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_InAppWebViewState createState() => _InAppWebViewState();
|
||||
}
|
||||
|
||||
class _InAppWebViewState extends State<InAppWebView> {
|
||||
|
||||
InAppWebViewController _controller;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
if (_controller != null) {
|
||||
_controller._dispose();
|
||||
_controller = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
return GestureDetector(
|
||||
onLongPress: () {},
|
||||
excludeFromSemantics: true,
|
||||
child: AndroidView(
|
||||
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
||||
onPlatformViewCreated: _onPlatformViewCreated,
|
||||
gestureRecognizers: widget.gestureRecognizers,
|
||||
layoutDirection: TextDirection.rtl,
|
||||
creationParams: <String, dynamic>{
|
||||
'initialUrl': widget.initialUrl,
|
||||
'initialFile': widget.initialFile,
|
||||
'initialData': widget.initialData?.toMap(),
|
||||
'initialHeaders': widget.initialHeaders,
|
||||
'initialOptions': widget.initialOptions
|
||||
},
|
||||
creationParamsCodec: const StandardMessageCodec(),
|
||||
),
|
||||
);
|
||||
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
|
||||
return UiKitView(
|
||||
viewType: 'com.pichillilorenzo/flutter_inappwebview',
|
||||
onPlatformViewCreated: _onPlatformViewCreated,
|
||||
gestureRecognizers: widget.gestureRecognizers,
|
||||
creationParams: <String, dynamic>{
|
||||
'initialUrl': widget.initialUrl,
|
||||
'initialFile': widget.initialFile,
|
||||
'initialData': widget.initialData?.toMap(),
|
||||
'initialHeaders': widget.initialHeaders,
|
||||
'initialOptions': widget.initialOptions
|
||||
},
|
||||
creationParamsCodec: const StandardMessageCodec(),
|
||||
);
|
||||
}
|
||||
return Text(
|
||||
'$defaultTargetPlatform is not yet supported by the flutter_inappbrowser plugin');
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(InAppWebView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
void _onPlatformViewCreated(int id) {
|
||||
_controller = InAppWebViewController(id, widget);
|
||||
if (widget.onWebViewCreated != null) {
|
||||
widget.onWebViewCreated(_controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Controls an [InAppWebView] widget instance.
|
||||
///
|
||||
/// An [InAppWebViewController] instance can be obtained by setting the [InAppWebView.onWebViewCreated]
|
||||
/// callback for an [InAppWebView] widget.
|
||||
class InAppWebViewController {
|
||||
|
||||
InAppWebView _widget;
|
||||
MethodChannel _channel;
|
||||
Map<String, JavaScriptHandlerCallback> javaScriptHandlersMap = HashMap<String, JavaScriptHandlerCallback>();
|
||||
bool _isOpened = false;
|
||||
// ignore: unused_field
|
||||
int _id;
|
||||
String _inAppBrowserUuid;
|
||||
InAppBrowser _inAppBrowser;
|
||||
|
||||
|
||||
InAppWebViewController(int id, InAppWebView widget) {
|
||||
_id = id;
|
||||
_channel = MethodChannel('com.pichillilorenzo/flutter_inappwebview_$id');
|
||||
_channel.setMethodCallHandler(handleMethod);
|
||||
_widget = widget;
|
||||
}
|
||||
|
||||
InAppWebViewController.fromInAppBrowser(String uuid, MethodChannel channel, InAppBrowser inAppBrowser) {
|
||||
_inAppBrowserUuid = uuid;
|
||||
_channel = channel;
|
||||
_inAppBrowser = inAppBrowser;
|
||||
}
|
||||
|
||||
Future<dynamic> handleMethod(MethodCall call) async {
|
||||
switch(call.method) {
|
||||
case "onLoadStart":
|
||||
String url = call.arguments["url"];
|
||||
if (_widget != null && _widget.onLoadStart != null)
|
||||
_widget.onLoadStart(this, url);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onLoadStart(url);
|
||||
break;
|
||||
case "onLoadStop":
|
||||
String url = call.arguments["url"];
|
||||
if (_widget != null && _widget.onLoadStop != null)
|
||||
_widget.onLoadStop(this, url);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onLoadStop(url);
|
||||
break;
|
||||
case "onLoadError":
|
||||
String url = call.arguments["url"];
|
||||
int code = call.arguments["code"];
|
||||
String message = call.arguments["message"];
|
||||
if (_widget != null && _widget.onLoadError != null)
|
||||
_widget.onLoadError(this, url, code, message);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onLoadError(url, code, message);
|
||||
break;
|
||||
case "onProgressChanged":
|
||||
int progress = call.arguments["progress"];
|
||||
if (_widget != null && _widget.onProgressChanged != null)
|
||||
_widget.onProgressChanged(this, progress);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onProgressChanged(progress);
|
||||
break;
|
||||
case "shouldOverrideUrlLoading":
|
||||
String url = call.arguments["url"];
|
||||
if (_widget != null && _widget.shouldOverrideUrlLoading != null)
|
||||
_widget.shouldOverrideUrlLoading(this, url);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.shouldOverrideUrlLoading(url);
|
||||
break;
|
||||
case "onLoadResource":
|
||||
Map<dynamic, dynamic> rawResponse = call.arguments["response"];
|
||||
rawResponse = rawResponse.cast<String, dynamic>();
|
||||
Map<dynamic, dynamic> rawRequest = call.arguments["request"];
|
||||
rawRequest = rawRequest.cast<String, dynamic>();
|
||||
|
||||
String urlResponse = rawResponse["url"];
|
||||
Map<dynamic, dynamic> headersResponse = rawResponse["headers"];
|
||||
headersResponse = headersResponse.cast<String, String>();
|
||||
int statusCode = rawResponse["statusCode"];
|
||||
int startTime = rawResponse["startTime"];
|
||||
int duration = rawResponse["duration"];
|
||||
Uint8List data = rawResponse["data"];
|
||||
|
||||
String urlRequest = rawRequest["url"];
|
||||
Map<dynamic, dynamic> headersRequest = rawRequest["headers"];
|
||||
headersRequest = headersResponse.cast<String, String>();
|
||||
String method = rawRequest["method"];
|
||||
|
||||
var response = new WebResourceResponse(urlResponse, headersResponse, statusCode, startTime, duration, data);
|
||||
var request = new WebResourceRequest(urlRequest, headersRequest, method);
|
||||
|
||||
if (_widget != null && _widget.onLoadResource != null)
|
||||
_widget.onLoadResource(this, response, request);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onLoadResource(response, request);
|
||||
break;
|
||||
case "onConsoleMessage":
|
||||
String sourceURL = call.arguments["sourceURL"];
|
||||
int lineNumber = call.arguments["lineNumber"];
|
||||
String message = call.arguments["message"];
|
||||
ConsoleMessageLevel messageLevel;
|
||||
ConsoleMessageLevel.values.forEach((element) {
|
||||
if ("ConsoleMessageLevel." + call.arguments["messageLevel"] == element.toString()) {
|
||||
messageLevel = element;
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (_widget != null && _widget.onConsoleMessage != null)
|
||||
_widget.onConsoleMessage(this, ConsoleMessage(sourceURL, lineNumber, message, messageLevel));
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onConsoleMessage(ConsoleMessage(sourceURL, lineNumber, message, messageLevel));
|
||||
break;
|
||||
case "onScrollChanged":
|
||||
int x = call.arguments["x"];
|
||||
int y = call.arguments["y"];
|
||||
if (_widget != null && _widget.onScrollChanged != null)
|
||||
_widget.onScrollChanged(this, x, y);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onScrollChanged(x, y);
|
||||
break;
|
||||
case "onDownloadStart":
|
||||
String url = call.arguments["url"];
|
||||
if (_widget != null && _widget.onDownloadStart != null)
|
||||
_widget.onDownloadStart(this, url);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onDownloadStart(url);
|
||||
break;
|
||||
case "onLoadResourceCustomScheme":
|
||||
String scheme = call.arguments["scheme"];
|
||||
String url = call.arguments["url"];
|
||||
if (_widget != null && _widget.onLoadResourceCustomScheme != null) {
|
||||
try {
|
||||
var response = await _widget.onLoadResourceCustomScheme(this, scheme, url);
|
||||
return (response != null) ? response.toJson(): null;
|
||||
} catch (error) {
|
||||
print(error);
|
||||
return null;
|
||||
}
|
||||
} else if (_inAppBrowser != null) {
|
||||
try {
|
||||
var response = await _inAppBrowser.onLoadResourceCustomScheme(scheme, url);
|
||||
return (response != null) ? response.toJson(): null;
|
||||
} catch (error) {
|
||||
print(error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "onTargetBlank":
|
||||
String url = call.arguments["url"];
|
||||
if (_widget != null && _widget.onTargetBlank != null)
|
||||
_widget.onTargetBlank(this, url);
|
||||
else if (_inAppBrowser != null)
|
||||
_inAppBrowser.onTargetBlank(url);
|
||||
break;
|
||||
case "onCallJsHandler":
|
||||
String handlerName = call.arguments["handlerName"];
|
||||
// decode args to json
|
||||
List<dynamic> args = jsonDecode(call.arguments["args"]);
|
||||
if (javaScriptHandlersMap.containsKey(handlerName)) {
|
||||
// convert result to json
|
||||
try {
|
||||
return jsonEncode(await javaScriptHandlersMap[handlerName](args));
|
||||
} catch (error) {
|
||||
print(error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw UnimplementedError("Unimplemented ${call.method} method");
|
||||
}
|
||||
}
|
||||
|
||||
///Gets the URL for the current page.
|
||||
///This is not always the same as the URL passed to [InAppWebView.onLoadStarted] because although the load for that URL has begun, the current page may not have changed.
|
||||
Future<String> getUrl() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('getUrl', args);
|
||||
}
|
||||
|
||||
///Gets the title for the current page.
|
||||
Future<String> getTitle() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('getTitle', args);
|
||||
}
|
||||
|
||||
///Gets the progress for the current page. The progress value is between 0 and 100.
|
||||
Future<int> getProgress() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('getProgress', args);
|
||||
}
|
||||
|
||||
///Gets the favicon for the current page.
|
||||
Future<List<int>> getFavicon() async {
|
||||
var completer = new Completer<List<int>>();
|
||||
var faviconData = new List<int>();
|
||||
HttpClient client = new HttpClient();
|
||||
var url = Uri.parse(await getUrl());
|
||||
// solution found here: https://stackoverflow.com/a/15750809/4637638
|
||||
var faviconUrl = Uri.parse("https://plus.google.com/_/favicon?domain_url=" + url.scheme + "://" + url.host);
|
||||
|
||||
client.getUrl(faviconUrl).then((HttpClientRequest request) {
|
||||
return request.close();
|
||||
}).then((HttpClientResponse response) {
|
||||
response.listen((List<int> data) {
|
||||
faviconData = data;
|
||||
}, onDone: () => completer.complete(faviconData));
|
||||
});
|
||||
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
///Loads the given [url] with optional [headers] specified as a map from name to value.
|
||||
Future<void> loadUrl(String url, {Map<String, String> headers = const {}}) async {
|
||||
assert(url != null && url.isNotEmpty);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened(message: 'Cannot laod $url!');
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('headers', () => headers);
|
||||
await _channel.invokeMethod('loadUrl', args);
|
||||
}
|
||||
|
||||
///Loads the given [url] with [postData] using `POST` method into this WebView.
|
||||
Future<void> postUrl(String url, Uint8List postData) async {
|
||||
assert(url != null && url.isNotEmpty);
|
||||
assert(postData != null);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened(message: 'Cannot laod $url!');
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('url', () => url);
|
||||
args.putIfAbsent('postData', () => postData);
|
||||
await _channel.invokeMethod('postUrl', args);
|
||||
}
|
||||
|
||||
///Loads the given [data] into this WebView, using [baseUrl] as the base URL for the content.
|
||||
///The [mimeType] parameter specifies the format of the data.
|
||||
///The [encoding] parameter specifies the encoding of the data.
|
||||
Future<void> loadData(String data, {String mimeType = "text/html", String encoding = "utf8", String baseUrl = "about:blank"}) async {
|
||||
assert(data != null);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('data', () => data);
|
||||
args.putIfAbsent('mimeType', () => mimeType);
|
||||
args.putIfAbsent('encoding', () => encoding);
|
||||
args.putIfAbsent('baseUrl', () => baseUrl);
|
||||
await _channel.invokeMethod('loadData', args);
|
||||
}
|
||||
|
||||
///Loads the given [assetFilePath] with optional [headers] specified as a map from name to value.
|
||||
///
|
||||
///To be able to load your local files (assets, js, css, etc.), you need to add them in the `assets` section of the `pubspec.yaml` file, otherwise they cannot be found!
|
||||
///
|
||||
///Example of a `pubspec.yaml` file:
|
||||
///```yaml
|
||||
///...
|
||||
///
|
||||
///# The following section is specific to Flutter.
|
||||
///flutter:
|
||||
///
|
||||
/// # The following line ensures that the Material Icons font is
|
||||
/// # included with your application, so that you can use the icons in
|
||||
/// # the material Icons class.
|
||||
/// uses-material-design: true
|
||||
///
|
||||
/// assets:
|
||||
/// - assets/index.html
|
||||
/// - assets/css/
|
||||
/// - assets/images/
|
||||
///
|
||||
///...
|
||||
///```
|
||||
///Example of a `main.dart` file:
|
||||
///```dart
|
||||
///...
|
||||
///inAppBrowser.loadFile("assets/index.html");
|
||||
///...
|
||||
///```
|
||||
Future<void> loadFile(String assetFilePath, {Map<String, String> headers = const {}}) async {
|
||||
assert(assetFilePath != null && assetFilePath.isNotEmpty);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened(message: 'Cannot laod $assetFilePath!');
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('url', () => assetFilePath);
|
||||
args.putIfAbsent('headers', () => headers);
|
||||
await _channel.invokeMethod('loadFile', args);
|
||||
}
|
||||
|
||||
///Reloads the [InAppWebView] window.
|
||||
Future<void> reload() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
await _channel.invokeMethod('reload', args);
|
||||
}
|
||||
|
||||
///Goes back in the history of the [InAppWebView] window.
|
||||
Future<void> goBack() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
await _channel.invokeMethod('goBack', args);
|
||||
}
|
||||
|
||||
///Returns a boolean value indicating whether the [InAppWebView] can move backward.
|
||||
Future<bool> canGoBack() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('canGoBack', args);
|
||||
}
|
||||
|
||||
///Goes forward in the history of the [InAppWebView] window.
|
||||
Future<void> goForward() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
await _channel.invokeMethod('goForward', args);
|
||||
}
|
||||
|
||||
///Returns a boolean value indicating whether the [InAppWebView] can move forward.
|
||||
Future<bool> canGoForward() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('canGoForward', args);
|
||||
}
|
||||
|
||||
///Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.
|
||||
Future<void> goBackOrForward(int steps) async {
|
||||
assert(steps != null);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('steps', () => steps);
|
||||
await _channel.invokeMethod('goBackOrForward', args);
|
||||
}
|
||||
|
||||
///Returns a boolean value indicating whether the [InAppWebView] can go back or forward the given number of steps. Steps is negative if backward and positive if forward.
|
||||
Future<bool> canGoBackOrForward(int steps) async {
|
||||
assert(steps != null);
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('steps', () => steps);
|
||||
return await _channel.invokeMethod('canGoBackOrForward', args);
|
||||
}
|
||||
|
||||
///Navigates to a [WebHistoryItem] from the back-forward [WebHistory.list] and sets it as the current item.
|
||||
Future<void> goTo(WebHistoryItem historyItem) async {
|
||||
await goBackOrForward(historyItem.offset);
|
||||
}
|
||||
|
||||
///Check if the Web View of the [InAppWebView] instance is in a loading state.
|
||||
Future<bool> isLoading() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('isLoading', args);
|
||||
}
|
||||
|
||||
///Stops the Web View of the [InAppWebView] instance from loading.
|
||||
Future<void> stopLoading() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
await _channel.invokeMethod('stopLoading', args);
|
||||
}
|
||||
|
||||
///Injects JavaScript code into the [InAppWebView] window and returns the result of the evaluation.
|
||||
Future<String> injectScriptCode(String source) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('source', () => source);
|
||||
return await _channel.invokeMethod('injectScriptCode', args);
|
||||
}
|
||||
|
||||
///Injects a JavaScript file into the [InAppWebView] window.
|
||||
Future<void> injectScriptFile(String urlFile) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('urlFile', () => urlFile);
|
||||
await _channel.invokeMethod('injectScriptFile', args);
|
||||
}
|
||||
|
||||
///Injects CSS into the [InAppWebView] window.
|
||||
Future<void> injectStyleCode(String source) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('source', () => source);
|
||||
await _channel.invokeMethod('injectStyleCode', args);
|
||||
}
|
||||
|
||||
///Injects a CSS file into the [InAppWebView] window.
|
||||
Future<void> injectStyleFile(String urlFile) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('urlFile', () => urlFile);
|
||||
await _channel.invokeMethod('injectStyleFile', args);
|
||||
}
|
||||
|
||||
///Adds a JavaScript message handler [callback] ([JavaScriptHandlerCallback]) that listen to post messages sent from JavaScript by the handler with name [handlerName].
|
||||
///
|
||||
///The Android implementation uses [addJavascriptInterface](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)).
|
||||
///The iOS implementation uses [addScriptMessageHandler](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537172-addscriptmessagehandler?language=objc)
|
||||
///
|
||||
///The JavaScript function that can be used to call the handler is `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)`, where `args` are [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
|
||||
///The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
|
||||
///
|
||||
///In order to call `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)` properly, you need to wait and listen the JavaScript event `flutterInAppBrowserPlatformReady`.
|
||||
///This event will be dispatch as soon as the platform (Android or iOS) is ready to handle the `callHandler` method.
|
||||
///```javascript
|
||||
/// window.addEventListener("flutterInAppBrowserPlatformReady", function(event) {
|
||||
/// console.log("ready");
|
||||
/// });
|
||||
///```
|
||||
///
|
||||
///`window.flutter_inappbrowser.callHandler` returns a JavaScript [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
||||
///that can be used to get the json result returned by [JavaScriptHandlerCallback].
|
||||
///In this case, simply return data that you want to send and it will be automatically json encoded using [jsonEncode] from the `dart:convert` library.
|
||||
///
|
||||
///So, on the JavaScript side, to get data coming from the Dart side, you will use:
|
||||
///```html
|
||||
///<script>
|
||||
/// window.addEventListener("flutterInAppBrowserPlatformReady", function(event) {
|
||||
/// window.flutter_inappbrowser.callHandler('handlerFoo').then(function(result) {
|
||||
/// console.log(result, typeof result);
|
||||
/// console.log(JSON.stringify(result));
|
||||
/// });
|
||||
///
|
||||
/// window.flutter_inappbrowser.callHandler('handlerFooWithArgs', 1, true, ['bar', 5], {foo: 'baz'}).then(function(result) {
|
||||
/// console.log(result, typeof result);
|
||||
/// console.log(JSON.stringify(result));
|
||||
/// });
|
||||
/// });
|
||||
///</script>
|
||||
///```
|
||||
///
|
||||
///Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
|
||||
///```dart
|
||||
/// // Inject JavaScript that will receive data back from Flutter
|
||||
/// inAppWebViewController.injectScriptCode("""
|
||||
/// window.flutter_inappbrowser.callHandler('test', 'Text from Javascript').then(function(result) {
|
||||
/// console.log(result);
|
||||
/// });
|
||||
/// """);
|
||||
///```
|
||||
void addJavaScriptHandler(String handlerName, JavaScriptHandlerCallback callback) {
|
||||
this.javaScriptHandlersMap[handlerName] = (callback);
|
||||
}
|
||||
|
||||
///Removes a JavaScript message handler previously added with the [addJavaScriptHandler()] associated to [handlerName] key.
|
||||
///Returns the value associated with [handlerName] before it was removed.
|
||||
///Returns `null` if [handlerName] was not found.
|
||||
JavaScriptHandlerCallback removeJavaScriptHandler(String handlerName) {
|
||||
return this.javaScriptHandlersMap.remove(handlerName);
|
||||
}
|
||||
|
||||
///Takes a screenshot (in PNG format) of the WebView's visible viewport and returns a `Uint8List`. Returns `null` if it wasn't be able to take it.
|
||||
///__safeBrowsingEnabled__
|
||||
///**NOTE for iOS**: available from iOS 11.0+.
|
||||
Future<Uint8List> takeScreenshot() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
return await _channel.invokeMethod('takeScreenshot', args);
|
||||
}
|
||||
|
||||
///Sets the [InAppWebView] options with the new [options] and evaluates them.
|
||||
Future<void> setOptions(Map<String, dynamic> options) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('options', () => options);
|
||||
args.putIfAbsent('optionsType', () => "InAppBrowserOptions");
|
||||
await _channel.invokeMethod('setOptions', args);
|
||||
}
|
||||
|
||||
///Gets the current [InAppWebView] options. Returns `null` if the options are not setted yet.
|
||||
Future<Map<String, dynamic>> getOptions() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
args.putIfAbsent('optionsType', () => "InAppBrowserOptions");
|
||||
Map<dynamic, dynamic> options = await ChannelManager.channel.invokeMethod('getOptions', args);
|
||||
options = options.cast<String, dynamic>();
|
||||
return options;
|
||||
}
|
||||
|
||||
///Gets the WebHistory for this WebView. This contains the back/forward list for use in querying each item in the history stack.
|
||||
///This contains only a snapshot of the current state.
|
||||
///Multiple calls to this method may return different objects.
|
||||
///The object returned from this method will not be updated to reflect any new state.
|
||||
Future<WebHistory> getCopyBackForwardList() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
if (_inAppBrowserUuid != null && _inAppBrowser != null) {
|
||||
_inAppBrowser.throwIsNotOpened();
|
||||
args.putIfAbsent('uuid', () => _inAppBrowserUuid);
|
||||
}
|
||||
Map<dynamic, dynamic> result = await _channel.invokeMethod('getCopyBackForwardList', args);
|
||||
result = result.cast<String, dynamic>();
|
||||
|
||||
List<dynamic> historyListMap = result["history"];
|
||||
historyListMap = historyListMap.cast<LinkedHashMap<dynamic, dynamic>>();
|
||||
|
||||
int currentIndex = result["currentIndex"];
|
||||
|
||||
List<WebHistoryItem> historyList = List();
|
||||
for(var i = 0; i < historyListMap.length; i++) {
|
||||
LinkedHashMap<dynamic, dynamic> historyItem = historyListMap[i];
|
||||
historyList.add(WebHistoryItem(historyItem["originalUrl"], historyItem["title"], historyItem["url"], i, i - currentIndex));
|
||||
}
|
||||
return WebHistory(historyList, currentIndex);
|
||||
}
|
||||
///Dispose/Destroy the WebView.
|
||||
Future<void> _dispose() async {
|
||||
await _channel.invokeMethod('dispose');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'in_app_webview.dart' show InAppWebViewController;
|
||||
|
||||
var uuidGenerator = new Uuid();
|
||||
|
||||
typedef Future<dynamic> ListenerCallback(MethodCall call);
|
||||
|
||||
///This type represents a callback, added with [addJavaScriptHandler], that listens to post messages sent from JavaScript.
|
||||
///
|
||||
///The Android implementation uses [addJavascriptInterface](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)).
|
||||
///The iOS implementation uses [addScriptMessageHandler](https://developer.apple.com/documentation/webkit/wkusercontentcontroller/1537172-addscriptmessagehandler?language=objc)
|
||||
///
|
||||
///The JavaScript function that can be used to call the handler is `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args);`, where `args` are [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
|
||||
///The `args` will be stringified automatically using `JSON.stringify(args)` method and then they will be decoded on the Dart side.
|
||||
///
|
||||
///Also, a [JavaScriptHandlerCallback] can return json data to the JavaScript side.
|
||||
///In this case, simply return data that you want to send and it will be automatically json encoded using [jsonEncode] from the `dart:convert` library.
|
||||
typedef dynamic JavaScriptHandlerCallback(List<dynamic> arguments);
|
||||
|
||||
///Enum representing the level of a console message.
|
||||
enum ConsoleMessageLevel {
|
||||
DEBUG, ERROR, LOG, TIP, WARNING
|
||||
}
|
||||
|
||||
///Public class representing a resource request of the [InAppBrowser] WebView.
|
||||
///It is used by the method [InAppBrowser.onLoadResource()].
|
||||
class WebResourceRequest {
|
||||
|
||||
String url;
|
||||
Map<String, String> headers;
|
||||
String method;
|
||||
|
||||
WebResourceRequest(this.url, this.headers, this.method);
|
||||
|
||||
}
|
||||
|
||||
///Public class representing a resource response of the [InAppBrowser] WebView.
|
||||
///It is used by the method [InAppBrowser.onLoadResource()].
|
||||
class WebResourceResponse {
|
||||
|
||||
String url;
|
||||
Map<String, String> headers;
|
||||
int statusCode;
|
||||
int startTime;
|
||||
int duration;
|
||||
Uint8List data;
|
||||
|
||||
WebResourceResponse(this.url, this.headers, this.statusCode, this.startTime, this.duration, this.data);
|
||||
|
||||
}
|
||||
|
||||
///Public class representing the response returned by the [onLoadResourceCustomScheme()] event of [InAppWebView].
|
||||
///It allows to load a specific resource. The resource data must be encoded to `base64`.
|
||||
class CustomSchemeResponse {
|
||||
String base64data;
|
||||
String contentType;
|
||||
String contentEnconding;
|
||||
|
||||
CustomSchemeResponse(this.base64data, this.contentType, this.contentEnconding);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'content-type': this.contentType,
|
||||
'content-encoding': this.contentEnconding,
|
||||
'base64data': this.base64data
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
///Public class representing a JavaScript console message from WebCore.
|
||||
///This could be a issued by a call to one of the console logging functions (e.g. console.log('...')) or a JavaScript error on the page.
|
||||
///
|
||||
///To receive notifications of these messages, override the [InAppBrowser.onConsoleMessage()] function.
|
||||
class ConsoleMessage {
|
||||
|
||||
String sourceURL = "";
|
||||
int lineNumber = 1;
|
||||
String message = "";
|
||||
ConsoleMessageLevel messageLevel = ConsoleMessageLevel.LOG;
|
||||
|
||||
ConsoleMessage(this.sourceURL, this.lineNumber, this.message, this.messageLevel);
|
||||
}
|
||||
|
||||
typedef onWebViewCreatedCallback = void Function(InAppWebViewController controller);
|
||||
typedef onWebViewLoadStartCallback = void Function(InAppWebViewController controller, String url);
|
||||
typedef onWebViewLoadStopCallback = void Function(InAppWebViewController controller, String url);
|
||||
typedef onWebViewLoadErrorCallback = void Function(InAppWebViewController controller, String url, int code, String message);
|
||||
typedef onWebViewProgressChangedCallback = void Function(InAppWebViewController controller, int progress);
|
||||
typedef onWebViewConsoleMessageCallback = void Function(InAppWebViewController controller, ConsoleMessage consoleMessage);
|
||||
typedef shouldOverrideUrlLoadingCallback = void Function(InAppWebViewController controller, String url);
|
||||
typedef onWebViewLoadResourceCallback = void Function(InAppWebViewController controller, WebResourceResponse response, WebResourceRequest request);
|
||||
typedef onWebViewScrollChangedCallback = void Function(InAppWebViewController controller, int x, int y);
|
||||
typedef onDownloadStartCallback = void Function(InAppWebViewController controller, String url);
|
||||
typedef onLoadResourceCustomSchemeCallback = Future<CustomSchemeResponse> Function(InAppWebViewController controller, String scheme, String url);
|
||||
typedef onTargetBlankCallback = void Function(InAppWebViewController controller, String url);
|
|
@ -0,0 +1,30 @@
|
|||
///WebHistory class.
|
||||
///
|
||||
///This class contains a snapshot of the current back/forward list for a WebView.
|
||||
class WebHistory {
|
||||
List<WebHistoryItem> _list;
|
||||
///List of all [WebHistoryItem]s.
|
||||
List<WebHistoryItem> get list => _list;
|
||||
///Index of the current [WebHistoryItem].
|
||||
int currentIndex;
|
||||
|
||||
WebHistory(this._list, this.currentIndex);
|
||||
}
|
||||
|
||||
///WebHistoryItem class.
|
||||
///
|
||||
///A convenience class for accessing fields in an entry in the back/forward list of a WebView. Each WebHistoryItem is a snapshot of the requested history item.
|
||||
class WebHistoryItem {
|
||||
///Original url of this history item.
|
||||
String originalUrl;
|
||||
///Document title of this history item.
|
||||
String title;
|
||||
///Url of this history item.
|
||||
String url;
|
||||
///0-based position index in the back-forward [WebHistory.list].
|
||||
int index;
|
||||
///Position offset respect to the currentIndex of the back-forward [WebHistory.list].
|
||||
int offset;
|
||||
|
||||
WebHistoryItem(this.originalUrl, this.title, this.url, this.index, this.offset);
|
||||
}
|
Loading…
Reference in New Issue