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 21d3bd783dbbb16dd41af4a176e14dc0f868ff63..fd1ab9bef72f5cca142e5fc2720abbca0076ccf0 100644 |
--- a/content/browser/android/content_view_core_impl.cc |
+++ b/content/browser/android/content_view_core_impl.cc |
@@ -10,6 +10,8 @@ |
#include "base/android/scoped_java_ref.h" |
#include "content/browser/android/content_view_client.h" |
#include "content/browser/android/touch_point.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/renderer_host/render_widget_host_impl.h" |
#include "content/browser/renderer_host/render_widget_host_view_android.h" |
@@ -18,11 +20,13 @@ |
#include "content/public/browser/interstitial_page.h" |
#include "content/public/browser/web_contents.h" |
#include "jni/ContentViewCore_jni.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEventFactory.h" |
#include "webkit/glue/webmenuitem.h" |
using base::android::AttachCurrentThread; |
+using base::android::ConvertJavaStringToUTF16; |
using base::android::ConvertUTF16ToJavaString; |
using base::android::ConvertUTF8ToJavaString; |
using base::android::GetClass; |
@@ -72,7 +76,7 @@ ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
WebContents* web_contents) |
- : web_contents_(web_contents), |
+ : web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
tab_crashed_(false) { |
DCHECK(web_contents) << |
"A ContentViewCoreImpl should be created with a valid WebContents."; |
@@ -313,6 +317,29 @@ void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { |
content_view_client_.swap(client); |
} |
+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_->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_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( |
+ ConvertJavaStringToUTF16(env, name)); |
+} |
+ |
// -------------------------------------------------------------------------- |
// Methods called from native code |
// -------------------------------------------------------------------------- |