OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
| 18 #include "cc/layers/solid_color_layer.h" |
18 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
19 #include "content/browser/android/gesture_event_type.h" | 20 #include "content/browser/android/gesture_event_type.h" |
20 #include "content/browser/android/interstitial_page_delegate_android.h" | 21 #include "content/browser/android/interstitial_page_delegate_android.h" |
21 #include "content/browser/android/load_url_params.h" | 22 #include "content/browser/android/load_url_params.h" |
22 #include "content/browser/frame_host/interstitial_page_impl.h" | 23 #include "content/browser/frame_host/interstitial_page_impl.h" |
23 #include "content/browser/frame_host/navigation_controller_impl.h" | 24 #include "content/browser/frame_host/navigation_controller_impl.h" |
24 #include "content/browser/frame_host/navigation_entry_impl.h" | 25 #include "content/browser/frame_host/navigation_entry_impl.h" |
25 #include "content/browser/media/android/browser_media_player_manager.h" | 26 #include "content/browser/media/android/browser_media_player_manager.h" |
26 #include "content/browser/renderer_host/compositor_impl_android.h" | 27 #include "content/browser/renderer_host/compositor_impl_android.h" |
27 #include "content/browser/renderer_host/input/motion_event_android.h" | 28 #include "content/browser/renderer_host/input/motion_event_android.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 211 } |
211 | 212 |
212 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, | 213 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, |
213 jobject obj, | 214 jobject obj, |
214 WebContents* web_contents, | 215 WebContents* web_contents, |
215 ui::ViewAndroid* view_android, | 216 ui::ViewAndroid* view_android, |
216 ui::WindowAndroid* window_android) | 217 ui::WindowAndroid* window_android) |
217 : WebContentsObserver(web_contents), | 218 : WebContentsObserver(web_contents), |
218 java_ref_(env, obj), | 219 java_ref_(env, obj), |
219 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 220 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
220 root_layer_(cc::Layer::Create()), | 221 root_layer_(cc::SolidColorLayer::Create()), |
221 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 222 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
222 view_android_(view_android), | 223 view_android_(view_android), |
223 window_android_(window_android), | 224 window_android_(window_android), |
224 device_orientation_(0), | 225 device_orientation_(0), |
225 geolocation_needs_pause_(false) { | 226 geolocation_needs_pause_(false) { |
226 CHECK(web_contents) << | 227 CHECK(web_contents) << |
227 "A ContentViewCoreImpl should be created with a valid WebContents."; | 228 "A ContentViewCoreImpl should be created with a valid WebContents."; |
228 | 229 |
| 230 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); |
| 231 gfx::Size physical_size( |
| 232 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 233 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 234 root_layer_->SetBounds(physical_size); |
| 235 root_layer_->SetIsDrawable(true); |
| 236 |
229 // Currently, the only use case we have for overriding a user agent involves | 237 // Currently, the only use case we have for overriding a user agent involves |
230 // spoofing a desktop Linux user agent for "Request desktop site". | 238 // spoofing a desktop Linux user agent for "Request desktop site". |
231 // Automatically set it for all WebContents so that it is available when a | 239 // Automatically set it for all WebContents so that it is available when a |
232 // NavigationEntry requires the user agent to be overridden. | 240 // NavigationEntry requires the user agent to be overridden. |
233 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 241 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
234 std::string product = content::GetContentClient()->GetProduct(); | 242 std::string product = content::GetContentClient()->GetProduct(); |
235 std::string spoofed_ua = | 243 std::string spoofed_ua = |
236 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 244 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
237 web_contents->SetUserAgentOverride(spoofed_ua); | 245 web_contents->SetUserAgentOverride(spoofed_ua); |
238 | 246 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 JNIEnv* env = AttachCurrentThread(); | 476 JNIEnv* env = AttachCurrentThread(); |
469 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 477 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
470 if (obj.is_null()) | 478 if (obj.is_null()) |
471 return; | 479 return; |
472 ScopedJavaLocalRef<jstring> jtitle = | 480 ScopedJavaLocalRef<jstring> jtitle = |
473 ConvertUTF8ToJavaString(env, base::UTF16ToUTF8(title)); | 481 ConvertUTF8ToJavaString(env, base::UTF16ToUTF8(title)); |
474 Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); | 482 Java_ContentViewCore_setTitle(env, obj.obj(), jtitle.obj()); |
475 } | 483 } |
476 | 484 |
477 void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) { | 485 void ContentViewCoreImpl::OnBackgroundColorChanged(SkColor color) { |
| 486 root_layer_->SetBackgroundColor(color); |
| 487 |
478 JNIEnv* env = AttachCurrentThread(); | 488 JNIEnv* env = AttachCurrentThread(); |
479 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 489 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
480 if (obj.is_null()) | 490 if (obj.is_null()) |
481 return; | 491 return; |
482 Java_ContentViewCore_onBackgroundColorChanged(env, obj.obj(), color); | 492 Java_ContentViewCore_onBackgroundColorChanged(env, obj.obj(), color); |
483 } | 493 } |
484 | 494 |
485 void ContentViewCoreImpl::ShowSelectPopupMenu(const gfx::Rect& bounds, | 495 void ContentViewCoreImpl::ShowSelectPopupMenu(const gfx::Rect& bounds, |
486 const std::vector<MenuItem>& items, int selected_item, bool multiple) { | 496 const std::vector<MenuItem>& items, int selected_item, bool multiple) { |
487 JNIEnv* env = AttachCurrentThread(); | 497 JNIEnv* env = AttachCurrentThread(); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 JNIEnv* env = AttachCurrentThread(); | 843 JNIEnv* env = AttachCurrentThread(); |
834 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 844 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
835 if (j_obj.is_null()) | 845 if (j_obj.is_null()) |
836 return 0.f; | 846 return 0.f; |
837 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) | 847 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) |
838 / dpi_scale(); | 848 / dpi_scale(); |
839 } | 849 } |
840 | 850 |
841 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { | 851 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { |
842 root_layer_->AddChild(layer); | 852 root_layer_->AddChild(layer); |
| 853 root_layer_->SetIsDrawable(false); |
843 } | 854 } |
844 | 855 |
845 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 856 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
846 layer->RemoveFromParent(); | 857 layer->RemoveFromParent(); |
| 858 |
| 859 if (!root_layer_->children().size()) |
| 860 root_layer_->SetIsDrawable(true); |
847 } | 861 } |
848 | 862 |
849 void ContentViewCoreImpl::LoadUrl( | 863 void ContentViewCoreImpl::LoadUrl( |
850 NavigationController::LoadURLParams& params) { | 864 NavigationController::LoadURLParams& params) { |
851 GetWebContents()->GetController().LoadURLWithParams(params); | 865 GetWebContents()->GetController().LoadURLWithParams(params); |
852 } | 866 } |
853 | 867 |
854 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 868 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
855 // view_android_ should never be null for Chrome. | 869 // view_android_ should never be null for Chrome. |
856 DCHECK(view_android_); | 870 DCHECK(view_android_); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 | 1307 |
1294 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1308 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
1295 jobject /* obj */, | 1309 jobject /* obj */, |
1296 jstring name) { | 1310 jstring name) { |
1297 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | 1311 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( |
1298 ConvertJavaStringToUTF16(env, name)); | 1312 ConvertJavaStringToUTF16(env, name)); |
1299 } | 1313 } |
1300 | 1314 |
1301 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1315 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
1302 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1316 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 1317 gfx::Size physical_size( |
| 1318 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
| 1319 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
| 1320 root_layer_->SetBounds(physical_size); |
| 1321 |
1303 if (view) { | 1322 if (view) { |
1304 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 1323 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
1305 view->GetRenderWidgetHost()); | 1324 view->GetRenderWidgetHost()); |
1306 host->SendScreenRects(); | 1325 host->SendScreenRects(); |
1307 view->WasResized(); | 1326 view->WasResized(); |
1308 } | 1327 } |
1309 } | 1328 } |
1310 | 1329 |
1311 void ContentViewCoreImpl::ShowInterstitialPage( | 1330 void ContentViewCoreImpl::ShowInterstitialPage( |
1312 JNIEnv* env, jobject obj, jstring jurl, jlong delegate_ptr) { | 1331 JNIEnv* env, jobject obj, jstring jurl, jlong delegate_ptr) { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1687 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1669 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1688 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1670 return reinterpret_cast<intptr_t>(view); | 1689 return reinterpret_cast<intptr_t>(view); |
1671 } | 1690 } |
1672 | 1691 |
1673 bool RegisterContentViewCore(JNIEnv* env) { | 1692 bool RegisterContentViewCore(JNIEnv* env) { |
1674 return RegisterNativesImpl(env); | 1693 return RegisterNativesImpl(env); |
1675 } | 1694 } |
1676 | 1695 |
1677 } // namespace content | 1696 } // namespace content |
OLD | NEW |