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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 #include "content/browser/android/popup_item_type_list.h" | 82 #include "content/browser/android/popup_item_type_list.h" |
83 #undef DEFINE_POPUP_ITEM_TYPE | 83 #undef DEFINE_POPUP_ITEM_TYPE |
84 }; | 84 }; |
85 | 85 |
86 } //namespace | 86 } //namespace |
87 | 87 |
88 namespace content { | 88 namespace content { |
89 | 89 |
90 namespace { | 90 namespace { |
91 | 91 |
92 const unsigned int kDefaultVSyncIntervalMicros = 16666u; | |
93 // TODO(brianderson): Use adaptive draw-time estimation. | |
94 const float kDefaultBrowserCompositeVSyncFraction = 1.0f / 3; | |
95 | |
96 const void* kContentViewUserDataKey = &kContentViewUserDataKey; | 92 const void* kContentViewUserDataKey = &kContentViewUserDataKey; |
97 | 93 |
98 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { | 94 int GetRenderProcessIdFromRenderViewHost(RenderViewHost* host) { |
99 DCHECK(host); | 95 DCHECK(host); |
100 RenderProcessHost* render_process = host->GetProcess(); | 96 RenderProcessHost* render_process = host->GetProcess(); |
101 DCHECK(render_process); | 97 DCHECK(render_process); |
102 if (render_process->HasConnection()) | 98 if (render_process->HasConnection()) |
103 return render_process->GetHandle(); | 99 return render_process->GetHandle(); |
104 else | 100 else |
105 return 0; | 101 return 0; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, | 221 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, |
226 jobject obj, | 222 jobject obj, |
227 WebContents* web_contents, | 223 WebContents* web_contents, |
228 ui::ViewAndroid* view_android, | 224 ui::ViewAndroid* view_android, |
229 ui::WindowAndroid* window_android) | 225 ui::WindowAndroid* window_android) |
230 : WebContentsObserver(web_contents), | 226 : WebContentsObserver(web_contents), |
231 java_ref_(env, obj), | 227 java_ref_(env, obj), |
232 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 228 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
233 root_layer_(cc::Layer::Create()), | 229 root_layer_(cc::Layer::Create()), |
234 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), | 230 dpi_scale_(GetPrimaryDisplayDeviceScaleFactor()), |
235 vsync_interval_(base::TimeDelta::FromMicroseconds( | |
236 kDefaultVSyncIntervalMicros)), | |
237 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | |
238 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | |
239 view_android_(view_android), | 231 view_android_(view_android), |
240 window_android_(window_android), | 232 window_android_(window_android), |
241 gesture_provider_(GetGestureProviderConfig(), this), | 233 gesture_provider_(GetGestureProviderConfig(), this), |
242 device_orientation_(0), | 234 device_orientation_(0), |
243 geolocation_needs_pause_(false) { | 235 geolocation_needs_pause_(false) { |
244 CHECK(web_contents) << | 236 CHECK(web_contents) << |
245 "A ContentViewCoreImpl should be created with a valid WebContents."; | 237 "A ContentViewCoreImpl should be created with a valid WebContents."; |
246 | 238 |
247 // 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 |
248 // spoofing a desktop Linux user agent for "Request desktop site". | 240 // spoofing a desktop Linux user agent for "Request desktop site". |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 geolocation_needs_pause_ = false; | 428 geolocation_needs_pause_ = false; |
437 } | 429 } |
438 } | 430 } |
439 } | 431 } |
440 | 432 |
441 void ContentViewCoreImpl::OnTabCrashed() { | 433 void ContentViewCoreImpl::OnTabCrashed() { |
442 JNIEnv* env = AttachCurrentThread(); | 434 JNIEnv* env = AttachCurrentThread(); |
443 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 435 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
444 if (obj.is_null()) | 436 if (obj.is_null()) |
445 return; | 437 return; |
446 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); | |
447 } | 438 } |
448 | 439 |
449 // All positions and sizes are in CSS pixels. | 440 // All positions and sizes are in CSS pixels. |
450 // Note that viewport_width/height is a best effort based. | 441 // Note that viewport_width/height is a best effort based. |
451 // ContentViewCore has the actual information about the physical viewport size. | 442 // ContentViewCore has the actual information about the physical viewport size. |
452 void ContentViewCoreImpl::UpdateFrameInfo( | 443 void ContentViewCoreImpl::UpdateFrameInfo( |
453 const gfx::Vector2dF& scroll_offset, | 444 const gfx::Vector2dF& scroll_offset, |
454 float page_scale_factor, | 445 float page_scale_factor, |
455 const gfx::Vector2dF& page_scale_factor_limits, | 446 const gfx::Vector2dF& page_scale_factor_limits, |
456 const gfx::SizeF& content_size, | 447 const gfx::SizeF& content_size, |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 | 851 |
861 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 852 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
862 layer->RemoveFromParent(); | 853 layer->RemoveFromParent(); |
863 } | 854 } |
864 | 855 |
865 void ContentViewCoreImpl::LoadUrl( | 856 void ContentViewCoreImpl::LoadUrl( |
866 NavigationController::LoadURLParams& params) { | 857 NavigationController::LoadURLParams& params) { |
867 GetWebContents()->GetController().LoadURLWithParams(params); | 858 GetWebContents()->GetController().LoadURLWithParams(params); |
868 } | 859 } |
869 | 860 |
870 void ContentViewCoreImpl::AddBeginFrameSubscriber() { | |
871 JNIEnv* env = AttachCurrentThread(); | |
872 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
873 if (obj.is_null()) | |
874 return; | |
875 Java_ContentViewCore_addVSyncSubscriber(env, obj.obj()); | |
876 } | |
877 | |
878 void ContentViewCoreImpl::RemoveBeginFrameSubscriber() { | |
879 JNIEnv* env = AttachCurrentThread(); | |
880 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
881 if (obj.is_null()) | |
882 return; | |
883 Java_ContentViewCore_removeVSyncSubscriber(env, obj.obj()); | |
884 } | |
885 | |
886 void ContentViewCoreImpl::SetNeedsAnimate() { | |
887 JNIEnv* env = AttachCurrentThread(); | |
888 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
889 if (obj.is_null()) | |
890 return; | |
891 Java_ContentViewCore_setNeedsAnimate(env, obj.obj()); | |
892 } | |
893 | |
894 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 861 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
895 // view_android_ should never be null for Chrome. | 862 // view_android_ should never be null for Chrome. |
896 DCHECK(view_android_); | 863 DCHECK(view_android_); |
897 return view_android_; | 864 return view_android_; |
898 } | 865 } |
899 | 866 |
900 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 867 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
901 // This should never be NULL for Chrome, but will be NULL for WebView. | 868 // This should never be NULL for Chrome, but will be NULL for WebView. |
902 DCHECK(window_android_); | 869 DCHECK(window_android_); |
903 return window_android_; | 870 return window_android_; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 blink::WebBindings::releaseObject(bound_object); | 1343 blink::WebBindings::releaseObject(bound_object); |
1377 } | 1344 } |
1378 | 1345 |
1379 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, | 1346 void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, |
1380 jobject /* obj */, | 1347 jobject /* obj */, |
1381 jstring name) { | 1348 jstring name) { |
1382 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( | 1349 web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( |
1383 ConvertJavaStringToUTF16(env, name)); | 1350 ConvertJavaStringToUTF16(env, name)); |
1384 } | 1351 } |
1385 | 1352 |
1386 void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */, | |
1387 jlong timebase_micros, | |
1388 jlong interval_micros) { | |
1389 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1390 if (!view) | |
1391 return; | |
1392 | |
1393 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | |
1394 view->GetRenderWidgetHost()); | |
1395 | |
1396 host->UpdateVSyncParameters( | |
1397 base::TimeTicks::FromInternalValue(timebase_micros), | |
1398 base::TimeDelta::FromMicroseconds(interval_micros)); | |
1399 | |
1400 vsync_interval_ = | |
1401 base::TimeDelta::FromMicroseconds(interval_micros); | |
1402 expected_browser_composite_time_ = | |
1403 vsync_interval_ * kDefaultBrowserCompositeVSyncFraction; | |
1404 } | |
1405 | |
1406 void ContentViewCoreImpl::OnVSync(JNIEnv* env, jobject /* obj */, | |
1407 jlong frame_time_micros) { | |
1408 base::TimeTicks frame_time = | |
1409 base::TimeTicks::FromInternalValue(frame_time_micros); | |
1410 SendBeginFrame(frame_time); | |
1411 } | |
1412 | |
1413 void ContentViewCoreImpl::SendBeginFrame(base::TimeTicks frame_time) { | |
1414 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1415 if (!view) | |
1416 return; | |
1417 | |
1418 base::TimeTicks display_time = frame_time + vsync_interval_; | |
1419 base::TimeTicks deadline = display_time - expected_browser_composite_time_; | |
1420 | |
1421 view->SendBeginFrame( | |
1422 cc::BeginFrameArgs::Create(frame_time, deadline, vsync_interval_)); | |
1423 } | |
1424 | |
1425 jboolean ContentViewCoreImpl::OnAnimate(JNIEnv* env, jobject /* obj */, | |
1426 jlong frame_time_micros) { | |
1427 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
1428 if (!view) | |
1429 return false; | |
1430 | |
1431 return view->Animate(base::TimeTicks::FromInternalValue(frame_time_micros)); | |
1432 } | |
1433 | |
1434 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { | 1353 void ContentViewCoreImpl::WasResized(JNIEnv* env, jobject obj) { |
1435 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 1354 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
1436 if (view) | 1355 if (view) |
1437 view->WasResized(); | 1356 view->WasResized(); |
1438 } | 1357 } |
1439 | 1358 |
1440 void ContentViewCoreImpl::ShowInterstitialPage( | 1359 void ContentViewCoreImpl::ShowInterstitialPage( |
1441 JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) { | 1360 JNIEnv* env, jobject obj, jstring jurl, jint delegate_ptr) { |
1442 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 1361 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
1443 InterstitialPageDelegateAndroid* delegate = | 1362 InterstitialPageDelegateAndroid* delegate = |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1716 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1798 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1717 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1799 return reinterpret_cast<intptr_t>(view); | 1718 return reinterpret_cast<intptr_t>(view); |
1800 } | 1719 } |
1801 | 1720 |
1802 bool RegisterContentViewCore(JNIEnv* env) { | 1721 bool RegisterContentViewCore(JNIEnv* env) { |
1803 return RegisterNativesImpl(env); | 1722 return RegisterNativesImpl(env); |
1804 } | 1723 } |
1805 | 1724 |
1806 } // namespace content | 1725 } // namespace content |
OLD | NEW |