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" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 java_ref_(env, obj), | 219 java_ref_(env, obj), |
220 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 220 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
221 root_layer_(cc::SolidColorLayer::Create()), | 221 root_layer_(cc::SolidColorLayer::Create()), |
222 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 222 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
223 view_android_(view_android), | 223 view_android_(view_android), |
224 window_android_(window_android), | 224 window_android_(window_android), |
225 device_orientation_(0), | 225 device_orientation_(0), |
226 accessibility_enabled_(false) { | 226 accessibility_enabled_(false) { |
227 CHECK(web_contents) << | 227 CHECK(web_contents) << |
228 "A ContentViewCoreImpl should be created with a valid WebContents."; | 228 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 229 DCHECK(view_android_); |
| 230 DCHECK(window_android_); |
229 | 231 |
230 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); | 232 root_layer_->SetBackgroundColor(GetBackgroundColor(env, obj)); |
231 gfx::Size physical_size( | 233 gfx::Size physical_size( |
232 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 234 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
233 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 235 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
234 root_layer_->SetBounds(physical_size); | 236 root_layer_->SetBounds(physical_size); |
235 root_layer_->SetIsDrawable(true); | 237 root_layer_->SetIsDrawable(true); |
236 | 238 |
237 // Currently, the only use case we have for overriding a user agent involves | 239 // Currently, the only use case we have for overriding a user agent involves |
238 // spoofing a desktop Linux user agent for "Request desktop site". | 240 // spoofing a desktop Linux user agent for "Request desktop site". |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 const gfx::SizeF& content_size, | 388 const gfx::SizeF& content_size, |
387 const gfx::SizeF& viewport_size, | 389 const gfx::SizeF& viewport_size, |
388 const gfx::Vector2dF& controls_offset, | 390 const gfx::Vector2dF& controls_offset, |
389 const gfx::Vector2dF& content_offset, | 391 const gfx::Vector2dF& content_offset, |
390 float overdraw_bottom_height) { | 392 float overdraw_bottom_height) { |
391 JNIEnv* env = AttachCurrentThread(); | 393 JNIEnv* env = AttachCurrentThread(); |
392 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 394 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
393 if (obj.is_null()) | 395 if (obj.is_null()) |
394 return; | 396 return; |
395 | 397 |
396 if (window_android_) { | 398 window_android_->set_content_offset( |
397 window_android_->set_content_offset( | 399 gfx::ScaleVector2d(content_offset, dpi_scale_)); |
398 gfx::ScaleVector2d(content_offset, dpi_scale_)); | |
399 } | |
400 | 400 |
401 Java_ContentViewCore_updateFrameInfo( | 401 Java_ContentViewCore_updateFrameInfo( |
402 env, obj.obj(), | 402 env, obj.obj(), |
403 scroll_offset.x(), | 403 scroll_offset.x(), |
404 scroll_offset.y(), | 404 scroll_offset.y(), |
405 page_scale_factor, | 405 page_scale_factor, |
406 page_scale_factor_limits.x(), | 406 page_scale_factor_limits.x(), |
407 page_scale_factor_limits.y(), | 407 page_scale_factor_limits.y(), |
408 content_size.width(), | 408 content_size.width(), |
409 content_size.height(), | 409 content_size.height(), |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 if (!root_layer_->children().size()) | 789 if (!root_layer_->children().size()) |
790 root_layer_->SetIsDrawable(true); | 790 root_layer_->SetIsDrawable(true); |
791 } | 791 } |
792 | 792 |
793 void ContentViewCoreImpl::LoadUrl( | 793 void ContentViewCoreImpl::LoadUrl( |
794 NavigationController::LoadURLParams& params) { | 794 NavigationController::LoadURLParams& params) { |
795 GetWebContents()->GetController().LoadURLWithParams(params); | 795 GetWebContents()->GetController().LoadURLWithParams(params); |
796 } | 796 } |
797 | 797 |
798 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 798 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
799 // view_android_ should never be null for Chrome. | |
800 DCHECK(view_android_); | |
801 return view_android_; | 799 return view_android_; |
802 } | 800 } |
803 | 801 |
804 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 802 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
805 // This should never be NULL for Chrome, but will be NULL for WebView. | |
806 DCHECK(window_android_); | |
807 return window_android_; | 803 return window_android_; |
808 } | 804 } |
809 | 805 |
810 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { | 806 scoped_refptr<cc::Layer> ContentViewCoreImpl::GetLayer() const { |
811 return root_layer_.get(); | 807 return root_layer_.get(); |
812 } | 808 } |
813 | 809 |
814 // ---------------------------------------------------------------------------- | 810 // ---------------------------------------------------------------------------- |
815 // Methods called from Java via JNI | 811 // Methods called from Java via JNI |
816 // ---------------------------------------------------------------------------- | 812 // ---------------------------------------------------------------------------- |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1653 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1658 retained_objects_set); | 1654 retained_objects_set); |
1659 return reinterpret_cast<intptr_t>(view); | 1655 return reinterpret_cast<intptr_t>(view); |
1660 } | 1656 } |
1661 | 1657 |
1662 bool RegisterContentViewCore(JNIEnv* env) { | 1658 bool RegisterContentViewCore(JNIEnv* env) { |
1663 return RegisterNativesImpl(env); | 1659 return RegisterNativesImpl(env); |
1664 } | 1660 } |
1665 | 1661 |
1666 } // namespace content | 1662 } // namespace content |
OLD | NEW |