From 8b7ffec80a1d42e361e7499e4dbcd943c039e422 Mon Sep 17 00:00:00 2001 From: AlexeyBarabash Date: Mon, 16 Nov 2020 16:50:38 +0200 Subject: [PATCH] History sub menu item for all tabs from other synced devices --- app/brave_generated_resources.grd | 3 ++ .../ui/toolbar/recent_tabs_sub_menu_model.cc | 43 +++++++++++++++++++ .../ui/toolbar/recent_tabs_sub_menu_model.h | 19 ++++++++ ...oolbar-recent_tabs_sub_menu_model.cc.patch | 20 +++++++++ ...toolbar-recent_tabs_sub_menu_model.h.patch | 12 ++++++ 5 files changed, 97 insertions(+) create mode 100644 chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc create mode 100644 chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h create mode 100644 patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.cc.patch create mode 100644 patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.h.patch diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 58fce4b1c1a6..36d4efd33766 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/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..74d93a5c6985 --- /dev/null +++ b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc @@ -0,0 +1,43 @@ +/* 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_EXECUTE_COMMAND \ + if (item.session_tag == kBraveStubSessionTag) { \ + ShowSingletonTabOverwritingNTP( \ + browser_, \ + GetSingletonTabNavigateParams(browser_, GURL(kBraveSyncedTabsUrl))); \ + return; \ + } + +#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 +#undef BRAVE_EXECUTE_COMMAND 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..9d940107c8b3 --- /dev/null +++ b/chromium_src/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h @@ -0,0 +1,19 @@ +/* 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_; \ + public: +// define BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ + +#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/patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.cc.patch b/patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.cc.patch new file mode 100644 index 000000000000..bbfe60f38c77 --- /dev/null +++ b/patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc +index 8cdfc6fbdddcb13bcd5e198cd6ebf53abfb0269d..d9102ed0aedb4d7c5561438715ec4fa277fc3cde 100644 +--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc ++++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc +@@ -270,6 +270,7 @@ void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { + const TabNavigationItem& item = (*tab_items)[tab_items_idx]; + DCHECK(item.tab_id.is_valid() && item.url.is_valid()); + ++ BRAVE_EXECUTE_COMMAND + if (item.session_tag.empty()) { // Restore tab of local session. + if (service && context) { + base::RecordAction( +@@ -479,6 +480,7 @@ void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() { + BuildOtherDevicesTabItem(session_tag, *tabs_in_session[k]); + } // for all tabs in one session + ++ BRAVE_BUILD_TABS_FROM_OTHER_DEVICES + ++num_sessions_added; + } // for all sessions + diff --git a/patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.h.patch b/patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.h.patch new file mode 100644 index 000000000000..7964e3c63a94 --- /dev/null +++ b/patches/chrome-browser-ui-toolbar-recent_tabs_sub_menu_model.h.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h +index 911131f854b202f2aa8b48377d7e287ce27c652b..46aee818d4872246cc531a78fcace8b2fa25cb15 100644 +--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h ++++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h +@@ -75,6 +75,7 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel, + bool GetURLAndTitleForItemAtIndex(int index, + std::string* url, + base::string16* title); ++ BRAVE_RECENT_TABS_SUB_MENU_MODEL_H_ + + private: + struct TabNavigationItem;