diff --git a/app/brave_command_ids.h b/app/brave_command_ids.h
index a828fd929b41..691abd3a4886 100644
--- a/app/brave_command_ids.h
+++ b/app/brave_command_ids.h
@@ -59,6 +59,11 @@
#define IDC_CONTENT_CONTEXT_IMPORT_IPNS_KEYS_START 56100
#define IDC_CONTENT_CONTEXT_IMPORT_IPNS_KEYS_END 56199
+#define IDC_BRAVE_BOOKMARK_BAR_SUBMENU 56200
+#define IDC_BRAVE_BOOKMARK_BAR_ALWAYS 56201
+#define IDC_BRAVE_BOOKMARK_BAR_NTP 56202
+#define IDC_BRAVE_BOOKMARK_BAR_NEVER 56203
+
#define IDC_BRAVE_COMMANDS_LAST 57000
#endif // BRAVE_APP_BRAVE_COMMAND_IDS_H_
diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd
index 4a88c2e51e63..6db4c2de65e2 100644
--- a/app/brave_generated_resources.grd
+++ b/app/brave_generated_resources.grd
@@ -168,6 +168,12 @@
Brave Rewards
+
+ Always
+
+
+ Never
+
Report a Broken Site
@@ -175,6 +181,9 @@
Copy Clean Link
+
+ Only On the New Tab Page
+
@@ -183,6 +192,9 @@
Copy clean link
+
+ Only on the new tab page
+
Sync
diff --git a/app/brave_settings_strings.grdp b/app/brave_settings_strings.grdp
index f595b134f3a1..8b9044f16985 100644
--- a/app/brave_settings_strings.grdp
+++ b/app/brave_settings_strings.grdp
@@ -95,8 +95,26 @@
Show Brave News button in address bar
+
+ Show bookmarks
+
+
+ Always
+
+
+ Bookmark bar is visible on all pages
+
- Always show bookmarks on new tab page
+ Only on the new tab page
+
+
+ Bookmark bar is hidden on all pages except the new tab page
+
+
+ Never
+
+
+ Bookmarks bar is hidden on all pages
Always show full URLs
diff --git a/browser/resources/settings/brave_appearance_page/bookmark_bar.html b/browser/resources/settings/brave_appearance_page/bookmark_bar.html
new file mode 100644
index 000000000000..4777703ecc75
--- /dev/null
+++ b/browser/resources/settings/brave_appearance_page/bookmark_bar.html
@@ -0,0 +1,21 @@
+
+
+
+
$i18n{appearanceSettingsBookmarBar}
+
+
+ [[bookmarkBarShowEnabledLabel_]]
+
+
+
+
+
+
diff --git a/browser/resources/settings/brave_appearance_page/bookmark_bar.ts b/browser/resources/settings/brave_appearance_page/bookmark_bar.ts
new file mode 100644
index 000000000000..59eca77172e8
--- /dev/null
+++ b/browser/resources/settings/brave_appearance_page/bookmark_bar.ts
@@ -0,0 +1,144 @@
+// 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/.
+
+import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'
+import {I18nMixin, I18nMixinInterface} from 'chrome://resources/cr_elements/i18n_mixin.js'
+import {PrefsMixin, PrefsMixinInterface} from '../prefs/prefs_mixin.js'
+import '../settings_shared.css.js'
+import '../settings_vars.css.js'
+import {getTemplate} from './bookmark_bar.html.js'
+
+const SettingsBraveAppearanceBookmarkBarElementBase =
+ PrefsMixin(I18nMixin(PolymerElement)) as {
+ new (): PolymerElement & I18nMixinInterface & PrefsMixinInterface
+ }
+
+enum BookmarkBarState {
+ ALWAYS = 0,
+ NONE = 1,
+ NTP = 2,
+}
+
+const kAlwaysShowBookmarBarPrefName = 'brave.always_show_bookmark_bar_on_ntp'
+const kShowOnAllTabsPrefName = 'bookmark_bar.show_on_all_tabs'
+
+/**
+ * 'settings-brave-appearance-bookmark-bar' is the settings page area containing
+ * brave's bookmark bar visibility settings in appearance settings.
+ */
+export class SettingsBraveAppearanceBookmarkBarElement
+ extends SettingsBraveAppearanceBookmarkBarElementBase {
+ static get is() {
+ return 'settings-brave-appearance-bookmark-bar'
+ }
+
+ static get template() {
+ return getTemplate()
+ }
+
+ static get properties() {
+ return {
+ /** @private {chrome.settingsPrivate.PrefType} */
+ bookmarkBarStatePref_: {
+ key: '',
+ type: Object,
+ value() {
+ return {
+ key: '',
+ type: chrome.settingsPrivate.PrefType.NUMBER,
+ value: BookmarkBarState.NTP
+ }
+ }
+ }
+ }
+ }
+
+ bookmarkBarStatePref_: chrome.settingsPrivate.PrefObject
+
+ private bookmarkBarShowOptions_ = [
+ {
+ value: BookmarkBarState.ALWAYS,
+ name: this.i18n('appearanceSettingsBookmarBarAlways')
+ },
+ {
+ value: BookmarkBarState.NONE,
+ name: this.i18n('appearanceSettingsBookmarBarNever')
+ },
+ {
+ value: BookmarkBarState.NTP,
+ name: this.i18n('appearanceSettingsBookmarBarNTP')
+ }
+ ]
+ private bookmarkBarShowEnabledLabel_: string
+
+ static get observers() {
+ return [
+ 'onPrefsChanged_(prefs.bookmark_bar.show_on_all_tabs.value,' +
+ ' prefs.brave.always_show_bookmark_bar_on_ntp.value)'
+ ]
+ }
+
+ override ready() {
+ super.ready()
+ window.addEventListener('load', this.onLoad_.bind(this));
+ }
+
+ private onLoad_() {
+ this.setControlValueFromPrefs()
+ }
+
+ private getBookmarkBarStateFromPrefs(): BookmarkBarState {
+ if (this.getPref(kShowOnAllTabsPrefName).value)
+ return BookmarkBarState.ALWAYS
+
+ if (this.getPref(kAlwaysShowBookmarBarPrefName).value)
+ return BookmarkBarState.NTP
+ return BookmarkBarState.NONE
+ }
+
+ private saveBookmarkBarStateToPrefs(state: BookmarkBarState) {
+ if (state === BookmarkBarState.ALWAYS) {
+ this.setPrefValue(kShowOnAllTabsPrefName, true)
+ } else if (state === BookmarkBarState.NTP) {
+ this.setPrefValue(kShowOnAllTabsPrefName, false)
+ this.setPrefValue(kAlwaysShowBookmarBarPrefName, true)
+ } else {
+ this.setPrefValue(kShowOnAllTabsPrefName, false)
+ this.setPrefValue(kAlwaysShowBookmarBarPrefName, false)
+ }
+ }
+ private setControlValueFromPrefs() {
+ const state = this.getBookmarkBarStateFromPrefs()
+ if (this.bookmarkBarStatePref_.value === state)
+ return
+ this.bookmarkBarStatePref_ = {
+ key: '',
+ type: chrome.settingsPrivate.PrefType.NUMBER,
+ value: state
+ };
+ }
+ private onPrefsChanged_() {
+ this.setControlValueFromPrefs()
+ }
+ private onShowOptionChanged_() {
+ const state = this.bookmarkBarStatePref_.value
+ if (state === BookmarkBarState.ALWAYS) {
+ this.bookmarkBarShowEnabledLabel_ =
+ this.i18n('appearanceSettingsBookmarBarAlwaysDesc')
+ } else if (state === BookmarkBarState.NTP) {
+ this.bookmarkBarShowEnabledLabel_ =
+ this.i18n('appearanceSettingsBookmarBarNTPDesc')
+ } else {
+ this.bookmarkBarShowEnabledLabel_ =
+ this.i18n('appearanceSettingsBookmarBarNeverDesc')
+ }
+
+ this.saveBookmarkBarStateToPrefs(this.bookmarkBarStatePref_.value)
+ }
+
+}
+
+customElements.define(SettingsBraveAppearanceBookmarkBarElement.is,
+ SettingsBraveAppearanceBookmarkBarElement)
diff --git a/browser/resources/settings/brave_appearance_page/toolbar.html b/browser/resources/settings/brave_appearance_page/toolbar.html
index 435c56f714cf..0d476ce3a137 100644
--- a/browser/resources/settings/brave_appearance_page/toolbar.html
+++ b/browser/resources/settings/brave_appearance_page/toolbar.html
@@ -60,9 +60,9 @@
+ label="$i18n{showFullUrls}">
+
+ `)
+
bookmarkBarToggle.insertAdjacentHTML('afterend', `
-
+
+
`)
+ // Remove Chromium bookmark toggle becasue it is replaced by
+ // settings-brave-appearance-bookmark-bar
+ bookmarkBarToggle.remove()
}
const zoomLevel = templateContent.getElementById('zoomLevel')
if (!zoomLevel || !zoomLevel.parentNode) {
diff --git a/browser/resources/settings/sources.gni b/browser/resources/settings/sources.gni
index 705a899c6194..be612ff29b65 100644
--- a/browser/resources/settings/sources.gni
+++ b/browser/resources/settings/sources.gni
@@ -14,6 +14,7 @@ brave_settings_preprocess_deps =
brave_settings_web_component_files = [
"brave_appearance_page/brave_theme.ts",
"brave_appearance_page/sidebar.ts",
+ "brave_appearance_page/bookmark_bar.ts",
"brave_appearance_page/super_referral.ts",
"brave_appearance_page/toolbar.ts",
"brave_clear_browsing_data_dialog/brave_clear_browsing_data_on_exit_page.ts",
diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn
index a8ae61fa3af1..cbeb7e30d8e1 100644
--- a/browser/ui/BUILD.gn
+++ b/browser/ui/BUILD.gn
@@ -99,8 +99,14 @@ source_set("ui") {
"omnibox/brave_omnibox_client_impl.cc",
"omnibox/brave_omnibox_client_impl.h",
"session_crashed_bubble_brave.cc",
+ "toolbar/bookmark_bar_sub_menu_model.cc",
+ "toolbar/bookmark_bar_sub_menu_model.h",
"toolbar/brave_app_menu_model.cc",
"toolbar/brave_app_menu_model.h",
+ "toolbar/brave_bookmark_context_menu_controller.cc",
+ "toolbar/brave_bookmark_context_menu_controller.h",
+ "toolbar/brave_bookmark_sub_menu_model.cc",
+ "toolbar/brave_bookmark_sub_menu_model.h",
"toolbar/brave_recent_tabs_sub_menu_model.h",
"webui/brave_rewards/rewards_panel_handler.cc",
"webui/brave_rewards/rewards_panel_handler.h",
@@ -211,6 +217,8 @@ source_set("ui") {
sources += [
"views/bookmarks/bookmark_bar_instructions_view.cc",
"views/bookmarks/bookmark_bar_instructions_view.h",
+ "views/bookmarks/brave_bookmark_context_menu.cc",
+ "views/bookmarks/brave_bookmark_context_menu.h",
"views/brave_first_run_dialog.cc",
"views/brave_first_run_dialog.h",
"views/brave_layout_provider.cc",
diff --git a/browser/ui/bookmark/BUILD.gn b/browser/ui/bookmark/BUILD.gn
index 0189f0b008f6..b78e7c50a004 100644
--- a/browser/ui/bookmark/BUILD.gn
+++ b/browser/ui/bookmark/BUILD.gn
@@ -1,7 +1,15 @@
+# Copyright (c) 2021 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 http://mozilla.org/MPL/2.0/.
+
source_set("bookmark") {
# Remove when https://github.com/brave/brave-browser/issues/10654 is resolved.
check_includes = false
+ assert(!is_android)
sources = [
+ "bookmark_helper.cc",
+ "bookmark_helper.h",
"bookmark_prefs_service.cc",
"bookmark_prefs_service.h",
"bookmark_prefs_service_factory.cc",
@@ -32,3 +40,16 @@ source_set("bookmark") {
"//ui/webui/resources/js/browser_command:mojo_bindings",
]
}
+
+source_set("unittest") {
+ testonly = true
+ assert(!is_android)
+ sources = [ "bookmark_helper_unittest.cc" ]
+
+ deps = [
+ "//brave/browser/ui/bookmark",
+ "//components/bookmarks/browser",
+ "//components/sync_preferences:test_support",
+ "//testing/gtest",
+ ]
+}
diff --git a/browser/ui/bookmark/bookmark_helper.cc b/browser/ui/bookmark/bookmark_helper.cc
new file mode 100644
index 000000000000..600c52308725
--- /dev/null
+++ b/browser/ui/bookmark/bookmark_helper.cc
@@ -0,0 +1,39 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/bookmark/bookmark_helper.h"
+
+#include "brave/components/constants/pref_names.h"
+#include "components/bookmarks/common/bookmark_pref_names.h"
+#include "components/prefs/pref_service.h"
+
+namespace brave {
+
+BookmarkBarState GetBookmarkBarState(PrefService* prefs) {
+ // kShowBookmarkBar has higher priority and the bookmark bar is shown always.
+ if (prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar))
+ return BookmarkBarState::kAlways;
+ // kShowBookmarkBar is false, kAlwaysShowBookmarkBarOnNTP is true
+ // -> the bookmark bar is shown only for NTP.
+ if (prefs->GetBoolean(kAlwaysShowBookmarkBarOnNTP))
+ return BookmarkBarState::kNtp;
+ // NEVER show the bookmark bar.
+ return BookmarkBarState::kNever;
+}
+
+void SetBookmarkState(BookmarkBarState state, PrefService* prefs) {
+ if (state == BookmarkBarState::kAlways) {
+ prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, true);
+ prefs->SetBoolean(kAlwaysShowBookmarkBarOnNTP, false);
+ } else if (state == BookmarkBarState::kNtp) {
+ prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
+ prefs->SetBoolean(kAlwaysShowBookmarkBarOnNTP, true);
+ } else {
+ prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
+ prefs->SetBoolean(kAlwaysShowBookmarkBarOnNTP, false);
+ }
+}
+
+} // namespace brave
diff --git a/browser/ui/bookmark/bookmark_helper.h b/browser/ui/bookmark/bookmark_helper.h
new file mode 100644
index 000000000000..03a93b80c6ac
--- /dev/null
+++ b/browser/ui/bookmark/bookmark_helper.h
@@ -0,0 +1,24 @@
+/* Copyright (c) 2023 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_BROWSER_UI_BOOKMARK_BOOKMARK_HELPER_H_
+#define BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_HELPER_H_
+
+class PrefService;
+
+namespace brave {
+
+// Show bookmarks a drop down choice of three options:
+// - Always (default)
+// - Never
+// - Only on the new tab page
+enum class BookmarkBarState { kAlways, kNever, kNtp };
+
+BookmarkBarState GetBookmarkBarState(PrefService* prefs);
+void SetBookmarkState(BookmarkBarState state, PrefService* prefs);
+
+} // namespace brave
+
+#endif // BRAVE_BROWSER_UI_BOOKMARK_BOOKMARK_HELPER_H_
diff --git a/browser/ui/bookmark/bookmark_helper_unittest.cc b/browser/ui/bookmark/bookmark_helper_unittest.cc
new file mode 100644
index 000000000000..ef2760566863
--- /dev/null
+++ b/browser/ui/bookmark/bookmark_helper_unittest.cc
@@ -0,0 +1,31 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/bookmark/bookmark_helper.h"
+
+#include "brave/browser/ui/bookmark/bookmark_prefs_service_factory.h"
+#include "components/bookmarks/browser/bookmark_utils.h"
+#include "components/sync_preferences/testing_pref_service_syncable.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(BookmarkStateUnittest, SetState) {
+ sync_preferences::TestingPrefServiceSyncable service;
+ BookmarkPrefsServiceFactory::GetInstance()->RegisterProfilePrefs(
+ service.registry());
+ bookmarks::RegisterProfilePrefs(service.registry());
+ // By default only NTP is enabled.
+ EXPECT_EQ(brave::GetBookmarkBarState(&service),
+ brave::BookmarkBarState::kNtp);
+
+ // Show bookmark bar always.
+ brave::SetBookmarkState(brave::BookmarkBarState::kAlways, &service);
+ EXPECT_EQ(brave::GetBookmarkBarState(&service),
+ brave::BookmarkBarState::kAlways);
+
+ // Never show bookmark bar.
+ brave::SetBookmarkState(brave::BookmarkBarState::kNever, &service);
+ EXPECT_EQ(brave::GetBookmarkBarState(&service),
+ brave::BookmarkBarState::kNever);
+}
diff --git a/browser/ui/bookmark/bookmark_prefs_service_factory.h b/browser/ui/bookmark/bookmark_prefs_service_factory.h
index c0f1699504df..8c5bf50e2f2a 100644
--- a/browser/ui/bookmark/bookmark_prefs_service_factory.h
+++ b/browser/ui/bookmark/bookmark_prefs_service_factory.h
@@ -24,6 +24,7 @@ class BookmarkPrefsServiceFactory : public BrowserContextKeyedServiceFactory {
private:
friend struct base::DefaultSingletonTraits;
+ FRIEND_TEST_ALL_PREFIXES(BookmarkStateUnittest, SetState);
BookmarkPrefsServiceFactory();
~BookmarkPrefsServiceFactory() override;
diff --git a/browser/ui/bookmark/bookmark_tab_helper_browsertest.cc b/browser/ui/bookmark/bookmark_tab_helper_browsertest.cc
index 0874a62805ae..15458a2faacc 100644
--- a/browser/ui/bookmark/bookmark_tab_helper_browsertest.cc
+++ b/browser/ui/bookmark/bookmark_tab_helper_browsertest.cc
@@ -66,7 +66,7 @@ IN_PROC_BROWSER_TEST_F(BookmarkTabHelperBrowserTest, BookmarkBarOnNTPTest) {
EXPECT_FALSE(IsNTP(contents));
EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
- // Check show bookarks on NTP is on by default.
+ // Check show bookmarks on NTP is on by default.
EXPECT_TRUE(profile->GetPrefs()->GetBoolean(kAlwaysShowBookmarkBarOnNTP));
// Loading NTP.
@@ -84,19 +84,59 @@ IN_PROC_BROWSER_TEST_F(BookmarkTabHelperBrowserTest, BookmarkBarOnNTPTest) {
chrome::ToggleBookmarkBar(browser());
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
chrome::ToggleBookmarkBar(browser());
- EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
-
+ EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
+ EXPECT_FALSE(profile->GetPrefs()->GetBoolean(kAlwaysShowBookmarkBarOnNTP));
// Turn off showing bookmark bar on NTP.
- profile->GetPrefs()->SetBoolean(kAlwaysShowBookmarkBarOnNTP, false);
+ profile->GetPrefs()->SetBoolean(kAlwaysShowBookmarkBarOnNTP, true);
- // Check bookmark bar on NTP is hidden.
- EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
+ // Check bookmark bar on NTP is visible when kAlwaysShowBookmarkBarOnNTP pref
+ // is on.
+ EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
// Check bookmark bar on NTP is visible when kBookmarkBar pref is on.
chrome::ToggleBookmarkBar(browser());
EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
+}
- // Check bookmark bar on NTP is hidden when kBookmarkBar pref is off.
- chrome::ToggleBookmarkBar(browser());
- EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state());
+IN_PROC_BROWSER_TEST_F(BookmarkTabHelperBrowserTest,
+ BookmarkBarOnNTPTestIncognito) {
+ Browser* incognito = CreateIncognitoBrowser();
+ auto* profile = incognito->profile();
+ auto* contents = incognito->tab_strip_model()->GetActiveWebContents();
+
+ // Check Bookmark bar is hidden by default for non NTP.
+ EXPECT_FALSE(IsNTP(contents));
+ EXPECT_EQ(BookmarkBar::HIDDEN, incognito->bookmark_bar_state());
+
+ // Check show bookmarks on NTP is on by default.
+ EXPECT_TRUE(profile->GetPrefs()->GetBoolean(kAlwaysShowBookmarkBarOnNTP));
+
+ // Loading NTP.
+ EXPECT_TRUE(
+ content::NavigateToURL(contents, GURL(chrome::kChromeUINewTabURL)));
+ EXPECT_TRUE(IsNTP(contents));
+
+ // Check bookmark bar on NTP is shown even if bookmark bar is empty.
+ EXPECT_EQ(BookmarkBar::SHOW, incognito->bookmark_bar_state());
+
+ AddBookmarkNode(profile);
+
+ // Check bookmark is also visible on NTP after adding bookmark regardless of
+ // show bookmark bar option value.
+ chrome::ToggleBookmarkBar(incognito);
+ EXPECT_EQ(BookmarkBar::SHOW, incognito->bookmark_bar_state());
+ chrome::ToggleBookmarkBar(incognito);
+ EXPECT_EQ(BookmarkBar::HIDDEN, incognito->bookmark_bar_state());
+ EXPECT_FALSE(profile->GetPrefs()->GetBoolean(kAlwaysShowBookmarkBarOnNTP));
+
+ // Turn on showing bookmark bar on NTP.
+ profile->GetPrefs()->SetBoolean(kAlwaysShowBookmarkBarOnNTP, true);
+
+ // Check bookmark bar on NTP is visible when kAlwaysShowBookmarkBarOnNTP pref
+ // is on.
+ EXPECT_EQ(BookmarkBar::SHOW, incognito->bookmark_bar_state());
+
+ // Check bookmark bar on NTP is visible when kBookmarkBar pref is on.
+ chrome::ToggleBookmarkBar(incognito);
+ EXPECT_EQ(BookmarkBar::SHOW, incognito->bookmark_bar_state());
}
diff --git a/browser/ui/brave_browser_command_controller.cc b/browser/ui/brave_browser_command_controller.cc
index 8cec0da918f1..d957275fa5f8 100644
--- a/browser/ui/brave_browser_command_controller.cc
+++ b/browser/ui/brave_browser_command_controller.cc
@@ -170,6 +170,7 @@ void BraveBrowserCommandController::InitBraveCommandState() {
#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
UpdateCommandEnabled(IDC_APP_MENU_IPFS_OPEN_FILES, true);
#endif
+ UpdateCommandEnabled(IDC_BRAVE_BOOKMARK_BAR_SUBMENU, true);
}
void BraveBrowserCommandController::UpdateCommandForBraveRewards() {
diff --git a/browser/ui/toolbar/bookmark_bar_sub_menu_model.cc b/browser/ui/toolbar/bookmark_bar_sub_menu_model.cc
new file mode 100644
index 000000000000..d6cdacfe6ac2
--- /dev/null
+++ b/browser/ui/toolbar/bookmark_bar_sub_menu_model.cc
@@ -0,0 +1,66 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/toolbar/bookmark_bar_sub_menu_model.h"
+
+#include "brave/browser/ui/bookmark/bookmark_helper.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/prefs/pref_service.h"
+#include "ui/base/models/simple_menu_model.h"
+
+BookmarkBarSubMenuModel::BookmarkBarSubMenuModel(Profile* profile)
+ : SimpleMenuModel(this), profile_(profile) {
+ Build();
+}
+
+BookmarkBarSubMenuModel::~BookmarkBarSubMenuModel() = default;
+
+void BookmarkBarSubMenuModel::Build() {
+ AddCheckItemWithStringId(IDC_BRAVE_BOOKMARK_BAR_ALWAYS,
+ IDS_BOOKMAR_BAR_MENU_SHOW_ALWAYS);
+
+ AddCheckItemWithStringId(IDC_BRAVE_BOOKMARK_BAR_NEVER,
+ IDS_BOOKMAR_BAR_MENU_SHOW_NEVER);
+
+ AddCheckItemWithStringId(IDC_BRAVE_BOOKMARK_BAR_NTP,
+ IDS_BOOKMAR_BAR_MENU_SHOW_NTP);
+}
+
+void BookmarkBarSubMenuModel::ExecuteCommand(int command_id, int event_flags) {
+ switch (command_id) {
+ case IDC_BRAVE_BOOKMARK_BAR_ALWAYS:
+ brave::SetBookmarkState(brave::BookmarkBarState::kAlways,
+ profile_->GetPrefs());
+ return;
+ case IDC_BRAVE_BOOKMARK_BAR_NEVER:
+ brave::SetBookmarkState(brave::BookmarkBarState::kNever,
+ profile_->GetPrefs());
+ return;
+ case IDC_BRAVE_BOOKMARK_BAR_NTP:
+ brave::SetBookmarkState(brave::BookmarkBarState::kNtp,
+ profile_->GetPrefs());
+ return;
+ }
+}
+
+bool BookmarkBarSubMenuModel::IsCommandIdChecked(int command_id) const {
+ switch (brave::GetBookmarkBarState(profile_->GetPrefs())) {
+ case brave::BookmarkBarState::kAlways:
+ return command_id == IDC_BRAVE_BOOKMARK_BAR_ALWAYS;
+ case brave::BookmarkBarState::kNtp:
+ return command_id == IDC_BRAVE_BOOKMARK_BAR_NTP;
+ case brave::BookmarkBarState::kNever:
+ return command_id == IDC_BRAVE_BOOKMARK_BAR_NEVER;
+ }
+ return false;
+}
+
+bool BookmarkBarSubMenuModel::IsCommandIdEnabled(int command_id) const {
+ return (command_id == IDC_BRAVE_BOOKMARK_BAR_ALWAYS ||
+ command_id == IDC_BRAVE_BOOKMARK_BAR_NEVER ||
+ command_id == IDC_BRAVE_BOOKMARK_BAR_NTP);
+}
diff --git a/browser/ui/toolbar/bookmark_bar_sub_menu_model.h b/browser/ui/toolbar/bookmark_bar_sub_menu_model.h
new file mode 100644
index 000000000000..6bdc66f5d773
--- /dev/null
+++ b/browser/ui/toolbar/bookmark_bar_sub_menu_model.h
@@ -0,0 +1,35 @@
+/* Copyright (c) 2023 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_BROWSER_UI_TOOLBAR_BOOKMARK_BAR_SUB_MENU_MODEL_H_
+#define BRAVE_BROWSER_UI_TOOLBAR_BOOKMARK_BAR_SUB_MENU_MODEL_H_
+
+#include "base/memory/raw_ptr.h"
+#include "ui/base/models/simple_menu_model.h"
+
+class Profile;
+
+class BookmarkBarSubMenuModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
+ public:
+ explicit BookmarkBarSubMenuModel(Profile* profile);
+
+ BookmarkBarSubMenuModel(const BookmarkBarSubMenuModel&) = delete;
+ BookmarkBarSubMenuModel& operator=(const BookmarkBarSubMenuModel&) = delete;
+
+ ~BookmarkBarSubMenuModel() override;
+
+ // ui::SimpleMenuModel::Delegate
+ void ExecuteCommand(int command_id, int event_flags) override;
+ bool IsCommandIdChecked(int command_id) const override;
+ bool IsCommandIdEnabled(int command_id) const override;
+
+ private:
+ void Build();
+
+ raw_ptr profile_ = nullptr;
+};
+
+#endif // BRAVE_BROWSER_UI_TOOLBAR_BOOKMARK_BAR_SUB_MENU_MODEL_H_
diff --git a/browser/ui/toolbar/brave_bookmark_context_menu_controller.cc b/browser/ui/toolbar/brave_bookmark_context_menu_controller.cc
new file mode 100644
index 000000000000..b9035e19d082
--- /dev/null
+++ b/browser/ui/toolbar/brave_bookmark_context_menu_controller.cc
@@ -0,0 +1,90 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/toolbar/brave_bookmark_context_menu_controller.h"
+
+#include
+#include
+
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/ui/bookmarks/bookmark_context_menu_controller.h"
+#include "chrome/grit/generated_resources.h"
+
+BraveBookmarkContextMenuController::BraveBookmarkContextMenuController(
+ gfx::NativeWindow parent_window,
+ BookmarkContextMenuControllerDelegate* delegate,
+ Browser* browser,
+ Profile* profile,
+ BookmarkLaunchLocation opened_from,
+ const bookmarks::BookmarkNode* parent,
+ const std::vector& selection)
+ : BookmarkContextMenuController(parent_window,
+ delegate,
+ browser,
+ profile,
+ opened_from,
+ parent,
+ selection) {
+ AddBraveBookmarksSubmenu(profile);
+}
+
+BraveBookmarkContextMenuController::~BraveBookmarkContextMenuController() =
+ default;
+
+void BraveBookmarkContextMenuController::AddBraveBookmarksSubmenu(
+ Profile* profile) {
+ auto index = menu_model()->GetIndexOfCommandId(IDC_BOOKMARK_BAR_ALWAYS_SHOW);
+ if (!index.has_value())
+ return;
+ menu_model()->RemoveItemAt(index.value());
+ brave_bookmarks_submenu_model_ =
+ std::make_unique(profile);
+
+ menu_model()->InsertSubMenuWithStringIdAt(
+ index.value(), IDC_BRAVE_BOOKMARK_BAR_SUBMENU, IDS_SHOW_BOOKMARK_BAR,
+ brave_bookmarks_submenu_model_.get());
+}
+
+bool BraveBookmarkContextMenuController::IsCommandIdChecked(
+ int command_id) const {
+ if (brave_bookmarks_submenu_model_->GetIndexOfCommandId(command_id))
+ return brave_bookmarks_submenu_model_->IsCommandIdChecked(command_id);
+ return BookmarkContextMenuController::IsCommandIdChecked(command_id);
+}
+
+bool BraveBookmarkContextMenuController::IsCommandIdEnabled(
+ int command_id) const {
+ if (brave_bookmarks_submenu_model_->GetIndexOfCommandId(command_id))
+ return brave_bookmarks_submenu_model_->IsCommandIdEnabled(command_id);
+ return BookmarkContextMenuController::IsCommandIdEnabled(command_id);
+}
+
+bool BraveBookmarkContextMenuController::IsCommandIdVisible(
+ int command_id) const {
+ if (brave_bookmarks_submenu_model_->GetIndexOfCommandId(command_id))
+ return brave_bookmarks_submenu_model_->IsCommandIdVisible(command_id);
+ return BookmarkContextMenuController::IsCommandIdVisible(command_id);
+}
+
+void BraveBookmarkContextMenuController::ExecuteCommand(int command_id,
+ int event_flags) {
+ if (brave_bookmarks_submenu_model_->GetIndexOfCommandId(command_id)) {
+ brave_bookmarks_submenu_model_->ExecuteCommand(command_id, event_flags);
+ return;
+ }
+ BookmarkContextMenuController::ExecuteCommand(command_id, event_flags);
+}
+
+std::u16string BraveBookmarkContextMenuController::GetLabelForCommandId(
+ int command_id) const {
+ if (brave_bookmarks_submenu_model_->GetIndexOfCommandId(command_id))
+ return brave_bookmarks_submenu_model_->GetLabelForCommandId(command_id);
+ return BookmarkContextMenuController::GetLabelForCommandId(command_id);
+}
+
+BookmarkBarSubMenuModel*
+BraveBookmarkContextMenuController::GetBookmarkSubmenuModel() {
+ return brave_bookmarks_submenu_model_.get();
+}
diff --git a/browser/ui/toolbar/brave_bookmark_context_menu_controller.h b/browser/ui/toolbar/brave_bookmark_context_menu_controller.h
new file mode 100644
index 000000000000..d9302840f44d
--- /dev/null
+++ b/browser/ui/toolbar/brave_bookmark_context_menu_controller.h
@@ -0,0 +1,55 @@
+/* Copyright (c) 2023 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_BROWSER_UI_TOOLBAR_BRAVE_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_
+#define BRAVE_BROWSER_UI_TOOLBAR_BRAVE_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_
+
+#include
+#include
+
+#include "brave/browser/ui/toolbar/bookmark_bar_sub_menu_model.h"
+#include "chrome/browser/ui/bookmarks/bookmark_context_menu_controller.h"
+#include "ui/base/models/simple_menu_model.h"
+#include "ui/gfx/native_widget_types.h"
+
+class Browser;
+class Profile;
+
+class BraveBookmarkContextMenuController
+ : public BookmarkContextMenuController {
+ public:
+ BraveBookmarkContextMenuController(
+ gfx::NativeWindow parent_window,
+ BookmarkContextMenuControllerDelegate* delegate,
+ Browser* browser,
+ Profile* profile,
+ BookmarkLaunchLocation opened_from,
+ const bookmarks::BookmarkNode* parent,
+ const std::vector& selection);
+
+ BraveBookmarkContextMenuController(
+ const BraveBookmarkContextMenuController&) = delete;
+ BraveBookmarkContextMenuController& operator=(
+ const BraveBookmarkContextMenuController&) = delete;
+
+ ~BraveBookmarkContextMenuController() override;
+
+ BookmarkBarSubMenuModel* GetBookmarkSubmenuModel();
+
+ // ui::SimpleMenuModel::Delegate implementation:
+ bool IsCommandIdChecked(int command_id) const override;
+ bool IsCommandIdEnabled(int command_id) const override;
+ bool IsCommandIdVisible(int command_id) const override;
+ void ExecuteCommand(int command_id, int event_flags) override;
+
+ std::u16string GetLabelForCommandId(int command_id) const override;
+
+ private:
+ void AddBraveBookmarksSubmenu(Profile* profile);
+
+ std::unique_ptr brave_bookmarks_submenu_model_;
+};
+
+#endif // BRAVE_BROWSER_UI_TOOLBAR_BRAVE_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_
diff --git a/chromium_src/chrome/browser/ui/bookmarks/brave_bookmark_context_menu_controller_unittest.cc b/browser/ui/toolbar/brave_bookmark_context_menu_controller_unittest.cc
similarity index 51%
rename from chromium_src/chrome/browser/ui/bookmarks/brave_bookmark_context_menu_controller_unittest.cc
rename to browser/ui/toolbar/brave_bookmark_context_menu_controller_unittest.cc
index 10d8ce5f7354..f50a9efacb3e 100644
--- a/chromium_src/chrome/browser/ui/bookmarks/brave_bookmark_context_menu_controller_unittest.cc
+++ b/browser/ui/toolbar/brave_bookmark_context_menu_controller_unittest.cc
@@ -1,15 +1,18 @@
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */
+ * You can obtain one at https://mozilla.org/MPL/2.0/. */
#include
#include
#include
+#include "brave/browser/ui/toolbar/brave_bookmark_context_menu_controller.h"
+
#include "base/memory/raw_ptr.h"
#include "base/values.h"
+#include "brave/browser/ui/bookmark/bookmark_helper.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -88,8 +91,76 @@ TEST_F(BraveBookmarkContextMenuControllerTest,
// And enabling the shortcut by user doesn't cause the command to be added.
prefs->RemoveManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar);
prefs->SetUserPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
- std::make_unique(true));
+ std::make_unique(true));
EXPECT_FALSE(controller.menu_model()
->GetIndexOfCommandId(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT)
.has_value());
}
+
+TEST_F(BraveBookmarkContextMenuControllerTest, AddBraveBookmarksSubmenu) {
+ BraveBookmarkContextMenuController controller(
+ nullptr, nullptr, nullptr, profile_.get(),
+ BookmarkLaunchLocation::kSidePanelFolder, model_->bookmark_bar_node(),
+ std::vector());
+ EXPECT_FALSE(controller.menu_model()
+ ->GetIndexOfCommandId(IDC_BOOKMARK_BAR_ALWAYS_SHOW)
+ .has_value());
+
+ EXPECT_FALSE(controller.menu_model()
+ ->GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_ALWAYS)
+ .has_value());
+ EXPECT_FALSE(controller.menu_model()
+ ->GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_NEVER)
+ .has_value());
+ EXPECT_FALSE(controller.menu_model()
+ ->GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_NTP)
+ .has_value());
+
+ auto submenu_index = controller.menu_model()->GetIndexOfCommandId(
+ IDC_BRAVE_BOOKMARK_BAR_SUBMENU);
+ EXPECT_TRUE(submenu_index.has_value());
+ auto* submenu_model =
+ controller.menu_model()->GetSubmenuModelAt(submenu_index.value());
+ ASSERT_TRUE(submenu_model);
+ EXPECT_EQ(submenu_model->GetCommandIdAt(0), IDC_BRAVE_BOOKMARK_BAR_ALWAYS);
+ EXPECT_EQ(submenu_model->GetCommandIdAt(1), IDC_BRAVE_BOOKMARK_BAR_NEVER);
+ EXPECT_EQ(submenu_model->GetCommandIdAt(2), IDC_BRAVE_BOOKMARK_BAR_NTP);
+
+ EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BRAVE_BOOKMARK_BAR_ALWAYS));
+ EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BRAVE_BOOKMARK_BAR_NEVER));
+ EXPECT_TRUE(controller.IsCommandIdEnabled(IDC_BRAVE_BOOKMARK_BAR_NTP));
+
+ EXPECT_TRUE(controller.IsCommandIdVisible(IDC_BRAVE_BOOKMARK_BAR_ALWAYS));
+ EXPECT_TRUE(controller.IsCommandIdVisible(IDC_BRAVE_BOOKMARK_BAR_NEVER));
+ EXPECT_TRUE(controller.IsCommandIdVisible(IDC_BRAVE_BOOKMARK_BAR_NTP));
+
+ auto* bookmark_submenu_model = controller.GetBookmarkSubmenuModel();
+ EXPECT_EQ(controller.GetLabelForCommandId(IDC_BRAVE_BOOKMARK_BAR_ALWAYS),
+ bookmark_submenu_model->GetLabelForCommandId(
+ IDC_BRAVE_BOOKMARK_BAR_ALWAYS));
+ EXPECT_EQ(controller.GetLabelForCommandId(IDC_BRAVE_BOOKMARK_BAR_NEVER),
+ bookmark_submenu_model->GetLabelForCommandId(
+ IDC_BRAVE_BOOKMARK_BAR_NEVER));
+ EXPECT_EQ(
+ controller.GetLabelForCommandId(IDC_BRAVE_BOOKMARK_BAR_NTP),
+ bookmark_submenu_model->GetLabelForCommandId(IDC_BRAVE_BOOKMARK_BAR_NTP));
+
+ // Default state is NTP only.
+ EXPECT_FALSE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_ALWAYS));
+ EXPECT_FALSE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_NEVER));
+ EXPECT_TRUE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_NTP));
+
+ // Set state as Always.
+ brave::SetBookmarkState(brave::BookmarkBarState::kAlways,
+ profile_->GetPrefs());
+ EXPECT_TRUE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_ALWAYS));
+ EXPECT_FALSE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_NEVER));
+ EXPECT_FALSE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_NTP));
+
+ // Set state as Never.
+ brave::SetBookmarkState(brave::BookmarkBarState::kNever,
+ profile_->GetPrefs());
+ EXPECT_FALSE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_ALWAYS));
+ EXPECT_TRUE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_NEVER));
+ EXPECT_FALSE(controller.IsCommandIdChecked(IDC_BRAVE_BOOKMARK_BAR_NTP));
+}
diff --git a/browser/ui/toolbar/brave_bookmark_sub_menu_model.cc b/browser/ui/toolbar/brave_bookmark_sub_menu_model.cc
new file mode 100644
index 000000000000..6b99d837c874
--- /dev/null
+++ b/browser/ui/toolbar/brave_bookmark_sub_menu_model.cc
@@ -0,0 +1,31 @@
+/* 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 "brave/browser/ui/toolbar/brave_bookmark_sub_menu_model.h"
+
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/grit/generated_resources.h"
+
+BraveBookmarkSubMenuModel::BraveBookmarkSubMenuModel(
+ ui::SimpleMenuModel::Delegate* delegate,
+ Browser* browser)
+ : BookmarkSubMenuModel(delegate, browser) {
+ Build(browser);
+}
+
+BraveBookmarkSubMenuModel::~BraveBookmarkSubMenuModel() = default;
+
+void BraveBookmarkSubMenuModel::Build(Browser* browser) {
+ auto index = GetIndexOfCommandId(IDC_SHOW_BOOKMARK_BAR);
+ if (!index.has_value())
+ return;
+ RemoveItemAt(index.value());
+ brave_bookmarks_submenu_model_ =
+ std::make_unique(browser->profile());
+ InsertSubMenuWithStringIdAt(index.value(), IDC_BRAVE_BOOKMARK_BAR_SUBMENU,
+ IDS_SHOW_BOOKMARK_BAR,
+ brave_bookmarks_submenu_model_.get());
+}
diff --git a/browser/ui/toolbar/brave_bookmark_sub_menu_model.h b/browser/ui/toolbar/brave_bookmark_sub_menu_model.h
new file mode 100644
index 000000000000..f9903077218c
--- /dev/null
+++ b/browser/ui/toolbar/brave_bookmark_sub_menu_model.h
@@ -0,0 +1,33 @@
+/* Copyright (c) 2023 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_BROWSER_UI_TOOLBAR_BRAVE_BOOKMARK_SUB_MENU_MODEL_H_
+#define BRAVE_BROWSER_UI_TOOLBAR_BRAVE_BOOKMARK_SUB_MENU_MODEL_H_
+
+#include
+
+#include "brave/browser/ui/toolbar/bookmark_bar_sub_menu_model.h"
+#include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h"
+
+class Browser;
+
+class BraveBookmarkSubMenuModel : public BookmarkSubMenuModel {
+ public:
+ BraveBookmarkSubMenuModel(ui::SimpleMenuModel::Delegate* delegate,
+ Browser* browser);
+
+ BraveBookmarkSubMenuModel(const BraveBookmarkSubMenuModel&) = delete;
+ BraveBookmarkSubMenuModel& operator=(const BraveBookmarkSubMenuModel&) =
+ delete;
+
+ ~BraveBookmarkSubMenuModel() override;
+
+ private:
+ void Build(Browser* browser);
+
+ std::unique_ptr brave_bookmarks_submenu_model_;
+};
+
+#endif // BRAVE_BROWSER_UI_TOOLBAR_BRAVE_BOOKMARK_SUB_MENU_MODEL_H_
diff --git a/browser/ui/toolbar/brave_bookmark_sub_menu_model_unittest.cc b/browser/ui/toolbar/brave_bookmark_sub_menu_model_unittest.cc
new file mode 100644
index 000000000000..93ca490a9b70
--- /dev/null
+++ b/browser/ui/toolbar/brave_bookmark_sub_menu_model_unittest.cc
@@ -0,0 +1,123 @@
+/* Copyright (c) 2023 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
+
+#include
+#include
+#include
+
+#include "brave/browser/ui/toolbar/brave_bookmark_sub_menu_model.h"
+
+#include "base/memory/raw_ptr.h"
+#include "base/values.h"
+#include "brave/browser/brave_local_state_prefs.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/bookmarks/bookmark_model_factory.h"
+#include "chrome/browser/prefs/browser_prefs.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/test/base/test_browser_window.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/bookmarks/test/bookmark_test_helpers.h"
+#include "components/sync_preferences/testing_pref_service_syncable.h"
+#include "content/public/test/browser_task_environment.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using bookmarks::BookmarkModel;
+using bookmarks::BookmarkNode;
+using content::BrowserThread;
+
+namespace {
+
+class TestSimpleMenuDelegate : public ui::SimpleMenuModel::Delegate {
+ public:
+ TestSimpleMenuDelegate() = default;
+
+ TestSimpleMenuDelegate(const TestSimpleMenuDelegate&) = delete;
+ TestSimpleMenuDelegate& operator=(const TestSimpleMenuDelegate&) = delete;
+
+ ~TestSimpleMenuDelegate() override = default;
+
+ bool IsCommandIdChecked(int command_id) const override { return false; }
+
+ bool IsCommandIdEnabled(int command_id) const override { return true; }
+
+ void ExecuteCommand(int command_id, int event_flags) override {}
+};
+
+} // namespace
+
+class BraveBookmarkSubMenuModelUnitTest : public testing::Test {
+ public:
+ BraveBookmarkSubMenuModelUnitTest() {}
+
+ void SetUp() override {
+ TestingProfile::Builder builder;
+ builder.AddTestingFactory(BookmarkModelFactory::GetInstance(),
+ BookmarkModelFactory::GetDefaultFactory());
+ auto prefs =
+ std::make_unique();
+ RegisterUserProfilePrefs(prefs->registry());
+
+ RegisterLocalState(test_local_state_.registry());
+ TestingBrowserProcess::GetGlobal()->SetLocalState(&test_local_state_);
+ builder.SetPrefService(std::move(prefs));
+ profile_ = builder.Build();
+ model_ = BookmarkModelFactory::GetForBrowserContext(profile_.get());
+ bookmarks::test::WaitForBookmarkModelToLoad(model_);
+ }
+
+ ui::SimpleMenuModel::Delegate* delegate() { return &delegate_; }
+
+ Browser* GetBrowser() {
+ if (!browser_) {
+ Browser::CreateParams params(profile_.get(), true);
+ test_window_ = std::make_unique();
+ params.window = test_window_.get();
+ browser_.reset(Browser::Create(params));
+ }
+ return browser_.get();
+ }
+ void TearDown() override {
+ browser_.reset();
+ TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
+ }
+
+ protected:
+ content::BrowserTaskEnvironment task_environment_;
+ TestSimpleMenuDelegate delegate_;
+ std::unique_ptr browser_;
+ std::unique_ptr test_window_;
+ std::unique_ptr profile_;
+ raw_ptr model_ = nullptr;
+ TestingPrefServiceSimple test_local_state_;
+};
+
+TEST_F(BraveBookmarkSubMenuModelUnitTest, Build) {
+ BraveBookmarkSubMenuModel model(delegate(), GetBrowser());
+ EXPECT_GT(model.GetItemCount(), 0u);
+ EXPECT_FALSE(model.GetIndexOfCommandId(IDC_SHOW_BOOKMARK_BAR).has_value());
+ EXPECT_FALSE(model.GetIndexOfCommandId(IDC_SHOW_BOOKMARK_BAR).has_value());
+ EXPECT_FALSE(
+ model.GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_ALWAYS).has_value());
+ EXPECT_FALSE(
+ model.GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_NEVER).has_value());
+ EXPECT_FALSE(
+ model.GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_NTP).has_value());
+
+ auto submenu_index =
+ model.GetIndexOfCommandId(IDC_BRAVE_BOOKMARK_BAR_SUBMENU);
+ EXPECT_TRUE(submenu_index.has_value());
+ auto* submenu_model = model.GetSubmenuModelAt(submenu_index.value());
+ ASSERT_TRUE(submenu_model);
+
+ EXPECT_EQ(submenu_model->GetCommandIdAt(0), IDC_BRAVE_BOOKMARK_BAR_ALWAYS);
+ EXPECT_EQ(submenu_model->GetCommandIdAt(1), IDC_BRAVE_BOOKMARK_BAR_NEVER);
+ EXPECT_EQ(submenu_model->GetCommandIdAt(2), IDC_BRAVE_BOOKMARK_BAR_NTP);
+ EXPECT_EQ(submenu_model->GetItemCount(), 3u);
+}
diff --git a/browser/ui/views/bookmarks/brave_bookmark_context_menu.cc b/browser/ui/views/bookmarks/brave_bookmark_context_menu.cc
new file mode 100644
index 000000000000..b617f6a6e186
--- /dev/null
+++ b/browser/ui/views/bookmarks/brave_bookmark_context_menu.cc
@@ -0,0 +1,41 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/views/bookmarks/brave_bookmark_context_menu.h"
+
+#include
+
+#include "brave/browser/ui/toolbar/brave_bookmark_context_menu_controller.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
+#include "chrome/grit/generated_resources.h"
+#include "ui/views/controls/menu/menu_item_view.h"
+#include "ui/views/controls/menu/menu_model_adapter.h"
+
+BraveBookmarkContextMenu::BraveBookmarkContextMenu(
+ views::Widget* parent_widget,
+ Browser* browser,
+ Profile* profile,
+ BookmarkLaunchLocation opened_from,
+ const bookmarks::BookmarkNode* parent,
+ const std::vector& selection,
+ bool close_on_remove)
+ : BookmarkContextMenu(parent_widget,
+ browser,
+ profile,
+ opened_from,
+ parent,
+ selection,
+ close_on_remove) {
+ auto* submenu = menu()->GetMenuItemByID(IDC_BRAVE_BOOKMARK_BAR_SUBMENU);
+ DCHECK(submenu);
+ auto* submenu_model = controller_->GetBookmarkSubmenuModel();
+ for (size_t j = 0; j < submenu_model->GetItemCount(); ++j) {
+ views::MenuModelAdapter::AppendMenuItemFromModel(
+ submenu_model, j, submenu, submenu_model->GetCommandIdAt(j));
+ }
+}
+
+BraveBookmarkContextMenu::~BraveBookmarkContextMenu() = default;
diff --git a/browser/ui/views/bookmarks/brave_bookmark_context_menu.h b/browser/ui/views/bookmarks/brave_bookmark_context_menu.h
new file mode 100644
index 000000000000..f1c8c12c0c81
--- /dev/null
+++ b/browser/ui/views/bookmarks/brave_bookmark_context_menu.h
@@ -0,0 +1,32 @@
+/* Copyright (c) 2023 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_BROWSER_UI_VIEWS_BOOKMARKS_BRAVE_BOOKMARK_CONTEXT_MENU_H_
+#define BRAVE_BROWSER_UI_VIEWS_BOOKMARKS_BRAVE_BOOKMARK_CONTEXT_MENU_H_
+
+#include
+
+#include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
+
+class BraveBookmarkContextMenu : public BookmarkContextMenu {
+ public:
+ // |browser| is used to open bookmarks as well as the bookmark manager, and
+ // is NULL in tests.
+ BraveBookmarkContextMenu(
+ views::Widget* parent_widget,
+ Browser* browser,
+ Profile* profile,
+ BookmarkLaunchLocation opened_from,
+ const bookmarks::BookmarkNode* parent,
+ const std::vector& selection,
+ bool close_on_remove);
+
+ BraveBookmarkContextMenu(const BraveBookmarkContextMenu&) = delete;
+ BraveBookmarkContextMenu& operator=(const BraveBookmarkContextMenu&) = delete;
+
+ ~BraveBookmarkContextMenu() override;
+};
+
+#endif // BRAVE_BROWSER_UI_VIEWS_BOOKMARKS_BRAVE_BOOKMARK_CONTEXT_MENU_H_
diff --git a/browser/ui/views/bookmarks/brave_bookmark_context_menu_unittest.cc b/browser/ui/views/bookmarks/brave_bookmark_context_menu_unittest.cc
new file mode 100644
index 000000000000..34860fd89ba4
--- /dev/null
+++ b/browser/ui/views/bookmarks/brave_bookmark_context_menu_unittest.cc
@@ -0,0 +1,69 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/views/bookmarks/brave_bookmark_context_menu.h"
+
+#include
+#include
+#include
+#include
+
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/bookmarks/bookmark_model_factory.h"
+#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/test/base/testing_profile.h"
+#include "components/bookmarks/test/bookmark_test_helpers.h"
+#include "components/prefs/pref_service.h"
+#include "content/public/test/browser_task_environment.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/controls/menu/menu_item_view.h"
+#include "ui/views/controls/menu/submenu_view.h"
+#include "ui/views/test/scoped_views_test_helper.h"
+
+using bookmarks::BookmarkModel;
+using bookmarks::BookmarkNode;
+
+class BraveBookmarkContextMenuTest : public testing::Test {
+ public:
+ BraveBookmarkContextMenuTest() : model_(nullptr) {}
+
+ void SetUp() override {
+ TestingProfile::Builder profile_builder;
+ profile_builder.AddTestingFactory(
+ BookmarkModelFactory::GetInstance(),
+ BookmarkModelFactory::GetDefaultFactory());
+ profile_builder.AddTestingFactory(
+ ManagedBookmarkServiceFactory::GetInstance(),
+ ManagedBookmarkServiceFactory::GetDefaultFactory());
+ profile_ = profile_builder.Build();
+
+ model_ = BookmarkModelFactory::GetForBrowserContext(profile_.get());
+ bookmarks::test::WaitForBookmarkModelToLoad(model_);
+ }
+
+ protected:
+ content::BrowserTaskEnvironment task_environment_;
+ views::ScopedViewsTestHelper views_test_helper_;
+ std::unique_ptr profile_;
+ raw_ptr model_;
+};
+
+TEST_F(BraveBookmarkContextMenuTest, OverrideBookmarkMenu) {
+ auto controller = std::make_unique(
+ nullptr, nullptr, profile_.get(), BookmarkLaunchLocation::kNone, nullptr,
+ std::vector(), false);
+ auto* menu =
+ controller->menu()->GetMenuItemByID(IDC_BRAVE_BOOKMARK_BAR_SUBMENU);
+ EXPECT_TRUE(menu);
+ auto* submenu = menu->GetSubmenu();
+ EXPECT_EQ(submenu->GetMenuItemAt(0)->GetCommand(),
+ IDC_BRAVE_BOOKMARK_BAR_ALWAYS);
+ EXPECT_EQ(submenu->GetMenuItemAt(1)->GetCommand(),
+ IDC_BRAVE_BOOKMARK_BAR_NEVER);
+ EXPECT_EQ(submenu->GetMenuItemAt(2)->GetCommand(),
+ IDC_BRAVE_BOOKMARK_BAR_NTP);
+ EXPECT_EQ(submenu->GetMenuItems().size(), 3u);
+}
diff --git a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc
index e52d9fd42989..db865c77f5cc 100644
--- a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc
+++ b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc
@@ -112,8 +112,18 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_SHOW_BRAVE_REWARDS_BUTTON_LABEL},
{"appearanceSettingsShowBraveNewsButtonLabel",
IDS_SETTINGS_SHOW_BRAVE_NEWS_BUTTON_LABEL},
- {"appearanceSettingsAlwaysShowBookmarkBarOnNTP",
+ {"appearanceSettingsBookmarBar", IDS_SETTINGS_SHOW_BOOKMARK_BAR},
+ {"appearanceSettingsBookmarBarAlways",
+ IDS_SETTINGS_ALWAYS_SHOW_BOOKMARK_BAR_ALWAYS},
+ {"appearanceSettingsBookmarBarNTP",
IDS_SETTINGS_ALWAYS_SHOW_BOOKMARK_BAR_ON_NTP},
+ {"appearanceSettingsBookmarBarNever", IDS_SETTINGS_NEVER_SHOW_BOOKMARK_BAR},
+ {"appearanceSettingsBookmarBarAlwaysDesc",
+ IDS_SETTINGS_ALWAYS_SHOW_BOOKMARK_BAR_ALWAYS_DESC},
+ {"appearanceSettingsBookmarBarNTPDesc",
+ IDS_SETTINGS_ALWAYS_SHOW_BOOKMARK_BAR_ON_NTP_DESC},
+ {"appearanceSettingsBookmarBarNeverDesc",
+ IDS_SETTINGS_NEVER_SHOW_BOOKMARK_BAR_DESC},
{"appearanceSettingsShowAutocompleteInAddressBar",
IDS_SETTINGS_APPEARANCE_SETTINGS_SHOW_AUTOCOMPLETE_IN_ADDRESS_BAR},
{"appearanceSettingsUseTopSiteSuggestions",
diff --git a/chromium_src/chrome/browser/prefs/pref_service_incognito_allowlist.cc b/chromium_src/chrome/browser/prefs/pref_service_incognito_allowlist.cc
index 09570dc18849..c76a97a28445 100644
--- a/chromium_src/chrome/browser/prefs/pref_service_incognito_allowlist.cc
+++ b/chromium_src/chrome/browser/prefs/pref_service_incognito_allowlist.cc
@@ -9,6 +9,7 @@
#include "brave/components/constants/pref_names.h"
#include "build/build_config.h"
#include "chrome/common/pref_names.h"
+#include "components/bookmarks/common/bookmark_pref_names.h"
namespace {
@@ -26,9 +27,9 @@ const std::vector& GetBravePersistentPrefNames() {
#define GetIncognitoPersistentPrefsAllowlist \
GetIncognitoPersistentPrefsAllowlist_ChromiumImpl
-
+#define kShowBookmarkBar kShowBookmarkBar, kAlwaysShowBookmarkBarOnNTP
#include "src/chrome/browser/prefs/pref_service_incognito_allowlist.cc"
-
+#undef kShowBookmarkBar
#undef GetIncognitoPersistentPrefsAllowlist
namespace prefs {
diff --git a/chromium_src/chrome/browser/sync/bookmark_sync_service_factory.cc b/chromium_src/chrome/browser/sync/bookmark_sync_service_factory.cc
new file mode 100644
index 000000000000..ba8490b35d21
--- /dev/null
+++ b/chromium_src/chrome/browser/sync/bookmark_sync_service_factory.cc
@@ -0,0 +1,22 @@
+/* Copyright (c) 2023 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/sync/bookmark_sync_service_factory.h"
+#include "build/build_config.h"
+
+#if !BUILDFLAG(IS_ANDROID)
+#include "brave/browser/ui/bookmark/bookmark_prefs_service_factory.h"
+
+// Adding BookmarkPrefsServiceFactory as dependency because kShowBookmarBar and
+// kAlwaysShowBookmarkBarOnNTP manage bookmark bar state together and need to
+// register both prefs at same time.
+#define DependsOn \
+ DependsOn(BookmarkPrefsServiceFactory::GetInstance()); \
+ DependsOn
+#endif
+#include "src/chrome/browser/sync/bookmark_sync_service_factory.cc"
+#if !BUILDFLAG(IS_ANDROID)
+#undef DependsOn
+#endif
diff --git a/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc b/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc
index 3599b7170c8a..91a5e7454b23 100644
--- a/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc
+++ b/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc
@@ -3,13 +3,39 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
+#include "brave/browser/ui/bookmark/bookmark_helper.h"
+#include "brave/components/constants/pref_names.h"
#include "build/build_config.h"
#include "chrome/grit/theme_resources.h"
+#include "components/bookmarks/common/bookmark_pref_names.h"
+#include "components/prefs/pref_service.h"
+#include "components/user_prefs/user_prefs.h"
+#include "content/public/browser/browser_context.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/color_utils.h"
+namespace chrome {
+
+void ToggleBookmarkBarWhenVisible_ChromiumImpl(
+ content::BrowserContext* browser_context);
+
+void BraveToggleBookmarkBarState(content::BrowserContext* browser_context) {
+ ToggleBookmarkBarWhenVisible_ChromiumImpl(browser_context);
+ auto* prefs = user_prefs::UserPrefs::Get(browser_context);
+ // On macOS with the View menu or via hotkeys, the options Always show
+ // bookmarks is a checkbox. We will keep that checkbox to be Always and Never.
+ const bool always_show =
+ prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar);
+ brave::SetBookmarkState(always_show ? brave::BookmarkBarState::kAlways
+ : brave::BookmarkBarState::kNever,
+ prefs);
+}
+
+} // namespace chrome
+
#define IsAppsShortcutEnabled IsAppsShortcutEnabled_Unused
#define ShouldShowAppsShortcutInBookmarkBar \
ShouldShowAppsShortcutInBookmarkBar_Unused
@@ -18,8 +44,14 @@
#define GetBookmarkFolderIcon GetBookmarkFolderIcon_UnUsed
#endif
-#include "src/chrome/browser/ui/bookmarks/bookmark_utils.cc"
+#define ToggleBookmarkBarWhenVisible \
+ ToggleBookmarkBarWhenVisible(content::BrowserContext* browser_context) { \
+ BraveToggleBookmarkBarState(browser_context); \
+ } \
+ void ToggleBookmarkBarWhenVisible_ChromiumImpl
+#include "src/chrome/browser/ui/bookmarks/bookmark_utils.cc"
+#undef ToggleBookmarkBarWhenVisible
#undef IsAppsShortcutEnabled
#undef ShouldShowAppsShortcutInBookmarkBar
diff --git a/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc b/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc
index eddc0ffae1bf..c594563ba6cf 100644
--- a/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc
+++ b/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc
@@ -3,10 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "brave/browser/ui/toolbar/brave_bookmark_sub_menu_model.h"
#include "brave/browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h"
+#include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h"
#define RecentTabsSubMenuModel BraveRecentTabsSubMenuModel
-
+#define BookmarkSubMenuModel BraveBookmarkSubMenuModel
#include "src/chrome/browser/ui/toolbar/app_menu_model.cc"
-
+#undef BookmarkSubMenuModel
#undef RecentTabsSubMenuModel
diff --git a/chromium_src/chrome/browser/ui/toolbar/app_menu_model.h b/chromium_src/chrome/browser/ui/toolbar/app_menu_model.h
new file mode 100644
index 000000000000..81c04107f388
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/toolbar/app_menu_model.h
@@ -0,0 +1,16 @@
+/* Copyright (c) 2023 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_TOOLBAR_APP_MENU_MODEL_H_
+#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOOLBAR_APP_MENU_MODEL_H_
+
+#include "brave/browser/ui/toolbar/brave_bookmark_sub_menu_model.h"
+#include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h"
+
+#define BookmarkSubMenuModel BraveBookmarkSubMenuModel
+#include "src/chrome/browser/ui/toolbar/app_menu_model.h"
+#undef BookmarkSubMenuModel
+
+#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOOLBAR_APP_MENU_MODEL_H_
diff --git a/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
index 00be25cd840c..fb774b9b29cf 100644
--- a/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -1,10 +1,11 @@
-/* Copyright 2019 The Brave Authors. All rights reserved.
+/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */
+ * You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/browser/ui/brave_view_ids.h"
#include "brave/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h"
+#include "brave/browser/ui/views/bookmarks/brave_bookmark_context_menu.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "ui/views/controls/highlight_path_generator.h"
@@ -69,8 +70,9 @@ void InstallNoHighlightPathGenerator(View* view) {
#define BRAVE_LAYOUT \
LayoutBookmarkBarInstructionsView(this, bookmark_model_, browser(), \
button_height, x, max_x, y);
-
+#define BookmarkContextMenu BraveBookmarkContextMenu
#define InstallPillHighlightPathGenerator InstallNoHighlightPathGenerator
#include "src/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc"
#undef InstallPillHighlightPathGenerator
+#undef BookmarkContextMenu
#undef BRAVE_LAYOUT
diff --git a/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc
new file mode 100644
index 000000000000..3dc229b5858a
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc
@@ -0,0 +1,12 @@
+/* Copyright (c) 2023 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/bookmarks/bookmark_context_menu.h"
+
+#include "brave/browser/ui/toolbar/brave_bookmark_context_menu_controller.h"
+
+#define BookmarkContextMenuController BraveBookmarkContextMenuController
+#include "src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc"
+#undef BookmarkContextMenuController
diff --git a/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.h b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.h
new file mode 100644
index 000000000000..f710199938a3
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.h
@@ -0,0 +1,19 @@
+/* Copyright (c) 2023 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_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_
+#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_
+
+#include "brave/browser/ui/toolbar/brave_bookmark_context_menu_controller.h"
+
+#define BookmarkContextMenuController BraveBookmarkContextMenuController
+#define close_on_remove_ \
+ close_on_remove_; \
+ friend class BraveBookmarkContextMenu
+#include "src/chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
+#undef BookmarkContextMenuController
+#undef close_on_remove_
+
+#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_
diff --git a/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc
new file mode 100644
index 000000000000..97d431895abf
--- /dev/null
+++ b/chromium_src/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc
@@ -0,0 +1,10 @@
+/* Copyright (c) 2023 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 "brave/browser/ui/views/bookmarks/brave_bookmark_context_menu.h"
+
+#define BookmarkContextMenu BraveBookmarkContextMenu
+#include "src/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc"
+#undef BookmarkContextMenu
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 4d687af91439..5643c844605d 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -364,15 +364,17 @@ test("brave_unit_tests") {
"//brave/browser/resources/settings/brandcode_config_fetcher_unittest.cc",
"//brave/browser/resources/settings/reset_report_uploader_unittest.cc",
"//brave/browser/themes/brave_theme_service_unittest.cc",
+ "//brave/browser/ui/toolbar/brave_bookmark_context_menu_controller_unittest.cc",
+ "//brave/browser/ui/toolbar/brave_bookmark_sub_menu_model_unittest.cc",
"//brave/browser/ui/toolbar/brave_location_bar_model_delegate_unittest.cc",
"//brave/browser/ui/views/accelerator_table_unittest.cc",
+ "//brave/browser/ui/views/bookmarks/brave_bookmark_context_menu_unittest.cc",
"//brave/browser/ui/views/wallet_bubble_focus_observer_unittest.cc",
"//brave/browser/ui/webui/brave_wallet/wallet_common_ui_unittest.cc",
"//brave/browser/ui/webui/ipfs_dom_handler_unittest.cc",
"//brave/browser/ui/webui/settings/brave_wallet_handler_unittest.cc",
"//brave/chromium_src/chrome/browser/devtools/url_constants_unittest.cc",
"//brave/chromium_src/chrome/browser/profiles/profile_avatar_icon_util_unittest.cc",
- "//brave/chromium_src/chrome/browser/ui/bookmarks/brave_bookmark_context_menu_controller_unittest.cc",
"//chrome/browser/push_messaging/push_messaging_app_identifier_unittest.cc",
"//chrome/browser/push_messaging/push_messaging_notification_manager_unittest.cc",
"//chrome/browser/push_messaging/push_messaging_service_unittest.cc",
@@ -397,6 +399,8 @@ test("brave_unit_tests") {
]
deps += [
"//brave/app:brave_generated_resources_grit",
+ "//brave/browser/ui/bookmark",
+ "//brave/browser/ui/bookmark:unittest",
"//brave/browser/ui/color:unit_tests",
"//brave/browser/ui/toolbar:brave_app_menu_unit_test",
"//brave/browser/ui/webui/settings:unittests",