Index: content/browser/android/audio_monitor_android.cc |
diff --git a/content/browser/android/audio_monitor_android.cc b/content/browser/android/audio_monitor_android.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5e71876188be9787a51e4d51e23c3e2b8291e44b |
--- /dev/null |
+++ b/content/browser/android/audio_monitor_android.cc |
@@ -0,0 +1,53 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/android/audio_monitor_android.h" |
+ |
+#include <climits> |
+#include "content/public/browser/web_contents.h" |
+ |
+namespace content { |
+ |
+AudioMonitorAndroid::AudioMonitorAndroid(WebContents* web_contents) |
+ : web_contents_(web_contents), |
+ is_audible_(false) { |
+} |
+ |
+AudioMonitorAndroid::~AudioMonitorAndroid() {} |
+ |
+void AudioMonitorAndroid::OnAudibleStateChanged(RenderFrameHost* rfh, |
+ int player_id, |
+ bool is_audible) { |
+ audio_status_map_[Key(rfh, player_id)] = is_audible; |
+ UpdateStatusAndNotify(); |
+} |
+ |
+void AudioMonitorAndroid::RemovePlayer(RenderFrameHost* rfh, int player_id) { |
+ audio_status_map_.erase(Key(rfh, player_id)); |
+ UpdateStatusAndNotify(); |
+} |
+ |
+void AudioMonitorAndroid::RenderFrameDeleted(RenderFrameHost* rfh) { |
+ StatusMap::iterator begin = audio_status_map_.lower_bound(Key(rfh, 0)); |
+ StatusMap::iterator end = audio_status_map_.upper_bound(Key(rfh, INT_MAX)); |
+ audio_status_map_.erase(begin, end); |
+ UpdateStatusAndNotify(); |
+} |
+ |
+void AudioMonitorAndroid::UpdateStatusAndNotify() { |
+ bool is_audible = false; |
+ for (const auto& player_status : audio_status_map_) { |
+ if (player_status.second) { |
+ is_audible = true; |
+ break; // at least one player is making noise |
+ } |
+ } |
+ |
+ if (is_audible_ != is_audible) { |
+ is_audible_ = is_audible; |
+ web_contents_->NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
Ted C
2015/02/07 00:07:15
Is this the navigation state that chrome uses to u
Tima Vaisburd
2015/02/07 03:00:23
Yes, on desktop the AudioStreamMonitor makes the s
|
+ } |
+} |
+ |
+} // namespace content |