diff options
-rw-r--r-- | content/content_shell.gypi | 15 | ||||
-rw-r--r-- | content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java | 12 | ||||
-rw-r--r-- | content/shell/android/java/src/org/chromium/content_shell/Shell.java (renamed from content/shell/android/java/src/org/chromium/content_shell/ShellView.java) | 68 | ||||
-rw-r--r-- | content/shell/android/java/src/org/chromium/content_shell/ShellManager.java | 14 | ||||
-rw-r--r-- | content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java | 2 | ||||
-rw-r--r-- | content/shell/android/res/layout/shell_view.xml | 4 | ||||
-rw-r--r-- | content/shell/android/shell_library_loader.cc | 5 | ||||
-rw-r--r-- | content/shell/android/shell_manager.cc | 7 | ||||
-rw-r--r-- | content/shell/android/shell_manager.h | 7 | ||||
-rw-r--r-- | content/shell/android/shell_view.cc | 35 | ||||
-rw-r--r-- | content/shell/android/shell_view.h | 40 | ||||
-rw-r--r-- | content/shell/shell.h | 10 | ||||
-rw-r--r-- | content/shell/shell_android.cc | 28 |
13 files changed, 92 insertions, 155 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 841ab57..7fd1c2f 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -138,7 +138,14 @@ # this combination is not yet supported on Android. '../webkit/support/webkit_support.gyp:webkit_support', ], - }], # OS!="android" + }, { # else: OS=="android" + 'dependencies': [ + 'content_shell_jni_headers', + ], + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)/content/shell', + ], + }], # OS=="android" ['use_aura==1', { 'sources/': [ ['exclude', 'shell/shell_gtk.cc'], @@ -499,11 +506,11 @@ 'variables': { 'java_sources': [ 'shell/android/java/src/org/chromium/content_shell/ShellManager.java', - 'shell/android/java/src/org/chromium/content_shell/ShellView.java', + 'shell/android/java/src/org/chromium/content_shell/Shell.java', ], 'jni_headers': [ '<(SHARED_INTERMEDIATE_DIR)/content/shell/jni/shell_manager_jni.h', - '<(SHARED_INTERMEDIATE_DIR)/content/shell/jni/shell_view_jni.h', + '<(SHARED_INTERMEDIATE_DIR)/content/shell/jni/shell_jni.h', ], }, 'includes': [ '../build/jni_generator.gypi' ], @@ -528,8 +535,6 @@ 'shell/android/shell_library_loader.h', 'shell/android/shell_manager.cc', 'shell/android/shell_manager.h', - 'shell/android/shell_view.cc', - 'shell/android/shell_view.h', ], 'sources!': [ 'shell/shell_main.cc', diff --git a/content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java b/content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java index 96ae2b5..7737b65 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java +++ b/content/shell/android/java/src/org/chromium/content_shell/ContentShellActivity.java @@ -35,7 +35,7 @@ public class ContentShellActivity extends Activity { String startupUrl = getUrlFromIntent(getIntent()); if (!TextUtils.isEmpty(startupUrl)) { CommandLine.getInstance().appendSwitchesAndArguments( - new String[] {ShellView.sanitizeUrl(startupUrl)}); + new String[] {Shell.sanitizeUrl(startupUrl)}); } waitForDebuggerIfNeeded(); @@ -59,7 +59,7 @@ public class ContentShellActivity extends Activity { public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_BACK) return super.onKeyUp(keyCode, event); - ShellView activeView = getActiveShellView(); + Shell activeView = getActiveShell(); if (activeView != null && activeView.getContentView().canGoBack()) { activeView.getContentView().goBack(); return true; @@ -72,7 +72,7 @@ public class ContentShellActivity extends Activity { protected void onNewIntent(Intent intent) { String url = getUrlFromIntent(intent); if (!TextUtils.isEmpty(url)) { - ShellView activeView = getActiveShellView(); + Shell activeView = getActiveShell(); if (activeView != null) { activeView.loadUrl(url); } @@ -92,10 +92,10 @@ public class ContentShellActivity extends Activity { } /** - * @return The currently visible {@link ShellView} or null if one is not showing. + * @return The currently visible {@link Shell} or null if one is not showing. */ - public ShellView getActiveShellView() { - return mShellManager != null ? mShellManager.getActiveShellView() : null; + public Shell getActiveShell() { + return mShellManager != null ? mShellManager.getActiveShell() : null; } private void initializeContentViewResources() { diff --git a/content/shell/android/java/src/org/chromium/content_shell/ShellView.java b/content/shell/android/java/src/org/chromium/content_shell/Shell.java index 27fd321..3ffdeee 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ShellView.java +++ b/content/shell/android/java/src/org/chromium/content_shell/Shell.java @@ -22,17 +22,22 @@ import android.widget.TextView.OnEditorActionListener; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.content.browser.ContentView; -import org.chromium.content.browser.ContentViewClient; /** * Container for the various UI components that make up a shell window. */ @JNINamespace("content") -public class ShellView extends LinearLayout { +public class Shell extends LinearLayout { private static final long COMPLETED_PROGRESS_TIMEOUT_MS = 200; - private int mNativeShellView; + private Runnable mClearProgressRunnable = new Runnable() { + @Override + public void run() { + mProgressDrawable.setLevel(0); + } + }; + // TODO(jrg): a mContentView.destroy() call is needed, both upstream and downstream. private ContentView mContentView; private EditText mUrlTextView; @@ -44,10 +49,8 @@ public class ShellView extends LinearLayout { /** * Constructor for inflating via XML. */ - public ShellView(Context context, AttributeSet attrs) { + public Shell(Context context, AttributeSet attrs) { super(context, attrs); - - mNativeShellView = nativeInit(); } @Override @@ -60,13 +63,6 @@ public class ShellView extends LinearLayout { initializeNavigationButtons(); } - /** - * @return the native shell view pointer. - */ - protected int getNativeShellView() { - return mNativeShellView; - } - private void initilizeUrlField() { mUrlTextView = (EditText) findViewById(R.id.url); mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() { @@ -142,6 +138,20 @@ public class ShellView extends LinearLayout { }); } + @SuppressWarnings("unused") + @CalledByNative + private void onUpdateUrl(String url) { + mUrlTextView.setText(url); + } + + @SuppressWarnings("unused") + @CalledByNative + private void onLoadProgressChanged(double progress) { + removeCallbacks(mClearProgressRunnable); + mProgressDrawable.setLevel((int) (10000.0 * progress)); + if (progress == 1.0) postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS); + } + /** * Initializes the ContentView based on the native tab contents pointer passed in. * @param nativeTabContents The pointer to the native tab contents object. @@ -151,7 +161,6 @@ public class ShellView extends LinearLayout { private void initFromNativeTabContents(int nativeTabContents) { 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, @@ -175,35 +184,4 @@ public class ShellView extends LinearLayout { imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); } } - - private native int nativeInit(); - - private class ShellContentViewClient extends ContentViewClient { - private Runnable mClearProgressRunnable = new Runnable() { - @Override - public void run() { - mProgressDrawable.setLevel(0); - } - }; - - @Override - public void onUpdateUrl(String url) { - super.onUpdateUrl(url); - mUrlTextView.setText(url); - } - - @Override - public void onLoadProgressChanged(final double progress) { - super.onLoadProgressChanged(progress); - removeCallbacks(mClearProgressRunnable); - mProgressDrawable.setLevel((int) (10000.0 * progress)); - if (progress == 1.0) postDelayed(mClearProgressRunnable, COMPLETED_PROGRESS_TIMEOUT_MS); - } - - @Override - public void onTabCrash(int pid) { - super.onTabCrash(pid); - mProgressDrawable.setLevel(0); - } - } } diff --git a/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java b/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java index 611da85..082e99e 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java +++ b/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java @@ -18,7 +18,7 @@ import org.chromium.base.JNINamespace; @JNINamespace("content") public class ShellManager extends FrameLayout { - private ShellView mActiveShellView; + private Shell mActiveShell; /** * Constructor for inflating via XML. @@ -31,23 +31,23 @@ public class ShellManager extends FrameLayout { /** * @return The currently visible shell view or null if one is not showing. */ - protected ShellView getActiveShellView() { - return mActiveShellView; + protected Shell getActiveShell() { + return mActiveShell; } @SuppressWarnings("unused") @CalledByNative - private int createShell() { + private Object createShell() { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - ShellView shellView = (ShellView) inflater.inflate(R.layout.shell_view, null); + Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); removeAllViews(); addView(shellView, new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); - mActiveShellView = shellView; + mActiveShell = shellView; - return shellView.getNativeShellView(); + return shellView; } private static native void nativeInit(Object shellManagerInstance); diff --git a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java index 370fd2b..f8b960c 100644 --- a/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java +++ b/content/shell/android/javatests/src/org/chromium/content_shell/ContentShellUrlTest.java @@ -23,6 +23,6 @@ public class ContentShellUrlTest extends ContentShellTestBase { assertNotNull(activity); // Make sure that the URL is set as expected. - assertEquals(URL, activity.getActiveShellView().getContentView().getUrl()); + assertEquals(URL, activity.getActiveShell().getContentView().getUrl()); } } diff --git a/content/shell/android/res/layout/shell_view.xml b/content/shell/android/res/layout/shell_view.xml index 05dca52..d6c15d6 100644 --- a/content/shell/android/res/layout/shell_view.xml +++ b/content/shell/android/res/layout/shell_view.xml @@ -6,7 +6,7 @@ found in the LICENSE file. --> -<org.chromium.content_shell.ShellView +<org.chromium.content_shell.Shell xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="match_parent" @@ -45,4 +45,4 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> -</org.chromium.content_shell.ShellView> +</org.chromium.content_shell.Shell> diff --git a/content/shell/android/shell_library_loader.cc b/content/shell/android/shell_library_loader.cc index 22ed8d9..87aa4a3 100644 --- a/content/shell/android/shell_library_loader.cc +++ b/content/shell/android/shell_library_loader.cc @@ -9,14 +9,13 @@ #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.h" #include "content/shell/shell_main_delegate.h" static base::android::RegistrationMethod kRegistrationMethods[] = { + { "Shell", content::Shell::Register }, { "ShellManager", content::RegisterShellManager }, - { "ShellView", content::ShellView::Register }, }; // This is called by the VM when the shared library is first loaded. diff --git a/content/shell/android/shell_manager.cc b/content/shell/android/shell_manager.cc index 77a7aec..18c1223 100644 --- a/content/shell/android/shell_manager.cc +++ b/content/shell/android/shell_manager.cc @@ -7,7 +7,6 @@ #include "base/android/jni_android.h" #include "base/android/scoped_java_ref.h" #include "base/lazy_instance.h" -#include "content/shell/android/shell_view.h" #include "jni/shell_manager_jni.h" using base::android::ScopedJavaLocalRef; @@ -17,10 +16,10 @@ base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> > namespace content { -ShellView* CreateShellView() { +jobject CreateShellView() { JNIEnv* env = base::android::AttachCurrentThread(); - return reinterpret_cast<ShellView*>(Java_ShellManager_createShell( - env, g_content_shell_manager.Get().obj())); + return Java_ShellManager_createShell( + env, g_content_shell_manager.Get().obj()).Release(); } // Register native methods diff --git a/content/shell/android/shell_manager.h b/content/shell/android/shell_manager.h index 4fa0f33..640d98e 100644 --- a/content/shell/android/shell_manager.h +++ b/content/shell/android/shell_manager.h @@ -5,17 +5,18 @@ #ifndef CONTENT_SHELL_ANDROID_SHELL_MANAGER_H_ #define CONTENT_SHELL_ANDROID_SHELL_MANAGER_H_ +#include <jni.h> + #include "base/android/jni_android.h" #include "base/android/scoped_java_ref.h" namespace content { -class ShellView; // Creates an Android specific shell view, which is our version of a shell // window. This view holds the controls and content views necessary to -// render a shell window. Returns a ShellView ptr bound to an initialized java +// render a shell window. Returns the java object representing the shell view. // object. -content::ShellView* CreateShellView(); +jobject CreateShellView(); // Registers the ShellManager native methods. bool RegisterShellManager(JNIEnv* env); diff --git a/content/shell/android/shell_view.cc b/content/shell/android/shell_view.cc deleted file mode 100644 index 63f8fdc..0000000 --- a/content/shell/android/shell_view.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 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. - -#include "content/shell/android/shell_view.h" - -#include "base/android/jni_android.h" -#include "jni/shell_view_jni.h" - -namespace content { - -ShellView::ShellView(JNIEnv* env, jobject obj) - : weak_java_shell_view_(env, obj) { -} - -ShellView::~ShellView() { -} - -void ShellView::InitFromTabContents(WebContents* tab_contents) { - JNIEnv* env = base::android::AttachCurrentThread(); - Java_ShellView_initFromNativeTabContents( - env, weak_java_shell_view_.get(env).obj(), - reinterpret_cast<jint>(tab_contents)); -} - -// static -bool ShellView::Register(JNIEnv* env) { - return RegisterNativesImpl(env); -} - -static jint Init(JNIEnv* env, jobject obj) { - return reinterpret_cast<jint>(new ShellView(env, obj)); -} - -} // namespace content diff --git a/content/shell/android/shell_view.h b/content/shell/android/shell_view.h deleted file mode 100644 index 38feef0..0000000 --- a/content/shell/android/shell_view.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CONTENT_SHELL_ANDROID_SHELL_VIEW_H_ -#define CONTENT_SHELL_ANDROID_SHELL_VIEW_H_ - -#include <jni.h> - -#include "base/basictypes.h" -#include "base/android/scoped_java_ref.h" -#include "base/android/jni_helper.h" -#include "content/public/browser/web_contents.h" - -class TabContents; - -namespace content { - -// Native representation of the java ShellView. Handles JNI communication -// between the two instances. -class ShellView { - public: - ShellView(JNIEnv* env, jobject obj); - virtual ~ShellView(); - - // Initializes the java components based on the tab contents. - void InitFromTabContents(WebContents* tab_contents); - - // Registers the ShellView native methods. - static bool Register(JNIEnv* env); - - private: - JavaObjectWeakGlobalRef weak_java_shell_view_; - - DISALLOW_COPY_AND_ASSIGN(ShellView); -}; - -} // namespace content - -#endif // CONTENT_SHELL_ANDROID_SHELL_VIEW_H_ diff --git a/content/shell/shell.h b/content/shell/shell.h index b08bb23..918b6ff 100644 --- a/content/shell/shell.h +++ b/content/shell/shell.h @@ -23,7 +23,7 @@ typedef struct _GtkToolItem GtkToolItem; #elif defined(OS_ANDROID) -#include "content/shell/android/shell_view.h" +#include "base/android/scoped_java_ref.h" #endif class GURL; @@ -76,6 +76,9 @@ class Shell : public WebContentsDelegate, // Public to be called by an ObjC bridge object. void ActionPerformed(int control); void URLEntered(std::string url_string); +#elif defined(OS_ANDROID) + // Registers the Android Java to native methods. + static bool Register(JNIEnv* env); #endif private: @@ -118,6 +121,9 @@ class Shell : public WebContentsDelegate, // content::WebContentsDelegate virtual void LoadingStateChanged(WebContents* source) OVERRIDE; +#if defined(OS_ANDROID) + virtual void LoadProgressChanged(double progress) OVERRIDE; +#endif virtual void WebContentsCreated(WebContents* source_contents, int64 source_frame_id, const GURL& target_url, @@ -185,7 +191,7 @@ class Shell : public WebContentsDelegate, int content_width_; int content_height_; #elif defined(OS_ANDROID) - scoped_ptr<ShellView> shell_view_; + base::android::ScopedJavaGlobalRef<jobject> java_object_; #endif // A container of all the open windows. We use a vector so we can keep track diff --git a/content/shell/shell_android.cc b/content/shell/shell_android.cc index ec51e7c..a8fea37 100644 --- a/content/shell/shell_android.cc +++ b/content/shell/shell_android.cc @@ -4,9 +4,17 @@ #include "content/shell/shell.h" +#include <jni.h> + +#include "base/android/scoped_java_ref.h" +#include "base/android/jni_string.h" #include "base/logging.h" #include "base/string_piece.h" #include "content/shell/android/shell_manager.h" +#include "jni/shell_jni.h" + +using base::android::AttachCurrentThread; +using base::android::ConvertUTF8ToJavaString; namespace content { @@ -24,17 +32,23 @@ void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { } void Shell::PlatformSetAddressBarURL(const GURL& url) { + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jstring> j_url = + ConvertUTF8ToJavaString(env, url.spec()); + Java_Shell_onUpdateUrl(env, java_object_.obj(), j_url.obj()); } void Shell::PlatformSetIsLoading(bool loading) { } void Shell::PlatformCreateWindow(int width, int height) { - shell_view_.reset(CreateShellView()); + java_object_.Reset(AttachCurrentThread(), CreateShellView()); } void Shell::PlatformSetContents() { - shell_view_->InitFromTabContents(web_contents_.get()); + JNIEnv* env = AttachCurrentThread(); + Java_Shell_initFromNativeTabContents( + env, java_object_.obj(), reinterpret_cast<jint>(web_contents())); } void Shell::PlatformResizeSubViews() { @@ -45,9 +59,19 @@ void Shell::PlatformSetTitle(const string16& title) { NOTIMPLEMENTED(); } +void Shell::LoadProgressChanged(double progress) { + JNIEnv* env = AttachCurrentThread(); + Java_Shell_onLoadProgressChanged(env, java_object_.obj(), progress); +} + void Shell::Close() { // TODO(tedchoc): Implement Close method for android shell NOTIMPLEMENTED(); } +// static +bool Shell::Register(JNIEnv* env) { + return RegisterNativesImpl(env); +} + } // namespace content |