Chromium Code Reviews| 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 ClearAllPowerSaveBlockers(); | |
| 434 | |
| 435 for (std::set<RenderWidgetHostImpl*>::iterator iter = | 425 for (std::set<RenderWidgetHostImpl*>::iterator iter = |
| 436 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) { | 426 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) { |
| 437 (*iter)->DetachDelegate(); | 427 (*iter)->DetachDelegate(); |
| 438 } | 428 } |
| 439 created_widgets_.clear(); | 429 created_widgets_.clear(); |
| 440 | 430 |
| 441 // Clear out any JavaScript state. | 431 // Clear out any JavaScript state. |
| 442 if (dialog_manager_) | 432 if (dialog_manager_) |
| 443 dialog_manager_->ResetDialogState(this); | 433 dialog_manager_->ResetDialogState(this); |
| 444 | 434 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 OnDomOperationResponse) | 613 OnDomOperationResponse) |
| 624 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, | 614 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, |
| 625 OnThemeColorChanged) | 615 OnThemeColorChanged) |
| 626 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, | 616 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
| 627 OnDocumentLoadedInFrame) | 617 OnDocumentLoadedInFrame) |
| 628 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) | 618 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
| 629 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) | 619 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 630 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) | 620 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) |
| 631 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, | 621 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, |
| 632 OnSetSelectedColorInColorChooser) | 622 OnSetSelectedColorInColorChooser) |
| 633 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification, | 623 |
| 634 OnMediaPlayingNotification) | |
| 635 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification, | |
| 636 OnMediaPausedNotification) | |
| 637 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, | 624 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
| 638 OnFirstVisuallyNonEmptyPaint) | 625 OnFirstVisuallyNonEmptyPaint) |
| 639 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, | 626 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, |
| 640 OnDidLoadResourceFromMemoryCache) | 627 OnDidLoadResourceFromMemoryCache) |
| 641 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, | 628 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, |
| 642 OnDidDisplayInsecureContent) | 629 OnDidDisplayInsecureContent) |
| 643 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, | 630 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, |
| 644 OnDidRunInsecureContent) | 631 OnDidRunInsecureContent) |
| 645 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) | 632 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
| 646 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) | 633 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1150 return is_being_destroyed_; | 1137 return is_being_destroyed_; |
| 1151 } | 1138 } |
| 1152 | 1139 |
| 1153 void WebContentsImpl::NotifyNavigationStateChanged( | 1140 void WebContentsImpl::NotifyNavigationStateChanged( |
| 1154 InvalidateTypes changed_flags) { | 1141 InvalidateTypes changed_flags) { |
| 1155 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 | 1142 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1156 // is fixed. | 1143 // is fixed. |
| 1157 tracked_objects::ScopedTracker tracking_profile( | 1144 tracked_objects::ScopedTracker tracking_profile( |
| 1158 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1145 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1159 "466285 WebContentsImpl::NotifyNavigationStateChanged")); | 1146 "466285 WebContentsImpl::NotifyNavigationStateChanged")); |
| 1160 // Create and release the audio power save blocker depending on whether the | 1147 // Notify the media observer of potential audibility changes. |
| 1161 // tab is actively producing audio or not. | 1148 if (changed_flags & INVALIDATE_TYPE_TAB) { |
| 1162 if ((changed_flags & INVALIDATE_TYPE_TAB) && | 1149 media_web_contents_observer_->MaybeUpdateAudibleState( |
| 1163 AudioStreamMonitor::monitoring_available()) { | 1150 AudioStreamMonitor::monitoring_available() && WasRecentlyAudible()); |
| 1164 if (WasRecentlyAudible()) { | |
| 1165 if (!audio_power_save_blocker_) | |
| 1166 CreateAudioPowerSaveBlocker(); | |
| 1167 } else { | |
| 1168 audio_power_save_blocker_.reset(); | |
| 1169 } | |
| 1170 } | 1151 } |
| 1171 | 1152 |
| 1172 if (delegate_) | 1153 if (delegate_) |
| 1173 delegate_->NavigationStateChanged(this, changed_flags); | 1154 delegate_->NavigationStateChanged(this, changed_flags); |
| 1174 } | 1155 } |
| 1175 | 1156 |
| 1176 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { | 1157 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
| 1177 return last_active_time_; | 1158 return last_active_time_; |
| 1178 } | 1159 } |
| 1179 | 1160 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1196 last_active_time_ = base::TimeTicks::Now(); | 1177 last_active_time_ = base::TimeTicks::Now(); |
| 1197 | 1178 |
| 1198 // The resize rect might have changed while this was inactive -- send the new | 1179 // The resize rect might have changed while this was inactive -- send the new |
| 1199 // one to make sure it's up to date. | 1180 // one to make sure it's up to date. |
| 1200 RenderViewHostImpl* rvh = GetRenderViewHost(); | 1181 RenderViewHostImpl* rvh = GetRenderViewHost(); |
| 1201 if (rvh) { | 1182 if (rvh) { |
| 1202 rvh->GetWidget()->ResizeRectChanged( | 1183 rvh->GetWidget()->ResizeRectChanged( |
| 1203 GetRootWindowResizerRect(rvh->GetWidget())); | 1184 GetRootWindowResizerRect(rvh->GetWidget())); |
| 1204 } | 1185 } |
| 1205 | 1186 |
| 1206 // Restore power save blocker if there are active video players running. | |
| 1207 if (!active_video_players_.empty() && !video_power_save_blocker_) | |
| 1208 CreateVideoPowerSaveBlocker(); | |
| 1209 | |
| 1210 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); | 1187 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); |
| 1211 | 1188 |
| 1212 should_normally_be_visible_ = true; | 1189 should_normally_be_visible_ = true; |
| 1213 } | 1190 } |
| 1214 | 1191 |
| 1215 void WebContentsImpl::WasHidden() { | 1192 void WebContentsImpl::WasHidden() { |
| 1216 // If there are entities capturing screenshots or video (e.g., mirroring), | 1193 // If there are entities capturing screenshots or video (e.g., mirroring), |
| 1217 // don't activate the "disable rendering" optimization. | 1194 // don't activate the "disable rendering" optimization. |
| 1218 if (capturer_count_ == 0) { | 1195 if (capturer_count_ == 0) { |
| 1219 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to | 1196 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
| 1220 // open a tab in the background, then closes the tab before selecting it. | 1197 // open a tab in the background, then closes the tab before selecting it. |
| 1221 // This is because closing the tab calls WebContentsImpl::Destroy(), which | 1198 // This is because closing the tab calls WebContentsImpl::Destroy(), which |
| 1222 // removes the |GetRenderViewHost()|; then when we actually destroy the | 1199 // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 1223 // window, OnWindowPosChanged() notices and calls WasHidden() (which | 1200 // window, OnWindowPosChanged() notices and calls WasHidden() (which |
| 1224 // calls us). | 1201 // calls us). |
| 1225 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { | 1202 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1226 if (view) | 1203 if (view) |
| 1227 view->Hide(); | 1204 view->Hide(); |
| 1228 } | 1205 } |
| 1229 | |
| 1230 // Release any video power save blockers held as video is not visible. | |
| 1231 video_power_save_blocker_.reset(); | |
| 1232 } | 1206 } |
| 1233 | 1207 |
| 1234 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); | 1208 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); |
| 1235 | 1209 |
| 1236 should_normally_be_visible_ = false; | 1210 should_normally_be_visible_ = false; |
| 1237 } | 1211 } |
| 1238 | 1212 |
| 1239 void WebContentsImpl::WasOccluded() { | 1213 void WebContentsImpl::WasOccluded() { |
| 1240 if (capturer_count_ > 0) | 1214 if (capturer_count_ > 0) |
| 1241 return; | 1215 return; |
| (...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3441 // for the new page has committed. | 3415 // for the new page has committed. |
| 3442 RenderViewHostImpl* rvhi = | 3416 RenderViewHostImpl* rvhi = |
| 3443 static_cast<RenderViewHostImpl*>(render_view_message_source_); | 3417 static_cast<RenderViewHostImpl*>(render_view_message_source_); |
| 3444 if (!rvhi->is_active()) | 3418 if (!rvhi->is_active()) |
| 3445 return; | 3419 return; |
| 3446 | 3420 |
| 3447 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3421 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3448 DidUpdateFaviconURL(candidates)); | 3422 DidUpdateFaviconURL(candidates)); |
| 3449 } | 3423 } |
| 3450 | 3424 |
| 3451 void WebContentsImpl::CreateAudioPowerSaveBlocker() { | |
| 3452 DCHECK(!audio_power_save_blocker_); | |
| 3453 audio_power_save_blocker_ = PowerSaveBlocker::Create( | |
| 3454 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
| 3455 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); | |
| 3456 } | |
| 3457 | |
| 3458 void WebContentsImpl::CreateVideoPowerSaveBlocker() { | |
| 3459 DCHECK(!video_power_save_blocker_); | |
| 3460 DCHECK(!active_video_players_.empty()); | |
| 3461 video_power_save_blocker_ = PowerSaveBlocker::Create( | |
| 3462 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | |
| 3463 PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); | |
| 3464 //TODO(mfomitchev): Support PowerSaveBlocker on Aura - crbug.com/546718. | |
| 3465 #if defined(OS_ANDROID) && !defined(USE_AURA) | |
| 3466 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) | |
| 3467 ->InitDisplaySleepBlocker(this); | |
| 3468 #endif | |
| 3469 } | |
| 3470 | |
| 3471 void WebContentsImpl::MaybeReleasePowerSaveBlockers() { | |
| 3472 // If there are no more audio players and we don't have audio stream | |
| 3473 // monitoring, release the audio power save blocker here instead of during | |
| 3474 // NotifyNavigationStateChanged(). | |
| 3475 if (active_audio_players_.empty() && | |
| 3476 !AudioStreamMonitor::monitoring_available()) { | |
| 3477 audio_power_save_blocker_.reset(); | |
| 3478 } | |
| 3479 | |
| 3480 // If there are no more video players, clear the video power save blocker. | |
| 3481 if (active_video_players_.empty()) | |
| 3482 video_power_save_blocker_.reset(); | |
| 3483 } | |
| 3484 | |
| 3485 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie, | |
| 3486 bool has_video, | |
| 3487 bool has_audio, | |
| 3488 bool is_remote) { | |
| 3489 // Ignore the videos playing remotely and don't hold the wake lock for the | |
| 3490 // screen. | |
| 3491 if (is_remote) return; | |
| 3492 | |
| 3493 if (has_audio) { | |
| 3494 AddMediaPlayerEntry(player_cookie, &active_audio_players_); | |
| 3495 | |
| 3496 // If we don't have audio stream monitoring, allocate the audio power save | |
| 3497 // blocker here instead of during NotifyNavigationStateChanged(). | |
| 3498 if (!audio_power_save_blocker_ && | |
| 3499 !AudioStreamMonitor::monitoring_available()) { | |
| 3500 CreateAudioPowerSaveBlocker(); | |
| 3501 } | |
| 3502 } | |
| 3503 | |
| 3504 if (has_video) { | |
| 3505 AddMediaPlayerEntry(player_cookie, &active_video_players_); | |
| 3506 | |
| 3507 // If we're not hidden and have just created a player, create a blocker. | |
| 3508 if (!video_power_save_blocker_ && !IsHidden()) | |
| 3509 CreateVideoPowerSaveBlocker(); | |
| 3510 } | |
| 3511 | |
| 3512 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying()); | |
| 3513 } | |
| 3514 | |
| 3515 void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) { | |
| 3516 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_); | |
| 3517 RemoveMediaPlayerEntry(player_cookie, &active_video_players_); | |
| 3518 MaybeReleasePowerSaveBlockers(); | |
| 3519 | |
| 3520 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaPaused()); | |
| 3521 } | |
| 3522 | |
| 3523 #if defined(OS_ANDROID) | 3425 #if defined(OS_ANDROID) |
| 3524 | 3426 |
| 3525 void WebContentsImpl::OnMediaSessionStateChanged() { | 3427 void WebContentsImpl::OnMediaSessionStateChanged() { |
| 3526 MediaSession* session = MediaSession::Get(this); | 3428 MediaSession* session = MediaSession::Get(this); |
| 3527 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3429 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3528 MediaSessionStateChanged(session->IsControllable(), | 3430 MediaSessionStateChanged(session->IsControllable(), |
| 3529 session->IsSuspended())); | 3431 session->IsSuspended())); |
| 3530 } | 3432 } |
| 3531 | 3433 |
| 3532 void WebContentsImpl::ResumeMediaSession() { | 3434 void WebContentsImpl::ResumeMediaSession() { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3747 } | 3649 } |
| 3748 | 3650 |
| 3749 void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { | 3651 void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
| 3750 FOR_EACH_OBSERVER(WebContentsObserver, | 3652 FOR_EACH_OBSERVER(WebContentsObserver, |
| 3751 observers_, | 3653 observers_, |
| 3752 RenderFrameCreated(render_frame_host)); | 3654 RenderFrameCreated(render_frame_host)); |
| 3753 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host); | 3655 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host); |
| 3754 } | 3656 } |
| 3755 | 3657 |
| 3756 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { | 3658 void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
| 3757 ClearPowerSaveBlockers(render_frame_host); | |
| 3758 FOR_EACH_OBSERVER(WebContentsObserver, | 3659 FOR_EACH_OBSERVER(WebContentsObserver, |
| 3759 observers_, | 3660 observers_, |
| 3760 RenderFrameDeleted(render_frame_host)); | 3661 RenderFrameDeleted(render_frame_host)); |
| 3761 } | 3662 } |
| 3762 | 3663 |
| 3763 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, | 3664 void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 3764 const ContextMenuParams& params) { | 3665 const ContextMenuParams& params) { |
| 3765 ContextMenuParams context_menu_params(params); | 3666 ContextMenuParams context_menu_params(params); |
| 3766 // Allow WebContentsDelegates to handle the context menu operation first. | 3667 // Allow WebContentsDelegates to handle the context menu operation first. |
| 3767 if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) | 3668 if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4704 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4605 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
| 4705 return browser_plugin_embedder_.get(); | 4606 return browser_plugin_embedder_.get(); |
| 4706 } | 4607 } |
| 4707 | 4608 |
| 4708 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4609 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 4709 if (browser_plugin_embedder_) | 4610 if (browser_plugin_embedder_) |
| 4710 return; | 4611 return; |
| 4711 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); | 4612 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 4712 } | 4613 } |
| 4713 | 4614 |
| 4714 void WebContentsImpl::ClearPowerSaveBlockers( | |
| 4715 RenderFrameHost* render_frame_host) { | |
| 4716 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_); | |
| 4717 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_); | |
| 4718 MaybeReleasePowerSaveBlockers(); | |
| 4719 } | |
| 4720 | |
| 4721 void WebContentsImpl::ClearAllPowerSaveBlockers() { | |
| 4722 active_audio_players_.clear(); | |
| 4723 active_video_players_.clear(); | |
| 4724 audio_power_save_blocker_.reset(); | |
| 4725 video_power_save_blocker_.reset(); | |
| 4726 } | |
| 4727 | |
| 4728 gfx::Size WebContentsImpl::GetSizeForNewRenderView() { | 4615 gfx::Size WebContentsImpl::GetSizeForNewRenderView() { |
| 4729 gfx::Size size; | 4616 gfx::Size size; |
| 4730 if (delegate_) | 4617 if (delegate_) |
| 4731 size = delegate_->GetSizeForNewRenderView(this); | 4618 size = delegate_->GetSizeForNewRenderView(this); |
| 4732 if (size.IsEmpty()) | 4619 if (size.IsEmpty()) |
| 4733 size = GetContainerBounds().size(); | 4620 size = GetContainerBounds().size(); |
| 4734 return size; | 4621 return size; |
| 4735 } | 4622 } |
| 4736 | 4623 |
| 4737 void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { | 4624 void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
| 4738 FOR_EACH_OBSERVER( | 4625 FOR_EACH_OBSERVER( |
| 4739 WebContentsObserver, observers_, FrameDeleted(render_frame_host)); | 4626 WebContentsObserver, observers_, FrameDeleted(render_frame_host)); |
| 4740 } | 4627 } |
| 4741 | 4628 |
| 4742 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4629 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 4743 if (!delegate_) | 4630 if (!delegate_) |
| 4744 return; | 4631 return; |
| 4745 const gfx::Size new_size = GetPreferredSize(); | 4632 const gfx::Size new_size = GetPreferredSize(); |
| 4746 if (new_size != old_size) | 4633 if (new_size != old_size) |
| 4747 delegate_->UpdatePreferredSize(this, new_size); | 4634 delegate_->UpdatePreferredSize(this, new_size); |
| 4748 } | 4635 } |
| 4749 | 4636 |
| 4750 void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie, | |
| 4751 ActiveMediaPlayerMap* player_map) { | |
| 4752 if (!HasValidFrameSource()) | |
| 4753 return; | |
| 4754 | |
| 4755 const uintptr_t key = | |
| 4756 reinterpret_cast<uintptr_t>(render_frame_message_source_); | |
| 4757 DCHECK(std::find((*player_map)[key].begin(), | |
| 4758 (*player_map)[key].end(), | |
| 4759 player_cookie) == (*player_map)[key].end()); | |
| 4760 (*player_map)[key].push_back(player_cookie); | |
| 4761 } | |
| 4762 | |
| 4763 void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie, | |
| 4764 ActiveMediaPlayerMap* player_map) { | |
| 4765 if (!HasValidFrameSource()) | |
| 4766 return; | |
| 4767 | |
| 4768 const uintptr_t key = | |
| 4769 reinterpret_cast<uintptr_t>(render_frame_message_source_); | |
| 4770 ActiveMediaPlayerMap::iterator it = player_map->find(key); | |
| 4771 if (it == player_map->end()) | |
| 4772 return; | |
| 4773 | |
| 4774 // Remove the player. | |
| 4775 PlayerList::iterator player_it = | |
| 4776 std::find(it->second.begin(), it->second.end(), player_cookie); | |
| 4777 if (player_it != it->second.end()) | |
| 4778 it->second.erase(player_it); | |
| 4779 | |
| 4780 // If there are no players left, remove the map entry. | |
| 4781 if (it->second.empty()) | |
| 4782 player_map->erase(it); | |
| 4783 } | |
| 4784 | |
| 4785 void WebContentsImpl::RemoveAllMediaPlayerEntries( | |
| 4786 RenderFrameHost* render_frame_host, | |
| 4787 ActiveMediaPlayerMap* player_map) { | |
| 4788 ActiveMediaPlayerMap::iterator it = | |
| 4789 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host)); | |
| 4790 if (it == player_map->end()) | |
| 4791 return; | |
| 4792 player_map->erase(it); | |
| 4793 } | |
| 4794 | |
| 4795 WebUI* WebContentsImpl::CreateWebUI(const GURL& url, | 4637 WebUI* WebContentsImpl::CreateWebUI(const GURL& url, |
| 4796 const std::string& frame_name) { | 4638 const std::string& frame_name) { |
| 4797 WebUIImpl* web_ui = new WebUIImpl(this, frame_name); | 4639 WebUIImpl* web_ui = new WebUIImpl(this, frame_name); |
| 4798 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> | 4640 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> |
| 4799 CreateWebUIControllerForURL(web_ui, url); | 4641 CreateWebUIControllerForURL(web_ui, url); |
| 4800 if (controller) { | 4642 if (controller) { |
| 4801 web_ui->AddMessageHandler(new GenericHandler()); | 4643 web_ui->AddMessageHandler(new GenericHandler()); |
| 4802 web_ui->SetController(controller); | 4644 web_ui->SetController(controller); |
| 4803 return web_ui; | 4645 return web_ui; |
| 4804 } | 4646 } |
| 4805 | 4647 |
| 4806 delete web_ui; | 4648 delete web_ui; |
| 4807 return NULL; | 4649 return NULL; |
| 4808 } | 4650 } |
| 4809 | 4651 |
| 4810 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4652 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4811 force_disable_overscroll_content_ = force_disable; | 4653 force_disable_overscroll_content_ = force_disable; |
| 4812 if (view_) | 4654 if (view_) |
| 4813 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4655 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4814 } | 4656 } |
| 4815 | 4657 |
| 4658 void WebContentsImpl::MediaStartedPlaying( | |
| 4659 const WebContentsObserver::MediaPlayerId& id) { | |
| 4660 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); | |
|
ncarter (slow)
2015/12/02 17:49:31
This FOR_EACH_OBSERVER will happen in the context
DaleCurtis
2015/12/02 19:55:46
Correct, which is also the existing behavior.
| |
| 4661 } | |
| 4662 | |
| 4663 void WebContentsImpl::MediaPaused( | |
| 4664 const WebContentsObserver::MediaPlayerId& id) { | |
| 4665 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaPaused(id)); | |
| 4666 } | |
| 4667 | |
| 4816 } // namespace content | 4668 } // namespace content |
| OLD | NEW |