| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "content/browser/frame_host/navigation_handle_impl.h" | 40 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 41 #include "content/browser/frame_host/navigator_impl.h" | 41 #include "content/browser/frame_host/navigator_impl.h" |
| 42 #include "content/browser/frame_host/render_frame_host_impl.h" | 42 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 43 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 43 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 44 #include "content/browser/geolocation/geolocation_service_context.h" | 44 #include "content/browser/geolocation/geolocation_service_context.h" |
| 45 #include "content/browser/host_zoom_map_impl.h" | 45 #include "content/browser/host_zoom_map_impl.h" |
| 46 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 46 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 47 #include "content/browser/manifest/manifest_manager_host.h" | 47 #include "content/browser/manifest/manifest_manager_host.h" |
| 48 #include "content/browser/media/audio_stream_monitor.h" | 48 #include "content/browser/media/audio_stream_monitor.h" |
| 49 #include "content/browser/media/capture/web_contents_audio_muter.h" | 49 #include "content/browser/media/capture/web_contents_audio_muter.h" |
| 50 #include "content/browser/media/media_web_contents_observer.h" |
| 50 #include "content/browser/message_port_message_filter.h" | 51 #include "content/browser/message_port_message_filter.h" |
| 51 #include "content/browser/plugin_content_origin_whitelist.h" | 52 #include "content/browser/plugin_content_origin_whitelist.h" |
| 52 #include "content/browser/power_save_blocker_impl.h" | |
| 53 #include "content/browser/renderer_host/render_process_host_impl.h" | 53 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 54 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 54 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
| 55 #include "content/browser/renderer_host/render_view_host_impl.h" | 55 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 56 #include "content/browser/renderer_host/render_widget_host_impl.h" | 56 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 57 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 57 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 58 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 58 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 59 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host_
impl.h" | 59 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host_
impl.h" |
| 60 #include "content/browser/site_instance_impl.h" | 60 #include "content/browser/site_instance_impl.h" |
| 61 #include "content/browser/wake_lock/wake_lock_service_context.h" | 61 #include "content/browser/wake_lock/wake_lock_service_context.h" |
| 62 #include "content/browser/web_contents/web_contents_view_guest.h" | 62 #include "content/browser/web_contents/web_contents_view_guest.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 84 #include "content/public/browser/navigation_details.h" | 84 #include "content/public/browser/navigation_details.h" |
| 85 #include "content/public/browser/notification_details.h" | 85 #include "content/public/browser/notification_details.h" |
| 86 #include "content/public/browser/notification_service.h" | 86 #include "content/public/browser/notification_service.h" |
| 87 #include "content/public/browser/render_widget_host_iterator.h" | 87 #include "content/public/browser/render_widget_host_iterator.h" |
| 88 #include "content/public/browser/resource_request_details.h" | 88 #include "content/public/browser/resource_request_details.h" |
| 89 #include "content/public/browser/screen_orientation_dispatcher_host.h" | 89 #include "content/public/browser/screen_orientation_dispatcher_host.h" |
| 90 #include "content/public/browser/security_style_explanations.h" | 90 #include "content/public/browser/security_style_explanations.h" |
| 91 #include "content/public/browser/storage_partition.h" | 91 #include "content/public/browser/storage_partition.h" |
| 92 #include "content/public/browser/user_metrics.h" | 92 #include "content/public/browser/user_metrics.h" |
| 93 #include "content/public/browser/web_contents_delegate.h" | 93 #include "content/public/browser/web_contents_delegate.h" |
| 94 #include "content/public/browser/web_contents_observer.h" | |
| 95 #include "content/public/common/bindings_policy.h" | 94 #include "content/public/common/bindings_policy.h" |
| 96 #include "content/public/common/browser_plugin_guest_mode.h" | 95 #include "content/public/common/browser_plugin_guest_mode.h" |
| 97 #include "content/public/common/content_constants.h" | 96 #include "content/public/common/content_constants.h" |
| 98 #include "content/public/common/content_switches.h" | 97 #include "content/public/common/content_switches.h" |
| 99 #include "content/public/common/page_zoom.h" | 98 #include "content/public/common/page_zoom.h" |
| 100 #include "content/public/common/result_codes.h" | 99 #include "content/public/common/result_codes.h" |
| 101 #include "content/public/common/security_style.h" | 100 #include "content/public/common/security_style.h" |
| 102 #include "content/public/common/url_constants.h" | 101 #include "content/public/common/url_constants.h" |
| 103 #include "content/public/common/url_utils.h" | 102 #include "content/public/common/url_utils.h" |
| 104 #include "content/public/common/web_preferences.h" | 103 #include "content/public/common/web_preferences.h" |
| 105 #include "mojo/common/url_type_converters.h" | 104 #include "mojo/common/url_type_converters.h" |
| 106 #include "mojo/converters/geometry/geometry_type_converters.h" | 105 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 107 #include "net/http/http_cache.h" | 106 #include "net/http/http_cache.h" |
| 108 #include "net/http/http_transaction_factory.h" | 107 #include "net/http/http_transaction_factory.h" |
| 109 #include "net/url_request/url_request_context.h" | 108 #include "net/url_request/url_request_context.h" |
| 110 #include "net/url_request/url_request_context_getter.h" | 109 #include "net/url_request/url_request_context_getter.h" |
| 111 #include "skia/public/type_converters.h" | 110 #include "skia/public/type_converters.h" |
| 112 #include "third_party/skia/include/core/SkBitmap.h" | 111 #include "third_party/skia/include/core/SkBitmap.h" |
| 113 #include "ui/base/layout.h" | 112 #include "ui/base/layout.h" |
| 114 #include "ui/gfx/display.h" | 113 #include "ui/gfx/display.h" |
| 115 #include "ui/gfx/screen.h" | 114 #include "ui/gfx/screen.h" |
| 116 #include "ui/gl/gl_switches.h" | 115 #include "ui/gl/gl_switches.h" |
| 117 | 116 |
| 118 #if defined(ENABLE_BROWSER_CDMS) | |
| 119 #include "content/browser/media/media_web_contents_observer.h" | |
| 120 #endif | |
| 121 | |
| 122 #if defined(OS_ANDROID) | 117 #if defined(OS_ANDROID) |
| 123 #include "content/browser/android/content_video_view.h" | 118 #include "content/browser/android/content_video_view.h" |
| 124 #include "content/browser/media/android/media_session.h" | 119 #include "content/browser/media/android/media_session.h" |
| 125 #endif // OS_ANDROID | 120 #endif // OS_ANDROID |
| 126 | 121 |
| 127 #if defined(OS_ANDROID) && !defined(USE_AURA) | 122 #if defined(OS_ANDROID) && !defined(USE_AURA) |
| 128 #include "content/browser/android/date_time_chooser_android.h" | 123 #include "content/browser/android/date_time_chooser_android.h" |
| 129 #include "content/browser/web_contents/web_contents_android.h" | 124 #include "content/browser/web_contents/web_contents_android.h" |
| 130 #endif // OS_ANDROID && !USE_AURA | 125 #endif // OS_ANDROID && !USE_AURA |
| 131 | 126 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 geolocation_service_context_(new GeolocationServiceContext()), | 401 geolocation_service_context_(new GeolocationServiceContext()), |
| 407 accessibility_mode_( | 402 accessibility_mode_( |
| 408 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), | 403 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
| 409 audio_stream_monitor_(this), | 404 audio_stream_monitor_(this), |
| 410 virtual_keyboard_requested_(false), | 405 virtual_keyboard_requested_(false), |
| 411 page_scale_factor_is_one_(true), | 406 page_scale_factor_is_one_(true), |
| 412 loading_weak_factory_(this) { | 407 loading_weak_factory_(this) { |
| 413 frame_tree_.SetFrameRemoveListener( | 408 frame_tree_.SetFrameRemoveListener( |
| 414 base::Bind(&WebContentsImpl::OnFrameRemoved, | 409 base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 415 base::Unretained(this))); | 410 base::Unretained(this))); |
| 416 #if defined(ENABLE_BROWSER_CDMS) | |
| 417 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); | 411 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
| 418 #endif | |
| 419 | |
| 420 wake_lock_service_context_.reset(new WakeLockServiceContext(this)); | 412 wake_lock_service_context_.reset(new WakeLockServiceContext(this)); |
| 421 } | 413 } |
| 422 | 414 |
| 423 WebContentsImpl::~WebContentsImpl() { | 415 WebContentsImpl::~WebContentsImpl() { |
| 424 is_being_destroyed_ = true; | 416 is_being_destroyed_ = true; |
| 425 | 417 |
| 426 rwh_input_event_router_.reset(); | 418 rwh_input_event_router_.reset(); |
| 427 | 419 |
| 428 // Delete all RFH pending shutdown, which will lead the corresponding RVH to | 420 // Delete all RFH pending shutdown, which will lead the corresponding RVH to |
| 429 // shutdown and be deleted as well. | 421 // shutdown and be deleted as well. |
| 430 frame_tree_.ForEach( | 422 frame_tree_.ForEach( |
| 431 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown)); | 423 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown)); |
| 432 | 424 |
| 433 // Destroy all WebUI instances. | 425 // Destroy all WebUI instances. |
| 434 frame_tree_.ForEach(base::Bind(&RenderFrameHostManager::ClearWebUIInstances)); | 426 frame_tree_.ForEach(base::Bind(&RenderFrameHostManager::ClearWebUIInstances)); |
| 435 | 427 |
| 436 ClearAllPowerSaveBlockers(); | |
| 437 | |
| 438 for (std::set<RenderWidgetHostImpl*>::iterator iter = | 428 for (std::set<RenderWidgetHostImpl*>::iterator iter = |
| 439 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) { | 429 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) { |
| 440 (*iter)->DetachDelegate(); | 430 (*iter)->DetachDelegate(); |
| 441 } | 431 } |
| 442 created_widgets_.clear(); | 432 created_widgets_.clear(); |
| 443 | 433 |
| 444 // Clear out any JavaScript state. | 434 // Clear out any JavaScript state. |
| 445 if (dialog_manager_) | 435 if (dialog_manager_) |
| 446 dialog_manager_->ResetDialogState(this); | 436 dialog_manager_->ResetDialogState(this); |
| 447 | 437 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 OnDomOperationResponse) | 616 OnDomOperationResponse) |
| 627 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, | 617 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, |
| 628 OnThemeColorChanged) | 618 OnThemeColorChanged) |
| 629 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, | 619 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
| 630 OnDocumentLoadedInFrame) | 620 OnDocumentLoadedInFrame) |
| 631 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) | 621 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
| 632 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) | 622 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 633 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) | 623 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) |
| 634 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, | 624 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, |
| 635 OnSetSelectedColorInColorChooser) | 625 OnSetSelectedColorInColorChooser) |
| 636 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification, | 626 |
| 637 OnMediaPlayingNotification) | |
| 638 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification, | |
| 639 OnMediaPausedNotification) | |
| 640 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, | 627 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
| 641 OnFirstVisuallyNonEmptyPaint) | 628 OnFirstVisuallyNonEmptyPaint) |
| 642 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, | 629 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, |
| 643 OnDidLoadResourceFromMemoryCache) | 630 OnDidLoadResourceFromMemoryCache) |
| 644 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, | 631 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, |
| 645 OnDidDisplayInsecureContent) | 632 OnDidDisplayInsecureContent) |
| 646 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, | 633 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, |
| 647 OnDidRunInsecureContent) | 634 OnDidRunInsecureContent) |
| 648 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors, | 635 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors, |
| 649 OnDidDisplayContentWithCertificateErrors) | 636 OnDidDisplayContentWithCertificateErrors) |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 return is_being_destroyed_; | 1149 return is_being_destroyed_; |
| 1163 } | 1150 } |
| 1164 | 1151 |
| 1165 void WebContentsImpl::NotifyNavigationStateChanged( | 1152 void WebContentsImpl::NotifyNavigationStateChanged( |
| 1166 InvalidateTypes changed_flags) { | 1153 InvalidateTypes changed_flags) { |
| 1167 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 1154 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1168 // is fixed. | 1155 // is fixed. |
| 1169 tracked_objects::ScopedTracker tracking_profile( | 1156 tracked_objects::ScopedTracker tracking_profile( |
| 1170 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1157 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1171 "466285 WebContentsImpl::NotifyNavigationStateChanged")); | 1158 "466285 WebContentsImpl::NotifyNavigationStateChanged")); |
| 1172 // Create and release the audio power save blocker depending on whether the | 1159 // Notify the media observer of potential audibility changes. |
| 1173 // tab is actively producing audio or not. | 1160 if (changed_flags & INVALIDATE_TYPE_TAB) { |
| 1174 if ((changed_flags & INVALIDATE_TYPE_TAB) && | 1161 media_web_contents_observer_->MaybeUpdateAudibleState( |
| 1175 AudioStreamMonitor::monitoring_available()) { | 1162 AudioStreamMonitor::monitoring_available() && WasRecentlyAudible()); |
| 1176 if (WasRecentlyAudible()) { | |
| 1177 if (!audio_power_save_blocker_) | |
| 1178 CreateAudioPowerSaveBlocker(); | |
| 1179 } else { | |
| 1180 audio_power_save_blocker_.reset(); | |
| 1181 } | |
| 1182 } | 1163 } |
| 1183 | 1164 |
| 1184 if (delegate_) | 1165 if (delegate_) |
| 1185 delegate_->NavigationStateChanged(this, changed_flags); | 1166 delegate_->NavigationStateChanged(this, changed_flags); |
| 1186 } | 1167 } |
| 1187 | 1168 |
| 1188 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { | 1169 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
| 1189 return last_active_time_; | 1170 return last_active_time_; |
| 1190 } | 1171 } |
| 1191 | 1172 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1208 last_active_time_ = base::TimeTicks::Now(); | 1189 last_active_time_ = base::TimeTicks::Now(); |
| 1209 | 1190 |
| 1210 // The resize rect might have changed while this was inactive -- send the new | 1191 // The resize rect might have changed while this was inactive -- send the new |
| 1211 // one to make sure it's up to date. | 1192 // one to make sure it's up to date. |
| 1212 RenderViewHostImpl* rvh = GetRenderViewHost(); | 1193 RenderViewHostImpl* rvh = GetRenderViewHost(); |
| 1213 if (rvh) { | 1194 if (rvh) { |
| 1214 rvh->GetWidget()->ResizeRectChanged( | 1195 rvh->GetWidget()->ResizeRectChanged( |
| 1215 GetRootWindowResizerRect(rvh->GetWidget())); | 1196 GetRootWindowResizerRect(rvh->GetWidget())); |
| 1216 } | 1197 } |
| 1217 | 1198 |
| 1218 // Restore power save blocker if there are active video players running. | |
| 1219 if (!active_video_players_.empty() && !video_power_save_blocker_) | |
| 1220 CreateVideoPowerSaveBlocker(); | |
| 1221 | |
| 1222 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); | 1199 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); |
| 1223 | 1200 |
| 1224 should_normally_be_visible_ = true; | 1201 should_normally_be_visible_ = true; |
| 1225 } | 1202 } |
| 1226 | 1203 |
| 1227 void WebContentsImpl::WasHidden() { | 1204 void WebContentsImpl::WasHidden() { |
| 1228 // If there are entities capturing screenshots or video (e.g., mirroring), | 1205 // If there are entities capturing screenshots or video (e.g., mirroring), |
| 1229 // don't activate the "disable rendering" optimization. | 1206 // don't activate the "disable rendering" optimization. |
| 1230 if (capturer_count_ == 0) { | 1207 if (capturer_count_ == 0) { |
| 1231 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to | 1208 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
| 1232 // open a tab in the background, then closes the tab before selecting it. | 1209 // open a tab in the background, then closes the tab before selecting it. |
| 1233 // This is because closing the tab calls WebContentsImpl::Destroy(), which | 1210 // This is because closing the tab calls WebContentsImpl::Destroy(), which |
| 1234 // removes the |GetRenderViewHost()|; then when we actually destroy the | 1211 // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 1235 // window, OnWindowPosChanged() notices and calls WasHidden() (which | 1212 // window, OnWindowPosChanged() notices and calls WasHidden() (which |
| 1236 // calls us). | 1213 // calls us). |
| 1237 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { | 1214 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1238 if (view) | 1215 if (view) |
| 1239 view->Hide(); | 1216 view->Hide(); |
| 1240 } | 1217 } |
| 1241 | |
| 1242 // Release any video power save blockers held as video is not visible. | |
| 1243 video_power_save_blocker_.reset(); | |
| 1244 } | 1218 } |
| 1245 | 1219 |
| 1246 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); | 1220 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); |
| 1247 | 1221 |
| 1248 should_normally_be_visible_ = false; | 1222 should_normally_be_visible_ = false; |
| 1249 } | 1223 } |
| 1250 | 1224 |
| 1251 void WebContentsImpl::WasOccluded() { | 1225 void WebContentsImpl::WasOccluded() { |
| 1252 if (capturer_count_ > 0) | 1226 if (capturer_count_ > 0) |
| 1253 return; | 1227 return; |
| (...skipping 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3486 // for the new page has committed. | 3460 // for the new page has committed. |
| 3487 RenderViewHostImpl* rvhi = | 3461 RenderViewHostImpl* rvhi = |
| 3488 static_cast<RenderViewHostImpl*>(render_view_message_source_); | 3462 static_cast<RenderViewHostImpl*>(render_view_message_source_); |
| 3489 if (!rvhi->is_active()) | 3463 if (!rvhi->is_active()) |
| 3490 return; | 3464 return; |
| 3491 | 3465 |
| 3492 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3466 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3493 DidUpdateFaviconURL(candidates)); | 3467 DidUpdateFaviconURL(candidates)); |
| 3494 } | 3468 } |
| 3495 | 3469 |
| 3496 void WebContentsImpl::CreateAudioPowerSaveBlocker() { | |
| 3497 DCHECK(!audio_power_save_blocker_); | |
| 3498 audio_power_save_blocker_ = PowerSaveBlocker::Create( | |
| 3499 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
| 3500 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); | |
| 3501 } | |
| 3502 | |
| 3503 void WebContentsImpl::CreateVideoPowerSaveBlocker() { | |
| 3504 DCHECK(!video_power_save_blocker_); | |
| 3505 DCHECK(!active_video_players_.empty()); | |
| 3506 video_power_save_blocker_ = PowerSaveBlocker::Create( | |
| 3507 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | |
| 3508 PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); | |
| 3509 //TODO(mfomitchev): Support PowerSaveBlocker on Aura - crbug.com/546718. | |
| 3510 #if defined(OS_ANDROID) && !defined(USE_AURA) | |
| 3511 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) | |
| 3512 ->InitDisplaySleepBlocker(this); | |
| 3513 #endif | |
| 3514 } | |
| 3515 | |
| 3516 void WebContentsImpl::MaybeReleasePowerSaveBlockers() { | |
| 3517 // If there are no more audio players and we don't have audio stream | |
| 3518 // monitoring, release the audio power save blocker here instead of during | |
| 3519 // NotifyNavigationStateChanged(). | |
| 3520 if (active_audio_players_.empty() && | |
| 3521 !AudioStreamMonitor::monitoring_available()) { | |
| 3522 audio_power_save_blocker_.reset(); | |
| 3523 } | |
| 3524 | |
| 3525 // If there are no more video players, clear the video power save blocker. | |
| 3526 if (active_video_players_.empty()) | |
| 3527 video_power_save_blocker_.reset(); | |
| 3528 } | |
| 3529 | |
| 3530 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie, | |
| 3531 bool has_video, | |
| 3532 bool has_audio, | |
| 3533 bool is_remote) { | |
| 3534 // Ignore the videos playing remotely and don't hold the wake lock for the | |
| 3535 // screen. | |
| 3536 if (is_remote) return; | |
| 3537 | |
| 3538 if (has_audio) { | |
| 3539 AddMediaPlayerEntry(player_cookie, &active_audio_players_); | |
| 3540 | |
| 3541 // If we don't have audio stream monitoring, allocate the audio power save | |
| 3542 // blocker here instead of during NotifyNavigationStateChanged(). | |
| 3543 if (!audio_power_save_blocker_ && | |
| 3544 !AudioStreamMonitor::monitoring_available()) { | |
| 3545 CreateAudioPowerSaveBlocker(); | |
| 3546 } | |
| 3547 } | |
| 3548 | |
| 3549 if (has_video) { | |
| 3550 AddMediaPlayerEntry(player_cookie, &active_video_players_); | |
| 3551 | |
| 3552 // If we're not hidden and have just created a player, create a blocker. | |
| 3553 if (!video_power_save_blocker_ && !IsHidden()) | |
| 3554 CreateVideoPowerSaveBlocker(); | |
| 3555 } | |
| 3556 | |
| 3557 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying()); | |
| 3558 } | |
| 3559 | |
| 3560 void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) { | |
| 3561 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_); | |
| 3562 RemoveMediaPlayerEntry(player_cookie, &active_video_players_); | |
| 3563 MaybeReleasePowerSaveBlockers(); | |
| 3564 | |
| 3565 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaPaused()); | |
| 3566 } | |
| 3567 | |
| 3568 #if defined(OS_ANDROID) | 3470 #if defined(OS_ANDROID) |
| 3569 | 3471 |
| 3570 void WebContentsImpl::OnMediaSessionStateChanged() { | 3472 void WebContentsImpl::OnMediaSessionStateChanged() { |
| 3571 MediaSession* session = MediaSession::Get(this); | 3473 MediaSession* session = MediaSession::Get(this); |
| 3572 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3474 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3573 MediaSessionStateChanged(session->IsControllable(), | 3475 MediaSessionStateChanged(session->IsControllable(), |
| 3574 session->IsSuspended())); | 3476 session->IsSuspended())); |
| 3575 } | 3477 } |
| 3576 | 3478 |
| 3577 void WebContentsImpl::ResumeMediaSession() { | 3479 void WebContentsImpl::ResumeMediaSession() { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3792 } | 3694 } |
| 3793 | 3695 |
| 3794 void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { | 3696 void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
| 3795 FOR_EACH_OBSERVER(WebContentsObserver, | 3697 FOR_EACH_OBSERVER(WebContentsObserver, |
| 3796 observers_, | 3698 observers_, |
| 3797 RenderFrameCreated(render_frame_host)); | 3699 RenderFrameCreated(render_frame_host)); |
| 3798 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host); | 3700 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host); |
| 3799 } | 3701 } |
| 3800 | 3702 |
| 3801 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { | 3703 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
| 3802 ClearPowerSaveBlockers(render_frame_host); | |
| 3803 FOR_EACH_OBSERVER(WebContentsObserver, | 3704 FOR_EACH_OBSERVER(WebContentsObserver, |
| 3804 observers_, | 3705 observers_, |
| 3805 RenderFrameDeleted(render_frame_host)); | 3706 RenderFrameDeleted(render_frame_host)); |
| 3806 } | 3707 } |
| 3807 | 3708 |
| 3808 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, | 3709 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 3809 const ContextMenuParams& params) { | 3710 const ContextMenuParams& params) { |
| 3810 ContextMenuParams context_menu_params(params); | 3711 ContextMenuParams context_menu_params(params); |
| 3811 // Allow WebContentsDelegates to handle the context menu operation first. | 3712 // Allow WebContentsDelegates to handle the context menu operation first. |
| 3812 if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) | 3713 if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4737 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4638 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
| 4738 return browser_plugin_embedder_.get(); | 4639 return browser_plugin_embedder_.get(); |
| 4739 } | 4640 } |
| 4740 | 4641 |
| 4741 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4642 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 4742 if (browser_plugin_embedder_) | 4643 if (browser_plugin_embedder_) |
| 4743 return; | 4644 return; |
| 4744 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); | 4645 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 4745 } | 4646 } |
| 4746 | 4647 |
| 4747 void WebContentsImpl::ClearPowerSaveBlockers( | |
| 4748 RenderFrameHost* render_frame_host) { | |
| 4749 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_); | |
| 4750 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_); | |
| 4751 MaybeReleasePowerSaveBlockers(); | |
| 4752 } | |
| 4753 | |
| 4754 void WebContentsImpl::ClearAllPowerSaveBlockers() { | |
| 4755 active_audio_players_.clear(); | |
| 4756 active_video_players_.clear(); | |
| 4757 audio_power_save_blocker_.reset(); | |
| 4758 video_power_save_blocker_.reset(); | |
| 4759 } | |
| 4760 | |
| 4761 gfx::Size WebContentsImpl::GetSizeForNewRenderView() { | 4648 gfx::Size WebContentsImpl::GetSizeForNewRenderView() { |
| 4762 gfx::Size size; | 4649 gfx::Size size; |
| 4763 if (delegate_) | 4650 if (delegate_) |
| 4764 size = delegate_->GetSizeForNewRenderView(this); | 4651 size = delegate_->GetSizeForNewRenderView(this); |
| 4765 if (size.IsEmpty()) | 4652 if (size.IsEmpty()) |
| 4766 size = GetContainerBounds().size(); | 4653 size = GetContainerBounds().size(); |
| 4767 return size; | 4654 return size; |
| 4768 } | 4655 } |
| 4769 | 4656 |
| 4770 void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { | 4657 void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
| 4771 FOR_EACH_OBSERVER( | 4658 FOR_EACH_OBSERVER( |
| 4772 WebContentsObserver, observers_, FrameDeleted(render_frame_host)); | 4659 WebContentsObserver, observers_, FrameDeleted(render_frame_host)); |
| 4773 } | 4660 } |
| 4774 | 4661 |
| 4775 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4662 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 4776 if (!delegate_) | 4663 if (!delegate_) |
| 4777 return; | 4664 return; |
| 4778 const gfx::Size new_size = GetPreferredSize(); | 4665 const gfx::Size new_size = GetPreferredSize(); |
| 4779 if (new_size != old_size) | 4666 if (new_size != old_size) |
| 4780 delegate_->UpdatePreferredSize(this, new_size); | 4667 delegate_->UpdatePreferredSize(this, new_size); |
| 4781 } | 4668 } |
| 4782 | 4669 |
| 4783 void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie, | |
| 4784 ActiveMediaPlayerMap* player_map) { | |
| 4785 if (!HasValidFrameSource()) | |
| 4786 return; | |
| 4787 | |
| 4788 const uintptr_t key = | |
| 4789 reinterpret_cast<uintptr_t>(render_frame_message_source_); | |
| 4790 DCHECK(std::find((*player_map)[key].begin(), | |
| 4791 (*player_map)[key].end(), | |
| 4792 player_cookie) == (*player_map)[key].end()); | |
| 4793 (*player_map)[key].push_back(player_cookie); | |
| 4794 } | |
| 4795 | |
| 4796 void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie, | |
| 4797 ActiveMediaPlayerMap* player_map) { | |
| 4798 if (!HasValidFrameSource()) | |
| 4799 return; | |
| 4800 | |
| 4801 const uintptr_t key = | |
| 4802 reinterpret_cast<uintptr_t>(render_frame_message_source_); | |
| 4803 ActiveMediaPlayerMap::iterator it = player_map->find(key); | |
| 4804 if (it == player_map->end()) | |
| 4805 return; | |
| 4806 | |
| 4807 // Remove the player. | |
| 4808 PlayerList::iterator player_it = | |
| 4809 std::find(it->second.begin(), it->second.end(), player_cookie); | |
| 4810 if (player_it != it->second.end()) | |
| 4811 it->second.erase(player_it); | |
| 4812 | |
| 4813 // If there are no players left, remove the map entry. | |
| 4814 if (it->second.empty()) | |
| 4815 player_map->erase(it); | |
| 4816 } | |
| 4817 | |
| 4818 void WebContentsImpl::RemoveAllMediaPlayerEntries( | |
| 4819 RenderFrameHost* render_frame_host, | |
| 4820 ActiveMediaPlayerMap* player_map) { | |
| 4821 ActiveMediaPlayerMap::iterator it = | |
| 4822 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host)); | |
| 4823 if (it == player_map->end()) | |
| 4824 return; | |
| 4825 player_map->erase(it); | |
| 4826 } | |
| 4827 | |
| 4828 WebUI* WebContentsImpl::CreateWebUI(const GURL& url, | 4670 WebUI* WebContentsImpl::CreateWebUI(const GURL& url, |
| 4829 const std::string& frame_name) { | 4671 const std::string& frame_name) { |
| 4830 WebUIImpl* web_ui = new WebUIImpl(this, frame_name); | 4672 WebUIImpl* web_ui = new WebUIImpl(this, frame_name); |
| 4831 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> | 4673 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> |
| 4832 CreateWebUIControllerForURL(web_ui, url); | 4674 CreateWebUIControllerForURL(web_ui, url); |
| 4833 if (controller) { | 4675 if (controller) { |
| 4834 web_ui->AddMessageHandler(new GenericHandler()); | 4676 web_ui->AddMessageHandler(new GenericHandler()); |
| 4835 web_ui->SetController(controller); | 4677 web_ui->SetController(controller); |
| 4836 return web_ui; | 4678 return web_ui; |
| 4837 } | 4679 } |
| 4838 | 4680 |
| 4839 delete web_ui; | 4681 delete web_ui; |
| 4840 return NULL; | 4682 return NULL; |
| 4841 } | 4683 } |
| 4842 | 4684 |
| 4843 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4685 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4844 force_disable_overscroll_content_ = force_disable; | 4686 force_disable_overscroll_content_ = force_disable; |
| 4845 if (view_) | 4687 if (view_) |
| 4846 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4688 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4847 } | 4689 } |
| 4848 | 4690 |
| 4691 void WebContentsImpl::MediaStartedPlaying( |
| 4692 const WebContentsObserver::MediaPlayerId& id) { |
| 4693 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); |
| 4694 } |
| 4695 |
| 4696 void WebContentsImpl::MediaStoppedPlaying( |
| 4697 const WebContentsObserver::MediaPlayerId& id) { |
| 4698 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); |
| 4699 } |
| 4700 |
| 4849 } // namespace content | 4701 } // namespace content |
| OLD | NEW |