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