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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #include "content/browser/android/popup_item_type_list.h" | 80 #include "content/browser/android/popup_item_type_list.h" |
81 #undef DEFINE_POPUP_ITEM_TYPE | 81 #undef DEFINE_POPUP_ITEM_TYPE |
82 }; | 82 }; |
83 | 83 |
84 } //namespace | 84 } //namespace |
85 | 85 |
86 namespace content { | 86 namespace content { |
87 | 87 |
88 namespace { | 88 namespace { |
89 | 89 |
90 const unsigned int kDefaultVSyncIntervalMicros = 16666u; | |
91 // TODO(brianderson): Use adaptive draw-time estimation. | |
92 const float kDefaultBrowserCompositeVSyncFraction = 1.0f / 3; | |
93 | |
94 const void* kContentViewUserDataKey = &kContentViewUserDataKey; | 90 const void* kContentViewUserDataKey = &kContentViewUserDataKey; |
95 | 91 |
96 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { | 92 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { |
97 DCHECK(host); | 93 DCHECK(host); |
98 RenderProcessHost* render_process = host->GetProcess(); | 94 RenderProcessHost* render_process = host->GetProcess(); |
99 DCHECK(render_process); | 95 DCHECK(render_process); |
100 if (render_process->HasConnection()) | 96 if (render_process->HasConnection()) |
101 return render_process->GetHandle(); | 97 return render_process->GetHandle(); |
102 else | 98 else |
103 return 0; | 99 return 0; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, | 212 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, |
217 jobject obj, | 213 jobject obj, |
218 WebContents* web_contents, | 214 WebContents* web_contents, |
219 ui::ViewAndroid* view_android, | 215 ui::ViewAndroid* view_android, |
220 ui::WindowAndroid* window_android) | 216 ui::WindowAndroid* window_android) |
221 : WebContentsObserver(web_contents), | 217 : WebContentsObserver(web_contents), |
222 java_ref_(env, obj), | 218 java_ref_(env, obj), |
223 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 219 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
224 root_layer_(cc::Layer::Create()), | 220 root_layer_(cc::Layer::Create()), |
225 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 221 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
226 vsync_interval_(base::TimeDelta::FromMicroseconds( | |
227 kDefaultVSyncIntervalMicros)), | |
228 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | |
229 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | |
230 view_android_(view_android), | 222 view_android_(view_android), |
231 window_android_(window_android), | 223 window_android_(window_android), |
232 device_orientation_(0), | 224 device_orientation_(0), |
233 geolocation_needs_pause_(false) { | 225 geolocation_needs_pause_(false) { |
234 CHECK(web_contents) << | 226 CHECK(web_contents) << |
235 "A ContentViewCoreImpl should be created with a valid WebContents."; | 227 "A ContentViewCoreImpl should be created with a valid WebContents."; |
236 | 228 |
237 // Currently, the only use case we have for overriding a user agent involves | 229 // Currently, the only use case we have for overriding a user agent involves |
238 // spoofing a desktop Linux user agent for "Request desktop site". | 230 // spoofing a desktop Linux user agent for "Request desktop site". |
239 // Automatically set it for all WebContents so that it is available when a | 231 // Automatically set it for all WebContents so that it is available when a |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 geolocation_needs_pause_ = false; | 420 geolocation_needs_pause_ = false; |
429 } | 421 } |
430 } | 422 } |
431 } | 423 } |
432 | 424 |
433 void ContentViewCoreImpl::OnTabCrashed() { | 425 void ContentViewCoreImpl::OnTabCrashed() { |
434 JNIEnv* env = AttachCurrentThread(); | 426 JNIEnv* env = AttachCurrentThread(); |
435 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 427 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
436 if (obj.is_null()) | 428 if (obj.is_null()) |
437 return; | 429 return; |
438 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); | |
439 } | 430 } |
440 | 431 |
441 // All positions and sizes are in CSS pixels. | 432 // All positions and sizes are in CSS pixels. |
442 // Note that viewport_width/height is a best effort based. | 433 // Note that viewport_width/height is a best effort based. |
443 // ContentViewCore has the actual information about the physical viewport size. | 434 // ContentViewCore has the actual information about the physical viewport size. |
444 void ContentViewCoreImpl::UpdateFrameInfo( | 435 void ContentViewCoreImpl::UpdateFrameInfo( |
445 const gfx::Vector2dF& scroll_offset, | 436 const gfx::Vector2dF& scroll_offset, |
446 float page_scale_factor, | 437 float page_scale_factor, |
447 const gfx::Vector2dF& page_scale_factor_limits, | 438 const gfx::Vector2dF& page_scale_factor_limits, |
448 const gfx::SizeF& content_size, | 439 const gfx::SizeF& content_size, |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 | 839 |
849 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 840 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
850 layer->RemoveFromParent(); | 841 layer->RemoveFromParent(); |
851 } | 842 } |
852 | 843 |
853 void ContentViewCoreImpl::LoadUrl( | 844 void ContentViewCoreImpl::LoadUrl( |
854 NavigationController::LoadURLParams& params) { | 845 NavigationController::LoadURLParams& params) { |
855 GetWebContents()->GetController().LoadURLWithParams(params); | 846 GetWebContents()->GetController().LoadURLWithParams(params); |
856 } | 847 } |
857 | 848 |
858 void ContentViewCoreImpl::AddBeginFrameSubscriber() { | |
859 JNIEnv* env = AttachCurrentThread(); | |
860 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
861 if (obj.is_null()) | |
862 return; | |
863 Java_ContentViewCore_addVSyncSubscriber(env, obj.obj()); | |
864 } | |
865 | |
866 void ContentViewCoreImpl::RemoveBeginFrameSubscriber() { | |
867 JNIEnv* env = AttachCurrentThread(); | |
868 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
869 if (obj.is_null()) | |
870 return; | |
871 Java_ContentViewCore_removeVSyncSubscriber(env, obj.obj()); | |
872 } | |
873 | |
874 void ContentViewCoreImpl::SetNeedsAnimate() { | |
875 JNIEnv* env = AttachCurrentThread(); | |
876 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
877 if (obj.is_null()) | |
878 return; | |
879 Java_ContentViewCore_setNeedsAnimate(env, obj.obj()); | |
880 } | |
881 | |
882 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 849 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
883 // view_android_ should never be null for Chrome. | 850 // view_android_ should never be null for Chrome. |
884 DCHECK(view_android_); | 851 DCHECK(view_android_); |
885 return view_android_; | 852 return view_android_; |
886 } | 853 } |
887 | 854 |
888 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 855 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
889 // This should never be NULL for Chrome, but will be NULL for WebView. | 856 // This should never be NULL for Chrome, but will be NULL for WebView. |
890 DCHECK(window_android_); | 857 DCHECK(window_android_); |
891 return window_android_; | 858 return window_android_; |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 blink::WebBindings::releaseObject(bound_object); | 1286 blink::WebBindings::releaseObject(bound_object); |
1320 } | 1287 } |
1321 | 1288 |
1322 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1289 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
1323 jobject /* obj */, | 1290 jobject /* obj */, |
1324 jstring name) { | 1291 jstring name) { |
1325 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | 1292 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( |
1326 ConvertJavaStringToUTF16(env, name)); | 1293 ConvertJavaStringToUTF16(env, name)); |
1327 } | 1294 } |
1328 | 1295 |
1329 void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */, | |
1330 jlong timebase_micros, | |
1331 jlong interval_micros) { | |
1332 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1333 if (!view) | |
1334 return; | |
1335 | |
1336 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | |
1337 view->GetRenderWidgetHost()); | |
1338 | |
1339 host->UpdateVSyncParameters( | |
1340 base::TimeTicks::FromInternalValue(timebase_micros), | |
1341 base::TimeDelta::FromMicroseconds(interval_micros)); | |
1342 | |
1343 vsync_interval_ = | |
1344 base::TimeDelta::FromMicroseconds(interval_micros); | |
1345 expected_browser_composite_time_ = | |
1346 vsync_interval_ * kDefaultBrowserCompositeVSyncFraction; | |
1347 } | |
1348 | |
1349 void ContentViewCoreImpl::OnVSync(JNIEnv* env, jobject /* obj */, | |
1350 jlong frame_time_micros) { | |
1351 base::TimeTicks frame_time = | |
1352 base::TimeTicks::FromInternalValue(frame_time_micros); | |
1353 SendBeginFrame(frame_time); | |
1354 } | |
1355 | |
1356 void ContentViewCoreImpl::SendBeginFrame(base::TimeTicks frame_time) { | |
1357 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1358 if (!view) | |
1359 return; | |
1360 | |
1361 base::TimeTicks display_time = frame_time + vsync_interval_; | |
1362 base::TimeTicks deadline = display_time - expected_browser_composite_time_; | |
1363 | |
1364 view->SendBeginFrame( | |
1365 cc::BeginFrameArgs::Create(frame_time, deadline, vsync_interval_)); | |
1366 } | |
1367 | |
1368 jboolean ContentViewCoreImpl::OnAnimate(JNIEnv* env, jobject /* obj */, | |
1369 jlong frame_time_micros) { | |
1370 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1371 if (!view) | |
1372 return false; | |
1373 | |
1374 return view->Animate(base::TimeTicks::FromInternalValue(frame_time_micros)); | |
1375 } | |
1376 | |
1377 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1296 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
1378 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1297 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
1379 if (view) { | 1298 if (view) { |
1380 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 1299 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
1381 view->GetRenderWidgetHost()); | 1300 view->GetRenderWidgetHost()); |
1382 host->SendScreenRects(); | 1301 host->SendScreenRects(); |
1383 view->WasResized(); | 1302 view->WasResized(); |
1384 } | 1303 } |
1385 } | 1304 } |
1386 | 1305 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1663 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1745 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1664 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1746 return reinterpret_cast<intptr_t>(view); | 1665 return reinterpret_cast<intptr_t>(view); |
1747 } | 1666 } |
1748 | 1667 |
1749 bool RegisterContentViewCore(JNIEnv* env) { | 1668 bool RegisterContentViewCore(JNIEnv* env) { |
1750 return RegisterNativesImpl(env); | 1669 return RegisterNativesImpl(env); |
1751 } | 1670 } |
1752 | 1671 |
1753 } // namespace content | 1672 } // namespace content |
OLD | NEW |