diff --git a/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc index 2dba5471640f..c2c2d6650fea 100644 --- a/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -10,6 +10,6 @@ trailing_decorations.AddDecoration(0, height(), false, 0, 0, right_most); #define ChromeOmniboxClient BraveOmniboxClientImpl -#include "../../../../../../../chrome/browser/ui/views/location_bar/location_bar_view.cc" // NOLINT +#include "../../../../../../../chrome/browser/ui/views/location_bar/location_bar_view.cc" #undef ChromeOmniboxClient #undef BRAVE_LAYOUT_TRAILING_DECORATIONS diff --git a/chromium_src/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chromium_src/chrome/browser/ui/views/omnibox/omnibox_view_views.cc deleted file mode 100644 index 9f80afa54b00..000000000000 --- a/chromium_src/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* 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_location_bar_model_delegate.h" -#include "brave/common/url_constants.h" -#include "content/public/common/url_constants.h" -#include "ui/base/clipboard/scoped_clipboard_writer.h" -#include "url/gurl.h" - -namespace { - -bool ShouldAdjust(const base::string16& original, - const base::string16& adjusted) { - // Only adjust scheme is changed from brave to chrome. - if (GURL(original).scheme() == kBraveUIScheme && - GURL(adjusted).scheme() == content::kChromeUIScheme) { - return true; - } - - return false; -} - -void ReplaceChromeSchemeToBrave(GURL* url) { - DCHECK_EQ(content::kChromeUIScheme, url->scheme()); - GURL::Replacements replacements; - replacements.SetSchemeStr(kBraveUIScheme); - *url = url->ReplaceComponents(replacements); -} - -} // namespace - -#define HANDLE_CHROME_SCHEME_URL \ - base::string16 original_selected_text; \ - cb->ReadText(clipboard_buffer, &original_selected_text); \ - if (ShouldAdjust(original_selected_text, selected_text)) { \ - BraveLocationBarModelDelegate::FormattedStringFromURL(url, \ - &selected_text); \ - ReplaceChromeSchemeToBrave(&url); \ - } - -#include "../../../../../../../chrome/browser/ui/views/omnibox/omnibox_view_views.cc" // NOLINT - -#undef HANDLE_CHROME_SCHEME_URL diff --git a/chromium_src/components/omnibox/browser/omnibox_edit_model.cc b/chromium_src/components/omnibox/browser/omnibox_edit_model.cc index 5e84f0d58e5b..88b1af3dd688 100644 --- a/chromium_src/components/omnibox/browser/omnibox_edit_model.cc +++ b/chromium_src/components/omnibox/browser/omnibox_edit_model.cc @@ -6,6 +6,11 @@ #include "brave/components/omnibox/browser/brave_omnibox_client.h" #include "components/omnibox/browser/omnibox_client.h" #include "components/omnibox/browser/omnibox_controller.h" +#include "url/gurl.h" + +#if !defined(OS_IOS) +#include "content/public/common/url_constants.h" +#endif class BraveOmniboxController : public OmniboxController { public: @@ -29,6 +34,23 @@ class BraveOmniboxController : public OmniboxController { DISALLOW_COPY_AND_ASSIGN(BraveOmniboxController); }; +namespace { +void BraveAdjustTextForCopy(GURL* url) { +#if !defined(OS_IOS) + if (url->scheme() == content::kChromeUIScheme) { + GURL::Replacements replacements; + replacements.SetSchemeStr(content::kBraveUIScheme); + *url = url->ReplaceComponents(replacements); + } +#endif +} + +} // namespace + +#define BRAVE_ADJUST_TEXT_FOR_COPY \ + BraveAdjustTextForCopy(url_from_text); + #define OmniboxController BraveOmniboxController #include "../../../../../components/omnibox/browser/omnibox_edit_model.cc" // NOLINT #undef OmniboxController +#undef BRAVE_ADJUST_TEXT_FOR_COPY diff --git a/components/omnibox/browser/BUILD.gn b/components/omnibox/browser/BUILD.gn index 85ae4b5246b3..50545aade4f3 100644 --- a/components/omnibox/browser/BUILD.gn +++ b/components/omnibox/browser/BUILD.gn @@ -22,5 +22,12 @@ source_set("browser") { "//skia", "//third_party/icu", "//third_party/metrics_proto", + "//url", ] + +if (!is_ios) { + deps += [ + "//content/public/common", + ] +} } diff --git a/patches/chrome-browser-ui-views-omnibox-omnibox_view_views.cc.patch b/patches/chrome-browser-ui-views-omnibox-omnibox_view_views.cc.patch deleted file mode 100644 index 54cb4948f4db..000000000000 --- a/patches/chrome-browser-ui-views-omnibox-omnibox_view_views.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc -index c4ddfc6ca822d1eb95ef7411d1c87846f1561be2..8418bc47de957d1bbdc3f9a1ccf7c4fe1e662020 100644 ---- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc -+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc -@@ -1762,6 +1762,7 @@ void OmniboxViewViews::OnAfterCutOrCopy(ui::ClipboardBuffer clipboard_buffer) { - if (IsSelectAll()) - UMA_HISTOGRAM_COUNTS_1M(OmniboxEditModel::kCutOrCopyAllTextHistogram, 1); - -+ HANDLE_CHROME_SCHEME_URL - ui::ScopedClipboardWriter scoped_clipboard_writer(clipboard_buffer); - scoped_clipboard_writer.WriteText(selected_text); - diff --git a/patches/components-omnibox-browser-omnibox_edit_model.cc.patch b/patches/components-omnibox-browser-omnibox_edit_model.cc.patch new file mode 100644 index 000000000000..4960254d5ba5 --- /dev/null +++ b/patches/components-omnibox-browser-omnibox_edit_model.cc.patch @@ -0,0 +1,12 @@ +diff --git a/components/omnibox/browser/omnibox_edit_model.cc b/components/omnibox/browser/omnibox_edit_model.cc +index 3cfedd66eff30f1966c10fdb6a8b62961a61a8bb..ba76ebe4d5aa54f65db3b157884e5a4c6d9e7c78 100644 +--- a/components/omnibox/browser/omnibox_edit_model.cc ++++ b/components/omnibox/browser/omnibox_edit_model.cc +@@ -384,6 +384,7 @@ void OmniboxEditModel::AdjustTextForCopy(int sel_min, + (*text == display_text_ || *text == url_for_editing_)) { + *url_from_text = controller()->GetLocationBarModel()->GetURL(); + *write_url = true; ++ BRAVE_ADJUST_TEXT_FOR_COPY + + // If the omnibox is displaying a URL, set the hyperlink text to the URL's + // spec. This undoes any URL elisions.