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 "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/common/chrome_switches.h" | |
10 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
11 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
12 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/animation/multi_animation.h" | 17 #include "ui/gfx/animation/multi_animation.h" |
16 | 18 |
17 namespace chrome { | 19 namespace chrome { |
18 | 20 |
19 namespace { | 21 namespace { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 scoped_refptr<MediaStreamCaptureIndicator> indicator = | 129 scoped_refptr<MediaStreamCaptureIndicator> indicator = |
128 MediaCaptureDevicesDispatcher::GetInstance()-> | 130 MediaCaptureDevicesDispatcher::GetInstance()-> |
129 GetMediaStreamCaptureIndicator(); | 131 GetMediaStreamCaptureIndicator(); |
130 if (indicator.get()) { | 132 if (indicator.get()) { |
131 if (indicator->IsBeingMirrored(contents)) | 133 if (indicator->IsBeingMirrored(contents)) |
132 return TAB_MEDIA_STATE_CAPTURING; | 134 return TAB_MEDIA_STATE_CAPTURING; |
133 if (indicator->IsCapturingUserMedia(contents)) | 135 if (indicator->IsCapturingUserMedia(contents)) |
134 return TAB_MEDIA_STATE_RECORDING; | 136 return TAB_MEDIA_STATE_RECORDING; |
135 } | 137 } |
136 | 138 |
139 if (IsTabAudioMutingFeatureEnabled() && contents->IsAudioMuted()) | |
140 return TAB_MEDIA_STATE_AUDIO_MUTING; | |
137 if (IsPlayingAudio(contents)) | 141 if (IsPlayingAudio(contents)) |
138 return TAB_MEDIA_STATE_AUDIO_PLAYING; | 142 return TAB_MEDIA_STATE_AUDIO_PLAYING; |
139 | 143 |
140 return TAB_MEDIA_STATE_NONE; | 144 return TAB_MEDIA_STATE_NONE; |
141 } | 145 } |
142 | 146 |
143 const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state) { | 147 const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state) { |
144 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 148 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
145 switch (media_state) { | 149 switch (media_state) { |
146 case TAB_MEDIA_STATE_AUDIO_PLAYING: | 150 case TAB_MEDIA_STATE_AUDIO_PLAYING: |
147 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_INDICATOR); | 151 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_INDICATOR); |
152 case TAB_MEDIA_STATE_AUDIO_MUTING: | |
153 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_MUTING_INDICATOR); | |
148 case TAB_MEDIA_STATE_RECORDING: | 154 case TAB_MEDIA_STATE_RECORDING: |
149 return rb.GetNativeImageNamed(IDR_TAB_RECORDING_INDICATOR); | 155 return rb.GetNativeImageNamed(IDR_TAB_RECORDING_INDICATOR); |
150 case TAB_MEDIA_STATE_CAPTURING: | 156 case TAB_MEDIA_STATE_CAPTURING: |
151 return rb.GetNativeImageNamed(IDR_TAB_CAPTURE_INDICATOR); | 157 return rb.GetNativeImageNamed(IDR_TAB_CAPTURE_INDICATOR); |
152 case TAB_MEDIA_STATE_NONE: | 158 case TAB_MEDIA_STATE_NONE: |
153 break; | 159 break; |
154 } | 160 } |
155 NOTREACHED(); | 161 NOTREACHED(); |
156 return rb.GetNativeImageNamed(IDR_SAD_FAVICON); | 162 return rb.GetNativeImageNamed(IDR_SAD_FAVICON); |
157 } | 163 } |
158 | 164 |
165 const gfx::Image& GetTabMediaIndicatorAffordanceImage( | |
166 TabMediaState media_state) { | |
167 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
168 switch (media_state) { | |
169 case TAB_MEDIA_STATE_AUDIO_PLAYING: | |
170 case TAB_MEDIA_STATE_AUDIO_MUTING: | |
171 return rb.GetNativeImageNamed(IDR_TAB_AUDIO_MUTING_AFFORDANCE); | |
172 default: | |
sky
2014/09/23 22:58:17
Can you explicitly list the states so that you get
miu
2014/09/24 22:34:15
Done.
| |
173 return GetTabMediaIndicatorImage(media_state); | |
174 } | |
175 } | |
176 | |
159 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation( | 177 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation( |
160 TabMediaState media_state) { | 178 TabMediaState media_state) { |
161 if (media_state == TAB_MEDIA_STATE_RECORDING || | 179 if (media_state == TAB_MEDIA_STATE_RECORDING || |
162 media_state == TAB_MEDIA_STATE_CAPTURING) { | 180 media_state == TAB_MEDIA_STATE_CAPTURING) { |
163 return TabRecordingIndicatorAnimation::Create().PassAs<gfx::Animation>(); | 181 return TabRecordingIndicatorAnimation::Create().PassAs<gfx::Animation>(); |
164 } | 182 } |
165 | 183 |
166 // Note: While it seems silly to use a one-part MultiAnimation, it's the only | 184 // 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. | 185 // gfx::Animation implementation that lets us control the frame interval. |
168 gfx::MultiAnimation::Parts parts; | 186 gfx::MultiAnimation::Parts parts; |
(...skipping 15 matching lines...) Expand all Loading... | |
184 return title; | 202 return title; |
185 | 203 |
186 base::string16 result = title; | 204 base::string16 result = title; |
187 if (!result.empty()) | 205 if (!result.empty()) |
188 result.append(1, '\n'); | 206 result.append(1, '\n'); |
189 switch (media_state) { | 207 switch (media_state) { |
190 case TAB_MEDIA_STATE_AUDIO_PLAYING: | 208 case TAB_MEDIA_STATE_AUDIO_PLAYING: |
191 result.append( | 209 result.append( |
192 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_PLAYING)); | 210 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_PLAYING)); |
193 break; | 211 break; |
212 case TAB_MEDIA_STATE_AUDIO_MUTING: | |
213 result.append( | |
214 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_AUDIO_MUTING)); | |
215 break; | |
194 case TAB_MEDIA_STATE_RECORDING: | 216 case TAB_MEDIA_STATE_RECORDING: |
195 result.append( | 217 result.append( |
196 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_RECORDING)); | 218 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_RECORDING)); |
197 break; | 219 break; |
198 case TAB_MEDIA_STATE_CAPTURING: | 220 case TAB_MEDIA_STATE_CAPTURING: |
199 result.append( | 221 result.append( |
200 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_CAPTURING)); | 222 l10n_util::GetStringUTF16(IDS_TOOLTIP_TAB_MEDIA_STATE_CAPTURING)); |
201 break; | 223 break; |
202 case TAB_MEDIA_STATE_NONE: | 224 case TAB_MEDIA_STATE_NONE: |
203 NOTREACHED(); | 225 NOTREACHED(); |
204 break; | 226 break; |
205 } | 227 } |
206 return result; | 228 return result; |
207 } | 229 } |
208 | 230 |
231 bool IsTabAudioMutingFeatureEnabled() { | |
232 #if defined(USE_AURA) | |
233 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
234 switches::kEnableTabAudioMuting); | |
235 #else | |
236 return false; | |
237 #endif | |
238 } | |
239 | |
240 bool CanToggleAudioMute(content::WebContents* contents) { | |
241 switch (GetTabMediaStateForContents(contents)) { | |
242 case TAB_MEDIA_STATE_NONE: | |
243 case TAB_MEDIA_STATE_AUDIO_PLAYING: | |
244 case TAB_MEDIA_STATE_AUDIO_MUTING: | |
245 return IsTabAudioMutingFeatureEnabled(); | |
246 case TAB_MEDIA_STATE_RECORDING: | |
247 case TAB_MEDIA_STATE_CAPTURING: | |
248 return false; | |
249 } | |
250 NOTREACHED(); | |
251 return false; | |
252 } | |
253 | |
209 } // namespace chrome | 254 } // namespace chrome |
OLD | NEW |