| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/omnibox/browser/clipboard_url_provider.h" | 5 #include "components/omnibox/browser/clipboard_url_provider.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/omnibox/browser/autocomplete_input.h" | 11 #include "components/omnibox/browser/autocomplete_input.h" |
| 11 #include "components/omnibox/browser/autocomplete_provider_client.h" | 12 #include "components/omnibox/browser/autocomplete_provider_client.h" |
| 13 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 12 #include "components/omnibox/browser/verbatim_match.h" | 14 #include "components/omnibox/browser/verbatim_match.h" |
| 13 #include "components/open_from_clipboard/clipboard_recent_content.h" | 15 #include "components/open_from_clipboard/clipboard_recent_content.h" |
| 14 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 15 #include "components/url_formatter/url_formatter.h" | 17 #include "components/url_formatter/url_formatter.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 17 | 19 |
| 18 ClipboardURLProvider::ClipboardURLProvider( | 20 ClipboardURLProvider::ClipboardURLProvider( |
| 19 AutocompleteProviderClient* client, | 21 AutocompleteProviderClient* client, |
| 20 HistoryURLProvider* history_url_provider, | 22 HistoryURLProvider* history_url_provider, |
| 21 ClipboardRecentContent* clipboard_content) | 23 ClipboardRecentContent* clipboard_content) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 // If the clipboard does not contain any URL, or the URL on the page is the | 42 // If the clipboard does not contain any URL, or the URL on the page is the |
| 41 // same as the URL in the clipboard, early return. | 43 // same as the URL in the clipboard, early return. |
| 42 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || | 44 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || |
| 43 url == input.current_url()) | 45 url == input.current_url()) |
| 44 return; | 46 return; |
| 45 | 47 |
| 46 DCHECK(url.is_valid()); | 48 DCHECK(url.is_valid()); |
| 47 // If the omnibox is not empty, add a default match. | 49 // If the omnibox is not empty, add a default match. |
| 48 // This match will be opened when the user presses "Enter". | 50 // This match will be opened when the user presses "Enter". |
| 49 if (!input.text().empty()) { | 51 if (!input.text().empty()) { |
| 50 AutocompleteMatch verbatim_match = VerbatimMatchForURL( | 52 const base::string16 description = |
| 51 client_, input, input.current_url(), history_url_provider_, -1); | 53 (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl)) |
| 54 ? input.current_title() |
| 55 : base::string16(); |
| 56 AutocompleteMatch verbatim_match = |
| 57 VerbatimMatchForURL(client_, input, input.current_url(), description, |
| 58 history_url_provider_, -1); |
| 52 matches_.push_back(verbatim_match); | 59 matches_.push_back(verbatim_match); |
| 53 } | 60 } |
| 54 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL", | 61 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL", |
| 55 !matches_.empty()); | 62 !matches_.empty()); |
| 56 UMA_HISTOGRAM_LONG_TIMES_100("Omnibox.ClipboardSuggestionShownAge", | 63 UMA_HISTOGRAM_LONG_TIMES_100("Omnibox.ClipboardSuggestionShownAge", |
| 57 clipboard_content_->GetClipboardContentAge()); | 64 clipboard_content_->GetClipboardContentAge()); |
| 58 | 65 |
| 59 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. | 66 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. |
| 60 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); | 67 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); |
| 61 match.destination_url = url; | 68 match.destination_url = url; |
| 62 match.contents.assign(url_formatter::FormatUrl( | 69 match.contents.assign(url_formatter::FormatUrl( |
| 63 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, | 70 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, |
| 64 nullptr, nullptr, nullptr)); | 71 nullptr, nullptr, nullptr)); |
| 65 AutocompleteMatch::ClassifyLocationInString( | 72 AutocompleteMatch::ClassifyLocationInString( |
| 66 base::string16::npos, 0, match.contents.length(), | 73 base::string16::npos, 0, match.contents.length(), |
| 67 ACMatchClassification::URL, &match.contents_class); | 74 ACMatchClassification::URL, &match.contents_class); |
| 68 | 75 |
| 69 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); | 76 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); |
| 70 AutocompleteMatch::ClassifyLocationInString( | 77 AutocompleteMatch::ClassifyLocationInString( |
| 71 base::string16::npos, 0, match.description.length(), | 78 base::string16::npos, 0, match.description.length(), |
| 72 ACMatchClassification::NONE, &match.description_class); | 79 ACMatchClassification::NONE, &match.description_class); |
| 73 | 80 |
| 74 matches_.push_back(match); | 81 matches_.push_back(match); |
| 75 } | 82 } |
| OLD | NEW |