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 |
| 21 : public content::WebContentsUserData<LastMuteMetadata> { |
| 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 |
| 33 const char kMutedToggleCauseUser[] = "user"; |
| 34 const char kMutedToggleCauseCapture[] = "auto-forced for capture"; |
| 35 |
22 namespace { | 36 namespace { |
23 | 37 |
24 // Interval between frame updates of the tab indicator animations. This is not | 38 // 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 | 39 // 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. | 40 // smoothness and media recording/playback performance on low-end hardware. |
27 const int kIndicatorFrameIntervalMs = 50; // 20 FPS | 41 const int kIndicatorFrameIntervalMs = 50; // 20 FPS |
28 | 42 |
29 // Fade-in/out duration for the tab indicator animations. Fade-in is quick to | 43 // Fade-in/out duration for the tab indicator animations. Fade-in is quick to |
30 // immediately notify the user. Fade-out is more gradual, so that the user has | 44 // immediately notify the user. Fade-out is more gradual, so that the user has |
31 // a chance of finding a tab that has quickly "blipped" on and off. | 45 // a chance of finding a tab that has quickly "blipped" on and off. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 case TAB_MEDIA_STATE_AUDIO_MUTING: | 259 case TAB_MEDIA_STATE_AUDIO_MUTING: |
246 return IsTabAudioMutingFeatureEnabled(); | 260 return IsTabAudioMutingFeatureEnabled(); |
247 case TAB_MEDIA_STATE_RECORDING: | 261 case TAB_MEDIA_STATE_RECORDING: |
248 case TAB_MEDIA_STATE_CAPTURING: | 262 case TAB_MEDIA_STATE_CAPTURING: |
249 return false; | 263 return false; |
250 } | 264 } |
251 NOTREACHED(); | 265 NOTREACHED(); |
252 return false; | 266 return false; |
253 } | 267 } |
254 | 268 |
255 void SetTabAudioMuted(content::WebContents* contents, bool mute) { | 269 const std::string& GetTabAudioMutedCause(content::WebContents* contents) { |
| 270 LastMuteMetadata::CreateForWebContents(contents); // Create if not exists. |
| 271 if (GetTabMediaStateForContents(contents) == TAB_MEDIA_STATE_CAPTURING) { |
| 272 // For tab capture, libcontent forces muting off. |
| 273 LastMuteMetadata::FromWebContents(contents)->cause = |
| 274 kMutedToggleCauseCapture; |
| 275 } |
| 276 return LastMuteMetadata::FromWebContents(contents)->cause; |
| 277 } |
| 278 |
| 279 void SetTabAudioMuted(content::WebContents* contents, |
| 280 bool mute, |
| 281 const std::string& cause) { |
256 if (!contents || !chrome::CanToggleAudioMute(contents)) | 282 if (!contents || !chrome::CanToggleAudioMute(contents)) |
257 return; | 283 return; |
| 284 |
| 285 LastMuteMetadata::CreateForWebContents(contents); // Create if not exists. |
| 286 LastMuteMetadata::FromWebContents(contents)->cause = cause; |
| 287 |
258 contents->SetAudioMuted(mute); | 288 contents->SetAudioMuted(mute); |
259 } | 289 } |
260 | 290 |
261 bool IsTabAudioMuted(content::WebContents* contents) { | 291 bool IsTabAudioMuted(content::WebContents* contents) { |
262 return contents && contents->IsAudioMuted(); | 292 return contents && contents->IsAudioMuted(); |
263 } | 293 } |
264 | 294 |
265 bool AreAllTabsMuted(const TabStripModel& tab_strip, | 295 bool AreAllTabsMuted(const TabStripModel& tab_strip, |
266 const std::vector<int>& indices) { | 296 const std::vector<int>& indices) { |
267 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end(); | 297 for (std::vector<int>::const_iterator i = indices.begin(); i != indices.end(); |
268 ++i) { | 298 ++i) { |
269 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i))) | 299 if (!IsTabAudioMuted(tab_strip.GetWebContentsAt(*i))) |
270 return false; | 300 return false; |
271 } | 301 } |
272 return true; | 302 return true; |
273 } | 303 } |
274 | 304 |
275 } // namespace chrome | 305 } // namespace chrome |
OLD | NEW |