Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 9192008: Hook up ContentViewCore.add/removeJavascriptInterface() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try again Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/content_view_core_impl.h" 5 #include "content/browser/android/content_view_core_impl.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/android/scoped_java_ref.h" 10 #include "base/android/scoped_java_ref.h"
11 #include "content/browser/android/content_view_client.h" 11 #include "content/browser/android/content_view_client.h"
12 #include "content/browser/android/touch_point.h" 12 #include "content/browser/android/touch_point.h"
13 #include "content/browser/renderer_host/java/java_bound_object.h"
14 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/renderer_host/render_widget_host_impl.h" 16 #include "content/browser/renderer_host/render_widget_host_impl.h"
15 #include "content/browser/renderer_host/render_widget_host_view_android.h" 17 #include "content/browser/renderer_host/render_widget_host_view_android.h"
16 #include "content/browser/web_contents/navigation_controller_impl.h" 18 #include "content/browser/web_contents/navigation_controller_impl.h"
17 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/interstitial_page.h" 20 #include "content/public/browser/interstitial_page.h"
19 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
20 #include "jni/ContentViewCore_jni.h" 22 #include "jni/ContentViewCore_jni.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h"
23 #include "webkit/glue/webmenuitem.h" 26 #include "webkit/glue/webmenuitem.h"
24 27
25 using base::android::AttachCurrentThread; 28 using base::android::AttachCurrentThread;
29 using base::android::ConvertJavaStringToUTF16;
26 using base::android::ConvertUTF16ToJavaString; 30 using base::android::ConvertUTF16ToJavaString;
27 using base::android::ConvertUTF8ToJavaString; 31 using base::android::ConvertUTF8ToJavaString;
28 using base::android::GetClass; 32 using base::android::GetClass;
29 using base::android::HasField; 33 using base::android::HasField;
30 using base::android::ScopedJavaGlobalRef; 34 using base::android::ScopedJavaGlobalRef;
31 using base::android::ScopedJavaLocalRef; 35 using base::android::ScopedJavaLocalRef;
32 using WebKit::WebInputEvent; 36 using WebKit::WebInputEvent;
33 using WebKit::WebInputEventFactory; 37 using WebKit::WebInputEventFactory;
34 38
35 // Describes the type and enabled state of a select popup item. 39 // Describes the type and enabled state of a select popup item.
(...skipping 29 matching lines...) Expand all
65 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, 69 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env,
66 jobject obj) { 70 jobject obj) {
67 return reinterpret_cast<ContentViewCore*>( 71 return reinterpret_cast<ContentViewCore*>(
68 env->GetIntField(obj, g_native_content_view)); 72 env->GetIntField(obj, g_native_content_view));
69 } 73 }
70 74
71 // ---------------------------------------------------------------------------- 75 // ----------------------------------------------------------------------------
72 76
73 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, 77 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj,
74 WebContents* web_contents) 78 WebContents* web_contents)
75 : web_contents_(web_contents), 79 : web_contents_(static_cast<WebContentsImpl*>(web_contents)),
76 tab_crashed_(false) { 80 tab_crashed_(false) {
77 DCHECK(web_contents) << 81 DCHECK(web_contents) <<
78 "A ContentViewCoreImpl should be created with a valid WebContents."; 82 "A ContentViewCoreImpl should be created with a valid WebContents.";
79 83
80 InitJNI(env, obj); 84 InitJNI(env, obj);
81 } 85 }
82 86
83 ContentViewCoreImpl::~ContentViewCoreImpl() { 87 ContentViewCoreImpl::~ContentViewCoreImpl() {
84 if (java_object_) { 88 if (java_object_) {
85 JNIEnv* env = AttachCurrentThread(); 89 JNIEnv* env = AttachCurrentThread();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 310
307 void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { 311 void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) {
308 scoped_ptr<ContentViewClient> client( 312 scoped_ptr<ContentViewClient> client(
309 ContentViewClient::CreateNativeContentViewClient(env, jclient)); 313 ContentViewClient::CreateNativeContentViewClient(env, jclient));
310 314
311 web_contents_->SetDelegate(client.get()); 315 web_contents_->SetDelegate(client.get());
312 316
313 content_view_client_.swap(client); 317 content_view_client_.swap(client);
314 } 318 }
315 319
320 void ContentViewCoreImpl::AddJavascriptInterface(
321 JNIEnv* env,
322 jobject /* obj */,
323 jobject object,
324 jstring name,
325 jboolean allow_inherited_methods) {
326 ScopedJavaLocalRef<jobject> scoped_object(env, object);
327 // JavaBoundObject creates the NPObject with a ref count of 1, and
328 // JavaBridgeDispatcherHostManager takes its own ref.
329 NPObject* bound_object = JavaBoundObject::Create(scoped_object,
330 allow_inherited_methods);
331 web_contents_->java_bridge_dispatcher_host_manager()->AddNamedObject(
332 ConvertJavaStringToUTF16(env, name), bound_object);
333 WebKit::WebBindings::releaseObject(bound_object);
334 }
335
336 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env,
337 jobject /* obj */,
338 jstring name) {
339 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject(
340 ConvertJavaStringToUTF16(env, name));
341 }
342
316 // -------------------------------------------------------------------------- 343 // --------------------------------------------------------------------------
317 // Methods called from native code 344 // Methods called from native code
318 // -------------------------------------------------------------------------- 345 // --------------------------------------------------------------------------
319 346
320 void ContentViewCoreImpl::LoadUrl(const GURL& url, int page_transition) { 347 void ContentViewCoreImpl::LoadUrl(const GURL& url, int page_transition) {
321 content::Referrer referer; 348 content::Referrer referer;
322 349
323 web_contents()->GetController().LoadURL( 350 web_contents()->GetController().LoadURL(
324 url, referer, content::PageTransitionFromInt(page_transition), 351 url, referer, content::PageTransitionFromInt(page_transition),
325 std::string()); 352 std::string());
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { 535 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) {
509 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; 536 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!";
510 return false; 537 return false;
511 } 538 }
512 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); 539 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I");
513 540
514 return RegisterNativesImpl(env) >= 0; 541 return RegisterNativesImpl(env) >= 0;
515 } 542 }
516 543
517 } // namespace content 544 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698