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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
39 #include "content/public/browser/notification_types.h" | 39 #include "content/public/browser/notification_types.h" |
40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
41 #include "content/public/common/content_client.h" | 41 #include "content/public/common/content_client.h" |
42 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
43 #include "content/public/common/page_transition_types.h" | 43 #include "content/public/common/page_transition_types.h" |
44 #include "jni/ContentViewCore_jni.h" | 44 #include "jni/ContentViewCore_jni.h" |
45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
47 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent
Factory.h" |
| 48 #include "ui/android/view_android.h" |
48 #include "ui/android/window_android.h" | 49 #include "ui/android/window_android.h" |
49 #include "ui/gfx/android/java_bitmap.h" | 50 #include "ui/gfx/android/java_bitmap.h" |
50 #include "ui/gfx/screen.h" | 51 #include "ui/gfx/screen.h" |
51 #include "ui/gfx/size_conversions.h" | 52 #include "ui/gfx/size_conversions.h" |
52 #include "ui/gfx/size_f.h" | 53 #include "ui/gfx/size_f.h" |
53 #include "webkit/glue/webmenuitem.h" | 54 #include "webkit/glue/webmenuitem.h" |
54 #include "webkit/user_agent/user_agent_util.h" | 55 #include "webkit/user_agent/user_agent_util.h" |
55 | 56 |
56 using base::android::AttachCurrentThread; | 57 using base::android::AttachCurrentThread; |
57 using base::android::ConvertJavaStringToUTF16; | 58 using base::android::ConvertJavaStringToUTF16; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 146 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
146 jobject obj) { | 147 jobject obj) { |
147 return reinterpret_cast<ContentViewCore*>( | 148 return reinterpret_cast<ContentViewCore*>( |
148 Java_ContentViewCore_getNativeContentViewCore(env, obj)); | 149 Java_ContentViewCore_getNativeContentViewCore(env, obj)); |
149 } | 150 } |
150 | 151 |
151 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 152 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
152 bool hardware_accelerated, | 153 bool hardware_accelerated, |
153 bool input_events_delivered_at_vsync, | 154 bool input_events_delivered_at_vsync, |
154 WebContents* web_contents, | 155 WebContents* web_contents, |
| 156 ui::ViewAndroid* view_android, |
155 ui::WindowAndroid* window_android) | 157 ui::WindowAndroid* window_android) |
156 : java_ref_(env, obj), | 158 : java_ref_(env, obj), |
157 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 159 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
158 root_layer_(cc::Layer::Create()), | 160 root_layer_(cc::Layer::Create()), |
159 tab_crashed_(false), | 161 tab_crashed_(false), |
160 input_events_delivered_at_vsync_(input_events_delivered_at_vsync), | 162 input_events_delivered_at_vsync_(input_events_delivered_at_vsync), |
| 163 view_android_(view_android), |
161 window_android_(window_android) { | 164 window_android_(window_android) { |
162 CHECK(web_contents) << | 165 CHECK(web_contents) << |
163 "A ContentViewCoreImpl should be created with a valid WebContents."; | 166 "A ContentViewCoreImpl should be created with a valid WebContents."; |
164 | 167 |
165 // When a tab is restored (from a saved state), it does not have a renderer | 168 // When a tab is restored (from a saved state), it does not have a renderer |
166 // process. We treat it like the tab is crashed. If the content is loaded | 169 // process. We treat it like the tab is crashed. If the content is loaded |
167 // when the tab is shown, tab_crashed_ will be reset. Since | 170 // when the tab is shown, tab_crashed_ will be reset. Since |
168 // RenderWidgetHostView is associated with the lifetime of the renderer | 171 // RenderWidgetHostView is associated with the lifetime of the renderer |
169 // process, we use it to test whether there is a renderer process. | 172 // process, we use it to test whether there is a renderer process. |
170 tab_crashed_ = !(web_contents->GetRenderWidgetHostView()); | 173 tab_crashed_ = !(web_contents->GetRenderWidgetHostView()); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 305 } |
303 } | 306 } |
304 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 307 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
305 } | 308 } |
306 | 309 |
307 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetJavaObject() { | 310 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetJavaObject() { |
308 JNIEnv* env = AttachCurrentThread(); | 311 JNIEnv* env = AttachCurrentThread(); |
309 return java_ref_.get(env); | 312 return java_ref_.get(env); |
310 } | 313 } |
311 | 314 |
312 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetContainerViewDelegate() { | |
313 JNIEnv* env = AttachCurrentThread(); | |
314 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
315 if (obj.is_null()) | |
316 return ScopedJavaLocalRef<jobject>(); | |
317 return Java_ContentViewCore_getContainerViewDelegate(env, obj.obj()); | |
318 } | |
319 | |
320 void ContentViewCoreImpl::OnWebPreferencesUpdated() { | 315 void ContentViewCoreImpl::OnWebPreferencesUpdated() { |
321 JNIEnv* env = AttachCurrentThread(); | 316 JNIEnv* env = AttachCurrentThread(); |
322 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 317 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
323 if (!obj.is_null()) | 318 if (!obj.is_null()) |
324 Java_ContentViewCore_onWebPreferencesUpdated(env, obj.obj()); | 319 Java_ContentViewCore_onWebPreferencesUpdated(env, obj.obj()); |
325 } | 320 } |
326 | 321 |
327 jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { | 322 jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { |
328 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 323 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
329 if (!rwhva) | 324 if (!rwhva) |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 687 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
693 layer->RemoveFromParent(); | 688 layer->RemoveFromParent(); |
694 } | 689 } |
695 | 690 |
696 void ContentViewCoreImpl::LoadUrl( | 691 void ContentViewCoreImpl::LoadUrl( |
697 NavigationController::LoadURLParams& params) { | 692 NavigationController::LoadURLParams& params) { |
698 GetWebContents()->GetController().LoadURLWithParams(params); | 693 GetWebContents()->GetController().LoadURLWithParams(params); |
699 tab_crashed_ = false; | 694 tab_crashed_ = false; |
700 } | 695 } |
701 | 696 |
| 697 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
| 698 // view_android_ should never be null for Chrome. |
| 699 DCHECK(view_android_); |
| 700 return view_android_; |
| 701 } |
| 702 |
702 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 703 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
703 // This should never be NULL for Chrome, but will be NULL for WebView. | 704 // This should never be NULL for Chrome, but will be NULL for WebView. |
704 DCHECK(window_android_); | 705 DCHECK(window_android_); |
705 return window_android_; | 706 return window_android_; |
706 } | 707 } |
707 | 708 |
708 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 709 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
709 return root_layer_.get(); | 710 return root_layer_.get(); |
710 } | 711 } |
711 | 712 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | 1488 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); |
1488 controller.ReloadOriginalRequestURL(false); | 1489 controller.ReloadOriginalRequestURL(false); |
1489 } | 1490 } |
1490 } | 1491 } |
1491 | 1492 |
1492 // This is called for each ContentView. | 1493 // This is called for each ContentView. |
1493 jint Init(JNIEnv* env, jobject obj, | 1494 jint Init(JNIEnv* env, jobject obj, |
1494 jboolean input_events_delivered_at_vsync, | 1495 jboolean input_events_delivered_at_vsync, |
1495 jboolean hardware_accelerated, | 1496 jboolean hardware_accelerated, |
1496 jint native_web_contents, | 1497 jint native_web_contents, |
1497 jint native_window) { | 1498 jint view_android, |
| 1499 jint window_android) { |
1498 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1500 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1499 env, obj, input_events_delivered_at_vsync, hardware_accelerated, | 1501 env, obj, input_events_delivered_at_vsync, hardware_accelerated, |
1500 reinterpret_cast<WebContents*>(native_web_contents), | 1502 reinterpret_cast<WebContents*>(native_web_contents), |
1501 reinterpret_cast<ui::WindowAndroid*>(native_window)); | 1503 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1504 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1502 return reinterpret_cast<jint>(view); | 1505 return reinterpret_cast<jint>(view); |
1503 } | 1506 } |
1504 | 1507 |
1505 bool RegisterContentViewCore(JNIEnv* env) { | 1508 bool RegisterContentViewCore(JNIEnv* env) { |
1506 return RegisterNativesImpl(env); | 1509 return RegisterNativesImpl(env); |
1507 } | 1510 } |
1508 | 1511 |
1509 } // namespace content | 1512 } // namespace content |
OLD | NEW |