Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb07f3ca authored by Torne (Richard Coles)'s avatar Torne (Richard Coles)
Browse files

WebViewChromium: don't use a separate class loader.

Use the ordinary system class loader to load the Chromium-based WebView
implementation classes now that the implementation .jar is part of the
boot class path. Instead of checking for the .jar file's existence, just
check to see if we can load the class to determine whether the new
WebView is available.

This also removes the check for Build.IS_DEBUGGABLE; the Chromium-based
WebView will now be available in user builds if enabled in the developer
options.

Change-Id: I06bae9b91656aa41b09c0e6f63f90736db993418
parent a4cda4d6
Loading
Loading
Loading
Loading
+12 −16
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@ public final class WebViewFactory {
    private static final String DEFAULT_WEBVIEW_FACTORY = "android.webkit.WebViewClassic$Factory";
    private static final String DEFAULT_WEBVIEW_FACTORY = "android.webkit.WebViewClassic$Factory";
    private static final String CHROMIUM_WEBVIEW_FACTORY =
    private static final String CHROMIUM_WEBVIEW_FACTORY =
            "com.android.webview.chromium.WebViewChromiumFactoryProvider";
            "com.android.webview.chromium.WebViewChromiumFactoryProvider";
    private static final String CHROMIUM_WEBVIEW_JAR = "/system/framework/webviewchromium.jar";


    private static final String LOGTAG = "WebViewFactory";
    private static final String LOGTAG = "WebViewFactory";


@@ -49,7 +48,14 @@ public final class WebViewFactory {
    private static final Object sProviderLock = new Object();
    private static final Object sProviderLock = new Object();


    public static boolean isExperimentalWebViewAvailable() {
    public static boolean isExperimentalWebViewAvailable() {
        return Build.IS_DEBUGGABLE && (new java.io.File(CHROMIUM_WEBVIEW_JAR).exists());
        try {
            // Pass false so we don't initialize the class at this point, as this will be wasted if
            // it's not enabled.
            Class.forName(CHROMIUM_WEBVIEW_FACTORY, false, WebViewFactory.class.getClassLoader());
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }
    }


    static WebViewFactoryProvider getProvider() {
    static WebViewFactoryProvider getProvider() {
@@ -61,7 +67,7 @@ public final class WebViewFactory {
            if (isExperimentalWebViewEnabled()) {
            if (isExperimentalWebViewEnabled()) {
                StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
                StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
                try {
                try {
                    sProviderInstance = loadChromiumProvider();
                    sProviderInstance = getFactoryByName(CHROMIUM_WEBVIEW_FACTORY);
                    if (DEBUG) Log.v(LOGTAG, "Loaded Chromium provider: " + sProviderInstance);
                    if (DEBUG) Log.v(LOGTAG, "Loaded Chromium provider: " + sProviderInstance);
                } finally {
                } finally {
                    StrictMode.setThreadPolicy(oldPolicy);
                    StrictMode.setThreadPolicy(oldPolicy);
@@ -71,8 +77,7 @@ public final class WebViewFactory {
            if (sProviderInstance == null) {
            if (sProviderInstance == null) {
                if (DEBUG) Log.v(LOGTAG, "Falling back to default provider: "
                if (DEBUG) Log.v(LOGTAG, "Falling back to default provider: "
                        + DEFAULT_WEBVIEW_FACTORY);
                        + DEFAULT_WEBVIEW_FACTORY);
                sProviderInstance = getFactoryByName(DEFAULT_WEBVIEW_FACTORY,
                sProviderInstance = getFactoryByName(DEFAULT_WEBVIEW_FACTORY);
                        WebViewFactory.class.getClassLoader());
                if (sProviderInstance == null) {
                if (sProviderInstance == null) {
                    if (DEBUG) Log.v(LOGTAG, "Falling back to explicit linkage");
                    if (DEBUG) Log.v(LOGTAG, "Falling back to explicit linkage");
                    sProviderInstance = new WebViewClassic.Factory();
                    sProviderInstance = new WebViewClassic.Factory();
@@ -96,19 +101,10 @@ public final class WebViewFactory {
        return SystemProperties.getBoolean(WEBVIEW_EXPERIMENTAL_PROPERTY, false);
        return SystemProperties.getBoolean(WEBVIEW_EXPERIMENTAL_PROPERTY, false);
    }
    }


    // TODO: This allows us to have the legacy and Chromium WebView coexist for development
    private static WebViewFactoryProvider getFactoryByName(String providerName) {
    // and side-by-side testing. After transition, remove this when no longer required.
    private static WebViewFactoryProvider loadChromiumProvider() {
        ClassLoader clazzLoader = new PathClassLoader(CHROMIUM_WEBVIEW_JAR, null,
                WebViewFactory.class.getClassLoader());
        return getFactoryByName(CHROMIUM_WEBVIEW_FACTORY, clazzLoader);
    }

    private static WebViewFactoryProvider getFactoryByName(String providerName,
            ClassLoader loader) {
        try {
        try {
            if (DEBUG) Log.v(LOGTAG, "attempt to load class " + providerName);
            if (DEBUG) Log.v(LOGTAG, "attempt to load class " + providerName);
            Class<?> c = Class.forName(providerName, true, loader);
            Class<?> c = Class.forName(providerName);
            if (DEBUG) Log.v(LOGTAG, "instantiating factory");
            if (DEBUG) Log.v(LOGTAG, "instantiating factory");
            return (WebViewFactoryProvider) c.newInstance();
            return (WebViewFactoryProvider) c.newInstance();
        } catch (ClassNotFoundException e) {
        } catch (ClassNotFoundException e) {