WebViewChromiumFactoryProvider.java revision b7f8bdb39f5ddfba3394d5335e728d9bf416f0ca
146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)/*
246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * Copyright (C) 2012 The Android Open Source Project
346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) *
446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License");
546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * you may not use this file except in compliance with the License.
646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * You may obtain a copy of the License at
746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) *
846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) *      http://www.apache.org/licenses/LICENSE-2.0
946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) *
1046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * Unless required by applicable law or agreed to in writing, software
1146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS,
1246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * See the License for the specific language governing permissions and
1446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) * limitations under the License.
1546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles) */
1646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
1746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)package com.android.webview.chromium;
1846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
19b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucciimport android.app.ActivityManager;
2046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.app.ActivityThread;
21b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucciimport android.content.ComponentCallbacks2;
2246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.content.Context;
23009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsenimport android.content.SharedPreferences;
24970a2065df4f96ceaa9bc38d82caea9221dfa4c9Jonathan Dixonimport android.os.Build;
2546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.os.Looper;
2646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.CookieManager;
2746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.GeolocationPermissions;
2846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.WebIconDatabase;
2946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.WebStorage;
3046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.WebView;
3146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.WebViewDatabase;
3246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.WebViewFactoryProvider;
3346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import android.webkit.WebViewProvider;
3446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
35aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsenimport org.chromium.android_webview.AwBrowserContext;
36f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixonimport org.chromium.android_webview.AwBrowserProcess;
37a2b0d0b4d6d1ff22fbb1329e358e1cc0a112aab3Jonathan Dixonimport org.chromium.android_webview.AwContents;
38d5f17bbd8703a56ac084a64b1ce2f673f67bd72dKristian Monsenimport org.chromium.android_webview.AwCookieManager;
3909e718bac5900c84b8402b774d306dca7f7fdf09Selim Gurunimport org.chromium.android_webview.AwFormDatabase;
40009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsenimport org.chromium.android_webview.AwGeolocationPermissions;
415d20093562806fbce9cc0d3eb4a411ed6c5ce1c0Bo Liuimport org.chromium.android_webview.AwQuotaManagerBridge;
42d6b56ff89338d0b3a6ba0cb413b1fe559d6284e0Mikhail Naganovimport org.chromium.android_webview.AwSettings;
43b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucciimport org.chromium.base.MemoryPressureListener;
4446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import org.chromium.base.PathService;
457b77b2fb0f7148bc31e23cabadb234231699ff93Jonathan Dixonimport org.chromium.base.ThreadUtils;
467b77b2fb0f7148bc31e23cabadb234231699ff93Jonathan Dixonimport org.chromium.content.app.LibraryLoader;
4746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import org.chromium.content.browser.ContentViewStatics;
4846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)import org.chromium.content.browser.ResourceExtractor;
49970a2065df4f96ceaa9bc38d82caea9221dfa4c9Jonathan Dixonimport org.chromium.content.common.CommandLine;
50970a2065df4f96ceaa9bc38d82caea9221dfa4c9Jonathan Dixonimport org.chromium.content.common.ProcessInitException;
5146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
5246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
5346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
54009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsen    private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs";
557962d3fa1b66ed25aba03a2d48f6c47528d7d95cPrimiano Tucci    private static final String COMMAND_LINE_FILE = "/data/local/tmp/webview-command-line";
56009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsen
5772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon    // Guards accees to the other members, and is notifyAll() signalled on the UI thread
5872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon    // when the chromium process has been started.
5972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon    private final Object mLock = new Object();
6072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
6146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    // Initialization guarded by mLock.
62aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen    private AwBrowserContext mBrowserContext;
63aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon    private Statics mStaticMethods;
64aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon    private GeolocationPermissionsAdapter mGeolocationPermissions;
65aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon    private CookieManagerAdapter mCookieManager;
66aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon    private WebIconDatabaseAdapter mWebIconDatabase;
67aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon    private WebStorageAdapter mWebStorage;
68aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon    private WebViewDatabaseAdapter mWebViewDatabase;
6946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
709aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon    // Read/write protected by mLock.
719aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon    private boolean mStarted;
72f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon
7311f7c1b02e49a6a8eaec26111f08edec45feb01aTorne (Richard Coles)    public WebViewChromiumFactoryProvider() {
74f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon        // Load chromium library.
75f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon        AwBrowserProcess.loadLibrary();
76a2b0d0b4d6d1ff22fbb1329e358e1cc0a112aab3Jonathan Dixon        // Load glue-layer support library.
77a2b0d0b4d6d1ff22fbb1329e358e1cc0a112aab3Jonathan Dixon        System.loadLibrary("webviewchromium_plat_support");
78f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon    }
79f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon
80f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon    private void initPlatSupportLibrary() {
819aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon        DrawGLFunctor.setChromiumAwDrawGLFunction(AwContents.getAwDrawGLFunction());
829aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon        AwContents.setAwDrawSWFunctionTable(GraphicsUtils.getDrawSWFunctionTable());
83c5cde8c18df853e11d1ec528508fd0fe2e742d5cKaan Baloglu        AwContents.setAwDrawGLFunctionTable(GraphicsUtils.getDrawGLFunctionTable());
84a2b0d0b4d6d1ff22fbb1329e358e1cc0a112aab3Jonathan Dixon    }
85a2b0d0b4d6d1ff22fbb1329e358e1cc0a112aab3Jonathan Dixon
86f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon    private void ensureChromiumStartedLocked() {
8746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        assert Thread.holdsLock(mLock);
8846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
8972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        if (mStarted) {  // Early-out for the common case.
9072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            return;
9172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        }
9272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
9372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        if (ThreadUtils.runningOnUiThread()) {
9472db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            startChromiumLocked();
959aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon            return;
969aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon        }
973053d8bc3be48b0cbc6f33e1975c03a10ac303a5Jonathan Dixon
9872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // We must post to the UI thread to cover the case that the user has invoked Chromium
9972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // startup by using the (thread-safe) CookieManager rather than creating a WebView.
10072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        ThreadUtils.postOnUiThread(new Runnable() {
1017b77b2fb0f7148bc31e23cabadb234231699ff93Jonathan Dixon            @Override
1027b77b2fb0f7148bc31e23cabadb234231699ff93Jonathan Dixon            public void run() {
10372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                synchronized (mLock) {
10472db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                    startChromiumLocked();
105970a2065df4f96ceaa9bc38d82caea9221dfa4c9Jonathan Dixon                }
10672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            }
10772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        });
10872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        while (!mStarted) {
10972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            try {
11072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                // Important: wait() releases |mLock| so the UI thread can take it :-)
11172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                mLock.wait();
11272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            } catch (InterruptedException e) {
11372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                // Keep trying... eventually the UI thread will process the task we sent it.
11472db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            }
11572db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        }
11672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon    }
117970a2065df4f96ceaa9bc38d82caea9221dfa4c9Jonathan Dixon
11872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon    private void startChromiumLocked() {
11972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        assert Thread.holdsLock(mLock) && ThreadUtils.runningOnUiThread();
1201e5325bde6fb074ce556a4e2833114d890ed21f3Jonathan Dixon
12172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // The post-condition of this method is everything is ready, so notify now to cover all
12272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // return paths. (Other threads will not wake-up until we release |mLock|, whatever).
12372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        mLock.notifyAll();
124970a2065df4f96ceaa9bc38d82caea9221dfa4c9Jonathan Dixon
12572db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        if (mStarted) {
12672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            return;
12772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        }
1289aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon
12972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        if (Build.IS_DEBUGGABLE) {
13072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            CommandLine.initFromFile(COMMAND_LINE_FILE);
13172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        } else {
13272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            CommandLine.init(null);
13372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        }
1347b77b2fb0f7148bc31e23cabadb234231699ff93Jonathan Dixon
13572db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        CommandLine cl = CommandLine.getInstance();
13672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // TODO: currently in a relase build the DCHECKs only log. We either need to insall
13772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // a report handler with SetLogReportHandler to make them assert, or else compile
13872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // them out of the build altogether (b/8284203). Either way, so long they're
13972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // compiled in, we may as unconditionally enable them here.
14072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        cl.appendSwitch("enable-dcheck");
14172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
14272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // TODO: Remove when GL is supported by default in the upstream code.
14372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        if (!cl.hasSwitch("disable-webview-gl-mode")) {
14472db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            cl.appendSwitch("testing-webview-gl-mode");
14572db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        }
14672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
14772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // We don't need to extract any paks because for WebView, they are
14872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // in the system image.
14972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        ResourceExtractor.setMandatoryPaksToExtract("");
15072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
15172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        try {
15272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            LibraryLoader.ensureInitialized();
15372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        } catch(ProcessInitException e) {
15472db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon            throw new RuntimeException("Error initializing WebView library", e);
15572db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        }
15672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
15772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        PathService.override(PathService.DIR_MODULE, "/system/lib/");
15872db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // TODO: DIR_RESOURCE_PAKS_ANDROID needs to live somewhere sensible,
15972db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // inlined here for simplicity setting up the HTMLViewer demo. Unfortunately
16072db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // it can't go into base.PathService, as the native constant it refers to
16172db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        // lives in the ui/ layer. See ui/base/ui_base_paths.h
16272db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        final int DIR_RESOURCE_PAKS_ANDROID = 3003;
16372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        PathService.override(DIR_RESOURCE_PAKS_ANDROID,
16472db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                "/system/framework/webview/paks");
16572db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon
16672db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        AwBrowserProcess.start(ActivityThread.currentApplication());
16772db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon        initPlatSupportLibrary();
1689aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon        mStarted = true;
16946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
17046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
17146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
17246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public Statics getStatics() {
17346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        synchronized (mLock) {
17446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)            if (mStaticMethods == null) {
1759aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon                // TODO: Optimization potential: most these methods only need the native library
176f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon                // loaded and initialized, not the entire browser process started.
177f3e3e4e6b6c5798f435c1d14379edeb479e3b25dJonathan Dixon                // See also http://b/7009882
1789aa44b4e29be9f4b271edb3f4d438d806d4cc176Jonathan Dixon                ensureChromiumStartedLocked();
17946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                mStaticMethods = new WebViewFactoryProvider.Statics() {
18046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    @Override
18146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    public String findAddress(String addr) {
18246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                        return ContentViewStatics.findAddress(addr);
18346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    }
18446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
18546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    @Override
18646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    public void setPlatformNotificationsEnabled(boolean enable) {
18746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                        // noop
18846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    }
18946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
190f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon                    @Override
19146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    public String getDefaultUserAgent(Context context) {
192d6b56ff89338d0b3a6ba0cb413b1fe559d6284e0Mikhail Naganov                        return AwSettings.getDefaultUserAgent();
19346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                    }
194b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci
195b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                    @Override
196b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                    public void freeMemoryForTests() {
197b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                        if (ActivityManager.isRunningInTestHarness()) {
198b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                            MemoryPressureListener.simulateMemoryPressureSignal(
199b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                                    ComponentCallbacks2.TRIM_MEMORY_COMPLETE);
200b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                        }
201b7f8bdb39f5ddfba3394d5335e728d9bf416f0caPrimiano Tucci                    }
20246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)                };
20346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)            }
20446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        }
20546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        return mStaticMethods;
20646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
20746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
20846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
20946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) {
21046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        assert Looper.myLooper() == Looper.getMainLooper();
211aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        AwBrowserContext browserContext;
21246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        synchronized (mLock) {
213f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon            ensureChromiumStartedLocked();
21446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)            ResourceProvider.registerResources(webView.getContext());
215aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen            browserContext = getBrowserContextLocked();
21646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        }
2178166110add693878f19ab0551c630a22caa2e30cKristian Monsen        // Make sure GeolocationPermissions is created before creating a webview
2188166110add693878f19ab0551c630a22caa2e30cKristian Monsen        getGeolocationPermissions();
219aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        return new WebViewChromium(webView, privateAccess, browserContext);
22046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
22146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
22246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
22346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public GeolocationPermissions getGeolocationPermissions() {
224009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsen        synchronized (mLock) {
225aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            if (mGeolocationPermissions == null) {
226f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon                ensureChromiumStartedLocked();
22750a184c1e058bc62f659fb80e09e7507ef13d6c9Jonathan Dixon                mGeolocationPermissions = new GeolocationPermissionsAdapter(
228aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen                        getBrowserContextLocked().getGeolocationPermissions());
229009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsen            }
230009ed27511c4606dcd16b352489b2d3f70b4b513Kristian Monsen        }
231ff2704e614eb490baea0acb5c8ab22e061033694Kristian Monsen        return mGeolocationPermissions;
23246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
23346f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
234aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen    private AwBrowserContext getBrowserContextLocked() {
235aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        assert Thread.holdsLock(mLock);
236aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        assert mStarted;
237aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        if (mBrowserContext == null) {
238aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen            mBrowserContext = new AwBrowserContext(
239aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen                    ActivityThread.currentApplication().getSharedPreferences(
240aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen                            CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE));
241aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        }
242aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen        return mBrowserContext;
243aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen    }
244aa8b39f3e3f208586f3750d7278f1239a09ebd32Kristian Monsen
24546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
24646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public CookieManager getCookieManager() {
24746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        synchronized (mLock) {
248aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            if (mCookieManager == null) {
249f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon                ensureChromiumStartedLocked();
250d5f17bbd8703a56ac084a64b1ce2f673f67bd72dKristian Monsen                mCookieManager = new CookieManagerAdapter(new AwCookieManager());
25146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)            }
25246f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        }
253aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        return mCookieManager;
25446f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
25546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
25646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
25746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public WebIconDatabase getWebIconDatabase() {
258aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        synchronized (mLock) {
259aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            if (mWebIconDatabase == null) {
260f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon                ensureChromiumStartedLocked();
261aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon                mWebIconDatabase = new WebIconDatabaseAdapter();
262aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            }
263aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        }
264aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        return mWebIconDatabase;
26546f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
26646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
26746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
26846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public WebStorage getWebStorage() {
269aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        synchronized (mLock) {
270aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            if (mWebStorage == null) {
271f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon                ensureChromiumStartedLocked();
2725d20093562806fbce9cc0d3eb4a411ed6c5ce1c0Bo Liu                mWebStorage = new WebStorageAdapter(AwQuotaManagerBridge.getInstance());
273aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            }
274aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        }
275aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        return mWebStorage;
27646f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
27746f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)
27846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    @Override
27946f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    public WebViewDatabase getWebViewDatabase(Context context) {
28046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        synchronized (mLock) {
281aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            if (mWebViewDatabase == null) {
282f0f355514e4420755c15491fe3b21a2eeaa42654Jonathan Dixon                ensureChromiumStartedLocked();
28372db47d0508d6733072c38ee44883ecfaf612ca6Jonathan Dixon                AwBrowserContext browserContext = getBrowserContextLocked();
284a6f2939f98aeaf67533a7fd3f5c999f207451f1cSelim Gurun                mWebViewDatabase = new WebViewDatabaseAdapter(
285a6f2939f98aeaf67533a7fd3f5c999f207451f1cSelim Gurun                        browserContext.getFormDatabase(),
286a6f2939f98aeaf67533a7fd3f5c999f207451f1cSelim Gurun                        browserContext.getHttpAuthDatabase(context));
287aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon            }
28846f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)        }
289aadb04e4198e1f0dce390e9434cb189603b8e713Jonathan Dixon        return mWebViewDatabase;
29046f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)    }
29146f104289826e85ba76a1a2139d7ecc7daca07b1Torne (Richard Coles)}
292