[cr149] FindLastActiveWithProfile returning BWI
This change allows a couple of more places to be migrated to `BrowserWindowInterface`. Chromium changes: https://chromium.googlesource.com/chromium/src/+/e8d0df41d25900497716dd3a4b070c6436fa1a97 commit e8d0df41d25900497716dd3a4b070c6436fa1a97 Author: Kun Wang <kunwang@microsoft.com> Date: Wed Apr 15 23:35:39 2026 -0700 [bedrock] Migrate FindLastActiveWithProfile Step 1 Bug: 494010890 Change-Id: Ie0385deeda2e2f28baf75a810ada0becf5807c78 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7753884 Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org> Reviewed-by: Qikai Zhong <qikaizhong@microsoft.com> Commit-Queue: Kun Wang <kunwang@microsoft.com> Cr-Commit-Position: refs/heads/main@{#1615659}
This commit is contained in:
@@ -87,7 +87,7 @@ class PlaylistServiceDelegateImpl : public PlaylistService::Delegate {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* tab_model = browser->tab_strip_model();
|
||||
auto* tab_model = browser->GetTabStripModel();
|
||||
DCHECK(tab_model);
|
||||
return tab_model->GetActiveWebContents();
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace {
|
||||
|
||||
std::unique_ptr<CommandItem> CreateOpenBookmarkItem(
|
||||
const bookmarks::UrlAndTitle& bookmark,
|
||||
Browser* browser) {
|
||||
BrowserWindowInterface* browser) {
|
||||
auto item = std::make_unique<CommandItem>();
|
||||
item->title = bookmark.title;
|
||||
item->entity_type = CommandItem::Entity::kBookmark;
|
||||
@@ -46,11 +46,11 @@ std::unique_ptr<CommandItem> CreateOpenBookmarkItem(
|
||||
}
|
||||
|
||||
CommandSource::CommandResults GetMatchingBookmarks(
|
||||
Browser* browser,
|
||||
BrowserWindowInterface* browser,
|
||||
const std::u16string& input) {
|
||||
CommandSource::CommandResults results;
|
||||
bookmarks::BookmarkModel* model =
|
||||
BookmarkModelFactory::GetForBrowserContext(browser->profile());
|
||||
BookmarkModelFactory::GetForBrowserContext(browser->GetProfile());
|
||||
// This should have been checked already.
|
||||
DCHECK(model && model->loaded());
|
||||
FuzzyFinder finder(input);
|
||||
@@ -74,10 +74,10 @@ BookmarkCommandSource::~BookmarkCommandSource() = default;
|
||||
|
||||
CommandSource::CommandResults BookmarkCommandSource::GetCommands(
|
||||
const std::u16string& input,
|
||||
Browser* browser) const {
|
||||
BrowserWindowInterface* browser) const {
|
||||
CommandSource::CommandResults results;
|
||||
bookmarks::BookmarkModel* model =
|
||||
BookmarkModelFactory::GetForBrowserContext(browser->profile());
|
||||
BookmarkModelFactory::GetForBrowserContext(browser->GetProfile());
|
||||
// Just no-op instead of waiting for the model to load, since this isn't
|
||||
// a persistent UI surface and they can just try again.
|
||||
if (!model || !model->loaded() || !model->HasBookmarks()) {
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include "brave/browser/ui/commander/command_source.h"
|
||||
|
||||
class BrowserWindowInterface;
|
||||
|
||||
namespace commander {
|
||||
|
||||
// Provides an "Open Bookmark..." composite command which lets the user
|
||||
@@ -28,8 +30,9 @@ class BookmarkCommandSource : public CommandSource {
|
||||
BookmarkCommandSource& operator=(const BookmarkCommandSource& other) = delete;
|
||||
|
||||
// Command source overrides
|
||||
CommandSource::CommandResults GetCommands(const std::u16string& input,
|
||||
Browser* browser) const override;
|
||||
CommandSource::CommandResults GetCommands(
|
||||
const std::u16string& input,
|
||||
BrowserWindowInterface* browser) const override;
|
||||
};
|
||||
|
||||
} // namespace commander
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "base/functional/callback.h"
|
||||
#include "ui/gfx/range/range.h"
|
||||
|
||||
class Browser;
|
||||
class BrowserWindowInterface;
|
||||
|
||||
namespace commander {
|
||||
|
||||
@@ -40,7 +40,7 @@ class CommandSource {
|
||||
// any particular order. |browser| is the browser the active commander
|
||||
// is attached to.
|
||||
virtual CommandResults GetCommands(const std::u16string& input,
|
||||
Browser* browser) const = 0;
|
||||
BrowserWindowInterface* browser) const = 0;
|
||||
};
|
||||
|
||||
// Represents a single option that can be presented in the command palette.
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_finder.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
|
||||
#include "chrome/browser/ui/browser_window/public/global_browser_collection.h"
|
||||
#include "chrome/browser/ui/location_bar/location_bar.h"
|
||||
#include "chrome/browser/ui/omnibox/omnibox_view.h"
|
||||
@@ -191,14 +192,12 @@ void CommanderService::UpdateTextFromCurrentBrowserOmnibox() {
|
||||
|
||||
// The last active browser can have no tabs, if we're in the process of moving
|
||||
// the last tab from the current window into another one.
|
||||
if (!browser || browser->tab_strip_model()->empty()) {
|
||||
if (!browser || browser->GetTabStripModel()->empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* window = browser->window();
|
||||
CHECK(window);
|
||||
|
||||
auto text = window->GetLocationBar()->GetOmniboxView()->GetText();
|
||||
auto text =
|
||||
browser->GetFeatures().location_bar()->GetOmniboxView()->GetText();
|
||||
UpdateText(text, /*force=*/true);
|
||||
}
|
||||
|
||||
@@ -209,7 +208,7 @@ void CommanderService::UpdateText(const std::u16string& text, bool force) {
|
||||
}
|
||||
|
||||
auto has_prefix = text.starts_with(kCommandPrefix);
|
||||
if (!has_prefix && !browser->profile()->GetPrefs()->GetBoolean(
|
||||
if (!has_prefix && !browser->GetProfile()->GetPrefs()->GetBoolean(
|
||||
omnibox::kCommanderSuggestionsEnabled)) {
|
||||
return;
|
||||
}
|
||||
@@ -245,9 +244,7 @@ OmniboxView* CommanderService::GetOmnibox() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* window = browser->window();
|
||||
CHECK(window);
|
||||
return window->GetLocationBar()->GetOmniboxView();
|
||||
return browser->GetFeatures().location_bar()->GetOmniboxView();
|
||||
}
|
||||
|
||||
bool CommanderService::IsShowing() const {
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "components/keyed_service/core/keyed_service.h"
|
||||
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||
|
||||
class Browser;
|
||||
class OmniboxView;
|
||||
class Profile;
|
||||
class BrowserCollection;
|
||||
@@ -86,7 +85,7 @@ class CommanderService : public CommanderFrontendDelegate,
|
||||
std::u16string prompt_;
|
||||
std::vector<std::unique_ptr<CommandItem>> items_;
|
||||
uint32_t current_result_set_id_ = 0;
|
||||
raw_ptr<Browser, DanglingUntriaged> last_browser_;
|
||||
raw_ptr<BrowserWindowInterface, DanglingUntriaged> last_browser_;
|
||||
raw_ptr<Profile> profile_;
|
||||
|
||||
// Some commands have multiple steps (like move tab to window, pick a
|
||||
|
||||
@@ -34,21 +34,23 @@ namespace {
|
||||
double constexpr kMaxTitleWidth = 1000;
|
||||
|
||||
// TODO(crbug.com/418774949) Move to TabGroupFeatures for desktop.
|
||||
std::u16string GetContentString(const Browser* browser, const TabGroup& group) {
|
||||
std::u16string GetContentString(const BrowserWindowInterface* browser,
|
||||
const TabGroup& group) {
|
||||
constexpr size_t kContextMenuTabTitleMaxLength = 30;
|
||||
std::u16string format_string = l10n_util::GetPluralStringFUTF16(
|
||||
IDS_TAB_CXMENU_PLACEHOLDER_GROUP_TITLE, group.tab_count() - 1);
|
||||
|
||||
std::u16string short_title;
|
||||
gfx::ElideString(
|
||||
TabUIHelper::From(browser->tab_strip_model()->GetActiveTab())->GetTitle(),
|
||||
TabUIHelper::From(browser->GetTabStripModel()->GetActiveTab())
|
||||
->GetTitle(),
|
||||
kContextMenuTabTitleMaxLength, &short_title);
|
||||
return base::ReplaceStringPlaceholders(format_string, short_title, nullptr);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
WindowMatch::WindowMatch(Browser* browser,
|
||||
WindowMatch::WindowMatch(BrowserWindowInterface* browser,
|
||||
const std::u16string& title,
|
||||
double score)
|
||||
: browser(browser), title(title), score(score) {}
|
||||
@@ -94,7 +96,7 @@ std::unique_ptr<CommandItem> TabMatch::ToCommandItem() const {
|
||||
TabSearchOptions::TabSearchOptions() = default;
|
||||
TabSearchOptions::~TabSearchOptions() = default;
|
||||
|
||||
std::vector<TabMatch> TabsMatchingInput(const Browser* browser,
|
||||
std::vector<TabMatch> TabsMatchingInput(const BrowserWindowInterface* browser,
|
||||
const std::u16string& input,
|
||||
const TabSearchOptions& options) {
|
||||
DCHECK(browser);
|
||||
@@ -106,7 +108,7 @@ std::vector<TabMatch> TabsMatchingInput(const Browser* browser,
|
||||
std::vector<TabMatch> results;
|
||||
FuzzyFinder finder(input);
|
||||
std::vector<gfx::Range> ranges;
|
||||
TabStripModel* tab_strip_model = browser->tab_strip_model();
|
||||
const TabStripModel* tab_strip_model = browser->GetTabStripModel();
|
||||
for (int i = 0; i < tab_strip_model->count(); ++i) {
|
||||
if (tab_strip_model->IsTabPinned(i) ? options.only_unpinned
|
||||
: options.only_pinned) {
|
||||
@@ -147,9 +149,10 @@ std::vector<TabMatch> TabsMatchingInput(const Browser* browser,
|
||||
return results;
|
||||
}
|
||||
|
||||
std::vector<WindowMatch> WindowsMatchingInput(const Browser* browser_to_exclude,
|
||||
const std::u16string& input,
|
||||
bool match_profile) {
|
||||
std::vector<WindowMatch> WindowsMatchingInput(
|
||||
const BrowserWindowInterface* browser_to_exclude,
|
||||
const std::u16string& input,
|
||||
bool match_profile) {
|
||||
std::vector<WindowMatch> results;
|
||||
double mru_score = .95;
|
||||
FuzzyFinder finder(input);
|
||||
@@ -164,7 +167,7 @@ std::vector<WindowMatch> WindowsMatchingInput(const Browser* browser_to_exclude,
|
||||
return true; // continue iterating
|
||||
}
|
||||
if (match_profile &&
|
||||
browser->profile() != browser_to_exclude->profile()) {
|
||||
browser->profile() != browser_to_exclude->GetProfile()) {
|
||||
return true; // continue iterating
|
||||
}
|
||||
std::u16string title =
|
||||
@@ -188,14 +191,14 @@ std::vector<WindowMatch> WindowsMatchingInput(const Browser* browser_to_exclude,
|
||||
}
|
||||
|
||||
std::vector<GroupMatch> GroupsMatchingInput(
|
||||
const Browser* browser,
|
||||
const BrowserWindowInterface* browser,
|
||||
const std::u16string& input,
|
||||
std::optional<tab_groups::TabGroupId> group_to_exclude) {
|
||||
DCHECK(browser);
|
||||
std::vector<GroupMatch> results;
|
||||
FuzzyFinder finder(input);
|
||||
std::vector<gfx::Range> ranges;
|
||||
TabGroupModel* model = browser->tab_strip_model()->group_model();
|
||||
TabGroupModel* model = browser->GetTabStripModel()->group_model();
|
||||
if (!model) {
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -21,14 +21,16 @@
|
||||
#include "components/tab_groups/tab_group_id.h"
|
||||
#include "ui/gfx/range/range.h"
|
||||
|
||||
class Browser;
|
||||
class BrowserWindowInterface;
|
||||
|
||||
namespace commander {
|
||||
|
||||
// Intermediate result type for browser windows that are eligible to be
|
||||
// presented to the user as an option for a particular command.
|
||||
struct WindowMatch {
|
||||
WindowMatch(Browser* browser, const std::u16string& title, double score);
|
||||
WindowMatch(BrowserWindowInterface* browser,
|
||||
const std::u16string& title,
|
||||
double score);
|
||||
~WindowMatch();
|
||||
|
||||
WindowMatch(WindowMatch&& other);
|
||||
@@ -36,7 +38,7 @@ struct WindowMatch {
|
||||
|
||||
std::unique_ptr<CommandItem> ToCommandItem() const;
|
||||
|
||||
raw_ptr<Browser> browser;
|
||||
raw_ptr<BrowserWindowInterface> browser;
|
||||
std::u16string title;
|
||||
std::vector<gfx::Range> matched_ranges;
|
||||
double score;
|
||||
@@ -88,15 +90,16 @@ struct TabMatch {
|
||||
// returns all eligible browser windows with score reflecting MRU order.
|
||||
// `browser_to_exclude` is excluded from the list, as are all browser windows
|
||||
// from a different profile unless `match_profile` is false.
|
||||
std::vector<WindowMatch> WindowsMatchingInput(const Browser* browser_to_exclude,
|
||||
const std::u16string& input,
|
||||
bool match_profile = false);
|
||||
std::vector<WindowMatch> WindowsMatchingInput(
|
||||
const BrowserWindowInterface* browser_to_exclude,
|
||||
const std::u16string& input,
|
||||
bool match_profile = false);
|
||||
|
||||
// Returns tab groups in `browser` whose titles fuzzy match `input`. If input is
|
||||
// empty, returns all groups in an arbitrary order. If `group_to_exclude` is
|
||||
// set, it is excluded from the list.
|
||||
std::vector<GroupMatch> GroupsMatchingInput(
|
||||
const Browser* browser,
|
||||
const BrowserWindowInterface* browser,
|
||||
const std::u16string& input,
|
||||
std::optional<tab_groups::TabGroupId> group_to_exclude = std::nullopt);
|
||||
|
||||
@@ -122,7 +125,7 @@ struct TabSearchOptions {
|
||||
|
||||
// Returns tabs in `browser` whose titles fuzzy match `input`. If input is
|
||||
// empty, returns all groups in the order they appear in the tab strip.
|
||||
std::vector<TabMatch> TabsMatchingInput(const Browser* browser,
|
||||
std::vector<TabMatch> TabsMatchingInput(const BrowserWindowInterface* browser,
|
||||
const std::u16string& input,
|
||||
const TabSearchOptions& options = {});
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ OpenURLCommandSource::~OpenURLCommandSource() = default;
|
||||
|
||||
CommandSource::CommandResults OpenURLCommandSource::GetCommands(
|
||||
const std::u16string& input,
|
||||
Browser* browser) const {
|
||||
BrowserWindowInterface* browser) const {
|
||||
CommandSource::CommandResults results;
|
||||
std::vector<gfx::Range> ranges;
|
||||
FuzzyFinder finder(input);
|
||||
|
||||
@@ -30,8 +30,9 @@ class OpenURLCommandSource : public CommandSource {
|
||||
OpenURLCommandSource& operator=(const OpenURLCommandSource& other) = delete;
|
||||
|
||||
// CommandSource overrides
|
||||
CommandSource::CommandResults GetCommands(const std::u16string& input,
|
||||
Browser* browser) const override;
|
||||
CommandSource::CommandResults GetCommands(
|
||||
const std::u16string& input,
|
||||
BrowserWindowInterface* browser) const override;
|
||||
|
||||
private:
|
||||
const std::vector<std::pair<std::u16string, GURL>> title_url_map_;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "chrome/browser/ui/accelerator_utils.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_commands.h"
|
||||
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
|
||||
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
|
||||
#include "ui/base/accelerators/accelerator.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_AI_CHAT)
|
||||
@@ -33,12 +35,13 @@ namespace commander {
|
||||
|
||||
namespace {
|
||||
|
||||
void MaybeReportCommandExecution(Browser* browser, int command_id) {
|
||||
void MaybeReportCommandExecution(BrowserWindowInterface* browser,
|
||||
int command_id) {
|
||||
#if BUILDFLAG(ENABLE_AI_CHAT)
|
||||
if (command_id == IDC_TOGGLE_AI_CHAT) {
|
||||
auto* profile_metrics =
|
||||
misc_metrics::ProfileMiscMetricsServiceFactory::GetServiceForContext(
|
||||
browser->profile());
|
||||
browser->GetProfile());
|
||||
if (!profile_metrics) {
|
||||
return;
|
||||
}
|
||||
@@ -59,9 +62,9 @@ SimpleCommandSource::~SimpleCommandSource() = default;
|
||||
|
||||
CommandSource::CommandResults SimpleCommandSource::GetCommands(
|
||||
const std::u16string& input,
|
||||
Browser* browser) const {
|
||||
BrowserWindowInterface* browser) const {
|
||||
CommandSource::CommandResults results;
|
||||
if (!browser || !browser->command_controller()) {
|
||||
if (!browser || !browser->GetFeatures().browser_command_controller()) {
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -84,13 +87,14 @@ CommandSource::CommandResults SimpleCommandSource::GetCommands(
|
||||
|
||||
auto item = std::make_unique<CommandItem>(name, score, ranges);
|
||||
ui::Accelerator accelerator;
|
||||
ui::AcceleratorProvider* provider = AcceleratorProviderForBrowser(browser);
|
||||
ui::AcceleratorProvider* provider =
|
||||
AcceleratorProviderForBrowser(browser->GetBrowserForMigrationOnly());
|
||||
if (provider->GetAcceleratorForCommandId(command_id, &accelerator)) {
|
||||
item->annotation = accelerator.GetShortcutText();
|
||||
}
|
||||
|
||||
item->command = base::BindOnce(
|
||||
[](Browser* browser, int command_id) {
|
||||
[](BrowserWindowInterface* browser, int command_id) {
|
||||
MaybeReportCommandExecution(browser, command_id);
|
||||
chrome::ExecuteCommand(browser, command_id);
|
||||
},
|
||||
|
||||
@@ -19,8 +19,9 @@ class SimpleCommandSource : public CommandSource {
|
||||
SimpleCommandSource& operator=(const SimpleCommandSource& other) = delete;
|
||||
|
||||
// CommandSource:
|
||||
CommandSource::CommandResults GetCommands(const std::u16string& input,
|
||||
Browser* browser) const override;
|
||||
CommandSource::CommandResults GetCommands(
|
||||
const std::u16string& input,
|
||||
BrowserWindowInterface* browser) const override;
|
||||
};
|
||||
|
||||
} // namespace commander
|
||||
|
||||
@@ -77,17 +77,18 @@ std::optional<tab_groups::TabGroupId> IneligibleGroupForSelected(
|
||||
|
||||
// Returns true only if `browser` is alive, and the contents at `index` match
|
||||
// `tab_session_id`.
|
||||
bool DoesTabAtIndexMatchSessionId(base::WeakPtr<Browser> browser,
|
||||
bool DoesTabAtIndexMatchSessionId(base::WeakPtr<BrowserWindowInterface> browser,
|
||||
int index,
|
||||
int tab_session_id) {
|
||||
if (!browser.get()) {
|
||||
return false;
|
||||
}
|
||||
if (browser->tab_strip_model()->count() <= index) {
|
||||
|
||||
auto* tab_strip_model = browser->GetTabStripModel();
|
||||
if (tab_strip_model->count() <= index) {
|
||||
return false;
|
||||
}
|
||||
content::WebContents* contents =
|
||||
browser->tab_strip_model()->GetWebContentsAt(index);
|
||||
content::WebContents* contents = tab_strip_model->GetWebContentsAt(index);
|
||||
DCHECK(contents);
|
||||
return sessions::SessionTabHelper::IdForTab(contents).id() == tab_session_id;
|
||||
}
|
||||
@@ -102,25 +103,26 @@ bool HasPinnedTabs(const TabStripModel* model) {
|
||||
return model->IndexOfFirstNonPinnedTab() > 0;
|
||||
}
|
||||
|
||||
bool CanMoveTabsToExistingWindow(const Browser* browser_to_exclude) {
|
||||
bool CanMoveTabsToExistingWindow(
|
||||
const BrowserWindowInterface* browser_to_exclude) {
|
||||
bool has_found = false;
|
||||
GlobalBrowserCollection::GetInstance()->ForEach(
|
||||
[browser_to_exclude, &has_found](BrowserWindowInterface* browser) {
|
||||
has_found = browser != browser_to_exclude &&
|
||||
browser->GetType() == BrowserWindowInterface::TYPE_NORMAL &&
|
||||
browser->GetProfile() == browser_to_exclude->profile();
|
||||
browser->GetProfile() == browser_to_exclude->GetProfile();
|
||||
return !has_found;
|
||||
});
|
||||
return has_found;
|
||||
}
|
||||
|
||||
void MoveTabsToExistingWindow(base::WeakPtr<Browser> source,
|
||||
base::WeakPtr<Browser> target) {
|
||||
void MoveTabsToExistingWindow(base::WeakPtr<BrowserWindowInterface> source,
|
||||
base::WeakPtr<BrowserWindowInterface> target) {
|
||||
if (!source.get() || !target.get()) {
|
||||
return;
|
||||
}
|
||||
const ui::ListSelectionModel::SelectedIndices& sel =
|
||||
source->tab_strip_model()
|
||||
source->GetTabStripModel()
|
||||
->selection_model()
|
||||
.GetListSelectionModel()
|
||||
.selected_indices();
|
||||
@@ -128,8 +130,8 @@ void MoveTabsToExistingWindow(base::WeakPtr<Browser> source,
|
||||
std::vector<int>(sel.begin(), sel.end()));
|
||||
}
|
||||
|
||||
void AddSelectedToNewGroup(Browser* browser) {
|
||||
TabStripModel* model = browser->tab_strip_model();
|
||||
void AddSelectedToNewGroup(BrowserWindowInterface* browser) {
|
||||
TabStripModel* model = browser->GetTabStripModel();
|
||||
const ui::ListSelectionModel::SelectedIndices& sel =
|
||||
model->selection_model().GetListSelectionModel().selected_indices();
|
||||
model->AddToNewGroup(std::vector<int>(sel.begin(), sel.end()));
|
||||
@@ -137,27 +139,27 @@ void AddSelectedToNewGroup(Browser* browser) {
|
||||
|
||||
// Multiphase commands:
|
||||
|
||||
void TogglePinTab(base::WeakPtr<Browser> browser,
|
||||
void TogglePinTab(base::WeakPtr<BrowserWindowInterface> browser,
|
||||
int tab_index,
|
||||
int tab_session_id,
|
||||
bool pin) {
|
||||
if (!DoesTabAtIndexMatchSessionId(browser, tab_index, tab_session_id)) {
|
||||
return;
|
||||
}
|
||||
browser->tab_strip_model()->SetTabPinned(tab_index, pin);
|
||||
browser->GetTabStripModel()->SetTabPinned(tab_index, pin);
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandItem> CreatePinTabItem(const TabMatch& match,
|
||||
Browser* browser,
|
||||
BrowserWindowInterface* browser,
|
||||
bool pin) {
|
||||
auto item = match.ToCommandItem();
|
||||
item->command = base::BindOnce(&TogglePinTab, browser->AsWeakPtr(),
|
||||
item->command = base::BindOnce(&TogglePinTab, browser->GetWeakPtr(),
|
||||
match.index, match.session_id, pin);
|
||||
return item;
|
||||
}
|
||||
|
||||
CommandSource::CommandResults TogglePinTabCommandsForTabsMatching(
|
||||
Browser* browser,
|
||||
BrowserWindowInterface* browser,
|
||||
bool pin,
|
||||
const std::u16string& input) {
|
||||
CommandSource::CommandResults results;
|
||||
@@ -174,16 +176,17 @@ CommandSource::CommandResults TogglePinTabCommandsForTabsMatching(
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandItem> CreateMoveTabsToWindowItem(
|
||||
Browser* source,
|
||||
BrowserWindowInterface* source,
|
||||
const WindowMatch& match) {
|
||||
auto item = match.ToCommandItem();
|
||||
item->command = base::BindOnce(&MoveTabsToExistingWindow, source->AsWeakPtr(),
|
||||
match.browser->AsWeakPtr());
|
||||
item->command =
|
||||
base::BindOnce(&MoveTabsToExistingWindow, source->GetWeakPtr(),
|
||||
match.browser->GetWeakPtr());
|
||||
return item;
|
||||
}
|
||||
|
||||
CommandSource::CommandResults MoveTabsToWindowCommandsForWindowsMatching(
|
||||
Browser* source,
|
||||
BrowserWindowInterface* source,
|
||||
const std::u16string& input) {
|
||||
CommandSource::CommandResults results;
|
||||
// Add "New Window", if appropriate. It should score highest with no input.
|
||||
@@ -210,25 +213,25 @@ CommandSource::CommandResults MoveTabsToWindowCommandsForWindowsMatching(
|
||||
return results;
|
||||
}
|
||||
|
||||
void AddTabsToGroup(base::WeakPtr<Browser> browser,
|
||||
void AddTabsToGroup(base::WeakPtr<BrowserWindowInterface> browser,
|
||||
tab_groups::TabGroupId group) {
|
||||
if (!browser.get()) {
|
||||
return;
|
||||
}
|
||||
const ui::ListSelectionModel::SelectedIndices& sel =
|
||||
browser->tab_strip_model()
|
||||
browser->GetTabStripModel()
|
||||
->selection_model()
|
||||
.GetListSelectionModel()
|
||||
.selected_indices();
|
||||
browser->tab_strip_model()->AddToExistingGroup(
|
||||
browser->GetTabStripModel()->AddToExistingGroup(
|
||||
std::vector<int>(sel.begin(), sel.end()), group);
|
||||
}
|
||||
|
||||
CommandSource::CommandResults AddTabsToGroupCommandsForGroupsMatching(
|
||||
Browser* browser,
|
||||
BrowserWindowInterface* browser,
|
||||
const std::u16string& input) {
|
||||
CommandSource::CommandResults results;
|
||||
TabStripModel* tab_strip_model = browser->tab_strip_model();
|
||||
TabStripModel* tab_strip_model = browser->GetTabStripModel();
|
||||
// Add "New Group", if appropriate. It should score highest with no input.
|
||||
std::u16string new_group_title =
|
||||
l10n_util::GetStringUTF16(IDS_TAB_CXMENU_SUBMENU_NEW_GROUP);
|
||||
@@ -251,7 +254,7 @@ CommandSource::CommandResults AddTabsToGroupCommandsForGroupsMatching(
|
||||
browser, input, IneligibleGroupForSelected(tab_strip_model))) {
|
||||
auto command_item = match.ToCommandItem();
|
||||
command_item->command =
|
||||
base::BindOnce(&AddTabsToGroup, browser->AsWeakPtr(), match.group);
|
||||
base::BindOnce(&AddTabsToGroup, browser->GetWeakPtr(), match.group);
|
||||
results.push_back(std::move(command_item));
|
||||
}
|
||||
return results;
|
||||
@@ -264,12 +267,12 @@ TabCommandSource::~TabCommandSource() = default;
|
||||
|
||||
CommandSource::CommandResults TabCommandSource::GetCommands(
|
||||
const std::u16string& input,
|
||||
Browser* browser) const {
|
||||
BrowserWindowInterface* browser) const {
|
||||
CommandSource::CommandResults results;
|
||||
FuzzyFinder finder(input);
|
||||
std::vector<gfx::Range> ranges;
|
||||
|
||||
TabStripModel* tab_strip_model = browser->tab_strip_model();
|
||||
TabStripModel* tab_strip_model = browser->GetTabStripModel();
|
||||
|
||||
if (CanMoveTabsToExistingWindow(browser)) {
|
||||
auto text = l10n_util::GetStringUTF16(IDS_COMMANDER_MOVE_TABS_TO_WINDOW);
|
||||
|
||||
@@ -25,8 +25,9 @@ class TabCommandSource : public CommandSource {
|
||||
TabCommandSource& operator=(const TabCommandSource& other) = delete;
|
||||
|
||||
// Command source overrides
|
||||
CommandSource::CommandResults GetCommands(const std::u16string& input,
|
||||
Browser* browser) const override;
|
||||
CommandSource::CommandResults GetCommands(
|
||||
const std::u16string& input,
|
||||
BrowserWindowInterface* browser) const override;
|
||||
};
|
||||
} // namespace commander
|
||||
|
||||
|
||||
@@ -29,19 +29,19 @@ namespace commander {
|
||||
namespace {
|
||||
|
||||
// Activates `browser` if it's still present.
|
||||
void SwitchToBrowser(base::WeakPtr<Browser> browser) {
|
||||
void SwitchToBrowser(base::WeakPtr<BrowserWindowInterface> browser) {
|
||||
if (browser.get()) {
|
||||
browser->window()->Show();
|
||||
browser->GetBrowserForMigrationOnly()->window()->Show();
|
||||
}
|
||||
}
|
||||
|
||||
// Merges all tabs from `source` into `target`, if they are both present.
|
||||
void MergeBrowsers(base::WeakPtr<Browser> source,
|
||||
base::WeakPtr<Browser> target) {
|
||||
void MergeBrowsers(base::WeakPtr<BrowserWindowInterface> source,
|
||||
base::WeakPtr<BrowserWindowInterface> target) {
|
||||
if (!source.get() || !target.get()) {
|
||||
return;
|
||||
}
|
||||
size_t source_count = source->tab_strip_model()->count();
|
||||
size_t source_count = source->GetTabStripModel()->count();
|
||||
std::vector<int> indices(source_count);
|
||||
std::iota(indices.begin(), indices.end(), 0);
|
||||
chrome::MoveTabsToExistingWindow(source.get(), target.get(), indices);
|
||||
@@ -54,20 +54,21 @@ void MergeBrowsers(base::WeakPtr<Browser> source,
|
||||
|
||||
std::unique_ptr<CommandItem> CreateSwitchWindowItem(const WindowMatch& match) {
|
||||
auto item = match.ToCommandItem();
|
||||
item->command = base::BindOnce(&SwitchToBrowser, match.browser->AsWeakPtr());
|
||||
item->command = base::BindOnce(&SwitchToBrowser, match.browser->GetWeakPtr());
|
||||
return item;
|
||||
}
|
||||
|
||||
std::unique_ptr<CommandItem> CreateMergeWindowItem(Browser* source,
|
||||
const WindowMatch& target) {
|
||||
std::unique_ptr<CommandItem> CreateMergeWindowItem(
|
||||
BrowserWindowInterface* source,
|
||||
const WindowMatch& target) {
|
||||
auto item = target.ToCommandItem();
|
||||
item->command = base::BindOnce(&MergeBrowsers, source->AsWeakPtr(),
|
||||
target.browser->AsWeakPtr());
|
||||
item->command = base::BindOnce(&MergeBrowsers, source->GetWeakPtr(),
|
||||
target.browser->GetWeakPtr());
|
||||
return item;
|
||||
}
|
||||
|
||||
CommandSource::CommandResults SwitchCommandsForWindowsMatching(
|
||||
Browser* browser_to_exclude,
|
||||
BrowserWindowInterface* browser_to_exclude,
|
||||
const std::u16string& input) {
|
||||
CommandSource::CommandResults results;
|
||||
for (auto& match : WindowsMatchingInput(browser_to_exclude, input)) {
|
||||
@@ -77,7 +78,7 @@ CommandSource::CommandResults SwitchCommandsForWindowsMatching(
|
||||
}
|
||||
|
||||
CommandSource::CommandResults MergeCommandsForWindowsMatching(
|
||||
Browser* source_browser,
|
||||
BrowserWindowInterface* source_browser,
|
||||
const std::u16string& input) {
|
||||
CommandSource::CommandResults results;
|
||||
for (auto& match : WindowsMatchingInput(source_browser, input, true)) {
|
||||
@@ -93,7 +94,7 @@ WindowCommandSource::~WindowCommandSource() = default;
|
||||
|
||||
CommandSource::CommandResults WindowCommandSource::GetCommands(
|
||||
const std::u16string& input,
|
||||
Browser* browser) const {
|
||||
BrowserWindowInterface* browser) const {
|
||||
CommandSource::CommandResults results;
|
||||
if (GlobalBrowserCollection::GetInstance()->GetSize() < 2) {
|
||||
return results;
|
||||
@@ -114,7 +115,8 @@ CommandSource::CommandResults WindowCommandSource::GetCommands(
|
||||
results.push_back(std::move(verb));
|
||||
}
|
||||
score = finder.Find(merge_title, ranges);
|
||||
if (score > 0 && !browser->is_type_devtools()) {
|
||||
if (score > 0 &&
|
||||
browser->GetType() != BrowserWindowInterface::Type::TYPE_DEVTOOLS) {
|
||||
auto verb = std::make_unique<CommandItem>(merge_title, score, ranges);
|
||||
verb->command = std::make_pair(
|
||||
merge_title, base::BindRepeating(&MergeCommandsForWindowsMatching,
|
||||
|
||||
@@ -25,8 +25,9 @@ class WindowCommandSource : public CommandSource {
|
||||
WindowCommandSource& operator=(const WindowCommandSource& other) = delete;
|
||||
|
||||
// Command source overrides
|
||||
CommandSource::CommandResults GetCommands(const std::u16string& input,
|
||||
Browser* browser) const override;
|
||||
CommandSource::CommandResults GetCommands(
|
||||
const std::u16string& input,
|
||||
BrowserWindowInterface* browser) const override;
|
||||
};
|
||||
} // namespace commander
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ class RewardsPageBubbleDelegate : public RewardsPageHandler::BubbleDelegate {
|
||||
|
||||
std::string GetPublisherIdForActiveTab() override {
|
||||
if (auto* browser = chrome::FindLastActiveWithProfile(profile_.get())) {
|
||||
if (auto* contents = browser->tab_strip_model()->GetActiveWebContents()) {
|
||||
if (auto* contents =
|
||||
browser->GetTabStripModel()->GetActiveWebContents()) {
|
||||
if (auto* tab_helper = RewardsTabHelper::FromWebContents(contents)) {
|
||||
return tab_helper->GetPublisherIdForTab();
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@ bool ShouldOpenSingletonTab(brave_vpn::mojom::ManageURLType type) {
|
||||
type == brave_vpn::mojom::ManageURLType::ABOUT;
|
||||
}
|
||||
|
||||
void ShowSingletonVPNTab(Browser* browser, const GURL& url) {
|
||||
for (auto i = 0; i < browser->tab_strip_model()->count(); i++) {
|
||||
auto* web_contents = browser->tab_strip_model()->GetWebContentsAt(i);
|
||||
void ShowSingletonVPNTab(BrowserWindowInterface* browser, const GURL& url) {
|
||||
for (auto i = 0; i < browser->GetTabStripModel()->count(); i++) {
|
||||
auto* web_contents = browser->GetTabStripModel()->GetWebContentsAt(i);
|
||||
const GURL& contents_url = web_contents->GetVisibleURL();
|
||||
bool is_equal = contents_url.SchemeIs(url.scheme()) &&
|
||||
contents_url.DomainIs(url.host()) &&
|
||||
contents_url.path() == url.path();
|
||||
if (is_equal) {
|
||||
browser->tab_strip_model()->ActivateTabAt(i);
|
||||
browser->GetTabStripModel()->ActivateTabAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser_finder.h"
|
||||
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
|
||||
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
|
||||
#include "chrome/browser/ui/webui/theme_source.h"
|
||||
#include "components/grit/brave_components_resources.h"
|
||||
@@ -37,7 +38,9 @@ SpeedreaderToolbarUI::SpeedreaderToolbarUI(content::WebUI* web_ui)
|
||||
->SetZoomLevelForHostAndScheme(content::kChromeUIScheme,
|
||||
kSpeedreaderPanelHost, 0);
|
||||
|
||||
browser_ = chrome::FindLastActiveWithProfile(profile_);
|
||||
if (auto* bwi = chrome::FindLastActiveWithProfile(profile_)) {
|
||||
browser_ = bwi->GetBrowserForMigrationOnly();
|
||||
}
|
||||
|
||||
content::WebUIDataSource* source = CreateAndAddWebUIDataSource(
|
||||
web_ui, kSpeedreaderPanelHost, kBraveSpeedreaderToolbarGenerated,
|
||||
|
||||
Reference in New Issue
Block a user