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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 698 |
704 void ContentViewCoreImpl::SetVSyncNotificationEnabled(bool enabled) { | 699 void ContentViewCoreImpl::SetVSyncNotificationEnabled(bool enabled) { |
705 JNIEnv* env = AttachCurrentThread(); | 700 JNIEnv* env = AttachCurrentThread(); |
706 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 701 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
707 if (obj.is_null()) | 702 if (obj.is_null()) |
708 return; | 703 return; |
709 Java_ContentViewCore_setVSyncNotificationEnabled( | 704 Java_ContentViewCore_setVSyncNotificationEnabled( |
710 env, obj.obj(), static_cast<jboolean>(enabled)); | 705 env, obj.obj(), static_cast<jboolean>(enabled)); |
711 } | 706 } |
712 | 707 |
| 708 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
| 709 // view_android_ should never be null for Chrome. |
| 710 DCHECK(view_android_); |
| 711 return view_android_; |
| 712 } |
| 713 |
713 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 714 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
714 // This should never be NULL for Chrome, but will be NULL for WebView. | 715 // This should never be NULL for Chrome, but will be NULL for WebView. |
715 DCHECK(window_android_); | 716 DCHECK(window_android_); |
716 return window_android_; | 717 return window_android_; |
717 } | 718 } |
718 | 719 |
719 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 720 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
720 return root_layer_.get(); | 721 return root_layer_.get(); |
721 } | 722 } |
722 | 723 |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | 1513 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); |
1513 controller.ReloadOriginalRequestURL(false); | 1514 controller.ReloadOriginalRequestURL(false); |
1514 } | 1515 } |
1515 } | 1516 } |
1516 | 1517 |
1517 // This is called for each ContentView. | 1518 // This is called for each ContentView. |
1518 jint Init(JNIEnv* env, jobject obj, | 1519 jint Init(JNIEnv* env, jobject obj, |
1519 jboolean input_events_delivered_at_vsync, | 1520 jboolean input_events_delivered_at_vsync, |
1520 jboolean hardware_accelerated, | 1521 jboolean hardware_accelerated, |
1521 jint native_web_contents, | 1522 jint native_web_contents, |
1522 jint native_window) { | 1523 jint view_android, |
| 1524 jint window_android) { |
1523 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1525 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1524 env, obj, input_events_delivered_at_vsync, hardware_accelerated, | 1526 env, obj, input_events_delivered_at_vsync, hardware_accelerated, |
1525 reinterpret_cast<WebContents*>(native_web_contents), | 1527 reinterpret_cast<WebContents*>(native_web_contents), |
1526 reinterpret_cast<ui::WindowAndroid*>(native_window)); | 1528 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1529 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1527 return reinterpret_cast<jint>(view); | 1530 return reinterpret_cast<jint>(view); |
1528 } | 1531 } |
1529 | 1532 |
1530 bool RegisterContentViewCore(JNIEnv* env) { | 1533 bool RegisterContentViewCore(JNIEnv* env) { |
1531 return RegisterNativesImpl(env); | 1534 return RegisterNativesImpl(env); |
1532 } | 1535 } |
1533 | 1536 |
1534 } // namespace content | 1537 } // namespace content |
OLD | NEW |