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

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

Issue 896673003: Propagate audible state from player to the containing tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed implementation of nativeIsPlayingAudio() 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"
111 #include "content/browser/media/android/browser_media_player_manager.h" 112 #include "content/browser/media/android/browser_media_player_manager.h"
112 #include "content/browser/web_contents/web_contents_android.h" 113 #include "content/browser/web_contents/web_contents_android.h"
113 #endif 114 #endif
114 115
115 #if defined(OS_MACOSX) 116 #if defined(OS_MACOSX)
116 #include "base/mac/foundation_util.h" 117 #include "base/mac/foundation_util.h"
117 #endif 118 #endif
118 119
119 namespace content { 120 namespace content {
120 namespace { 121 namespace {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 render_view_message_source_(NULL), 352 render_view_message_source_(NULL),
352 render_frame_message_source_(NULL), 353 render_frame_message_source_(NULL),
353 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), 354 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
354 fullscreen_widget_had_focus_at_shutdown_(false), 355 fullscreen_widget_had_focus_at_shutdown_(false),
355 is_subframe_(false), 356 is_subframe_(false),
356 force_disable_overscroll_content_(false), 357 force_disable_overscroll_content_(false),
357 last_dialog_suppressed_(false), 358 last_dialog_suppressed_(false),
358 geolocation_service_context_(new GeolocationServiceContext()), 359 geolocation_service_context_(new GeolocationServiceContext()),
359 accessibility_mode_( 360 accessibility_mode_(
360 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), 361 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
370 } 376 }
371 377
372 WebContentsImpl::~WebContentsImpl() { 378 WebContentsImpl::~WebContentsImpl() {
373 is_being_destroyed_ = true; 379 is_being_destroyed_ = true;
374 380
375 // Delete all RFH pending shutdown, which will lead the corresponding RVH to 381 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
376 // shutdown and be deleted as well. 382 // shutdown and be deleted as well.
377 frame_tree_.ForEach( 383 frame_tree_.ForEach(
378 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown)); 384 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
379 385
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 result.push_back(wci); 481 result.push_back(wci);
476 } 482 }
477 } 483 }
478 return result; 484 return result;
479 } 485 }
480 486
481 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { 487 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
482 return GetRenderManager(); 488 return GetRenderManager();
483 } 489 }
484 490
491 void WebContentsImpl::SetAudioStateProviderForTesting(
492 AudioStateProvider* provider) {
493 // Take ownership
494 audio_state_provider_.reset(provider);
495 }
496
485 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, 497 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
486 const IPC::Message& message) { 498 const IPC::Message& message) {
487 return OnMessageReceived(render_view_host, NULL, message); 499 return OnMessageReceived(render_view_host, NULL, message);
488 } 500 }
489 501
490 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, 502 bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
491 RenderFrameHost* render_frame_host, 503 RenderFrameHost* render_frame_host,
492 const IPC::Message& message) { 504 const IPC::Message& message) {
493 DCHECK(render_view_host || render_frame_host); 505 DCHECK(render_view_host || render_frame_host);
494 if (GetWebUI() && 506 if (GetWebUI() &&
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1043
1032 bool WebContentsImpl::IsBeingDestroyed() const { 1044 bool WebContentsImpl::IsBeingDestroyed() const {
1033 return is_being_destroyed_; 1045 return is_being_destroyed_;
1034 } 1046 }
1035 1047
1036 void WebContentsImpl::NotifyNavigationStateChanged( 1048 void WebContentsImpl::NotifyNavigationStateChanged(
1037 InvalidateTypes changed_flags) { 1049 InvalidateTypes changed_flags) {
1038 // Create and release the audio power save blocker depending on whether the 1050 // Create and release the audio power save blocker depending on whether the
1039 // tab is actively producing audio or not. 1051 // tab is actively producing audio or not.
1040 if ((changed_flags & INVALIDATE_TYPE_TAB) && 1052 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
1041 AudioStreamMonitor::monitoring_available()) { 1053 audio_state_provider_->IsAudioStateAvailable()) {
1042 if (WasRecentlyAudible()) { 1054 if (WasRecentlyAudible()) {
1043 if (!audio_power_save_blocker_) 1055 if (!audio_power_save_blocker_)
1044 CreateAudioPowerSaveBlocker(); 1056 CreateAudioPowerSaveBlocker();
1045 } else { 1057 } else {
1046 audio_power_save_blocker_.reset(); 1058 audio_power_save_blocker_.reset();
1047 } 1059 }
1048 } 1060 }
1049 1061
1050 if (delegate_) 1062 if (delegate_)
1051 delegate_->NavigationStateChanged(this, changed_flags); 1063 delegate_->NavigationStateChanged(this, changed_flags);
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2506 } 2518 }
2507 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); 2519 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2508 } 2520 }
2509 2521
2510 void WebContentsImpl::InsertCSS(const std::string& css) { 2522 void WebContentsImpl::InsertCSS(const std::string& css) {
2511 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest( 2523 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2512 GetMainFrame()->GetRoutingID(), css)); 2524 GetMainFrame()->GetRoutingID(), css));
2513 } 2525 }
2514 2526
2515 bool WebContentsImpl::WasRecentlyAudible() { 2527 bool WebContentsImpl::WasRecentlyAudible() {
2516 return audio_stream_monitor_.WasRecentlyAudible(); 2528 return audio_state_provider_->WasRecentlyAudible();
2517 } 2529 }
2518 2530
2519 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { 2531 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2520 manifest_manager_host_->GetManifest(GetMainFrame(), callback); 2532 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2521 } 2533 }
2522 2534
2523 void WebContentsImpl::ExitFullscreen() { 2535 void WebContentsImpl::ExitFullscreen() {
2524 // Clean up related state and initiate the fullscreen exit. 2536 // Clean up related state and initiate the fullscreen exit.
2525 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary(); 2537 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2526 ExitFullscreenMode(); 2538 ExitFullscreenMode();
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) 3205 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3194 ->InitDisplaySleepBlocker(GetView()->GetNativeView()); 3206 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3195 #endif 3207 #endif
3196 } 3208 }
3197 3209
3198 void WebContentsImpl::MaybeReleasePowerSaveBlockers() { 3210 void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3199 // If there are no more audio players and we don't have audio stream 3211 // If there are no more audio players and we don't have audio stream
3200 // monitoring, release the audio power save blocker here instead of during 3212 // monitoring, release the audio power save blocker here instead of during
3201 // NotifyNavigationStateChanged(). 3213 // NotifyNavigationStateChanged().
3202 if (active_audio_players_.empty() && 3214 if (active_audio_players_.empty() &&
3203 !AudioStreamMonitor::monitoring_available()) { 3215 !audio_state_provider_->IsAudioStateAvailable()) {
3204 audio_power_save_blocker_.reset(); 3216 audio_power_save_blocker_.reset();
3205 } 3217 }
3206 3218
3207 // If there are no more video players, clear the video power save blocker. 3219 // If there are no more video players, clear the video power save blocker.
3208 if (active_video_players_.empty()) 3220 if (active_video_players_.empty())
3209 video_power_save_blocker_.reset(); 3221 video_power_save_blocker_.reset();
3210 } 3222 }
3211 3223
3212 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie, 3224 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3213 bool has_video, 3225 bool has_video,
3214 bool has_audio, 3226 bool has_audio,
3215 bool is_remote) { 3227 bool is_remote) {
3216 // Ignore the videos playing remotely and don't hold the wake lock for the 3228 // Ignore the videos playing remotely and don't hold the wake lock for the
3217 // screen. 3229 // screen.
3218 if (is_remote) return; 3230 if (is_remote) return;
3219 3231
3220 if (has_audio) { 3232 if (has_audio) {
3221 AddMediaPlayerEntry(player_cookie, &active_audio_players_); 3233 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3222 3234
3223 // If we don't have audio stream monitoring, allocate the audio power save 3235 // If we don't have audio stream monitoring, allocate the audio power save
3224 // blocker here instead of during NotifyNavigationStateChanged(). 3236 // blocker here instead of during NotifyNavigationStateChanged().
3225 if (!audio_power_save_blocker_ && 3237 if (!audio_power_save_blocker_ &&
3226 !AudioStreamMonitor::monitoring_available()) { 3238 !audio_state_provider_->IsAudioStateAvailable()) {
3227 CreateAudioPowerSaveBlocker(); 3239 CreateAudioPowerSaveBlocker();
3228 } 3240 }
3229 } 3241 }
3230 3242
3231 if (has_video) { 3243 if (has_video) {
3232 AddMediaPlayerEntry(player_cookie, &active_video_players_); 3244 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3233 3245
3234 // If we're not hidden and have just created a player, create a blocker. 3246 // If we're not hidden and have just created a player, create a blocker.
3235 if (!video_power_save_blocker_ && !IsHidden()) 3247 if (!video_power_save_blocker_ && !IsHidden())
3236 CreateVideoPowerSaveBlocker(); 3248 CreateVideoPowerSaveBlocker();
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
4513 node->render_manager()->ResumeResponseDeferredAtStart(); 4525 node->render_manager()->ResumeResponseDeferredAtStart();
4514 } 4526 }
4515 4527
4516 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4528 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4517 force_disable_overscroll_content_ = force_disable; 4529 force_disable_overscroll_content_ = force_disable;
4518 if (view_) 4530 if (view_)
4519 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4531 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4520 } 4532 }
4521 4533
4522 } // namespace content 4534 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698