diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt index b519bdd256c6..08485cc9e908 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/previewer/CardViewerFragment.kt @@ -146,6 +146,12 @@ abstract class CardViewerFragment( protected open fun onCreateWebChromeClient() = CardViewerWebChromeClient() + /** + * Reconfigures the [WebView] after a render process crash by calling [setupWebView]. + * + * Subclasses that override this method must call `super.onWebViewRecreated(webView)`, + * as the base implementation reapplies all clients, settings, and content. + */ override fun onWebViewRecreated(webView: WebView) { setupWebView(null) } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/SafeWebViewLayout.kt b/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/SafeWebViewLayout.kt index 6272c72ef09a..6a24a17e3d1f 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/SafeWebViewLayout.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/SafeWebViewLayout.kt @@ -217,6 +217,26 @@ open class SafeWebViewLayout : } } +/** + * Listener for [SafeWebViewLayout.onRenderProcessGone], called after the internal [WebView] is + * replaced due to a render process crash or the system killing it to free memory. + * + * Any [Fragment] containing a [SafeWebViewLayout] **must** implement this interface. In debug builds, + * a missing implementation will throw at [SafeWebViewLayout.onAttachedToWindow()] + * + * @see SafeWebViewLayout.onRenderProcessGone + */ fun interface OnWebViewRecreatedListener { + /** + * Reconfigures a [WebView] after [SafeWebViewLayout.onRenderProcessGone] has replaced + * the old instance. Implementations must reapply all clients, settings and content + * that were configured on the original [WebView], as [SafeWebViewLayout] only handles + * the structural replacement and cannot reapply app level configuration. + * + * To manually trigger this path, call `webViewLayout.loadUrl("chrome://crash")`. + * Automated testing requires an instrumented test; a unit test is not sufficient. + * + * @param webView the new [WebView], already attached to [SafeWebViewLayout] + */ fun onWebViewRecreated(webView: WebView) }