Chromium Code Reviews| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 WebContents* web_contents, | 210 WebContents* web_contents, |
| 211 float dpi_scale, | 211 float dpi_scale, |
| 212 const JavaRef<jobject>& java_bridge_retained_object_set) | 212 const JavaRef<jobject>& java_bridge_retained_object_set) |
| 213 : WebContentsObserver(web_contents), | 213 : WebContentsObserver(web_contents), |
| 214 java_ref_(env, obj), | 214 java_ref_(env, obj), |
| 215 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 215 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 216 page_scale_(1), | 216 page_scale_(1), |
| 217 dpi_scale_(dpi_scale), | 217 dpi_scale_(dpi_scale), |
| 218 device_orientation_(0), | 218 device_orientation_(0), |
| 219 accessibility_enabled_(false) { | 219 accessibility_enabled_(false) { |
| 220 GetViewAndroid()->SetLayer(cc::Layer::Create()); | |
| 221 gfx::Size physical_size( | |
| 222 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
| 223 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
| 224 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
| 225 | |
| 226 // Currently, the only use case we have for overriding a user agent involves | 220 // Currently, the only use case we have for overriding a user agent involves |
| 227 // spoofing a desktop Linux user agent for "Request desktop site". | 221 // spoofing a desktop Linux user agent for "Request desktop site". |
| 228 // Automatically set it for all WebContents so that it is available when a | 222 // Automatically set it for all WebContents so that it is available when a |
| 229 // NavigationEntry requires the user agent to be overridden. | 223 // NavigationEntry requires the user agent to be overridden. |
| 230 const char kLinuxInfoStr[] = "X11; Linux x86_64"; | 224 const char kLinuxInfoStr[] = "X11; Linux x86_64"; |
| 231 std::string product = content::GetContentClient()->GetProduct(); | 225 std::string product = content::GetContentClient()->GetProduct(); |
| 232 std::string spoofed_ua = | 226 std::string spoofed_ua = |
| 233 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); | 227 BuildUserAgentFromOSAndProduct(kLinuxInfoStr, product); |
| 234 web_contents->SetUserAgentOverride(spoofed_ua); | 228 web_contents->SetUserAgentOverride(spoofed_ua); |
| 235 | 229 |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 return size_dip; | 709 return size_dip; |
| 716 } | 710 } |
| 717 | 711 |
| 718 gfx::Size ContentViewCoreImpl::GetViewSize() const { | 712 gfx::Size ContentViewCoreImpl::GetViewSize() const { |
| 719 gfx::Size size = GetViewportSizeDip(); | 713 gfx::Size size = GetViewportSizeDip(); |
| 720 if (DoBrowserControlsShrinkBlinkSize()) | 714 if (DoBrowserControlsShrinkBlinkSize()) |
| 721 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); | 715 size.Enlarge(0, -GetTopControlsHeightDip() - GetBottomControlsHeightDip()); |
| 722 return size; | 716 return size; |
| 723 } | 717 } |
| 724 | 718 |
| 725 gfx::Size ContentViewCoreImpl::GetPhysicalBackingSize() const { | |
| 726 JNIEnv* env = AttachCurrentThread(); | |
| 727 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | |
| 728 if (j_obj.is_null()) | |
| 729 return gfx::Size(); | |
| 730 return gfx::Size( | |
| 731 Java_ContentViewCore_getPhysicalBackingWidthPix(env, j_obj), | |
| 732 Java_ContentViewCore_getPhysicalBackingHeightPix(env, j_obj)); | |
| 733 } | |
| 734 | |
| 735 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { | 719 gfx::Size ContentViewCoreImpl::GetViewportSizePix() const { |
| 736 JNIEnv* env = AttachCurrentThread(); | 720 JNIEnv* env = AttachCurrentThread(); |
| 737 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 721 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 738 if (j_obj.is_null()) | 722 if (j_obj.is_null()) |
| 739 return gfx::Size(); | 723 return gfx::Size(); |
| 740 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), | 724 return gfx::Size(Java_ContentViewCore_getViewportWidthPix(env, j_obj), |
| 741 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); | 725 Java_ContentViewCore_getViewportHeightPix(env, j_obj)); |
| 742 } | 726 } |
| 743 | 727 |
| 744 int ContentViewCoreImpl::GetTopControlsHeightPix() const { | 728 int ContentViewCoreImpl::GetTopControlsHeightPix() const { |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1243 void ContentViewCoreImpl::RemoveJavascriptInterface( | 1227 void ContentViewCoreImpl::RemoveJavascriptInterface( |
| 1244 JNIEnv* env, | 1228 JNIEnv* env, |
| 1245 const JavaParamRef<jobject>& /* obj */, | 1229 const JavaParamRef<jobject>& /* obj */, |
| 1246 const JavaParamRef<jstring>& name) { | 1230 const JavaParamRef<jstring>& name) { |
| 1247 java_bridge_dispatcher_host_->RemoveNamedObject( | 1231 java_bridge_dispatcher_host_->RemoveNamedObject( |
| 1248 ConvertJavaStringToUTF8(env, name)); | 1232 ConvertJavaStringToUTF8(env, name)); |
| 1249 } | 1233 } |
| 1250 | 1234 |
| 1251 void ContentViewCoreImpl::WasResized(JNIEnv* env, | 1235 void ContentViewCoreImpl::WasResized(JNIEnv* env, |
| 1252 const JavaParamRef<jobject>& obj) { | 1236 const JavaParamRef<jobject>& obj) { |
| 1253 gfx::Size physical_size( | 1237 GetViewAndroid()->UpdateLayerBounds(); |
|
boliu
2016/12/06 23:15:45
hmm, why is this still needed? did physical bounds
Jinsuk Kim
2016/12/07 12:36:28
Removed.
| |
| 1254 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | |
| 1255 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | |
| 1256 GetViewAndroid()->GetLayer()->SetBounds(physical_size); | |
| 1257 | |
| 1258 SendScreenRectsAndResizeWidget(); | 1238 SendScreenRectsAndResizeWidget(); |
| 1259 } | 1239 } |
| 1260 | 1240 |
| 1261 long ContentViewCoreImpl::GetNativeImeAdapter( | 1241 long ContentViewCoreImpl::GetNativeImeAdapter( |
| 1262 JNIEnv* env, | 1242 JNIEnv* env, |
| 1263 const JavaParamRef<jobject>& obj) { | 1243 const JavaParamRef<jobject>& obj) { |
| 1264 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 1244 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 1265 if (!rwhva) | 1245 if (!rwhva) |
| 1266 return 0; | 1246 return 0; |
| 1267 return rwhva->GetNativeImeAdapter(); | 1247 return rwhva->GetNativeImeAdapter(); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1567 const JavaParamRef<jobject>& jview_android_delegate, | 1547 const JavaParamRef<jobject>& jview_android_delegate, |
| 1568 jlong jwindow_android, | 1548 jlong jwindow_android, |
| 1569 jfloat dipScale, | 1549 jfloat dipScale, |
| 1570 const JavaParamRef<jobject>& retained_objects_set) { | 1550 const JavaParamRef<jobject>& retained_objects_set) { |
| 1571 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1551 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1572 WebContents::FromJavaWebContents(jweb_contents)); | 1552 WebContents::FromJavaWebContents(jweb_contents)); |
| 1573 CHECK(web_contents) << | 1553 CHECK(web_contents) << |
| 1574 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1554 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 1575 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1555 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
| 1576 view_android->SetDelegate(jview_android_delegate); | 1556 view_android->SetDelegate(jview_android_delegate); |
| 1557 view_android->SetLayer(cc::Layer::Create()); | |
|
boliu
2016/12/06 23:15:45
is this to avoid null checks in ViewAndroid for up
Jinsuk Kim
2016/12/07 12:36:28
Yes, also the line now looked like an odd one out
| |
| 1577 | 1558 |
| 1578 ui::WindowAndroid* window_android = | 1559 ui::WindowAndroid* window_android = |
| 1579 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | 1560 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); |
| 1580 DCHECK(window_android); | 1561 DCHECK(window_android); |
| 1581 window_android->AddChild(view_android); | 1562 window_android->AddChild(view_android); |
| 1582 | 1563 |
| 1583 // TODO: pass dipScale. | 1564 // TODO: pass dipScale. |
| 1584 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1565 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1585 env, obj, web_contents, dipScale, retained_objects_set); | 1566 env, obj, web_contents, dipScale, retained_objects_set); |
| 1586 return reinterpret_cast<intptr_t>(view); | 1567 return reinterpret_cast<intptr_t>(view); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1599 return ScopedJavaLocalRef<jobject>(); | 1580 return ScopedJavaLocalRef<jobject>(); |
| 1600 | 1581 |
| 1601 return view->GetJavaObject(); | 1582 return view->GetJavaObject(); |
| 1602 } | 1583 } |
| 1603 | 1584 |
| 1604 bool RegisterContentViewCore(JNIEnv* env) { | 1585 bool RegisterContentViewCore(JNIEnv* env) { |
| 1605 return RegisterNativesImpl(env); | 1586 return RegisterNativesImpl(env); |
| 1606 } | 1587 } |
| 1607 | 1588 |
| 1608 } // namespace content | 1589 } // namespace content |
| OLD | NEW |