Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get back Tabs from other devices history section; #7121

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions browser/ui/toolbar/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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",
]
}
30 changes: 30 additions & 0 deletions browser/ui/toolbar/brave_recent_tabs_sub_menu_model.h
Original file line number Diff line number Diff line change
@@ -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_
12 changes: 12 additions & 0 deletions chromium_src/chrome/browser/ui/toolbar/app_menu_model.cc
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<sessions::SessionTab> 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_
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion patches/chrome-VERSION.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/VERSION b/chrome/VERSION
index 2c4514a701725958eed9feacc7a43c46ef1f2fba..205283ea59b247e3aa5ac69d0d81f2c05133c5b8 100644
index 2c4514a701725958eed9feacc7a43c46ef1f2fba..6d423561e1ebcc4ca78cb414346bbb09695b328f 100644
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch shouldn't be in the PR. No need to rerun CI if you remove it.

--- a/chrome/VERSION
+++ b/chrome/VERSION
@@ -1,4 +1,4 @@
Expand Down
20 changes: 0 additions & 20 deletions patches/chrome-browser-resources-history-app.html.patch

This file was deleted.

18 changes: 0 additions & 18 deletions patches/chrome-browser-resources-history-side_bar.html.patch

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/chrome/browser/resources/history/synced_device_manager.html b/chrome/browser/resources/history/synced_device_manager.html
index d03a367a7cb1ea6ccad6478a2300606b4c20829a..bfa8a2debda7e0c35b217cea85df668232c5507b 100644
--- a/chrome/browser/resources/history/synced_device_manager.html
+++ b/chrome/browser/resources/history/synced_device_manager.html
@@ -73,6 +73,7 @@
guestSession_)]]">
[[noSyncedTabsMessage(fetchingSyncedTabs_, searchTerm)]]
</div>
+<!--
<div id="sign-in-guide"
hidden="[[!showSignInGuide(signInState, guestSession_)]]">
<div id="illustration"></div>
@@ -83,6 +84,7 @@
$i18n{signInButton}
</cr-button>
</div>
+-->

<cr-lazy-render id="menu">
<template>
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.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
index 8cdfc6fbdddcb13bcd5e198cd6ebf53abfb0269d..719d296a16ae05e6d8c897af91684b4efa3527fa 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc
@@ -479,6 +479,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;
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_unittest.cc b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc
index 737e6bae0885c335ee8028704827563fc1bd2eea..1fa69f30bf2bd62f7f4aa0faf1ab0beea4ddefcd 100644
--- a/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc
@@ -675,6 +675,7 @@ TEST_F(RecentTabsSubMenuModelTest, MaxTabsPerSessionAndRecency) {

TestRecentTabsSubMenuModel model(nullptr, browser());
int num_items = model.GetItemCount();
+ BRAVE_MAX_TABS_PER_SESSION_AND_RECENCY
EXPECT_EQ(9, num_items);

std::vector<base::string16> tab_titles =
4 changes: 4 additions & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ test("brave_unit_tests") {
]
}

if (!is_android && !is_ios) {
deps += [ "//brave/browser/ui/toolbar:brave_app_menu_unit_test" ]
}

# On Windows, brave_install_static_unittests covers channel test.
if (is_mac || is_linux) {
sources += [ "//brave/common/brave_channel_info_unittest.cc" ]
Expand Down