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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/omnibox/browser/autocomplete_input.h" | 9 #include "components/omnibox/browser/autocomplete_input.h" |
10 #include "components/omnibox/browser/autocomplete_provider_client.h" | 10 #include "components/omnibox/browser/autocomplete_provider_client.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 clipboard_content_(clipboard_content), | 23 clipboard_content_(clipboard_content), |
24 history_url_provider_(history_url_provider) { | 24 history_url_provider_(history_url_provider) { |
25 DCHECK(clipboard_content_); | 25 DCHECK(clipboard_content_); |
26 } | 26 } |
27 | 27 |
28 ClipboardURLProvider::~ClipboardURLProvider() {} | 28 ClipboardURLProvider::~ClipboardURLProvider() {} |
29 | 29 |
30 void ClipboardURLProvider::Start(const AutocompleteInput& input, | 30 void ClipboardURLProvider::Start(const AutocompleteInput& input, |
31 bool minimal_changes) { | 31 bool minimal_changes) { |
32 matches_.clear(); | 32 matches_.clear(); |
33 | |
34 // If the user started typing, do not offer clipboard based match. | |
Peter Kasting
2016/07/18 22:16:15
Nit: I would not add these next two comments. The
| |
33 if (!input.from_omnibox_focus()) | 35 if (!input.from_omnibox_focus()) |
34 return; | 36 return; |
35 | 37 |
36 GURL url; | 38 GURL url; |
39 // If the clipboard does not contain any URL, or the URL on the page is the | |
40 // same as the URL in the clipboard, early return. | |
37 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || | 41 if (!clipboard_content_->GetRecentURLFromClipboard(&url) || |
38 url == input.current_url()) | 42 url == input.current_url()) |
39 return; | 43 return; |
40 | 44 |
41 DCHECK(url.is_valid()); | 45 DCHECK(url.is_valid()); |
42 // Adds a default match. This match will be opened when the user presses "Go". | 46 // If the omnibox is not empty, add a default match. |
Peter Kasting
2016/07/18 22:16:15
Again, this adds detail that just restates the cod
| |
43 AutocompleteMatch verbatim_match = VerbatimMatchForURL( | 47 // This match will be opened when the user presses "Enter". |
44 client_, input, input.current_url(), history_url_provider_, -1); | 48 if (!input.text().empty()) { |
45 if (verbatim_match.destination_url.is_valid()) | 49 AutocompleteMatch verbatim_match = VerbatimMatchForURL( |
50 client_, input, input.current_url(), history_url_provider_, -1); | |
46 matches_.push_back(verbatim_match); | 51 matches_.push_back(verbatim_match); |
52 } | |
47 | 53 |
48 // Add a clipboard match just below the verbatim match. | 54 // Add the clipboard match. The relevance is 800 to beat ZeroSuggest results. |
49 AutocompleteMatch match(this, verbatim_match.relevance - 1, false, | 55 AutocompleteMatch match(this, 800, false, AutocompleteMatchType::CLIPBOARD); |
Peter Kasting
2016/07/18 22:16:15
I don't think we should hardcode 800 here. If the
| |
50 AutocompleteMatchType::CLIPBOARD); | |
51 match.destination_url = url; | 56 match.destination_url = url; |
52 match.contents.assign(url_formatter::FormatUrl( | 57 match.contents.assign(url_formatter::FormatUrl( |
53 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, | 58 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, |
54 nullptr, nullptr, nullptr)); | 59 nullptr, nullptr, nullptr)); |
55 AutocompleteMatch::ClassifyLocationInString( | 60 AutocompleteMatch::ClassifyLocationInString( |
56 base::string16::npos, 0, match.contents.length(), | 61 base::string16::npos, 0, match.contents.length(), |
57 ACMatchClassification::URL, &match.contents_class); | 62 ACMatchClassification::URL, &match.contents_class); |
58 | 63 |
59 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); | 64 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); |
60 AutocompleteMatch::ClassifyLocationInString( | 65 AutocompleteMatch::ClassifyLocationInString( |
61 base::string16::npos, 0, match.description.length(), | 66 base::string16::npos, 0, match.description.length(), |
62 ACMatchClassification::NONE, &match.description_class); | 67 ACMatchClassification::NONE, &match.description_class); |
63 | 68 |
64 // At least one match must be default, so if verbatim_match was invalid, | 69 // At least one match must be default, so if verbatim_match was invalid, |
65 // the clipboard match is allowed to be default. | 70 // the clipboard match is allowed to be default. |
66 match.allowed_to_be_default_match = matches_.empty(); | 71 match.allowed_to_be_default_match = matches_.empty(); |
67 matches_.push_back(match); | 72 matches_.push_back(match); |
68 } | 73 } |
OLD | NEW |