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

Support "Copy clean link" from context menu on webpage when URL text (not link) is highlighted #17494

Merged
merged 2 commits into from
Mar 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ bool BraveRenderViewContextMenu::IsCommandIdEnabled(int id) const {
return params_.has_image_contents;
#endif
case IDC_COPY_CLEAN_LINK:
return params_.link_url.is_valid();
return params_.link_url.is_valid() ||
GetSelectionNavigationURL(GetProfile(), params_.selection_text)
.is_valid();
case IDC_CONTENT_CONTEXT_FORCE_PASTE:
// only enable if there is plain text data to paste - this is what
// IsPasteAndMatchStyleEnabled checks internally, but IsPasteEnabled
Expand Down Expand Up @@ -237,9 +239,13 @@ void BraveRenderViewContextMenu::ExecuteIPFSCommand(int id, int event_flags) {

void BraveRenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
switch (id) {
case IDC_COPY_CLEAN_LINK:
brave::CopyLinkWithStrictCleaning(GetBrowser(), params_.link_url);
break;
case IDC_COPY_CLEAN_LINK: {
auto link_url =
params_.link_url.is_valid()
? params_.link_url
: GetSelectionNavigationURL(GetProfile(), params_.selection_text);
brave::CopyLinkWithStrictCleaning(GetBrowser(), link_url);
}; break;
case IDC_CONTENT_CONTEXT_FORCE_PASTE: {
std::u16string result;
ui::Clipboard::GetForCurrentThread()->ReadText(
Expand Down Expand Up @@ -453,7 +459,16 @@ void BraveRenderViewContextMenu::InitMenu() {
link_index.value() + 1, IDC_COPY_CLEAN_LINK, IDS_COPY_CLEAN_LINK);
}
}

if (GetSelectionNavigationURL(GetProfile(), params_.selection_text)
.is_valid()) {
absl::optional<size_t> copy_index =
menu_model_.GetIndexOfCommandId(IDC_CONTENT_CONTEXT_COPY);
if (copy_index.has_value() &&
!menu_model_.GetIndexOfCommandId(IDC_COPY_CLEAN_LINK).has_value()) {
menu_model_.InsertItemWithStringIdAt(
copy_index.value() + 1, IDC_COPY_CLEAN_LINK, IDS_COPY_CLEAN_LINK);
}
}
#if BUILDFLAG(ENABLE_IPFS)
BuildIPFSMenu();
#endif
Expand Down
4 changes: 4 additions & 0 deletions test/filters/unit_tests.filter
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,7 @@
-WebUsbServiceImplTest.*
-WellKnownChangePasswordNavigationThrottleTest.*
-ZipFileInstallerTest.*

# This test crashes because AutocompleteClassifier called when TabStripModel
# was not initialized in test.
-RenderViewContextMenuPrefsTest.ShowAllPasswordsIncognito
simonhong marked this conversation as resolved.
Show resolved Hide resolved