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

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: Remove a case that fails on Android. 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
« no previous file with comments | « no previous file | chrome/browser/autocomplete/builtin_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 void BuiltinProvider::Start(const AutocompleteInput& input, 64 void BuiltinProvider::Start(const AutocompleteInput& input,
65 bool minimal_changes) { 65 bool minimal_changes) {
66 matches_.clear(); 66 matches_.clear();
67 if ((input.type() == AutocompleteInput::INVALID) || 67 if ((input.type() == AutocompleteInput::INVALID) ||
68 (input.type() == AutocompleteInput::FORCED_QUERY) || 68 (input.type() == AutocompleteInput::FORCED_QUERY) ||
69 (input.type() == AutocompleteInput::QUERY)) 69 (input.type() == AutocompleteInput::QUERY))
70 return; 70 return;
71 71
72 const size_t kAboutSchemeLength = strlen(content::kAboutScheme);
72 const base::string16 kAbout = base::ASCIIToUTF16(content::kAboutScheme) + 73 const base::string16 kAbout = base::ASCIIToUTF16(content::kAboutScheme) +
73 base::ASCIIToUTF16(content::kStandardSchemeSeparator); 74 base::ASCIIToUTF16(content::kStandardSchemeSeparator);
74 const base::string16 kChrome = base::ASCIIToUTF16(content::kChromeUIScheme) + 75 const base::string16 kChrome = base::ASCIIToUTF16(content::kChromeUIScheme) +
75 base::ASCIIToUTF16(content::kStandardSchemeSeparator); 76 base::ASCIIToUTF16(content::kStandardSchemeSeparator);
76 77
77 const int kUrl = ACMatchClassification::URL; 78 const int kUrl = ACMatchClassification::URL;
78 const int kMatch = kUrl | ACMatchClassification::MATCH; 79 const int kMatch = kUrl | ACMatchClassification::MATCH;
79 80
80 base::string16 text = input.text(); 81 base::string16 text = input.text();
81 bool starting_chrome = StartsWith(kChrome, text, false); 82 bool starting_chrome = StartsWith(kChrome, text, false);
82 if (starting_chrome || StartsWith(kAbout, text, false)) { 83 if (starting_chrome || StartsWith(kAbout, text, false)) {
83 ACMatchClassifications styles; 84 ACMatchClassifications styles;
84 // Highlight the input portion matching "chrome://"; or if the user has 85 // Highlight the input portion matching "chrome://"; or if the user has
85 // input "about:" (with optional slashes), highlight the whole "chrome://". 86 // input "about:" (with optional slashes), highlight the whole "chrome://".
86 const size_t kAboutSchemeLength = strlen(content::kAboutScheme);
87 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; 87 bool highlight = starting_chrome || text.length() > kAboutSchemeLength;
88 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); 88 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl));
89 size_t offset = starting_chrome ? text.length() : kChrome.length(); 89 size_t offset = starting_chrome ? text.length() : kChrome.length();
90 if (highlight) 90 if (highlight)
91 styles.push_back(ACMatchClassification(offset, kUrl)); 91 styles.push_back(ACMatchClassification(offset, kUrl));
92 // Include some common builtin chrome URLs as the user types the scheme. 92 // Include some common builtin chrome URLs as the user types the scheme.
93 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), 93 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIChromeURLsURL),
94 base::string16(), styles); 94 base::string16(), styles);
95 #if !defined(OS_ANDROID) 95 #if !defined(OS_ANDROID)
96 AddMatch(base::ASCIIToUTF16(chrome::kChromeUISettingsURL), 96 AddMatch(base::ASCIIToUTF16(chrome::kChromeUISettingsURL),
97 base::string16(), styles); 97 base::string16(), styles);
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.
109 // Chrome does not support trailing slashes or paths for about:blank.
110 const base::string16 blank_host = base::ASCIIToUTF16("blank");
111 const base::string16 host = base::UTF8ToUTF16(url.host());
112 if (StartsWith(text, base::ASCIIToUTF16(content::kAboutScheme), false) &&
113 StartsWith(blank_host, host, false) && (url.path().length() <= 1) &&
114 !EndsWith(text, base::ASCIIToUTF16("/"), false)) {
115 ACMatchClassifications styles;
116 styles.push_back(ACMatchClassification(0, kMatch));
117 base::string16 match = base::ASCIIToUTF16(content::kAboutBlankURL);
118 // Measure the length of the matching host after the "about:" scheme.
119 const size_t corrected_length = kAboutSchemeLength + 1 + host.length();
120 if (blank_host.length() > host.length())
121 styles.push_back(ACMatchClassification(corrected_length, kUrl));
122 AddMatch(match, match.substr(corrected_length), styles);
123 }
124
108 // Include the path for sub-pages (e.g. "chrome://settings/browser"). 125 // Include the path for sub-pages (e.g. "chrome://settings/browser").
109 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); 126 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path());
110 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path); 127 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path);
111 size_t match_length = kChrome.length() + host_and_path.length(); 128 size_t match_length = kChrome.length() + host_and_path.length();
112 for (Builtins::const_iterator i(builtins_.begin()); 129 for (Builtins::const_iterator i(builtins_.begin());
113 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { 130 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) {
114 if (StartsWith(*i, host_and_path, false)) { 131 if (StartsWith(*i, host_and_path, false)) {
115 ACMatchClassifications styles; 132 ACMatchClassifications styles;
116 // Highlight the "chrome://" scheme, even for input "about:foo". 133 // Highlight the "chrome://" scheme, even for input "about:foo".
117 styles.push_back(ACMatchClassification(0, kMatch)); 134 styles.push_back(ACMatchClassification(0, kMatch));
(...skipping 25 matching lines...) Expand all
143 const ACMatchClassifications& styles) { 160 const ACMatchClassifications& styles) {
144 AutocompleteMatch match(this, kRelevance, false, 161 AutocompleteMatch match(this, kRelevance, false,
145 AutocompleteMatchType::NAVSUGGEST); 162 AutocompleteMatchType::NAVSUGGEST);
146 match.fill_into_edit = match_string; 163 match.fill_into_edit = match_string;
147 match.inline_autocompletion = inline_completion; 164 match.inline_autocompletion = inline_completion;
148 match.destination_url = GURL(match_string); 165 match.destination_url = GURL(match_string);
149 match.contents = match_string; 166 match.contents = match_string;
150 match.contents_class = styles; 167 match.contents_class = styles;
151 matches_.push_back(match); 168 matches_.push_back(match);
152 } 169 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/builtin_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698