From 8a57947ad0c3b327e19d2f46a2c5614c5d39af15 Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Thu, 28 Sep 2023 17:25:33 -0500 Subject: [PATCH 1/4] feat(android): allow developers to provide logic for onRenderProcessGone in WebViewListener --- .../com/getcapacitor/BridgeWebViewClient.java | 17 +++++++++++++++++ .../java/com/getcapacitor/WebViewListener.java | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java index 87a6c6f77c..779347ff7b 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java @@ -2,6 +2,7 @@ import android.graphics.Bitmap; import android.net.Uri; +import android.webkit.RenderProcessGoneDetail; import android.webkit.WebResourceError; import android.webkit.WebResourceRequest; import android.webkit.WebResourceResponse; @@ -92,4 +93,20 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebRes view.loadUrl(errorPath); } } + + @Override + public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { + super.onRenderProcessGone(view, detail); + List webViewListeners = bridge.getWebViewListeners(); + + if (webViewListeners != null) { + for (WebViewListener listener : bridge.getWebViewListeners()) { + listener.onRenderProcessGone(view, detail); + } + + return true; + } + + return false; + } } diff --git a/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java b/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java index f509e637c4..438188eda3 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java +++ b/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java @@ -1,5 +1,6 @@ package com.getcapacitor; +import android.webkit.RenderProcessGoneDetail; import android.webkit.WebView; /** @@ -42,4 +43,13 @@ public void onReceivedHttpError(WebView webView) { public void onPageStarted(WebView webView) { // Override me to add behavior to the page started event } + + /** + * Callback for render process gone event. + * + * @param webView The WebView that loaded + */ + public void onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) { + // Override me to add behavior to the web view render process gone event + } } From 8ac6eb237c0db686cd68c78ada915f99d8fe4560 Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Fri, 29 Sep 2023 10:27:22 -0500 Subject: [PATCH 2/4] update to allow developer to return true or false state --- .../main/java/com/getcapacitor/BridgeWebViewClient.java | 7 +++---- .../src/main/java/com/getcapacitor/WebViewListener.java | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java index 779347ff7b..084ab858a5 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java @@ -98,13 +98,12 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebRes public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { super.onRenderProcessGone(view, detail); List webViewListeners = bridge.getWebViewListeners(); - if (webViewListeners != null) { for (WebViewListener listener : bridge.getWebViewListeners()) { - listener.onRenderProcessGone(view, detail); + if (listener.onRenderProcessGone(view, detail)) { + return true; + } } - - return true; } return false; diff --git a/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java b/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java index 438188eda3..6df4f6c0ae 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java +++ b/android/capacitor/src/main/java/com/getcapacitor/WebViewListener.java @@ -45,11 +45,13 @@ public void onPageStarted(WebView webView) { } /** - * Callback for render process gone event. + * Callback for render process gone event. Return true if the state is handled. * * @param webView The WebView that loaded + * @return returns false by default if the listener is not overridden and used */ - public void onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) { + public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) { // Override me to add behavior to the web view render process gone event + return false; } } From cac42d4354d48ed9452b124ea0b8bccfb8b1e9de Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Tue, 3 Oct 2023 15:30:38 -0500 Subject: [PATCH 3/4] dont return early, it shortcuts potential listeners --- .../main/java/com/getcapacitor/BridgeWebViewClient.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java index 084ab858a5..05cabdc0ea 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java @@ -97,15 +97,15 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request, WebRes @Override public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) { super.onRenderProcessGone(view, detail); + boolean result = false; + List webViewListeners = bridge.getWebViewListeners(); if (webViewListeners != null) { for (WebViewListener listener : bridge.getWebViewListeners()) { - if (listener.onRenderProcessGone(view, detail)) { - return true; - } + result = result || listener.onRenderProcessGone(view, detail); } } - return false; + return result; } } From d7c008821851307744b61a56addacd97f282c40b Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Thu, 5 Oct 2023 09:29:10 -0500 Subject: [PATCH 4/4] Update android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java Co-authored-by: jcesarmobile --- .../src/main/java/com/getcapacitor/BridgeWebViewClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java index 05cabdc0ea..c434247a27 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java @@ -102,7 +102,7 @@ public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) List webViewListeners = bridge.getWebViewListeners(); if (webViewListeners != null) { for (WebViewListener listener : bridge.getWebViewListeners()) { - result = result || listener.onRenderProcessGone(view, detail); + result = listener.onRenderProcessGone(view, detail) || result; } }