[go: nahoru, domu]

[iOS][Omnibox] Allow text and image clipboard matches to be type search

Usually, clipboard matches contains the clipboard content in `contents` and the match description (ex: Text You Copied) in `description`.

Previously, clipboard matches that perform (Text and Image) searches where considered URL matches on iOS.
However, this is not correct and breaks some logic in the shortcuts provider.
This CL allows Text and Image clipboard matches to be considered as search matches.

Bug: 1516053
Change-Id: I26c5e10710fab6cce0af5ac8e1d152c122d715b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5237128
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: manuk hovanesian <manukh@chromium.org>
Reviewed-by: Stepan Khapugin <stkhapugin@chromium.org>
Auto-Submit: Christian Xu <christianxu@chromium.org>
Commit-Queue: Christian Xu <christianxu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1254446}
diff --git a/components/omnibox/browser/autocomplete_match.cc b/components/omnibox/browser/autocomplete_match.cc
index 2dde50f4..cdb8c1f 100644
--- a/components/omnibox/browser/autocomplete_match.cc
+++ b/components/omnibox/browser/autocomplete_match.cc
@@ -816,12 +816,8 @@
          type == AutocompleteMatchType::SEARCH_OTHER_ENGINE ||
          type == AutocompleteMatchType::CALCULATOR ||
          type == AutocompleteMatchType::VOICE_SUGGEST ||
-#if BUILDFLAG(IS_ANDROID)
-         // TODO(crbug.com/1470185): iOS tests fail if Clipboard searches are
-         //   annotated as searches.
          type == AutocompleteMatchType::CLIPBOARD_TEXT ||
          type == AutocompleteMatchType::CLIPBOARD_IMAGE ||
-#endif
          IsSpecializedSearchType(type);
 }
 
diff --git a/components/omnibox/browser/shortcuts_provider.cc b/components/omnibox/browser/shortcuts_provider.cc
index a7ea001..5c2f4b7a3 100644
--- a/components/omnibox/browser/shortcuts_provider.cc
+++ b/components/omnibox/browser/shortcuts_provider.cc
@@ -546,8 +546,6 @@
   // a fill_into_edit of "http://foo.com".
   const bool is_search_type = AutocompleteMatch::IsSearchType(match.type);
 
-// TODO(crbug.com/1470185): iOS annotates clipboard searches as URLs.
-#if !BUILDFLAG(IS_IOS)
   const bool is_starter_pack = AutocompleteMatch::IsStarterPackType(match.type);
   if (OmniboxFieldTrial::IsKeywordModeRefreshEnabled()) {
     DCHECK(!is_starter_pack);
@@ -557,7 +555,6 @@
     DCHECK(is_search_type != match.keyword.empty() || is_starter_pack)
         << "type: " << match.type << ", keyword: " << match.keyword;
   }
-#endif
 
   const bool keyword_matches =
       base::StartsWith(base::UTF16ToUTF8(input.text()),
diff --git a/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm b/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm
index a579aba..3da4e1fe 100644
--- a/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm
+++ b/ios/chrome/browser/ui/omnibox/popup/autocomplete_match_formatter.mm
@@ -186,7 +186,16 @@
     // The text should be search term (`_match.contents`) for searches,
     // otherwise page title (`_match.description`).
     std::u16string textString =
-        !self.isURL ? _match.contents : _match.description;
+        self.isURL ? _match.description : _match.contents;
+
+    // Clipboard suggestion "Text you copied" text is stored in description.
+    // The content is empty as iOS doesn't access the clipboard when creating
+    // the match.
+    if (_match.type == AutocompleteMatchType::CLIPBOARD_TEXT ||
+        _match.type == AutocompleteMatchType::CLIPBOARD_IMAGE) {
+      textString = _match.description;
+    }
+
     NSString* text = base::SysUTF16ToNSString(textString);
 
     // If for some reason the title is empty, copy the detailText.