Chromium Code Reviews| Index: content/browser/android/content_view_core_impl.cc |
| diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc |
| index a867ae5d2e027d0b0b57335b719a60350fd86bc3..1185a82557e18413a9b56fb945e9775c4356a31c 100644 |
| --- a/content/browser/android/content_view_core_impl.cc |
| +++ b/content/browser/android/content_view_core_impl.cc |
| @@ -9,17 +9,21 @@ |
| #include "base/android/jni_string.h" |
| #include "base/android/scoped_java_ref.h" |
| #include "content/browser/android/content_view_client.h" |
| +#include "content/browser/renderer_host/java/java_bound_object.h" |
| +#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/web_contents/navigation_controller_impl.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/web_contents.h" |
| #include "jni/ContentViewCore_jni.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| #include "webkit/glue/webmenuitem.h" |
| using base::android::AttachCurrentThread; |
| using base::android::ConvertUTF16ToJavaString; |
| using base::android::ConvertUTF8ToJavaString; |
| using base::android::GetClass; |
| +using base::android::ConvertJavaStringToUTF16; |
|
Ted C
2012/07/27 18:09:04
move under AttachCurrentThread
Steve Block
2012/07/30 11:45:14
Done.
|
| using base::android::HasField; |
| using base::android::ScopedJavaGlobalRef; |
| using base::android::ScopedJavaLocalRef; |
| @@ -64,7 +68,7 @@ ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
| ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
| WebContents* web_contents) |
| - : web_contents_(web_contents), |
| + : web_contents_impl_(static_cast<WebContentsImpl*>(web_contents)), |
|
jam
2012/07/27 23:29:57
nit: just keep it web_contents_, even if it is a W
Steve Block
2012/07/30 11:45:14
Done.
|
| tab_crashed_(false) { |
| DCHECK(web_contents) << |
| "A ContentViewCoreImpl should be created with a valid WebContents."; |
| @@ -146,56 +150,56 @@ jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { |
| } |
| jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { |
| - return web_contents_->GetController().CanGoBack(); |
| + return web_contents_impl_->GetController().CanGoBack(); |
| } |
| jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { |
| - return web_contents_->GetController().CanGoForward(); |
| + return web_contents_impl_->GetController().CanGoForward(); |
| } |
| jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, |
| jint offset) { |
| - return web_contents_->GetController().CanGoToOffset(offset); |
| + return web_contents_impl_->GetController().CanGoToOffset(offset); |
| } |
| void ContentViewCoreImpl::GoBack(JNIEnv* env, jobject obj) { |
| - web_contents_->GetController().GoBack(); |
| + web_contents_impl_->GetController().GoBack(); |
| tab_crashed_ = false; |
| } |
| void ContentViewCoreImpl::GoForward(JNIEnv* env, jobject obj) { |
| - web_contents_->GetController().GoForward(); |
| + web_contents_impl_->GetController().GoForward(); |
| tab_crashed_ = false; |
| } |
| void ContentViewCoreImpl::GoToOffset(JNIEnv* env, jobject obj, jint offset) { |
| - web_contents_->GetController().GoToOffset(offset); |
| + web_contents_impl_->GetController().GoToOffset(offset); |
| } |
| void ContentViewCoreImpl::StopLoading(JNIEnv* env, jobject obj) { |
| - web_contents_->Stop(); |
| + web_contents_impl_->Stop(); |
| } |
| void ContentViewCoreImpl::Reload(JNIEnv* env, jobject obj) { |
| // Set check_for_repost parameter to false as we have no repost confirmation |
| // dialog ("confirm form resubmission" screen will still appear, however). |
| - web_contents_->GetController().Reload(false); |
| + web_contents_impl_->GetController().Reload(false); |
| tab_crashed_ = false; |
| } |
| void ContentViewCoreImpl::ClearHistory(JNIEnv* env, jobject obj) { |
| - web_contents_->GetController().PruneAllButActive(); |
| + web_contents_impl_->GetController().PruneAllButActive(); |
| } |
| jboolean ContentViewCoreImpl::NeedsReload(JNIEnv* env, jobject obj) { |
| - return web_contents_->GetController().NeedsReload(); |
| + return web_contents_impl_->GetController().NeedsReload(); |
| } |
| void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { |
| scoped_ptr<ContentViewClient> client( |
| ContentViewClient::CreateNativeContentViewClient(env, jclient)); |
| - web_contents_->SetDelegate(client.get()); |
| + web_contents_impl_->SetDelegate(client.get()); |
| content_view_client_.swap(client); |
| } |
| @@ -343,7 +347,7 @@ void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
| void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, |
| jintArray indices) { |
| RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
| - web_contents_->GetRenderViewHost()); |
| + web_contents_impl_->GetRenderViewHost()); |
| DCHECK(rvhi); |
| if (indices == NULL) { |
| rvhi->DidCancelPopupMenu(); |
| @@ -359,6 +363,29 @@ void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, |
| rvhi->DidSelectPopupMenuItems(selected_indices); |
| } |
| +void ContentViewCoreImpl::AddJavascriptInterface( |
| + JNIEnv* env, |
| + jobject /* obj */, |
| + jobject object, |
| + jstring name, |
| + jboolean allow_inherited_methods) { |
| + ScopedJavaLocalRef<jobject> scoped_object(env, object); |
| + // JavaBoundObject creates the NPObject with a ref count of 1, and |
| + // JavaBridgeDispatcherHostManager takes its own ref. |
| + NPObject* bound_object = JavaBoundObject::Create(scoped_object, |
| + allow_inherited_methods); |
| + web_contents_impl_->java_bridge_dispatcher_host_manager()->AddNamedObject( |
| + ConvertJavaStringToUTF16(env, name), bound_object); |
| + WebKit::WebBindings::releaseObject(bound_object); |
| +} |
| + |
| +void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
| + jobject /* obj */, |
| + jstring name) { |
| + web_contents_impl_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( |
| + ConvertJavaStringToUTF16(env, name)); |
| +} |
| + |
| // -------------------------------------------------------------------------- |
| // Methods called from native code |
| // -------------------------------------------------------------------------- |