diff --git a/.fvm/flutter_sdk b/.fvm/flutter_sdk
new file mode 120000
index 00000000..c6e3b15b
--- /dev/null
+++ b/.fvm/flutter_sdk
@@ -0,0 +1 @@
+/Users/lorenzopichilli/fvm/versions/2.10.4
\ No newline at end of file
diff --git a/.fvm/fvm_config.json b/.fvm/fvm_config.json
new file mode 100644
index 00000000..d2faf497
--- /dev/null
+++ b/.fvm/fvm_config.json
@@ -0,0 +1,4 @@
+{
+ "flutterSdkVersion": "2.10.4",
+ "flavors": {}
+}
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index eb487e55..9be145fd 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,29 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
.DS_Store
+.atom/
+.buildlog/
+.history
+.svn/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
+/pubspec.lock
+**/doc/api/
.dart_tool/
-
-.vscode/
.packages
-.pub/
-pubspec.lock
-
build/
-
-.idea/workspace.xml
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
deleted file mode 100755
index 6bbadb56..00000000
--- a/.idea/codeStyles/Project.xml
+++ /dev/null
@@ -1,122 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- xmlns:android
-
- ^$
-
-
-
-
-
-
-
-
- xmlns:.*
-
- ^$
-
-
- BY_NAME
-
-
-
-
-
-
- .*:id
-
- http://schemas.android.com/apk/res/android
-
-
-
-
-
-
-
-
- .*:name
-
- http://schemas.android.com/apk/res/android
-
-
-
-
-
-
-
-
- name
-
- ^$
-
-
-
-
-
-
-
-
- style
-
- ^$
-
-
-
-
-
-
-
-
- .*
-
- ^$
-
-
- BY_NAME
-
-
-
-
-
-
- .*
-
- http://schemas.android.com/apk/res/android
-
-
- ANDROID_ATTRIBUTE_ORDER
-
-
-
-
-
-
- .*
-
- .*
-
-
- BY_NAME
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
deleted file mode 100755
index 79ee123c..00000000
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100755
index 15a15b21..00000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
deleted file mode 100644
index 3b0b4626..00000000
--- a/.idea/libraries/Dart_Packages.xml
+++ /dev/null
@@ -1,420 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml
deleted file mode 100755
index 62be7eab..00000000
--- a/.idea/libraries/Dart_SDK.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml
deleted file mode 100755
index 31799730..00000000
--- a/.idea/libraries/Flutter_Plugins.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/Flutter_for_Android.xml b/.idea/libraries/Flutter_for_Android.xml
deleted file mode 100755
index 282dba69..00000000
--- a/.idea/libraries/Flutter_for_Android.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/.idea/markdown-navigator-enh.xml b/.idea/markdown-navigator-enh.xml
deleted file mode 100644
index 12fb99d1..00000000
--- a/.idea/markdown-navigator-enh.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml
deleted file mode 100755
index 097c2565..00000000
--- a/.idea/markdown-navigator.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100755
index eac9d8a9..00000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100755
index dea0765f..00000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations/example_lib_main_dart.xml b/.idea/runConfigurations/example_lib_main_dart.xml
deleted file mode 100755
index bac2c8a7..00000000
--- a/.idea/runConfigurations/example_lib_main_dart.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100755
index 46ea4792..00000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d19becd8..e7935ed8 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,41 @@
+## 5.4.0
+
+- `getOriginalUrl` method is cross-platform now
+- Updated Android `compileSdkVersion` to 31
+- Updated Flutter environment: sdk to `>=2.14.0 <3.0.0` and flutter version to `>=2.5.0`
+- Added `singleInstance` option for Android `ChromeSafariBrowser` implementation
+- Added `onDownloadStartRequest` event and deprecated old `onDownloadStart` event
+- Fixed missing `onZoomScaleChanged` call for `InAppBrowser` class
+- Fixed `requestImageRef` method always `null` on iOS
+- Fixed "applicationNameForUserAgent is not work in ios" [#525](https://github.com/pichillilorenzo/flutter_inappwebview/issues/525)
+- Fixed "Crash when try select file from webview input on Android" [#867](https://github.com/pichillilorenzo/flutter_inappwebview/issues/867)
+- Fixed "NavigationAction.request should use toMap method" [#878](https://github.com/pichillilorenzo/flutter_inappwebview/issues/878)
+- Fixed "Missing body field in URLRequest toMap method" [#990](https://github.com/pichillilorenzo/flutter_inappwebview/issues/990)
+- Fixed "iOS : createWindowAction.request.body in onCreateWindow() is NULL" [#994](https://github.com/pichillilorenzo/flutter_inappwebview/issues/994)
+- Fixed "Crash at HeadlessInAppWebView dispose" [#881](https://github.com/pichillilorenzo/flutter_inappwebview/issues/881)
+- Fixed "Crash happens when HeadlessInAppWebView's dispose function is called in iOS" [#972](https://github.com/pichillilorenzo/flutter_inappwebview/issues/972)
+- Fixed "In android, when click a href with img returns img src on onCreateWindow" [#951](https://github.com/pichillilorenzo/flutter_inappwebview/issues/951)
+- Fixed "crash at com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebView$11.run (InAppWebView.java:1307)" [#1040](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1040)
+- Fixed "Unexpected behavior when using a null initialUrlRequest" [#1063](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1063)
+- Fixed "Local storage & cookie didn't persist when sharedCookie and cache both enabled" [#1092](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1092)
+- Fixed "ios zoomBy crash: Foundation/NSNumber.swift:467: Fatal error: Unable to bridge NSNumber to Float" [#873](https://github.com/pichillilorenzo/flutter_inappwebview/issues/873)
+- Merged "Update Options.swift" [#889](https://github.com/pichillilorenzo/flutter_inappwebview/pull/889) (thanks to [cloudygeek](https://github.com/cloudygeek))
+- Merged "fix: Applicatio nNameForUserAgent is not working in iOS" [#1095](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1095) (thanks to [sunalwaysknows](https://github.com/sunalwaysknows))
+- Merged "Make sure we open a new instance of a custom chrome chrome tab" [#812](https://github.com/pichillilorenzo/flutter_inappwebview/pull/812) (thanks to [savy-91](https://github.com/savy-91))
+- Merged "fix bug when in String[] array come null" [#868](https://github.com/pichillilorenzo/flutter_inappwebview/pull/868) (thanks to [Ser1ous](https://github.com/Ser1ous))
+- Merged "fix: use in NavigationAction request toMap method" [#879](https://github.com/pichillilorenzo/flutter_inappwebview/pull/879) (thanks to [chreck](https://github.com/chreck))
+- Merged "switch android mockserver dependency with okhttp" [#946](https://github.com/pichillilorenzo/flutter_inappwebview/pull/946) (thanks to [randysecrist](https://github.com/randysecrist))
+- Merged "Adds missing body to URLRequest mapping." [#991](https://github.com/pichillilorenzo/flutter_inappwebview/pull/991) (thanks to [Miiha](https://github.com/Miiha))
+- Merged "fix. Crash happens when HeadlessInAppWebView's dispose function is called in iOS" [#1017](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1017) (thanks to [hoanglm4](https://github.com/hoanglm4))
+- Merged "Fixes URL returned when taping image with href in onCreateWindow [Android]" [#1042](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1042) (thanks to [Manuito83](https://github.com/Manuito83))
+- Merged "Fix Android Sometimes crash after close webpage and return to platform code." [#1050](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1050) (thanks to [rsydor](https://github.com/rsydor))
+- Merged "Add application/wasm MimeType with InAppLocalhostServer" [#1054](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1054) (thanks to [foxstream528](https://github.com/foxstream528))
+- Merged "Fixed the unexpected behavior of InAppWebView and HeadlessInAppWebView when initialUrlRequest was set as null." [#1064](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1064) (thanks to [RodXander](https://github.com/RodXander))
+- Merged "updated com.android.tools.build:gradle" [#1066](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1066) (thanks to [chownation](https://github.com/chownation))
+- Merged "WIP - expose content-disposition and content-length from android" [#1088](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1088) (thanks to [ashank96](https://github.com/ashank96))
+- Merged "Fix ios persistance when using sharedCookie" [#1093](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1093) (thanks to [EA-YOUHOU](https://github.com/EA-YOUHOU))
+- Merged "Fixes zoomBy with floats (iOS)" [#1109](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1109) (thanks to [Manuito83](https://github.com/Manuito83))
+
## 5.3.2
- Added `onLoad` and `onError` callbacks in `ScriptHtmlTagAttributes` class used by `InAppWebViewController.injectJavascriptFileFromUrl`
@@ -63,7 +101,7 @@
- Fixed iOS sometimes `scrollView.contentSize` doesn't fit all the `frame.size` available
- Fixed ajax and fetch interceptor when the data/body sent is not a string
- Fixed "InAppLocalhostServer - Error: type 'List' is not a subtype of type 'List' in type cast" [#724](https://github.com/pichillilorenzo/flutter_inappwebview/issues/724)
-- Merge "fix proguard" [#737](https://github.com/pichillilorenzo/flutter_inappwebview/pull/737) (thanks to [myroid](https://github.com/myroid))
+- Merged "fix proguard" [#737](https://github.com/pichillilorenzo/flutter_inappwebview/pull/737) (thanks to [myroid](https://github.com/myroid))
### BREAKING CHANGES
@@ -149,19 +187,19 @@
- Added new iOS-specific attributes to `ShouldOverrideUrlLoadingRequest` and `CreateWindowRequest` classes
- Added `toolbarTopTranslucent`, `toolbarTopTintColor`, `toolbarBottomTintColor`, `toolbarTopBarTintColor` ios-specific InAppBrowser options
- Updated integration tests
-- Merge "Upgraded appcompat to 1.2.0-rc-02" [#465](https://github.com/pichillilorenzo/flutter_inappwebview/pull/465) (thanks to [andreidiaconu](https://github.com/andreidiaconu))
-- Merge "Added missing field 'headers' which returned by WebResourceResponse.toMap()" [#490](https://github.com/pichillilorenzo/flutter_inappwebview/pull/490) (thanks to [Doflatango](https://github.com/Doflatango))
-- Merge "Fix: added iOS fallback module import" [#466](https://github.com/pichillilorenzo/flutter_inappwebview/pull/466) (thanks to [Eddayy](https://github.com/Eddayy))
-- Merge "Fix NullPointerException after taking a photo by a camera app on Android" [#492](https://github.com/pichillilorenzo/flutter_inappwebview/pull/492) (thanks to [AAkira](https://github.com/AAkira))
-- Merge "iOS CookieManager.getCookies - Check that URL has suffix of cookie do…" [#658](https://github.com/pichillilorenzo/flutter_inappwebview/pull/658) (thanks to [arneke](https://github.com/arneke))
-- Merge "Add NTLM Auth" [#634](https://github.com/pichillilorenzo/flutter_inappwebview/pull/634) (thanks to [albatrosify](https://github.com/albatrosify))
-- Merge "iOS ChromeSafariBrowserManager - Fixing unnecessary casting of rootViewController to FlutterViewController" [#567](https://github.com/pichillilorenzo/flutter_inappwebview/pull/567) (thanks to [gunantosteven](https://github.com/gunantosteven))
-- Merge "Fix _channel.invokeMethod name for injectCSSFileFromUrl method" [#645](https://github.com/pichillilorenzo/flutter_inappwebview/pull/645) (thanks to [omralcrt](https://github.com/omralcrt))
-- Merge "Add android media intents on wildcard input accept" [#620](https://github.com/pichillilorenzo/flutter_inappwebview/pull/620) (thanks to [cbodin](https://github.com/cbodin))
-- Merge "Add ChromeSafariBrowser support for Android 11" [#538](https://github.com/pichillilorenzo/flutter_inappwebview/pull/538) (thanks to [DRSchlaubi](https://github.com/DRSchlaubi))
-- Merge "fix(iOS): missing implementation of method zoomBy" [#670](https://github.com/pichillilorenzo/flutter_inappwebview/pull/670) (thanks to [pcqpcq](https://github.com/pcqpcq))
-- Merge "[mod] Fix all issues relate to long click in Android version 7.0 (#657, #527)" [#671](https://github.com/pichillilorenzo/flutter_inappwebview/pull/671) (thanks to [MrNinja](https://github.com/MrNinja))
-- Merge "Fix ViewGroup.removeView NullPointerException (#450)" [#683](https://github.com/pichillilorenzo/flutter_inappwebview/pull/683) (thanks to [toda-bps](https://github.com/toda-bps))
+- Merged "Upgraded appcompat to 1.2.0-rc-02" [#465](https://github.com/pichillilorenzo/flutter_inappwebview/pull/465) (thanks to [andreidiaconu](https://github.com/andreidiaconu))
+- Merged "Added missing field 'headers' which returned by WebResourceResponse.toMap()" [#490](https://github.com/pichillilorenzo/flutter_inappwebview/pull/490) (thanks to [Doflatango](https://github.com/Doflatango))
+- Merged "Fix: added iOS fallback module import" [#466](https://github.com/pichillilorenzo/flutter_inappwebview/pull/466) (thanks to [Eddayy](https://github.com/Eddayy))
+- Merged "Fix NullPointerException after taking a photo by a camera app on Android" [#492](https://github.com/pichillilorenzo/flutter_inappwebview/pull/492) (thanks to [AAkira](https://github.com/AAkira))
+- Merged "iOS CookieManager.getCookies - Check that URL has suffix of cookie do…" [#658](https://github.com/pichillilorenzo/flutter_inappwebview/pull/658) (thanks to [arneke](https://github.com/arneke))
+- Merged "Add NTLM Auth" [#634](https://github.com/pichillilorenzo/flutter_inappwebview/pull/634) (thanks to [albatrosify](https://github.com/albatrosify))
+- Merged "iOS ChromeSafariBrowserManager - Fixing unnecessary casting of rootViewController to FlutterViewController" [#567](https://github.com/pichillilorenzo/flutter_inappwebview/pull/567) (thanks to [gunantosteven](https://github.com/gunantosteven))
+- Merged "Fix _channel.invokeMethod name for injectCSSFileFromUrl method" [#645](https://github.com/pichillilorenzo/flutter_inappwebview/pull/645) (thanks to [omralcrt](https://github.com/omralcrt))
+- Merged "Add android media intents on wildcard input accept" [#620](https://github.com/pichillilorenzo/flutter_inappwebview/pull/620) (thanks to [cbodin](https://github.com/cbodin))
+- Merged "Add ChromeSafariBrowser support for Android 11" [#538](https://github.com/pichillilorenzo/flutter_inappwebview/pull/538) (thanks to [DRSchlaubi](https://github.com/DRSchlaubi))
+- Merged "fix(iOS): missing implementation of method zoomBy" [#670](https://github.com/pichillilorenzo/flutter_inappwebview/pull/670) (thanks to [pcqpcq](https://github.com/pcqpcq))
+- Merged "[mod] Fix all issues relate to long click in Android version 7.0 (#657, #527)" [#671](https://github.com/pichillilorenzo/flutter_inappwebview/pull/671) (thanks to [MrNinja](https://github.com/MrNinja))
+- Merged "Fix ViewGroup.removeView NullPointerException (#450)" [#683](https://github.com/pichillilorenzo/flutter_inappwebview/pull/683) (thanks to [toda-bps](https://github.com/toda-bps))
- Fixed missing properties initialization when using InAppWebViewController.fromInAppBrowser
- Fixed "Issue in Flutter web: 'Unsupported operation: Platform._operatingSystem'" [#507](https://github.com/pichillilorenzo/flutter_inappwebview/issues/507)
- Fixed "window.flutter_inappwebview.callHandler is not a function" [#218](https://github.com/pichillilorenzo/flutter_inappwebview/issues/218)
@@ -363,13 +401,13 @@
- Updated for Flutter 1.12 new Java Embedding API (Android)
- Updated `clearCache` for Android
- Updated default value for `domStorageEnabled` and `databaseEnabled` options to `true` for Android
-- Merge "Fixes null error when calling getOptions for InAppBrowser class" [#214](https://github.com/pichillilorenzo/flutter_inappwebview/pull/214) (thanks to [panndoraBoo](https://github.com/panndoraBoo))
-- Merge "Fixes crash onConsoleMessage iOS forced unwrapping" [#228](https://github.com/pichillilorenzo/flutter_inappwebview/pull/228) (thanks to [tokonu](https://github.com/tokonu))
-- Merge "Fix HTTPCookie.secure" [#311](https://github.com/pichillilorenzo/flutter_inappwebview/pull/311) (thanks to [xtyxtyx](https://github.com/xtyxtyx))
-- Merge "Fix config options for Android release builds" [#295](https://github.com/pichillilorenzo/flutter_inappwebview/pull/295) (thanks to [wwwdata](https://github.com/wwwdata))
-- Merge "fix scrollbar on iOS always show if not disable scroll" [#256](https://github.com/pichillilorenzo/flutter_inappwebview/pull/256) (thanks to [phamnhuvu-dev](https://github.com/phamnhuvu-dev))
-- Merge "Fix crash on nil/invalid URL (iOS)" [#262](https://github.com/pichillilorenzo/flutter_inappwebview/pull/262) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
-- Merge "Fix crash when `prompt` was called on Android Q." [#262](https://github.com/pichillilorenzo/flutter_inappwebview/pull/263) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
+- Merged "Fixes null error when calling getOptions for InAppBrowser class" [#214](https://github.com/pichillilorenzo/flutter_inappwebview/pull/214) (thanks to [panndoraBoo](https://github.com/panndoraBoo))
+- Merged "Fixes crash onConsoleMessage iOS forced unwrapping" [#228](https://github.com/pichillilorenzo/flutter_inappwebview/pull/228) (thanks to [tokonu](https://github.com/tokonu))
+- Merged "Fix HTTPCookie.secure" [#311](https://github.com/pichillilorenzo/flutter_inappwebview/pull/311) (thanks to [xtyxtyx](https://github.com/xtyxtyx))
+- Merged "Fix config options for Android release builds" [#295](https://github.com/pichillilorenzo/flutter_inappwebview/pull/295) (thanks to [wwwdata](https://github.com/wwwdata))
+- Merged "fix scrollbar on iOS always show if not disable scroll" [#256](https://github.com/pichillilorenzo/flutter_inappwebview/pull/256) (thanks to [phamnhuvu-dev](https://github.com/phamnhuvu-dev))
+- Merged "Fix crash on nil/invalid URL (iOS)" [#262](https://github.com/pichillilorenzo/flutter_inappwebview/pull/262) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
+- Merged "Fix crash when `prompt` was called on Android Q." [#262](https://github.com/pichillilorenzo/flutter_inappwebview/pull/263) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
- Fix for Android and iOS `InAppBrowser` for some controller methods not exposed.
- Fixed "App Crashes after clicking on dropdown (Using inappwebview)" [#182](https://github.com/pichillilorenzo/flutter_inappwebview/issues/182)
- Fixed "webview can not be released when in ios" [#225](https://github.com/pichillilorenzo/flutter_inappwebview/issues/225). Now the iOS WebView is released from memory when it is disposed from Flutter.
@@ -416,16 +454,16 @@
## 2.0.0
-- Merge "Avoid null pointer exception after webview is disposed" [#116](https://github.com/pichillilorenzo/flutter_inappwebview/pull/116) (thanks to [robsonfingo](https://github.com/robsonfingo))
-- Merge "Remove async call in close" [#119](https://github.com/pichillilorenzo/flutter_inappwebview/pull/119) (thanks to [benfingo](https://github.com/benfingo))
-- Merge "Android takeScreenshot does not work properly." [#122](https://github.com/pichillilorenzo/flutter_inappwebview/pull/122) (thanks to [PauloMelo](https://github.com/PauloMelo))
-- Merge "Resolving gradle error." [#144](https://github.com/pichillilorenzo/flutter_inappwebview/pull/144) (thanks to [Klingens13](https://github.com/Klingens13))
-- Merge "Create issue and pull request templates" [#150](https://github.com/pichillilorenzo/flutter_inappwebview/pull/150) (thanks to [deandreamatias](https://github.com/deandreamatias))
-- Merge "Fix abstract method error && swift version error" [#155](https://github.com/pichillilorenzo/flutter_inappwebview/pull/155) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
-- Merge "migrating to swift 5.0" [#162](https://github.com/pichillilorenzo/flutter_inappwebview/pull/162) (thanks to [fattiger00](https://github.com/fattiger00))
-- Merge "Update readme example" [#178](https://github.com/pichillilorenzo/flutter_inappwebview/pull/178) (thanks to [SebastienBtr](https://github.com/SebastienBtr))
-- Merge "handle choose file callback in android" [#183](https://github.com/pichillilorenzo/flutter_inappwebview/pull/183) (thanks to [crazecoder](https://github.com/crazecoder))
-- Merge "add initialScale in android" [#186](https://github.com/pichillilorenzo/flutter_inappwebview/pull/186) (thanks to [crazecoder](https://github.com/crazecoder))
+- Merged "Avoid null pointer exception after webview is disposed" [#116](https://github.com/pichillilorenzo/flutter_inappwebview/pull/116) (thanks to [robsonfingo](https://github.com/robsonfingo))
+- Merged "Remove async call in close" [#119](https://github.com/pichillilorenzo/flutter_inappwebview/pull/119) (thanks to [benfingo](https://github.com/benfingo))
+- Merged "Android takeScreenshot does not work properly." [#122](https://github.com/pichillilorenzo/flutter_inappwebview/pull/122) (thanks to [PauloMelo](https://github.com/PauloMelo))
+- Merged "Resolving gradle error." [#144](https://github.com/pichillilorenzo/flutter_inappwebview/pull/144) (thanks to [Klingens13](https://github.com/Klingens13))
+- Merged "Create issue and pull request templates" [#150](https://github.com/pichillilorenzo/flutter_inappwebview/pull/150) (thanks to [deandreamatias](https://github.com/deandreamatias))
+- Merged "Fix abstract method error && swift version error" [#155](https://github.com/pichillilorenzo/flutter_inappwebview/pull/155) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
+- Merged "migrating to swift 5.0" [#162](https://github.com/pichillilorenzo/flutter_inappwebview/pull/162) (thanks to [fattiger00](https://github.com/fattiger00))
+- Merged "Update readme example" [#178](https://github.com/pichillilorenzo/flutter_inappwebview/pull/178) (thanks to [SebastienBtr](https://github.com/SebastienBtr))
+- Merged "handle choose file callback in android" [#183](https://github.com/pichillilorenzo/flutter_inappwebview/pull/183) (thanks to [crazecoder](https://github.com/crazecoder))
+- Merged "add initialScale in android" [#186](https://github.com/pichillilorenzo/flutter_inappwebview/pull/186) (thanks to [crazecoder](https://github.com/crazecoder))
- Added `horizontalScrollBarEnabled` and `verticalScrollBarEnabled` options to enable/disable the corresponding scrollbar of the WebView [#165](https://github.com/pichillilorenzo/flutter_inappwebview/issues/165)
- Added `onDownloadStart` event and `useOnDownloadStart` option: 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
@@ -464,22 +502,22 @@
## 1.2.2
-- Merge "added a shared WKProcessPool for webview instances" [#198](https://github.com/pichillilorenzo/flutter_inappwebview/pull/198) (thanks to [robertcnst](https://github.com/robertcnst))
+- Merged "added a shared WKProcessPool for webview instances" [#198](https://github.com/pichillilorenzo/flutter_inappwebview/pull/198) (thanks to [robertcnst](https://github.com/robertcnst))
- Fixed iOS setCookie.
## 1.2.1
-- Merge "Add new option to control the contentMode in Android platform" [#101](https://github.com/pichillilorenzo/flutter_inappwebview/pull/101) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
-- Merge "Fix crash on xcode 10.2" [#107](https://github.com/pichillilorenzo/flutter_inappwebview/pull/107) (thanks to [robsonfingo](https://github.com/robsonfingo))
-- Merge "Remove headers_build_phase from example's Podfile" [#108](https://github.com/pichillilorenzo/flutter_inappwebview/pull/108) (thanks to [robsonfingo](https://github.com/robsonfingo))
+- Merged "Add new option to control the contentMode in Android platform" [#101](https://github.com/pichillilorenzo/flutter_inappwebview/pull/101) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
+- Merged "Fix crash on xcode 10.2" [#107](https://github.com/pichillilorenzo/flutter_inappwebview/pull/107) (thanks to [robsonfingo](https://github.com/robsonfingo))
+- Merged "Remove headers_build_phase from example's Podfile" [#108](https://github.com/pichillilorenzo/flutter_inappwebview/pull/108) (thanks to [robsonfingo](https://github.com/robsonfingo))
- Fixed "Make html5 video fullscreen" for Android [#43](https://github.com/pichillilorenzo/flutter_inappwebview/issues/43)
- Fixed "AllowsInlineMediaPlayback not working" for iOS [#73](https://github.com/pichillilorenzo/flutter_inappwebview/issues/73)
## 1.2.0
-- Merge "Adds a transparentBackground option for iOS and Android" [#86](https://github.com/pichillilorenzo/flutter_inappwebview/pull/86) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
-- Merge "The 'open' method requires an options dictionary" [#87](https://github.com/pichillilorenzo/flutter_inappwebview/pull/87) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
-- Merge "iOS: Call setNeedsLayout() in scrollViewDidScroll()" [#88](https://github.com/pichillilorenzo/flutter_inappwebview/pull/88) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Merged "Adds a transparentBackground option for iOS and Android" [#86](https://github.com/pichillilorenzo/flutter_inappwebview/pull/86) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Merged "The 'open' method requires an options dictionary" [#87](https://github.com/pichillilorenzo/flutter_inappwebview/pull/87) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Merged "iOS: Call setNeedsLayout() in scrollViewDidScroll()" [#88](https://github.com/pichillilorenzo/flutter_inappwebview/pull/88) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
- Fixed "java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread." [#98](https://github.com/pichillilorenzo/flutter_inappwebview/issues/98) (thanks to [DreamBuddy](https://github.com/DreamBuddy))
- Fixed "app force close/crash when enabling zoom and repeatedly changing orientation and zoomin zoomout" [#93](https://github.com/pichillilorenzo/flutter_inappwebview/issues/93)
- Added `displayZoomControls` webview option for Android
@@ -487,14 +525,14 @@
## 1.1.3
-- Merge "Add null checks around calls to InAppWebView callbacks" [#85](https://github.com/pichillilorenzo/flutter_inappwebview/pull/85) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
+- Merged "Add null checks around calls to InAppWebView callbacks" [#85](https://github.com/pichillilorenzo/flutter_inappwebview/pull/85) (thanks to [matthewlloyd](https://github.com/matthewlloyd))
## 1.1.2
- Fix InAppBrowser crashes the app when i change the page "Lost connection" [#74](https://github.com/pichillilorenzo/flutter_inappwebview/issues/74)
- Fix javascript `...args` parameter of `window.flutter_inappwebview.callHandler()`
-- Merge Enable setTextZoom function of Android WebViewSetting [#81](https://github.com/pichillilorenzo/flutter_inappwebview/pull/81) (thanks to [YouCii](https://github.com/YouCii))
-- Merge bug fix for android build: Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath [#83](https://github.com/pichillilorenzo/flutter_inappwebview/pull/83) (thanks to [cinos1](https://github.com/cinos1))
+- Merged Enable setTextZoom function of Android WebViewSetting [#81](https://github.com/pichillilorenzo/flutter_inappwebview/pull/81) (thanks to [YouCii](https://github.com/YouCii))
+- Merged bug fix for android build: Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath [#83](https://github.com/pichillilorenzo/flutter_inappwebview/pull/83) (thanks to [cinos1](https://github.com/cinos1))
## 1.1.1
diff --git a/android/.gitignore b/android/.gitignore
index c6cbe562..4b97ae3e 100755
--- a/android/.gitignore
+++ b/android/.gitignore
@@ -1,8 +1,13 @@
*.iml
.gradle
+gradlew
+gradlew.bat
+gradle-wrapper.jar
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
+local.properties
+keystore.properties
\ No newline at end of file
diff --git a/android/build.gradle b/android/build.gradle
index f0408fc9..9cc60378 100755
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -8,7 +8,7 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.6.4'
+ classpath 'com.android.tools.build:gradle:4.1.0'
}
}
@@ -48,7 +48,7 @@ android {
implementation 'androidx.webkit:webkit:1.4.0'
implementation 'androidx.browser:browser:1.3.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
- implementation 'com.squareup.okhttp3:mockwebserver:3.14.7'
+ implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
}
}
diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar
deleted file mode 100755
index f6b961fd..00000000
Binary files a/android/gradle/wrapper/gradle-wrapper.jar and /dev/null differ
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100755
index fd50c3ca..00000000
--- a/android/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
\ No newline at end of file
diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index c5d3bbfb..fbaf1980 100755
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -11,6 +11,10 @@
android:theme="@style/ThemeTransparent"
android:exported="false"
android:name="com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeCustomTabsActivity" />
+
params = (HashMap) args;
- FlutterWebView flutterWebView = new FlutterWebView(plugin, context, id, params);
+
+ PlatformWebView flutterWebView;
+ WebViewImplementation implementation = WebViewImplementation.fromValue((Integer) params.get("implementation"));
+ switch (implementation) {
+ case NATIVE:
+ default:
+ flutterWebView = new FlutterWebView(plugin, context, id, params);
+ }
flutterWebView.makeInitialLoad(params);
+
return flutterWebView;
}
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java
index c3864a14..ceff965b 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewFlutterPlugin.java
@@ -9,7 +9,6 @@ import android.webkit.ValueCallback;
import com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs.ChromeSafariBrowserManager;
import com.pichillilorenzo.flutter_inappwebview.credential_database.CredentialDatabaseHandler;
import com.pichillilorenzo.flutter_inappwebview.in_app_browser.InAppBrowserManager;
-import com.pichillilorenzo.flutter_inappwebview.in_app_webview.FlutterWebViewFactory;
import com.pichillilorenzo.flutter_inappwebview.headless_in_app_webview.HeadlessInAppWebViewManager;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewMethodHandler.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewMethodHandler.java
index ae0b4e03..0e24b925 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewMethodHandler.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewMethodHandler.java
@@ -16,11 +16,15 @@ import com.pichillilorenzo.flutter_inappwebview.in_app_browser.InAppBrowserOptio
import com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebView;
import com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebViewOptions;
import com.pichillilorenzo.flutter_inappwebview.types.ContentWorld;
+import com.pichillilorenzo.flutter_inappwebview.types.HitTestResult;
+import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface;
import com.pichillilorenzo.flutter_inappwebview.types.SslCertificateExt;
import com.pichillilorenzo.flutter_inappwebview.types.URLRequest;
import com.pichillilorenzo.flutter_inappwebview.types.UserScript;
+import com.pichillilorenzo.flutter_inappwebview.types.WebMessage;
import com.pichillilorenzo.flutter_inappwebview.types.WebMessageChannel;
import com.pichillilorenzo.flutter_inappwebview.types.WebMessageListener;
+import com.pichillilorenzo.flutter_inappwebview.types.WebMessagePort;
import java.io.IOException;
import java.util.ArrayList;
@@ -34,9 +38,9 @@ import io.flutter.plugin.common.MethodChannel;
public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandler {
static final String LOG_TAG = "IAWMethodHandler";
- public InAppWebView webView;
+ public InAppWebViewInterface webView;
- public InAppWebViewMethodHandler(InAppWebView webView) {
+ public InAppWebViewMethodHandler(InAppWebViewInterface webView) {
this.webView = webView;
}
@@ -176,8 +180,8 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
result.success(null);
break;
case "setOptions":
- if (webView != null && webView.inAppBrowserDelegate != null && webView.inAppBrowserDelegate instanceof InAppBrowserActivity) {
- InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.inAppBrowserDelegate;
+ if (webView != null && webView.getInAppBrowserDelegate() != null && webView.getInAppBrowserDelegate() instanceof InAppBrowserActivity) {
+ InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.getInAppBrowserDelegate();
InAppBrowserOptions inAppBrowserOptions = new InAppBrowserOptions();
HashMap inAppBrowserOptionsMap = (HashMap) call.argument("options");
inAppBrowserOptions.parse(inAppBrowserOptionsMap);
@@ -191,24 +195,24 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
result.success(true);
break;
case "getOptions":
- if (webView != null && webView.inAppBrowserDelegate != null && webView.inAppBrowserDelegate instanceof InAppBrowserActivity) {
- InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.inAppBrowserDelegate;
+ if (webView != null && webView.getInAppBrowserDelegate() != null && webView.getInAppBrowserDelegate() instanceof InAppBrowserActivity) {
+ InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.getInAppBrowserDelegate();
result.success(inAppBrowserActivity.getOptions());
} else {
result.success((webView != null) ? webView.getOptions() : null);
}
break;
case "close":
- if (webView != null && webView.inAppBrowserDelegate != null && webView.inAppBrowserDelegate instanceof InAppBrowserActivity) {
- InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.inAppBrowserDelegate;
+ if (webView != null && webView.getInAppBrowserDelegate() != null && webView.getInAppBrowserDelegate() instanceof InAppBrowserActivity) {
+ InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.getInAppBrowserDelegate();
inAppBrowserActivity.close(result);
} else {
result.notImplemented();
}
break;
case "show":
- if (webView != null && webView.inAppBrowserDelegate != null && webView.inAppBrowserDelegate instanceof InAppBrowserActivity) {
- InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.inAppBrowserDelegate;
+ if (webView != null && webView.getInAppBrowserDelegate() != null && webView.getInAppBrowserDelegate() instanceof InAppBrowserActivity) {
+ InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.getInAppBrowserDelegate();
inAppBrowserActivity.show();
result.success(true);
} else {
@@ -216,8 +220,8 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
}
break;
case "hide":
- if (webView != null && webView.inAppBrowserDelegate != null && webView.inAppBrowserDelegate instanceof InAppBrowserActivity) {
- InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.inAppBrowserDelegate;
+ if (webView != null && webView.getInAppBrowserDelegate() != null && webView.getInAppBrowserDelegate() instanceof InAppBrowserActivity) {
+ InAppBrowserActivity inAppBrowserActivity = (InAppBrowserActivity) webView.getInAppBrowserDelegate();
inAppBrowserActivity.hide();
result.success(true);
} else {
@@ -319,7 +323,11 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
result.success(true);
break;
case "getContentHeight":
- result.success((webView != null) ? webView.getContentHeight() : null);
+ if (webView instanceof InAppWebView) {
+ result.success(webView.getContentHeight());
+ } else {
+ result.success(null);
+ }
break;
case "zoomBy":
if (webView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@@ -332,22 +340,27 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
result.success((webView != null) ? webView.getOriginalUrl() : null);
break;
case "getZoomScale":
- result.success((webView != null) ? webView.zoomScale : null);
+ if (webView instanceof InAppWebView) {
+ result.success(webView.getZoomScale());
+ } else {
+ result.success(null);
+ }
break;
case "getSelectedText":
- if (webView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- webView.getSelectedText(result);
+ if ((webView instanceof InAppWebView && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)) {
+ webView.getSelectedText(new ValueCallback() {
+ @Override
+ public void onReceiveValue(String value) {
+ result.success(value);
+ }
+ });
} else {
result.success(null);
}
break;
case "getHitTestResult":
- if (webView != null) {
- WebView.HitTestResult hitTestResult = webView.getHitTestResult();
- Map obj = new HashMap<>();
- obj.put("type", hitTestResult.getType());
- obj.put("extra", hitTestResult.getExtra());
- result.success(obj);
+ if (webView instanceof InAppWebView) {
+ result.success(HitTestResult.fromWebViewHitTestResult(webView.getHitTestResult()).toMap());
} else {
result.success(null);
}
@@ -405,7 +418,7 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
case "setContextMenu":
if (webView != null) {
Map contextMenu = (Map) call.argument("contextMenu");
- webView.contextMenu = contextMenu;
+ webView.setContextMenu(contextMenu);
}
result.success(true);
break;
@@ -451,34 +464,34 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
result.success(true);
break;
case "addUserScript":
- if (webView != null && webView.userContentController != null) {
+ if (webView != null && webView.getUserContentController() != null) {
Map userScriptMap = (Map) call.argument("userScript");
UserScript userScript = UserScript.fromMap(userScriptMap);
- result.success(webView.userContentController.addUserOnlyScript(userScript));
+ result.success(webView.getUserContentController().addUserOnlyScript(userScript));
} else {
result.success(false);
}
break;
case "removeUserScript":
- if (webView != null && webView.userContentController != null) {
+ if (webView != null && webView.getUserContentController() != null) {
Integer index = (Integer) call.argument("index");
Map userScriptMap = (Map) call.argument("userScript");
UserScript userScript = UserScript.fromMap(userScriptMap);
- result.success(webView.userContentController.removeUserOnlyScriptAt(index, userScript.getInjectionTime()));
+ result.success(webView.getUserContentController().removeUserOnlyScriptAt(index, userScript.getInjectionTime()));
} else {
result.success(false);
}
break;
case "removeUserScriptsByGroupName":
- if (webView != null && webView.userContentController != null) {
+ if (webView != null && webView.getUserContentController() != null) {
String groupName = (String) call.argument("groupName");
- webView.userContentController.removeUserOnlyScriptsByGroupName(groupName);
+ webView.getUserContentController().removeUserOnlyScriptsByGroupName(groupName);
}
result.success(true);
break;
case "removeAllUserScripts":
- if (webView != null && webView.userContentController != null) {
- webView.userContentController.removeAllUserOnlyScripts();
+ if (webView != null && webView.getUserContentController() != null) {
+ webView.getUserContentController().removeAllUserOnlyScripts();
}
result.success(true);
break;
@@ -512,8 +525,12 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
}
break;
case "createWebMessageChannel":
- if (webView != null && WebViewFeature.isFeatureSupported(WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL)) {
- result.success(webView.createCompatWebMessageChannel().toMap());
+ if (webView != null) {
+ if (webView instanceof InAppWebView && WebViewFeature.isFeatureSupported(WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL)) {
+ result.success(webView.createCompatWebMessageChannel().toMap());
+ } else {
+ result.success(null);
+ }
} else {
result.success(null);
}
@@ -522,38 +539,47 @@ public class InAppWebViewMethodHandler implements MethodChannel.MethodCallHandle
if (webView != null && WebViewFeature.isFeatureSupported(WebViewFeature.POST_WEB_MESSAGE)) {
Map message = (Map) call.argument("message");
String targetOrigin = (String) call.argument("targetOrigin");
- List ports = new ArrayList<>();
+ List compatPorts = new ArrayList<>();
+ List ports = new ArrayList<>();
List> portsMap = (List>) message.get("ports");
if (portsMap != null) {
for (Map portMap : portsMap) {
String webMessageChannelId = (String) portMap.get("webMessageChannelId");
Integer index = (Integer) portMap.get("index");
- WebMessageChannel webMessageChannel = webView.webMessageChannels.get(webMessageChannelId);
+ WebMessageChannel webMessageChannel = webView.getWebMessageChannels().get(webMessageChannelId);
if (webMessageChannel != null) {
- ports.add(webMessageChannel.ports.get(index));
+ if (webView instanceof InAppWebView) {
+ compatPorts.add(webMessageChannel.compatPorts.get(index));
+ }
}
}
}
- WebMessageCompat webMessage = new WebMessageCompat((String) message.get("data"), ports.toArray(new WebMessagePortCompat[0]));
- try {
- WebViewCompat.postWebMessage(webView, webMessage, Uri.parse(targetOrigin));
- result.success(true);
- } catch (Exception e) {
- result.error(LOG_TAG, e.getMessage(), null);
+ if (webView instanceof InAppWebView) {
+ WebMessageCompat webMessage = new WebMessageCompat((String) message.get("data"), compatPorts.toArray(new WebMessagePortCompat[0]));
+ try {
+ WebViewCompat.postWebMessage((WebView) webView, webMessage, Uri.parse(targetOrigin));
+ result.success(true);
+ } catch (Exception e) {
+ result.error(LOG_TAG, e.getMessage(), null);
+ }
}
} else {
result.success(true);
}
break;
case "addWebMessageListener":
- if (webView != null && WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
+ if (webView != null) {
Map webMessageListenerMap = (Map) call.argument("webMessageListener");
- WebMessageListener webMessageListener = WebMessageListener.fromMap(webView.plugin.messenger, webMessageListenerMap);
- try {
- webView.addWebMessageListener(webMessageListener);
+ WebMessageListener webMessageListener = WebMessageListener.fromMap(webView, webView.getPlugin().messenger, webMessageListenerMap);
+ if (webView instanceof InAppWebView && WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
+ try {
+ webView.addWebMessageListener(webMessageListener);
+ result.success(true);
+ } catch (Exception e) {
+ result.error(LOG_TAG, e.getMessage(), null);
+ }
+ } else {
result.success(true);
- } catch (Exception e) {
- result.error(LOG_TAG, e.getMessage(), null);
}
} else {
result.success(true);
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java
index ffd4ba47..eb1731c4 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/InAppWebViewStatic.java
@@ -99,9 +99,11 @@ public class InAppWebViewStatic implements MethodChannel.MethodCallHandler {
}
break;
case "setWebContentsDebuggingEnabled":
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ {
boolean debuggingEnabled = (boolean) call.argument("debuggingEnabled");
- WebView.setWebContentsDebuggingEnabled(debuggingEnabled);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ WebView.setWebContentsDebuggingEnabled(debuggingEnabled);
+ }
}
result.success(true);
break;
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java
index 5ed84717..fceaffbf 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/Util.java
@@ -19,6 +19,9 @@ import org.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.security.Key;
import java.security.KeyStore;
import java.security.PrivateKey;
@@ -26,6 +29,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
@@ -33,6 +37,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier;
@@ -77,7 +82,7 @@ public class Util {
return ANDROID_ASSET_URL + key;
}
- public static InputStream getFileAsset(InAppWebViewFlutterPlugin plugin,String assetFilePath) throws IOException {
+ public static InputStream getFileAsset(InAppWebViewFlutterPlugin plugin, String assetFilePath) throws IOException {
String key = (plugin.registrar != null) ? plugin.registrar.lookupKeyForAsset(assetFilePath) : plugin.flutterAssets.getAssetFilePathByName(assetFilePath);
AssetManager mg = plugin.applicationContext.getResources().getAssets();
return mg.open(key);
@@ -287,4 +292,33 @@ public class Util {
public static float getPixelDensity(Context context) {
return context.getResources().getDisplayMetrics().density;
}
+
+ public static boolean isClass(String className) {
+ try {
+ Class.forName(className);
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
+ public static boolean isIPv6(String address) {
+ try {
+ Inet6Address.getByName(address);
+ } catch (UnknownHostException e) {
+ return false;
+ }
+ return true;
+ }
+
+ public static String normalizeIPv6(String address) throws Exception {
+ if (!Util.isIPv6(address)) {
+ throw new Exception("Invalid address: " + address);
+ }
+ return InetAddress.getByName(address).getCanonicalHostName();
+ }
+
+ public static Object getOrDefault(Map map, String key, Object defaultValue) {
+ return map.containsKey(key) ? map.get(key) : defaultValue;
+ }
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivitySingleInstance.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivitySingleInstance.java
new file mode 100755
index 00000000..8554edac
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsActivitySingleInstance.java
@@ -0,0 +1,7 @@
+package com.pichillilorenzo.flutter_inappwebview.chrome_custom_tabs;
+
+public class ChromeCustomTabsActivitySingleInstance extends ChromeCustomTabsActivity {
+
+ protected static final String LOG_TAG = "ChromeCustomTabsActivitySingleInstance";
+
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java
index c572f480..f9207fb0 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeSafariBrowserManager.java
@@ -7,6 +7,7 @@ import android.os.Bundle;
import androidx.annotation.Nullable;
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
+import com.pichillilorenzo.flutter_inappwebview.Util;
import java.io.Serializable;
import java.util.HashMap;
@@ -67,9 +68,13 @@ public class ChromeSafariBrowserManager implements MethodChannel.MethodCallHandl
extras.putSerializable("options", options);
extras.putSerializable("menuItemList", (Serializable) menuItemList);
+ Boolean isSingleInstance = (Boolean) options.get("singleInstance");
if (CustomTabActivityHelper.isAvailable(activity)) {
- intent = new Intent(activity, ChromeCustomTabsActivity.class);
+ intent = new Intent(activity, !isSingleInstance ? ChromeCustomTabsActivity.class : ChromeCustomTabsActivitySingleInstance.class);
intent.putExtras(extras);
+ if ((Boolean) options.get("noHistory")) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+ }
activity.startActivity(intent);
result.success(true);
return;
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java
index 1ef7daa2..4f226493 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/FlutterWebView.java
@@ -22,6 +22,7 @@ import com.pichillilorenzo.flutter_inappwebview.InAppWebViewMethodHandler;
import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.JavaScriptBridgeJS;
import com.pichillilorenzo.flutter_inappwebview.pull_to_refresh.PullToRefreshLayout;
import com.pichillilorenzo.flutter_inappwebview.pull_to_refresh.PullToRefreshOptions;
+import com.pichillilorenzo.flutter_inappwebview.types.PlatformWebView;
import com.pichillilorenzo.flutter_inappwebview.types.URLRequest;
import com.pichillilorenzo.flutter_inappwebview.types.UserScript;
@@ -32,9 +33,8 @@ import java.util.List;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
-import io.flutter.plugin.platform.PlatformView;
-public class FlutterWebView implements PlatformView {
+public class FlutterWebView implements PlatformWebView {
static final String LOG_TAG = "IAWFlutterWebView";
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java
index dcde9159..e0de2517 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebView.java
@@ -9,6 +9,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -22,7 +23,6 @@ import android.util.AttributeSet;
import android.util.Log;
import android.view.ActionMode;
import android.view.ContextMenu;
-import android.view.DragEvent;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -37,9 +37,11 @@ import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
+import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebBackForwardList;
import android.webkit.WebHistoryItem;
+import android.webkit.WebMessage;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.widget.HorizontalScrollView;
@@ -53,6 +55,8 @@ import androidx.webkit.WebViewCompat;
import androidx.webkit.WebViewFeature;
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
+import com.pichillilorenzo.flutter_inappwebview.types.DownloadStartRequest;
+import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface;
import com.pichillilorenzo.flutter_inappwebview.JavaScriptBridgeInterface;
import com.pichillilorenzo.flutter_inappwebview.R;
import com.pichillilorenzo.flutter_inappwebview.Util;
@@ -99,7 +103,7 @@ import okhttp3.OkHttpClient;
import static android.content.Context.INPUT_METHOD_SERVICE;
import static com.pichillilorenzo.flutter_inappwebview.types.PreferredContentModeOptionType.fromValue;
-final public class InAppWebView extends InputAwareWebView {
+final public class InAppWebView extends InputAwareWebView implements InAppWebViewInterface {
static final String LOG_TAG = "InAppWebView";
@@ -129,7 +133,7 @@ final public class InAppWebView extends InputAwareWebView {
public LinearLayout floatingContextMenu = null;
@Nullable
public Map contextMenu = null;
- public Handler headlessHandler = new Handler(Looper.getMainLooper());
+ public Handler mainLooperHandler = new Handler(Looper.getMainLooper());
static Handler mHandler = new Handler();
public Runnable checkScrollStoppedTask;
@@ -145,6 +149,7 @@ final public class InAppWebView extends InputAwareWebView {
public Map> evaluateJavaScriptContentWorldCallbacks = new HashMap<>();
public Map webMessageChannels = new HashMap<>();
+ public List webMessageListeners = new ArrayList<>();
public InAppWebView(Context context) {
super(context);
@@ -174,11 +179,6 @@ final public class InAppWebView extends InputAwareWebView {
plugin.activity.registerForContextMenu(this);
}
- @Override
- public void reload() {
- super.reload();
- }
-
public void prepare() {
httpClient = new OkHttpClient().newBuilder().build();
@@ -400,7 +400,7 @@ final public class InAppWebView extends InputAwareWebView {
onScrollStopped();
} else {
initialPositionScrollStoppedTask = getScrollY();
- headlessHandler.postDelayed(checkScrollStoppedTask, newCheckScrollStoppedTask);
+ mainLooperHandler.postDelayed(checkScrollStoppedTask, newCheckScrollStoppedTask);
}
}
};
@@ -418,7 +418,7 @@ final public class InAppWebView extends InputAwareWebView {
hideContextMenu();
}
} else {
- headlessHandler.postDelayed(checkContextMenuShouldBeClosedTask, newCheckContextMenuShouldBeClosedTaskTask);
+ mainLooperHandler.postDelayed(checkContextMenuShouldBeClosedTask, newCheckContextMenuShouldBeClosedTaskTask);
}
}
});
@@ -471,11 +471,9 @@ final public class InAppWebView extends InputAwareWebView {
setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
- HitTestResult hitTestResult = getHitTestResult();
- Map obj = new HashMap<>();
- obj.put("type", hitTestResult.getType());
- obj.put("extra", hitTestResult.getExtra());
- channel.invokeMethod("onLongPressHitTestResult", obj);
+ com.pichillilorenzo.flutter_inappwebview.types.HitTestResult hitTestResult =
+ com.pichillilorenzo.flutter_inappwebview.types.HitTestResult.fromWebViewHitTestResult(getHitTestResult());
+ channel.invokeMethod("onLongPressHitTestResult", hitTestResult.toMap());
return false;
}
});
@@ -540,6 +538,10 @@ final public class InAppWebView extends InputAwareWebView {
}
public void loadFile(String assetFilePath) throws IOException {
+ if (plugin == null) {
+ return;
+ }
+
loadUrl(Util.getUrlAsset(plugin, assetFilePath));
}
@@ -570,12 +572,12 @@ final public class InAppWebView extends InputAwareWebView {
public void takeScreenshot(final @Nullable Map screenshotConfiguration, final MethodChannel.Result result) {
final float pixelDensity = Util.getPixelDensity(getContext());
- headlessHandler.post(new Runnable() {
+ mainLooperHandler.post(new Runnable() {
@Override
public void run() {
try {
- Bitmap resized = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(resized);
+ Bitmap screenshotBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(screenshotBitmap);
c.translate(-getScrollX(), -getScrollY());
draw(c);
@@ -588,10 +590,10 @@ final public class InAppWebView extends InputAwareWebView {
if (rect != null) {
int rectX = (int) Math.floor(rect.get("x") * pixelDensity + 0.5);
int rectY = (int) Math.floor(rect.get("y") * pixelDensity + 0.5);
- int rectWidth = Math.min(resized.getWidth(), (int) Math.floor(rect.get("width") * pixelDensity + 0.5));
- int rectHeight = Math.min(resized.getHeight(), (int) Math.floor(rect.get("height") * pixelDensity + 0.5));
- resized = Bitmap.createBitmap(
- resized,
+ int rectWidth = Math.min(screenshotBitmap.getWidth(), (int) Math.floor(rect.get("width") * pixelDensity + 0.5));
+ int rectHeight = Math.min(screenshotBitmap.getHeight(), (int) Math.floor(rect.get("height") * pixelDensity + 0.5));
+ screenshotBitmap = Bitmap.createBitmap(
+ screenshotBitmap,
rectX,
rectY,
rectWidth,
@@ -601,9 +603,9 @@ final public class InAppWebView extends InputAwareWebView {
Double snapshotWidth = (Double) screenshotConfiguration.get("snapshotWidth");
if (snapshotWidth != null) {
int dstWidth = (int) Math.floor(snapshotWidth * pixelDensity + 0.5);
- float ratioBitmap = (float) resized.getWidth() / (float) resized.getHeight();
+ float ratioBitmap = (float) screenshotBitmap.getWidth() / (float) screenshotBitmap.getHeight();
int dstHeight = (int) ((float) dstWidth / ratioBitmap);
- resized = Bitmap.createScaledBitmap(resized, dstWidth, dstHeight, true);
+ screenshotBitmap = Bitmap.createScaledBitmap(screenshotBitmap, dstWidth, dstHeight, true);
}
try {
@@ -615,7 +617,7 @@ final public class InAppWebView extends InputAwareWebView {
quality = (Integer) screenshotConfiguration.get("quality");
}
- resized.compress(
+ screenshotBitmap.compress(
compressFormat,
quality,
byteArrayOutputStream);
@@ -625,7 +627,7 @@ final public class InAppWebView extends InputAwareWebView {
} catch (IOException e) {
e.printStackTrace();
}
- resized.recycle();
+ screenshotBitmap.recycle();
result.success(byteArrayOutputStream.toByteArray());
} catch (IllegalArgumentException e) {
@@ -982,7 +984,7 @@ final public class InAppWebView extends InputAwareWebView {
.replace(PluginScriptsUtil.VAR_RESULT_UUID, resultUuid);
}
final String finalScriptToInject = scriptToInject;
- headlessHandler.post(new Runnable() {
+ mainLooperHandler.post(new Runnable() {
@Override
public void run() {
String scriptToInject = userContentController.generateCodeForScriptEvaluation(finalScriptToInject, contentWorld);
@@ -1181,10 +1183,17 @@ final public class InAppWebView extends InputAwareWebView {
class DownloadStartListener implements DownloadListener {
@Override
- public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
- Map obj = new HashMap<>();
- obj.put("url", url);
- channel.invokeMethod("onDownloadStart", obj);
+ public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
+ DownloadStartRequest downloadStartRequest = new DownloadStartRequest(
+ url,
+ userAgent,
+ contentDisposition,
+ mimeType,
+ contentLength,
+ URLUtil.guessFileName(url, contentDisposition, mimeType),
+ null
+ );
+ channel.invokeMethod("onDownloadStartRequest", downloadStartRequest.toMap());
}
}
@@ -1231,11 +1240,9 @@ final public class InAppWebView extends InputAwareWebView {
}
private void sendOnCreateContextMenuEvent() {
- HitTestResult hitTestResult = getHitTestResult();
- Map obj = new HashMap<>();
- obj.put("type", hitTestResult.getType());
- obj.put("extra", hitTestResult.getExtra());
- channel.invokeMethod("onCreateContextMenu", obj);
+ com.pichillilorenzo.flutter_inappwebview.types.HitTestResult hitTestResult =
+ com.pichillilorenzo.flutter_inappwebview.types.HitTestResult.fromWebViewHitTestResult(getHitTestResult());
+ channel.invokeMethod("onCreateContextMenu", hitTestResult.toMap());
}
private Point contextMenuPoint = new Point(0, 0);
@@ -1302,8 +1309,7 @@ final public class InAppWebView extends InputAwareWebView {
public void run() {
InputMethodManager imm =
(InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE);
- if (imm != null && !imm.isAcceptingText()) {
-
+ if (containerView != null && imm != null && !imm.isAcceptingText()) {
imm.hideSoftInputFromWindow(
containerView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
@@ -1477,7 +1483,7 @@ final public class InAppWebView extends InputAwareWebView {
new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, curx, ((int) cury) + getScrollY())
);
- headlessHandler.post(new Runnable() {
+ mainLooperHandler.post(new Runnable() {
@Override
public void run() {
if (floatingContextMenu != null) {
@@ -1551,16 +1557,6 @@ final public class InAppWebView extends InputAwareWebView {
});
}
- @RequiresApi(api = Build.VERSION_CODES.KITKAT)
- public void getSelectedText(final MethodChannel.Result result) {
- getSelectedText(new ValueCallback() {
- @Override
- public void onReceiveValue(String value) {
- result.success(value);
- }
- });
- }
-
public Map requestFocusNodeHref() {
Message msg = InAppWebView.mHandler.obtainMessage();
requestFocusNodeHref(msg);
@@ -1649,8 +1645,16 @@ final public class InAppWebView extends InputAwareWebView {
return webMessageChannel;
}
- public void addWebMessageListener(@NonNull WebMessageListener webMessageListener) {
+ @Override
+ public WebMessageChannel createWebMessageChannel(ValueCallback callback) {
+ WebMessageChannel webMessageChannel = createCompatWebMessageChannel();
+ callback.onReceiveValue(webMessageChannel);
+ return webMessageChannel;
+ }
+
+ public void addWebMessageListener(@NonNull WebMessageListener webMessageListener) throws Exception {
WebViewCompat.addWebMessageListener(this, webMessageListener.jsObjectName, webMessageListener.allowedOriginRules, webMessageListener.listener);
+ webMessageListeners.add(webMessageListener);
}
public void disposeWebMessageChannels() {
@@ -1660,19 +1664,94 @@ final public class InAppWebView extends InputAwareWebView {
webMessageChannels.clear();
}
-// @Override
+ public void disposeWebMessageListeners() {
+ for (WebMessageListener webMessageListener : webMessageListeners) {
+ webMessageListener.dispose();
+ }
+ webMessageListeners.clear();
+ }
+
+ @Override
+ public void postWebMessage(com.pichillilorenzo.flutter_inappwebview.types.WebMessage message, Uri targetOrigin, ValueCallback callback) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ // @Override
// protected void onWindowVisibilityChanged(int visibility) {
// if (visibility != View.GONE) super.onWindowVisibilityChanged(View.VISIBLE);
// }
+ public float getZoomScale() {
+ return zoomScale;
+ }
+
+ @Override
+ public void getZoomScale(final ValueCallback callback) {
+ callback.onReceiveValue(zoomScale);
+ }
+
+ @Nullable
+ public Map getContextMenu() {
+ return contextMenu;
+ }
+
+ public void setContextMenu(@Nullable Map contextMenu) {
+ this.contextMenu = contextMenu;
+ }
+
+ @Nullable
+ public InAppWebViewFlutterPlugin getPlugin() {
+ return plugin;
+ }
+
+ public void setPlugin(@Nullable InAppWebViewFlutterPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ @Nullable
+ public InAppBrowserDelegate getInAppBrowserDelegate() {
+ return inAppBrowserDelegate;
+ }
+
+ public void setInAppBrowserDelegate(@Nullable InAppBrowserDelegate inAppBrowserDelegate) {
+ this.inAppBrowserDelegate = inAppBrowserDelegate;
+ }
+
+ public UserContentController getUserContentController() {
+ return userContentController;
+ }
+
+ public void setUserContentController(UserContentController userContentController) {
+ this.userContentController = userContentController;
+ }
+
+ public Map getWebMessageChannels() {
+ return webMessageChannels;
+ }
+
+ public void setWebMessageChannels(Map webMessageChannels) {
+ this.webMessageChannels = webMessageChannels;
+ }
+
+ @Override
+ public void getContentHeight(ValueCallback callback) {
+ callback.onReceiveValue(getContentHeight());
+ }
+
+ @Override
+ public void getHitTestResult(ValueCallback callback) {
+ callback.onReceiveValue(com.pichillilorenzo.flutter_inappwebview.types.HitTestResult.fromWebViewHitTestResult(getHitTestResult()));
+ }
+
@Override
public void dispose() {
if (windowId != null) {
InAppWebViewChromeClient.windowWebViewMessages.remove(windowId);
}
- headlessHandler.removeCallbacksAndMessages(null);
+ mainLooperHandler.removeCallbacksAndMessages(null);
mHandler.removeCallbacksAndMessages(null);
disposeWebMessageChannels();
+ disposeWebMessageListeners();
removeAllViews();
if (checkContextMenuShouldBeClosedTask != null)
removeCallbacks(checkContextMenuShouldBeClosedTask);
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java
index 224d75cd..b49f07f1 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewChromeClient.java
@@ -11,6 +11,7 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
+import android.os.Bundle;
import android.os.Environment;
import android.os.Message;
import android.os.Parcelable;
@@ -573,6 +574,19 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
WebView.HitTestResult result = view.getHitTestResult();
String url = result.getExtra();
+ // Ensure that images with hyperlink return the correct URL, not the image source
+ if(result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
+ Message href = view.getHandler().obtainMessage();
+ view.requestFocusNodeHref(href);
+ Bundle data = href.getData();
+ if (data != null) {
+ String imageUrl = data.getString("url");
+ if(imageUrl != null && !imageUrl.isEmpty()) {
+ url = imageUrl;
+ }
+ }
+ }
+
URLRequest request = new URLRequest(url, "GET", null, null);
CreateWindowAction createWindowAction = new CreateWindowAction(
request,
@@ -1004,7 +1018,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
private Boolean arrayContainsString(String[] array, String pattern) {
for (String content : array) {
- if (content.contains(pattern)) {
+ if (content != null && content.contains(pattern)) {
return true;
}
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewOptions.java
index 921c3c29..21917383 100755
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewOptions.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/in_app_webview/InAppWebViewOptions.java
@@ -7,6 +7,7 @@ import android.webkit.WebSettings;
import androidx.annotation.Nullable;
import com.pichillilorenzo.flutter_inappwebview.Options;
+import com.pichillilorenzo.flutter_inappwebview.types.InAppWebViewInterface;
import com.pichillilorenzo.flutter_inappwebview.types.PreferredContentModeOptionType;
import java.util.ArrayList;
@@ -17,7 +18,7 @@ import java.util.Map;
import static android.webkit.WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
import static android.webkit.WebSettings.LayoutAlgorithm.NORMAL;
-public class InAppWebViewOptions implements Options {
+public class InAppWebViewOptions implements Options {
public static final String LOG_TAG = "InAppWebViewOptions";
@@ -455,9 +456,10 @@ public class InAppWebViewOptions implements Options {
}
@Override
- public Map getRealOptions(InAppWebView webView) {
+ public Map getRealOptions(InAppWebViewInterface inAppWebView) {
Map realOptions = toMap();
- if (webView != null) {
+ if (inAppWebView instanceof InAppWebView) {
+ InAppWebView webView = (InAppWebView) inAppWebView;
WebSettings settings = webView.getSettings();
realOptions.put("userAgent", settings.getUserAgentString());
realOptions.put("javaScriptEnabled", settings.getJavaScriptEnabled());
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/plugin_scripts_js/JavaScriptBridgeJS.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/plugin_scripts_js/JavaScriptBridgeJS.java
index d4fa5fa8..565a6120 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/plugin_scripts_js/JavaScriptBridgeJS.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/plugin_scripts_js/JavaScriptBridgeJS.java
@@ -15,6 +15,7 @@ public class JavaScriptBridgeJS {
);
public static final String JAVASCRIPT_UTIL_VAR_NAME = "window." + JAVASCRIPT_BRIDGE_NAME + "._Util";
+ public static final String WEB_MESSAGE_CHANNELS_VARIABLE_NAME = "window." + JAVASCRIPT_BRIDGE_NAME + "._webMessageChannels";
public static final String UTIL_JS_SOURCE = JAVASCRIPT_UTIL_VAR_NAME + " = {" +
" support: {" +
@@ -131,10 +132,10 @@ public class JavaScriptBridgeJS {
" }," +
" convertBodyRequest: function(body) {" +
" if (body == null) {" +
- " return new Promise((resolve, reject) => resolve(null));" +
+ " return new Promise(function(resolve, reject) { resolve(null); });" +
" }" +
" if (" + JAVASCRIPT_UTIL_VAR_NAME + ".isString(body) || (" + JAVASCRIPT_UTIL_VAR_NAME + ".support.searchParams && body instanceof URLSearchParams)) {" +
- " return new Promise((resolve, reject) => resolve(body.toString()));" +
+ " return new Promise(function(resolve, reject) { resolve(body.toString()); });" +
" }" +
" if (window.Response != null) {" +
" return new Response(body).arrayBuffer().then(function(arrayBuffer) {" +
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/DownloadStartRequest.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/DownloadStartRequest.java
new file mode 100644
index 00000000..504fb693
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/DownloadStartRequest.java
@@ -0,0 +1,150 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class DownloadStartRequest {
+
+ @NonNull
+ private String url;
+ @NonNull
+ private String userAgent;
+ @NonNull
+ private String contentDisposition;
+ @NonNull
+ private String mimeType;
+ private long contentLength;
+ @Nullable
+ private String suggestedFilename;
+ @Nullable
+ private String textEncodingName;
+
+ public DownloadStartRequest(@NonNull String url, @NonNull String userAgent, @NonNull String contentDisposition, @NonNull String mimeType, long contentLength, @Nullable String suggestedFilename, @Nullable String textEncodingName) {
+ this.url = url;
+ this.userAgent = userAgent;
+ this.contentDisposition = contentDisposition;
+ this.mimeType = mimeType;
+ this.contentLength = contentLength;
+ this.suggestedFilename = suggestedFilename;
+ this.textEncodingName = textEncodingName;
+ }
+
+ public Map toMap() {
+ Map obj = new HashMap<>();
+ obj.put("url", url);
+ obj.put("userAgent", userAgent);
+ obj.put("contentDisposition", contentDisposition);
+ obj.put("mimeType", mimeType);
+ obj.put("contentLength", contentLength);
+ obj.put("suggestedFilename", suggestedFilename);
+ obj.put("textEncodingName", textEncodingName);
+ return obj;
+ }
+
+ @NonNull
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(@NonNull String url) {
+ this.url = url;
+ }
+
+ @NonNull
+ public String getUserAgent() {
+ return userAgent;
+ }
+
+ public void setUserAgent(@NonNull String userAgent) {
+ this.userAgent = userAgent;
+ }
+
+ @NonNull
+ public String getContentDisposition() {
+ return contentDisposition;
+ }
+
+ public void setContentDisposition(@NonNull String contentDisposition) {
+ this.contentDisposition = contentDisposition;
+ }
+
+ @NonNull
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ public void setMimeType(@NonNull String mimeType) {
+ this.mimeType = mimeType;
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public void setContentLength(long contentLength) {
+ this.contentLength = contentLength;
+ }
+
+ @Nullable
+ public String getSuggestedFilename() {
+ return suggestedFilename;
+ }
+
+ public void setSuggestedFilename(@Nullable String suggestedFilename) {
+ this.suggestedFilename = suggestedFilename;
+ }
+
+ @Nullable
+ public String getTextEncodingName() {
+ return textEncodingName;
+ }
+
+ public void setTextEncodingName(@Nullable String textEncodingName) {
+ this.textEncodingName = textEncodingName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ DownloadStartRequest that = (DownloadStartRequest) o;
+
+ if (contentLength != that.contentLength) return false;
+ if (!url.equals(that.url)) return false;
+ if (!userAgent.equals(that.userAgent)) return false;
+ if (!contentDisposition.equals(that.contentDisposition)) return false;
+ if (!mimeType.equals(that.mimeType)) return false;
+ if (suggestedFilename != null ? !suggestedFilename.equals(that.suggestedFilename) : that.suggestedFilename != null)
+ return false;
+ return textEncodingName != null ? textEncodingName.equals(that.textEncodingName) : that.textEncodingName == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = url.hashCode();
+ result = 31 * result + userAgent.hashCode();
+ result = 31 * result + contentDisposition.hashCode();
+ result = 31 * result + mimeType.hashCode();
+ result = 31 * result + (int) (contentLength ^ (contentLength >>> 32));
+ result = 31 * result + (suggestedFilename != null ? suggestedFilename.hashCode() : 0);
+ result = 31 * result + (textEncodingName != null ? textEncodingName.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "DownloadStartRequest{" +
+ "url='" + url + '\'' +
+ ", userAgent='" + userAgent + '\'' +
+ ", contentDisposition='" + contentDisposition + '\'' +
+ ", mimeType='" + mimeType + '\'' +
+ ", contentLength=" + contentLength +
+ ", suggestedFilename='" + suggestedFilename + '\'' +
+ ", textEncodingName='" + textEncodingName + '\'' +
+ '}';
+ }
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/HitTestResult.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/HitTestResult.java
new file mode 100644
index 00000000..058fd442
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/HitTestResult.java
@@ -0,0 +1,79 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+import android.webkit.WebView;
+
+import androidx.annotation.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class HitTestResult {
+ private int type;
+ @Nullable
+ private String extra;
+
+ public HitTestResult(int type, @Nullable String extra) {
+ this.type = type;
+ this.extra = extra;
+ }
+
+ @Nullable
+ static public HitTestResult fromWebViewHitTestResult(@Nullable WebView.HitTestResult hitTestResult) {
+ if (hitTestResult == null) {
+ return null;
+ }
+
+ return new HitTestResult(hitTestResult.getType(), hitTestResult.getExtra());
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ @Nullable
+ public String getExtra() {
+ return extra;
+ }
+
+ public void setExtra(@Nullable String extra) {
+ this.extra = extra;
+ }
+
+ @Nullable
+ public Map toMap() {
+ Map hitTestResultMap = new HashMap<>();
+ hitTestResultMap.put("type", type);
+ hitTestResultMap.put("extra", extra);
+ return hitTestResultMap;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ HitTestResult that = (HitTestResult) o;
+
+ if (type != that.type) return false;
+ return extra != null ? extra.equals(that.extra) : that.extra == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type;
+ result = 31 * result + (extra != null ? extra.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "HitTestResultMap{" +
+ "type=" + type +
+ ", extra='" + extra + '\'' +
+ '}';
+ }
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/InAppWebViewInterface.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/InAppWebViewInterface.java
new file mode 100644
index 00000000..dd20b474
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/InAppWebViewInterface.java
@@ -0,0 +1,101 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+import android.content.Context;
+import android.net.Uri;
+import android.net.http.SslCertificate;
+import android.webkit.ValueCallback;
+import android.webkit.WebMessage;
+import android.webkit.WebView;
+
+import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
+import com.pichillilorenzo.flutter_inappwebview.in_app_browser.InAppBrowserDelegate;
+import com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebViewOptions;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.flutter.plugin.common.MethodChannel;
+
+public interface InAppWebViewInterface {
+ Context getContext();
+ String getUrl();
+ String getTitle();
+ int getProgress();
+ void loadUrl(URLRequest urlRequest);
+ void postUrl(String url, byte[] postData);
+ void loadDataWithBaseURL(String baseUrl, String data,
+ String mimeType, String encoding, String historyUrl);
+ void loadFile(String assetFilePath) throws IOException;
+ void evaluateJavascript(String source, ContentWorld contentWorld, ValueCallback resultCallback);
+ void injectJavascriptFileFromUrl(String urlFile, Map scriptHtmlTagAttributes);
+ void injectCSSCode(String source);
+ void injectCSSFileFromUrl(String urlFile, Map cssLinkHtmlTagAttributes);
+ void reload();
+ void goBack();
+ boolean canGoBack();
+ void goForward();
+ boolean canGoForward();
+ void goBackOrForward(int steps);
+ boolean canGoBackOrForward(int steps);
+ void stopLoading();
+ boolean isLoading();
+ void takeScreenshot(Map screenshotConfiguration, MethodChannel.Result result);
+ void setOptions(InAppWebViewOptions newOptions, HashMap newOptionsMap);
+ Map getOptions();
+ HashMap getCopyBackForwardList();
+ void clearAllCache();
+ void clearSslPreferences();
+ void findAllAsync(String find);
+ void findNext(boolean forward);
+ void clearMatches();
+ void scrollTo(Integer x, Integer y, Boolean animated);
+ void scrollBy(Integer x, Integer y, Boolean animated);
+ void onPause();
+ void onResume();
+ void pauseTimers();
+ void resumeTimers();
+ void printCurrentPage();
+ int getContentHeight();
+ void getContentHeight(ValueCallback callback);
+ void zoomBy(float zoomFactor);
+ String getOriginalUrl();
+ void getSelectedText(ValueCallback callback);
+ WebView.HitTestResult getHitTestResult();
+ void getHitTestResult(ValueCallback callback);
+ boolean pageDown(boolean bottom);
+ boolean pageUp(boolean top);
+ void saveWebArchive(String basename, boolean autoname, ValueCallback callback);
+ boolean zoomIn();
+ boolean zoomOut();
+ void clearFocus();
+ Map requestFocusNodeHref();
+ Map requestImageRef();
+ int getScrollX();
+ int getScrollY();
+ SslCertificate getCertificate();
+ void clearHistory();
+ void callAsyncJavaScript(String functionBody, Map arguments, ContentWorld contentWorld, ValueCallback resultCallback);
+ void isSecureContext(final ValueCallback resultCallback);
+ WebMessageChannel createCompatWebMessageChannel();
+ WebMessageChannel createWebMessageChannel(ValueCallback callback);
+ void postWebMessage(WebMessage message, Uri targetOrigin);
+ void postWebMessage(com.pichillilorenzo.flutter_inappwebview.types.WebMessage message, Uri targetOrigin, ValueCallback callback) throws Exception;
+ void addWebMessageListener(WebMessageListener webMessageListener) throws Exception;
+ boolean canScrollVertically();
+ boolean canScrollHorizontally();
+ float getZoomScale();
+ void getZoomScale(ValueCallback callback);
+ Map getContextMenu();
+ void setContextMenu(Map contextMenu);
+ InAppWebViewFlutterPlugin getPlugin();
+ void setPlugin(InAppWebViewFlutterPlugin plugin);
+ InAppBrowserDelegate getInAppBrowserDelegate();
+ void setInAppBrowserDelegate(InAppBrowserDelegate inAppBrowserDelegate);
+ UserContentController getUserContentController();
+ void setUserContentController(UserContentController userContentController);
+ Map getWebMessageChannels();
+ void setWebMessageChannels(Map webMessageChannels);
+ void disposeWebMessageChannels();
+ void disposeWebMessageListeners();
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/PlatformWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/PlatformWebView.java
new file mode 100644
index 00000000..260f87d4
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/PlatformWebView.java
@@ -0,0 +1,9 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+import java.util.HashMap;
+
+import io.flutter.plugin.platform.PlatformView;
+
+public interface PlatformWebView extends PlatformView {
+ void makeInitialLoad(HashMap params);
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/UserContentController.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/UserContentController.java
index 2e019caf..ee1a3467 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/UserContentController.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/UserContentController.java
@@ -60,7 +60,7 @@ public class UserContentController {
return js;
}
- private String generateCodeForDocumentStart() {
+ public String generateCodeForDocumentStart() {
UserScriptInjectionTime injectionTime = UserScriptInjectionTime.AT_DOCUMENT_START;
String js = "";
js += generatePluginScriptsCodeAt(injectionTime);
@@ -70,7 +70,7 @@ public class UserContentController {
return js;
}
- private String generateContentWorldsCreatorCode() {
+ public String generateContentWorldsCreatorCode() {
if (this.contentWorlds.size() == 1) {
return "";
}
@@ -94,7 +94,7 @@ public class UserContentController {
}
- private String generatePluginScriptsCodeAt(UserScriptInjectionTime injectionTime) {
+ public String generatePluginScriptsCodeAt(UserScriptInjectionTime injectionTime) {
StringBuilder js = new StringBuilder();
LinkedHashSet scripts = this.getPluginScriptsAt(injectionTime);
for (PluginScript script : scripts) {
@@ -105,7 +105,7 @@ public class UserContentController {
return js.toString();
}
- private String generateUserOnlyScriptsCodeAt(UserScriptInjectionTime injectionTime) {
+ public String generateUserOnlyScriptsCodeAt(UserScriptInjectionTime injectionTime) {
StringBuilder js = new StringBuilder();
LinkedHashSet scripts = this.getUserOnlyScriptsAt(injectionTime);
for (UserScript script : scripts) {
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessage.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessage.java
new file mode 100644
index 00000000..497c3ca3
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessage.java
@@ -0,0 +1,23 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+import androidx.annotation.Nullable;
+
+import java.util.List;
+
+public class WebMessage {
+ @Nullable
+ public String data;
+ @Nullable
+ public List ports;
+
+ public WebMessage(@Nullable String data, @Nullable List ports) {
+ this.data = data;
+ this.ports = ports;
+ }
+
+ public void dispose() {
+ if (ports != null) {
+ ports.clear();
+ }
+ }
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageChannel.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageChannel.java
index 48d00985..c2b24b8b 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageChannel.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageChannel.java
@@ -1,5 +1,7 @@
package com.pichillilorenzo.flutter_inappwebview.types;
+import android.webkit.ValueCallback;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.webkit.WebMessageCompat;
@@ -8,6 +10,7 @@ import androidx.webkit.WebViewCompat;
import androidx.webkit.WebViewFeature;
import com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebView;
+import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.JavaScriptBridgeJS;
import java.util.ArrayList;
import java.util.Arrays;
@@ -23,85 +26,64 @@ public class WebMessageChannel implements MethodChannel.MethodCallHandler {
public String id;
public MethodChannel channel;
- public final List ports;
- private InAppWebView webView;
+ public final List compatPorts;
+ public final List ports;
+ public InAppWebViewInterface webView;
- public WebMessageChannel(@NonNull String id, @NonNull InAppWebView webView) {
+ public WebMessageChannel(@NonNull String id, @NonNull InAppWebViewInterface webView) {
this.id = id;
- this.channel = new MethodChannel(webView.plugin.messenger, "com.pichillilorenzo/flutter_inappwebview_web_message_channel_" + id);
+ this.channel = new MethodChannel(webView.getPlugin().messenger, "com.pichillilorenzo/flutter_inappwebview_web_message_channel_" + id);
this.channel.setMethodCallHandler(this);
- this.ports = new ArrayList<>(Arrays.asList(WebViewCompat.createWebMessageChannel(webView)));
+ if (webView instanceof InAppWebView) {
+ this.compatPorts = new ArrayList<>(Arrays.asList(WebViewCompat.createWebMessageChannel((InAppWebView) webView)));
+ this.ports = new ArrayList<>();
+ } else {
+ this.ports = Arrays.asList(new WebMessagePort("port1", this), new WebMessagePort("port2", this));
+ this.compatPorts = new ArrayList<>();
+ }
this.webView = webView;
}
+ public void initJsInstance(InAppWebViewInterface webView, final ValueCallback callback) {
+ if (webView != null) {
+ final WebMessageChannel webMessageChannel = this;
+ webView.evaluateJavascript("(function() {" +
+ JavaScriptBridgeJS.WEB_MESSAGE_CHANNELS_VARIABLE_NAME + "['" + webMessageChannel.id + "'] = new MessageChannel();" +
+ "})();", null, new ValueCallback() {
+ @Override
+ public void onReceiveValue(String value) {
+ callback.onReceiveValue(webMessageChannel);
+ }
+ });
+ } else {
+ callback.onReceiveValue(this);
+ }
+ }
+
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
switch (call.method) {
case "setWebMessageCallback":
- if (webView != null && ports.size() > 0 &&
- WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK)) {
+ if (webView instanceof InAppWebView) {
final Integer index = (Integer) call.argument("index");
- final WebMessagePortCompat webMessagePort = ports.get(index);
- try {
- webMessagePort.setWebMessageCallback(new WebMessagePortCompat.WebMessageCallbackCompat() {
- @Override
- public void onMessage(@NonNull WebMessagePortCompat port, @Nullable WebMessageCompat message) {
- super.onMessage(port, message);
-
- Map obj = new HashMap<>();
- obj.put("index", index);
- obj.put("message", message != null ? message.getData() : null);
- channel.invokeMethod("onMessage", obj);
- }
- });
- result.success(true);
- } catch (Exception e) {
- result.error(LOG_TAG, e.getMessage(), null);
- }
+ setWebMessageCallbackForInAppWebView(index, result);
} else {
result.success(true);
}
break;
case "postMessage":
- if (webView != null && ports.size() > 0 &&
- WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE)) {
+ if (webView instanceof InAppWebView) {
final Integer index = (Integer) call.argument("index");
- WebMessagePortCompat port = ports.get(index);
Map message = (Map) call.argument("message");
- List webMessagePorts = new ArrayList<>();
- List> portsMap = (List>) message.get("ports");
- if (portsMap != null) {
- for (Map portMap : portsMap) {
- String webMessageChannelId = (String) portMap.get("webMessageChannelId");
- Integer portIndex = (Integer) portMap.get("index");
- WebMessageChannel webMessageChannel = webView.webMessageChannels.get(webMessageChannelId);
- if (webMessageChannel != null) {
- webMessagePorts.add(webMessageChannel.ports.get(portIndex));
- }
- }
- }
- WebMessageCompat webMessage = new WebMessageCompat((String) message.get("data"), webMessagePorts.toArray(new WebMessagePortCompat[0]));
- try {
- port.postMessage(webMessage);
- result.success(true);
- } catch (Exception e) {
- result.error(LOG_TAG, e.getMessage(), null);
- }
+ postMessageForInAppWebView(index, message, result);
} else {
result.success(true);
}
break;
case "close":
- if (webView != null && ports.size() > 0 &&
- WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_CLOSE)) {
+ if (webView instanceof InAppWebView) {
Integer index = (Integer) call.argument("index");
- WebMessagePortCompat port = ports.get(index);
- try {
- port.close();
- result.success(true);
- } catch (Exception e) {
- result.error(LOG_TAG, e.getMessage(), null);
- }
+ closeForInAppWebView(index, result);
} else {
result.success(true);
}
@@ -110,6 +92,81 @@ public class WebMessageChannel implements MethodChannel.MethodCallHandler {
result.notImplemented();
}
}
+
+ private void setWebMessageCallbackForInAppWebView(final Integer index, @NonNull MethodChannel.Result result) {
+ if (webView != null && compatPorts.size() > 0 &&
+ WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK)) {
+ final WebMessagePortCompat webMessagePort = compatPorts.get(index);
+ try {
+ webMessagePort.setWebMessageCallback(new WebMessagePortCompat.WebMessageCallbackCompat() {
+ @Override
+ public void onMessage(@NonNull WebMessagePortCompat port, @Nullable WebMessageCompat message) {
+ super.onMessage(port, message);
+
+ Map obj = new HashMap<>();
+ obj.put("index", index);
+ obj.put("message", message != null ? message.getData() : null);
+ channel.invokeMethod("onMessage", obj);
+ }
+ });
+ result.success(true);
+ } catch (Exception e) {
+ result.error(LOG_TAG, e.getMessage(), null);
+ }
+ } else {
+ result.success(true);
+ }
+ }
+
+ private void postMessageForInAppWebView(final Integer index, Map message, @NonNull MethodChannel.Result result) {
+ if (webView != null && compatPorts.size() > 0 &&
+ WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE)) {
+ WebMessagePortCompat port = compatPorts.get(index);
+ List webMessagePorts = new ArrayList<>();
+ List> portsMap = (List>) message.get("ports");
+ if (portsMap != null) {
+ for (Map portMap : portsMap) {
+ String webMessageChannelId = (String) portMap.get("webMessageChannelId");
+ Integer portIndex = (Integer) portMap.get("index");
+ WebMessageChannel webMessageChannel = webView.getWebMessageChannels().get(webMessageChannelId);
+ if (webMessageChannel != null) {
+ webMessagePorts.add(webMessageChannel.compatPorts.get(portIndex));
+ }
+ }
+ }
+ WebMessageCompat webMessage = new WebMessageCompat((String) message.get("data"), webMessagePorts.toArray(new WebMessagePortCompat[0]));
+ try {
+ port.postMessage(webMessage);
+ result.success(true);
+ } catch (Exception e) {
+ result.error(LOG_TAG, e.getMessage(), null);
+ }
+ } else {
+ result.success(true);
+ }
+ }
+
+ private void closeForInAppWebView(Integer index, @NonNull MethodChannel.Result result) {
+ if (webView != null && compatPorts.size() > 0 &&
+ WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_CLOSE)) {
+ WebMessagePortCompat port = compatPorts.get(index);
+ try {
+ port.close();
+ result.success(true);
+ } catch (Exception e) {
+ result.error(LOG_TAG, e.getMessage(), null);
+ }
+ } else {
+ result.success(true);
+ }
+ }
+
+ public void onMessage(Integer index, String message) {
+ Map obj = new HashMap<>();
+ obj.put("index", index);
+ obj.put("message", message );
+ channel.invokeMethod("onMessage", obj);
+ }
public Map toMap() {
Map webMessageChannelMap = new HashMap<>();
@@ -119,14 +176,14 @@ public class WebMessageChannel implements MethodChannel.MethodCallHandler {
public void dispose() {
if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_PORT_CLOSE)) {
- for (WebMessagePortCompat port : ports) {
+ for (WebMessagePortCompat port : compatPorts) {
try {
port.close();
} catch (Exception ignored) {}
}
}
this.channel.setMethodCallHandler(null);
- this.ports.clear();
+ this.compatPorts.clear();
this.webView = null;
}
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageListener.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageListener.java
index 16379e4c..ded33592 100644
--- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageListener.java
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessageListener.java
@@ -1,6 +1,8 @@
package com.pichillilorenzo.flutter_inappwebview.types;
import android.net.Uri;
+import android.text.TextUtils;
+import android.webkit.ValueCallback;
import android.webkit.WebView;
import androidx.annotation.NonNull;
@@ -10,6 +12,11 @@ import androidx.webkit.WebMessageCompat;
import androidx.webkit.WebViewCompat;
import androidx.webkit.WebViewFeature;
+import com.pichillilorenzo.flutter_inappwebview.Util;
+import com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebView;
+import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.JavaScriptBridgeJS;
+
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -28,27 +35,63 @@ public class WebMessageListener implements MethodChannel.MethodCallHandler {
public WebViewCompat.WebMessageListener listener;
public JavaScriptReplyProxy replyProxy;
public MethodChannel channel;
+ public InAppWebViewInterface webView;
- public WebMessageListener(@NonNull BinaryMessenger messenger, @NonNull String jsObjectName, @NonNull Set allowedOriginRules) {
+ public WebMessageListener(@NonNull InAppWebViewInterface webView, @NonNull BinaryMessenger messenger, @NonNull String jsObjectName, @NonNull Set allowedOriginRules) {
+ this.webView = webView;
this.jsObjectName = jsObjectName;
this.allowedOriginRules = allowedOriginRules;
this.channel = new MethodChannel(messenger, "com.pichillilorenzo/flutter_inappwebview_web_message_listener_" + this.jsObjectName);
this.channel.setMethodCallHandler(this);
- this.listener = new WebViewCompat.WebMessageListener() {
- @Override
- public void onPostMessage(@NonNull WebView view, @NonNull WebMessageCompat message, @NonNull Uri sourceOrigin, boolean isMainFrame, @NonNull JavaScriptReplyProxy javaScriptReplyProxy) {
- replyProxy = javaScriptReplyProxy;
- Map obj = new HashMap<>();
- obj.put("message", message.getData());
- obj.put("sourceOrigin", sourceOrigin.toString().equals("null") ? null : sourceOrigin.toString());
- obj.put("isMainFrame", isMainFrame);
- channel.invokeMethod("onPostMessage", obj);
+ if (this.webView instanceof InAppWebView) {
+ final WebMessageListener self = this;
+ this.listener = new WebViewCompat.WebMessageListener() {
+ @Override
+ public void onPostMessage(@NonNull WebView view, @NonNull WebMessageCompat message, @NonNull Uri sourceOrigin, boolean isMainFrame, @NonNull JavaScriptReplyProxy javaScriptReplyProxy) {
+ replyProxy = javaScriptReplyProxy;
+ self.onPostMessage(message.getData(), sourceOrigin, isMainFrame);
+ }
+ };
+ }
+ }
+
+ public void initJsInstance() {
+ if (webView != null) {
+ String jsObjectNameEscaped = Util.replaceAll(jsObjectName, "\'", "\\'");
+ List allowedOriginRulesStringList = new ArrayList<>();
+ for (String allowedOriginRule : allowedOriginRules) {
+ if ("*".equals(allowedOriginRule)) {
+ allowedOriginRulesStringList.add("'*'");
+ } else {
+ Uri rule = Uri.parse(allowedOriginRule);
+ String host = rule.getHost() != null ? "'" + Util.replaceAll(rule.getHost(), "\'", "\\'") + "'" : "null";
+ allowedOriginRulesStringList.add("{scheme: '" + rule.getScheme() + "', host: " + host + ", port: " + (rule.getPort() != -1 ? rule.getPort() : "null") + "}");
+ }
}
- };
+ String allowedOriginRulesString = TextUtils.join(", ", allowedOriginRulesStringList);
+
+ String source = "(function() {" +
+ " var allowedOriginRules = [" + allowedOriginRulesString + "];" +
+ " var isPageBlank = window.location.href === 'about:blank';" +
+ " var scheme = !isPageBlank ? window.location.protocol.replace(':', '') : null;" +
+ " var host = !isPageBlank ? window.location.hostname : null;" +
+ " var port = !isPageBlank ? window.location.port : null;" +
+ " if (window." + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "._isOriginAllowed(allowedOriginRules, scheme, host, port)) {" +
+ " window['" + jsObjectNameEscaped + "'] = new FlutterInAppWebViewWebMessageListener('" + jsObjectNameEscaped + "');" +
+ " }" +
+ "})();";
+ webView.getUserContentController().addPluginScript(new PluginScript(
+ "WebMessageListener-" + jsObjectName,
+ source,
+ UserScriptInjectionTime.AT_DOCUMENT_START,
+ null,
+ false
+ ));
+ }
}
@Nullable
- public static WebMessageListener fromMap(@NonNull BinaryMessenger messenger, @Nullable Map map) {
+ public static WebMessageListener fromMap(@NonNull InAppWebViewInterface webView, @NonNull BinaryMessenger messenger, @Nullable Map map) {
if (map == null) {
return null;
}
@@ -57,27 +100,137 @@ public class WebMessageListener implements MethodChannel.MethodCallHandler {
List allowedOriginRuleList = (List) map.get("allowedOriginRules");
assert allowedOriginRuleList != null;
Set allowedOriginRules = new HashSet<>(allowedOriginRuleList);
- return new WebMessageListener(messenger, jsObjectName, allowedOriginRules);
+ return new WebMessageListener(webView, messenger, jsObjectName, allowedOriginRules);
}
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
switch (call.method) {
case "postMessage":
- if (replyProxy != null && WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
+ if (webView instanceof InAppWebView) {
String message = (String) call.argument("message");
- replyProxy.postMessage(message);
+ postMessageForInAppWebView(message, result);
+ } else {
+ result.success(true);
}
- result.success(true);
break;
default:
result.notImplemented();
}
}
+ public void assertOriginRulesValid() throws Exception {
+ int index = 0;
+ for (String originRule : allowedOriginRules) {
+ if (originRule == null) {
+ throw new Exception("allowedOriginRules[" + index + "] is null");
+ }
+ if (originRule.isEmpty()) {
+ throw new Exception("allowedOriginRules[" + index + "] is empty");
+ }
+ if ("*".equals(originRule)) {
+ continue;
+ }
+ Uri url = Uri.parse(originRule);
+ String scheme = url.getScheme();
+ String host = url.getHost();
+ String path = url.getPath();
+ int port = url.getPort();
+ if (scheme == null) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ if (("http".equals(scheme) || "https".equals(scheme)) && (host == null || host.isEmpty())) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ if (!"http".equals(scheme) && !"https".equals(scheme) && (host != null || port != -1)) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ if ((host == null || host.isEmpty()) && port != -1) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ if (!path.isEmpty()) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ if (host != null) {
+ int distance = host.indexOf("*");
+ if (distance != 0 || (distance == 0 && !host.startsWith("*."))) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ if (host.startsWith("[")) {
+ if (!host.endsWith("]")) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ String ipv6 = host.substring(1, host.length() - 1);
+ if (!Util.isIPv6(ipv6)) {
+ throw new Exception("allowedOriginRules " + originRule + " is invalid");
+ }
+ }
+ }
+ index++;
+ }
+ }
+
+ private void postMessageForInAppWebView(String message, @NonNull MethodChannel.Result result) {
+ if (replyProxy != null && WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
+ replyProxy.postMessage(message);
+ }
+ result.success(true);
+ }
+
+ public boolean isOriginAllowed(String scheme, String host, int port) {
+ for (String allowedOriginRule : allowedOriginRules) {
+ if ("*".equals(allowedOriginRule)) {
+ return true;
+ }
+ if (scheme == null || scheme.isEmpty()) {
+ continue;
+ }
+ if ((scheme == null || scheme.isEmpty()) && (host == null || host.isEmpty()) && (port == 0 || port == -1)) {
+ continue;
+ }
+ Uri rule = Uri.parse(allowedOriginRule);
+ int rulePort = rule.getPort() == -1 || rule.getPort() == 0 ? ("https".equals(rule.getScheme()) ? 443 : 80) : rule.getPort();
+ int currentPort = port == 0 || port == -1 ? ("https".equals(scheme) ? 443 : 80) : port;
+ String IPv6 = null;
+ if (rule.getHost() != null && rule.getHost().startsWith("[")) {
+ try {
+ IPv6 = Util.normalizeIPv6(rule.getHost().substring(1, rule.getHost().length() - 1));
+ } catch (Exception ignored) {}
+ }
+ String hostIPv6 = null;
+ try {
+ hostIPv6 = Util.normalizeIPv6(host);
+ } catch (Exception ignored) {}
+
+ boolean schemeAllowed = rule.getScheme().equals(scheme);
+
+ boolean hostAllowed = rule.getHost() == null ||
+ rule.getHost().isEmpty() ||
+ rule.getHost().equals(host) ||
+ (rule.getHost().startsWith("*") && host != null && host.contains(rule.getHost().split("\\*")[1])) ||
+ (hostIPv6 != null && IPv6 != null && hostIPv6.equals(IPv6));
+
+ boolean portAllowed = rulePort == currentPort;
+
+ if (schemeAllowed && hostAllowed && portAllowed) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void onPostMessage(String message, Uri sourceOrigin, boolean isMainFrame) {
+ Map obj = new HashMap<>();
+ obj.put("message", message);
+ obj.put("sourceOrigin", sourceOrigin.toString().equals("null") ? null : sourceOrigin.toString());
+ obj.put("isMainFrame", isMainFrame);
+ channel.invokeMethod("onPostMessage", obj);
+ }
+
public void dispose() {
this.channel.setMethodCallHandler(null);
this.listener = null;
this.replyProxy = null;
+ this.webView = null;
}
}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessagePort.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessagePort.java
new file mode 100644
index 00000000..f3c07d2b
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebMessagePort.java
@@ -0,0 +1,130 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+import android.text.TextUtils;
+import android.webkit.ValueCallback;
+
+import com.pichillilorenzo.flutter_inappwebview.Util;
+import com.pichillilorenzo.flutter_inappwebview.plugin_scripts_js.JavaScriptBridgeJS;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WebMessagePort {
+ public String name;
+ public WebMessageChannel webMessageChannel;
+ public boolean isClosed = false;
+ public boolean isTransferred = false;
+ public boolean isStarted = false;
+
+ public WebMessagePort(String name, WebMessageChannel webMessageChannel) {
+ this.name = name;
+ this.webMessageChannel = webMessageChannel;
+ }
+
+ public void setWebMessageCallback(final ValueCallback callback) throws Exception {
+ if (isClosed || isTransferred) {
+ throw new Exception("Port is already closed or transferred");
+ }
+ this.isStarted = true;
+ InAppWebViewInterface webView = webMessageChannel != null && webMessageChannel.webView != null ? webMessageChannel.webView : null;
+ if (webView != null) {
+ int index = name.equals("port1") ? 0 : 1;
+ webView.evaluateJavascript("(function() {" +
+ " var webMessageChannel = " + JavaScriptBridgeJS.WEB_MESSAGE_CHANNELS_VARIABLE_NAME + "['" + webMessageChannel.id + "'];" +
+ " if (webMessageChannel != null) {" +
+ " webMessageChannel." + this.name + ".onmessage = function (event) {" +
+ " window." + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + ".callHandler('onWebMessagePortMessageReceived', {" +
+ " 'webMessageChannelId': '" + webMessageChannel.id + "'," +
+ " 'index': " + index + "," +
+ " 'message': event.data" +
+ " });" +
+ " }" +
+ " }" +
+ "})();", null, new ValueCallback() {
+ @Override
+ public void onReceiveValue(String value) {
+ if (callback != null) {
+ callback.onReceiveValue(null);
+ }
+ }
+ });
+ } else {
+ if (callback != null) {
+ callback.onReceiveValue(null);
+ }
+ }
+ }
+
+ public void postMessage(WebMessage message, final ValueCallback callback) throws Exception {
+ if (isClosed || isTransferred) {
+ throw new Exception("Port is already closed or transferred");
+ }
+ InAppWebViewInterface webView = webMessageChannel != null && webMessageChannel.webView != null ? webMessageChannel.webView : null;
+ if (webView != null) {
+ String portsString = "null";
+ List ports = message.ports;
+ if (ports != null) {
+ List portArrayString = new ArrayList<>();
+ for (WebMessagePort port : ports) {
+ if (port == this) {
+ throw new Exception("Source port cannot be transferred");
+ }
+ if (port.isStarted) {
+ throw new Exception("Port is already started");
+ }
+ if (port.isClosed || port.isTransferred) {
+ throw new Exception("Port is already closed or transferred");
+ }
+ port.isTransferred = true;
+ portArrayString.add(JavaScriptBridgeJS.WEB_MESSAGE_CHANNELS_VARIABLE_NAME + "['" + webMessageChannel.id + "']." + port.name);
+ }
+ portsString = "[" + TextUtils.join(", ", portArrayString) + "]";
+ }
+ String data = message.data != null ? Util.replaceAll(message.data, "\'", "\\'") : "null";
+ String source = "(function() {" +
+ " var webMessageChannel = " + JavaScriptBridgeJS.WEB_MESSAGE_CHANNELS_VARIABLE_NAME + "['" + webMessageChannel.id + "'];" +
+ " if (webMessageChannel != null) {" +
+ " webMessageChannel." + this.name + ".postMessage('" + data + "', " + portsString + ");" +
+ " }" +
+ "})();";
+ webView.evaluateJavascript(source, null, new ValueCallback() {
+ @Override
+ public void onReceiveValue(String value) {
+ callback.onReceiveValue(null);
+ }
+ });
+ } else {
+ callback.onReceiveValue(null);
+ }
+ message.dispose();
+ }
+
+ public void close(final ValueCallback callback) throws Exception {
+ if (isTransferred) {
+ throw new Exception("Port is already transferred");
+ }
+ isClosed = true;
+ InAppWebViewInterface webView = webMessageChannel != null && webMessageChannel.webView != null ? webMessageChannel.webView : null;
+ if (webView != null) {
+ String source = "(function() {" +
+ " var webMessageChannel = " + JavaScriptBridgeJS.WEB_MESSAGE_CHANNELS_VARIABLE_NAME + "['" + webMessageChannel.id + "'];" +
+ " if (webMessageChannel != null) {" +
+ " webMessageChannel." + this.name + ".close();" +
+ " }" +
+ "})();";
+ webView.evaluateJavascript(source, null, new ValueCallback() {
+ @Override
+ public void onReceiveValue(String value) {
+ callback.onReceiveValue(null);
+ }
+ });
+ } else {
+ callback.onReceiveValue(null);
+ }
+ }
+
+ public void dispose() {
+ isClosed = true;
+ webMessageChannel = null;
+ }
+}
diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebViewImplementation.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebViewImplementation.java
new file mode 100644
index 00000000..81d37d26
--- /dev/null
+++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebViewImplementation.java
@@ -0,0 +1,32 @@
+package com.pichillilorenzo.flutter_inappwebview.types;
+
+public enum WebViewImplementation {
+ NATIVE(0);
+
+ private final int value;
+
+ private WebViewImplementation(int value) {
+ this.value = value;
+ }
+
+ public boolean equalsValue(int otherValue) {
+ return value == otherValue;
+ }
+
+ public static WebViewImplementation fromValue(int value) {
+ for( WebViewImplementation type : WebViewImplementation.values()) {
+ if(value == type.value)
+ return type;
+ }
+ throw new IllegalArgumentException("No enum constant: " + value);
+ }
+
+ public int rawValue() {
+ return this.value;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.value);
+ }
+}
\ No newline at end of file
diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies
index 8f69f5ce..6dcd5d95 100644
--- a/example/.flutter-plugins-dependencies
+++ b/example/.flutter-plugins-dependencies
@@ -1 +1 @@
-{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/fvm/versions/2.1.0-10.0.pre/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"android":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/fvm/versions/2.1.0-10.0.pre/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.5-nullsafety/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.1.0-nullsafety.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.2.0-nullsafety/","dependencies":[]},{"name":"url_launcher_linux","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.1.0-nullsafety.3/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.1.0-nullsafety.3/","dependencies":[]},{"name":"url_launcher_windows","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-0.1.0-nullsafety.2/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2021-04-07 18:05:10.935076","version":"2.1.0-10.0.pre"}
\ No newline at end of file
+{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/fvm/versions/2.10.4/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"android":[{"name":"flutter_downloader","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.5.2/","dependencies":[]},{"name":"flutter_inappwebview","path":"/Users/lorenzopichilli/Desktop/flutter_inappwebview/","dependencies":[]},{"name":"integration_test","path":"/Users/lorenzopichilli/fvm/versions/2.10.4/packages/integration_test/","dependencies":[]},{"name":"path_provider","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.0-nullsafety/","dependencies":[]},{"name":"permission_handler","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/","dependencies":[]},{"name":"url_launcher","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.0-nullsafety.6/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.5-nullsafety/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.1.0-nullsafety.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.2.0-nullsafety/","dependencies":[]},{"name":"url_launcher_linux","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.1.0-nullsafety.3/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.1.0-nullsafety.3/","dependencies":[]},{"name":"url_launcher_windows","path":"/Users/lorenzopichilli/.pub-cache/hosted/pub.dartlang.org/url_launcher_windows-0.1.0-nullsafety.2/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"flutter_inappwebview","dependencies":[]},{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2022-04-17 17:18:13.163601","version":"2.10.4"}
\ No newline at end of file
diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index fe6dd2d3..f1038725 100755
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -27,7 +27,6 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
@@ -36,22 +35,22 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
();
final Completer onDownloadStartCompleter = Completer();
await tester.pumpWidget(
@@ -2739,8 +2739,8 @@ void main() {
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
- onDownloadStart: (controller, url) {
- onDownloadStartCompleter.complete(url.toString());
+ onDownloadStartRequest: (controller, request) {
+ onDownloadStartCompleter.complete(request.url.toString());
},
),
),
diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist
index 9367d483..8d4492f9 100755
--- a/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/example/ios/Flutter/AppFrameworkInfo.plist
@@ -21,6 +21,6 @@
CFBundleVersion
1.0
MinimumOSVersion
- 8.0
+ 9.0
diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec
index 2c4421cf..663d5b29 100644
--- a/example/ios/Flutter/Flutter.podspec
+++ b/example/ios/Flutter/Flutter.podspec
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
- s.ios.deployment_target = '8.0'
+ s.ios.deployment_target = '9.0'
# Framework linking is handled by Flutter tooling, not CocoaPods.
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
s.vendored_frameworks = 'path/to/nothing'
diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh
index ff713474..9e98dd5e 100755
--- a/example/ios/Flutter/flutter_export_environment.sh
+++ b/example/ios/Flutter/flutter_export_environment.sh
@@ -1,13 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
-export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.1.0-10.0.pre"
+export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
-export "FLUTTER_TARGET=integration_test/webview_flutter_test.dart"
+export "COCOAPODS_PARALLEL_CODE_SIGN=true"
+export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
-export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
-export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
+export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index 8a7c5b93..06db17d9 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
- objectVersion = 46;
+ objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
@@ -170,7 +170,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1240;
- LastUpgradeCheck = 1110;
+ LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "The Chromium Authors";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
@@ -375,7 +375,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -427,7 +427,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
index 24c05c50..50a8cfc9 100755
--- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
+++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
@@ -1,6 +1,6 @@
{
InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
- mediaPlaybackRequiresUserGesture: false,
+ mediaPlaybackRequiresUserGesture: false
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
diff --git a/flutter_inappwebview.iml b/flutter_inappwebview.iml
index 4cb39159..4f3a5faa 100755
--- a/flutter_inappwebview.iml
+++ b/flutter_inappwebview.iml
@@ -5,6 +5,12 @@
+
+
+
+
+
+
@@ -80,6 +86,5 @@
-
\ No newline at end of file
diff --git a/ios/.gitignore b/ios/.gitignore
index 710ec6cf..0c885071 100755
--- a/ios/.gitignore
+++ b/ios/.gitignore
@@ -34,3 +34,5 @@ Icon?
.tags*
/Flutter/Generated.xcconfig
+/Flutter/ephemeral/
+/Flutter/flutter_export_environment.sh
\ No newline at end of file
diff --git a/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift b/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift
index 6fb9a1be..b5f2ef62 100644
--- a/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift
+++ b/ios/Classes/HeadlessInAppWebView/HeadlessInAppWebView.swift
@@ -92,4 +92,9 @@ public class HeadlessInAppWebView : FlutterMethodCallDelegate {
HeadlessInAppWebViewManager.webViews.removeValue(forKey: id)
flutterWebView = nil
}
+
+ deinit {
+ print("HeadlessInAppWebView - dealloc")
+ dispose()
+ }
}
diff --git a/ios/Classes/InAppWebView/InAppWebView.swift b/ios/Classes/InAppWebView/InAppWebView.swift
index f49fcef7..4c59f433 100755
--- a/ios/Classes/InAppWebView/InAppWebView.swift
+++ b/ios/Classes/InAppWebView/InAppWebView.swift
@@ -19,6 +19,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
var pullToRefreshControl: PullToRefreshControl?
var webMessageChannels: [String:WebMessageChannel] = [:]
var webMessageListeners: [WebMessageListener] = []
+ var currentOriginalUrl: URL?
static var sslCertificatesMap: [String: SslCertificate] = [:] // [URL host name : SslCertificate]
static var credentialsProposed: [URLCredential] = []
@@ -26,6 +27,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
var lastScrollX: CGFloat = 0
var lastScrollY: CGFloat = 0
+ // Used to manage pauseTimers() and resumeTimers()
var isPausedTimers = false
var isPausedTimersCompletionHandler: (() -> Void)?
@@ -405,9 +407,6 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
if #available(iOS 9.0, *) {
configuration.allowsAirPlayForMediaPlayback = options.allowsAirPlayForMediaPlayback
configuration.allowsPictureInPictureMediaPlayback = options.allowsPictureInPictureMediaPlayback
- if !options.applicationNameForUserAgent.isEmpty {
- configuration.applicationNameForUserAgent = options.applicationNameForUserAgent
- }
}
configuration.preferences.javaScriptCanOpenWindowsAutomatically = options.javaScriptCanOpenWindowsAutomatically
@@ -499,6 +498,11 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
} else if options.cacheEnabled {
configuration.websiteDataStore = WKWebsiteDataStore.default()
}
+ if !options.applicationNameForUserAgent.isEmpty {
+ if let applicationNameForUserAgent = configuration.applicationNameForUserAgent {
+ configuration.applicationNameForUserAgent = applicationNameForUserAgent + " " + options.applicationNameForUserAgent
+ }
+ }
}
if #available(iOS 10.0, *) {
@@ -527,7 +531,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
// Set Cookies in iOS 11 and above, initialize websiteDataStore before setting cookies
// See also https://forums.developer.apple.com/thread/97194
// check if websiteDataStore has not been initialized before
- if(!options.incognito && options.cacheEnabled) {
+ if(!options.incognito && !options.cacheEnabled) {
configuration.websiteDataStore = WKWebsiteDataStore.nonPersistent()
}
for cookie in HTTPCookieStorage.shared.cookies ?? [] {
@@ -1542,7 +1546,14 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
let mimeType = navigationResponse.response.mimeType
if let url = navigationResponse.response.url, navigationResponse.isForMainFrame {
if url.scheme != "file", mimeType != nil, !mimeType!.starts(with: "text/") {
- onDownloadStart(url: url.absoluteString)
+ let downloadStartRequest = DownloadStartRequest(url: url.absoluteString,
+ userAgent: nil,
+ contentDisposition: nil,
+ mimeType: mimeType,
+ contentLength: navigationResponse.response.expectedContentLength,
+ suggestedFilename: navigationResponse.response.suggestedFilename,
+ textEncodingName: navigationResponse.response.textEncodingName)
+ onDownloadStartRequest(request: downloadStartRequest)
if useOnNavigationResponse == nil || !useOnNavigationResponse! {
decisionHandler(.cancel)
}
@@ -1557,6 +1568,9 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
}
public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
+ currentOriginalUrl = url
+ lastTouchPoint = nil
+
disposeWebMessageChannels()
initializeWindowIdJS()
@@ -2356,9 +2370,8 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
channel?.invokeMethod("onOverScrolled", arguments: arguments)
}
- public func onDownloadStart(url: String) {
- let arguments: [String: Any] = ["url": url]
- channel?.invokeMethod("onDownloadStart", arguments: arguments)
+ public func onDownloadStartRequest(request: DownloadStartRequest) {
+ channel?.invokeMethod("onDownloadStartRequest", arguments: request.toMap())
}
public func onLoadResourceCustomScheme(url: String, result: FlutterResult?) {
@@ -2723,6 +2736,10 @@ if(window.\(JAVASCRIPT_BRIDGE_NAME)[\(_callHandlerID)] != null) {
scrollView.setZoomScale(currentZoomScale * CGFloat(zoomFactor), animated: animated)
}
+ public func getOriginalUrl() -> URL? {
+ return currentOriginalUrl
+ }
+
public func getZoomScale() -> Float {
return Float(scrollView.zoomScale)
}
@@ -2883,10 +2900,7 @@ if(window.\(JAVASCRIPT_BRIDGE_NAME)[\(_callHandlerID)] != null) {
}
public func dispose() {
- if isPausedTimers, let completionHandler = isPausedTimersCompletionHandler {
- isPausedTimersCompletionHandler = nil
- completionHandler()
- }
+ resumeTimers()
stopLoading()
disposeWebMessageChannels()
for webMessageListener in webMessageListeners {
diff --git a/ios/Classes/InAppWebViewMethodHandler.swift b/ios/Classes/InAppWebViewMethodHandler.swift
index 58092f63..ca13aa8c 100644
--- a/ios/Classes/InAppWebViewMethodHandler.swift
+++ b/ios/Classes/InAppWebViewMethodHandler.swift
@@ -289,8 +289,8 @@ public class InAppWebViewMethodHandler: FlutterMethodCallDelegate {
result(webView?.getContentHeight())
break
case "zoomBy":
- let zoomFactor = arguments!["zoomFactor"] as! Float
- let animated = arguments!["iosAnimated"] as! Bool
+ let zoomFactor = (arguments!["zoomFactor"] as! NSNumber).floatValue
+ let animated = arguments!["animated"] as! Bool
webView?.zoomBy(zoomFactor: zoomFactor, animated: animated)
result(true)
break
@@ -298,6 +298,9 @@ public class InAppWebViewMethodHandler: FlutterMethodCallDelegate {
webView?.reloadFromOrigin()
result(true)
break
+ case "getOriginalUrl":
+ result(webView?.getOriginalUrl()?.absoluteString)
+ break
case "getZoomScale":
result(webView?.getZoomScale())
break
diff --git a/ios/Classes/Options.swift b/ios/Classes/Options.swift
index 286a2f83..46ecf21c 100755
--- a/ios/Classes/Options.swift
+++ b/ios/Classes/Options.swift
@@ -16,7 +16,7 @@ public class Options: NSObject {
func parse(options: [String: Any?]) -> Options {
for (key, value) in options {
- if value != nil, !(value is NSNull), self.responds(to: Selector(key)) {
+ if !(value is NSNull), value != nil, self.responds(to: Selector(key)) {
self.setValue(value, forKey: key)
}
}
diff --git a/ios/Classes/PluginScriptsJS/LastTouchedAnchorOrImageJS.swift b/ios/Classes/PluginScriptsJS/LastTouchedAnchorOrImageJS.swift
index 4f3442f9..ef2e7d67 100644
--- a/ios/Classes/PluginScriptsJS/LastTouchedAnchorOrImageJS.swift
+++ b/ios/Classes/PluginScriptsJS/LastTouchedAnchorOrImageJS.swift
@@ -27,7 +27,7 @@ window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched = null;
if (target.tagName === 'IMG') {
var img = target;
window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched = {
- src: img.src
+ url: img.src
};
var parent = img.parentNode;
while (parent) {
@@ -47,7 +47,7 @@ window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched = null;
var images = link.getElementsByTagName('img');
var img = (images.length > 0) ? images[0] : null;
var imgSrc = (img != null) ? img.src : null;
- window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched = (img != null) ? {src: img.src} : window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched;
+ window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched = (img != null) ? {url: imgSrc} : window.\(JAVASCRIPT_BRIDGE_NAME)._lastImageTouched;
window.\(JAVASCRIPT_BRIDGE_NAME)._lastAnchorOrImageTouched = {
title: link.textContent,
url: link.href,
diff --git a/ios/Classes/PluginScriptsJS/WebMessageListenerJS.swift b/ios/Classes/PluginScriptsJS/WebMessageListenerJS.swift
index 91ff57ea..9d9fc60d 100644
--- a/ios/Classes/PluginScriptsJS/WebMessageListenerJS.swift
+++ b/ios/Classes/PluginScriptsJS/WebMessageListenerJS.swift
@@ -36,7 +36,7 @@ window.\(JAVASCRIPT_BRIDGE_NAME)._normalizeIPv6 = function(ip_string) {
// replace ipv4 address if any
var ipv4 = ip_string.match(/(.*:)([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$)/);
if (ipv4) {
- var ip_string = ipv4[1];
+ ip_string = ipv4[1];
ipv4 = ipv4[2].match(/[0-9]+/g);
for (var i = 0;i < 4;i ++) {
var byte = parseInt(ipv4[i],10);
@@ -85,12 +85,12 @@ window.\(JAVASCRIPT_BRIDGE_NAME)._isOriginAllowed = function(allowedOriginRules,
var IPv6 = null;
if (rule.host != null && rule.host[0] === "[") {
try {
- IPv6 = normalizeIPv6(rule.host.substring(1, rule.host.length - 1));
+ IPv6 = window.\(JAVASCRIPT_BRIDGE_NAME)._normalizeIPv6(rule.host.substring(1, rule.host.length - 1));
} catch {}
}
var hostIPv6 = null;
try {
- hostIPv6 = normalizeIPv6(host);
+ hostIPv6 = window.\(JAVASCRIPT_BRIDGE_NAME)._normalizeIPv6(host);
} catch {}
var schemeAllowed = scheme == rule.scheme;
diff --git a/ios/Classes/Types/DownloadStartRequest.swift b/ios/Classes/Types/DownloadStartRequest.swift
new file mode 100644
index 00000000..808f9453
--- /dev/null
+++ b/ios/Classes/Types/DownloadStartRequest.swift
@@ -0,0 +1,42 @@
+//
+// DownloadStartRequest.swift
+// flutter_inappwebview
+//
+// Created by Lorenzo Pichilli on 17/04/22.
+//
+
+import Foundation
+
+public class DownloadStartRequest: NSObject {
+ var url: String
+ var userAgent: String?
+ var contentDisposition: String?
+ var mimeType: String?
+ var contentLength: Int64
+ var suggestedFilename: String?
+ var textEncodingName: String?
+
+ public init(url: String, userAgent: String?, contentDisposition: String?,
+ mimeType: String?, contentLength: Int64,
+ suggestedFilename: String?, textEncodingName: String?) {
+ self.url = url
+ self.userAgent = userAgent
+ self.contentDisposition = contentDisposition
+ self.mimeType = mimeType
+ self.contentLength = contentLength
+ self.suggestedFilename = suggestedFilename
+ self.textEncodingName = textEncodingName
+ }
+
+ public func toMap () -> [String:Any?] {
+ return [
+ "url": url,
+ "userAgent": userAgent,
+ "contentDisposition": contentDisposition,
+ "mimeType": mimeType,
+ "contentLength": contentLength,
+ "suggestedFilename": suggestedFilename,
+ "textEncodingName": textEncodingName
+ ]
+ }
+}
diff --git a/ios/Classes/Types/URLRequest.swift b/ios/Classes/Types/URLRequest.swift
index 336ea693..efaf3e3c 100644
--- a/ios/Classes/Types/URLRequest.swift
+++ b/ios/Classes/Types/URLRequest.swift
@@ -63,6 +63,7 @@ extension URLRequest {
"url": url?.absoluteString,
"method": httpMethod,
"headers": allHTTPHeaderFields,
+ "body": httpBody.map(FlutterStandardTypedData.init(bytes:)),
"iosAllowsCellularAccess": allowsCellularAccess,
"iosAllowsConstrainedNetworkAccess": iosAllowsConstrainedNetworkAccess,
"iosAllowsExpensiveNetworkAccess": iosAllowsExpensiveNetworkAccess,
diff --git a/ios/Classes/Types/WebMessageListener.swift b/ios/Classes/Types/WebMessageListener.swift
index 6e283741..0d85c331 100644
--- a/ios/Classes/Types/WebMessageListener.swift
+++ b/ios/Classes/Types/WebMessageListener.swift
@@ -83,8 +83,9 @@ public class WebMessageListener : FlutterMethodCallDelegate {
return "'*'"
}
let rule = URL(string: allowedOriginRule)!
+ let host = rule.host != nil ? "'" + rule.host!.replacingOccurrences(of: "\'", with: "\\'") + "'" : "null"
return """
- {scheme: '\(rule.scheme!)', host: '\(rule.host?.replacingOccurrences(of: "\'", with: "\\'") ?? "null")', port: \(rule.port != nil ? String(rule.port!) : "null")}
+ {scheme: '\(rule.scheme!)', host: \(host), port: \(rule.port != nil ? String(rule.port!) : "null")}
"""
}.joined(separator: ", ")
let source = """
diff --git a/lib/t_rex_runner/t-rex.css b/lib/assets/t_rex_runner/t-rex.css
similarity index 100%
rename from lib/t_rex_runner/t-rex.css
rename to lib/assets/t_rex_runner/t-rex.css
diff --git a/lib/t_rex_runner/t-rex.html b/lib/assets/t_rex_runner/t-rex.html
similarity index 100%
rename from lib/t_rex_runner/t-rex.html
rename to lib/assets/t_rex_runner/t-rex.html
diff --git a/lib/src/chrome_safari_browser/android/chrome_custom_tabs_options.dart b/lib/src/chrome_safari_browser/android/chrome_custom_tabs_options.dart
index d6901bb8..d6a353a8 100755
--- a/lib/src/chrome_safari_browser/android/chrome_custom_tabs_options.dart
+++ b/lib/src/chrome_safari_browser/android/chrome_custom_tabs_options.dart
@@ -35,6 +35,12 @@ class AndroidChromeCustomTabsOptions
///Set to `true` to enable Keep Alive. The default value is `false`.
bool keepAliveEnabled;
+ ///Set to `true` to launch the Android activity in `singleInstance` mode. The default value is `false`.
+ bool singleInstance;
+
+ ///Set to `true` to launch the Android intent with the flag `FLAG_ACTIVITY_NO_HISTORY`. The default value is `false`.
+ bool noHistory;
+
AndroidChromeCustomTabsOptions(
{this.addDefaultShareMenuItem = true,
this.showTitle = true,
@@ -42,7 +48,9 @@ class AndroidChromeCustomTabsOptions
this.enableUrlBarHiding = false,
this.instantAppsEnabled = false,
this.packageName,
- this.keepAliveEnabled = false});
+ this.keepAliveEnabled = false,
+ this.singleInstance = false,
+ this.noHistory = false});
@override
Map toMap() {
@@ -53,7 +61,9 @@ class AndroidChromeCustomTabsOptions
"enableUrlBarHiding": enableUrlBarHiding,
"instantAppsEnabled": instantAppsEnabled,
"packageName": packageName,
- "keepAliveEnabled": keepAliveEnabled
+ "keepAliveEnabled": keepAliveEnabled,
+ "singleInstance": singleInstance,
+ "noHistory": noHistory
};
}
@@ -68,6 +78,8 @@ class AndroidChromeCustomTabsOptions
options.instantAppsEnabled = map["instantAppsEnabled"];
options.packageName = map["packageName"];
options.keepAliveEnabled = map["keepAliveEnabled"];
+ options.singleInstance = map["singleInstance"];
+ options.noHistory = map["noHistory"];
return options;
}
diff --git a/lib/src/in_app_browser/in_app_browser.dart b/lib/src/in_app_browser/in_app_browser.dart
index ff4e2877..74f45c1b 100755
--- a/lib/src/in_app_browser/in_app_browser.dart
+++ b/lib/src/in_app_browser/in_app_browser.dart
@@ -64,8 +64,12 @@ class InAppBrowser {
///The window id of a [CreateWindowAction.windowId].
final int? windowId;
+ ///Represents the WebView native implementation to be used.
+ ///The default value is [WebViewImplementation.NATIVE].
+ final WebViewImplementation implementation;
+
///
- InAppBrowser({this.windowId, this.initialUserScripts}) {
+ InAppBrowser({this.windowId, this.initialUserScripts, this.implementation = WebViewImplementation.NATIVE}) {
id = IdGenerator.generate();
this._channel =
MethodChannel('com.pichillilorenzo/flutter_inappbrowser_$id');
@@ -109,6 +113,7 @@ class InAppBrowser {
() => options?.toMap() ?? InAppBrowserClassOptions().toMap());
args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
args.putIfAbsent('windowId', () => windowId);
+ args.putIfAbsent('implementation', () => implementation.toValue());
args.putIfAbsent('initialUserScripts',
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
args.putIfAbsent(
@@ -167,6 +172,7 @@ class InAppBrowser {
() => options?.toMap() ?? InAppBrowserClassOptions().toMap());
args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
args.putIfAbsent('windowId', () => windowId);
+ args.putIfAbsent('implementation', () => implementation.toValue());
args.putIfAbsent('initialUserScripts',
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
args.putIfAbsent(
@@ -207,6 +213,7 @@ class InAppBrowser {
'historyUrl', () => androidHistoryUrl?.toString() ?? "about:blank");
args.putIfAbsent('contextMenu', () => contextMenu?.toMap() ?? {});
args.putIfAbsent('windowId', () => windowId);
+ args.putIfAbsent('implementation', () => implementation.toValue());
args.putIfAbsent('initialUserScripts',
() => initialUserScripts?.map((e) => e.toMap()).toList() ?? []);
args.putIfAbsent(
@@ -290,16 +297,16 @@ class InAppBrowser {
///Event fired when the [InAppBrowser] starts to load an [url].
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455621-webview
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebViewClient.onPageStarted](https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)))
+ ///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455621-webview))
void onLoadStart(Uri? url) {}
///Event fired when the [InAppBrowser] finishes loading an [url].
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebViewClient#onPageFinished(android.webkit.WebView,%20java.lang.String)
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455629-webview
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebViewClient.onPageFinished](https://developer.android.com/reference/android/webkit/WebViewClient#onPageFinished(android.webkit.WebView,%20java.lang.String)))
+ ///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455629-webview))
void onLoadStop(Uri? url) {}
///Event fired when the [InAppBrowser] encounters an error loading an [url].
@@ -326,7 +333,9 @@ class InAppBrowser {
///Event fired when the current [progress] (range 0-100) of loading a page is changed.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebChromeClient#onProgressChanged(android.webkit.WebView,%20int)
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebChromeClient.onProgressChanged](https://developer.android.com/reference/android/webkit/WebChromeClient#onProgressChanged(android.webkit.WebView,%20int)))
+ ///- iOS
void onProgressChanged(int progress) {}
///Event fired when the [InAppBrowser] webview receives a [ConsoleMessage].
@@ -368,16 +377,21 @@ class InAppBrowser {
///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollviewdelegate/1619392-scrollviewdidscroll
void onScrollChanged(int x, int y) {}
- ///Event fired when [InAppBrowser] recognizes and starts a downloadable file.
+ ///Use [onDownloadStartRequest] instead
+ @Deprecated('Use `onDownloadStartRequest` instead')
+ void onDownloadStart(Uri url) {}
+
+ ///Event fired when [WebView] recognizes a downloadable file.
+ ///To download the file, you can use the [flutter_downloader](https://pub.dev/packages/flutter_downloader) plugin.
///
- ///[url] represents the url of the file.
+ ///[downloadStartRequest] represents the request of the file to download.
///
///**NOTE**: In order to be able to listen this event, you need to set [InAppWebViewOptions.useOnDownloadStart] option to `true`.
///
///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setDownloadListener(android.webkit.DownloadListener)
///
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455643-webview
- void onDownloadStart(Uri url) {}
+ void onDownloadStartRequest(DownloadStartRequest downloadStartRequest) {}
///Event fired 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`.
///
@@ -501,7 +515,7 @@ class InAppBrowser {
URLAuthenticationChallenge challenge) {}
///Event fired as find-on-page operations progress.
- ///The listener may be notified multiple times while the operation is underway, and the numberOfMatches value should not be considered final unless [isDoneCounting] is true.
+ ///The listener may be notified multiple times while the operation is underway, and the [numberOfMatches] value should not be considered final unless [isDoneCounting] is true.
///
///[activeMatchOrdinal] represents the zero-based ordinal of the currently selected match.
///
@@ -509,7 +523,9 @@ class InAppBrowser {
///
///[isDoneCounting] whether the find operation has actually completed.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#setFindListener(android.webkit.WebView.FindListener)
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.FindListener.onFindResultReceived](https://developer.android.com/reference/android/webkit/WebView.FindListener#onFindResultReceived(int,%20int,%20boolean)))
+ ///- iOS
void onFindResultReceived(
int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting) {}
@@ -562,7 +578,9 @@ class InAppBrowser {
///
///[url] represents the url on which is called.
///
- ///**NOTE**: available on Android 21+.
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
void onPrint(Uri? url) {}
///Event fired when an HTML element of the webview has been clicked and held.
diff --git a/lib/src/in_app_localhost_server.dart b/lib/src/in_app_localhost_server.dart
index 7bde49e6..2c7d2c5d 100755
--- a/lib/src/in_app_localhost_server.dart
+++ b/lib/src/in_app_localhost_server.dart
@@ -56,17 +56,16 @@ class InAppLocalhostServer {
return;
}
- var contentType = ['text', 'html'];
+ var contentType = ContentType('text', 'html', charset: 'utf-8');
if (!request.requestedUri.path.endsWith('/') &&
request.requestedUri.pathSegments.isNotEmpty) {
var mimeType = MimeTypeResolver.lookup(request.requestedUri.path);
if (mimeType != null) {
- contentType = mimeType.split('/');
+ contentType = _getContentTypeFromMimeType(mimeType);
}
}
- request.response.headers.contentType =
- ContentType(contentType[0], contentType[1], charset: 'utf-8');
+ request.response.headers.contentType = contentType;
request.response.add(body);
request.response.close();
});
@@ -93,4 +92,20 @@ class InAppLocalhostServer {
bool isRunning() {
return this._server != null;
}
+
+ ContentType _getContentTypeFromMimeType(String mimeType) {
+ final contentType = mimeType.split('/');
+ String? charset;
+
+ if (_isTextFile(mimeType)) {
+ charset = 'utf-8';
+ }
+
+ return ContentType(contentType[0], contentType[1], charset: charset);
+ }
+
+ bool _isTextFile(String mimeType) {
+ final textFile = RegExp(r'^text\/|^application\/(javascript|json)');
+ return textFile.hasMatch(mimeType);
+ }
}
diff --git a/lib/src/in_app_webview/android/in_app_webview_controller.dart b/lib/src/in_app_webview/android/in_app_webview_controller.dart
index 0e3c8e22..3c0805bc 100644
--- a/lib/src/in_app_webview/android/in_app_webview_controller.dart
+++ b/lib/src/in_app_webview/android/in_app_webview_controller.dart
@@ -59,11 +59,8 @@ class AndroidInAppWebViewController {
await _channel.invokeMethod('resume', args);
}
- ///Gets the URL that was originally requested 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. Also, there may have been redirects resulting in a different URL to that originally requested.
- ///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getOriginalUrl()
+ ///Use [InAppWebViewController.getOriginalUrl] instead.
+ @Deprecated('Use `InAppWebViewController.getOriginalUrl` instead')
Future getOriginalUrl() async {
Map args = {};
String? url = await _channel.invokeMethod('getOriginalUrl', args);
@@ -114,7 +111,8 @@ class AndroidInAppWebViewController {
///Clears the internal back/forward list.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#clearHistory()
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.clearHistory](https://developer.android.com/reference/android/webkit/WebView#clearHistory())).
Future clearHistory() async {
Map args = {};
return await _channel.invokeMethod('clearHistory', args);
diff --git a/lib/src/in_app_webview/headless_in_app_webview.dart b/lib/src/in_app_webview/headless_in_app_webview.dart
index f19b5152..7507cb3a 100644
--- a/lib/src/in_app_webview/headless_in_app_webview.dart
+++ b/lib/src/in_app_webview/headless_in_app_webview.dart
@@ -53,6 +53,7 @@ class HeadlessInAppWebView implements WebView {
this.contextMenu,
this.initialUserScripts,
this.pullToRefreshController,
+ this.implementation = WebViewImplementation.NATIVE,
this.onWebViewCreated,
this.onLoadStart,
this.onLoadStop,
@@ -63,7 +64,8 @@ class HeadlessInAppWebView implements WebView {
this.shouldOverrideUrlLoading,
this.onLoadResource,
this.onScrollChanged,
- this.onDownloadStart,
+ @Deprecated('Use `onDownloadStartRequest` instead') this.onDownloadStart,
+ this.onDownloadStartRequest,
this.onLoadResourceCustomScheme,
this.onCreateWindow,
this.onCloseWindow,
@@ -139,14 +141,13 @@ class HeadlessInAppWebView implements WebView {
args.putIfAbsent(
'params',
() => {
- 'initialUrlRequest': (this.initialUrlRequest ??
- URLRequest(url: Uri.parse("about:blank")))
- .toMap(),
+ 'initialUrlRequest': this.initialUrlRequest?.toMap(),
'initialFile': this.initialFile,
'initialData': this.initialData?.toMap(),
'initialOptions': this.initialOptions?.toMap() ?? {},
'contextMenu': this.contextMenu?.toMap() ?? {},
'windowId': this.windowId,
+ 'implementation': this.implementation.toValue(),
'initialUserScripts':
this.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
'pullToRefreshOptions':
@@ -227,6 +228,9 @@ class HeadlessInAppWebView implements WebView {
@override
final PullToRefreshController? pullToRefreshController;
+ @override
+ final WebViewImplementation implementation;
+
@override
void Function(InAppWebViewController controller)?
androidOnGeolocationPermissionsHidePrompt;
@@ -298,8 +302,15 @@ class HeadlessInAppWebView implements WebView {
@override
void Function(InAppWebViewController controller)? onWindowBlur;
+ ///Use [onDownloadStartRequest] instead
+ @Deprecated('Use `onDownloadStartRequest` instead')
@override
- void Function(InAppWebViewController controller, Uri url)? onDownloadStart;
+ final void Function(InAppWebViewController controller, Uri url)?
+ onDownloadStart;
+
+ @override
+ final void Function(InAppWebViewController controller, DownloadStartRequest downloadStartRequest)?
+ onDownloadStartRequest;
@override
void Function(InAppWebViewController controller, int activeMatchOrdinal,
diff --git a/lib/src/in_app_webview/in_app_webview.dart b/lib/src/in_app_webview/in_app_webview.dart
index 7ef7ee2f..c136fa22 100755
--- a/lib/src/in_app_webview/in_app_webview.dart
+++ b/lib/src/in_app_webview/in_app_webview.dart
@@ -41,6 +41,7 @@ class InAppWebView extends StatefulWidget implements WebView {
this.initialOptions,
this.initialUserScripts,
this.pullToRefreshController,
+ this.implementation = WebViewImplementation.NATIVE,
this.contextMenu,
this.onWebViewCreated,
this.onLoadStart,
@@ -52,7 +53,8 @@ class InAppWebView extends StatefulWidget implements WebView {
this.shouldOverrideUrlLoading,
this.onLoadResource,
this.onScrollChanged,
- this.onDownloadStart,
+ @Deprecated('Use `onDownloadStartRequest` instead') this.onDownloadStart,
+ this.onDownloadStartRequest,
this.onLoadResourceCustomScheme,
this.onCreateWindow,
this.onCloseWindow,
@@ -135,6 +137,9 @@ class InAppWebView extends StatefulWidget implements WebView {
@override
final URLRequest? initialUrlRequest;
+ @override
+ final WebViewImplementation implementation;
+
@override
final UnmodifiableListView? initialUserScripts;
@@ -207,10 +212,16 @@ class InAppWebView extends StatefulWidget implements WebView {
InAppWebViewController controller, Uri url, bool precomposed)?
androidOnReceivedTouchIconUrl;
+ ///Use [onDownloadStartRequest] instead
+ @Deprecated('Use `onDownloadStartRequest` instead')
@override
final void Function(InAppWebViewController controller, Uri url)?
onDownloadStart;
+ @override
+ final void Function(InAppWebViewController controller, DownloadStartRequest downloadStartRequest)?
+ onDownloadStartRequest;
+
@override
final void Function(InAppWebViewController controller, int activeMatchOrdinal,
int numberOfMatches, bool isDoneCounting)? onFindResultReceived;
@@ -395,14 +406,13 @@ class _InAppWebViewState extends State {
viewType: 'com.pichillilorenzo/flutter_inappwebview',
layoutDirection: TextDirection.rtl,
creationParams: {
- 'initialUrlRequest': (widget.initialUrlRequest ??
- URLRequest(url: Uri.parse("about:blank")))
- .toMap(),
+ 'initialUrlRequest': widget.initialUrlRequest?.toMap(),
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
'initialOptions': widget.initialOptions?.toMap() ?? {},
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
+ 'implementation': widget.implementation.toValue(),
'initialUserScripts':
widget.initialUserScripts?.map((e) => e.toMap()).toList() ??
[],
@@ -423,16 +433,15 @@ class _InAppWebViewState extends State {
viewType: 'com.pichillilorenzo/flutter_inappwebview',
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
- layoutDirection: TextDirection.rtl,
+ layoutDirection: Directionality.maybeOf(context) ?? TextDirection.rtl,
creationParams: {
- 'initialUrlRequest': (widget.initialUrlRequest ??
- URLRequest(url: Uri.parse("about:blank")))
- .toMap(),
+ 'initialUrlRequest': widget.initialUrlRequest?.toMap(),
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
'initialOptions': widget.initialOptions?.toMap() ?? {},
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
+ 'implementation': widget.implementation.toValue(),
'initialUserScripts':
widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
'pullToRefreshOptions':
@@ -448,14 +457,13 @@ class _InAppWebViewState extends State {
onPlatformViewCreated: _onPlatformViewCreated,
gestureRecognizers: widget.gestureRecognizers,
creationParams: {
- 'initialUrlRequest': (widget.initialUrlRequest ??
- URLRequest(url: Uri.parse("about:blank")))
- .toMap(),
+ 'initialUrlRequest': widget.initialUrlRequest?.toMap(),
'initialFile': widget.initialFile,
'initialData': widget.initialData?.toMap(),
'initialOptions': widget.initialOptions?.toMap() ?? {},
'contextMenu': widget.contextMenu?.toMap() ?? {},
'windowId': widget.windowId,
+ 'implementation': widget.implementation.toValue(),
'initialUserScripts':
widget.initialUserScripts?.map((e) => e.toMap()).toList() ?? [],
'pullToRefreshOptions':
diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart
index d34072bb..998e64d6 100644
--- a/lib/src/in_app_webview/in_app_webview_controller.dart
+++ b/lib/src/in_app_webview/in_app_webview_controller.dart
@@ -201,15 +201,26 @@ class InAppWebViewController {
_inAppBrowser!.onScrollChanged(x, y);
}
break;
- case "onDownloadStart":
- if ((_webview != null && _webview!.onDownloadStart != null) ||
+ case "onDownloadStartRequest":
+ if ((_webview != null &&
+ // ignore: deprecated_member_use_from_same_package
+ (_webview!.onDownloadStart != null || _webview!.onDownloadStartRequest != null)) ||
_inAppBrowser != null) {
- String url = call.arguments["url"];
- Uri uri = Uri.parse(url);
- if (_webview != null && _webview!.onDownloadStart != null)
- _webview!.onDownloadStart!(this, uri);
- else
- _inAppBrowser!.onDownloadStart(uri);
+ Map arguments = call.arguments.cast();
+ DownloadStartRequest downloadStartRequest = DownloadStartRequest.fromMap(arguments)!;
+
+ if (_webview != null) {
+ if (_webview!.onDownloadStartRequest != null)
+ _webview!.onDownloadStartRequest!(this, downloadStartRequest);
+ else {
+ // ignore: deprecated_member_use_from_same_package
+ _webview!.onDownloadStart!(this, downloadStartRequest.url);
+ }
+ } else {
+ // ignore: deprecated_member_use_from_same_package
+ _inAppBrowser!.onDownloadStart(downloadStartRequest.url);
+ _inAppBrowser!.onDownloadStartRequest(downloadStartRequest);
+ }
}
break;
case "onLoadResourceCustomScheme":
@@ -375,6 +386,7 @@ class InAppWebViewController {
} else {
// ignore: deprecated_member_use_from_same_package
_inAppBrowser!.androidOnScaleChanged(oldScale, newScale);
+ _inAppBrowser!.onZoomScaleChanged(oldScale, newScale);
}
}
break;
@@ -904,9 +916,9 @@ class InAppWebViewController {
///Gets the URL for the current page.
///This is not always the same as the URL passed to [WebView.onLoadStart] because although the load for that URL has begun, the current page may not have changed.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getUrl()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415005-url
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.getUrl](https://developer.android.com/reference/android/webkit/WebView#getUrl()))
+ ///- iOS ([Official API - WKWebView.url](https://developer.apple.com/documentation/webkit/wkwebview/1415005-url))
Future getUrl() async {
Map args = {};
String? url = await _channel.invokeMethod('getUrl', args);
@@ -915,9 +927,9 @@ class InAppWebViewController {
///Gets the title for the current page.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getTitle()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415015-title
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.getTitle](https://developer.android.com/reference/android/webkit/WebView#getTitle()))
+ ///- iOS ([Official API - WKWebView.title](https://developer.apple.com/documentation/webkit/wkwebview/1415015-title))
Future getTitle() async {
Map args = {};
return await _channel.invokeMethod('getTitle', args);
@@ -925,9 +937,9 @@ class InAppWebViewController {
///Gets the progress for the current page. The progress value is between 0 and 100.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getProgress()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1415007-estimatedprogress
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.getProgress](https://developer.android.com/reference/android/webkit/WebView#getProgress()))
+ ///- iOS ([Official API - WKWebView.estimatedProgress](https://developer.apple.com/documentation/webkit/wkwebview/1415007-estimatedprogress))
Future getProgress() async {
Map args = {};
return await _channel.invokeMethod('getProgress', args);
@@ -1138,21 +1150,20 @@ class InAppWebViewController {
///Loads the given [urlRequest].
///
- ///[iosAllowingReadAccessTo], used in combination with [urlRequest] (using the `file://` scheme),
- ///is an iOS-specific argument that represents the URL from which to read the web content.
+ ///- [allowingReadAccessTo], used in combination with [urlRequest] (using the `file://` scheme),
+ ///it represents the URL from which to read the web content.
///This URL must be a file-based URL (using the `file://` scheme).
///Specify the same value as the URL parameter to prevent WebView from reading any other content.
///Specify a directory to give WebView permission to read additional files in the specified directory.
+ ///**NOTE**: available only on iOS.
///
///**NOTE for Android**: when loading an URL Request using "POST" method, headers are ignored.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String)
- ///
- ///**Official iOS API**:
- ///- https://developer.apple.com/documentation/webkit/wkwebview/1414954-load
- ///- if [iosAllowingReadAccessTo] is used, https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.loadUrl](https://developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String))). If method is "POST", [Official API - WebView.postUrl](https://developer.android.com/reference/android/webkit/WebView#postUrl(java.lang.String,%20byte[]))
+ ///- iOS ([Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1414954-load). If [allowingReadAccessTo] is used, [Official API - WKWebView.loadFileURL](https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl))
Future loadUrl(
- {required URLRequest urlRequest, Uri? iosAllowingReadAccessTo}) async {
+ {required URLRequest urlRequest, @Deprecated('Use `allowingReadAccessTo` instead') Uri? iosAllowingReadAccessTo, Uri? allowingReadAccessTo}) async {
assert(urlRequest.url != null && urlRequest.url.toString().isNotEmpty);
assert(iosAllowingReadAccessTo == null ||
iosAllowingReadAccessTo.isScheme("file"));
@@ -1160,19 +1171,21 @@ class InAppWebViewController {
Map args = {};
args.putIfAbsent('urlRequest', () => urlRequest.toMap());
args.putIfAbsent(
- 'allowingReadAccessTo', () => iosAllowingReadAccessTo?.toString());
+ 'allowingReadAccessTo', () => allowingReadAccessTo?.toString() ?? iosAllowingReadAccessTo?.toString());
await _channel.invokeMethod('loadUrl', args);
}
///Loads the given [url] with [postData] (x-www-form-urlencoded) using `POST` method into this WebView.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#postUrl(java.lang.String,%20byte[])
- ///
///Example
///```dart
///var postData = Uint8List.fromList(utf8.encode("firstname=Foo&surname=Bar"));
///controller.postUrl(url: Uri.parse("https://www.example.com/"), postData: postData);
///```
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.postUrl](https://developer.android.com/reference/android/webkit/WebView#postUrl(java.lang.String,%20byte[])))
+ ///- iOS
Future postUrl({required Uri url, required Uint8List postData}) async {
assert(url.toString().isNotEmpty);
Map args = {};
@@ -1183,27 +1196,30 @@ class InAppWebViewController {
///Loads the given [data] into this WebView, using [baseUrl] as the base URL for the content.
///
- ///- [mimeType] parameter specifies the format of the data. The default value is `"text/html"`.
- ///- [encoding] parameter specifies the encoding of the data. The default value is `"utf8"`.
- ///- [androidHistoryUrl] parameter is the URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL. This parameter is used only on Android.
- ///- [iosAllowingReadAccessTo], used in combination with [baseUrl] (using the `file://` scheme),
- ///is an iOS-specific argument that represents the URL from which to read the web content.
+ ///- [mimeType] argument specifies the format of the data. The default value is `"text/html"`.
+ ///- [encoding] argument specifies the encoding of the data. The default value is `"utf8"`.
+ ///- [historyUrl] is an Android-specific argument that represents the URL to use as the history entry. The default value is `about:blank`. If non-null, this must be a valid URL.
+ ///- [allowingReadAccessTo], used in combination with [baseUrl] (using the `file://` scheme),
+ ///it represents the URL from which to read the web content.
///This [baseUrl] must be a file-based URL (using the `file://` scheme).
///Specify the same value as the [baseUrl] parameter to prevent WebView from reading any other content.
///Specify a directory to give WebView permission to read additional files in the specified directory.
+ ///**NOTE**: available only on iOS.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)
- ///
- ///**Official iOS API**:
- ///- https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring
- ///- https://developer.apple.com/documentation/webkit/wkwebview/1415011-load
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.loadDataWithBaseURL](https://developer.android.com/reference/android/webkit/WebView#loadDataWithBaseURL(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)))
+ ///- iOS ([Official API - WKWebView.loadHTMLString](https://developer.apple.com/documentation/webkit/wkwebview/1415004-loadhtmlstring) or [Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1415011-load))
Future loadData(
{required String data,
String mimeType = "text/html",
String encoding = "utf8",
Uri? baseUrl,
+ @Deprecated('Use `historyUrl` instead')
Uri? androidHistoryUrl,
- Uri? iosAllowingReadAccessTo}) async {
+ Uri? historyUrl,
+ @Deprecated('Use `allowingReadAccessTo` instead')
+ Uri? iosAllowingReadAccessTo,
+ Uri? allowingReadAccessTo}) async {
assert(iosAllowingReadAccessTo == null ||
iosAllowingReadAccessTo.isScheme("file"));
@@ -1213,9 +1229,9 @@ class InAppWebViewController {
args.putIfAbsent('encoding', () => encoding);
args.putIfAbsent('baseUrl', () => baseUrl?.toString() ?? "about:blank");
args.putIfAbsent(
- 'historyUrl', () => androidHistoryUrl?.toString() ?? "about:blank");
+ 'historyUrl', () => historyUrl?.toString() ?? androidHistoryUrl?.toString() ?? "about:blank");
args.putIfAbsent(
- 'allowingReadAccessTo', () => iosAllowingReadAccessTo?.toString());
+ 'allowingReadAccessTo', () => allowingReadAccessTo?.toString() ?? iosAllowingReadAccessTo?.toString());
await _channel.invokeMethod('loadData', args);
}
@@ -1248,6 +1264,10 @@ class InAppWebViewController {
///controller.loadFile(assetFilePath: "assets/index.html");
///...
///```
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.loadUrl](https://developer.android.com/reference/android/webkit/WebView#loadUrl(java.lang.String)))
+ ///- iOS ([Official API - WKWebView.load](https://developer.apple.com/documentation/webkit/wkwebview/1414954-load))
Future loadFile({required String assetFilePath}) async {
assert(assetFilePath.isNotEmpty);
Map args = {};
@@ -1257,9 +1277,9 @@ class InAppWebViewController {
///Reloads the WebView.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#reload()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414969-reload
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.reload](https://developer.android.com/reference/android/webkit/WebView#reload()))
+ ///- iOS ([Official API - WKWebView.reload](https://developer.apple.com/documentation/webkit/wkwebview/1414969-reload))
Future reload() async {
Map args = {};
await _channel.invokeMethod('reload', args);
@@ -1267,9 +1287,9 @@ class InAppWebViewController {
///Goes back in the history of the WebView.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#goBack()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414952-goback
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.goBack](https://developer.android.com/reference/android/webkit/WebView#goBack()))
+ ///- iOS ([Official API - WKWebView.goBack](https://developer.apple.com/documentation/webkit/wkwebview/1414952-goback))
Future goBack() async {
Map args = {};
await _channel.invokeMethod('goBack', args);
@@ -1277,9 +1297,9 @@ class InAppWebViewController {
///Returns a boolean value indicating whether the WebView can move backward.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#canGoBack()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.canGoBack](https://developer.android.com/reference/android/webkit/WebView#canGoBack()))
+ ///- iOS ([Official API - WKWebView.canGoBack](https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback))
Future canGoBack() async {
Map args = {};
return await _channel.invokeMethod('canGoBack', args);
@@ -1287,9 +1307,9 @@ class InAppWebViewController {
///Goes forward in the history of the WebView.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#goForward()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414993-goforward
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.goForward](https://developer.android.com/reference/android/webkit/WebView#goForward()))
+ ///- iOS ([Official API - WKWebView.goForward](https://developer.apple.com/documentation/webkit/wkwebview/1414993-goforward))
Future goForward() async {
Map args = {};
await _channel.invokeMethod('goForward', args);
@@ -1297,9 +1317,9 @@ class InAppWebViewController {
///Returns a boolean value indicating whether the WebView can move forward.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#canGoForward()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.canGoForward](https://developer.android.com/reference/android/webkit/WebView#canGoForward()))
+ ///- iOS ([Official API - WKWebView.canGoForward](https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward))
Future canGoForward() async {
Map args = {};
return await _channel.invokeMethod('canGoForward', args);
@@ -1307,9 +1327,9 @@ class InAppWebViewController {
///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.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#goBackOrForward(int)
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414991-go
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.goBackOrForward](https://developer.android.com/reference/android/webkit/WebView#goBackOrForward(int)))
+ ///- iOS ([Official API - WKWebView.go](https://developer.apple.com/documentation/webkit/wkwebview/1414991-go))
Future goBackOrForward({required int steps}) async {
Map args = {};
args.putIfAbsent('steps', () => steps);
@@ -1318,7 +1338,9 @@ class InAppWebViewController {
///Returns a boolean value indicating whether the WebView can go back or forward the given number of steps. Steps is negative if backward and positive if forward.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#canGoBackOrForward(int)
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.canGoBackOrForward](https://developer.android.com/reference/android/webkit/WebView#canGoBackOrForward(int)))
+ ///- iOS
Future canGoBackOrForward({required int steps}) async {
Map args = {};
args.putIfAbsent('steps', () => steps);
@@ -1326,13 +1348,22 @@ class InAppWebViewController {
}
///Navigates to a [WebHistoryItem] from the back-forward [WebHistory.list] and sets it as the current item.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future goTo({required WebHistoryItem historyItem}) async {
- if (historyItem.offset != null) {
- await goBackOrForward(steps: historyItem.offset!);
+ var steps = historyItem.offset;
+ if (steps != null) {
+ await goBackOrForward(steps: steps);
}
}
///Check if the WebView instance is in a loading state.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future isLoading() async {
Map args = {};
return await _channel.invokeMethod('isLoading', args);
@@ -1340,9 +1371,9 @@ class InAppWebViewController {
///Stops the WebView from loading.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#stopLoading()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414981-stoploading
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.stopLoading](https://developer.android.com/reference/android/webkit/WebView#stopLoading()))
+ ///- iOS ([Official API - WKWebView.stopLoading](https://developer.apple.com/documentation/webkit/wkwebview/1414981-stoploading))
Future stopLoading() async {
Map args = {};
await _channel.invokeMethod('stopLoading', args);
@@ -1362,19 +1393,22 @@ class InAppWebViewController {
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)
- ///
- ///**Official iOS API**:
- ///- https://developer.apple.com/documentation/webkit/wkwebview/1415017-evaluatejavascript
- ///- https://developer.apple.com/documentation/webkit/wkwebview/3656442-evaluatejavascript
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.evaluateJavascript](https://developer.android.com/reference/android/webkit/WebView#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)))
+ ///- iOS ([Official API - WKWebView.evaluateJavascript](https://developer.apple.com/documentation/webkit/wkwebview/3656442-evaluatejavascript))
Future evaluateJavascript(
{required String source, ContentWorld? contentWorld}) async {
Map args = {};
args.putIfAbsent('source', () => source);
args.putIfAbsent('contentWorld', () => contentWorld?.toMap());
var data = await _channel.invokeMethod('evaluateJavascript', args);
- if (data != null && defaultTargetPlatform == TargetPlatform.android)
- data = json.decode(data);
+ if (data != null && defaultTargetPlatform == TargetPlatform.android) {
+ try {
+ // try to json decode the data coming from JavaScript
+ // otherwise return it as it is.
+ data = json.decode(data);
+ } catch (e) {}
+ }
return data;
}
@@ -1386,6 +1420,10 @@ class InAppWebViewController {
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future injectJavascriptFileFromUrl(
{required Uri urlFile,
ScriptHtmlTagAttributes? scriptHtmlTagAttributes}) async {
@@ -1407,6 +1445,10 @@ class InAppWebViewController {
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future injectJavascriptFileFromAsset(
{required String assetFilePath}) async {
String source = await rootBundle.loadString(assetFilePath);
@@ -1419,6 +1461,10 @@ class InAppWebViewController {
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future injectCSSCode({required String source}) async {
Map args = {};
args.putIfAbsent('source', () => source);
@@ -1433,6 +1479,10 @@ class InAppWebViewController {
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future injectCSSFileFromUrl(
{required Uri urlFile,
CSSLinkHtmlTagAttributes? cssLinkHtmlTagAttributes}) async {
@@ -1450,6 +1500,10 @@ class InAppWebViewController {
///because, in these events, the [WebView] is not ready to handle it yet.
///Instead, you should call this method, for example, inside the [WebView.onLoadStop] event or in any other events
///where you know the page is ready "enough".
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future injectCSSFileFromAsset({required String assetFilePath}) async {
String source = await rootBundle.loadString(assetFilePath);
await injectCSSCode(source: source);
@@ -1505,6 +1559,10 @@ class InAppWebViewController {
///**NOTE**: This method should be called, for example, in the [WebView.onWebViewCreated] or [WebView.onLoadStart] events or, at least,
///before you know that your JavaScript code will call the `window.flutter_inappwebview.callHandler` method,
///otherwise you won't be able to intercept the JavaScript message.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
void addJavaScriptHandler(
{required String handlerName,
required JavaScriptHandlerCallback callback}) {
@@ -1516,6 +1574,10 @@ class InAppWebViewController {
///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.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
JavaScriptHandlerCallback? removeJavaScriptHandler(
{required String handlerName}) {
return this.javaScriptHandlersMap.remove(handlerName);
@@ -1527,7 +1589,9 @@ class InAppWebViewController {
///
///**NOTE for iOS**: available on iOS 11.0+.
///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/2873260-takesnapshot
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS ([Official API - WKWebView.takeSnapshot](https://developer.apple.com/documentation/webkit/wkwebview/2873260-takesnapshot))
Future takeScreenshot(
{ScreenshotConfiguration? screenshotConfiguration}) async {
Map args = {};
@@ -1537,6 +1601,10 @@ class InAppWebViewController {
}
///Sets the WebView options with the new [options] and evaluates them.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future setOptions({required InAppWebViewGroupOptions options}) async {
Map args = {};
@@ -1545,6 +1613,10 @@ class InAppWebViewController {
}
///Gets the current WebView options. Returns `null` if it wasn't able to get them.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future getOptions() async {
Map args = {};
@@ -1563,9 +1635,9 @@ class InAppWebViewController {
///Multiple calls to this method may return different objects.
///The object returned from this method will not be updated to reflect any new state.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#copyBackForwardList()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkwebview/1414977-backforwardlist
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.copyBackForwardList](https://developer.android.com/reference/android/webkit/WebView#copyBackForwardList()))
+ ///- iOS ([Official API - WKWebView.backForwardList](https://developer.apple.com/documentation/webkit/wkwebview/1414977-backforwardlist))
Future getCopyBackForwardList() async {
Map args = {};
Map? result =
@@ -1574,7 +1646,11 @@ class InAppWebViewController {
return WebHistory.fromMap(result);
}
- ///Clears all the webview's cache.
+ ///Clears all the WebView's cache.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future clearCache() async {
Map args = {};
await _channel.invokeMethod('clearCache', args);
@@ -1584,24 +1660,28 @@ class InAppWebViewController {
///
///[find] represents the string to find.
///
- ///**NOTE**: on Android, it finds all instances asynchronously. Successive calls to this will cancel any pending searches.
+ ///**NOTE**: on Android native WebView, it finds all instances asynchronously. Successive calls to this will cancel any pending searches.
///
///**NOTE**: on iOS, this is implemented using CSS and Javascript.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#findAllAsync(java.lang.String)
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.findAllAsync](https://developer.android.com/reference/android/webkit/WebView#findAllAsync(java.lang.String)))
+ ///- iOS
Future findAllAsync({required String find}) async {
Map args = {};
args.putIfAbsent('find', () => find);
await _channel.invokeMethod('findAllAsync', args);
}
- ///Highlights and scrolls to the next match found by [findAllAsync()]. Notifies [WebView.onFindResultReceived] listener.
+ ///Highlights and scrolls to the next match found by [findAllAsync]. Notifies [WebView.onFindResultReceived] listener.
///
///[forward] represents the direction to search.
///
///**NOTE**: on iOS, this is implemented using CSS and Javascript.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#findNext(boolean)
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.findNext](https://developer.android.com/reference/android/webkit/WebView#findNext(boolean)))
+ ///- iOS
Future findNext({required bool forward}) async {
Map args = {};
args.putIfAbsent('forward', () => forward);
@@ -1612,22 +1692,32 @@ class InAppWebViewController {
///
///**NOTE**: on iOS, this is implemented using CSS and Javascript.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#clearMatches()
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.clearMatches](https://developer.android.com/reference/android/webkit/WebView#clearMatches()))
+ ///- iOS
Future clearMatches() async {
Map args = {};
await _channel.invokeMethod('clearMatches', args);
}
- ///Gets the html (with javascript) of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerCss()].
+ ///Gets the html (with javascript) of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerCss].
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future getTRexRunnerHtml() async {
return await rootBundle
- .loadString("packages/flutter_inappwebview/t_rex_runner/t-rex.html");
+ .loadString("packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html");
}
- ///Gets the css of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerHtml()].
+ ///Gets the css of the Chromium's t-rex runner game. Used in combination with [getTRexRunnerHtml].
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS
Future getTRexRunnerCss() async {
return await rootBundle
- .loadString("packages/flutter_inappwebview/t_rex_runner/t-rex.css");
+ .loadString("packages/flutter_inappwebview/assets/t_rex_runner/t-rex.css");
}
///Scrolls the WebView to the position.
@@ -1638,9 +1728,9 @@ class InAppWebViewController {
///
///[animated] `true` to animate the scroll transition, `false` to make the scoll transition immediate.
///
- ///**Official Android API**: https://developer.android.com/reference/android/view/View#scrollTo(int,%20int)
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - View.scrollTo](https://developer.android.com/reference/android/view/View#scrollTo(int,%20int)))
+ ///- iOS ([Official API - UIScrollView.setContentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset))
Future scrollTo(
{required int x, required int y, bool animated = false}) async {
Map args = {};
@@ -1658,9 +1748,9 @@ class InAppWebViewController {
///
///[animated] `true` to animate the scroll transition, `false` to make the scoll transition immediate.
///
- ///**Official Android API**: https://developer.android.com/reference/android/view/View#scrollBy(int,%20int)
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - View.scrollBy](https://developer.android.com/reference/android/view/View#scrollBy(int,%20int)))
+ ///- iOS ([Official API - UIScrollView.setContentOffset](https://developer.apple.com/documentation/uikit/uiscrollview/1619400-setcontentoffset))
Future scrollBy(
{required int x, required int y, bool animated = false}) async {
Map args = {};
@@ -1670,12 +1760,14 @@ class InAppWebViewController {
await _channel.invokeMethod('scrollBy', args);
}
- ///On Android, it pauses all layout, parsing, and JavaScript timers for all WebViews.
+ ///On Android native WebView, it pauses all layout, parsing, and JavaScript timers for all WebViews.
///This is a global requests, not restricted to just this WebView. This can be useful if the application has been paused.
///
- ///On iOS, it is restricted to just this WebView.
+ ///On iOS, it is implemented using JavaScript and it is restricted to just this WebView.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#pauseTimers()
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.pauseTimers](https://developer.android.com/reference/android/webkit/WebView#pauseTimers()))
+ ///- iOS
Future pauseTimers() async {
Map args = {};
await _channel.invokeMethod('pauseTimers', args);
@@ -1683,9 +1775,11 @@ class InAppWebViewController {
///On Android, it resumes all layout, parsing, and JavaScript timers for all WebViews. This will resume dispatching all timers.
///
- ///On iOS, it resumes all layout, parsing, and JavaScript timers to just this WebView.
+ ///On iOS, it is implemented using JavaScript and it resumes all layout, parsing, and JavaScript timers to just this WebView.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#resumeTimers()
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.resumeTimers](https://developer.android.com/reference/android/webkit/WebView#resumeTimers()))
+ ///- iOS
Future resumeTimers() async {
Map args = {};
await _channel.invokeMethod('resumeTimers', args);
@@ -1695,9 +1789,9 @@ class InAppWebViewController {
///
///**NOTE**: available on Android 21+.
///
- ///**Official Android API**: https://developer.android.com/reference/android/print/PrintManager
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiprintinteractioncontroller
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - PrintManager](https://developer.android.com/reference/android/print/PrintManager))
+ ///- iOS ([Official API - UIPrintInteractionController](https://developer.apple.com/documentation/uikit/uiprintinteractioncontroller))
Future printCurrentPage() async {
Map args = {};
await _channel.invokeMethod('printCurrentPage', args);
@@ -1705,9 +1799,9 @@ class InAppWebViewController {
///Gets the height of the HTML content.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#getContentHeight()
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619399-contentsize
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.getContentHeight](https://developer.android.com/reference/android/webkit/WebView#getContentHeight()))
+ ///- iOS ([Official API - UIScrollView.contentSize](https://developer.apple.com/documentation/uikit/uiscrollview/1619399-contentsize))
Future getContentHeight() async {
Map args = {};
return await _channel.invokeMethod('getContentHeight', args);
@@ -1717,16 +1811,16 @@ class InAppWebViewController {
///
///[zoomFactor] represents the zoom factor to apply. On Android, the zoom factor will be clamped to the Webview's zoom limits and, also, this value must be in the range 0.01 (excluded) to 100.0 (included).
///
- ///[iosAnimated] `true` to animate the transition to the new scale, `false` to make the transition immediate.
+ ///[animated] `true` to animate the transition to the new scale, `false` to make the transition immediate.
///**NOTE**: available only on iOS.
///
///**NOTE**: available on Android 21+.
///
- ///**Official Android API**: https://developer.android.com/reference/android/webkit/WebView#zoomBy(float)
- ///
- ///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619412-setzoomscale
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.zoomBy](https://developer.android.com/reference/android/webkit/WebView#zoomBy(float)))
+ ///- iOS ([Official API - UIScrollView.setZoomScale](https://developer.apple.com/documentation/uikit/uiscrollview/1619412-setzoomscale))
Future zoomBy(
- {required double zoomFactor, bool iosAnimated = false}) async {
+ {required double zoomFactor, @Deprecated('Use `animated` instead') bool? iosAnimated, bool animated = false}) async {
assert(defaultTargetPlatform != TargetPlatform.android ||
(defaultTargetPlatform == TargetPlatform.android &&
zoomFactor > 0.01 &&
@@ -1734,13 +1828,28 @@ class InAppWebViewController {
Map args = {};
args.putIfAbsent('zoomFactor', () => zoomFactor);
- args.putIfAbsent('iosAnimated', () => iosAnimated);
+ args.putIfAbsent('animated', () => iosAnimated ?? animated);
return await _channel.invokeMethod('zoomBy', args);
}
+ ///Gets the URL that was originally requested 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. Also, there may have been redirects resulting in a different URL to that originally requested.
+ ///
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView ([Official API - WebView.getOriginalUrl](https://developer.android.com/reference/android/webkit/WebView#getOriginalUrl()))
+ ///- iOS
+ Future getOriginalUrl() async {
+ Map args = {};
+ String? url = await _channel.invokeMethod('getOriginalUrl', args);
+ return url != null ? Uri.parse(url) : null;
+ }
+
///Gets the current zoom scale of the WebView.
///
- ///**Official iOS API**: https://developer.apple.com/documentation/uikit/uiscrollview/1619419-zoomscale
+ ///**Supported Platforms/Implementations**:
+ ///- Android native WebView
+ ///- iOS ([Official API - UIScrollView.zoomScale](https://developer.apple.com/documentation/uikit/uiscrollview/1619419-zoomscale))
Future getZoomScale() async {
Map