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

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

Make WebViewLibraryLoader interface more flexible.

Pass the library file name to WebViewLibraryLoader.loadNativeLibrary
instead of passing the ApplicationInfo, which was only used to look the
native library file name up. This will allow loadNativeLibrary to be
called from the webview zygote, which doesn't have the ApplicationInfo
available.

Bug: 63749735
Test: CtsWebkitTests
Change-Id: I0bd2de38cd1a0112bbeee6225563d4d0add048e7
parent 32bdf162
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -205,25 +205,21 @@ public final class WebViewFactory {
        }

        PackageManager packageManager = AppGlobals.getInitialApplication().getPackageManager();
        PackageInfo packageInfo;
        String libraryFileName;
        try {
            packageInfo = packageManager.getPackageInfo(packageName,
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName,
                    PackageManager.GET_META_DATA | PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
            libraryFileName = getWebViewLibrary(packageInfo.applicationInfo);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(LOGTAG, "Couldn't find package " + packageName);
            return LIBLOAD_WRONG_PACKAGE_NAME;
        }

        try {
            int loadNativeRet = WebViewLibraryLoader.loadNativeLibrary(clazzLoader, packageInfo);
        int loadNativeRet = WebViewLibraryLoader.loadNativeLibrary(clazzLoader, libraryFileName);
        // If we failed waiting for relro we want to return that fact even if we successfully
        // load the relro file.
        if (loadNativeRet == LIBLOAD_SUCCESS) return response.status;
        return loadNativeRet;
        } catch (MissingWebViewPackageException e) {
            Log.e(LOGTAG, "Couldn't load native library: " + e);
            return LIBLOAD_FAILED_TO_LOAD_LIBRARY;
        }
    }

    static WebViewFactoryProvider getProvider() {
@@ -454,7 +450,8 @@ public final class WebViewFactory {
                ClassLoader clazzLoader = webViewContext.getClassLoader();

                Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
                WebViewLibraryLoader.loadNativeLibrary(clazzLoader, sPackageInfo);
                WebViewLibraryLoader.loadNativeLibrary(clazzLoader,
                        getWebViewLibrary(sPackageInfo.applicationInfo));
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);

                Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
+2 −5
Original line number Diff line number Diff line
@@ -234,17 +234,14 @@ public class WebViewLibraryLoader {
     * <p class="note"><b>Note:</b> Assumes that we have waited for relro creation.
     *
     * @param clazzLoader class loader used to find the linker namespace to load the library into.
     * @param packageInfo the package from which WebView is loaded.
     * @param libraryFileName the filename of the library to load.
     */
    static int loadNativeLibrary(ClassLoader clazzLoader, PackageInfo packageInfo)
            throws WebViewFactory.MissingWebViewPackageException {
    public static int loadNativeLibrary(ClassLoader clazzLoader, String libraryFileName) {
        if (!sAddressSpaceReserved) {
            Log.e(LOGTAG, "can't load with relro file; address space not reserved");
            return WebViewFactory.LIBLOAD_ADDRESS_SPACE_NOT_RESERVED;
        }

        final String libraryFileName =
                WebViewFactory.getWebViewLibrary(packageInfo.applicationInfo);
        String relroPath = VMRuntime.getRuntime().is64Bit() ? CHROMIUM_WEBVIEW_NATIVE_RELRO_64 :
                                                              CHROMIUM_WEBVIEW_NATIVE_RELRO_32;
        int result = nativeLoadWithRelroFile(libraryFileName, relroPath, clazzLoader);