diff options
author | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-09 17:07:18 +0000 |
---|---|---|
committer | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-09 17:07:18 +0000 |
commit | 155c7f293b39e0c37a0394c48aabe8a330c89d1b (patch) | |
tree | 0b4e0f5e3737dcf5bac82540b4ddf9eae41485a0 /content | |
parent | 18cbba0aedd9d569b27be8adbd2836c839ae9897 (diff) | |
download | chromium_src-155c7f293b39e0c37a0394c48aabe8a330c89d1b.zip chromium_src-155c7f293b39e0c37a0394c48aabe8a330c89d1b.tar.gz chromium_src-155c7f293b39e0c37a0394c48aabe8a330c89d1b.tar.bz2 |
Add support for java versions of WebContents and NavigationController.
This is on the path of cleaning of ContentViewCore, which has been a
dumping ground for all things webcontents-y. The hope is to move to a
world where java mimics other platforms more closely.
BUG=
Review URL: https://codereview.chromium.org/82693007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239506 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
17 files changed, 513 insertions, 54 deletions
diff --git a/content/browser/android/browser_jni_registrar.cc b/content/browser/android/browser_jni_registrar.cc index 88c8801..be30869 100644 --- a/content/browser/android/browser_jni_registrar.cc +++ b/content/browser/android/browser_jni_registrar.cc @@ -24,6 +24,7 @@ #include "content/browser/android/tracing_controller_android.h" #include "content/browser/android/web_contents_observer_android.h" #include "content/browser/device_orientation/data_fetcher_impl_android.h" +#include "content/browser/frame_host/navigation_controller_android.h" #include "content/browser/geolocation/location_api_adapter_android.h" #include "content/browser/media/android/media_drm_credential_manager.h" #include "content/browser/media/android/media_resource_getter_impl.h" @@ -33,6 +34,7 @@ #include "content/browser/renderer_host/java/java_bound_object.h" #include "content/browser/speech/speech_recognizer_impl_android.h" #include "content/browser/vibration/vibration_provider_android.h" +#include "content/browser/web_contents/web_contents_android.h" using content::SurfaceTexturePeerBrowserImpl; @@ -56,11 +58,13 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = { {"InterstitialPageDelegateAndroid", content::InterstitialPageDelegateAndroid:: RegisterInterstitialPageDelegateAndroid}, + {"LoadUrlParams", content::RegisterLoadUrlParams}, {"MediaDrmCredentialManager", content::MediaDrmCredentialManager::RegisterMediaDrmCredentialManager}, {"MediaResourceGetterImpl", content::MediaResourceGetterImpl::RegisterMediaResourceGetter}, - {"LoadUrlParams", content::RegisterLoadUrlParams}, + {"NavigationControllerAndroid", + content::NavigationControllerAndroid::Register}, {"PowerSaveBlock", content::RegisterPowerSaveBlocker}, {"RegisterImeAdapter", content::RegisterImeAdapter}, {"SpeechRecognizerImplAndroid", @@ -70,6 +74,7 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = { {"TouchPoint", content::RegisterTouchPoint}, {"TracingControllerAndroid", content::RegisterTracingControllerAndroid}, {"VibrationProvider", content::VibrationProviderAndroid::Register}, + {"WebContentsAndroid", content::WebContentsAndroid::Register}, {"WebContentsObserverAndroid", content::RegisterWebContentsObserverAndroid}, {"WebViewStatics", content::RegisterWebViewStatics}, }; diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 474e995..7fb557f 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -209,6 +209,11 @@ ContentViewCoreImpl::~ContentViewCoreImpl() { notification_registrar_.RemoveAll(); } +base::android::ScopedJavaLocalRef<jobject> +ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, jobject obj) { + return web_contents_->GetJavaWebContents(); +} + void ContentViewCoreImpl::OnJavaContentViewCoreDestroyed(JNIEnv* env, jobject obj) { DCHECK(env->IsSameObject(java_ref_.get(env).obj(), obj)); @@ -1124,37 +1129,6 @@ void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, } } -jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { - return web_contents_->GetController().CanGoBack(); -} - -jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { - return web_contents_->GetController().CanGoForward(); -} - -jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, - jint offset) { - return web_contents_->GetController().CanGoToOffset(offset); -} - -void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) { - web_contents_->GetController().GoBack(); -} - -void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { - web_contents_->GetController().GoForward(); -} - -void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { - web_contents_->GetController().GoToOffset(offset); -} - -void ContentViewCoreImpl::GoToNavigationIndex(JNIEnv* env, - jobject obj, - jint index) { - web_contents_->GetController().GoToIndex(index); -} - void ContentViewCoreImpl::LoadIfNecessary(JNIEnv* env, jobject obj) { web_contents_->GetController().LoadIfNecessary(); } diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index 138aecc..040d6e0 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -68,6 +68,9 @@ class ContentViewCoreImpl : public ContentViewCore, // Methods called from Java via JNI // -------------------------------------------------------------------------- + base::android::ScopedJavaLocalRef<jobject> GetWebContentsAndroid(JNIEnv* env, + jobject obj); + void OnJavaContentViewCoreDestroyed(JNIEnv* env, jobject obj); // Notifies the ContentViewCore that items were selected in the currently @@ -141,13 +144,6 @@ class ContentViewCoreImpl : public ContentViewCore, jfloat x2, jfloat y2); void MoveCaret(JNIEnv* env, jobject obj, jfloat x, jfloat y); - jboolean CanGoBack(JNIEnv* env, jobject obj); - jboolean CanGoForward(JNIEnv* env, jobject obj); - jboolean CanGoToOffset(JNIEnv* env, jobject obj, jint offset); - void GoBack(JNIEnv* env, jobject obj); - void GoForward(JNIEnv* env, jobject obj); - void GoToOffset(JNIEnv* env, jobject obj, jint offset); - void GoToNavigationIndex(JNIEnv* env, jobject obj, jint index); void LoadIfNecessary(JNIEnv* env, jobject obj); void RequestRestoreLoad(JNIEnv* env, jobject obj); void StopLoading(JNIEnv* env, jobject obj); diff --git a/content/browser/frame_host/navigation_controller_android.cc b/content/browser/frame_host/navigation_controller_android.cc new file mode 100644 index 0000000..536e17d --- /dev/null +++ b/content/browser/frame_host/navigation_controller_android.cc @@ -0,0 +1,73 @@ +// Copyright 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. + +#include "content/browser/frame_host/navigation_controller_android.h" + +#include "base/android/jni_android.h" +#include "content/public/browser/navigation_controller.h" +#include "jni/NavigationControllerImpl_jni.h" + +using base::android::AttachCurrentThread; + +namespace content { + +// static +bool NavigationControllerAndroid::Register(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +NavigationControllerAndroid::NavigationControllerAndroid( + NavigationController* navigation_controller) + : navigation_controller_(navigation_controller) { + JNIEnv* env = AttachCurrentThread(); + obj_.Reset(env, + Java_NavigationControllerImpl_create( + env, reinterpret_cast<intptr_t>(this)).obj()); +} + +NavigationControllerAndroid::~NavigationControllerAndroid() { + Java_NavigationControllerImpl_destroy(AttachCurrentThread(), obj_.obj()); +} + +base::android::ScopedJavaLocalRef<jobject> +NavigationControllerAndroid::GetJavaObject() { + return base::android::ScopedJavaLocalRef<jobject>(obj_); +} + +jboolean NavigationControllerAndroid::CanGoBack(JNIEnv* env, jobject obj) { + return navigation_controller_->CanGoBack(); +} + +jboolean NavigationControllerAndroid::CanGoForward(JNIEnv* env, + jobject obj) { + return navigation_controller_->CanGoForward(); +} + +jboolean NavigationControllerAndroid::CanGoToOffset(JNIEnv* env, + jobject obj, + jint offset) { + return navigation_controller_->CanGoToOffset(offset); +} + +void NavigationControllerAndroid::GoBack(JNIEnv* env, jobject obj) { + navigation_controller_->GoBack(); +} + +void NavigationControllerAndroid::GoForward(JNIEnv* env, jobject obj) { + navigation_controller_->GoForward(); +} + +void NavigationControllerAndroid::GoToOffset(JNIEnv* env, + jobject obj, + jint offset) { + navigation_controller_->GoToOffset(offset); +} + +void NavigationControllerAndroid::GoToNavigationIndex(JNIEnv* env, + jobject obj, + jint index) { + navigation_controller_->GoToIndex(index); +} + +} // namespace content diff --git a/content/browser/frame_host/navigation_controller_android.h b/content/browser/frame_host/navigation_controller_android.h new file mode 100644 index 0000000..e0c96a6 --- /dev/null +++ b/content/browser/frame_host/navigation_controller_android.h @@ -0,0 +1,53 @@ +// Copyright 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. + +#ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_CONTROLLER_ANDROID_H_ +#define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_CONTROLLER_ANDROID_H_ + +#include <jni.h> + +#include "base/android/scoped_java_ref.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/common/content_export.h" + +namespace content { + +class NavigationController; + +// Android wrapper around NavigationController that provides safer passage +// from java and back to native and provides java with a means of communicating +// with its native counterpart. +class CONTENT_EXPORT NavigationControllerAndroid { + public: + static bool Register(JNIEnv* env); + + explicit NavigationControllerAndroid( + NavigationController* navigation_controller); + ~NavigationControllerAndroid(); + + NavigationController* navigation_controller() const { + return navigation_controller_; + } + + base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); + + jboolean CanGoBack(JNIEnv* env, jobject obj); + jboolean CanGoForward(JNIEnv* env, jobject obj); + jboolean CanGoToOffset(JNIEnv* env, jobject obj, jint offset); + void GoBack(JNIEnv* env, jobject obj); + void GoForward(JNIEnv* env, jobject obj); + void GoToOffset(JNIEnv* env, jobject obj, jint offset); + void GoToNavigationIndex(JNIEnv* env, jobject obj, jint index); + + private: + NavigationController* navigation_controller_; + base::android::ScopedJavaGlobalRef<jobject> obj_; + + DISALLOW_COPY_AND_ASSIGN(NavigationControllerAndroid); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_CONTROLLER_ANDROID_H_ diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc new file mode 100644 index 0000000..88922b1 --- /dev/null +++ b/content/browser/web_contents/web_contents_android.cc @@ -0,0 +1,58 @@ +// Copyright 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. + +#include "content/browser/web_contents/web_contents_android.h" + +#include "base/android/jni_android.h" +#include "base/logging.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/web_contents.h" +#include "jni/WebContentsImpl_jni.h" + +using base::android::AttachCurrentThread; + +namespace content { + +// static +WebContents* WebContents::FromJavaWebContents( + jobject jweb_contents_android) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!jweb_contents_android) + return NULL; + + WebContentsAndroid* web_contents_android = + reinterpret_cast<WebContentsAndroid*>( + Java_WebContentsImpl_getNativePointer(AttachCurrentThread(), + jweb_contents_android)); + if (!web_contents_android) + return NULL; + return web_contents_android->web_contents(); +} + +// static +bool WebContentsAndroid::Register(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +WebContentsAndroid::WebContentsAndroid(WebContents* web_contents) + : web_contents_(web_contents), + navigation_controller_(&(web_contents->GetController())) { + JNIEnv* env = AttachCurrentThread(); + obj_.Reset(env, + Java_WebContentsImpl_create( + env, + reinterpret_cast<intptr_t>(this), + navigation_controller_.GetJavaObject().obj()).obj()); +} + +WebContentsAndroid::~WebContentsAndroid() { + Java_WebContentsImpl_destroy(AttachCurrentThread(), obj_.obj()); +} + +base::android::ScopedJavaLocalRef<jobject> +WebContentsAndroid::GetJavaObject() { + return base::android::ScopedJavaLocalRef<jobject>(obj_); +} + +} // namespace content diff --git a/content/browser/web_contents/web_contents_android.h b/content/browser/web_contents/web_contents_android.h new file mode 100644 index 0000000..a9595e2 --- /dev/null +++ b/content/browser/web_contents/web_contents_android.h @@ -0,0 +1,46 @@ +// Copyright 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. + +#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_ANDROID_H_ +#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_ANDROID_H_ + +#include <jni.h> + +#include "base/android/scoped_java_ref.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/supports_user_data.h" +#include "content/browser/frame_host/navigation_controller_android.h" +#include "content/common/content_export.h" + +namespace content { + +class WebContents; + +// Android wrapper around WebContents that provides safer passage from java and +// back to native and provides java with a means of communicating with its +// native counterpart. +class CONTENT_EXPORT WebContentsAndroid + : public base::SupportsUserData::Data { + public: + static bool Register(JNIEnv* env); + + explicit WebContentsAndroid(WebContents* web_contents); + virtual ~WebContentsAndroid(); + + WebContents* web_contents() const { return web_contents_; } + + base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); + + private: + WebContents* web_contents_; + NavigationControllerAndroid navigation_controller_; + base::android::ScopedJavaGlobalRef<jobject> obj_; + + DISALLOW_COPY_AND_ASSIGN(WebContentsAndroid); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_ANDROID_H_ diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 81edfed..3c5437c 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -92,6 +92,7 @@ #if defined(OS_ANDROID) #include "content/browser/android/date_time_chooser_android.h" #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h" +#include "content/browser/web_contents/web_contents_android.h" #include "content/common/java_bridge_messages.h" #include "content/public/browser/android/content_view_core.h" #endif @@ -157,6 +158,10 @@ namespace { const char kDotGoogleDotCom[] = ".google.com"; +#if defined(OS_ANDROID) +const char kWebContentsAndroidKey[] = "web_contents_android"; +#endif // OS_ANDROID + base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > g_created_callbacks = LAZY_INSTANCE_INITIALIZER; @@ -3666,6 +3671,19 @@ bool WebContentsImpl::CreateRenderViewForRenderManager( } #if defined(OS_ANDROID) +base::android::ScopedJavaLocalRef<jobject> +WebContentsImpl::GetJavaWebContents() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + WebContentsAndroid* web_contents_android = + static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey)); + if (!web_contents_android) { + web_contents_android = new WebContentsAndroid(this); + SetUserData(kWebContentsAndroidKey, web_contents_android); + } + return web_contents_android->GetJavaObject(); +} + bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { return CreateRenderViewForRenderManager(GetRenderViewHost(), MSG_ROUTING_NONE); diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 7752dce..79bfc23 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -268,6 +268,10 @@ class CONTENT_EXPORT WebContentsImpl bool is_favicon, uint32_t max_bitmap_size, const ImageDownloadCallback& callback) OVERRIDE; +#if defined(OS_ANDROID) + virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() + OVERRIDE; +#endif // Implementation of PageNavigator. virtual WebContents* OpenURL(const OpenURLParams& params) OVERRIDE; diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 78ce7b4..d067d57 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -512,6 +512,8 @@ 'browser/frame_host/interstitial_page_impl.h', 'browser/frame_host/interstitial_page_navigator_impl.cc', 'browser/frame_host/interstitial_page_navigator_impl.h', + 'browser/frame_host/navigation_controller_android.cc', + 'browser/frame_host/navigation_controller_android.h', 'browser/frame_host/navigation_controller_delegate.h', 'browser/frame_host/navigation_controller_impl.cc', 'browser/frame_host/navigation_controller_impl.h', @@ -1194,6 +1196,8 @@ 'browser/web_contents/drag_utils_gtk.h', 'browser/web_contents/touch_editable_impl_aura.cc', 'browser/web_contents/touch_editable_impl_aura.h', + 'browser/web_contents/web_contents_android.cc', + 'browser/web_contents/web_contents_android.h', 'browser/web_contents/web_contents_drag_win.cc', 'browser/web_contents/web_contents_drag_win.h', 'browser/web_contents/web_contents_impl.cc', diff --git a/content/content_jni.gypi b/content/content_jni.gypi index c5a268d..2c955ba 100644 --- a/content/content_jni.gypi +++ b/content/content_jni.gypi @@ -35,6 +35,8 @@ 'public/android/java/src/org/chromium/content/browser/TracingControllerAndroid.java', 'public/android/java/src/org/chromium/content/browser/VibrationProvider.java', 'public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java', + 'public/android/java/src/org/chromium/content/browser/framehost/NavigationControllerImpl.java', + 'public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java', 'public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java', 'public/android/java/src/org/chromium/content/common/TraceEvent.java', ], diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index c0f2341..0c42df1 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -351,6 +351,7 @@ public class ContentViewCore private final Context mContext; private ViewGroup mContainerView; private InternalAccessDelegate mContainerViewInternals; + private WebContents mWebContents; private WebContentsObserverAndroid mWebContentsObserver; private ContentViewClient mContentViewClient; @@ -509,6 +510,13 @@ public class ContentViewCore } /** + * @return The WebContents currently being rendered. + */ + public WebContents getWebContents() { + return mWebContents; + } + + /** * Specifies how much smaller the WebKit layout size should be relative to the size of this * view. * @param offsetXPix The X amount in pixels to shrink the viewport by. @@ -762,6 +770,7 @@ public class ContentViewCore mNativeContentViewCore = nativeInit(mHardwareAccelerated, nativeWebContents, viewAndroidNativePointer, windowNativePointer); + mWebContents = nativeGetWebContentsAndroid(mNativeContentViewCore); mContentSettings = new ContentSettings(this, mNativeContentViewCore); initializeContainerView(internalDispatcher); @@ -900,6 +909,7 @@ public class ContentViewCore if (mNativeContentViewCore != 0) { nativeOnJavaContentViewCoreDestroyed(mNativeContentViewCore); } + mWebContents = null; resetVSyncNotification(); mVSyncProvider = null; if (mViewAndroid != null) mViewAndroid.destroy(); @@ -1169,18 +1179,20 @@ public class ContentViewCore scale); } + // TODO(teddchoc): Remove all these navigation controller methods from here and have the + // embedders manage it. /** * @return Whether the current WebContents has a previous navigation entry. */ public boolean canGoBack() { - return mNativeContentViewCore != 0 && nativeCanGoBack(mNativeContentViewCore); + return mWebContents != null && mWebContents.getNavigationController().canGoBack(); } /** * @return Whether the current WebContents has a navigation entry after the current one. */ public boolean canGoForward() { - return mNativeContentViewCore != 0 && nativeCanGoForward(mNativeContentViewCore); + return mWebContents != null && mWebContents.getNavigationController().canGoForward(); } /** @@ -1188,7 +1200,8 @@ public class ContentViewCore * @return Whether we can move in history by given offset */ public boolean canGoToOffset(int offset) { - return mNativeContentViewCore != 0 && nativeCanGoToOffset(mNativeContentViewCore, offset); + return mWebContents != null && + mWebContents.getNavigationController().canGoToOffset(offset); } /** @@ -1197,27 +1210,28 @@ public class ContentViewCore * @param offset The offset into the navigation history. */ public void goToOffset(int offset) { - if (mNativeContentViewCore != 0) nativeGoToOffset(mNativeContentViewCore, offset); + if (mWebContents != null) mWebContents.getNavigationController().goToOffset(offset); } @Override public void goToNavigationIndex(int index) { - if (mNativeContentViewCore != 0) nativeGoToNavigationIndex(mNativeContentViewCore, index); + if (mWebContents != null) { + mWebContents.getNavigationController().goToNavigationIndex(index); + } } /** * Goes to the navigation entry before the current one. */ public void goBack() { - reportActionAfterDoubleTapUMA(ContentViewCore.UMAActionAfterDoubleTap.NAVIGATE_BACK); - if (mNativeContentViewCore != 0) nativeGoBack(mNativeContentViewCore); + if (mWebContents != null) mWebContents.getNavigationController().goBack(); } /** * Goes to the navigation entry following the current one. */ public void goForward() { - if (mNativeContentViewCore != 0) nativeGoForward(mNativeContentViewCore); + if (mWebContents != null) mWebContents.getNavigationController().goForward(); } /** @@ -3220,6 +3234,8 @@ public class ContentViewCore return getContentViewClient().shouldBlockMediaRequest(url); } + private native WebContents nativeGetWebContentsAndroid(long nativeContentViewCoreImpl); + private native void nativeOnJavaContentViewCoreDestroyed(long nativeContentViewCoreImpl); private native void nativeLoadUrl( @@ -3310,13 +3326,6 @@ public class ContentViewCore private native void nativeMoveCaret(long nativeContentViewCoreImpl, float x, float y); - private native boolean nativeCanGoBack(long nativeContentViewCoreImpl); - private native boolean nativeCanGoForward(long nativeContentViewCoreImpl); - private native boolean nativeCanGoToOffset(long nativeContentViewCoreImpl, int offset); - private native void nativeGoBack(long nativeContentViewCoreImpl); - private native void nativeGoForward(long nativeContentViewCoreImpl); - private native void nativeGoToOffset(long nativeContentViewCoreImpl, int offset); - private native void nativeGoToNavigationIndex(long nativeContentViewCoreImpl, int index); private native void nativeLoadIfNecessary(long nativeContentViewCoreImpl); private native void nativeRequestRestoreLoad(long nativeContentViewCoreImpl); diff --git a/content/public/android/java/src/org/chromium/content/browser/NavigationController.java b/content/public/android/java/src/org/chromium/content/browser/NavigationController.java new file mode 100644 index 0000000..d07845c --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/browser/NavigationController.java @@ -0,0 +1,50 @@ +// Copyright 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.content.browser; + +/** + * The NavigationController Java wrapper to allow communicating with the native + * NavigationController object. + */ +public interface NavigationController { + /** + * @return Whether back navigation is possible from the "current entry". + */ + boolean canGoBack(); + + /** + * @return Whether forward navigation is possible from the "current entry". + */ + boolean canGoForward(); + + /** + * @param offset The offset into the navigation history. + * @return Whether we can move in history by given offset + */ + boolean canGoToOffset(int offset); + + /** + * Navigates to the specified offset from the "current entry". Does nothing if the offset is + * out of bounds. + * @param offset The offset into the navigation history. + */ + void goToOffset(int offset); + + /** + * Navigates to the specified index in the navigation entry for this page. + * @param index The navigation index to navigate to. + */ + void goToNavigationIndex(int index); + + /** + * Goes to the navigation entry before the current one. + */ + void goBack(); + + /** + * Goes to the navigation entry following the current one. + */ + void goForward(); +} diff --git a/content/public/android/java/src/org/chromium/content/browser/WebContents.java b/content/public/android/java/src/org/chromium/content/browser/WebContents.java new file mode 100644 index 0000000..c89e2b9 --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/browser/WebContents.java @@ -0,0 +1,15 @@ +// Copyright 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.content.browser; + +/** + * The WebContents Java wrapper to allow communicating with the native WebContents object. + */ +public interface WebContents { + /** + * @return The navigation controller associated with this WebContents. + */ + NavigationController getNavigationController(); +} diff --git a/content/public/android/java/src/org/chromium/content/browser/framehost/NavigationControllerImpl.java b/content/public/android/java/src/org/chromium/content/browser/framehost/NavigationControllerImpl.java new file mode 100644 index 0000000..a5047aa --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/browser/framehost/NavigationControllerImpl.java @@ -0,0 +1,91 @@ +// Copyright 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.content.browser.framehost; + +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; +import org.chromium.content.browser.NavigationController; + +/** + * The NavigationControllerImpl Java wrapper to allow communicating with the native + * NavigationControllerImpl object. + */ +@JNINamespace("content") +// TODO(tedchoc): Remove the package restriction once this class moves to a non-public content +// package whose visibility will be enforced via DEPS. +/* package */ class NavigationControllerImpl implements NavigationController { + + private long mNativeNavigationControllerAndroid; + + private NavigationControllerImpl(long nativeNavigationControllerAndroid) { + mNativeNavigationControllerAndroid = nativeNavigationControllerAndroid; + } + + @CalledByNative + private static NavigationControllerImpl create(long nativeNavigationControllerAndroid) { + return new NavigationControllerImpl(nativeNavigationControllerAndroid); + } + + @CalledByNative + private void destroy() { + mNativeNavigationControllerAndroid = 0; + } + + @Override + public boolean canGoBack() { + return mNativeNavigationControllerAndroid != 0 + && nativeCanGoBack(mNativeNavigationControllerAndroid); + } + + @Override + public boolean canGoForward() { + return mNativeNavigationControllerAndroid != 0 + && nativeCanGoForward(mNativeNavigationControllerAndroid); + } + + @Override + public boolean canGoToOffset(int offset) { + return mNativeNavigationControllerAndroid != 0 + && nativeCanGoToOffset(mNativeNavigationControllerAndroid, offset); + } + + @Override + public void goToOffset(int offset) { + if (mNativeNavigationControllerAndroid != 0) { + nativeGoToOffset(mNativeNavigationControllerAndroid, offset); + } + } + + @Override + public void goToNavigationIndex(int index) { + if (mNativeNavigationControllerAndroid != 0) { + nativeGoToNavigationIndex(mNativeNavigationControllerAndroid, index); + } + } + + @Override + public void goBack() { + if (mNativeNavigationControllerAndroid != 0) { + nativeGoBack(mNativeNavigationControllerAndroid); + } + } + + @Override + public void goForward() { + if (mNativeNavigationControllerAndroid != 0) { + nativeGoForward(mNativeNavigationControllerAndroid); + } + } + + private native boolean nativeCanGoBack(long nativeNavigationControllerAndroid); + private native boolean nativeCanGoForward(long nativeNavigationControllerAndroid); + private native boolean nativeCanGoToOffset( + long nativeNavigationControllerAndroid, int offset); + private native void nativeGoBack(long nativeNavigationControllerAndroid); + private native void nativeGoForward(long nativeNavigationControllerAndroid); + private native void nativeGoToOffset(long nativeNavigationControllerAndroid, int offset); + private native void nativeGoToNavigationIndex( + long nativeNavigationControllerAndroid, int index); +} diff --git a/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java b/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java new file mode 100644 index 0000000..550333e --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/browser/webcontents/WebContentsImpl.java @@ -0,0 +1,51 @@ +// Copyright 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.content.browser.webcontents; + +import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; +import org.chromium.content.browser.NavigationController; +import org.chromium.content.browser.WebContents; + +/** + * The WebContentsImpl Java wrapper to allow communicating with the native WebContentsImpl + * object. + */ +@JNINamespace("content") +//TODO(tedchoc): Remove the package restriction once this class moves to a non-public content +// package whose visibility will be enforced via DEPS. +/* package */ class WebContentsImpl implements WebContents { + + private long mNativeWebContentsAndroid; + private NavigationController mNavigationController; + + private WebContentsImpl( + long nativeWebContentsAndroid, NavigationController navigationController) { + mNativeWebContentsAndroid = nativeWebContentsAndroid; + mNavigationController = navigationController; + } + + @CalledByNative + private static WebContentsImpl create( + long nativeWebContentsAndroid, NavigationController navigationController) { + return new WebContentsImpl(nativeWebContentsAndroid, navigationController); + } + + @CalledByNative + private void destroy() { + mNativeWebContentsAndroid = 0; + mNavigationController = null; + } + + @CalledByNative + private long getNativePointer() { + return mNativeWebContentsAndroid; + } + + @Override + public NavigationController getNavigationController() { + return mNavigationController; + } +} diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index d9bb1e4..a195ba3 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -24,6 +24,10 @@ #include "ui/gfx/native_widget_types.h" #include "ui/gfx/size.h" +#if defined(OS_ANDROID) +#include "base/android/scoped_java_ref.h" +#endif + namespace base { class TimeTicks; } @@ -462,6 +466,12 @@ class WebContents : public PageNavigator, uint32_t max_bitmap_size, const ImageDownloadCallback& callback) = 0; +#if defined(OS_ANDROID) + CONTENT_EXPORT static WebContents* FromJavaWebContents( + jobject jweb_contents_android); + virtual base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() = 0; +#endif // OS_ANDROID + private: // This interface should only be implemented inside content. friend class WebContentsImpl; |