| 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/gfx/android/java_bitmap.h" | 49 #include "ui/gfx/android/java_bitmap.h" |
| 49 #include "ui/gfx/android/window_android.h" | 50 #include "ui/gfx/android/window_android.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), |
| 161 renderer_frame_pending_(false), | 163 renderer_frame_pending_(false), |
| 164 view_android_(view_android), |
| 162 window_android_(window_android) { | 165 window_android_(window_android) { |
| 163 CHECK(web_contents) << | 166 CHECK(web_contents) << |
| 164 "A ContentViewCoreImpl should be created with a valid WebContents."; | 167 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 165 | 168 |
| 166 // When a tab is restored (from a saved state), it does not have a renderer | 169 // When a tab is restored (from a saved state), it does not have a renderer |
| 167 // process. We treat it like the tab is crashed. If the content is loaded | 170 // process. We treat it like the tab is crashed. If the content is loaded |
| 168 // when the tab is shown, tab_crashed_ will be reset. Since | 171 // when the tab is shown, tab_crashed_ will be reset. Since |
| 169 // RenderWidgetHostView is associated with the lifetime of the renderer | 172 // RenderWidgetHostView is associated with the lifetime of the renderer |
| 170 // process, we use it to test whether there is a renderer process. | 173 // process, we use it to test whether there is a renderer process. |
| 171 tab_crashed_ = !(web_contents->GetRenderWidgetHostView()); | 174 tab_crashed_ = !(web_contents->GetRenderWidgetHostView()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 296 } |
| 294 } | 297 } |
| 295 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | 298 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
| 296 } | 299 } |
| 297 | 300 |
| 298 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetJavaObject() { | 301 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetJavaObject() { |
| 299 JNIEnv* env = AttachCurrentThread(); | 302 JNIEnv* env = AttachCurrentThread(); |
| 300 return java_ref_.get(env); | 303 return java_ref_.get(env); |
| 301 } | 304 } |
| 302 | 305 |
| 303 ScopedJavaLocalRef<jobject> ContentViewCoreImpl::GetContainerViewDelegate() { | |
| 304 JNIEnv* env = AttachCurrentThread(); | |
| 305 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 306 if (obj.is_null()) | |
| 307 return ScopedJavaLocalRef<jobject>(); | |
| 308 return Java_ContentViewCore_getContainerViewDelegate(env, obj.obj()); | |
| 309 } | |
| 310 | |
| 311 void ContentViewCoreImpl::OnWebPreferencesUpdated() { | 306 void ContentViewCoreImpl::OnWebPreferencesUpdated() { |
| 312 JNIEnv* env = AttachCurrentThread(); | 307 JNIEnv* env = AttachCurrentThread(); |
| 313 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 308 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 314 if (!obj.is_null()) | 309 if (!obj.is_null()) |
| 315 Java_ContentViewCore_onWebPreferencesUpdated(env, obj.obj()); | 310 Java_ContentViewCore_onWebPreferencesUpdated(env, obj.obj()); |
| 316 } | 311 } |
| 317 | 312 |
| 318 jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { | 313 jint ContentViewCoreImpl::GetBackgroundColor(JNIEnv* env, jobject obj) { |
| 319 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 314 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 320 if (!rwhva) | 315 if (!rwhva) |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 void ContentViewCoreImpl::DidProduceRendererFrame() { | 665 void ContentViewCoreImpl::DidProduceRendererFrame() { |
| 671 renderer_frame_pending_ = true; | 666 renderer_frame_pending_ = true; |
| 672 } | 667 } |
| 673 | 668 |
| 674 void ContentViewCoreImpl::LoadUrl( | 669 void ContentViewCoreImpl::LoadUrl( |
| 675 NavigationController::LoadURLParams& params) { | 670 NavigationController::LoadURLParams& params) { |
| 676 GetWebContents()->GetController().LoadURLWithParams(params); | 671 GetWebContents()->GetController().LoadURLWithParams(params); |
| 677 tab_crashed_ = false; | 672 tab_crashed_ = false; |
| 678 } | 673 } |
| 679 | 674 |
| 675 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
| 676 return view_android_; |
| 677 } |
| 678 |
| 680 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 679 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
| 681 return window_android_; | 680 return window_android_; |
| 682 } | 681 } |
| 683 | 682 |
| 684 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 683 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
| 685 return root_layer_.get(); | 684 return root_layer_.get(); |
| 686 } | 685 } |
| 687 | 686 |
| 688 // ---------------------------------------------------------------------------- | 687 // ---------------------------------------------------------------------------- |
| 689 // Methods called from Java via JNI | 688 // Methods called from Java via JNI |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | 1465 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); |
| 1467 controller.ReloadOriginalRequestURL(false); | 1466 controller.ReloadOriginalRequestURL(false); |
| 1468 } | 1467 } |
| 1469 } | 1468 } |
| 1470 | 1469 |
| 1471 // This is called for each ContentView. | 1470 // This is called for each ContentView. |
| 1472 jint Init(JNIEnv* env, jobject obj, | 1471 jint Init(JNIEnv* env, jobject obj, |
| 1473 jboolean input_events_delivered_at_vsync, | 1472 jboolean input_events_delivered_at_vsync, |
| 1474 jboolean hardware_accelerated, | 1473 jboolean hardware_accelerated, |
| 1475 jint native_web_contents, | 1474 jint native_web_contents, |
| 1475 jint native_view, |
| 1476 jint native_window) { | 1476 jint native_window) { |
| 1477 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1477 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1478 env, obj, input_events_delivered_at_vsync, hardware_accelerated, | 1478 env, obj, input_events_delivered_at_vsync, hardware_accelerated, |
| 1479 reinterpret_cast<WebContents*>(native_web_contents), | 1479 reinterpret_cast<WebContents*>(native_web_contents), |
| 1480 reinterpret_cast<ui::ViewAndroid*>(native_view), |
| 1480 reinterpret_cast<ui::WindowAndroid*>(native_window)); | 1481 reinterpret_cast<ui::WindowAndroid*>(native_window)); |
| 1481 return reinterpret_cast<jint>(view); | 1482 return reinterpret_cast<jint>(view); |
| 1482 } | 1483 } |
| 1483 | 1484 |
| 1484 bool RegisterContentViewCore(JNIEnv* env) { | 1485 bool RegisterContentViewCore(JNIEnv* env) { |
| 1485 return RegisterNativesImpl(env); | 1486 return RegisterNativesImpl(env); |
| 1486 } | 1487 } |
| 1487 | 1488 |
| 1488 } // namespace content | 1489 } // namespace content |
| OLD | NEW |