Skip to content

Commit

Permalink
feat: add plugin hooks for WebViewClient.onRenderProcessGone
Browse files Browse the repository at this point in the history
  • Loading branch information
peitschie committed Mar 20, 2023
1 parent dbddbf2 commit 930b777
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions framework/src/org/apache/cordova/CordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.webkit.RenderProcessGoneDetail;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -442,4 +443,17 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions,
public CordovaPluginPathHandler getPathHandler() {
return null;
}

/**
* Called when the WebView's render process has exited.
*
* See <a href="https://developer.android.com/reference/android/webkit/WebViewClient#onRenderProcessGone(android.webkit.WebView,%20android.webkit.RenderProcessGoneDetail)">WebViewClient#onRenderProcessGone</a>
*
* @return true if the host application handled the situation that process has exited,
* otherwise, application will crash if render process crashed, or be killed
* if render process was killed by the system.
*/
public boolean onRenderProcessGone(CordovaWebView view, RenderProcessGoneDetail detail) {
return false;
}
}
26 changes: 26 additions & 0 deletions framework/src/org/apache/cordova/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.os.Bundle;
import android.os.Debug;
import android.os.Build;
import android.webkit.RenderProcessGoneDetail;

/**
* PluginManager is exposed to JavaScript in the Cordova WebView.
Expand Down Expand Up @@ -617,4 +618,29 @@ public ArrayList<CordovaPluginPathHandler> getPluginPathHandlers() {
}
return handlers;
}

/**
* Called when the WebView's render process has exited.
*
* See https://developer.android.com/reference/android/webkit/WebViewClient#onRenderProcessGone(android.webkit.WebView,%20android.webkit.RenderProcessGoneDetail)
*
* @return true if the host application handled the situation that process has exited,
* otherwise, application will crash if render process crashed, or be killed
* if render process was killed by the system.
*/
public boolean onRenderProcessGone(RenderProcessGoneDetail detail) {
boolean result = false;
synchronized (this.entryMap) {
for (PluginEntry entry : this.entryMap.values()) {
CordovaPlugin plugin = pluginMap.get(entry.service);
if (plugin != null) {
if (plugin.onRenderProcessGone(app, detail)) {
result = true;
}
}
}
}

return result;
}
}
12 changes: 12 additions & 0 deletions framework/src/org/apache/cordova/engine/SystemWebViewClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.webkit.ClientCertRequest;
import android.webkit.HttpAuthHandler;
import android.webkit.MimeTypeMap;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
Expand Down Expand Up @@ -422,4 +423,15 @@ private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
return this.assetLoader.shouldInterceptRequest(request.getUrl());
}

@Override
public boolean onRenderProcessGone(final WebView view, RenderProcessGoneDetail detail) {
// Check if there is some plugin which can handle this event
PluginManager pluginManager = this.parentEngine.pluginManager;
if (pluginManager != null && pluginManager.onRenderProcessGone(detail)) {
return true;
}

return super.onRenderProcessGone(view, detail);
}
}

0 comments on commit 930b777

Please sign in to comment.