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

Unified Diff: chrome/browser/ui/tabs/tab_utils.cc

Issue 591963002: Tab audio mute control (views UI), behind a switch (off by default). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + add about:flags experiment Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/tabs/tab_utils.h ('k') | chrome/browser/ui/views/tabs/browser_tab_strip_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/tabs/tab_utils.cc
diff --git a/chrome/browser/ui/tabs/tab_utils.cc b/chrome/browser/ui/tabs/tab_utils.cc
index 84956d19d9407363313a12bc4873cce71d3d2557..25fcaf33831bc163e30775c14751827e7aa962ad 100644
--- a/chrome/browser/ui/tabs/tab_utils.cc
+++ b/chrome/browser/ui/tabs/tab_utils.cc
@@ -4,9 +4,12 @@
#include "chrome/browser/ui/tabs/tab_utils.h"
+#include "base/command_line.h"
#include "base/strings/string16.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/media_stream_capture_indicator.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_contents.h"
#include "grit/theme_resources.h"
@@ -134,6 +137,8 @@ TabMediaState GetTabMediaStateForContents(content::WebContents* contents) {
return TAB_MEDIA_STATE_RECORDING;
}
+ if (IsTabAudioMutingFeatureEnabled() && contents->IsAudioMuted())
+ return TAB_MEDIA_STATE_AUDIO_MUTING;
if (IsPlayingAudio(contents))
return TAB_MEDIA_STATE_AUDIO_PLAYING;
@@ -145,6 +150,8 @@ const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state) {
switch (media_state) {
case TAB_MEDIA_STATE_AUDIO_PLAYING:
return rb.GetNativeImageNamed(IDR_TAB_AUDIO_INDICATOR);
+ case TAB_MEDIA_STATE_AUDIO_MUTING:
+ return rb.GetNativeImageNamed(IDR_TAB_AUDIO_MUTING_INDICATOR);
case TAB_MEDIA_STATE_RECORDING:
return rb.GetNativeImageNamed(IDR_TAB_RECORDING_INDICATOR);
case TAB_MEDIA_STATE_CAPTURING:
@@ -156,6 +163,22 @@ const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state) {
return rb.GetNativeImageNamed(IDR_SAD_FAVICON);
}
+const gfx::Image& GetTabMediaIndicatorAffordanceImage(
+ TabMediaState media_state) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ switch (media_state) {
+ case TAB_MEDIA_STATE_AUDIO_PLAYING:
+ case TAB_MEDIA_STATE_AUDIO_MUTING:
+ return rb.GetNativeImageNamed(IDR_TAB_AUDIO_MUTING_AFFORDANCE);
+ case TAB_MEDIA_STATE_NONE:
+ case TAB_MEDIA_STATE_RECORDING:
+ case TAB_MEDIA_STATE_CAPTURING:
+ return GetTabMediaIndicatorImage(media_state);
+ }
+ NOTREACHED();
+ return GetTabMediaIndicatorImage(media_state);
+}
+
scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation(
TabMediaState media_state) {
if (media_state == TAB_MEDIA_STATE_RECORDING ||
@@ -191,6 +214,10 @@ base::string16 AssembleTabTooltipText(const base::string16& title,
result.append(
l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_PLAYING));
break;
+ case TAB_MEDIA_STATE_AUDIO_MUTING:
+ result.append(
+ l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_MUTING));
+ break;
case TAB_MEDIA_STATE_RECORDING:
result.append(
l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_RECORDING));
@@ -206,4 +233,47 @@ base::string16 AssembleTabTooltipText(const base::string16& title,
return result;
}
+bool IsTabAudioMutingFeatureEnabled() {
+#if defined(USE_AURA)
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableTabAudioMuting);
+#else
+ return false;
+#endif
+}
+
+bool CanToggleAudioMute(content::WebContents* contents) {
+ switch (GetTabMediaStateForContents(contents)) {
+ case TAB_MEDIA_STATE_NONE:
+ case TAB_MEDIA_STATE_AUDIO_PLAYING:
+ case TAB_MEDIA_STATE_AUDIO_MUTING:
+ return IsTabAudioMutingFeatureEnabled();
+ case TAB_MEDIA_STATE_RECORDING:
+ case TAB_MEDIA_STATE_CAPTURING:
+ return false;
+ }
+ NOTREACHED();
+ return false;
+}
+
+void SetTabAudioMuted(content::WebContents* contents, bool mute) {
+ if (!contents || !chrome::CanToggleAudioMute(contents))
+ return;
+ contents->SetAudioMuted(mute);
+}
+
+bool IsTabAudioMuted(content::WebContents* contents) {
+ return contents && contents->IsAudioMuted();
+}
+
+bool AreAllTabsMuted(const TabStripModel& tab_strip,
+ const std::vector<int>& indices) {
+ for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end();
+ ++i) {
+ if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i)))
+ return false;
+ }
+ return true;
+}
+
} // namespace chrome
« no previous file with comments | « chrome/browser/ui/tabs/tab_utils.h ('k') | chrome/browser/ui/views/tabs/browser_tab_strip_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698