Throw platform exception when ProcessGlobalConfig.apply throws an error on the native side to be able to catch it on Flutter side, updated e.printStackTrace with Log.e where possible

This commit is contained in:
Lorenzo Pichilli 2023-11-30 10:08:49 +01:00
parent 35fea2c331
commit 23097dbce0
15 changed files with 53 additions and 56 deletions

View File

@ -1,3 +1,7 @@
## 1.0.4
- Throw platform exception when ProcessGlobalConfig.apply throws an error on the native side
## 1.0.3 ## 1.0.3
- Updated `ContentBlockerHandler` CSS_DISPLAY_NONE action type and `JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_JS_SOURCE` javascript implementation code - Updated `ContentBlockerHandler` CSS_DISPLAY_NONE action type and `JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_JS_SOURCE` javascript implementation code

View File

@ -250,16 +250,14 @@ public class MyCookieManager extends ChannelDelegateImpl {
cookieMap.put("expiresDate", expiryDate.getTime()); cookieMap.put("expiresDate", expiryDate.getTime());
} }
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
Log.e(LOG_TAG, e.getMessage());
} }
} else if (cookieParamName.equalsIgnoreCase("Max-Age")) { } else if (cookieParamName.equalsIgnoreCase("Max-Age")) {
try { try {
long maxAge = Long.parseLong(cookieParamValue); long maxAge = Long.parseLong(cookieParamValue);
cookieMap.put("expiresDate", System.currentTimeMillis() + maxAge); cookieMap.put("expiresDate", System.currentTimeMillis() + maxAge);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
Log.e(LOG_TAG, e.getMessage());
} }
} else if (cookieParamName.equalsIgnoreCase("Domain")) { } else if (cookieParamName.equalsIgnoreCase("Domain")) {
cookieMap.put("domain", cookieParamValue); cookieMap.put("domain", cookieParamValue);

View File

@ -142,15 +142,13 @@ public class Util {
} }
certificateFileStream.close(); certificateFileStream.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
Log.e(LOG_TAG, e.getMessage());
} finally { } finally {
if (certificateFileStream != null) { if (certificateFileStream != null) {
try { try {
certificateFileStream.close(); certificateFileStream.close();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); Log.e(LOG_TAG, "", ex);
Log.e(LOG_TAG, ex.getMessage());
} }
} }
} }
@ -193,8 +191,7 @@ public class Util {
} }
catch (Exception e) { catch (Exception e) {
if (!(e instanceof SSLHandshakeException)) { if (!(e instanceof SSLHandshakeException)) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
Log.e(LOG_TAG, e.getMessage());
} }
if (urlConnection != null) { if (urlConnection != null) {
urlConnection.disconnect(); urlConnection.disconnect();

View File

@ -3,6 +3,7 @@ package com.pichillilorenzo.flutter_inappwebview_android.content_blocker;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebResourceResponse; import android.webkit.WebResourceResponse;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -229,7 +230,7 @@ public class ContentBlockerHandler {
} }
} catch (Exception e) { } catch (Exception e) {
if (!(e instanceof SSLHandshakeException)) { if (!(e instanceof SSLHandshakeException)) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} finally { } finally {
urlConnection.disconnect(); urlConnection.disconnect();
@ -262,8 +263,7 @@ public class ContentBlockerHandler {
// response.close(); // response.close();
// } // }
// if (!(e instanceof SSLHandshakeException)) { // if (!(e instanceof SSLHandshakeException)) {
// e.printStackTrace(); // Log.e(LOG_TAG, "", e);
// Log.e(LOG_TAG, e.getMessage());
// } // }
// } // }
} }
@ -302,7 +302,7 @@ public class ContentBlockerHandler {
responseResourceType = getResourceTypeFromContentType(contentType); responseResourceType = getResourceTypeFromContentType(contentType);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} finally { } finally {
urlConnection.disconnect(); urlConnection.disconnect();
} }

View File

@ -163,7 +163,6 @@ public class InAppBrowserActivity extends AppCompatActivity implements InAppBrow
try { try {
webView.loadFile(initialFile); webView.loadFile(initialFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e); Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e);
return; return;
} }
@ -417,8 +416,7 @@ public class InAppBrowserActivity extends AppCompatActivity implements InAppBrow
openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); openActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(openActivity, 0); startActivityIfNeeded(openActivity, 0);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); Log.d(LOG_TAG, "", e);
Log.d(LOG_TAG, e.getMessage());
} }
} }
} }

View File

@ -1,5 +1,7 @@
package com.pichillilorenzo.flutter_inappwebview_android.process_global_config; package com.pichillilorenzo.flutter_inappwebview_android.process_global_config;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.webkit.ProcessGlobalConfig; import androidx.webkit.ProcessGlobalConfig;
@ -13,7 +15,7 @@ import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
public class ProcessGlobalConfigManager extends ChannelDelegateImpl { public class ProcessGlobalConfigManager extends ChannelDelegateImpl {
protected static final String LOG_TAG = "ProcessGlobalConfigManager"; protected static final String LOG_TAG = "ProcessGlobalConfigM";
public static final String METHOD_CHANNEL_NAME = "com.pichillilorenzo/flutter_inappwebview_processglobalconfig"; public static final String METHOD_CHANNEL_NAME = "com.pichillilorenzo/flutter_inappwebview_processglobalconfig";
@Nullable @Nullable
@ -31,9 +33,15 @@ public class ProcessGlobalConfigManager extends ChannelDelegateImpl {
if (plugin != null && plugin.activity != null) { if (plugin != null && plugin.activity != null) {
ProcessGlobalConfigSettings settings = (new ProcessGlobalConfigSettings()) ProcessGlobalConfigSettings settings = (new ProcessGlobalConfigSettings())
.parse((Map<String, Object>) call.argument("settings")); .parse((Map<String, Object>) call.argument("settings"));
try {
ProcessGlobalConfig.apply(settings.toProcessGlobalConfig(plugin.activity)); ProcessGlobalConfig.apply(settings.toProcessGlobalConfig(plugin.activity));
}
result.success(true); result.success(true);
} catch (Exception e) {
result.error(LOG_TAG, "", e);
}
} else {
result.success(false);
}
break; break;
default: default:
result.notImplemented(); result.notImplemented();

View File

@ -1,6 +1,7 @@
package com.pichillilorenzo.flutter_inappwebview_android.service_worker; package com.pichillilorenzo.flutter_inappwebview_android.service_worker;
import android.os.Build; import android.os.Build;
import android.util.Log;
import android.webkit.WebResourceRequest; import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse; import android.webkit.WebResourceResponse;
@ -61,7 +62,7 @@ public class ServiceWorkerManager implements Disposable {
try { try {
response = channelDelegate.shouldInterceptRequest(requestExt); response = channelDelegate.shouldInterceptRequest(requestExt);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
return null; return null;
} }
} }

View File

@ -2,6 +2,7 @@ package com.pichillilorenzo.flutter_inappwebview_android.types;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.util.Log;
import android.webkit.WebResourceResponse; import android.webkit.WebResourceResponse;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -122,7 +123,7 @@ public class WebViewAssetLoaderExt implements Disposable {
try { try {
response = channelDelegate.handle(path); response = channelDelegate.handle(path);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
return null; return null;
} }

View File

@ -100,7 +100,7 @@ public class JavaScriptBridgeInterface {
inAppWebView.callAsyncJavaScriptCallbacks.remove(resultUuid); inAppWebView.callAsyncJavaScriptCallbacks.remove(resultUuid);
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
return; return;
} else if (handlerName.equals("evaluateJavaScriptWithContentWorld")) { } else if (handlerName.equals("evaluateJavaScriptWithContentWorld")) {
@ -114,7 +114,7 @@ public class JavaScriptBridgeInterface {
inAppWebView.evaluateJavaScriptContentWorldCallbacks.remove(resultUuid); inAppWebView.evaluateJavaScriptContentWorldCallbacks.remove(resultUuid);
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
return; return;
} }

View File

@ -128,7 +128,6 @@ public class FlutterWebView implements PlatformWebView {
try { try {
webView.loadFile(initialFile); webView.loadFile(initialFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e); Log.e(LOG_TAG, initialFile + " asset file cannot be found!", e);
} }
} }

View File

@ -729,7 +729,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
try { try {
compressFormat = Bitmap.CompressFormat.valueOf((String) screenshotConfiguration.get("compressFormat")); compressFormat = Bitmap.CompressFormat.valueOf((String) screenshotConfiguration.get("compressFormat"));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
quality = (Integer) screenshotConfiguration.get("quality"); quality = (Integer) screenshotConfiguration.get("quality");
@ -743,13 +743,13 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
try { try {
byteArrayOutputStream.close(); byteArrayOutputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
screenshotBitmap.recycle(); screenshotBitmap.recycle();
result.success(byteArrayOutputStream.toByteArray()); result.success(byteArrayOutputStream.toByteArray());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
result.success(null); result.success(null);
} }
} }

View File

@ -790,11 +790,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
try { try {
byteArrayOutputStream.close(); byteArrayOutputStream.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
String errorMessage = e.getMessage();
if (errorMessage != null) {
Log.e(LOG_TAG, errorMessage);
}
} }
icon.recycle(); icon.recycle();
@ -1176,7 +1172,6 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
capturedFile = getCapturedFile(intentType); capturedFile = getCapturedFile(intentType);
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "Error occurred while creating the File", e); Log.e(LOG_TAG, "Error occurred while creating the File", e);
e.printStackTrace();
} }
if (capturedFile == null) { if (capturedFile == null) {
return null; return null;
@ -1199,11 +1194,7 @@ public class InAppWebViewChromeClient extends WebChromeClient implements PluginR
fileProviderAuthority, fileProviderAuthority,
capturedFile); capturedFile);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
String errorMessage = e.getMessage();
if (errorMessage != null) {
Log.e(LOG_TAG, errorMessage);
}
} }
return null; return null;
} }

View File

@ -360,7 +360,7 @@ public class InAppWebViewClient extends WebViewClient {
protocol = uri.getScheme(); protocol = uri.getScheme();
port = uri.getPort(); port = uri.getPort();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
@ -451,7 +451,7 @@ public class InAppWebViewClient extends WebViewClient {
protocol = uri.getScheme(); protocol = uri.getScheme();
port = uri.getPort(); port = uri.getPort();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError); URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError);
@ -510,7 +510,7 @@ public class InAppWebViewClient extends WebViewClient {
URI uri = new URI(url); URI uri = new URI(url);
protocol = uri.getScheme(); protocol = uri.getScheme();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
@ -640,7 +640,7 @@ public class InAppWebViewClient extends WebViewClient {
return webResourceResponse; return webResourceResponse;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
@ -650,7 +650,7 @@ public class InAppWebViewClient extends WebViewClient {
try { try {
response = webView.channelDelegate.shouldInterceptRequest(request); response = webView.channelDelegate.shouldInterceptRequest(request);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
return null; return null;
} }
} }
@ -687,7 +687,7 @@ public class InAppWebViewClient extends WebViewClient {
try { try {
customSchemeResponse = webView.channelDelegate.onLoadResourceWithCustomScheme(request); customSchemeResponse = webView.channelDelegate.onLoadResourceWithCustomScheme(request);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
return null; return null;
} }
} }
@ -697,7 +697,7 @@ public class InAppWebViewClient extends WebViewClient {
try { try {
response = webView.contentBlockerHandler.checkUrl(webView, request, customSchemeResponse.getContentType()); response = webView.contentBlockerHandler.checkUrl(webView, request, customSchemeResponse.getContentType());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
if (response != null) if (response != null)
return response; return response;
@ -712,7 +712,7 @@ public class InAppWebViewClient extends WebViewClient {
try { try {
response = webView.contentBlockerHandler.checkUrl(webView, request); response = webView.contentBlockerHandler.checkUrl(webView, request);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
return response; return response;

View File

@ -372,7 +372,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
protocol = uri.getScheme(); protocol = uri.getScheme();
port = uri.getPort(); port = uri.getPort();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
@ -463,7 +463,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
protocol = uri.getScheme(); protocol = uri.getScheme();
port = uri.getPort(); port = uri.getPort();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError); URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError);
@ -522,7 +522,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
URI uri = new URI(url); URI uri = new URI(url);
protocol = uri.getScheme(); protocol = uri.getScheme();
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
@ -667,7 +667,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
return webResourceResponse; return webResourceResponse;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
@ -677,7 +677,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
try { try {
response = webView.channelDelegate.shouldInterceptRequest(request); response = webView.channelDelegate.shouldInterceptRequest(request);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
return null; return null;
} }
} }
@ -714,7 +714,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
try { try {
customSchemeResponse = webView.channelDelegate.onLoadResourceWithCustomScheme(request); customSchemeResponse = webView.channelDelegate.onLoadResourceWithCustomScheme(request);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
return null; return null;
} }
} }
@ -724,7 +724,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
try { try {
response = webView.contentBlockerHandler.checkUrl(webView, request, customSchemeResponse.getContentType()); response = webView.contentBlockerHandler.checkUrl(webView, request, customSchemeResponse.getContentType());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
if (response != null) if (response != null)
return response; return response;
@ -739,7 +739,7 @@ public class InAppWebViewClientCompat extends WebViewClientCompat {
try { try {
response = webView.contentBlockerHandler.checkUrl(webView, request); response = webView.contentBlockerHandler.checkUrl(webView, request);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(LOG_TAG, "", e);
} }
} }
return response; return response;

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_android name: flutter_inappwebview_android
description: Android implementation of the flutter_inappwebview plugin. description: Android implementation of the flutter_inappwebview plugin.
version: 1.0.3 version: 1.0.4
homepage: https://inappwebview.dev/ homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues