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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/omnibox/browser/autocomplete_input.h" | 10 #include "components/omnibox/browser/autocomplete_input.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 // If the clipboard does not contain any URL, or the URL on the page is the | 40 // 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. | 41 // same as the URL in the clipboard, early return. |
42 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || | 42 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || |
43 url == input.current_url()) | 43 url == input.current_url()) |
44 return; | 44 return; |
45 | 45 |
46 DCHECK(url.is_valid()); | 46 DCHECK(url.is_valid()); |
47 // If the omnibox is not empty, add a default match. | 47 // If the omnibox is not empty, add a default match. |
48 // This match will be opened when the user presses "Enter". | 48 // This match will be opened when the user presses "Enter". |
49 if (!input.text().empty()) { | 49 if (!input.text().empty()) { |
50 AutocompleteMatch verbatim_match = VerbatimMatchForURL( | 50 AutocompleteMatch verbatim_match = |
51 client_, input, input.current_url(), history_url_provider_, -1); | 51 VerbatimMatchForURL(client_, input, input.current_url(), |
Mark P
2017/04/13 21:12:28
Ditto comment about using the real title (again un
gcomanici
2017/04/18 18:52:52
Done.
| |
52 base::string16(), history_url_provider_, -1); | |
52 matches_.push_back(verbatim_match); | 53 matches_.push_back(verbatim_match); |
53 } | 54 } |
54 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL", | 55 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL", |
55 !matches_.empty()); | 56 !matches_.empty()); |
56 UMA_HISTOGRAM_LONG_TIMES_100("Omnibox.ClipboardSuggestionShownAge", | 57 UMA_HISTOGRAM_LONG_TIMES_100("Omnibox.ClipboardSuggestionShownAge", |
57 clipboard_content_->GetClipboardContentAge()); | 58 clipboard_content_->GetClipboardContentAge()); |
58 | 59 |
59 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. | 60 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. |
60 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); | 61 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); |
61 match.destination_url = url; | 62 match.destination_url = url; |
62 match.contents.assign(url_formatter::FormatUrl( | 63 match.contents.assign(url_formatter::FormatUrl( |
63 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, | 64 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, |
64 nullptr, nullptr, nullptr)); | 65 nullptr, nullptr, nullptr)); |
65 AutocompleteMatch::ClassifyLocationInString( | 66 AutocompleteMatch::ClassifyLocationInString( |
66 base::string16::npos, 0, match.contents.length(), | 67 base::string16::npos, 0, match.contents.length(), |
67 ACMatchClassification::URL, &match.contents_class); | 68 ACMatchClassification::URL, &match.contents_class); |
68 | 69 |
69 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); | 70 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); |
70 AutocompleteMatch::ClassifyLocationInString( | 71 AutocompleteMatch::ClassifyLocationInString( |
71 base::string16::npos, 0, match.description.length(), | 72 base::string16::npos, 0, match.description.length(), |
72 ACMatchClassification::NONE, &match.description_class); | 73 ACMatchClassification::NONE, &match.description_class); |
73 | 74 |
74 matches_.push_back(match); | 75 matches_.push_back(match); |
75 } | 76 } |
OLD | NEW |