diff options
author | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 20:38:52 +0000 |
---|---|---|
committer | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 20:38:52 +0000 |
commit | 6a7980156cfc9c165fa7d2169d34015bb3a5b2ac (patch) | |
tree | aea39537c6db55aa1c99891f3acdc0ce908ed4f6 | |
parent | 61685df6664fff12daff135744a9c6d851fd23e1 (diff) | |
download | chromium_src-6a7980156cfc9c165fa7d2169d34015bb3a5b2ac.zip chromium_src-6a7980156cfc9c165fa7d2169d34015bb3a5b2ac.tar.gz chromium_src-6a7980156cfc9c165fa7d2169d34015bb3a5b2ac.tar.bz2 |
Upstream the proper ContentView constructor for ContentShell.
Passes the native web contents from the shell view to the content shell down
to the native content shell implemenation.
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10565019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143041 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 64 insertions, 23 deletions
diff --git a/content/browser/android/content_view_impl.cc b/content/browser/android/content_view_impl.cc index 92eefe9..be0a506 100644 --- a/content/browser/android/content_view_impl.cc +++ b/content/browser/android/content_view_impl.cc @@ -10,6 +10,7 @@ // (below), we won't need the next two headers. #include "base/basictypes.h" #include "base/logging.h" +#include "content/public/browser/web_contents.h" // TODO(jrg): content_view_jni.h is generated by // base/android/jni_generator/jni_generator.py from ContentView.java. @@ -37,8 +38,9 @@ namespace content { // ---------------------------------------------------------------------------- // Implementation of static ContentView public interfaces -ContentView* ContentView::Create(JNIEnv* env, jobject obj) { - return new ContentViewImpl(env, obj); +ContentView* ContentView::Create(JNIEnv* env, jobject obj, + WebContents* web_contents) { + return new ContentViewImpl(env, obj, web_contents); } ContentView* ContentView::GetNativeContentView(JNIEnv* env, jobject obj) { @@ -48,7 +50,11 @@ ContentView* ContentView::GetNativeContentView(JNIEnv* env, jobject obj) { // ---------------------------------------------------------------------------- -ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj) { +ContentViewImpl::ContentViewImpl(JNIEnv* env, jobject obj, + WebContents* web_contents) + : web_contents_(web_contents) { + DCHECK(web_contents) << + "A ContentViewImpl should be created with a valid WebContents."; } ContentViewImpl::~ContentViewImpl() { @@ -69,10 +75,10 @@ void ContentViewImpl::Observe(int type, // ---------------------------------------------------------------------------- // This is called for each ContentView. -// TODO(jrg): add extra args (e.g. hardware_accelerated, -// native_web_contents) once other pieces are upstreamed. -static jint Init(JNIEnv* env, jobject obj) { - ContentView* view = ContentView::Create(env, obj); +static jint Init(JNIEnv* env, jobject obj, + jint native_web_contents) { + ContentView* view = ContentView::Create( + env, obj, reinterpret_cast<WebContents*>(native_web_contents)); return reinterpret_cast<jint>(view); } diff --git a/content/browser/android/content_view_impl.h b/content/browser/android/content_view_impl.h index 330d584..5550434 100644 --- a/content/browser/android/content_view_impl.h +++ b/content/browser/android/content_view_impl.h @@ -20,7 +20,8 @@ class ContentViewImpl : public ContentView, public NotificationObserver { public: ContentViewImpl(JNIEnv* env, - jobject obj); + jobject obj, + WebContents* web_contents); virtual void Destroy(JNIEnv* env, jobject obj); private: @@ -37,6 +38,11 @@ class ContentViewImpl : public ContentView, // -------------------------------------------------------------------------- // Other private methods and data // -------------------------------------------------------------------------- + + // Reference to the current WebContents used to determine how and what to + // display in the ContentView. + WebContents* web_contents_; + DISALLOW_COPY_AND_ASSIGN(ContentViewImpl); }; diff --git a/content/public/android/java/org/chromium/content/browser/ContentView.java b/content/public/android/java/org/chromium/content/browser/ContentView.java index b9a5754..98e6a3a 100644 --- a/content/public/android/java/org/chromium/content/browser/ContentView.java +++ b/content/public/android/java/org/chromium/content/browser/ContentView.java @@ -5,20 +5,33 @@ package org.chromium.content.browser; import android.content.Context; +import android.util.AttributeSet; import android.util.Log; import android.webkit.DownloadListener; import android.widget.FrameLayout; +import org.chromium.base.WeakContext; import org.chromium.content.browser.AndroidBrowserProcess; public class ContentView extends FrameLayout { private static final String TAG = "ContentView"; + // Personality of the ContentView. + private int mPersonality; + // Used when ContentView implements a standalone View. + public static final int PERSONALITY_VIEW = 0; + // Used for Chrome. + public static final int PERSONALITY_CHROME = 1; + /** * Automatically decide the number of renderer processes to use based on device memory class. * */ - public static final int MAX_RENDERERS_AUTOMATIC = -1; - + public static final int MAX_RENDERERS_AUTOMATIC = AndroidBrowserProcess.MAX_RENDERERS_AUTOMATIC; + /** + * Use single-process mode that runs the renderer on a separate thread in the main application. + */ + public static final int MAX_RENDERERS_SINGLE_PROCESS = + AndroidBrowserProcess.MAX_RENDERERS_SINGLE_PROCESS; // content_view_client.cc depends on ContentView.java holding a ref to the current client // instance since the native side only holds a weak pointer to the client. We chose this @@ -100,14 +113,26 @@ public class ContentView extends FrameLayout { // TODO(tedchoc): Implement. } - public ContentView(Context context) { - super(context, null); - initialize(context); + public ContentView(Context context, int nativeWebContents, int personality) { + this(context, nativeWebContents, null, android.R.attr.webViewStyle, personality); + } + + private ContentView(Context context, int nativeWebContents, AttributeSet attrs, int defStyle, + int personality) { + super(context, attrs, defStyle); + + WeakContext.initializeWeakContext(context); + // By default, ContentView will initialize single process mode. The call to + // initContentViewProcess below is ignored if either the ContentView host called + // enableMultiProcess() or the platform browser called initChromiumBrowserProcess(). + AndroidBrowserProcess.initContentViewProcess(context, MAX_RENDERERS_SINGLE_PROCESS); + + initialize(context, nativeWebContents, personality); } // TODO(jrg): incomplete; upstream the rest of this method. - private void initialize(Context context) { - mNativeContentView = nativeInit(); + private void initialize(Context context, int nativeWebContents, int personality) { + mNativeContentView = nativeInit(nativeWebContents); Log.i(TAG, "mNativeContentView=0x"+ Integer.toHexString(mNativeContentView)); } @@ -221,12 +246,11 @@ public class ContentView extends FrameLayout { * Should be called with a valid native WebContents. * If nativeInitProcess is never called, the first time this method is called, nativeInitProcess * will be called implicitly with the default settings. - * @param hardwareAccelerated if true, the View uses hardware accelerated rendering. - * @param nativeWebContents the ContentView does not create a new native WebContents and uses - * the provided one. + * @param webContentsPtr the ContentView does not create a new native WebContents and uses + * the provided one. * @return a native pointer to the native ContentView object. */ - private native int nativeInit(); + private native int nativeInit(int webContentsPtr); private native void nativeDestroy(int nativeContentView); diff --git a/content/public/browser/android/content_view.h b/content/public/browser/android/content_view.h index fccfc35..4001476 100644 --- a/content/public/browser/android/content_view.h +++ b/content/public/browser/android/content_view.h @@ -9,6 +9,9 @@ #include <jni.h> namespace content { + +class WebContents; + // Native side of the ContentView.java, the primary FrameLayout of // Chromium on Android. This is a public interface used by native // code outside of the content module. @@ -27,7 +30,8 @@ class ContentView { public: virtual void Destroy(JNIEnv* env, jobject obj) = 0; - static ContentView* Create(JNIEnv* env, jobject obj); + static ContentView* Create(JNIEnv* env, jobject obj, + WebContents* web_contents); static ContentView* GetNativeContentView(JNIEnv* env, jobject obj); protected: diff --git a/content/shell/android/java/org/chromium/content_shell/ShellView.java b/content/shell/android/java/org/chromium/content_shell/ShellView.java index b4059b0..01ffab0 100644 --- a/content/shell/android/java/org/chromium/content_shell/ShellView.java +++ b/content/shell/android/java/org/chromium/content_shell/ShellView.java @@ -140,13 +140,13 @@ public class ShellView extends LinearLayout { @SuppressWarnings("unused") @CalledByNative private void initFromNativeTabContents(int nativeTabContents) { - // TODO(tedchoc): Pass along native tab contents. - mContentView = new ContentView(getContext()); + mContentView = new ContentView( + getContext(), nativeTabContents, ContentView.PERSONALITY_CHROME); + mContentView.setContentViewClient(new ShellContentViewClient()); ((FrameLayout) findViewById(R.id.contentview_holder)).addView(mContentView, new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); - mContentView.setContentViewClient(new ShellContentViewClient()); } /** diff --git a/content/shell/android/shell_library_loader.cc b/content/shell/android/shell_library_loader.cc index e520073..22ed8d9 100644 --- a/content/shell/android/shell_library_loader.cc +++ b/content/shell/android/shell_library_loader.cc @@ -9,6 +9,7 @@ #include "base/android/jni_registrar.h" #include "content/public/app/android_library_loader_hooks.h" #include "content/public/app/content_main.h" +#include "content/shell/shell_main_delegate.h" #include "content/shell/android/shell_manager.h" #include "content/shell/android/shell_view.h" #include "content/shell/shell_main_delegate.h" |