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

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

Issue 757033005: Make tab audible and muted states and cause available for an extension API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 currentPinchZoomStepDelta_(0), 324 currentPinchZoomStepDelta_(0),
325 render_view_message_source_(NULL), 325 render_view_message_source_(NULL),
326 fullscreen_widget_routing_id_(MSG_ROUTING_NONE), 326 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
327 fullscreen_widget_had_focus_at_shutdown_(false), 327 fullscreen_widget_had_focus_at_shutdown_(false),
328 is_subframe_(false), 328 is_subframe_(false),
329 force_disable_overscroll_content_(false), 329 force_disable_overscroll_content_(false),
330 last_dialog_suppressed_(false), 330 last_dialog_suppressed_(false),
331 geolocation_service_context_(new GeolocationServiceContext()), 331 geolocation_service_context_(new GeolocationServiceContext()),
332 accessibility_mode_( 332 accessibility_mode_(
333 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), 333 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
334 audio_stream_monitor_(this), 334 audio_stream_monitor_(base::Bind(
335 &WebContentsImpl::NotifyAudibleStateChanged, base::Unretained(this))),
335 loading_weak_factory_(this) { 336 loading_weak_factory_(this) {
336 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) 337 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
337 g_created_callbacks.Get().at(i).Run(this); 338 g_created_callbacks.Get().at(i).Run(this);
338 frame_tree_.SetFrameRemoveListener( 339 frame_tree_.SetFrameRemoveListener(
339 base::Bind(&WebContentsImpl::OnFrameRemoved, 340 base::Bind(&WebContentsImpl::OnFrameRemoved,
340 base::Unretained(this))); 341 base::Unretained(this)));
341 } 342 }
342 343
343 WebContentsImpl::~WebContentsImpl() { 344 WebContentsImpl::~WebContentsImpl() {
344 is_being_destroyed_ = true; 345 is_being_destroyed_ = true;
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 943 }
943 944
944 int WebContentsImpl::GetCapturerCount() const { 945 int WebContentsImpl::GetCapturerCount() const {
945 return capturer_count_; 946 return capturer_count_;
946 } 947 }
947 948
948 bool WebContentsImpl::IsAudioMuted() const { 949 bool WebContentsImpl::IsAudioMuted() const {
949 return audio_muter_.get() && audio_muter_->is_muting(); 950 return audio_muter_.get() && audio_muter_->is_muting();
950 } 951 }
951 952
952 void WebContentsImpl::SetAudioMuted(bool mute) { 953 void WebContentsImpl::SetAudioMuted(bool muted, const std::string& cause) {
953 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() 954 DVLOG(1) << "SetAudioMuted(muted=" << muted << ", cause =" << cause << "), was " << IsAudioMuted()
954 << " for WebContentsImpl@" << this; 955 << " for WebContentsImpl@" << this;
955 956
956 if (mute == IsAudioMuted()) 957 if (muted == IsAudioMuted())
957 return; 958 return;
958 959
959 if (mute) { 960 NotifyMutedStateChanged(muted, cause);
961
962 if (muted) {
960 if (!audio_muter_) 963 if (!audio_muter_)
961 audio_muter_.reset(new WebContentsAudioMuter(this)); 964 audio_muter_.reset(new WebContentsAudioMuter(this));
962 audio_muter_->StartMuting(); 965 audio_muter_->StartMuting();
963 } else { 966 } else {
964 DCHECK(audio_muter_); 967 DCHECK(audio_muter_);
965 audio_muter_->StopMuting(); 968 audio_muter_->StopMuting();
966 } 969 }
967 970
968 // Notification for UI updates in response to the changed muting state. 971 // Notification for UI updates in response to the changed muting state.
969 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); 972 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
(...skipping 18 matching lines...) Expand all
988 base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { 991 base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
989 return crashed_status_; 992 return crashed_status_;
990 } 993 }
991 994
992 bool WebContentsImpl::IsBeingDestroyed() const { 995 bool WebContentsImpl::IsBeingDestroyed() const {
993 return is_being_destroyed_; 996 return is_being_destroyed_;
994 } 997 }
995 998
996 void WebContentsImpl::NotifyNavigationStateChanged( 999 void WebContentsImpl::NotifyNavigationStateChanged(
997 InvalidateTypes changed_flags) { 1000 InvalidateTypes changed_flags) {
998 // Create and release the audio power save blocker depending on whether the
999 // tab is actively producing audio or not.
1000 if (changed_flags == INVALIDATE_TYPE_TAB &&
1001 AudioStreamMonitor::monitoring_available()) {
1002 if (WasRecentlyAudible()) {
1003 if (!audio_power_save_blocker_)
1004 CreateAudioPowerSaveBlocker();
1005 } else {
1006 audio_power_save_blocker_.reset();
1007 }
1008 }
1009
1010 if (delegate_) 1001 if (delegate_)
1011 delegate_->NavigationStateChanged(this, changed_flags); 1002 delegate_->NavigationStateChanged(this, changed_flags);
1012 } 1003 }
1013 1004
1005 void WebContentsImpl::NotifyAudibleStateChanged(bool is_audible) {
1006 DCHECK(AudioStreamMonitor::monitoring_available());
1007
1008 // Create and release the audio power save blocker depending on whether the
1009 // tab is actively producing audio or not.
1010 if (WasRecentlyAudible()) {
1011 if (!audio_power_save_blocker_)
1012 CreateAudioPowerSaveBlocker();
1013 } else {
1014 audio_power_save_blocker_.reset();
1015 }
1016
1017 // TODO: The following should be eliminated once the browser UI uses the new W ebContentsObserver interface.
miu 2014/12/05 23:46:48 Actually, I think I gave you bad advice (earlier)
1018 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1019
1020 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabAudible(is_audible));
1021 }
1022
1023 void WebContentsImpl::NotifyMutedStateChanged(bool is_muted, const std::string& cause) {
1024 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabMuted(is_muted, cause));
1025 }
1026
1014 base::TimeTicks WebContentsImpl::GetLastActiveTime() const { 1027 base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1015 return last_active_time_; 1028 return last_active_time_;
1016 } 1029 }
1017 1030
1018 void WebContentsImpl::WasShown() { 1031 void WebContentsImpl::WasShown() {
1019 controller_.SetActive(true); 1032 controller_.SetActive(true);
1020 1033
1021 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree(); 1034 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1022 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin(); 1035 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
1023 iter != widgets.end(); 1036 iter != widgets.end();
(...skipping 3324 matching lines...) Expand 10 before | Expand all | Expand 10 after
4348 node->render_manager()->ResumeResponseDeferredAtStart(); 4361 node->render_manager()->ResumeResponseDeferredAtStart();
4349 } 4362 }
4350 4363
4351 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4364 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4352 force_disable_overscroll_content_ = force_disable; 4365 force_disable_overscroll_content_ = force_disable;
4353 if (view_) 4366 if (view_)
4354 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4367 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4355 } 4368 }
4356 4369
4357 } // namespace content 4370 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698