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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "components/omnibox/browser/autocomplete_input.h" | 10 #include "components/omnibox/browser/autocomplete_input.h" |
10 #include "components/omnibox/browser/autocomplete_provider_client.h" | 11 #include "components/omnibox/browser/autocomplete_provider_client.h" |
11 #include "components/omnibox/browser/verbatim_match.h" | 12 #include "components/omnibox/browser/verbatim_match.h" |
12 #include "components/open_from_clipboard/clipboard_recent_content.h" | 13 #include "components/open_from_clipboard/clipboard_recent_content.h" |
13 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
14 #include "components/url_formatter/url_formatter.h" | 15 #include "components/url_formatter/url_formatter.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 | 17 |
17 ClipboardURLProvider::ClipboardURLProvider( | 18 ClipboardURLProvider::ClipboardURLProvider( |
(...skipping 25 matching lines...) Expand all Loading... |
43 return; | 44 return; |
44 | 45 |
45 DCHECK(url.is_valid()); | 46 DCHECK(url.is_valid()); |
46 // If the omnibox is not empty, add a default match. | 47 // If the omnibox is not empty, add a default match. |
47 // This match will be opened when the user presses "Enter". | 48 // This match will be opened when the user presses "Enter". |
48 if (!input.text().empty()) { | 49 if (!input.text().empty()) { |
49 AutocompleteMatch verbatim_match = VerbatimMatchForURL( | 50 AutocompleteMatch verbatim_match = VerbatimMatchForURL( |
50 client_, input, input.current_url(), history_url_provider_, -1); | 51 client_, input, input.current_url(), history_url_provider_, -1); |
51 matches_.push_back(verbatim_match); | 52 matches_.push_back(verbatim_match); |
52 } | 53 } |
| 54 UMA_HISTOGRAM_BOOLEAN("Omnibox.ClipboardSuggestionShownWithCurrentURL", |
| 55 !matches_.empty()); |
53 | 56 |
54 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. | 57 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. |
55 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); | 58 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); |
56 match.destination_url = url; | 59 match.destination_url = url; |
57 match.contents.assign(url_formatter::FormatUrl( | 60 match.contents.assign(url_formatter::FormatUrl( |
58 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, | 61 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, |
59 nullptr, nullptr, nullptr)); | 62 nullptr, nullptr, nullptr)); |
60 AutocompleteMatch::ClassifyLocationInString( | 63 AutocompleteMatch::ClassifyLocationInString( |
61 base::string16::npos, 0, match.contents.length(), | 64 base::string16::npos, 0, match.contents.length(), |
62 ACMatchClassification::URL, &match.contents_class); | 65 ACMatchClassification::URL, &match.contents_class); |
63 | 66 |
64 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); | 67 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); |
65 AutocompleteMatch::ClassifyLocationInString( | 68 AutocompleteMatch::ClassifyLocationInString( |
66 base::string16::npos, 0, match.description.length(), | 69 base::string16::npos, 0, match.description.length(), |
67 ACMatchClassification::NONE, &match.description_class); | 70 ACMatchClassification::NONE, &match.description_class); |
68 | 71 |
69 matches_.push_back(match); | 72 matches_.push_back(match); |
70 } | 73 } |
OLD | NEW |