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" |
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 |
| 113 void IsGeolocationActiveForTestingOnIOThread( |
| 114 scoped_refptr<GeolocationDispatcherHost> d, |
| 115 base::WaitableEvent* completion, |
| 116 bool* result) { |
| 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 118 *result = d->IsGeolocationActive(); |
| 119 completion->Signal(); |
| 120 } |
| 121 |
111 } // namespace | 122 } // namespace |
112 | 123 |
113 // Enables a callback when the underlying WebContents is destroyed, to enable | 124 // Enables a callback when the underlying WebContents is destroyed, to enable |
114 // nulling the back-pointer. | 125 // nulling the back-pointer. |
115 class ContentViewCoreImpl::ContentViewUserData | 126 class ContentViewCoreImpl::ContentViewUserData |
116 : public base::SupportsUserData::Data { | 127 : public base::SupportsUserData::Data { |
117 public: | 128 public: |
118 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) | 129 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) |
119 : content_view_core_(content_view_core) { | 130 : content_view_core_(content_view_core) { |
120 } | 131 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 : WebContentsObserver(web_contents), | 177 : WebContentsObserver(web_contents), |
167 java_ref_(env, obj), | 178 java_ref_(env, obj), |
168 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 179 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
169 root_layer_(cc::Layer::Create()), | 180 root_layer_(cc::Layer::Create()), |
170 vsync_interval_(base::TimeDelta::FromMicroseconds( | 181 vsync_interval_(base::TimeDelta::FromMicroseconds( |
171 kDefaultVSyncIntervalMicros)), | 182 kDefaultVSyncIntervalMicros)), |
172 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( | 183 expected_browser_composite_time_(base::TimeDelta::FromMicroseconds( |
173 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), | 184 kDefaultVSyncIntervalMicros * kDefaultBrowserCompositeVSyncFraction)), |
174 view_android_(view_android), | 185 view_android_(view_android), |
175 window_android_(window_android), | 186 window_android_(window_android), |
176 device_orientation_(0) { | 187 device_orientation_(0), |
| 188 geolocation_needs_pause_(false) { |
177 CHECK(web_contents) << | 189 CHECK(web_contents) << |
178 "A ContentViewCoreImpl should be created with a valid WebContents."; | 190 "A ContentViewCoreImpl should be created with a valid WebContents."; |
179 | 191 |
180 // TODO(leandrogracia): make use of the hardware_accelerated argument. | 192 // TODO(leandrogracia): make use of the hardware_accelerated argument. |
181 | 193 |
182 const gfx::Display& display = | 194 const gfx::Display& display = |
183 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 195 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
184 dpi_scale_ = display.device_scale_factor(); | 196 dpi_scale_ = display.device_scale_factor(); |
185 | 197 |
186 // Currently, the only use case we have for overriding a user agent involves | 198 // Currently, the only use case we have for overriding a user agent involves |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (new_pid != old_pid) { | 263 if (new_pid != old_pid) { |
252 // Notify the Java side of the change of the current renderer process. | 264 // Notify the Java side of the change of the current renderer process. |
253 JNIEnv* env = AttachCurrentThread(); | 265 JNIEnv* env = AttachCurrentThread(); |
254 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 266 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
255 if (!obj.is_null()) { | 267 if (!obj.is_null()) { |
256 Java_ContentViewCore_onRenderProcessSwap( | 268 Java_ContentViewCore_onRenderProcessSwap( |
257 env, obj.obj(), old_pid, new_pid); | 269 env, obj.obj(), old_pid, new_pid); |
258 } | 270 } |
259 } | 271 } |
260 SetFocusInternal(HasFocus()); | 272 SetFocusInternal(HasFocus()); |
| 273 if (geolocation_needs_pause_) |
| 274 PauseOrResumeGeolocation(true); |
261 break; | 275 break; |
262 } | 276 } |
263 case NOTIFICATION_RENDERER_PROCESS_CREATED: { | 277 case NOTIFICATION_RENDERER_PROCESS_CREATED: { |
264 // Notify the Java side of the current renderer process. | 278 // Notify the Java side of the current renderer process. |
265 RenderProcessHost* source_process_host = | 279 RenderProcessHost* source_process_host = |
266 Source<RenderProcessHost>(source).ptr(); | 280 Source<RenderProcessHost>(source).ptr(); |
267 RenderProcessHost* current_process_host = | 281 RenderProcessHost* current_process_host = |
268 web_contents_->GetRenderViewHost()->GetProcess(); | 282 web_contents_->GetRenderViewHost()->GetProcess(); |
269 | 283 |
270 if (source_process_host == current_process_host) { | 284 if (source_process_host == current_process_host) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 GetWebContents()->WasHidden(); | 350 GetWebContents()->WasHidden(); |
337 PauseVideo(); | 351 PauseVideo(); |
338 } | 352 } |
339 | 353 |
340 void ContentViewCoreImpl::PauseVideo() { | 354 void ContentViewCoreImpl::PauseVideo() { |
341 RenderViewHost* host = web_contents_->GetRenderViewHost(); | 355 RenderViewHost* host = web_contents_->GetRenderViewHost(); |
342 if (host) | 356 if (host) |
343 host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); | 357 host->Send(new ViewMsg_PauseVideo(host->GetRoutingID())); |
344 } | 358 } |
345 | 359 |
| 360 void ContentViewCoreImpl::PauseOrResumeGeolocation(bool should_pause) { |
| 361 geolocation_needs_pause_ = should_pause; |
| 362 RenderViewHostImpl* rvh = |
| 363 static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 364 if (rvh) { |
| 365 scoped_refptr<GeolocationDispatcherHost> geolocation_dispatcher = |
| 366 static_cast<RenderProcessHostImpl*>( |
| 367 web_contents_->GetRenderProcessHost())-> |
| 368 geolocation_dispatcher_host(); |
| 369 if (geolocation_dispatcher.get()) { |
| 370 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 371 base::Bind(&GeolocationDispatcherHost::PauseOrResume, |
| 372 geolocation_dispatcher, |
| 373 rvh->GetRoutingID(), |
| 374 should_pause)); |
| 375 geolocation_needs_pause_ = false; |
| 376 } |
| 377 } |
| 378 } |
| 379 |
346 void ContentViewCoreImpl::OnTabCrashed() { | 380 void ContentViewCoreImpl::OnTabCrashed() { |
347 JNIEnv* env = AttachCurrentThread(); | 381 JNIEnv* env = AttachCurrentThread(); |
348 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 382 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
349 if (obj.is_null()) | 383 if (obj.is_null()) |
350 return; | 384 return; |
351 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); | 385 Java_ContentViewCore_resetVSyncNotification(env, obj.obj()); |
352 } | 386 } |
353 | 387 |
354 // All positions and sizes are in CSS pixels. | 388 // All positions and sizes are in CSS pixels. |
355 // Note that viewport_width/height is a best effort based. | 389 // Note that viewport_width/height is a best effort based. |
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { | 1654 void ContentViewCoreImpl::SendOrientationChangeEventInternal() { |
1621 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1655 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1622 if (rwhv) | 1656 if (rwhv) |
1623 rwhv->UpdateScreenInfo(rwhv->GetNativeView()); | 1657 rwhv->UpdateScreenInfo(rwhv->GetNativeView()); |
1624 | 1658 |
1625 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( | 1659 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( |
1626 web_contents_->GetRenderViewHost()); | 1660 web_contents_->GetRenderViewHost()); |
1627 rvhi->SendOrientationChangeEvent(device_orientation_); | 1661 rvhi->SendOrientationChangeEvent(device_orientation_); |
1628 } | 1662 } |
1629 | 1663 |
| 1664 bool ContentViewCoreImpl::IsGeolocationActiveForTesting(JNIEnv* env, |
| 1665 jobject obj) { |
| 1666 RenderViewHostImpl* rvh = |
| 1667 static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 1668 if (rvh) { |
| 1669 scoped_refptr<GeolocationDispatcherHost> geolocation_dispatcher = |
| 1670 static_cast<RenderProcessHostImpl*>( |
| 1671 web_contents_->GetRenderProcessHost())-> |
| 1672 geolocation_dispatcher_host(); |
| 1673 if (geolocation_dispatcher.get()) { |
| 1674 bool result = false; |
| 1675 base::WaitableEvent completion(false, false); |
| 1676 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 1677 base::Bind(IsGeolocationActiveForTestingOnIOThread, |
| 1678 geolocation_dispatcher, &completion, &result)); |
| 1679 completion.Wait(); |
| 1680 return result; |
| 1681 } |
| 1682 } |
| 1683 |
| 1684 return false; |
| 1685 } |
| 1686 |
1630 // This is called for each ContentView. | 1687 // This is called for each ContentView. |
1631 jlong Init(JNIEnv* env, jobject obj, | 1688 jlong Init(JNIEnv* env, jobject obj, |
1632 jboolean hardware_accelerated, | 1689 jboolean hardware_accelerated, |
1633 jlong native_web_contents, | 1690 jlong native_web_contents, |
1634 jlong view_android, | 1691 jlong view_android, |
1635 jlong window_android) { | 1692 jlong window_android) { |
1636 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1693 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
1637 env, obj, hardware_accelerated, | 1694 env, obj, hardware_accelerated, |
1638 reinterpret_cast<WebContents*>(native_web_contents), | 1695 reinterpret_cast<WebContents*>(native_web_contents), |
1639 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1696 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1640 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1697 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1641 return reinterpret_cast<intptr_t>(view); | 1698 return reinterpret_cast<intptr_t>(view); |
1642 } | 1699 } |
1643 | 1700 |
1644 bool RegisterContentViewCore(JNIEnv* env) { | 1701 bool RegisterContentViewCore(JNIEnv* env) { |
1645 return RegisterNativesImpl(env); | 1702 return RegisterNativesImpl(env); |
1646 } | 1703 } |
1647 | 1704 |
1648 } // namespace content | 1705 } // namespace content |
OLD | NEW |