Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: components/omnibox/browser/clipboard_url_provider.cc

Issue 2124563002: Don't try to create a verbatim match with an empty input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
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, adds a default match.
sdefresne 2016/07/05 10:08:56 nit: I would use if (!input.text().empty())
Mark P 2016/07/06 18:56:47 nit: adds -> add
jif 2016/07/11 15:09:36 Done.
jif 2016/07/11 15:09:36 Done.
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().length()) {
45 if (verbatim_match.destination_url.is_valid()) 49 AutocompleteMatch verbatim_match = VerbatimMatchForURL(
46 matches_.push_back(verbatim_match); 50 client_, input, input.current_url(), history_url_provider_, -1);
51 if (verbatim_match.destination_url.is_valid())
Mark P 2016/07/06 18:56:47 This if test shouldn't be necessary anymore. (It
jif 2016/07/11 15:09:36 Good catch. Done.
52 matches_.push_back(verbatim_match);
53 }
47 54
48 // Add a clipboard match just below the verbatim match. 55 // Add the clipboard match. The relevance can be '1' because there can only be
Mark P 2016/07/06 18:56:47 side comment: once iOS enables ZeroSuggest to most
jif 2016/07/11 15:09:36 Done.
49 AutocompleteMatch match(this, verbatim_match.relevance - 1, false, 56 // 0 or 1 match before: more matches will appear once the user starts typing,
57 // but when the user starts typing the clipboard based match stops showing up.
58 AutocompleteMatch match(this, 1, false,
50 AutocompleteMatchType::CLIPBOARD); 59 AutocompleteMatchType::CLIPBOARD);
51 match.destination_url = url; 60 match.destination_url = url;
52 match.contents.assign(url_formatter::FormatUrl( 61 match.contents.assign(url_formatter::FormatUrl(
53 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES, 62 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::SPACES,
54 nullptr, nullptr, nullptr)); 63 nullptr, nullptr, nullptr));
55 AutocompleteMatch::ClassifyLocationInString( 64 AutocompleteMatch::ClassifyLocationInString(
56 base::string16::npos, 0, match.contents.length(), 65 base::string16::npos, 0, match.contents.length(),
57 ACMatchClassification::URL, &match.contents_class); 66 ACMatchClassification::URL, &match.contents_class);
58 67
59 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD)); 68 match.description.assign(l10n_util::GetStringUTF16(IDS_LINK_FROM_CLIPBOARD));
60 AutocompleteMatch::ClassifyLocationInString( 69 AutocompleteMatch::ClassifyLocationInString(
61 base::string16::npos, 0, match.description.length(), 70 base::string16::npos, 0, match.description.length(),
62 ACMatchClassification::NONE, &match.description_class); 71 ACMatchClassification::NONE, &match.description_class);
63 72
64 // At least one match must be default, so if verbatim_match was invalid, 73 // At least one match must be default, so if verbatim_match was invalid,
65 // the clipboard match is allowed to be default. 74 // the clipboard match is allowed to be default.
66 match.allowed_to_be_default_match = matches_.empty(); 75 match.allowed_to_be_default_match = matches_.empty();
67 matches_.push_back(match); 76 matches_.push_back(match);
68 } 77 }
OLDNEW
« no previous file with comments | « no previous file | components/omnibox/browser/verbatim_match.h » ('j') | components/omnibox/browser/verbatim_match.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698