Skip to content

Commit a42b0e4

Browse files
Updated window.flutter_inappwebview.callHandler implementation: if there is an error/exception on Flutter/Dart side, the callHandler will reject the JavaScript promise with the error/exception message, so you can catch it also on JavaScript side, Fixed Android Web Storage Manager deleteAllData and deleteOrigin methods implementation, fix #1462, fix #1475
1 parent 0f1c7e3 commit a42b0e4

File tree

22 files changed

+120
-39
lines changed

22 files changed

+120
-39
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 6.0.0-beta.22
2+
3+
- Updated `window.flutter_inappwebview.callHandler` implementation: if there is an error/exception on Flutter/Dart side, the `callHandler` will reject the JavaScript promise with the error/exception message, so you can catch it also on JavaScript side
4+
- Fixed Android Web Storage Manager `deleteAllData` and `deleteOrigin` methods implementation
5+
- Fixed "Xiaomi store - Conflict of Privacy Permissions, android.permission.MY_READ_INSTALLED_PACKAGES" [#1462](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1462)
6+
- Fixed "Flutter 3.0.5 compilation issue" [#1475](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1475)
7+
18
## 6.0.0-beta.21
29

310
- Fixed "Android plugin version 6 - UserScripts not executing on new tabs." [#1455](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1455)
@@ -174,6 +181,10 @@
174181
- Removed `URLProtectionSpace.iosIsProxy` property
175182
- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null`
176183

184+
## 5.7.2+3
185+
186+
- Fixed "Xiaomi store - Conflict of Privacy Permissions, android.permission.MY_READ_INSTALLED_PACKAGES" [#1462](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1462)
187+
177188
## 5.7.2+2
178189

179190
- Fixed "Unexpected addWebMessageListener behaviour" [#1422](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1422)

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/MyCookieManager.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ public class MyCookieManager extends ChannelDelegateImpl {
3030
@Nullable
3131
public InAppWebViewFlutterPlugin plugin;
3232

33-
public MyCookieManager(final InAppWebViewFlutterPlugin plugin) {
33+
public MyCookieManager(@NonNull final InAppWebViewFlutterPlugin plugin) {
3434
super(new MethodChannel(plugin.messenger, METHOD_CHANNEL_NAME));
3535
this.plugin = plugin;
36-
cookieManager = getCookieManager();
36+
}
37+
38+
public static void init() {
39+
if (cookieManager == null) {
40+
cookieManager = getCookieManager();
41+
}
3742
}
3843

3944
@Override
4045
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
46+
init();
47+
4148
switch (call.method) {
4249
case "setCookie":
4350
{

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/MyWebStorage.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,27 @@ public class MyWebStorage extends ChannelDelegateImpl {
2525
@Nullable
2626
public InAppWebViewFlutterPlugin plugin;
2727

28-
public MyWebStorage(final InAppWebViewFlutterPlugin plugin) {
28+
public MyWebStorage(@NonNull final InAppWebViewFlutterPlugin plugin) {
2929
super(new MethodChannel(plugin.messenger, METHOD_CHANNEL_NAME));
3030
this.plugin = plugin;
31-
webStorageManager = WebStorage.getInstance();
31+
}
32+
33+
public static void init() {
34+
if (webStorageManager == null) {
35+
webStorageManager = WebStorage.getInstance();
36+
}
3237
}
3338

3439
@Override
3540
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
41+
init();
42+
3643
switch (call.method) {
3744
case "getOrigins":
3845
getOrigins(result);
3946
break;
4047
case "deleteAllData":
41-
if (webStorageManager == null) {
48+
if (webStorageManager != null) {
4249
webStorageManager.deleteAllData();
4350
result.success(true);
4451
} else {
@@ -47,7 +54,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
4754
break;
4855
case "deleteOrigin":
4956
{
50-
if (webStorageManager == null) {
57+
if (webStorageManager != null) {
5158
String origin = (String) call.argument("origin");
5259
webStorageManager.deleteOrigin(origin);
5360
result.success(true);

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/WebViewFeatureManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class WebViewFeatureManager extends ChannelDelegateImpl {
1616
@Nullable
1717
public InAppWebViewFlutterPlugin plugin;
1818

19-
public WebViewFeatureManager(final InAppWebViewFlutterPlugin plugin) {
19+
public WebViewFeatureManager(@NonNull final InAppWebViewFlutterPlugin plugin) {
2020
super(new MethodChannel(plugin.messenger, METHOD_CHANNEL_NAME));
2121
this.plugin = plugin;
2222
}

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/credential_database/CredentialDatabaseHandler.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,23 @@ public class CredentialDatabaseHandler extends ChannelDelegateImpl {
3030
@Nullable
3131
public InAppWebViewFlutterPlugin plugin;
3232

33-
public CredentialDatabaseHandler(final InAppWebViewFlutterPlugin plugin) {
33+
public CredentialDatabaseHandler(@NonNull final InAppWebViewFlutterPlugin plugin) {
3434
super(new MethodChannel(plugin.messenger, METHOD_CHANNEL_NAME));
3535
this.plugin = plugin;
36-
credentialDatabase = CredentialDatabase.getInstance(plugin.applicationContext);
36+
}
37+
38+
public static void init(@NonNull InAppWebViewFlutterPlugin plugin) {
39+
if (credentialDatabase == null) {
40+
credentialDatabase = CredentialDatabase.getInstance(plugin.applicationContext);
41+
}
3742
}
3843

3944
@Override
4045
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
46+
if (plugin != null) {
47+
init(plugin);
48+
}
49+
4150
switch (call.method) {
4251
case "getAllAuthCredentials":
4352
{

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/plugin_scripts_js/JavaScriptBridgeJS.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public class JavaScriptBridgeJS {
220220
" var _callHandlerID = setTimeout(function(){});" +
221221
" window." + JAVASCRIPT_BRIDGE_NAME + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));" +
222222
" return new Promise(function(resolve, reject) {" +
223-
" window." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = resolve;" +
223+
" window." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = {resolve: resolve, reject: reject};" +
224224
" });" +
225225
" };" +
226226
" }"+
@@ -230,7 +230,7 @@ public class JavaScriptBridgeJS {
230230
" var _callHandlerID = setTimeout(function(){});" +
231231
" window.top." + JAVASCRIPT_BRIDGE_NAME + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));" +
232232
" return new Promise(function(resolve, reject) {" +
233-
" window.top." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = resolve;" +
233+
" window.top." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = {resolve: resolve, reject: reject};" +
234234
" });" +
235235
" };" +
236236
"}" +

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxyManager.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@ public class ProxyManager extends ChannelDelegateImpl {
2525
@Nullable
2626
public InAppWebViewFlutterPlugin plugin;
2727

28-
public ProxyManager(final InAppWebViewFlutterPlugin plugin) {
28+
public ProxyManager(@NonNull final InAppWebViewFlutterPlugin plugin) {
2929
super(new MethodChannel(plugin.messenger, METHOD_CHANNEL_NAME));
3030
this.plugin = plugin;
31-
if (WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE)) {
31+
}
32+
33+
public static void init() {
34+
if (proxyController == null &&
35+
WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE)) {
3236
proxyController = ProxyController.getInstance();
33-
} else {
34-
proxyController = null;
3537
}
3638
}
3739

3840
@Override
3941
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
42+
init();
43+
4044
switch (call.method) {
4145
case "setProxyOverride":
4246
if (proxyController != null) {

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/service_worker/ServiceWorkerChannelDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public ServiceWorkerChannelDelegate(@NonNull ServiceWorkerManager serviceWorkerM
3636
@SuppressLint("RestrictedApi")
3737
@Override
3838
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
39+
ServiceWorkerManager.init();
3940
ServiceWorkerControllerCompat serviceWorkerController = ServiceWorkerManager.serviceWorkerController;
4041
ServiceWorkerWebSettingsCompat serviceWorkerWebSettings = (serviceWorkerController != null) ?
4142
serviceWorkerController.getServiceWorkerWebSettings() : null;

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/service_worker/ServiceWorkerManager.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ public class ServiceWorkerManager implements Disposable {
3333
@Nullable
3434
public InAppWebViewFlutterPlugin plugin;
3535

36-
public ServiceWorkerManager(final InAppWebViewFlutterPlugin plugin) {
36+
public ServiceWorkerManager(@NonNull final InAppWebViewFlutterPlugin plugin) {
3737
this.plugin = plugin;
3838
final MethodChannel channel = new MethodChannel(plugin.messenger, METHOD_CHANNEL_NAME);
3939
this.channelDelegate = new ServiceWorkerChannelDelegate(this, channel);
40-
if (WebViewFeature.isFeatureSupported(WebViewFeature.SERVICE_WORKER_BASIC_USAGE)) {
40+
}
41+
42+
public static void init() {
43+
if (serviceWorkerController == null &&
44+
WebViewFeature.isFeatureSupported(WebViewFeature.SERVICE_WORKER_BASIC_USAGE)) {
4145
serviceWorkerController = ServiceWorkerControllerCompat.getInstance();
42-
} else {
43-
serviceWorkerController = null;
4446
}
4547
}
4648

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/tracing/TracingControllerChannelDelegate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public TracingControllerChannelDelegate(@NonNull TracingControllerManager tracin
2727

2828
@Override
2929
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
30+
TracingControllerManager.init();
3031
TracingController tracingController = TracingControllerManager.tracingController;
3132

3233
switch (call.method) {

0 commit comments

Comments
 (0)