| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 | 1040 |
| 1035 bool WebContentsImpl::IsBeingDestroyed() const { | 1041 bool WebContentsImpl::IsBeingDestroyed() const { |
| 1036 return is_being_destroyed_; | 1042 return is_being_destroyed_; |
| 1037 } | 1043 } |
| 1038 | 1044 |
| 1039 void WebContentsImpl::NotifyNavigationStateChanged( | 1045 void WebContentsImpl::NotifyNavigationStateChanged( |
| 1040 InvalidateTypes changed_flags) { | 1046 InvalidateTypes changed_flags) { |
| 1041 // Create and release the audio power save blocker depending on whether the | 1047 // Create and release the audio power save blocker depending on whether the |
| 1042 // tab is actively producing audio or not. | 1048 // tab is actively producing audio or not. |
| 1043 if ((changed_flags & INVALIDATE_TYPE_TAB) && | 1049 if ((changed_flags & INVALIDATE_TYPE_TAB) && |
| 1044 AudioStreamMonitor::monitoring_available()) { | 1050 audio_state_provider_->IsAudioStateAvailable()) { |
| 1045 if (WasRecentlyAudible()) { | 1051 if (WasRecentlyAudible()) { |
| 1046 if (!audio_power_save_blocker_) | 1052 if (!audio_power_save_blocker_) |
| 1047 CreateAudioPowerSaveBlocker(); | 1053 CreateAudioPowerSaveBlocker(); |
| 1048 } else { | 1054 } else { |
| 1049 audio_power_save_blocker_.reset(); | 1055 audio_power_save_blocker_.reset(); |
| 1050 } | 1056 } |
| 1051 } | 1057 } |
| 1052 | 1058 |
| 1053 if (delegate_) | 1059 if (delegate_) |
| 1054 delegate_->NavigationStateChanged(this, changed_flags); | 1060 delegate_->NavigationStateChanged(this, changed_flags); |
| (...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2516 } | 2522 } |
| 2517 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); | 2523 Send(new ViewMsg_StopFinding(GetRoutingID(), action)); |
| 2518 } | 2524 } |
| 2519 | 2525 |
| 2520 void WebContentsImpl::InsertCSS(const std::string& css) { | 2526 void WebContentsImpl::InsertCSS(const std::string& css) { |
| 2521 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest( | 2527 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest( |
| 2522 GetMainFrame()->GetRoutingID(), css)); | 2528 GetMainFrame()->GetRoutingID(), css)); |
| 2523 } | 2529 } |
| 2524 | 2530 |
| 2525 bool WebContentsImpl::WasRecentlyAudible() { | 2531 bool WebContentsImpl::WasRecentlyAudible() { |
| 2526 return audio_stream_monitor_.WasRecentlyAudible(); | 2532 return audio_state_provider_->WasRecentlyAudible(); |
| 2527 } | 2533 } |
| 2528 | 2534 |
| 2529 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { | 2535 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { |
| 2530 manifest_manager_host_->GetManifest(GetMainFrame(), callback); | 2536 manifest_manager_host_->GetManifest(GetMainFrame(), callback); |
| 2531 } | 2537 } |
| 2532 | 2538 |
| 2533 void WebContentsImpl::ExitFullscreen() { | 2539 void WebContentsImpl::ExitFullscreen() { |
| 2534 // Clean up related state and initiate the fullscreen exit. | 2540 // Clean up related state and initiate the fullscreen exit. |
| 2535 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary(); | 2541 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary(); |
| 2536 ExitFullscreenMode(); | 2542 ExitFullscreenMode(); |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3203 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) | 3209 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) |
| 3204 ->InitDisplaySleepBlocker(GetView()->GetNativeView()); | 3210 ->InitDisplaySleepBlocker(GetView()->GetNativeView()); |
| 3205 #endif | 3211 #endif |
| 3206 } | 3212 } |
| 3207 | 3213 |
| 3208 void WebContentsImpl::MaybeReleasePowerSaveBlockers() { | 3214 void WebContentsImpl::MaybeReleasePowerSaveBlockers() { |
| 3209 // If there are no more audio players and we don't have audio stream | 3215 // If there are no more audio players and we don't have audio stream |
| 3210 // monitoring, release the audio power save blocker here instead of during | 3216 // monitoring, release the audio power save blocker here instead of during |
| 3211 // NotifyNavigationStateChanged(). | 3217 // NotifyNavigationStateChanged(). |
| 3212 if (active_audio_players_.empty() && | 3218 if (active_audio_players_.empty() && |
| 3213 !AudioStreamMonitor::monitoring_available()) { | 3219 !audio_state_provider_->IsAudioStateAvailable()) { |
| 3214 audio_power_save_blocker_.reset(); | 3220 audio_power_save_blocker_.reset(); |
| 3215 } | 3221 } |
| 3216 | 3222 |
| 3217 // If there are no more video players, clear the video power save blocker. | 3223 // If there are no more video players, clear the video power save blocker. |
| 3218 if (active_video_players_.empty()) | 3224 if (active_video_players_.empty()) |
| 3219 video_power_save_blocker_.reset(); | 3225 video_power_save_blocker_.reset(); |
| 3220 } | 3226 } |
| 3221 | 3227 |
| 3222 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie, | 3228 void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie, |
| 3223 bool has_video, | 3229 bool has_video, |
| 3224 bool has_audio, | 3230 bool has_audio, |
| 3225 bool is_remote) { | 3231 bool is_remote) { |
| 3226 // Ignore the videos playing remotely and don't hold the wake lock for the | 3232 // Ignore the videos playing remotely and don't hold the wake lock for the |
| 3227 // screen. | 3233 // screen. |
| 3228 if (is_remote) return; | 3234 if (is_remote) return; |
| 3229 | 3235 |
| 3230 if (has_audio) { | 3236 if (has_audio) { |
| 3231 AddMediaPlayerEntry(player_cookie, &active_audio_players_); | 3237 AddMediaPlayerEntry(player_cookie, &active_audio_players_); |
| 3232 | 3238 |
| 3233 // If we don't have audio stream monitoring, allocate the audio power save | 3239 // If we don't have audio stream monitoring, allocate the audio power save |
| 3234 // blocker here instead of during NotifyNavigationStateChanged(). | 3240 // blocker here instead of during NotifyNavigationStateChanged(). |
| 3235 if (!audio_power_save_blocker_ && | 3241 if (!audio_power_save_blocker_ && |
| 3236 !AudioStreamMonitor::monitoring_available()) { | 3242 !audio_state_provider_->IsAudioStateAvailable()) { |
| 3237 CreateAudioPowerSaveBlocker(); | 3243 CreateAudioPowerSaveBlocker(); |
| 3238 } | 3244 } |
| 3239 } | 3245 } |
| 3240 | 3246 |
| 3241 if (has_video) { | 3247 if (has_video) { |
| 3242 AddMediaPlayerEntry(player_cookie, &active_video_players_); | 3248 AddMediaPlayerEntry(player_cookie, &active_video_players_); |
| 3243 | 3249 |
| 3244 // If we're not hidden and have just created a player, create a blocker. | 3250 // If we're not hidden and have just created a player, create a blocker. |
| 3245 if (!video_power_save_blocker_ && !IsHidden()) | 3251 if (!video_power_save_blocker_ && !IsHidden()) |
| 3246 CreateVideoPowerSaveBlocker(); | 3252 CreateVideoPowerSaveBlocker(); |
| (...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4529 node->render_manager()->ResumeResponseDeferredAtStart(); | 4535 node->render_manager()->ResumeResponseDeferredAtStart(); |
| 4530 } | 4536 } |
| 4531 | 4537 |
| 4532 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4538 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4533 force_disable_overscroll_content_ = force_disable; | 4539 force_disable_overscroll_content_ = force_disable; |
| 4534 if (view_) | 4540 if (view_) |
| 4535 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4541 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4536 } | 4542 } |
| 4537 | 4543 |
| 4538 } // namespace content | 4544 } // namespace content |
| OLD | NEW |