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/command_line.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
10 #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" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/animation/multi_animation.h" | 18 #include "ui/gfx/animation/multi_animation.h" |
19 | 19 |
20 struct LastMuteMetadata : public | |
21 content::WebContentsUserData<LastMuteMetadata> { | |
miu
2015/01/22 00:55:23
style: Please run `git cl format` to make indentat
| |
22 std::string cause; // Extension ID or constant from header file | |
23 // or empty string | |
24 private: | |
25 explicit LastMuteMetadata(content::WebContents* contents) {} | |
26 friend class content::WebContentsUserData<LastMuteMetadata>; | |
27 }; | |
28 | |
29 DEFINE_WEB_CONTENTS_USER_DATA_KEY(LastMuteMetadata); | |
30 | |
20 namespace chrome { | 31 namespace chrome { |
21 | 32 |
22 namespace { | 33 namespace { |
23 | 34 |
24 // Interval between frame updates of the tab indicator animations. This is not | 35 // Interval between frame updates of the tab indicator animations. This is not |
25 // the usual 60 FPS because a trade-off must be made between tab UI animation | 36 // the usual 60 FPS because a trade-off must be made between tab UI animation |
26 // smoothness and media recording/playback performance on low-end hardware. | 37 // smoothness and media recording/playback performance on low-end hardware. |
27 const int kIndicatorFrameIntervalMs = 50; // 20 FPS | 38 const int kIndicatorFrameIntervalMs = 50; // 20 FPS |
28 | 39 |
29 // Fade-in/out duration for the tab indicator animations. Fade-in is quick to | 40 // Fade-in/out duration for the tab indicator animations. Fade-in is quick to |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 case TAB_MEDIA_STATE_AUDIO_MUTING: | 256 case TAB_MEDIA_STATE_AUDIO_MUTING: |
246 return IsTabAudioMutingFeatureEnabled(); | 257 return IsTabAudioMutingFeatureEnabled(); |
247 case TAB_MEDIA_STATE_RECORDING: | 258 case TAB_MEDIA_STATE_RECORDING: |
248 case TAB_MEDIA_STATE_CAPTURING: | 259 case TAB_MEDIA_STATE_CAPTURING: |
249 return false; | 260 return false; |
250 } | 261 } |
251 NOTREACHED(); | 262 NOTREACHED(); |
252 return false; | 263 return false; |
253 } | 264 } |
254 | 265 |
255 void SetTabAudioMuted(content::WebContents* contents, bool mute) { | 266 std::string& GetTabAudioMutedCause(content::WebContents* contents) { |
267 LastMuteMetadata::CreateForWebContents(contents); // Create if not exists. | |
268 if (GetTabMediaStateForContents(contents) == TAB_MEDIA_STATE_CAPTURING) { | |
269 // For tab capture, libcontent forces muting off. | |
270 LastMuteMetadata::FromWebContents(contents)->cause = | |
271 kMutedToggleCauseCapture; | |
272 } | |
273 return LastMuteMetadata::FromWebContents(contents)->cause; | |
274 } | |
275 | |
276 void SetTabAudioMuted(content::WebContents* contents, | |
277 bool muted, | |
278 const std::string& cause) { | |
256 if (!contents || !chrome::CanToggleAudioMute(contents)) | 279 if (!contents || !chrome::CanToggleAudioMute(contents)) |
257 return; | 280 return; |
258 contents->SetAudioMuted(mute); | 281 |
282 LastMuteMetadata::CreateForWebContents(contents); // Create if not exists. | |
283 LastMuteMetadata::FromWebContents(contents)->cause = cause; | |
284 | |
285 contents->SetAudioMuted(muted); | |
259 } | 286 } |
260 | 287 |
261 bool IsTabAudioMuted(content::WebContents* contents) { | 288 bool IsTabAudioMuted(content::WebContents* contents) { |
262 return contents && contents->IsAudioMuted(); | 289 return contents && contents->IsAudioMuted(); |
263 } | 290 } |
264 | 291 |
265 bool AreAllTabsMuted(const TabStripModel& tab_strip, | 292 bool AreAllTabsMuted(const TabStripModel& tab_strip, |
266 const std::vector<int>& indices) { | 293 const std::vector<int>& indices) { |
267 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end(); | 294 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end(); |
268 ++i) { | 295 ++i) { |
269 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i))) | 296 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i))) |
270 return false; | 297 return false; |
271 } | 298 } |
272 return true; | 299 return true; |
273 } | 300 } |
274 | 301 |
275 } // namespace chrome | 302 } // namespace chrome |
OLD | NEW |