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

Commit 8ca1e41a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make WebView data directory configurable."

parents 52992ae1 12f64dad
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -49920,6 +49920,7 @@ package android.webkit {
    method public android.print.PrintDocumentAdapter createPrintDocumentAdapter(java.lang.String);
    method public android.webkit.WebMessagePort[] createWebMessageChannel();
    method public void destroy();
    method public static void disableWebView();
    method public void documentHasImages(android.os.Message);
    method public static void enableSlowWholeDocumentDraw();
    method public void evaluateJavascript(java.lang.String, android.webkit.ValueCallback<java.lang.String>);
@@ -49980,6 +49981,7 @@ package android.webkit {
    method public void saveWebArchive(java.lang.String);
    method public void saveWebArchive(java.lang.String, boolean, android.webkit.ValueCallback<java.lang.String>);
    method public deprecated void setCertificate(android.net.http.SslCertificate);
    method public static void setDataDirectorySuffix(java.lang.String);
    method public void setDownloadListener(android.webkit.DownloadListener);
    method public void setFindListener(android.webkit.WebView.FindListener);
    method public deprecated void setHorizontalScrollbarOverlay(boolean);
+1 −0
Original line number Diff line number Diff line
@@ -4605,6 +4605,7 @@ package android.webkit {
    method public boolean canInvokeDrawGlFunctor(android.view.View);
    method public void detachDrawGlFunctor(android.view.View, long);
    method public android.app.Application getApplication();
    method public java.lang.String getDataDirectorySuffix();
    method public java.lang.String getErrorString(android.content.Context, int);
    method public int getPackageId(android.content.res.Resources, java.lang.String);
    method public void invokeDrawGlFunctor(android.view.View, long, boolean);
+42 −0
Original line number Diff line number Diff line
@@ -2080,6 +2080,48 @@ public class WebView extends AbsoluteLayout
        return new PluginList();
    }

    /**
     * Define the directory used to store WebView data for the current process.
     * The provided suffix will be used when constructing data and cache
     * directory paths. If this API is not called, no suffix will be used.
     * Each directory can be used by only one process in the application. If more
     * than one process in an app wishes to use WebView, only one process can use
     * the default directory, and other processes must call this API to define
     * a unique suffix.
     * <p>
     * This API must be called before any instances of WebView are created in
     * this process and before any other methods in the android.webkit package
     * are called by this process.
     *
     * @param suffix The directory name suffix to be used for the current
     *               process. Must not contain a path separator.
     * @throws IllegalStateException if WebView has already been initialized
     *                               in the current process.
     * @throws IllegalArgumentException if the suffix contains a path separator.
     */
    public static void setDataDirectorySuffix(String suffix) {
        WebViewFactory.setDataDirectorySuffix(suffix);
    }

    /**
     * Indicate that the current process does not intend to use WebView, and
     * that an exception should be thrown if a WebView is created or any other
     * methods in the android.webkit package are used.
     * <p>
     * Applications with multiple processes may wish to call this in processes
     * which are not intended to use WebView to prevent potential data directory
     * conflicts (see {@link #setDataDirectorySuffix}) and to avoid accidentally
     * incurring the memory usage of initializing WebView in long-lived
     * processes which have no need for it.
     *
     * @throws IllegalStateException if WebView has already been initialized
     *                               in the current process.
     */
    public static void disableWebView() {
        WebViewFactory.disableWebView();
    }


    /**
     * @deprecated This was used for Gears, which has been deprecated.
     * @hide
+7 −0
Original line number Diff line number Diff line
@@ -218,4 +218,11 @@ public final class WebViewDelegate {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns the data directory suffix to use, or null for none.
     */
    public String getDataDirectorySuffix() {
        return WebViewFactory.getDataDirectorySuffix();
    }
}
+47 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.AndroidRuntimeException;
import android.util.ArraySet;
import android.util.Log;

import java.io.File;
import java.lang.reflect.Method;

/**
@@ -63,6 +64,8 @@ public final class WebViewFactory {
    private static final Object sProviderLock = new Object();
    private static PackageInfo sPackageInfo;
    private static Boolean sWebViewSupported;
    private static boolean sWebViewDisabled;
    private static String sDataDirectorySuffix; // stored here so it can be set without loading WV

    // Error codes for loadWebViewNativeLibraryFromPackage
    public static final int LIBLOAD_SUCCESS = 0;
@@ -112,6 +115,45 @@ public final class WebViewFactory {
        return sWebViewSupported;
    }

    /**
     * @hide
     */
    static void disableWebView() {
        synchronized (sProviderLock) {
            if (sProviderInstance != null) {
                throw new IllegalStateException(
                        "Can't disable WebView: WebView already initialized");
            }
            sWebViewDisabled = true;
        }
    }

    /**
     * @hide
     */
    static void setDataDirectorySuffix(String suffix) {
        synchronized (sProviderLock) {
            if (sProviderInstance != null) {
                throw new IllegalStateException(
                        "Can't set data directory suffix: WebView already initialized");
            }
            if (suffix.indexOf(File.separatorChar) >= 0) {
                throw new IllegalArgumentException("Suffix " + suffix
                                                   + " contains a path separator");
            }
            sDataDirectorySuffix = suffix;
        }
    }

    /**
     * @hide
     */
    static String getDataDirectorySuffix() {
        synchronized (sProviderLock) {
            return sDataDirectorySuffix;
        }
    }

    /**
     * @hide
     */
@@ -204,6 +246,11 @@ public final class WebViewFactory {
                throw new UnsupportedOperationException();
            }

            if (sWebViewDisabled) {
                throw new IllegalStateException(
                        "WebView.disableWebView() was called: WebView is disabled");
            }

            StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()");
            try {