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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 WebContents* web_contents, | 223 WebContents* web_contents, |
224 float dpi_scale, | 224 float dpi_scale, |
225 const JavaRef<jobject>& java_bridge_retained_object_set) | 225 const JavaRef<jobject>& java_bridge_retained_object_set) |
226 : WebContentsObserver(web_contents), | 226 : WebContentsObserver(web_contents), |
227 java_ref_(env, obj), | 227 java_ref_(env, obj), |
228 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 228 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
229 page_scale_(1), | 229 page_scale_(1), |
230 dpi_scale_(dpi_scale), | 230 dpi_scale_(dpi_scale), |
231 device_orientation_(0), | 231 device_orientation_(0), |
232 accessibility_enabled_(false) { | 232 accessibility_enabled_(false) { |
233 GetViewAndroid()->SetLayer(cc::Layer::Create()); | |
234 gfx::Size physical_size( | |
235 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
236 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
237 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
238 | |
239 // Currently, the only use case we have for overriding a user agent involves | 233 // Currently, the only use case we have for overriding a user agent involves |
240 // spoofing a desktop Linux user agent for "Request desktop site". | 234 // spoofing a desktop Linux user agent for "Request desktop site". |
241 // Automatically set it for all WebContents so that it is available when a | 235 // Automatically set it for all WebContents so that it is available when a |
242 // NavigationEntry requires the user agent to be overridden. | 236 // NavigationEntry requires the user agent to be overridden. |
243 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 237 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
244 std::string product = content::GetContentClient()->GetProduct(); | 238 std::string product = content::GetContentClient()->GetProduct(); |
245 std::string spoofed_ua = | 239 std::string spoofed_ua = |
246 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 240 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
247 web_contents->SetUserAgentOverride(spoofed_ua); | 241 web_contents->SetUserAgentOverride(spoofed_ua); |
248 | 242 |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 return size_dip; | 722 return size_dip; |
729 } | 723 } |
730 | 724 |
731 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 725 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
732 gfx::Size size = GetViewportSizeDip(); | 726 gfx::Size size = GetViewportSizeDip(); |
733 if (DoBrowserControlsShrinkBlinkSize()) | 727 if (DoBrowserControlsShrinkBlinkSize()) |
734 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); | 728 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); |
735 return size; | 729 return size; |
736 } | 730 } |
737 | 731 |
738 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | |
739 JNIEnv* env = AttachCurrentThread(); | |
740 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
741 if (j_obj.is_null()) | |
742 return gfx::Size(); | |
743 return gfx::Size( | |
744 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), | |
745 Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj)); | |
746 } | |
747 | |
748 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { | 732 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { |
749 JNIEnv* env = AttachCurrentThread(); | 733 JNIEnv* env = AttachCurrentThread(); |
750 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 734 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
751 if (j_obj.is_null()) | 735 if (j_obj.is_null()) |
752 return gfx::Size(); | 736 return gfx::Size(); |
753 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), | 737 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), |
754 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); | 738 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); |
755 } | 739 } |
756 | 740 |
757 int ContentViewCoreImpl::GetTopControlsHeightPix() const { | 741 int ContentViewCoreImpl::GetTopControlsHeightPix() const { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 void ContentViewCoreImpl::RemoveJavascriptInterface( | 1245 void ContentViewCoreImpl::RemoveJavascriptInterface( |
1262 JNIEnv* env, | 1246 JNIEnv* env, |
1263 const JavaParamRef<jobject>& /* obj */, | 1247 const JavaParamRef<jobject>& /* obj */, |
1264 const JavaParamRef<jstring>& name) { | 1248 const JavaParamRef<jstring>& name) { |
1265 java_bridge_dispatcher_host_->RemoveNamedObject( | 1249 java_bridge_dispatcher_host_->RemoveNamedObject( |
1266 ConvertJavaStringToUTF8(env, name)); | 1250 ConvertJavaStringToUTF8(env, name)); |
1267 } | 1251 } |
1268 | 1252 |
1269 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1253 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
1270 const JavaParamRef<jobject>& obj) { | 1254 const JavaParamRef<jobject>& obj) { |
1271 gfx::Size physical_size( | |
1272 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
1273 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
1274 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
1275 | |
1276 SendScreenRectsAndResizeWidget(); | 1255 SendScreenRectsAndResizeWidget(); |
1277 } | 1256 } |
1278 | 1257 |
1279 long ContentViewCoreImpl::GetNativeImeAdapter( | 1258 long ContentViewCoreImpl::GetNativeImeAdapter( |
1280 JNIEnv* env, | 1259 JNIEnv* env, |
1281 const JavaParamRef<jobject>& obj) { | 1260 const JavaParamRef<jobject>& obj) { |
1282 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1261 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
1283 if (!rwhva) | 1262 if (!rwhva) |
1284 return 0; | 1263 return 0; |
1285 return rwhva->GetNativeImeAdapter(); | 1264 return rwhva->GetNativeImeAdapter(); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 const JavaParamRef<jobject>& jview_android_delegate, | 1534 const JavaParamRef<jobject>& jview_android_delegate, |
1556 jlong jwindow_android, | 1535 jlong jwindow_android, |
1557 jfloat dipScale, | 1536 jfloat dipScale, |
1558 const JavaParamRef<jobject>& retained_objects_set) { | 1537 const JavaParamRef<jobject>& retained_objects_set) { |
1559 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1538 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
1560 WebContents::FromJavaWebContents(jweb_contents)); | 1539 WebContents::FromJavaWebContents(jweb_contents)); |
1561 CHECK(web_contents) << | 1540 CHECK(web_contents) << |
1562 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1541 "A ContentViewCoreImpl should be created with a valid WebContents."; |
1563 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1542 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
1564 view_android->SetDelegate(jview_android_delegate); | 1543 view_android->SetDelegate(jview_android_delegate); |
| 1544 view_android->SetLayer(cc::Layer::Create()); |
1565 | 1545 |
1566 ui::WindowAndroid* window_android = | 1546 ui::WindowAndroid* window_android = |
1567 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1547 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); |
1568 DCHECK(window_android); | 1548 DCHECK(window_android); |
1569 window_android->AddChild(view_android); | 1549 window_android->AddChild(view_android); |
1570 | 1550 |
1571 // TODO: pass dipScale. | 1551 // TODO: pass dipScale. |
1572 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1552 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1573 env, obj, web_contents, dipScale, retained_objects_set); | 1553 env, obj, web_contents, dipScale, retained_objects_set); |
1574 return reinterpret_cast<intptr_t>(view); | 1554 return reinterpret_cast<intptr_t>(view); |
(...skipping 12 matching lines...) Expand all Loading... |
1587 return ScopedJavaLocalRef<jobject>(); | 1567 return ScopedJavaLocalRef<jobject>(); |
1588 | 1568 |
1589 return view->GetJavaObject(); | 1569 return view->GetJavaObject(); |
1590 } | 1570 } |
1591 | 1571 |
1592 bool RegisterContentViewCore(JNIEnv* env) { | 1572 bool RegisterContentViewCore(JNIEnv* env) { |
1593 return RegisterNativesImpl(env); | 1573 return RegisterNativesImpl(env); |
1594 } | 1574 } |
1595 | 1575 |
1596 } // namespace content | 1576 } // namespace content |
OLD | NEW |