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 "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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/synchronization/waitable_event.h" | |
|
bulach
2013/12/11 13:29:27
nit: no longer needed
benm (inactive)
2013/12/11 20:08:51
Done.
| |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "cc/layers/layer.h" | 18 #include "cc/layers/layer.h" |
| 18 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
| 19 #include "content/browser/android/interstitial_page_delegate_android.h" | 20 #include "content/browser/android/interstitial_page_delegate_android.h" |
| 20 #include "content/browser/android/load_url_params.h" | 21 #include "content/browser/android/load_url_params.h" |
| 21 #include "content/browser/android/touch_point.h" | 22 #include "content/browser/android/touch_point.h" |
| 22 #include "content/browser/frame_host/interstitial_page_impl.h" | 23 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 23 #include "content/browser/frame_host/navigation_controller_impl.h" | 24 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 24 #include "content/browser/frame_host/navigation_entry_impl.h" | 25 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 25 #include "content/browser/media/android/browser_media_player_manager.h" | 26 #include "content/browser/media/android/browser_media_player_manager.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 | 101 |
| 101 ScopedJavaLocalRef<jobject> CreateJavaRect( | 102 ScopedJavaLocalRef<jobject> CreateJavaRect( |
| 102 JNIEnv* env, | 103 JNIEnv* env, |
| 103 const gfx::Rect& rect) { | 104 const gfx::Rect& rect) { |
| 104 return ScopedJavaLocalRef<jobject>( | 105 return ScopedJavaLocalRef<jobject>( |
| 105 Java_ContentViewCore_createRect(env, | 106 Java_ContentViewCore_createRect(env, |
| 106 static_cast<int>(rect.x()), | 107 static_cast<int>(rect.x()), |
| 107 static_cast<int>(rect.y()), | 108 static_cast<int>(rect.y()), |
| 108 static_cast<int>(rect.right()), | 109 static_cast<int>(rect.right()), |
| 109 static_cast<int>(rect.bottom()))); | 110 static_cast<int>(rect.bottom()))); |
| 110 }; | 111 } |
| 112 | |
| 111 } // namespace | 113 } // namespace |
| 112 | 114 |
| 113 // Enables a callback when the underlying WebContents is destroyed, to enable | 115 // Enables a callback when the underlying WebContents is destroyed, to enable |
| 114 // nulling the back-pointer. | 116 // nulling the back-pointer. |
| 115 class ContentViewCoreImpl::ContentViewUserData | 117 class ContentViewCoreImpl::ContentViewUserData |
| 116 : public base::SupportsUserData::Data { | 118 : public base::SupportsUserData::Data { |
| 117 public: | 119 public: |
| 118 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) | 120 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) |
| 119 : content_view_core_(content_view_core) { | 121 : content_view_core_(content_view_core) { |
| 120 } | 122 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 : WebContentsObserver(web_contents), | 168 : WebContentsObserver(web_contents), |
| 167 java_ref_(env, obj), | 169 java_ref_(env, obj), |
| 168 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 170 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 169 root_layer_(cc::Layer::Create()), | 171 root_layer_(cc::Layer::Create()), |
| 170 vsync_interval_(base::TimeDelta::FromMicroseconds( | 172 vsync_interval_(base::TimeDelta::FromMicroseconds( |
| 171 kDefaultVSyncIntervalMicros)), | 173 kDefaultVSyncIntervalMicros)), |
| 172 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 174 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
| 173 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 175 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
| 174 view_android_(view_android), | 176 view_android_(view_android), |
| 175 window_android_(window_android), | 177 window_android_(window_android), |
| 176 device_orientation_(0) { | 178 device_orientation_(0), |
| 179 geolocation_needs_pause_(false) { | |
| 177 CHECK(web_contents) << | 180 CHECK(web_contents) << |
| 178 "A ContentViewCoreImpl should be created with a valid WebContents."; | 181 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 179 | 182 |
| 180 // TODO(leandrogracia): make use of the hardware_accelerated argument. | 183 // TODO(leandrogracia): make use of the hardware_accelerated argument. |
| 181 | 184 |
| 182 const gfx::Display& display = | 185 const gfx::Display& display = |
| 183 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 186 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 184 dpi_scale_ = display.device_scale_factor(); | 187 dpi_scale_ = display.device_scale_factor(); |
| 185 | 188 |
| 186 // Currently, the only use case we have for overriding a user agent involves | 189 // Currently, the only use case we have for overriding a user agent involves |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 if (new_pid != old_pid) { | 259 if (new_pid != old_pid) { |
| 257 // Notify the Java side of the change of the current renderer process. | 260 // Notify the Java side of the change of the current renderer process. |
| 258 JNIEnv* env = AttachCurrentThread(); | 261 JNIEnv* env = AttachCurrentThread(); |
| 259 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 262 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 260 if (!obj.is_null()) { | 263 if (!obj.is_null()) { |
| 261 Java_ContentViewCore_onRenderProcessSwap( | 264 Java_ContentViewCore_onRenderProcessSwap( |
| 262 env, obj.obj(), old_pid, new_pid); | 265 env, obj.obj(), old_pid, new_pid); |
| 263 } | 266 } |
| 264 } | 267 } |
| 265 SetFocusInternal(HasFocus()); | 268 SetFocusInternal(HasFocus()); |
| 269 if (geolocation_needs_pause_) | |
| 270 PauseOrResumeGeolocation(true); | |
| 266 break; | 271 break; |
| 267 } | 272 } |
| 268 case NOTIFICATION_RENDERER_PROCESS_CREATED: { | 273 case NOTIFICATION_RENDERER_PROCESS_CREATED: { |
| 269 // Notify the Java side of the current renderer process. | 274 // Notify the Java side of the current renderer process. |
| 270 RenderProcessHost* source_process_host = | 275 RenderProcessHost* source_process_host = |
| 271 Source<RenderProcessHost>(source).ptr(); | 276 Source<RenderProcessHost>(source).ptr(); |
| 272 RenderProcessHost* current_process_host = | 277 RenderProcessHost* current_process_host = |
| 273 web_contents_->GetRenderViewHost()->GetProcess(); | 278 web_contents_->GetRenderViewHost()->GetProcess(); |
| 274 | 279 |
| 275 if (source_process_host == current_process_host) { | 280 if (source_process_host == current_process_host) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 GetWebContents()->WasHidden(); | 346 GetWebContents()->WasHidden(); |
| 342 PauseVideo(); | 347 PauseVideo(); |
| 343 } | 348 } |
| 344 | 349 |
| 345 void ContentViewCoreImpl::PauseVideo() { | 350 void ContentViewCoreImpl::PauseVideo() { |
| 346 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 351 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 347 if (host) | 352 if (host) |
| 348 host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); | 353 host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); |
| 349 } | 354 } |
| 350 | 355 |
| 356 void ContentViewCoreImpl::PauseOrResumeGeolocation(bool should_pause) { | |
| 357 geolocation_needs_pause_ = should_pause; | |
| 358 RenderViewHostImpl* rvh = | |
| 359 static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | |
| 360 if (rvh) { | |
| 361 scoped_refptr<GeolocationDispatcherHost> geolocation_dispatcher = | |
| 362 static_cast<RenderProcessHostImpl*>( | |
| 363 web_contents_->GetRenderProcessHost())-> | |
| 364 geolocation_dispatcher_host(); | |
| 365 if (geolocation_dispatcher.get()) { | |
| 366 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 367 base::Bind(&GeolocationDispatcherHost::PauseOrResume, | |
| 368 geolocation_dispatcher, | |
| 369 rvh->GetRoutingID(), | |
| 370 should_pause)); | |
| 371 geolocation_needs_pause_ = false; | |
| 372 } | |
| 373 } | |
| 374 } | |
| 375 | |
| 351 void ContentViewCoreImpl::OnTabCrashed() { | 376 void ContentViewCoreImpl::OnTabCrashed() { |
| 352 JNIEnv* env = AttachCurrentThread(); | 377 JNIEnv* env = AttachCurrentThread(); |
| 353 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 378 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 354 if (obj.is_null()) | 379 if (obj.is_null()) |
| 355 return; | 380 return; |
| 356 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); | 381 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); |
| 357 } | 382 } |
| 358 | 383 |
| 359 // All positions and sizes are in CSS pixels. | 384 // All positions and sizes are in CSS pixels. |
| 360 // Note that viewport_width/height is a best effort based. | 385 // Note that viewport_width/height is a best effort based. |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1613 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1638 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1614 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1639 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1615 return reinterpret_cast<intptr_t>(view); | 1640 return reinterpret_cast<intptr_t>(view); |
| 1616 } | 1641 } |
| 1617 | 1642 |
| 1618 bool RegisterContentViewCore(JNIEnv* env) { | 1643 bool RegisterContentViewCore(JNIEnv* env) { |
| 1619 return RegisterNativesImpl(env); | 1644 return RegisterNativesImpl(env); |
| 1620 } | 1645 } |
| 1621 | 1646 |
| 1622 } // namespace content | 1647 } // namespace content |
| OLD | NEW |