Skip to content

Commit

Permalink
History sub menu item for all tabs from other synced devices
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Nov 17, 2020
1 parent 8e1e204 commit 8b7ffec
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<message name="IDS_OPEN_GUEST_PROFILE" desc="The app menu item to create a new User Profile">
Open Guest Window
</message>
<message name="IDS_OPEN_MORE_OTHER_DEVICES_SESSIONS" desc="The history sub-menu item to show sessions from other devices">
More...
</message>
<message name="IDS_EXTENSION_CANT_INSTALL_ON_BRAVE" desc="Error message when user tries to install an extension that is not allowed in Brave.">
<ph name="EXTENSION_NAME">$1</ph> (extension ID "<ph name="EXTENSION_ID">$2<ex>abacabadabacabaeabacabadabacabaf</ex></ph>") is not allowed in Brave.
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<sessions::SessionTab> 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_
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 8b7ffec

Please sign in to comment.