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

Commit d89a30af authored by Kristian Monsen's avatar Kristian Monsen
Browse files

Move getDatabaseDirectory and getCacheDirectory to a new class

The reason for this is that the CookieSyncManager might not be
initialized right after a webview is created since the initialization
is done with a message.

If someone creates a webview and tries to access a cookie right
afterwards that would cause an unintended exception.

This requires a change in external/webkit

Bug 3172863

Change-Id: I4f4f162253e2af09f63ee582bfce9f75ccf4037b
parent 69919bd6
Loading
Loading
Loading
Loading
+1 −25
Original line number Diff line number Diff line
@@ -65,11 +65,6 @@ public final class CookieSyncManager extends WebSyncManager {
    // time when last update happened
    private long mLastUpdate;

    // Used by the Chromium HTTP stack. Everything else in this class is used only by the Android
    // Java HTTP stack.
    private static String sDatabaseDirectory;
    private static String sCacheDirectory;

    private CookieSyncManager(Context context) {
        super(context, "CookieSyncManager");
    }
@@ -93,11 +88,10 @@ public final class CookieSyncManager extends WebSyncManager {
     */
    public static synchronized CookieSyncManager createInstance(
            Context context) {
        JniUtil.setContext(context);
        Context appContext = context.getApplicationContext();
        if (sRef == null) {
            sRef = new CookieSyncManager(appContext);
            sDatabaseDirectory = appContext.getDatabasePath("dummy").getParent();
            sCacheDirectory = appContext.getCacheDir().getAbsolutePath();
        }
        return sRef;
    }
@@ -222,22 +216,4 @@ public final class CookieSyncManager extends WebSyncManager {
                            + "before CookieSyncManager::getInstance()");
        }
    }

    /**
     * Called by JNI. Gets the application's database directory, excluding the trailing slash.
     * @return String The application's database directory
     */
    private static synchronized String getDatabaseDirectory() {
        checkInstanceIsCreated();
        return sDatabaseDirectory;
    }

    /**
     * Called by JNI. Gets the application's cache directory, excluding the trailing slash.
     * @return String The application's cache directory
     */
    private static synchronized String getCacheDirectory() {
        checkInstanceIsCreated();
        return sCacheDirectory;
    }
}
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.webkit;

import android.content.Context;

class JniUtil {
    // Used by the Chromium HTTP stack.
    private static String sDatabaseDirectory;
    private static String sCacheDirectory;

    private static boolean initialized = false;

    private static void checkIntialized() {
        if (!initialized) {
            throw new IllegalStateException("Call CookieSyncManager::createInstance() or create a webview before using this class");
        }
    }

    protected static synchronized void setContext(Context context) {
        if (initialized)
            return;

        Context appContext = context.getApplicationContext();
        sDatabaseDirectory = appContext.getDatabasePath("dummy").getParent();
        sCacheDirectory = appContext.getCacheDir().getAbsolutePath();
        initialized = true;
    }

    /**
     * Called by JNI. Gets the application's database directory, excluding the trailing slash.
     * @return String The application's database directory
     */
    private static synchronized String getDatabaseDirectory() {
        checkIntialized();
        return sDatabaseDirectory;
    }

    /**
     * Called by JNI. Gets the application's cache directory, excluding the trailing slash.
     * @return String The application's cache directory
     */
    private static synchronized String getCacheDirectory() {
        checkIntialized();
        return sCacheDirectory;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -893,6 +893,9 @@ public class WebView extends AbsoluteLayout
            Map<String, Object> javascriptInterfaces, boolean privateBrowsing) {
        super(context, attrs, defStyle);

        // Used by the chrome stack to find application paths
        JniUtil.setContext(context);

        if (AccessibilityManager.getInstance(context).isEnabled()) {
            if (javascriptInterfaces == null) {
                javascriptInterfaces = new HashMap<String, Object>();