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

Side by Side Diff: chrome/browser/autocomplete/builtin_provider.cc

Issue 290333015: Suggest about:blank autocompletion from BuiltinProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix OmniboxViewTest.UndoRedo, minor cleanup. Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/builtin_provider.h" 5 #include "chrome/browser/autocomplete/builtin_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #endif 98 #endif
99 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIVersionURL), 99 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIVersionURL),
100 base::string16(), styles); 100 base::string16(), styles);
101 } else { 101 } else {
102 // Match input about: or chrome: URL input against builtin chrome URLs. 102 // Match input about: or chrome: URL input against builtin chrome URLs.
103 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string()); 103 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string());
104 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment 104 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment
105 // extensions to chrome: URLs. 105 // extensions to chrome: URLs.
106 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() && 106 if (url.SchemeIs(content::kChromeUIScheme) && url.has_host() &&
107 !url.has_query() && !url.has_ref()) { 107 !url.has_query() && !url.has_ref()) {
108 // Suggest about:blank for substrings, taking URL fixup into account.
Mark P 2014/05/29 23:48:05 Note that this was of doing it will put about:blan
msw 2014/05/30 00:29:49 It might be considered alphabetical if you're comp
Mark P 2014/05/30 18:16:41 Okay.
109 const base::string16 blank_host = base::ASCIIToUTF16("blank");
110 const base::string16 host = base::UTF8ToUTF16(url.host());
111 if (StartsWith(text, base::ASCIIToUTF16(content::kAboutScheme), false) &&
112 StartsWith(blank_host, host, false) && url.path().length() <= 1 &&
Mark P 2014/05/29 23:48:05 nit: parens around binary operator <=
msw 2014/05/30 00:29:49 Done.
113 !EndsWith(text, base::ASCIIToUTF16("/"), false)) {
Mark P 2014/05/29 23:48:05 please comment on the need for this final EndsWith
msw 2014/05/30 00:29:49 Done.
114 ACMatchClassifications styles;
115 styles.push_back(ACMatchClassification(0, kMatch));
116 base::string16 match = base::ASCIIToUTF16(content::kAboutBlankURL);
117 const size_t corrected_input_length = 6 + host.length();
Mark P 2014/05/29 23:48:05 comment on the "6" (and if it's 6 because this is
msw 2014/05/30 00:29:49 Done (used kAboutSchemeLength + 1) and added a com
118 if (blank_host.length() > host.length())
119 styles.push_back(ACMatchClassification(corrected_input_length, kUrl));
120 AddMatch(match, match.substr(corrected_input_length), styles);
121 }
122
108 // Include the path for sub-pages (e.g. "chrome://settings/browser"). 123 // Include the path for sub-pages (e.g. "chrome://settings/browser").
109 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); 124 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path());
110 base::TrimString(host_and_path, base::ASCIIToUTF16("/").c_str(), 125 base::TrimString(host_and_path, base::ASCIIToUTF16("/").c_str(),
111 &host_and_path); 126 &host_and_path);
112 size_t match_length = kChrome.length() + host_and_path.length(); 127 size_t match_length = kChrome.length() + host_and_path.length();
113 for (Builtins::const_iterator i(builtins_.begin()); 128 for (Builtins::const_iterator i(builtins_.begin());
114 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { 129 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) {
115 if (StartsWith(*i, host_and_path, false)) { 130 if (StartsWith(*i, host_and_path, false)) {
116 ACMatchClassifications styles; 131 ACMatchClassifications styles;
117 // Highlight the "chrome://" scheme, even for input "about:foo". 132 // Highlight the "chrome://" scheme, even for input "about:foo".
(...skipping 26 matching lines...) Expand all
144 const ACMatchClassifications& styles) { 159 const ACMatchClassifications& styles) {
145 AutocompleteMatch match(this, kRelevance, false, 160 AutocompleteMatch match(this, kRelevance, false,
146 AutocompleteMatchType::NAVSUGGEST); 161 AutocompleteMatchType::NAVSUGGEST);
147 match.fill_into_edit = match_string; 162 match.fill_into_edit = match_string;
148 match.inline_autocompletion = inline_completion; 163 match.inline_autocompletion = inline_completion;
149 match.destination_url = GURL(match_string); 164 match.destination_url = GURL(match_string);
150 match.contents = match_string; 165 match.contents = match_string;
151 match.contents_class = styles; 166 match.contents_class = styles;
152 matches_.push_back(match); 167 matches_.push_back(match);
153 } 168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698