diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 8ada7008fe2f..676d78ac1f7f 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -172,6 +172,9 @@ Open Guest Window + + Moreā€¦ + $1 (extension ID "$2abacabadabacabaeabacabadabacabaf") is not allowed in Brave. diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 332a142ffb86..ba68d10548c1 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -75,6 +75,7 @@ source_set("ui") { "content_settings/brave_content_setting_image_models.h", "omnibox/brave_omnibox_client_impl.cc", "omnibox/brave_omnibox_client_impl.h", + "toolbar/brave_recent_tabs_sub_menu_model.h", "toolbar/brave_app_menu_model.cc", "toolbar/brave_app_menu_model.h", "webui/brave_settings_ui.cc", diff --git a/browser/ui/toolbar/BUILD.gn b/browser/ui/toolbar/BUILD.gn new file mode 100644 index 000000000000..af477bf1f7ee --- /dev/null +++ b/browser/ui/toolbar/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2020 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/. + +assert(!is_android && !is_ios) + +source_set("brave_app_menu_unit_test") { + testonly = true + + public_deps = [ + "//testing/gmock", + "//testing/gtest", + ] + + sources = [ + "//chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.cc", + "//chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h", + "//chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc", + "//chrome/test/base/browser_with_test_window_test.cc", + "//chrome/test/base/browser_with_test_window_test.h", + "//chrome/test/base/menu_model_test.cc", + "//chrome/test/base/menu_model_test.h", + ] + + deps = [ + "//chrome/app:command_ids", + "//chrome/browser/ui:ui", + "//chrome/test:test_support", + "//components/constrained_window:constrained_window", + "//components/sessions:test_support", + "//components/sync_preferences:sync_preferences", + "//components/sync_sessions:sync_sessions", + "//content/test:test_support", + "//ui/views:test_support", + ] +} diff --git a/browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h b/browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h new file mode 100644 index 000000000000..23140a5a7d1d --- /dev/null +++ b/browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2020 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/. */ + +#ifndef BRAVE_BROWSER_UI_TOOLBAR_BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ +#define BRAVE_BROWSER_UI_TOOLBAR_BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ + +#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" + +class Browser; + +namespace ui { +class AcceleratorProvider; +} + +class BraveRecentTabsSubMenuModel : public RecentTabsSubMenuModel { + public: + BraveRecentTabsSubMenuModel(ui::AcceleratorProvider* accelerator_provider, + Browser* browser); + + ~BraveRecentTabsSubMenuModel() override; + + void ExecuteCommand(int command_id, int event_flags) override; + + private: + DISALLOW_COPY_AND_ASSIGN(BraveRecentTabsSubMenuModel); +}; + +#endif // BRAVE_BROWSER_UI_TOOLBAR_BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ diff --git a/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc b/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc new file mode 100644 index 000000000000..4cdbd47c2f44 --- /dev/null +++ b/chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc @@ -0,0 +1,12 @@ +/* Copyright (c) 2020 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/. */ + +#include "brave/browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h" + +#define RecentTabsSubMenuModel BraveRecentTabsSubMenuModel + +#include "../../../../../../chrome/browser/ui/toolbar/app_menu_model.cc" + +#undef RecentTabsSubMenuModel diff --git a/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc new file mode 100644 index 000000000000..e104de66c875 --- /dev/null +++ b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc @@ -0,0 +1,66 @@ +/* Copyright (c) 2020 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/. */ + +#include "chrome/browser/ui/singleton_tabs.h" + +namespace { + +const char kBraveStubSessionTag[] = "brave_stub_more_session_tag"; +const char kBraveSyncedTabsUrl[] = "brave://history/syncedTabs"; + +} // namespace + +#define BRAVE_BUILD_TABS_FROM_OTHER_DEVICES \ + if (tabs_in_session.size() > kMaxTabsPerSessionToShow) { \ + /* Not all the tabs are shown in menu */ \ + if (!stub_tab_.get()) { \ + stub_tab_.reset(new sessions::SessionTab()); \ + sessions::SerializedNavigationEntry stub_nav_entry; \ + stub_nav_entry.set_title( \ + l10n_util::GetStringUTF16(IDS_OPEN_MORE_OTHER_DEVICES_SESSIONS)); \ + stub_nav_entry.set_virtual_url(GURL(kBraveSyncedTabsUrl)); \ + stub_tab_->navigations.push_back(stub_nav_entry); \ + stub_tab_->tab_id = SessionID::NewUnique(); \ + } \ + tabs_in_session[kMaxTabsPerSessionToShow] = stub_tab_.get(); \ + BuildOtherDevicesTabItem(kBraveStubSessionTag, \ + *tabs_in_session[kMaxTabsPerSessionToShow]); \ + } + +#include "../../../../../../chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc" + +#undef BRAVE_BUILD_TABS_FROM_OTHER_DEVICES + +#include "brave/browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h" + +// Methods of BraveRecentTabsSubMenuModel are implemented below instead of +// brave_recent_tabs_sub_menu_model.cc to have the access to functions in +// anonymous namespace in recent_tabs_sub_menu_model.cc + +BraveRecentTabsSubMenuModel::BraveRecentTabsSubMenuModel( + ui::AcceleratorProvider* accelerator_provider, + Browser* browser) + : RecentTabsSubMenuModel(accelerator_provider, browser) {} + +BraveRecentTabsSubMenuModel::~BraveRecentTabsSubMenuModel() {} + +void BraveRecentTabsSubMenuModel::ExecuteCommand(int command_id, + int event_flags) { + if (IsTabModelCommandId(command_id)) { + TabNavigationItems* tab_items = NULL; + int tab_items_idx = CommandIdToTabVectorIndex(command_id, &tab_items); + const TabNavigationItem& item = (*tab_items)[tab_items_idx]; + DCHECK(item.tab_id.is_valid() && item.url.is_valid()); + + if (item.session_tag == kBraveStubSessionTag) { + ShowSingletonTabOverwritingNTP( + browser_, + GetSingletonTabNavigateParams(browser_, GURL(kBraveSyncedTabsUrl))); + return; + } + } + + RecentTabsSubMenuModel::ExecuteCommand(command_id, event_flags); +} diff --git a/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h new file mode 100644 index 000000000000..f118beff4639 --- /dev/null +++ b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2020 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ + +#define BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ \ + private: \ + std::auto_ptr stub_tab_; \ + friend class BraveRecentTabsSubMenuModel; \ + public: +#include "../../../../../../chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" + +#undef BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_TOOLBAR_RECENT_TABS_SUB_MENU_MODEL_H_ diff --git a/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc new file mode 100644 index 000000000000..6f104d5584fd --- /dev/null +++ b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc @@ -0,0 +1,32 @@ +/* Copyright (c) 2020 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/. */ + +// Disabling these tests because they refer g_brave_browser_process which is not +// initialized in unit tests, is null and so they are crashing. +// Not related to change in RecentTabsSubMenuModel for additional `More...` +// menu item +#define RecentlyClosedTabsFromCurrentSession \ + DISABLED_RecentlyClosedTabsFromCurrentSession + +#define RecentlyClosedTabsAndWindowsFromLastSession \ + DISABLED_RecentlyClosedTabsAndWindowsFromLastSession + +// Need to expect more items at that place, because Brave has additional item +// `More...` which redirects to brave://history/syncedTabs +// The perfect way is to have +// EXPECT_EQ(10, num_items) +// instead +// EXPECT_EQ(9, num_items); +// But in favor to reduce patch, just decrease num_items: +#define BRAVE_MAX_TABS_PER_SESSION_AND_RECENCY \ + --num_items; + +// The case when number of tabs on other device is <=4 so we do not add +// `More...` item is tested by RecentTabsSubMenuModelTest.MaxSessionsAndRecency + +#include "../../../../../../chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc" + +#undef RecentlyClosedTabsAndWindowsFromLastSession +#undef RecentlyClosedTabsFromCurrentSession diff --git a/patches/chrome-VERSION.patch b/patches/chrome-VERSION.patch index a54994ed567a..3c9fe8e61b15 100644 --- a/patches/chrome-VERSION.patch +++ b/patches/chrome-VERSION.patch @@ -1,5 +1,5 @@ diff --git a/chrome/VERSION b/chrome/VERSION -index 2c4514a701725958eed9feacc7a43c46ef1f2fba..205283ea59b247e3aa5ac69d0d81f2c05133c5b8 100644 +index 2c4514a701725958eed9feacc7a43c46ef1f2fba..6d423561e1ebcc4ca78cb414346bbb09695b328f 100644 --- a/chrome/VERSION +++ b/chrome/VERSION @@ -1,4 +1,4 @@ diff --git a/patches/chrome-browser-resources-history-app.html.patch b/patches/chrome-browser-resources-history-app.html.patch deleted file mode 100644 index 861c8777f478..000000000000 --- a/patches/chrome-browser-resources-history-app.html.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/chrome/browser/resources/history/app.html b/chrome/browser/resources/history/app.html -index 0afd8eb41341f3e10aa216dc00599078fc8f5df0..1360df4b5e903f3eca956d32e9765d34173309d5 100644 ---- a/chrome/browser/resources/history/app.html -+++ b/chrome/browser/resources/history/app.html -@@ -70,6 +70,7 @@ - query-result="[[queryResult_]]" - path="history"> - -+ - - - diff --git a/patches/chrome-browser-resources-history-side_bar.html.patch b/patches/chrome-browser-resources-history-side_bar.html.patch deleted file mode 100644 index 80849daf210f..000000000000 --- a/patches/chrome-browser-resources-history-side_bar.html.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/chrome/browser/resources/history/side_bar.html b/chrome/browser/resources/history/side_bar.html -index 372d46cf8efc72e91bb9473a59b762cbfc868090..d0cfe9cca0e895713302f4e410d1a45bef4a94c6 100644 ---- a/chrome/browser/resources/history/side_bar.html -+++ b/chrome/browser/resources/history/side_bar.html -@@ -101,11 +101,13 @@ - $i18n{historyMenuItem} - - -+ -
- + [[noSyncedTabsMessage(fetchingSyncedTabs_, searchTerm)]] + ++ + + +