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

Side by Side 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, 2 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 "chrome/browser/ui/tabs/tab_utils.h" 5 #include "chrome/browser/ui/tabs/tab_utils.h"
6 6
7 #include "base/command_line.h"
7 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
8 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
9 #include "chrome/browser/media/media_stream_capture_indicator.h" 10 #include "chrome/browser/media/media_stream_capture_indicator.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_switches.h"
10 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
11 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
12 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
13 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/animation/multi_animation.h" 18 #include "ui/gfx/animation/multi_animation.h"
16 19
17 namespace chrome { 20 namespace chrome {
18 21
19 namespace { 22 namespace {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 scoped_refptr<MediaStreamCaptureIndicator> indicator = 130 scoped_refptr<MediaStreamCaptureIndicator> indicator =
128 MediaCaptureDevicesDispatcher::GetInstance()-> 131 MediaCaptureDevicesDispatcher::GetInstance()->
129 GetMediaStreamCaptureIndicator(); 132 GetMediaStreamCaptureIndicator();
130 if (indicator.get()) { 133 if (indicator.get()) {
131 if (indicator->IsBeingMirrored(contents)) 134 if (indicator->IsBeingMirrored(contents))
132 return TAB_MEDIA_STATE_CAPTURING; 135 return TAB_MEDIA_STATE_CAPTURING;
133 if (indicator->IsCapturingUserMedia(contents)) 136 if (indicator->IsCapturingUserMedia(contents))
134 return TAB_MEDIA_STATE_RECORDING; 137 return TAB_MEDIA_STATE_RECORDING;
135 } 138 }
136 139
140 if (IsTabAudioMutingFeatureEnabled() && contents->IsAudioMuted())
141 return TAB_MEDIA_STATE_AUDIO_MUTING;
137 if (IsPlayingAudio(contents)) 142 if (IsPlayingAudio(contents))
138 return TAB_MEDIA_STATE_AUDIO_PLAYING; 143 return TAB_MEDIA_STATE_AUDIO_PLAYING;
139 144
140 return TAB_MEDIA_STATE_NONE; 145 return TAB_MEDIA_STATE_NONE;
141 } 146 }
142 147
143 const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state) { 148 const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state) {
144 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 149 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
145 switch (media_state) { 150 switch (media_state) {
146 case TAB_MEDIA_STATE_AUDIO_PLAYING: 151 case TAB_MEDIA_STATE_AUDIO_PLAYING:
147 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_INDICATOR); 152 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_INDICATOR);
153 case TAB_MEDIA_STATE_AUDIO_MUTING:
154 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_MUTING_INDICATOR);
148 case TAB_MEDIA_STATE_RECORDING: 155 case TAB_MEDIA_STATE_RECORDING:
149 return rb.GetNativeImageNamed(IDR_TAB_RECORDING_INDICATOR); 156 return rb.GetNativeImageNamed(IDR_TAB_RECORDING_INDICATOR);
150 case TAB_MEDIA_STATE_CAPTURING: 157 case TAB_MEDIA_STATE_CAPTURING:
151 return rb.GetNativeImageNamed(IDR_TAB_CAPTURE_INDICATOR); 158 return rb.GetNativeImageNamed(IDR_TAB_CAPTURE_INDICATOR);
152 case TAB_MEDIA_STATE_NONE: 159 case TAB_MEDIA_STATE_NONE:
153 break; 160 break;
154 } 161 }
155 NOTREACHED(); 162 NOTREACHED();
156 return rb.GetNativeImageNamed(IDR_SAD_FAVICON); 163 return rb.GetNativeImageNamed(IDR_SAD_FAVICON);
157 } 164 }
158 165
166 const gfx::Image& GetTabMediaIndicatorAffordanceImage(
167 TabMediaState media_state) {
168 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
169 switch (media_state) {
170 case TAB_MEDIA_STATE_AUDIO_PLAYING:
171 case TAB_MEDIA_STATE_AUDIO_MUTING:
172 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_MUTING_AFFORDANCE);
173 case TAB_MEDIA_STATE_NONE:
174 case TAB_MEDIA_STATE_RECORDING:
175 case TAB_MEDIA_STATE_CAPTURING:
176 return GetTabMediaIndicatorImage(media_state);
177 }
178 NOTREACHED();
179 return GetTabMediaIndicatorImage(media_state);
180 }
181
159 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation( 182 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation(
160 TabMediaState media_state) { 183 TabMediaState media_state) {
161 if (media_state == TAB_MEDIA_STATE_RECORDING || 184 if (media_state == TAB_MEDIA_STATE_RECORDING ||
162 media_state == TAB_MEDIA_STATE_CAPTURING) { 185 media_state == TAB_MEDIA_STATE_CAPTURING) {
163 return TabRecordingIndicatorAnimation::Create().PassAs<gfx::Animation>(); 186 return TabRecordingIndicatorAnimation::Create().PassAs<gfx::Animation>();
164 } 187 }
165 188
166 // Note: While it seems silly to use a one-part MultiAnimation, it's the only 189 // Note: While it seems silly to use a one-part MultiAnimation, it's the only
167 // gfx::Animation implementation that lets us control the frame interval. 190 // gfx::Animation implementation that lets us control the frame interval.
168 gfx::MultiAnimation::Parts parts; 191 gfx::MultiAnimation::Parts parts;
(...skipping 15 matching lines...) Expand all
184 return title; 207 return title;
185 208
186 base::string16 result = title; 209 base::string16 result = title;
187 if (!result.empty()) 210 if (!result.empty())
188 result.append(1, '\n'); 211 result.append(1, '\n');
189 switch (media_state) { 212 switch (media_state) {
190 case TAB_MEDIA_STATE_AUDIO_PLAYING: 213 case TAB_MEDIA_STATE_AUDIO_PLAYING:
191 result.append( 214 result.append(
192 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_PLAYING)); 215 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_PLAYING));
193 break; 216 break;
217 case TAB_MEDIA_STATE_AUDIO_MUTING:
218 result.append(
219 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_MUTING));
220 break;
194 case TAB_MEDIA_STATE_RECORDING: 221 case TAB_MEDIA_STATE_RECORDING:
195 result.append( 222 result.append(
196 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_RECORDING)); 223 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_RECORDING));
197 break; 224 break;
198 case TAB_MEDIA_STATE_CAPTURING: 225 case TAB_MEDIA_STATE_CAPTURING:
199 result.append( 226 result.append(
200 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_CAPTURING)); 227 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_CAPTURING));
201 break; 228 break;
202 case TAB_MEDIA_STATE_NONE: 229 case TAB_MEDIA_STATE_NONE:
203 NOTREACHED(); 230 NOTREACHED();
204 break; 231 break;
205 } 232 }
206 return result; 233 return result;
207 } 234 }
208 235
236 bool IsTabAudioMutingFeatureEnabled() {
237 #if defined(USE_AURA)
238 return base::CommandLine::ForCurrentProcess()->HasSwitch(
239 switches::kEnableTabAudioMuting);
240 #else
241 return false;
242 #endif
243 }
244
245 bool CanToggleAudioMute(content::WebContents* contents) {
246 switch (GetTabMediaStateForContents(contents)) {
247 case TAB_MEDIA_STATE_NONE:
248 case TAB_MEDIA_STATE_AUDIO_PLAYING:
249 case TAB_MEDIA_STATE_AUDIO_MUTING:
250 return IsTabAudioMutingFeatureEnabled();
251 case TAB_MEDIA_STATE_RECORDING:
252 case TAB_MEDIA_STATE_CAPTURING:
253 return false;
254 }
255 NOTREACHED();
256 return false;
257 }
258
259 void SetTabAudioMuted(content::WebContents* contents, bool mute) {
260 if (!contents || !chrome::CanToggleAudioMute(contents))
261 return;
262 contents->SetAudioMuted(mute);
263 }
264
265 bool IsTabAudioMuted(content::WebContents* contents) {
266 return contents && contents->IsAudioMuted();
267 }
268
269 bool AreAllTabsMuted(const TabStripModel& tab_strip,
270 const std::vector<int>& indices) {
271 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end();
272 ++i) {
273 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i)))
274 return false;
275 }
276 return true;
277 }
278
209 } // namespace chrome 279 } // namespace chrome
OLDNEW
« 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