From 5fc1d405d3fa108f3a1cba24f0979cf40ff60689 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli <pichillilorenzo@gmail.com> Date: Fri, 25 Oct 2019 03:21:03 +0200 Subject: [PATCH] updated plugin version, added new options to hide/show scrollbars #165, initial support for DownloadManager in Android and iOS --- .idea/workspace.xml | 216 +++++++----------- CHANGELOG.md | 11 + README.md | 1 - android/src/main/AndroidManifest.xml | 1 + .../InAppWebView/InAppWebView.java | 113 ++++++--- .../InAppWebView/InAppWebViewOptions.java | 2 + .../RequestPermissionHandler.java | 2 + example/lib/inline_example.screen.dart | 4 +- ios/Classes/InAppWebView.swift | 86 ++++++- ios/Classes/InAppWebViewOptions.swift | 2 + pubspec.yaml | 4 +- 11 files changed, 268 insertions(+), 174 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8c01449..07de65f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -16,62 +16,16 @@ <component name="ChangeListManager"> <list default="true" id="9b41f7a2-a71e-4923-91fb-249d7815b3e7" name="Default" comment=""> <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$/example/ios/Flutter/AppFrameworkInfo.plist" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Flutter/AppFrameworkInfo.plist" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Flutter/Debug.xcconfig" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Flutter/Debug.xcconfig" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Flutter/Release.xcconfig" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Flutter/Release.xcconfig" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Podfile" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Podfile" 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.xcodeproj/project.xcworkspace/contents.xcworkspacedata" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/contents.xcworkspacedata" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/contents.xcworkspacedata" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings" 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/Assets.xcassets/AppIcon.appiconset/Contents.json" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/Contents.json" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/Contents.json" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Base.lproj/LaunchScreen.storyboard" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Base.lproj/LaunchScreen.storyboard" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/example/ios/Runner/Base.lproj/Main.storyboard" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/Runner/Base.lproj/Main.storyboard" 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$/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/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/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$/example/lib/inline_example.screen.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/inline_example.screen.dart" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/ios/.gitignore" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Assets/.gitkeep" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Assets/.gitkeep" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/FlutterWebViewController.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/FlutterWebViewController.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/FlutterWebViewFactory.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/FlutterWebViewFactory.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserFlutterPlugin.h" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserFlutterPlugin.h" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserFlutterPlugin.m" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserFlutterPlugin.m" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserOptions.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserOptions.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ios/Classes/InAppWebView.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppWebView.swift" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ios/Classes/InAppWebViewOptions.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/InAppWebViewOptions.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/MyCookieManager.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/MyCookieManager.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/Options.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/Options.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/SafariBrowserOptions.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/SafariBrowserOptions.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/SafariViewController.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/SafariViewController.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/SwiftFlutterPlugin.swift" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/Storyboards/WebView.storyboard" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Storyboards/WebView.storyboard" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" beforeDir="false" afterPath="$PROJECT_DIR$/ios/flutter_inappbrowser.podspec" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.yaml" afterDir="false" /> </list> <ignored path="$PROJECT_DIR$/.dart_tool/" /> <ignored path="$PROJECT_DIR$/.idea/" /> @@ -94,17 +48,17 @@ <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="55"> - <caret line="24" selection-start-line="24" selection-end-line="24" /> + <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="true"> + <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="176"> - <caret line="73" column="187" selection-start-line="73" selection-start-column="187" selection-end-line="73" selection-end-column="187" /> + <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" /> @@ -113,11 +67,11 @@ </provider> </entry> </file> - <file pinned="false" current-in-tab="false"> + <file pinned="false" current-in-tab="true"> <entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="229"> - <caret line="48" column="75" selection-start-line="48" selection-start-column="75" selection-end-line="48" selection-end-column="86" /> + <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" /> <folding> <element signature="e#0#39#0" expanded="true" /> </folding> @@ -126,10 +80,10 @@ </entry> </file> <file pinned="false" current-in-tab="false"> - <entry file="file://$PROJECT_DIR$/ios/flutter_inappbrowser.podspec"> + <entry file="file://$PROJECT_DIR$/CHANGELOG.md"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="345"> - <caret line="23" selection-start-line="23" selection-end-line="23" /> + <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> @@ -145,7 +99,6 @@ </component> <component name="FindInProjectRecents"> <findStrings> - <find>openFile</find> <find>File</find> <find>onExit</find> <find>_handleMethod</find> @@ -175,6 +128,7 @@ <find>_dispose</find> <find>UIImagePNGRepresentation</find> <find>png</find> + <find>cordova</find> </findStrings> <replaceStrings> <replace>activity.getPreferences(0)</replace> @@ -193,7 +147,6 @@ <option name="CHANGED_PATHS"> <list> <option value="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutterwebview/WebViewActivity.java" /> - <option value="$PROJECT_DIR$/android/src/main/AndroidManifest.xml" /> <option value="$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutterwebview/FlutterWebviewPlugin.java" /> <option value="$PROJECT_DIR$/lib/flutter_webview.dart" /> <option value="$PROJECT_DIR$/example/ios/Flutter/Debug.xcconfig" /> @@ -223,24 +176,25 @@ <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$/pubspec.yaml" /> <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$/CHANGELOG.md" /> <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$/example/lib/inline_example.screen.dart" /> + <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$/example/lib/inline_example.screen.dart" /> </list> </option> </component> <component name="ProjectFrameBounds" extendedState="6"> <option name="y" value="23" /> <option name="width" value="1920" /> - <option name="height" value="1027" /> + <option name="height" value="1057" /> </component> <component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectView"> @@ -248,36 +202,6 @@ <foldersAlwaysOnTop value="true" /> </navigator> <panes> - <pane id="AndroidView"> - <subPane> - <expand> - <path> - <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> - <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> - </path> - <path> - <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> - <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> - <item name="java" type="f7eae187:NonAndroidSourceTypeNode" /> - </path> - <path> - <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> - <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> - <item name="java" type="f7eae187:NonAndroidSourceTypeNode" /> - <item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" /> - </path> - <path> - <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> - <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> - <item name="java" type="f7eae187:NonAndroidSourceTypeNode" /> - <item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" /> - <item name="InAppWebView" type="462c0819:PsiDirectoryNode" /> - </path> - </expand> - <select /> - </subPane> - </pane> - <pane id="PackagesPane" /> <pane id="ProjectPane"> <subPane> <expand> @@ -288,13 +212,13 @@ <path> <item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" /> <item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" /> - <item name="ios" 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="ios" type="462c0819:PsiDirectoryNode" /> - <item name="Assets" type="462c0819:PsiDirectoryNode" /> + <item name="android" type="462c0819:PsiDirectoryNode" /> + <item name="main" type="462c0819:PsiDirectoryNode" /> </path> <path> <item name="flutter_inappbrowser" type="b2602c69:ProjectViewProjectNode" /> @@ -305,6 +229,7 @@ <select /> </subPane> </pane> + <pane id="PackagesPane" /> <pane id="Scope"> <subPane subId="Project Files"> <expand> @@ -316,6 +241,35 @@ <select /> </subPane> </pane> + <pane id="AndroidView"> + <subPane> + <expand> + <path> + <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> + <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> + </path> + <path> + <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> + <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> + <item name="java" type="f7eae187:NonAndroidSourceTypeNode" /> + </path> + <path> + <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> + <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> + <item name="java" type="f7eae187:NonAndroidSourceTypeNode" /> + <item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" /> + </path> + <path> + <item name="flutter_inappbrowser" type="1abcf292:AndroidViewProjectNode" /> + <item name="flutter_inappbrowser_android" type="e9137016:NonAndroidModuleNode" /> + <item name="java" type="f7eae187:NonAndroidSourceTypeNode" /> + <item name="flutter_inappbrowser" type="462c0819:PsiDirectoryNode" /> + <item name="InAppWebView" type="462c0819:PsiDirectoryNode" /> + </path> + </expand> + <select /> + </subPane> + </pane> </panes> </component> <component name="PropertiesComponent"> @@ -466,8 +420,8 @@ <frame x="0" y="23" width="1920" height="1057" extended-state="6" /> <editor active="true" /> <layout> - <window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.61403507" visible="true" weight="0.15867944" /> - <window_info id="Structure" order="1" sideWeight="0.3859649" side_tool="true" visible="true" weight="0.15867944" /> + <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 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" /> @@ -477,7 +431,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 anchor="bottom" id="Run" order="2" sideWeight="0.49478307" weight="0.36791444" /> + <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="Cvs" order="4" weight="0.25" /> <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> @@ -485,7 +439,7 @@ <window_info anchor="bottom" id="Android Profiler" order="7" show_stripe_button="false" /> <window_info anchor="bottom" id="Event Log" order="8" sideWeight="0.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.2919786" /> + <window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.49533224" weight="0.2911917" /> <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="Dependency Viewer" order="13" weight="0.32800853" /> @@ -513,9 +467,6 @@ </ignored-roots> </component> <component name="editorHistoryManager"> - <entry file="file://$PROJECT_DIR$/example/ios/Pods/Target Support Files/flutter_inappbrowser/flutter_inappbrowser-prefix.pch"> - <provider selected="true" editor-type-id="text-editor" /> - </entry> <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> @@ -525,13 +476,7 @@ <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"> - <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="255"> - <caret line="17" column="24" selection-start-line="17" selection-start-column="24" selection-end-line="17" selection-end-column="24" /> - </state> - </provider> - </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"> @@ -742,13 +687,6 @@ </state> </provider> </entry> - <entry file="file://$PROJECT_DIR$/CHANGELOG.md"> - <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="90"> - <caret line="6" column="17" selection-start-line="6" selection-start-column="17" selection-end-line="6" selection-end-column="17" /> - </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"> @@ -773,30 +711,44 @@ </state> </provider> </entry> - <entry file="file://$PROJECT_DIR$/example/lib/inline_example.screen.dart"> + <entry file="file://$PROJECT_DIR$/README.md"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="229"> - <caret line="48" column="75" selection-start-line="48" selection-start-column="75" selection-end-line="48" selection-end-column="86" /> + <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="55"> - <caret line="24" selection-start-line="24" selection-end-line="24" /> + <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$/README.md"> + <entry file="file://$PROJECT_DIR$/android/src/main/AndroidManifest.xml"> <provider selected="true" editor-type-id="text-editor"> - <state relative-caret-position="176"> - <caret line="73" column="187" selection-start-line="73" selection-start-column="187" selection-end-line="73" selection-end-column="187" /> + <state relative-caret-position="180"> + <caret line="12" column="11" selection-start-line="12" selection-start-column="11" selection-end-line="12" selection-end-column="11" /> + </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="267"> + <caret line="57" column="12" selection-start-line="57" selection-start-column="12" selection-end-line="57" selection-end-column="12" /> <folding> <element signature="e#0#39#0" expanded="true" /> - <element signature="e#0#39#0" expanded="true" /> </folding> </state> </provider> diff --git a/CHANGELOG.md b/CHANGELOG.md index fb1f7af..ea07554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 1.3.0 + +- Merge +- Merge +- Merge +- Merge +- Merge +- Merge +- Added `horizontalScrollBarEnabled` and `verticalScrollBarEnabled` options to enable/disable the corresponding scrollbar of the WebView [#165](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/165) + + ## 1.2.1 - Merge "Add new option to control the contentMode in Android platform" [#101](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/101) (thanks to [DreamBuddy](https://github.com/DreamBuddy)) diff --git a/README.md b/README.md index 1a1b672..9caeb11 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ [](https://www.patreon.com/bePatron?u=9269604) A Flutter plugin that allows you to add an inline webview or open an in-app browser window. -This plugin is inspired by the popular [cordova-plugin-inappbrowser](https://github.com/apache/cordova-plugin-inappbrowser)! ### Requirements - Dart sdk: ">=2.1.0-dev.7.1 <3.0.0" diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index aaa8e93..3245b43 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ package="com.pichillilorenzo.flutter_inappbrowser"> <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application> <activity android:theme="@style/AppTheme" android:name=".InAppBrowserActivity" android:configChanges="orientation|screenSize"></activity> diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java index d5b9129..79d4e58 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java @@ -1,16 +1,26 @@ 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; @@ -21,6 +31,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.RequestPermissionHandler; import com.pichillilorenzo.flutter_inappbrowser.Util; import java.io.ByteArrayOutputStream; @@ -36,6 +47,8 @@ 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"; @@ -110,6 +123,8 @@ public class InAppWebView extends WebView { public void prepare() { + final Activity activity = (inAppBrowserActivity != null) ? inAppBrowserActivity : registrar.activity(); + boolean isFromInAppBrowserActivity = inAppBrowserActivity != null; httpClient = new OkHttpClient().newBuilder().cache(new Cache(getContext().getCacheDir(), okHttpClientCacheSize)).build(); @@ -122,39 +137,43 @@ public class InAppWebView extends WebView { inAppWebViewClient = new InAppWebViewClient((isFromInAppBrowserActivity) ? inAppBrowserActivity : flutterWebView); setWebViewClient(inAppWebViewClient); -// final Activity activity = this; -// -// webView.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(){ -// 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) 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(); -// } -// } -// }); -// } -// }); + 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(); + } + } + }); + } + }); WebSettings settings = getSettings(); @@ -187,6 +206,8 @@ public class InAppWebView extends WebView { settings.setUseWideViewPort(options.useWideViewPort); settings.setSupportZoom(options.supportZoom); settings.setTextZoom(options.textZoom); + setVerticalScrollBarEnabled(options.verticalScrollBarEnabled); + setHorizontalScrollBarEnabled(options.horizontalScrollBarEnabled); if (options.transparentBackground) { setBackgroundColor(Color.TRANSPARENT); @@ -205,6 +226,19 @@ public class InAppWebView extends WebView { } } + 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); @@ -367,6 +401,12 @@ public class InAppWebView extends WebView { if (newOptionsMap.get("textZoom") != null && options.textZoom != newOptions.textZoom) settings.setTextZoom(newOptions.textZoom); + if (newOptionsMap.get("verticalScrollBarEnabled") != null && options.verticalScrollBarEnabled != newOptions.verticalScrollBarEnabled) + setVerticalScrollBarEnabled(newOptions.verticalScrollBarEnabled); + + if (newOptionsMap.get("horizontalScrollBarEnabled") != null && options.horizontalScrollBarEnabled != newOptions.horizontalScrollBarEnabled) + setHorizontalScrollBarEnabled(newOptions.horizontalScrollBarEnabled); + if (newOptionsMap.get("transparentBackground") != null && options.transparentBackground != newOptions.transparentBackground) { if (newOptions.transparentBackground) { setBackgroundColor(Color.TRANSPARENT); @@ -524,4 +564,11 @@ public class InAppWebView extends WebView { private MethodChannel getChannel() { return (inAppBrowserActivity != null) ? InAppBrowserFlutterPlugin.channel : flutterWebView.channel; } + + @Override + public void destroy() { + final Activity activity = (inAppBrowserActivity != null) ? inAppBrowserActivity : registrar.activity(); + activity.unregisterReceiver(onDownloadComplete); + super.destroy(); + } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java index 14c9e89..4d998f6 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java @@ -14,6 +14,8 @@ public class InAppWebViewOptions extends Options { public boolean javaScriptCanOpenWindowsAutomatically = false; public boolean mediaPlaybackRequiresUserGesture = true; public int textZoom = 100; + public boolean verticalScrollBarEnabled = true; + public boolean horizontalScrollBarEnabled = true; public boolean clearSessionCache = false; public boolean builtInZoomControls = false; diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java index 76ccb1f..cf5cbb2 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/RequestPermissionHandler.java @@ -15,6 +15,8 @@ public abstract class RequestPermissionHandler implements ActivityCompat.OnReque private static Map<Integer, List<Runnable>> actionDictionary = new HashMap<>(); + public static int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 1; + public static void checkAndRun(Activity activity, String permission, int requestCode, Runnable runnable) { int permissionCheck = ContextCompat.checkSelfPermission(activity.getApplicationContext(), permission); diff --git a/example/lib/inline_example.screen.dart b/example/lib/inline_example.screen.dart index 360a4f2..445126d 100644 --- a/example/lib/inline_example.screen.dart +++ b/example/lib/inline_example.screen.dart @@ -55,8 +55,8 @@ 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, diff --git a/ios/Classes/InAppWebView.swift b/ios/Classes/InAppWebView.swift index 8f6dd4a..3ab4a3c 100755 --- a/ios/Classes/InAppWebView.swift +++ b/ios/Classes/InAppWebView.swift @@ -82,8 +82,8 @@ window.\(JAVASCRIPT_BRIDGE_NAME).callHandler = function() { let platformReadyJS = "window.dispatchEvent(new Event('flutterInAppBrowserPlatformReady'));"; -public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler { - +public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, URLSessionDownloadDelegate { + var IABController: InAppBrowserWebViewController? var IAWController: FlutterWebViewController? var options: InAppWebViewOptions? @@ -180,6 +180,9 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi configuration.preferences.javaScriptEnabled = (options?.javaScriptEnabled)! + scrollView.showsVerticalScrollIndicator = (options?.verticalScrollBarEnabled)! + scrollView.showsHorizontalScrollIndicator = (options?.horizontalScrollBarEnabled)! + if ((options?.userAgent)! != "") { if #available(iOS 9.0, *) { customUserAgent = (options?.userAgent)! @@ -388,6 +391,13 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi configuration.preferences.javaScriptEnabled = newOptions.javaScriptEnabled } + if newOptionsMap["verticalScrollBarEnabled"] != nil && options?.verticalScrollBarEnabled != newOptions.verticalScrollBarEnabled { + scrollView.showsVerticalScrollIndicator = newOptions.verticalScrollBarEnabled + } + if newOptionsMap["horizontalScrollBarEnabled"] != nil && options?.horizontalScrollBarEnabled != newOptions.horizontalScrollBarEnabled { + scrollView.showsHorizontalScrollIndicator = newOptions.horizontalScrollBarEnabled + } + if newOptionsMap["userAgent"] != nil && options?.userAgent != newOptions.userAgent && (newOptions.userAgent != "") { if #available(iOS 9.0, *) { customUserAgent = newOptions.userAgent @@ -514,9 +524,8 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { - + if let url = navigationAction.request.url { - if url.absoluteString != url.absoluteString && (options?.useOnLoadResource)! { WKNavigationMap[url.absoluteString] = [ "startTime": currentTimeInMilliSeconds(), @@ -556,6 +565,17 @@ 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) + }) + decisionHandler(.cancel) + return + } + } + decisionHandler(.allow) } @@ -647,6 +667,20 @@ 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 { @@ -839,3 +873,47 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi 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() + } +} diff --git a/ios/Classes/InAppWebViewOptions.swift b/ios/Classes/InAppWebViewOptions.swift index dfaf0eb..788dd54 100755 --- a/ios/Classes/InAppWebViewOptions.swift +++ b/ios/Classes/InAppWebViewOptions.swift @@ -17,6 +17,8 @@ public class InAppWebViewOptions: Options { var javaScriptEnabled = true var javaScriptCanOpenWindowsAutomatically = false var mediaPlaybackRequiresUserGesture = true + var verticalScrollBarEnabled = true + var horizontalScrollBarEnabled = true var disallowOverScroll = false var enableViewportScale = false diff --git a/pubspec.yaml b/pubspec.yaml index 4530783..917ddba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappbrowser -description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window (inspired by the popular cordova-plugin-inappbrowser). -version: 1.2.1 +description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window. +version: 1.3.0 author: Lorenzo Pichilli <pichillilorenzo@gmail.com> homepage: https://github.com/pichillilorenzo/flutter_inappbrowser -- 2.26.2