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

Unified Diff: chrome/browser/ui/tabs/tab_strip_model.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: Addressed mpearson's comments; added a few CloseTab UMA's. 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
Index: chrome/browser/ui/tabs/tab_strip_model.cc
diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc
index b7c60fbf90b974ee96176bae87dab73caad7e934..5d8e60dced924cd6c0857676644f8006d18c93b0 100644
--- a/chrome/browser/ui/tabs/tab_strip_model.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
+#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "chrome/common/url_constants.h"
#include "components/web_modal/popup_manager.h"
@@ -701,6 +702,18 @@ bool TabStripModel::IsTabPinned(int index) const {
return contents_data_[index]->pinned();
}
+void TabStripModel::SetTabAudioMuted(int index, bool mute) {
sky 2014/09/23 22:58:17 Move this and IsTabAudioMuted into tab_util. My ra
miu 2014/09/24 22:34:15 Done. Agreed; I wasn't encapsulating this functio
sky 2014/09/25 19:25:04 Can you also move the setters? Long term TabStripM
miu 2014/09/25 22:49:36 Done.
+ content::WebContents* const contents = GetWebContentsAt(index);
+ if (!contents || !chrome::CanToggleAudioMute(contents))
+ return;
+ contents->SetAudioMuted(mute);
+}
+
+bool TabStripModel::IsTabAudioMuted(int index) const {
+ content::WebContents* const contents = GetWebContentsAt(index);
+ return contents && contents->IsAudioMuted();
+}
+
bool TabStripModel::IsMiniTab(int index) const {
return IsTabPinned(index) || IsAppTab(index);
}
@@ -919,6 +932,18 @@ bool TabStripModel::IsContextMenuCommandEnabled(
return false;
}
+ case CommandToggleTabAudioMuted: {
+ if (!chrome::IsTabAudioMutingFeatureEnabled())
sky 2014/09/23 22:58:17 Does this check matter here?
miu 2014/09/24 22:34:15 Done since the CanToggleAudioMute() should return
+ return false;
+ std::vector<int> indices = GetIndicesForCommand(context_index);
+ for (size_t i = 0; i < indices.size(); ++i) {
+ WebContents* const tab = GetWebContentsAt(indices[i]);
+ if (!tab || !chrome::CanToggleAudioMute(tab))
sky 2014/09/23 22:58:17 You shouldn't need the !tab here, at which point y
miu 2014/09/24 22:34:15 Done.
+ return false;
+ }
+ return true;
+ }
+
case CommandBookmarkAllTabs:
return browser_defaults::bookmarks_enabled &&
delegate_->CanBookmarkAllTabs();
@@ -1026,6 +1051,18 @@ void TabStripModel::ExecuteContextMenuCommand(
break;
}
+ case CommandToggleTabAudioMuted: {
+ const bool mute = WillContextMenuMute(context_index);
+ if (mute)
+ content::RecordAction(UserMetricsAction("TabContextMenu_MuteTabs"));
+ else
+ content::RecordAction(UserMetricsAction("TabContextMenu_UnmuteTabs"));
+ std::vector<int> indices = GetIndicesForCommand(context_index);
+ for (size_t i = 0; i < indices.size(); ++i)
+ SetTabAudioMuted(indices[i], mute);
+ break;
+ }
+
case CommandBookmarkAllTabs: {
content::RecordAction(
UserMetricsAction("TabContextMenu_BookmarkAllTabs"));
@@ -1091,6 +1128,16 @@ bool TabStripModel::WillContextMenuPin(int index) {
return !all_pinned;
}
+bool TabStripModel::WillContextMenuMute(int index) {
sky 2014/09/23 22:58:17 Move this to tab_util and make it take a const std
miu 2014/09/24 22:34:15 Done.
+ std::vector<int> indices = GetIndicesForCommand(index);
+ // If all tabs are muted, then we unmute, otherwise we mute.
+ for (size_t i = 0; i < indices.size(); ++i) {
+ if (!IsTabAudioMuted(indices[i]))
+ return true;
+ }
+ return false;
+}
+
// static
bool TabStripModel::ContextMenuCommandToBrowserCommand(int cmd_id,
int* browser_cmd) {

Powered by Google App Engine
This is Rietveld 408576698