Skip to content

Commit

Permalink
[WebLayer] Fix renderer crash in Android <= M
Browse files Browse the repository at this point in the history
When loading WebLayer from the WebView provider on M or lower, all
renderer processes crash because the webviewupdate service is not
available in isolated processes.

Bug: 1027028
Change-Id: I9b68c911e44f480762a9b702f34eef9d1a99d893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1928046
Reviewed-by: Richard Coles <[email protected]>
Commit-Queue: Clark DuVall <[email protected]>
Cr-Commit-Position: refs/heads/master@{#717904}
  • Loading branch information
clarkduvall authored and Commit Bot committed Nov 21, 2019
1 parent 34d3a07 commit 4928f27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void onCreate() {
super.onCreate();
try {
Context appContext = getApplicationContext();
ClassLoader remoteClassLoader = WebLayer.getOrCreateRemoteClassLoader(appContext);
ClassLoader remoteClassLoader =
WebLayer.getOrCreateRemoteClassLoaderForChildProcess(appContext);
mImpl = IChildProcessService.Stub.asInterface(
(IBinder) remoteClassLoader
.loadClass("org.chromium.weblayer_private.ChildProcessServiceImpl")
Expand Down
25 changes: 25 additions & 0 deletions weblayer/public/java/org/chromium/weblayer/WebLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.support.v4.app.Fragment;
import android.util.AndroidRuntimeException;
Expand Down Expand Up @@ -249,6 +250,30 @@ public static Fragment createBrowserFragment(@Nullable String profilePath) {
}
}

@SuppressWarnings("NewApi")
static ClassLoader getOrCreateRemoteClassLoaderForChildProcess(Context appContext)
throws PackageManager.NameNotFoundException, ReflectiveOperationException {
if (sRemoteClassLoader != null) {
return sRemoteClassLoader;
}
if (getImplPackageName(appContext) == null && Process.isIsolated()
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
// In <= M, the WebView update service is not available in isolated processes. This
// causes a crash when trying to initialize WebView through the normal machinery, so we
// need to directly make the remote context here.
String packageName = (String) Class.forName("android.webkit.WebViewFactory")
.getMethod("getWebViewPackageName")
.invoke(null);
sRemoteClassLoader =
appContext
.createPackageContext(packageName,
Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE)
.getClassLoader();
return sRemoteClassLoader;
}
return getOrCreateRemoteClassLoader(appContext);
}

/**
* Creates a ClassLoader for the remote (weblayer implementation) side.
*/
Expand Down

0 comments on commit 4928f27

Please sign in to comment.