diff --git a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc index 838f2aee16c8..0a9daa2679fd 100644 --- a/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -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 @@ -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( @@ -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 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 diff --git a/test/filters/unit_tests.filter b/test/filters/unit_tests.filter index 896a84ed9db6..87cf425ccd37 100644 --- a/test/filters/unit_tests.filter +++ b/test/filters/unit_tests.filter @@ -608,3 +608,7 @@ -WebUsbServiceImplTest.* -WellKnownChangePasswordNavigationThrottleTest.* -ZipFileInstallerTest.* + +# This test crashes because AutocompleteClassifier called when TabStripModel +# was not initialized in test. +-RenderViewContextMenuPrefsTest.ShowAllPasswordsIncognito