Make muting sites easier (#16269)

This commit is contained in:
Jay Harris
2022-12-13 23:49:46 +01:00
committed by GitHub
parent 4e681eb030
commit 89cb653421
17 changed files with 177 additions and 13 deletions
+12
View File
@@ -852,6 +852,12 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_TAB_CXMENU_USE_FLOATING_VERTICAL_TABS" desc="The label of the tab context menu item for enabling floating mode for vertical tab strip">
Float on mouseover
</message>
<message name="IDS_TAB_CXMENU_SOUND_MUTE_TAB" desc="The label of the tab context menu item for muting one or more tabs. NOTE: If having no explicit # makes the phrasing awkward, feel free to add a # as necessary. [ICU Syntax]">
{NUM_TABS, plural, =1 {Mute tab} other {Mute tabs}}
</message>
<message name="IDS_TAB_CXMENU_SOUND_UNMUTE_TAB" desc="The label of the tab context menu item for unmuting one or more tabs. NOTE: If having no explicit # makes the phrasing awkward, feel free to add a # as necessary. [ICU Syntax]">
{NUM_TABS, plural, =1 {Unmute tab} other {Unmute tabs}}
</message>
</if>
<if expr="use_titlecase">
<message name="IDS_TAB_CXMENU_BOOKMARK_ALL_TABS" desc="In Title Case: The label of the tab context menu item for creating a bookmark folder containing an entry for each open tab.">
@@ -866,6 +872,12 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_TAB_CXMENU_USE_FLOATING_VERTICAL_TABS" desc="The label of the tab context menu item for enabling floating mode for vertical tab strip">
Float on Mouseover
</message>
<message name="IDS_TAB_CXMENU_SOUND_MUTE_TAB" desc="The label of the tab context menu item for muting one or more tabs. NOTE: If having no explicit # makes the phrasing awkward, feel free to add a # as necessary. [ICU Syntax]">
{NUM_TABS, plural, =1 {Mute Tab} other {Mute Tabs}}
</message>
<message name="IDS_TAB_CXMENU_SOUND_UNMUTE_TAB" desc="The label of the tab context menu item for unmuting one or more tabs. NOTE: If having no explicit # makes the phrasing awkward, feel free to add a # as necessary. [ICU Syntax]">
{NUM_TABS, plural, =1 {Unmute Tab} other {Unmute Tabs}}
</message>
</if>
<!-- Brave VPN -->
+3
View File
@@ -1171,6 +1171,9 @@
<message name="IDS_SETTINGS_CLOSING_LAST_TAB_OPTION_LABEL" desc="The text for settings option">
Close window when closing last tab
</message>
<message name="IDS_SETTINGS_DISABLE_CLICKABLE_MUTE_INDICATORS" desc="The text for the settings option for disabling clickable tab mute indicators">
Disable mute function in tab speaker icons
</message>
<!-- Avatars. Generated via zsh and node:
declare -i a=56
+1
View File
@@ -204,6 +204,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(brave_rewards::prefs::kShowButton, true);
registry->RegisterBooleanPref(kMRUCyclingEnabled, false);
registry->RegisterBooleanPref(kTabsSearchShow, true);
registry->RegisterBooleanPref(kTabMuteIndicatorNotClickable, false);
brave_sync::Prefs::RegisterProfilePrefs(registry);
@@ -168,6 +168,8 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_tabs::kTabHoverMode] =
settings_api::PREF_TYPE_NUMBER;
(*s_brave_allowlist)[kTabMuteIndicatorNotClickable] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
#if BUILDFLAG(ENABLE_BRAVE_VPN)
(*s_brave_allowlist)[brave_vpn::prefs::kBraveVPNShowButton] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
@@ -20,6 +20,11 @@
class="cr-row"
label="$i18n{showFullUrls}">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.brave.tabs.mute_indicator_not_clickable}}"
class="cr-row"
label="$i18n{braveDisableClickableMuteIndicators}">
</settings-toggle-button>
<settings-toggle-button
class="cr-row"
pref="{{prefs.brave.autocomplete_enabled}}"
+27 -4
View File
@@ -5,6 +5,11 @@
#include "brave/browser/ui/tabs/brave_tab_menu_model.h"
#include <algorithm>
#include <vector>
#include "brave/browser/ui/tabs/brave_tab_strip_model.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/ui/browser.h"
@@ -12,6 +17,8 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/grit/generated_resources.h"
#include "components/sessions/core/tab_restore_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/list_selection_model.h"
BraveTabMenuModel::BraveTabMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
@@ -26,7 +33,13 @@ BraveTabMenuModel::BraveTabMenuModel(
TabRestoreServiceFactory::GetForProfile(browser->profile());
}
Build();
auto indices = static_cast<BraveTabStripModel*>(tab_strip_model)
->GetTabIndicesForCommandAt(index);
all_muted_ = std::all_of(
indices.begin(), indices.end(), [&tab_strip_model](int index) {
return tab_strip_model->GetWebContentsAt(index)->IsAudioMuted();
});
Build(indices.size());
}
BraveTabMenuModel::~BraveTabMenuModel() = default;
@@ -44,15 +57,25 @@ int BraveTabMenuModel::GetRestoreTabCommandStringId() const {
return id;
if (restore_service_->entries().front()->type ==
sessions::TabRestoreService::WINDOW) {
id = IDS_RESTORE_WINDOW;
sessions::TabRestoreService::WINDOW) {
id = IDS_RESTORE_WINDOW;
}
return id;
}
void BraveTabMenuModel::Build() {
void BraveTabMenuModel::Build(int selected_tab_count) {
AddSeparator(ui::NORMAL_SEPARATOR);
auto mute_site_index =
GetIndexOfCommandId(TabStripModel::CommandToggleSiteMuted);
auto toggle_tab_mute_label = l10n_util::GetPluralStringFUTF16(
all_muted() ? IDS_TAB_CXMENU_SOUND_UNMUTE_TAB
: IDS_TAB_CXMENU_SOUND_MUTE_TAB,
selected_tab_count);
InsertItemAt(mute_site_index.value_or(GetItemCount()), CommandToggleTabMuted,
toggle_tab_mute_label);
AddItemWithStringId(CommandRestoreTab, GetRestoreTabCommandStringId());
AddItemWithStringId(CommandBookmarkAllTabs, IDS_TAB_CXMENU_BOOKMARK_ALL_TABS);
AddCheckItemWithStringId(CommandShowVerticalTabs,
+5 -1
View File
@@ -27,6 +27,7 @@ class BraveTabMenuModel : public TabMenuModel {
CommandShowVerticalTabs,
CommandShowTitleBar,
CommandUseFloatingVerticalTabStrip,
CommandToggleTabMuted,
CommandLast,
};
@@ -38,12 +39,15 @@ class BraveTabMenuModel : public TabMenuModel {
BraveTabMenuModel& operator=(const BraveTabMenuModel&) = delete;
~BraveTabMenuModel() override;
bool all_muted() const { return all_muted_; }
private:
void Build();
void Build(int selected_tab_count);
int GetRestoreTabCommandStringId() const;
raw_ptr<content::WebContents> web_contents_ = nullptr;
sessions::TabRestoreService* restore_service_ = nullptr;
bool all_muted_;
};
#endif // BRAVE_BROWSER_UI_TABS_BRAVE_TAB_MENU_MODEL_H_
+6
View File
@@ -6,6 +6,7 @@
#include "brave/browser/ui/tabs/brave_tab_strip_model.h"
#include <algorithm>
#include <vector>
#include "brave/browser/ui/brave_browser_window.h"
#include "brave/components/constants/pref_names.h"
@@ -14,6 +15,7 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_contents.h"
@@ -76,3 +78,7 @@ void BraveTabStripModel::SelectMRUTab(TabRelativeDirection direction,
void BraveTabStripModel::StopMRUCycling() {
mru_cycle_list_.clear();
}
std::vector<int> BraveTabStripModel::GetTabIndicesForCommandAt(int tab_index) {
return TabStripModel::GetIndicesForCommand(tab_index);
}
+3
View File
@@ -33,6 +33,9 @@ class BraveTabStripModel : public TabStripModel {
// Stop MRU cycling, called when releasing the Ctrl key
void StopMRUCycling();
// Exposes a |TabStripModel| api to |BraveTabMenuModel|.
std::vector<int> GetTabIndicesForCommandAt(int tab_index);
private:
// List of tab indexes sorted by most recently used
std::vector<int> mru_cycle_list_;
@@ -5,9 +5,15 @@
#include "brave/browser/ui/views/tabs/brave_tab_context_menu_contents.h"
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include "brave/browser/ui/browser_commands.h"
#include "brave/browser/ui/tabs/brave_tab_menu_model.h"
#include "brave/browser/ui/tabs/brave_tab_prefs.h"
#include "brave/browser/ui/tabs/brave_tab_strip_model.h"
#include "brave/browser/ui/views/tabs/brave_browser_tab_strip_controller.h"
#include "brave/browser/ui/views/tabs/features.h"
#include "chrome/browser/defaults.h"
@@ -15,8 +21,12 @@
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "components/sessions/core/tab_restore_service.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/controls/menu/menu_runner.h"
BraveTabContextMenuContents::BraveTabContextMenuContents(
@@ -24,6 +34,7 @@ BraveTabContextMenuContents::BraveTabContextMenuContents(
BraveBrowserTabStripController* controller,
int index)
: tab_(tab),
tab_index_(index),
browser_(const_cast<Browser*>(controller->browser())),
controller_(controller) {
model_ = std::make_unique<BraveTabMenuModel>(
@@ -42,9 +53,8 @@ void BraveTabContextMenuContents::Cancel() {
controller_ = nullptr;
}
void BraveTabContextMenuContents::RunMenuAt(
const gfx::Point& point,
ui::MenuSourceType source_type) {
void BraveTabContextMenuContents::RunMenuAt(const gfx::Point& point,
ui::MenuSourceType source_type) {
menu_runner_->RunMenuAt(tab_->GetWidget(), nullptr,
gfx::Rect(point, gfx::Size()),
views::MenuAnchorPosition::kTopLeft, source_type);
@@ -72,8 +82,7 @@ bool BraveTabContextMenuContents::IsCommandIdEnabled(int command_id) const {
return IsBraveCommandIdEnabled(command_id);
return controller_->IsCommandEnabledForTab(
static_cast<TabStripModel::ContextMenuCommand>(command_id),
tab_);
static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_);
}
bool BraveTabContextMenuContents::IsCommandIdVisible(int command_id) const {
@@ -111,8 +120,7 @@ void BraveTabContextMenuContents::ExecuteCommand(int command_id,
// Executing the command destroys |this|, and can also end up destroying
// |controller_|. So stop the highlights before executing the command.
controller_->ExecuteCommandForTab(
static_cast<TabStripModel::ContextMenuCommand>(command_id),
tab_);
static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_);
}
bool BraveTabContextMenuContents::IsBraveCommandIdEnabled(
@@ -131,6 +139,14 @@ bool BraveTabContextMenuContents::IsBraveCommandIdEnabled(
case BraveTabMenuModel::CommandShowVerticalTabs:
case BraveTabMenuModel::CommandUseFloatingVerticalTabStrip:
return true;
case BraveTabMenuModel::CommandToggleTabMuted: {
auto* model = static_cast<BraveTabStripModel*>(controller_->model());
for (const auto& index : model->GetTabIndicesForCommandAt(tab_index_)) {
if (!model->GetWebContentsAt(index)->GetLastCommittedURL().is_empty())
return true;
}
return false;
}
default:
NOTREACHED();
break;
@@ -161,6 +177,22 @@ void BraveTabContextMenuContents::ExecuteBraveCommand(int command_id) {
brave::ToggleVerticalTabStripFloatingMode(browser_);
return;
}
case BraveTabMenuModel::CommandToggleTabMuted: {
auto* model = static_cast<BraveTabStripModel*>(controller_->model());
auto indices = model->GetTabIndicesForCommandAt(tab_index_);
std::vector<content::WebContents*> contentses;
std::transform(
indices.begin(), indices.end(), std::back_inserter(contentses),
[&model](int index) { return model->GetWebContentsAt(index); });
auto all_muted = model_->all_muted();
for (auto* contents : contentses) {
chrome::SetTabAudioMuted(contents, !all_muted,
TabMutedReason::AUDIO_INDICATOR,
/*extension_id=*/std::string());
}
return;
}
default:
NOTREACHED();
return;
@@ -60,6 +60,7 @@ class BraveTabContextMenuContents : public ui::SimpleMenuModel::Delegate {
std::unique_ptr<views::MenuRunner> menu_runner_;
raw_ptr<Tab> tab_ = nullptr;
int tab_index_;
raw_ptr<Browser> browser_ = nullptr;
sessions::TabRestoreService* restore_service_ = nullptr;
raw_ptr<BraveBrowserTabStripController> controller_ = nullptr;
@@ -280,6 +280,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"braveHelpTipsWarnBeforeClosingWindow",
IDS_SETTINGS_WINDOW_CLOSING_CONFIRM_OPTION_LABEL},
{"braveHelpTipsClosingLastTab", IDS_SETTINGS_CLOSING_LAST_TAB_OPTION_LABEL},
{"braveDisableClickableMuteIndicators",
IDS_SETTINGS_DISABLE_CLICKABLE_MUTE_INDICATORS},
// New Tab Page
{"braveNewTab", IDS_SETTINGS_NEW_TAB},
{"braveNewTabBraveRewards", IDS_SETTINGS_NEW_TAB_BRAVE_REWARDS},
@@ -6,6 +6,7 @@
#include <vector>
#include "base/no_destructor.h"
#include "brave/components/constants/pref_names.h"
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
@@ -14,7 +15,7 @@ namespace {
const std::vector<const char*>& GetBravePersistentPrefNames() {
static base::NoDestructor<std::vector<const char*>> brave_allowlist({
#if !BUILDFLAG(IS_ANDROID)
prefs::kSidePanelHorizontalAlignment,
prefs::kSidePanelHorizontalAlignment, kTabMuteIndicatorNotClickable,
#endif
});
@@ -0,0 +1,37 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "chrome/browser/ui/views/tabs/alert_indicator_button.h"
#include "brave/components/constants/pref_names.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_slot_controller.h"
#include "components/prefs/pref_service.h"
#define AlertIndicatorButton AlertIndicatorButtonBase
#include "src/chrome/browser/ui/views/tabs/alert_indicator_button.cc"
#undef AlertIndicatorButton
void AlertIndicatorButton::UpdateEnabledForMuteToggle() {
const bool was_enabled = GetEnabled();
auto* browser = GetTab()->controller()->GetBrowser();
// We have clickable mute indicators enabled by default. Thus, if our pref is
// disabled we can force the indicator off.
// Note: We have a test which checks the feature is enabled by default. If
// that changes this may need to as well.
// Note: |browser| is |nullptr| in some unit_tests.
if (browser && browser->profile()->GetPrefs()->GetBoolean(
kTabMuteIndicatorNotClickable)) {
if (was_enabled)
SetEnabled(false);
return;
}
AlertIndicatorButtonBase::UpdateEnabledForMuteToggle();
}
@@ -0,0 +1,29 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_ALERT_INDICATOR_BUTTON_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_ALERT_INDICATOR_BUTTON_H_
class AlertIndicatorButton;
#define AlertIndicatorButton AlertIndicatorButtonBase
#define GetTab \
GetTab_Unused(); \
\
protected: \
Tab* GetTab
#define UpdateEnabledForMuteToggle virtual UpdateEnabledForMuteToggle
#include "src/chrome/browser/ui/views/tabs/alert_indicator_button.h"
#undef UpdateEnabledForMuteToggle
#undef GetTab
#undef AlertIndicatorButton
class AlertIndicatorButton : public AlertIndicatorButtonBase {
public:
using AlertIndicatorButtonBase::AlertIndicatorButtonBase;
void UpdateEnabledForMuteToggle() override;
};
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_ALERT_INDICATOR_BUTTON_H_
+2
View File
@@ -79,6 +79,8 @@ const char kImportDialogExtensions[] = "import_dialog_extensions";
const char kImportDialogPayments[] = "import_dialog_payments";
const char kMRUCyclingEnabled[] = "brave.mru_cycling_enabled";
const char kTabsSearchShow[] = "brave.tabs_search_show";
const char kTabMuteIndicatorNotClickable[] =
"brave.tabs.mute_indicator_not_clickable";
const char kDontAskForCrashReporting[] = "brave.dont_ask_for_crash_reporting";
const char kEnableMediaRouterOnRestart[] =
"brave.enable_media_router_on_restart";
+1
View File
@@ -84,6 +84,7 @@ extern const char kEnableClosingLastTab[];
#endif
extern const char kDefaultBrowserLaunchingCount[];
extern const char kTabsSearchShow[];
extern const char kTabMuteIndicatorNotClickable[];
extern const char kDontAskForCrashReporting[];
// Cast extension requires a browser restart once the setting is toggled.