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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 float dpi_scale, | 214 float dpi_scale, |
215 const JavaRef<jobject>& java_bridge_retained_object_set) | 215 const JavaRef<jobject>& java_bridge_retained_object_set) |
216 : WebContentsObserver(web_contents), | 216 : WebContentsObserver(web_contents), |
217 java_ref_(env, obj), | 217 java_ref_(env, obj), |
218 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 218 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
219 page_scale_(1), | 219 page_scale_(1), |
220 dpi_scale_(dpi_scale), | 220 dpi_scale_(dpi_scale), |
221 device_orientation_(0), | 221 device_orientation_(0), |
222 accessibility_enabled_(false) { | 222 accessibility_enabled_(false) { |
223 GetViewAndroid()->SetLayer(cc::Layer::Create()); | 223 GetViewAndroid()->SetLayer(cc::Layer::Create()); |
224 gfx::Size physical_size( | |
225 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
226 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
227 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
228 | 224 |
229 // Currently, the only use case we have for overriding a user agent involves | 225 // Currently, the only use case we have for overriding a user agent involves |
230 // spoofing a desktop Linux user agent for "Request desktop site". | 226 // spoofing a desktop Linux user agent for "Request desktop site". |
231 // Automatically set it for all WebContents so that it is available when a | 227 // Automatically set it for all WebContents so that it is available when a |
232 // NavigationEntry requires the user agent to be overridden. | 228 // NavigationEntry requires the user agent to be overridden. |
233 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 229 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
234 std::string product = content::GetContentClient()->GetProduct(); | 230 std::string product = content::GetContentClient()->GetProduct(); |
235 std::string spoofed_ua = | 231 std::string spoofed_ua = |
236 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 232 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
237 web_contents->SetUserAgentOverride(spoofed_ua); | 233 web_contents->SetUserAgentOverride(spoofed_ua); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 return Java_ContentViewCore_getContext(env, obj); | 645 return Java_ContentViewCore_getContext(env, obj); |
650 } | 646 } |
651 | 647 |
652 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 648 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
653 gfx::Size size = GetViewportSizeDip(); | 649 gfx::Size size = GetViewportSizeDip(); |
654 if (DoBrowserControlsShrinkBlinkSize()) | 650 if (DoBrowserControlsShrinkBlinkSize()) |
655 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); | 651 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); |
656 return size; | 652 return size; |
657 } | 653 } |
658 | 654 |
659 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | |
660 JNIEnv* env = AttachCurrentThread(); | |
661 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
662 if (j_obj.is_null()) | |
663 return gfx::Size(); | |
664 return gfx::Size( | |
665 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), | |
666 Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj)); | |
667 } | |
668 | |
669 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { | 655 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { |
670 JNIEnv* env = AttachCurrentThread(); | 656 JNIEnv* env = AttachCurrentThread(); |
671 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 657 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
672 if (j_obj.is_null()) | 658 if (j_obj.is_null()) |
673 return gfx::Size(); | 659 return gfx::Size(); |
674 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), | 660 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), |
675 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); | 661 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); |
676 } | 662 } |
677 | 663 |
678 int ContentViewCoreImpl::GetTopControlsHeightPix() const { | 664 int ContentViewCoreImpl::GetTopControlsHeightPix() const { |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 void ContentViewCoreImpl::RemoveJavascriptInterface( | 1009 void ContentViewCoreImpl::RemoveJavascriptInterface( |
1024 JNIEnv* env, | 1010 JNIEnv* env, |
1025 const JavaParamRef<jobject>& /* obj */, | 1011 const JavaParamRef<jobject>& /* obj */, |
1026 const JavaParamRef<jstring>& name) { | 1012 const JavaParamRef<jstring>& name) { |
1027 java_bridge_dispatcher_host_->RemoveNamedObject( | 1013 java_bridge_dispatcher_host_->RemoveNamedObject( |
1028 ConvertJavaStringToUTF8(env, name)); | 1014 ConvertJavaStringToUTF8(env, name)); |
1029 } | 1015 } |
1030 | 1016 |
1031 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1017 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
1032 const JavaParamRef<jobject>& obj) { | 1018 const JavaParamRef<jobject>& obj) { |
1033 gfx::Size physical_size( | 1019 GetViewAndroid()->UpdateLayerBounds(); |
1034 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
1035 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
1036 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
1037 | |
1038 SendScreenRectsAndResizeWidget(); | 1020 SendScreenRectsAndResizeWidget(); |
1039 } | 1021 } |
1040 | 1022 |
1041 void ContentViewCoreImpl::SetAccessibilityEnabled( | 1023 void ContentViewCoreImpl::SetAccessibilityEnabled( |
1042 JNIEnv* env, | 1024 JNIEnv* env, |
1043 const JavaParamRef<jobject>& obj, | 1025 const JavaParamRef<jobject>& obj, |
1044 bool enabled) { | 1026 bool enabled) { |
1045 SetAccessibilityEnabledInternal(enabled); | 1027 SetAccessibilityEnabledInternal(enabled); |
1046 } | 1028 } |
1047 | 1029 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 return ScopedJavaLocalRef<jobject>(); | 1257 return ScopedJavaLocalRef<jobject>(); |
1276 | 1258 |
1277 return view->GetJavaObject(); | 1259 return view->GetJavaObject(); |
1278 } | 1260 } |
1279 | 1261 |
1280 bool RegisterContentViewCore(JNIEnv* env) { | 1262 bool RegisterContentViewCore(JNIEnv* env) { |
1281 return RegisterNativesImpl(env); | 1263 return RegisterNativesImpl(env); |
1282 } | 1264 } |
1283 | 1265 |
1284 } // namespace content | 1266 } // namespace content |
OLD | NEW |