| 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.android_webview; |
| 6 | |
| 7 | import android.content.Context; |
| 8 | import android.content.SharedPreferences; |
| 9 | |
| 10 | import org.chromium.content.browser.ContentViewStatics; |
| 11 | |
| 12 | /** |
| 13 | * Java side of the Browser Context: contains all the java side objects needed to host one |
| 14 | * browing session (i.e. profile). |
| 15 | * Note that due to running in single process mode, and limitations on renderer process only |
| 16 | * being able to use a single browser context, currently there can only be one AwBrowserContext |
| 17 | * instance, so at this point the class mostly exists for conceptual clarity. |
| 18 | * |
| 19 | * Obtain the default (singleton) instance with AwBrowserProcess.getDefaultBrowserContext(). |
| 20 | */ |
| 21 | public class AwBrowserContext { |
| 22 | |
| 23 | private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db"; |
| 24 | |
| 25 | private SharedPreferences mSharedPreferences; |
| 26 | |
| 27 | private AwGeolocationPermissions mGeolocationPermissions; |
| 28 | private AwCookieManager mCookieManager; |
| 29 | private AwFormDatabase mFormDatabase; |
| 30 | private HttpAuthDatabase mHttpAuthDatabase; |
| 31 | |
| 32 | public AwBrowserContext(SharedPreferences sharedPreferences) { |
| 33 | mSharedPreferences = sharedPreferences; |
| 34 | } |
| 35 | |
| 36 | public AwGeolocationPermissions getGeolocationPermissions() { |
| 37 | if (mGeolocationPermissions == null) { |
| 38 | mGeolocationPermissions = new AwGeolocationPermissions(mSharedPreferences); |
| 39 | } |
| 40 | return mGeolocationPermissions; |
| 41 | } |
| 42 | |
| 43 | public AwCookieManager getCookieManager() { |
| 44 | if (mCookieManager == null) { |
| 45 | mCookieManager = new AwCookieManager(); |
| 46 | } |
| 47 | return mCookieManager; |
| 48 | } |
| 49 | |
| 50 | public AwFormDatabase getFormDatabase() { |
| 51 | if (mFormDatabase == null) { |
| 52 | mFormDatabase = new AwFormDatabase(); |
| 53 | } |
| 54 | return mFormDatabase; |
| 55 | } |
| 56 | |
| 57 | public HttpAuthDatabase getHttpAuthDatabase(Context context) { |
| 58 | if (mHttpAuthDatabase == null) { |
| 59 | mHttpAuthDatabase = new HttpAuthDatabase(context, HTTP_AUTH_DATABASE_FILE); |
| 60 | }; |
| 61 | return mHttpAuthDatabase; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @see android.webkit.WebView#pauseTimers() |
| 66 | */ |
| 67 | public void pauseTimers() { |
| 68 | ContentViewStatics.setWebKitSharedTimersSuspended(true); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @see android.webkit.WebView#resumeTimers() |
| 73 | */ |
| 74 | public void resumeTimers() { |
| 75 | ContentViewStatics.setWebKitSharedTimersSuspended(false); |
| 76 | } |
| 77 | } |