OLD | NEW |
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" | |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
17 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 15 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
18 #include "content/browser/web_contents/navigation_controller_impl.h" | 16 #include "content/browser/web_contents/navigation_controller_impl.h" |
19 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
20 #include "content/public/browser/interstitial_page.h" | 18 #include "content/public/browser/interstitial_page.h" |
21 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
22 #include "jni/ContentViewCore_jni.h" | 20 #include "jni/ContentViewCore_jni.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" |
26 #include "webkit/glue/webmenuitem.h" | 23 #include "webkit/glue/webmenuitem.h" |
27 | 24 |
28 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
29 using base::android::ConvertJavaStringToUTF16; | |
30 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
31 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
32 using base::android::GetClass; | 28 using base::android::GetClass; |
33 using base::android::HasField; | 29 using base::android::HasField; |
34 using base::android::ScopedJavaGlobalRef; | 30 using base::android::ScopedJavaGlobalRef; |
35 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
36 using WebKit::WebInputEvent; | 32 using WebKit::WebInputEvent; |
37 using WebKit::WebInputEventFactory; | 33 using WebKit::WebInputEventFactory; |
38 | 34 |
39 // Describes the type and enabled state of a select popup item. | 35 // Describes the type and enabled state of a select popup item. |
(...skipping 29 matching lines...) Expand all Loading... |
69 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 65 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
70 jobject obj) { | 66 jobject obj) { |
71 return reinterpret_cast<ContentViewCore*>( | 67 return reinterpret_cast<ContentViewCore*>( |
72 env->GetIntField(obj, g_native_content_view)); | 68 env->GetIntField(obj, g_native_content_view)); |
73 } | 69 } |
74 | 70 |
75 // ---------------------------------------------------------------------------- | 71 // ---------------------------------------------------------------------------- |
76 | 72 |
77 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 73 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
78 WebContents* web_contents) | 74 WebContents* web_contents) |
79 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 75 : web_contents_(web_contents), |
80 tab_crashed_(false) { | 76 tab_crashed_(false) { |
81 DCHECK(web_contents) << | 77 DCHECK(web_contents) << |
82 "A ContentViewCoreImpl should be created with a valid WebContents."; | 78 "A ContentViewCoreImpl should be created with a valid WebContents."; |
83 | 79 |
84 InitJNI(env, obj); | 80 InitJNI(env, obj); |
85 } | 81 } |
86 | 82 |
87 ContentViewCoreImpl::~ContentViewCoreImpl() { | 83 ContentViewCoreImpl::~ContentViewCoreImpl() { |
88 if (java_object_) { | 84 if (java_object_) { |
89 JNIEnv* env = AttachCurrentThread(); | 85 JNIEnv* env = AttachCurrentThread(); |
(...skipping 23 matching lines...) Expand all Loading... |
113 RenderWidgetHostView* rwhv = NULL; | 109 RenderWidgetHostView* rwhv = NULL; |
114 if (web_contents_) | 110 if (web_contents_) |
115 rwhv = web_contents_->GetRenderWidgetHostView(); | 111 rwhv = web_contents_->GetRenderWidgetHostView(); |
116 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 112 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
117 } | 113 } |
118 | 114 |
119 // ---------------------------------------------------------------------------- | 115 // ---------------------------------------------------------------------------- |
120 // Methods called from Java via JNI | 116 // Methods called from Java via JNI |
121 // ---------------------------------------------------------------------------- | 117 // ---------------------------------------------------------------------------- |
122 | 118 |
123 void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, | |
124 jintArray indices) { | |
125 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | |
126 web_contents_->GetRenderViewHost()); | |
127 DCHECK(rvhi); | |
128 if (indices == NULL) { | |
129 rvhi->DidCancelPopupMenu(); | |
130 return; | |
131 } | |
132 | |
133 int selected_count = env->GetArrayLength(indices); | |
134 std::vector<int> selected_indices; | |
135 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); | |
136 for (int i = 0; i < selected_count; ++i) | |
137 selected_indices.push_back(indices_ptr[i]); | |
138 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); | |
139 rvhi->DidSelectPopupMenuItems(selected_indices); | |
140 } | |
141 | |
142 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, | 119 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, |
143 jobject, | 120 jobject, |
144 jstring jurl, | 121 jstring jurl, |
145 int page_transition) { | 122 int page_transition) { |
146 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 123 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
147 | 124 |
148 LoadUrl(url, page_transition); | 125 LoadUrl(url, page_transition); |
149 } | 126 } |
150 | 127 |
151 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitizationWithUserAgentOverride( | 128 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitizationWithUserAgentOverride( |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 306 |
330 void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { | 307 void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { |
331 scoped_ptr<ContentViewClient> client( | 308 scoped_ptr<ContentViewClient> client( |
332 ContentViewClient::CreateNativeContentViewClient(env, jclient)); | 309 ContentViewClient::CreateNativeContentViewClient(env, jclient)); |
333 | 310 |
334 web_contents_->SetDelegate(client.get()); | 311 web_contents_->SetDelegate(client.get()); |
335 | 312 |
336 content_view_client_.swap(client); | 313 content_view_client_.swap(client); |
337 } | 314 } |
338 | 315 |
339 void ContentViewCoreImpl::AddJavascriptInterface( | |
340 JNIEnv* env, | |
341 jobject /* obj */, | |
342 jobject object, | |
343 jstring name, | |
344 jboolean allow_inherited_methods) { | |
345 ScopedJavaLocalRef<jobject> scoped_object(env, object); | |
346 // JavaBoundObject creates the NPObject with a ref count of 1, and | |
347 // JavaBridgeDispatcherHostManager takes its own ref. | |
348 NPObject* bound_object = JavaBoundObject::Create(scoped_object, | |
349 allow_inherited_methods); | |
350 web_contents_->java_bridge_dispatcher_host_manager()->AddNamedObject( | |
351 ConvertJavaStringToUTF16(env, name), bound_object); | |
352 WebKit::WebBindings::releaseObject(bound_object); | |
353 } | |
354 | |
355 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | |
356 jobject /* obj */, | |
357 jstring name) { | |
358 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | |
359 ConvertJavaStringToUTF16(env, name)); | |
360 } | |
361 | |
362 // -------------------------------------------------------------------------- | 316 // -------------------------------------------------------------------------- |
363 // Methods called from native code | 317 // Methods called from native code |
364 // -------------------------------------------------------------------------- | 318 // -------------------------------------------------------------------------- |
365 | 319 |
366 void ContentViewCoreImpl::LoadUrl(const GURL& url, int page_transition) { | 320 void ContentViewCoreImpl::LoadUrl(const GURL& url, int page_transition) { |
367 content::Referrer referer; | 321 content::Referrer referer; |
368 | 322 |
369 web_contents()->GetController().LoadURL( | 323 web_contents()->GetController().LoadURL( |
370 url, referer, content::PageTransitionFromInt(page_transition), | 324 url, referer, content::PageTransitionFromInt(page_transition), |
371 std::string()); | 325 std::string()); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { | 459 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
506 JNIEnv* env = AttachCurrentThread(); | 460 JNIEnv* env = AttachCurrentThread(); |
507 ScopedJavaLocalRef<jstring> jcontent_url = | 461 ScopedJavaLocalRef<jstring> jcontent_url = |
508 ConvertUTF8ToJavaString(env, content_url.spec()); | 462 ConvertUTF8ToJavaString(env, content_url.spec()); |
509 Java_ContentViewCore_startContentIntent(env, | 463 Java_ContentViewCore_startContentIntent(env, |
510 java_object_->View(env).obj(), | 464 java_object_->View(env).obj(), |
511 jcontent_url.obj()); | 465 jcontent_url.obj()); |
512 } | 466 } |
513 | 467 |
514 // -------------------------------------------------------------------------- | 468 // -------------------------------------------------------------------------- |
| 469 // Methods called from Java via JNI |
| 470 // -------------------------------------------------------------------------- |
| 471 |
| 472 void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, |
| 473 jintArray indices) { |
| 474 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
| 475 web_contents_->GetRenderViewHost()); |
| 476 DCHECK(rvhi); |
| 477 if (indices == NULL) { |
| 478 rvhi->DidCancelPopupMenu(); |
| 479 return; |
| 480 } |
| 481 |
| 482 int selected_count = env->GetArrayLength(indices); |
| 483 std::vector<int> selected_indices; |
| 484 jint* indices_ptr = env->GetIntArrayElements(indices, NULL); |
| 485 for (int i = 0; i < selected_count; ++i) |
| 486 selected_indices.push_back(indices_ptr[i]); |
| 487 env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); |
| 488 rvhi->DidSelectPopupMenuItems(selected_indices); |
| 489 } |
| 490 |
| 491 // -------------------------------------------------------------------------- |
515 // Methods called from native code | 492 // Methods called from native code |
516 // -------------------------------------------------------------------------- | 493 // -------------------------------------------------------------------------- |
517 | 494 |
518 gfx::Rect ContentViewCoreImpl::GetBounds() const { | 495 gfx::Rect ContentViewCoreImpl::GetBounds() const { |
519 NOTIMPLEMENTED() << "not upstreamed yet"; | 496 NOTIMPLEMENTED() << "not upstreamed yet"; |
520 return gfx::Rect(); | 497 return gfx::Rect(); |
521 } | 498 } |
522 | 499 |
523 // ---------------------------------------------------------------------------- | 500 // ---------------------------------------------------------------------------- |
524 | 501 |
525 bool RegisterContentViewCore(JNIEnv* env) { | 502 bool RegisterContentViewCore(JNIEnv* env) { |
526 if (!base::android::HasClass(env, kContentViewCoreClassPath)) { | 503 if (!base::android::HasClass(env, kContentViewCoreClassPath)) { |
527 DLOG(ERROR) << "Unable to find class ContentViewCore!"; | 504 DLOG(ERROR) << "Unable to find class ContentViewCore!"; |
528 return false; | 505 return false; |
529 } | 506 } |
530 ScopedJavaLocalRef<jclass> clazz = GetClass(env, kContentViewCoreClassPath); | 507 ScopedJavaLocalRef<jclass> clazz = GetClass(env, kContentViewCoreClassPath); |
531 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 508 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
532 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 509 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
533 return false; | 510 return false; |
534 } | 511 } |
535 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 512 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
536 | 513 |
537 return RegisterNativesImpl(env) >= 0; | 514 return RegisterNativesImpl(env) >= 0; |
538 } | 515 } |
539 | 516 |
540 } // namespace content | 517 } // namespace content |
OLD | NEW |