Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 972973002: Revert of Propagate audible state from player to the containing tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #include "ui/gfx/screen.h" 101 #include "ui/gfx/screen.h"
102 #include "ui/gl/gl_switches.h" 102 #include "ui/gl/gl_switches.h"
103 103
104 #if defined(ENABLE_BROWSER_CDMS) 104 #if defined(ENABLE_BROWSER_CDMS)
105 #include "content/browser/media/media_web_contents_observer.h" 105 #include "content/browser/media/media_web_contents_observer.h"
106 #endif 106 #endif
107 107
108 #if defined(OS_ANDROID) 108 #if defined(OS_ANDROID)
109 #include "content/browser/android/content_video_view.h" 109 #include "content/browser/android/content_video_view.h"
110 #include "content/browser/android/date_time_chooser_android.h" 110 #include "content/browser/android/date_time_chooser_android.h"
111 #include "content/browser/android/media_players_observer.h"
112 #include "content/browser/media/android/browser_media_player_manager.h" 111 #include "content/browser/media/android/browser_media_player_manager.h"
113 #include "content/browser/web_contents/web_contents_android.h" 112 #include "content/browser/web_contents/web_contents_android.h"
114 #endif 113 #endif
115 114
116 #if defined(OS_MACOSX) 115 #if defined(OS_MACOSX)
117 #include "base/mac/foundation_util.h" 116 #include "base/mac/foundation_util.h"
118 #endif 117 #endif
119 118
120 namespace content { 119 namespace content {
121 namespace { 120 namespace {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 render_view_message_source_(NULL), 351 render_view_message_source_(NULL),
353 render_frame_message_source_(NULL), 352 render_frame_message_source_(NULL),
354 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), 353 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
355 fullscreen_widget_had_focus_at_shutdown_(false), 354 fullscreen_widget_had_focus_at_shutdown_(false),
356 is_subframe_(false), 355 is_subframe_(false),
357 force_disable_overscroll_content_(false), 356 force_disable_overscroll_content_(false),
358 last_dialog_suppressed_(false), 357 last_dialog_suppressed_(false),
359 geolocation_service_context_(new GeolocationServiceContext()), 358 geolocation_service_context_(new GeolocationServiceContext()),
360 accessibility_mode_( 359 accessibility_mode_(
361 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), 360 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
361 audio_stream_monitor_(this),
362 virtual_keyboard_requested_(false), 362 virtual_keyboard_requested_(false),
363 loading_weak_factory_(this) { 363 loading_weak_factory_(this) {
364 frame_tree_.SetFrameRemoveListener( 364 frame_tree_.SetFrameRemoveListener(
365 base::Bind(&WebContentsImpl::OnFrameRemoved, 365 base::Bind(&WebContentsImpl::OnFrameRemoved,
366 base::Unretained(this))); 366 base::Unretained(this)));
367 #if defined(ENABLE_BROWSER_CDMS) 367 #if defined(ENABLE_BROWSER_CDMS)
368 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); 368 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
369 #endif 369 #endif
370
371 #if defined(OS_ANDROID)
372 audio_state_provider_.reset(new MediaPlayersObserver(this));
373 #else
374 audio_state_provider_.reset(new AudioStreamMonitor(this));
375 #endif
376 } 370 }
377 371
378 WebContentsImpl::~WebContentsImpl() { 372 WebContentsImpl::~WebContentsImpl() {
379 is_being_destroyed_ = true; 373 is_being_destroyed_ = true;
380 374
381 // Delete all RFH pending shutdown, which will lead the corresponding RVH to 375 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
382 // shutdown and be deleted as well. 376 // shutdown and be deleted as well.
383 frame_tree_.ForEach( 377 frame_tree_.ForEach(
384 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown)); 378 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
385 379
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1034
1041 bool WebContentsImpl::IsBeingDestroyed() const { 1035 bool WebContentsImpl::IsBeingDestroyed() const {
1042 return is_being_destroyed_; 1036 return is_being_destroyed_;
1043 } 1037 }
1044 1038
1045 void WebContentsImpl::NotifyNavigationStateChanged( 1039 void WebContentsImpl::NotifyNavigationStateChanged(
1046 InvalidateTypes changed_flags) { 1040 InvalidateTypes changed_flags) {
1047 // Create and release the audio power save blocker depending on whether the 1041 // Create and release the audio power save blocker depending on whether the
1048 // tab is actively producing audio or not. 1042 // tab is actively producing audio or not.
1049 if ((changed_flags & INVALIDATE_TYPE_TAB) && 1043 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
1050 audio_state_provider_->IsAudioStateAvailable()) { 1044 AudioStreamMonitor::monitoring_available()) {
1051 if (WasRecentlyAudible()) { 1045 if (WasRecentlyAudible()) {
1052 if (!audio_power_save_blocker_) 1046 if (!audio_power_save_blocker_)
1053 CreateAudioPowerSaveBlocker(); 1047 CreateAudioPowerSaveBlocker();
1054 } else { 1048 } else {
1055 audio_power_save_blocker_.reset(); 1049 audio_power_save_blocker_.reset();
1056 } 1050 }
1057 } 1051 }
1058 1052
1059 if (delegate_) 1053 if (delegate_)
1060 delegate_->NavigationStateChanged(this, changed_flags); 1054 delegate_->NavigationStateChanged(this, changed_flags);
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 } 2509 }
2516 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); 2510 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2517 } 2511 }
2518 2512
2519 void WebContentsImpl::InsertCSS(const std::string& css) { 2513 void WebContentsImpl::InsertCSS(const std::string& css) {
2520 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest( 2514 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2521 GetMainFrame()->GetRoutingID(), css)); 2515 GetMainFrame()->GetRoutingID(), css));
2522 } 2516 }
2523 2517
2524 bool WebContentsImpl::WasRecentlyAudible() { 2518 bool WebContentsImpl::WasRecentlyAudible() {
2525 return audio_state_provider_->WasRecentlyAudible(); 2519 return audio_stream_monitor_.WasRecentlyAudible();
2526 } 2520 }
2527 2521
2528 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { 2522 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2529 manifest_manager_host_->GetManifest(GetMainFrame(), callback); 2523 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2530 } 2524 }
2531 2525
2532 void WebContentsImpl::ExitFullscreen() { 2526 void WebContentsImpl::ExitFullscreen() {
2533 // Clean up related state and initiate the fullscreen exit. 2527 // Clean up related state and initiate the fullscreen exit.
2534 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary(); 2528 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2535 ExitFullscreenMode(); 2529 ExitFullscreenMode();
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
3202 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) 3196 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3203 ->InitDisplaySleepBlocker(GetView()->GetNativeView()); 3197 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3204 #endif 3198 #endif
3205 } 3199 }
3206 3200
3207 void WebContentsImpl::MaybeReleasePowerSaveBlockers() { 3201 void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3208 // If there are no more audio players and we don't have audio stream 3202 // If there are no more audio players and we don't have audio stream
3209 // monitoring, release the audio power save blocker here instead of during 3203 // monitoring, release the audio power save blocker here instead of during
3210 // NotifyNavigationStateChanged(). 3204 // NotifyNavigationStateChanged().
3211 if (active_audio_players_.empty() && 3205 if (active_audio_players_.empty() &&
3212 !audio_state_provider_->IsAudioStateAvailable()) { 3206 !AudioStreamMonitor::monitoring_available()) {
3213 audio_power_save_blocker_.reset(); 3207 audio_power_save_blocker_.reset();
3214 } 3208 }
3215 3209
3216 // If there are no more video players, clear the video power save blocker. 3210 // If there are no more video players, clear the video power save blocker.
3217 if (active_video_players_.empty()) 3211 if (active_video_players_.empty())
3218 video_power_save_blocker_.reset(); 3212 video_power_save_blocker_.reset();
3219 } 3213 }
3220 3214
3221 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie, 3215 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3222 bool has_video, 3216 bool has_video,
3223 bool has_audio, 3217 bool has_audio,
3224 bool is_remote) { 3218 bool is_remote) {
3225 // Ignore the videos playing remotely and don't hold the wake lock for the 3219 // Ignore the videos playing remotely and don't hold the wake lock for the
3226 // screen. 3220 // screen.
3227 if (is_remote) return; 3221 if (is_remote) return;
3228 3222
3229 if (has_audio) { 3223 if (has_audio) {
3230 AddMediaPlayerEntry(player_cookie, &active_audio_players_); 3224 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3231 3225
3232 // If we don't have audio stream monitoring, allocate the audio power save 3226 // If we don't have audio stream monitoring, allocate the audio power save
3233 // blocker here instead of during NotifyNavigationStateChanged(). 3227 // blocker here instead of during NotifyNavigationStateChanged().
3234 if (!audio_power_save_blocker_ && 3228 if (!audio_power_save_blocker_ &&
3235 !audio_state_provider_->IsAudioStateAvailable()) { 3229 !AudioStreamMonitor::monitoring_available()) {
3236 CreateAudioPowerSaveBlocker(); 3230 CreateAudioPowerSaveBlocker();
3237 } 3231 }
3238 } 3232 }
3239 3233
3240 if (has_video) { 3234 if (has_video) {
3241 AddMediaPlayerEntry(player_cookie, &active_video_players_); 3235 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3242 3236
3243 // If we're not hidden and have just created a player, create a blocker. 3237 // If we're not hidden and have just created a player, create a blocker.
3244 if (!video_power_save_blocker_ && !IsHidden()) 3238 if (!video_power_save_blocker_ && !IsHidden())
3245 CreateVideoPowerSaveBlocker(); 3239 CreateVideoPowerSaveBlocker();
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
4522 node->render_manager()->ResumeResponseDeferredAtStart(); 4516 node->render_manager()->ResumeResponseDeferredAtStart();
4523 } 4517 }
4524 4518
4525 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4519 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4526 force_disable_overscroll_content_ = force_disable; 4520 force_disable_overscroll_content_ = force_disable;
4527 if (view_) 4521 if (view_)
4528 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4522 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4529 } 4523 }
4530 4524
4531 } // namespace content 4525 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698