summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authorkristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-27 00:25:22 +0000
committerkristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-27 00:25:22 +0000
commitb9ea96c7442e147bca17e5a26e63d2feced3c7a1 (patch)
treeb44e5607a428a07cbb0ce5a77d87b46b0ef7304a /android_webview
parent987e542432df2c5e6a37636959b1ca1b7818c107 (diff)
downloadchromium_src-b9ea96c7442e147bca17e5a26e63d2feced3c7a1.zip
chromium_src-b9ea96c7442e147bca17e5a26e63d2feced3c7a1.tar.gz
chromium_src-b9ea96c7442e147bca17e5a26e63d2feced3c7a1.tar.bz2
Create java AwBrowserContext
This will allow all the singleton object (geolocation, cookie manager etc) instances to be collected together by their logical association. BUG= Review URL: https://chromiumcodereview.appspot.com/12313055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184788 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java42
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java20
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java15
3 files changed, 74 insertions, 3 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java
new file mode 100644
index 0000000..b860687
--- /dev/null
+++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserContext.java
@@ -0,0 +1,42 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.android_webview;
+
+import android.content.SharedPreferences;
+
+/**
+ * Java side of the Browser Context: contains all the java side objects needed to host one
+ * browing session (i.e. profile).
+ * Note that due to running in single process mode, and limitations on renderer process only
+ * being able to use a single browser context, currently there can only be one AwBrowserContext
+ * instance, so at this point the class mostly exists for conceptual clarity.
+ *
+ * Obtain the default (singleton) instance with AwBrowserProcess.getDefaultBrowserContext().
+ */
+public class AwBrowserContext {
+
+ private SharedPreferences mSharedPreferences;
+
+ private AwGeolocationPermissions mGeolocationPermissions;
+ private AwCookieManager mCookieManager;
+
+ public AwBrowserContext(SharedPreferences sharedPreferences) {
+ mSharedPreferences = sharedPreferences;
+ }
+
+ public AwGeolocationPermissions getGeolocationPermissions() {
+ if (mGeolocationPermissions == null) {
+ mGeolocationPermissions = new AwGeolocationPermissions(mSharedPreferences);
+ }
+ return mGeolocationPermissions;
+ }
+
+ public AwCookieManager getCookieManager() {
+ if (mCookieManager == null) {
+ mCookieManager = new AwCookieManager();
+ }
+ return mCookieManager;
+ }
+} \ No newline at end of file
diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
index 5e027f6..4d6c1ff 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
@@ -5,6 +5,7 @@
package org.chromium.android_webview;
import android.content.Context;
+import android.content.SharedPreferences;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
@@ -24,6 +25,8 @@ public abstract class AwBrowserProcess {
private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "webview";
+ private static AwBrowserContext sDefaultBrowserContext;
+
/**
* Loads the native library, and performs basic static construction of objects needed
* to run webview in this process. Does not create threads; safe to call from zygote.
@@ -35,12 +38,22 @@ public abstract class AwBrowserProcess {
LibraryLoader.loadNow();
}
+ // TODO(joth): remove when downstream is using new version below.
+ @Deprecated
+ public static void start(Context c) {
+ start(c, null);
+ }
+
/**
* Starts the chromium browser process running within this process. Creates threads
* and performs other per-app resource allocations; must not be called from zygote.
* Note: it is up to the caller to ensure this is only called once.
+ * @param context The Android application context
+ * @param defaultContextPreferences SharedPreferences that will be used for the default
+ * browsing context.
*/
- public static void start(final Context context) {
+ public static void start(final Context context,
+ final SharedPreferences defaultContextPreferences) {
// We must post to the UI thread to cover the case that the user
// has invoked Chromium startup by using the (thread-safe)
// CookieManager rather than creating a WebView.
@@ -54,7 +67,12 @@ public abstract class AwBrowserProcess {
} catch (ProcessInitException e) {
throw new RuntimeException("Cannot initialize WebView", e);
}
+ sDefaultBrowserContext = new AwBrowserContext(defaultContextPreferences);
}
});
}
+
+ public static AwBrowserContext getDefaultBrowserContext() {
+ return sDefaultBrowserContext;
+ }
}
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index c327694..99b0251 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -86,6 +86,7 @@ public class AwContents {
}
private int mNativeAwContents;
+ private AwBrowserContext mBrowserContext;
private ViewGroup mContainerView;
private ContentViewCore mContentViewCore;
private AwContentsClient mContentsClient;
@@ -223,14 +224,24 @@ public class AwContents {
}
}
+ // TODO(joth): Delete this when all callers pass browserContext
+ public AwContents(ViewGroup containerView, InternalAccessDelegate internalAccessAdapter,
+ AwContentsClient contentsClient, boolean isAccessFromFileURLsGrantedByDefault) {
+ this(AwBrowserProcess.getDefaultBrowserContext(), containerView, internalAccessAdapter,
+ contentsClient, isAccessFromFileURLsGrantedByDefault);
+ }
+
/**
+ * @param browserContext the browsing context to associate this view contents with.
* @param containerView the view-hierarchy item this object will be bound to.
* @param internalAccessAdapter to access private methods on containerView.
* @param contentsClient will receive API callbacks from this WebView Contents
* @param isAccessFromFileURLsGrantedByDefault passed to ContentViewCore.initialize.
*/
- public AwContents(ViewGroup containerView, InternalAccessDelegate internalAccessAdapter,
- AwContentsClient contentsClient, boolean isAccessFromFileURLsGrantedByDefault) {
+ public AwContents(AwBrowserContext browserContext, ViewGroup containerView,
+ InternalAccessDelegate internalAccessAdapter, AwContentsClient contentsClient,
+ boolean isAccessFromFileURLsGrantedByDefault) {
+ mBrowserContext = browserContext;
mContainerView = containerView;
mInternalAccessAdapter = internalAccessAdapter;
// Note that ContentViewCore must be set up before AwContents, as ContentViewCore