Skip to content

Commit

Permalink
#17254 Cannot copy autocompleted url on macos uplift to 1.49.x (#17435)
Browse files Browse the repository at this point in the history
Copy url from omnibox instead of webcontent (#17254)
  • Loading branch information
spylogsster authored Mar 2, 2023
1 parent 4b2b9b9 commit 431d506
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion browser/brave_app_controller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
- (void)executeCommand:(id)sender withProfile:(Profile*)profile {
NSInteger tag = [sender tag];
if (tag == IDC_COPY_CLEAN_LINK) {
chrome::ExecuteCommand([self getBrowser], IDC_COPY_CLEAN_LINK);
brave::CleanAndCopySelectedURL([self getBrowser]);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions browser/ui/brave_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ sidebar::Sidebar* BraveBrowserWindow::InitSidebar() {
bool BraveBrowserWindow::HasSelectedURL() const {
return false;
}
void BraveBrowserWindow::CleanAndCopySelectedURL() {}

#endif
1 change: 1 addition & 0 deletions browser/ui/brave_browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BraveBrowserWindow : public BrowserWindow {
#if defined(TOOLKIT_VIEWS)
virtual sidebar::Sidebar* InitSidebar();
virtual bool HasSelectedURL() const;
virtual void CleanAndCopySelectedURL();
#endif

virtual void ShowBraveVPNBubble() {}
Expand Down
9 changes: 9 additions & 0 deletions browser/ui/browser_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,13 @@ bool HasSelectedURL(Browser* browser) {
return brave_browser_window && brave_browser_window->HasSelectedURL();
}

void CleanAndCopySelectedURL(Browser* browser) {
if (!browser) {
return;
}
auto* brave_browser_window = BraveBrowserWindow::From(browser->window());
if (brave_browser_window) {
brave_browser_window->CleanAndCopySelectedURL();
}
}
} // namespace brave
1 change: 1 addition & 0 deletions browser/ui/browser_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GURL;

namespace brave {
bool HasSelectedURL(Browser* browser);
void CleanAndCopySelectedURL(Browser* browser);
void NewOffTheRecordWindowTor(Browser*);
void NewTorConnectionForSite(Browser*);
void AddNewProfile();
Expand Down
12 changes: 12 additions & 0 deletions browser/ui/views/frame/brave_browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ bool BraveBrowserView::HasSelectedURL() const {
return brave_omnibox_view && brave_omnibox_view->SelectedTextIsURL();
}

void BraveBrowserView::CleanAndCopySelectedURL() {
if (!GetLocationBarView()) {
return;
}
auto* brave_omnibox_view =
static_cast<BraveOmniboxViewViews*>(GetLocationBarView()->omnibox_view());
if (!brave_omnibox_view) {
return;
}
brave_omnibox_view->CleanAndCopySelectedURL();
}

WalletButton* BraveBrowserView::GetWalletButton() {
return static_cast<BraveToolbarView*>(toolbar())->wallet_button();
}
Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/frame/brave_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class BraveBrowserView : public BrowserView {

sidebar::Sidebar* InitSidebar() override;
bool HasSelectedURL() const override;
void CleanAndCopySelectedURL() override;
void UpdateSideBarHorizontalAlignment();

bool closing_confirm_dialog_activated_ = false;
Expand Down
8 changes: 8 additions & 0 deletions browser/ui/views/omnibox/brave_omnibox_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ bool BraveOmniboxViewViews::SelectedTextIsURL() {
return GetURLToCopy().has_value();
}

void BraveOmniboxViewViews::CleanAndCopySelectedURL() {
auto url_to_copy = GetURLToCopy();
if (!url_to_copy.has_value()) {
return;
}
CopySanitizedURL(url_to_copy.value());
}

void BraveOmniboxViewViews::CopySanitizedURL(const GURL& url) {
OnBeforePossibleChange();
brave::CopySanitizedURL(chrome::FindLastActive(), url);
Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/omnibox/brave_omnibox_view_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BraveOmniboxViewViews : public OmniboxViewViews {
~BraveOmniboxViewViews() override;

bool SelectedTextIsURL();
void CleanAndCopySelectedURL();

protected:
absl::optional<GURL> GetURLToCopy();
Expand Down

0 comments on commit 431d506

Please sign in to comment.