OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 AutocompleteInput::AutocompleteInput() | 45 AutocompleteInput::AutocompleteInput() |
46 : type_(INVALID), | 46 : type_(INVALID), |
47 initial_prevent_inline_autocomplete_(false), | 47 initial_prevent_inline_autocomplete_(false), |
48 prevent_inline_autocomplete_(false), | 48 prevent_inline_autocomplete_(false), |
49 prefer_keyword_(false), | 49 prefer_keyword_(false), |
50 allow_exact_keyword_match_(true), | 50 allow_exact_keyword_match_(true), |
51 synchronous_only_(false) { | 51 synchronous_only_(false) { |
52 } | 52 } |
53 | 53 |
54 AutocompleteInput::AutocompleteInput(const std::wstring& text, | 54 AutocompleteInput::AutocompleteInput(const string16& text, |
55 const std::wstring& desired_tld, | 55 const string16& desired_tld, |
56 bool prevent_inline_autocomplete, | 56 bool prevent_inline_autocomplete, |
57 bool prefer_keyword, | 57 bool prefer_keyword, |
58 bool allow_exact_keyword_match, | 58 bool allow_exact_keyword_match, |
59 bool synchronous_only) | 59 bool synchronous_only) |
60 : desired_tld_(desired_tld), | 60 : desired_tld_(desired_tld), |
61 initial_prevent_inline_autocomplete_(prevent_inline_autocomplete), | 61 initial_prevent_inline_autocomplete_(prevent_inline_autocomplete), |
62 prevent_inline_autocomplete_(prevent_inline_autocomplete), | 62 prevent_inline_autocomplete_(prevent_inline_autocomplete), |
63 prefer_keyword_(prefer_keyword), | 63 prefer_keyword_(prefer_keyword), |
64 allow_exact_keyword_match_(allow_exact_keyword_match), | 64 allow_exact_keyword_match_(allow_exact_keyword_match), |
65 synchronous_only_(synchronous_only) { | 65 synchronous_only_(synchronous_only) { |
(...skipping 15 matching lines...) Expand all Loading... | |
81 canonicalized_url_ = canonicalized_url; | 81 canonicalized_url_ = canonicalized_url; |
82 | 82 |
83 RemoveForcedQueryStringIfNecessary(type_, &text_); | 83 RemoveForcedQueryStringIfNecessary(type_, &text_); |
84 } | 84 } |
85 | 85 |
86 AutocompleteInput::~AutocompleteInput() { | 86 AutocompleteInput::~AutocompleteInput() { |
87 } | 87 } |
88 | 88 |
89 // static | 89 // static |
90 void AutocompleteInput::RemoveForcedQueryStringIfNecessary(Type type, | 90 void AutocompleteInput::RemoveForcedQueryStringIfNecessary(Type type, |
91 std::wstring* text) { | 91 string16* text) { |
92 if (type == FORCED_QUERY && !text->empty() && (*text)[0] == L'?') | 92 if (type == FORCED_QUERY && !text->empty() && (*text)[0] == L'?') |
93 text->erase(0, 1); | 93 text->erase(0, 1); |
94 } | 94 } |
95 | 95 |
96 // static | 96 // static |
97 std::string AutocompleteInput::TypeToString(Type type) { | 97 std::string AutocompleteInput::TypeToString(Type type) { |
98 switch (type) { | 98 switch (type) { |
99 case INVALID: return "invalid"; | 99 case INVALID: return "invalid"; |
100 case UNKNOWN: return "unknown"; | 100 case UNKNOWN: return "unknown"; |
101 case REQUESTED_URL: return "requested-url"; | 101 case REQUESTED_URL: return "requested-url"; |
102 case URL: return "url"; | 102 case URL: return "url"; |
103 case QUERY: return "query"; | 103 case QUERY: return "query"; |
104 case FORCED_QUERY: return "forced-query"; | 104 case FORCED_QUERY: return "forced-query"; |
105 | 105 |
106 default: | 106 default: |
107 NOTREACHED(); | 107 NOTREACHED(); |
108 return std::string(); | 108 return std::string(); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 // static | 112 // static |
113 AutocompleteInput::Type AutocompleteInput::Parse( | 113 AutocompleteInput::Type AutocompleteInput::Parse( |
114 const std::wstring& text, | 114 const string16& text, |
115 const std::wstring& desired_tld, | 115 const string16& desired_tld, |
116 url_parse::Parsed* parts, | 116 url_parse::Parsed* parts, |
117 std::wstring* scheme, | 117 string16* scheme, |
118 GURL* canonicalized_url) { | 118 GURL* canonicalized_url) { |
119 const size_t first_non_white = text.find_first_not_of(kWhitespaceWide, 0); | 119 const size_t first_non_white = text.find_first_not_of(kWhitespaceUTF16, 0); |
120 if (first_non_white == std::wstring::npos) | 120 if (first_non_white == string16::npos) |
121 return INVALID; // All whitespace. | 121 return INVALID; // All whitespace. |
122 | 122 |
123 if (text.at(first_non_white) == L'?') { | 123 if (text.at(first_non_white) == L'?') { |
124 // If the first non-whitespace character is a '?', we magically treat this | 124 // If the first non-whitespace character is a '?', we magically treat this |
125 // as a query. | 125 // as a query. |
126 return FORCED_QUERY; | 126 return FORCED_QUERY; |
127 } | 127 } |
128 | 128 |
129 // Ask our parsing back-end to help us understand what the user typed. We | 129 // Ask our parsing back-end to help us understand what the user typed. We |
130 // use the URLFixerUpper here because we want to be smart about what we | 130 // use the URLFixerUpper here because we want to be smart about what we |
131 // consider a scheme. For example, we shouldn't consider www.google.com:80 | 131 // consider a scheme. For example, we shouldn't consider www.google.com:80 |
132 // to have a scheme. | 132 // to have a scheme. |
133 url_parse::Parsed local_parts; | 133 url_parse::Parsed local_parts; |
134 if (!parts) | 134 if (!parts) |
135 parts = &local_parts; | 135 parts = &local_parts; |
136 const std::wstring parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); | 136 const string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); |
137 if (scheme) | 137 if (scheme) |
138 *scheme = parsed_scheme; | 138 *scheme = parsed_scheme; |
139 if (canonicalized_url) { | 139 if (canonicalized_url) { |
140 *canonicalized_url = URLFixerUpper::FixupURL(WideToUTF8(text), | 140 *canonicalized_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), |
141 WideToUTF8(desired_tld)); | 141 UTF16ToUTF8(desired_tld)); |
142 } | 142 } |
143 | 143 |
144 if (parsed_scheme == L"file") { | 144 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { |
Avi (use Gerrit)
2011/01/21 18:23:08
Yes, this change is deliberate. LowerCaseEqualsASC
| |
145 // A user might or might not type a scheme when entering a file URL. In | 145 // A user might or might not type a scheme when entering a file URL. In |
146 // either case, |parsed_scheme| will tell us that this is a file URL, but | 146 // either case, |parsed_scheme| will tell us that this is a file URL, but |
147 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". | 147 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". |
148 return URL; | 148 return URL; |
149 } | 149 } |
150 | 150 |
151 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it | 151 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it |
152 // well enough that we can fall through to the heuristics below. If it's | 152 // well enough that we can fall through to the heuristics below. If it's |
153 // something else, we can just determine our action based on what we do with | 153 // something else, we can just determine our action based on what we do with |
154 // any input of this scheme. In theory we could do better with some schemes | 154 // any input of this scheme. In theory we could do better with some schemes |
155 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that | 155 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that |
156 // until I run into some cases that really need it. | 156 // until I run into some cases that really need it. |
157 if (parts->scheme.is_nonempty() && | 157 if (parts->scheme.is_nonempty() && |
158 (parsed_scheme != L"http") && (parsed_scheme != L"https")) { | 158 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpScheme) && |
159 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpsScheme)) { | |
159 // See if we know how to handle the URL internally. | 160 // See if we know how to handle the URL internally. |
160 if (net::URLRequest::IsHandledProtocol(WideToASCII(parsed_scheme))) | 161 if (net::URLRequest::IsHandledProtocol(UTF16ToASCII(parsed_scheme))) |
161 return URL; | 162 return URL; |
162 | 163 |
163 // There are also some schemes that we convert to other things before they | 164 // There are also some schemes that we convert to other things before they |
164 // reach the renderer or else the renderer handles internally without | 165 // reach the renderer or else the renderer handles internally without |
165 // reaching the net::URLRequest logic. We thus won't catch these above, but | 166 // reaching the net::URLRequest logic. We thus won't catch these above, but |
166 // we should still claim to handle them. | 167 // we should still claim to handle them. |
167 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kViewSourceScheme) || | 168 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kViewSourceScheme) || |
168 LowerCaseEqualsASCII(parsed_scheme, chrome::kJavaScriptScheme) || | 169 LowerCaseEqualsASCII(parsed_scheme, chrome::kJavaScriptScheme) || |
169 LowerCaseEqualsASCII(parsed_scheme, chrome::kDataScheme)) | 170 LowerCaseEqualsASCII(parsed_scheme, chrome::kDataScheme)) |
170 return URL; | 171 return URL; |
171 | 172 |
172 // Finally, check and see if the user has explicitly opened this scheme as | 173 // Finally, check and see if the user has explicitly opened this scheme as |
173 // a URL before, or if the "scheme" is actually a username. We need to do | 174 // a URL before, or if the "scheme" is actually a username. We need to do |
174 // this last because some schemes (e.g. "javascript") may be treated as | 175 // this last because some schemes (e.g. "javascript") may be treated as |
175 // "blocked" by the external protocol handler because we don't want pages to | 176 // "blocked" by the external protocol handler because we don't want pages to |
176 // open them, but users still can. | 177 // open them, but users still can. |
177 // TODO(viettrungluu): get rid of conversion. | 178 // TODO(viettrungluu): get rid of conversion. |
178 switch (ExternalProtocolHandler::GetBlockState(WideToUTF8(parsed_scheme))) { | 179 switch ( |
180 ExternalProtocolHandler::GetBlockState(UTF16ToUTF8(parsed_scheme))) { | |
evanm
2011/01/24 19:14:14
Might be easier to read if you put getting the blo
Avi (use Gerrit)
2011/01/24 19:46:42
Done.
| |
179 case ExternalProtocolHandler::DONT_BLOCK: | 181 case ExternalProtocolHandler::DONT_BLOCK: |
180 return URL; | 182 return URL; |
181 | 183 |
182 case ExternalProtocolHandler::BLOCK: | 184 case ExternalProtocolHandler::BLOCK: |
183 // If we don't want the user to open the URL, don't let it be navigated | 185 // If we don't want the user to open the URL, don't let it be navigated |
184 // to at all. | 186 // to at all. |
185 return QUERY; | 187 return QUERY; |
186 | 188 |
187 default: { | 189 default: { |
188 // We don't know about this scheme. It might be that the user typed a | 190 // We don't know about this scheme. It might be that the user typed a |
189 // URL of the form "username:password@foo.com". | 191 // URL of the form "username:password@foo.com". |
190 const std::wstring http_scheme_prefix = L"http://"; | 192 const string16 http_scheme_prefix = |
193 ASCIIToUTF16(std::string(chrome::kHttpScheme) + | |
194 chrome::kStandardSchemeSeparator); | |
191 url_parse::Parsed http_parts; | 195 url_parse::Parsed http_parts; |
192 std::wstring http_scheme; | 196 string16 http_scheme; |
193 GURL http_canonicalized_url; | 197 GURL http_canonicalized_url; |
194 Type http_type = Parse(http_scheme_prefix + text, desired_tld, | 198 Type http_type = Parse(http_scheme_prefix + text, desired_tld, |
195 &http_parts, &http_scheme, | 199 &http_parts, &http_scheme, |
196 &http_canonicalized_url); | 200 &http_canonicalized_url); |
197 DCHECK_EQ("http", WideToUTF8(http_scheme)); | 201 DCHECK_EQ(std::string(chrome::kHttpScheme), UTF16ToUTF8(http_scheme)); |
198 | 202 |
199 if ((http_type == URL || http_type == REQUESTED_URL) && | 203 if ((http_type == URL || http_type == REQUESTED_URL) && |
200 http_parts.username.is_nonempty() && | 204 http_parts.username.is_nonempty() && |
201 http_parts.password.is_nonempty()) { | 205 http_parts.password.is_nonempty()) { |
202 // Manually re-jigger the parsed parts to match |text| (without the | 206 // Manually re-jigger the parsed parts to match |text| (without the |
203 // http scheme added). | 207 // http scheme added). |
204 http_parts.scheme.reset(); | 208 http_parts.scheme.reset(); |
205 url_parse::Component* components[] = { | 209 url_parse::Component* components[] = { |
206 &http_parts.username, | 210 &http_parts.username, |
207 &http_parts.password, | 211 &http_parts.password, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 // Either the user didn't type a scheme, in which case we need to distinguish | 243 // Either the user didn't type a scheme, in which case we need to distinguish |
240 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which | 244 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which |
241 // case we should reject invalid formulations. | 245 // case we should reject invalid formulations. |
242 | 246 |
243 // If we have an empty host it can't be a URL. | 247 // If we have an empty host it can't be a URL. |
244 if (!parts->host.is_nonempty()) | 248 if (!parts->host.is_nonempty()) |
245 return QUERY; | 249 return QUERY; |
246 | 250 |
247 // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also | 251 // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also |
248 // use the registry length later below.) | 252 // use the registry length later below.) |
249 const std::wstring host(text.substr(parts->host.begin, parts->host.len)); | 253 const string16 host(text.substr(parts->host.begin, parts->host.len)); |
250 const size_t registry_length = | 254 const size_t registry_length = |
251 net::RegistryControlledDomainService::GetRegistryLength(host, false); | 255 net::RegistryControlledDomainService::GetRegistryLength(UTF16ToUTF8(host), |
252 if (registry_length == std::wstring::npos) { | 256 false); |
257 if (registry_length == string16::npos) { | |
Avi (use Gerrit)
2011/01/21 18:23:08
std::string::npos; fixed already.
| |
253 // Try to append the desired_tld. | 258 // Try to append the desired_tld. |
254 if (!desired_tld.empty()) { | 259 if (!desired_tld.empty()) { |
255 std::wstring host_with_tld(host); | 260 string16 host_with_tld(host); |
256 if (host[host.length() - 1] != '.') | 261 if (host[host.length() - 1] != '.') |
257 host_with_tld += '.'; | 262 host_with_tld += '.'; |
258 host_with_tld += desired_tld; | 263 host_with_tld += desired_tld; |
259 if (net::RegistryControlledDomainService::GetRegistryLength( | 264 if (net::RegistryControlledDomainService::GetRegistryLength( |
260 host_with_tld, false) != std::wstring::npos) | 265 UTF16ToUTF8(host_with_tld), false) != string16::npos) |
Avi (use Gerrit)
2011/01/21 18:23:08
Ditto.
| |
261 return REQUESTED_URL; // Something like "99999999999" that looks like a | 266 return REQUESTED_URL; // Something like "99999999999" that looks like a |
262 // bad IP address, but becomes valid on attaching | 267 // bad IP address, but becomes valid on attaching |
263 // a TLD. | 268 // a TLD. |
264 } | 269 } |
265 return QUERY; // Could be a broken IP address, etc. | 270 return QUERY; // Could be a broken IP address, etc. |
266 } | 271 } |
267 | 272 |
268 | 273 |
269 // See if the hostname is valid. While IE and GURL allow hostnames to contain | 274 // See if the hostname is valid. While IE and GURL allow hostnames to contain |
270 // many other characters (perhaps for weird intranet machines), it's extremely | 275 // many other characters (perhaps for weird intranet machines), it's extremely |
271 // unlikely that a user would be trying to type those in for anything other | 276 // unlikely that a user would be trying to type those in for anything other |
272 // than a search query. | 277 // than a search query. |
273 url_canon::CanonHostInfo host_info; | 278 url_canon::CanonHostInfo host_info; |
274 const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); | 279 const std::string canonicalized_host(net::CanonicalizeHost(UTF16ToUTF8(host), |
280 &host_info)); | |
evanm
2011/01/24 19:14:14
Are these APIs really in terms of UTF-8? (I'm won
Avi (use Gerrit)
2011/01/24 19:46:42
Yes, they are. First note that I didn't change the
| |
275 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && | 281 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && |
276 !net::IsCanonicalizedHostCompliant(canonicalized_host, | 282 !net::IsCanonicalizedHostCompliant(canonicalized_host, |
277 WideToUTF8(desired_tld))) { | 283 UTF16ToUTF8(desired_tld))) { |
278 // Invalid hostname. There are several possible cases: | 284 // Invalid hostname. There are several possible cases: |
279 // * Our checker is too strict and the user pasted in a real-world URL | 285 // * Our checker is too strict and the user pasted in a real-world URL |
280 // that's "invalid" but resolves. To catch these, we return UNKNOWN when | 286 // that's "invalid" but resolves. To catch these, we return UNKNOWN when |
281 // the user explicitly typed a scheme, so we'll still search by default | 287 // the user explicitly typed a scheme, so we'll still search by default |
282 // but we'll show the accidental search infobar if necessary. | 288 // but we'll show the accidental search infobar if necessary. |
283 // * The user is typing a multi-word query. If we see a space anywhere in | 289 // * The user is typing a multi-word query. If we see a space anywhere in |
284 // the hostname we assume this is a search and return QUERY. | 290 // the hostname we assume this is a search and return QUERY. |
285 // * Our checker is too strict and the user is typing a real-world hostname | 291 // * Our checker is too strict and the user is typing a real-world hostname |
286 // that's "invalid" but resolves. We return UNKNOWN if the TLD is known. | 292 // that's "invalid" but resolves. We return UNKNOWN if the TLD is known. |
287 // Note that we explicitly excluded hosts with spaces above so that | 293 // Note that we explicitly excluded hosts with spaces above so that |
288 // "toys at amazon.com" will be treated as a search. | 294 // "toys at amazon.com" will be treated as a search. |
289 // * The user is typing some garbage string. Return QUERY. | 295 // * The user is typing some garbage string. Return QUERY. |
290 // | 296 // |
291 // Thus we fall down in the following cases: | 297 // Thus we fall down in the following cases: |
292 // * Trying to navigate to a hostname with spaces | 298 // * Trying to navigate to a hostname with spaces |
293 // * Trying to navigate to a hostname with invalid characters and an unknown | 299 // * Trying to navigate to a hostname with invalid characters and an unknown |
294 // TLD | 300 // TLD |
295 // These are rare, though probably possible in intranets. | 301 // These are rare, though probably possible in intranets. |
296 return (parts->scheme.is_nonempty() || | 302 return (parts->scheme.is_nonempty() || |
297 ((registry_length != 0) && (host.find(' ') == std::wstring::npos))) ? | 303 ((registry_length != 0) && (host.find(' ') == string16::npos))) ? |
298 UNKNOWN : QUERY; | 304 UNKNOWN : QUERY; |
299 } | 305 } |
300 | 306 |
301 // A port number is a good indicator that this is a URL. However, it might | 307 // A port number is a good indicator that this is a URL. However, it might |
302 // also be a query like "1.66:1" that looks kind of like an IP address and | 308 // also be a query like "1.66:1" that looks kind of like an IP address and |
303 // port number. So here we only check for "port numbers" that are illegal and | 309 // port number. So here we only check for "port numbers" that are illegal and |
304 // thus mean this can't be navigated to (e.g. "1.2.3.4:garbage"), and we save | 310 // thus mean this can't be navigated to (e.g. "1.2.3.4:garbage"), and we save |
305 // handling legal port numbers until after the "IP address" determination | 311 // handling legal port numbers until after the "IP address" determination |
306 // below. | 312 // below. |
307 if (parts->port.is_nonempty()) { | 313 if (parts->port.is_nonempty()) { |
308 int port; | 314 int port; |
309 if (!base::StringToInt(WideToUTF8( | 315 if (!base::StringToInt(text.substr(parts->port.begin, parts->port.len), |
310 text.substr(parts->port.begin, parts->port.len)), &port) || | 316 &port) || |
311 (port < 0) || (port > 65535)) | 317 (port < 0) || (port > 65535)) |
312 return QUERY; | 318 return QUERY; |
313 } | 319 } |
314 | 320 |
315 // Now that we've ruled out all schemes other than http or https and done a | 321 // Now that we've ruled out all schemes other than http or https and done a |
316 // little more sanity checking, the presence of a scheme means this is likely | 322 // little more sanity checking, the presence of a scheme means this is likely |
317 // a URL. | 323 // a URL. |
318 if (parts->scheme.is_nonempty()) | 324 if (parts->scheme.is_nonempty()) |
319 return URL; | 325 return URL; |
320 | 326 |
(...skipping 28 matching lines...) Expand all Loading... | |
349 if (parts->path.is_nonempty()) { | 355 if (parts->path.is_nonempty()) { |
350 // Most inputs with paths are URLs, even ones without known registries (e.g. | 356 // Most inputs with paths are URLs, even ones without known registries (e.g. |
351 // intranet URLs). However, if there's no known registry and the path has | 357 // intranet URLs). However, if there's no known registry and the path has |
352 // a space, this is more likely a query with a slash in the first term | 358 // a space, this is more likely a query with a slash in the first term |
353 // (e.g. "ps/2 games") than a URL. We can still open URLs with spaces in | 359 // (e.g. "ps/2 games") than a URL. We can still open URLs with spaces in |
354 // the path by escaping the space, and we will still inline autocomplete | 360 // the path by escaping the space, and we will still inline autocomplete |
355 // them if users have typed them in the past, but we default to searching | 361 // them if users have typed them in the past, but we default to searching |
356 // since that's the common case. | 362 // since that's the common case. |
357 return ((registry_length == 0) && | 363 return ((registry_length == 0) && |
358 (text.substr(parts->path.begin, parts->path.len).find(' ') != | 364 (text.substr(parts->path.begin, parts->path.len).find(' ') != |
359 std::wstring::npos)) ? UNKNOWN : URL; | 365 string16::npos)) ? UNKNOWN : URL; |
360 } | 366 } |
361 | 367 |
362 // If we reach here with a username, our input looks like "user@host". | 368 // If we reach here with a username, our input looks like "user@host". |
363 // Because there is no scheme explicitly specified, we think this is more | 369 // Because there is no scheme explicitly specified, we think this is more |
364 // likely an email address than an HTTP auth attempt. Hence, we search by | 370 // likely an email address than an HTTP auth attempt. Hence, we search by |
365 // default and let users correct us on a case-by-case basis. | 371 // default and let users correct us on a case-by-case basis. |
366 if (parts->username.is_nonempty()) | 372 if (parts->username.is_nonempty()) |
367 return UNKNOWN; | 373 return UNKNOWN; |
368 | 374 |
369 // We have a bare host string. If it has a known TLD, it's probably a URL. | 375 // We have a bare host string. If it has a known TLD, it's probably a URL. |
(...skipping 15 matching lines...) Expand all Loading... | |
385 // "browser.tabs.closeButtons" or "java.awt.event.*"). This is ideally a | 391 // "browser.tabs.closeButtons" or "java.awt.event.*"). This is ideally a |
386 // QUERY. Since the above case and this one are indistinguishable, and this | 392 // QUERY. Since the above case and this one are indistinguishable, and this |
387 // case is likely to be much more common, just say these are both UNKNOWN, | 393 // case is likely to be much more common, just say these are both UNKNOWN, |
388 // which should default to the right thing and let users correct us on a | 394 // which should default to the right thing and let users correct us on a |
389 // case-by-case basis. | 395 // case-by-case basis. |
390 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; | 396 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; |
391 } | 397 } |
392 | 398 |
393 // static | 399 // static |
394 void AutocompleteInput::ParseForEmphasizeComponents( | 400 void AutocompleteInput::ParseForEmphasizeComponents( |
395 const std::wstring& text, | 401 const string16& text, |
396 const std::wstring& desired_tld, | 402 const string16& desired_tld, |
397 url_parse::Component* scheme, | 403 url_parse::Component* scheme, |
398 url_parse::Component* host) { | 404 url_parse::Component* host) { |
399 url_parse::Parsed parts; | 405 url_parse::Parsed parts; |
400 std::wstring scheme_str; | 406 string16 scheme_str; |
401 Parse(text, desired_tld, &parts, &scheme_str, NULL); | 407 Parse(text, desired_tld, &parts, &scheme_str, NULL); |
402 | 408 |
403 *scheme = parts.scheme; | 409 *scheme = parts.scheme; |
404 *host = parts.host; | 410 *host = parts.host; |
405 | 411 |
406 int after_scheme_and_colon = parts.scheme.end() + 1; | 412 int after_scheme_and_colon = parts.scheme.end() + 1; |
407 // For the view-source scheme, we should emphasize the scheme and host of the | 413 // For the view-source scheme, we should emphasize the scheme and host of the |
408 // URL qualified by the view-source prefix. | 414 // URL qualified by the view-source prefix. |
409 if (LowerCaseEqualsASCII(scheme_str, chrome::kViewSourceScheme) && | 415 if (LowerCaseEqualsASCII(scheme_str, chrome::kViewSourceScheme) && |
410 (static_cast<int>(text.length()) > after_scheme_and_colon)) { | 416 (static_cast<int>(text.length()) > after_scheme_and_colon)) { |
411 // Obtain the URL prefixed by view-source and parse it. | 417 // Obtain the URL prefixed by view-source and parse it. |
412 std::wstring real_url(text.substr(after_scheme_and_colon)); | 418 string16 real_url(text.substr(after_scheme_and_colon)); |
413 url_parse::Parsed real_parts; | 419 url_parse::Parsed real_parts; |
414 AutocompleteInput::Parse(real_url, desired_tld, &real_parts, NULL, NULL); | 420 AutocompleteInput::Parse(real_url, desired_tld, &real_parts, NULL, NULL); |
415 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { | 421 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { |
416 if (real_parts.scheme.is_nonempty()) { | 422 if (real_parts.scheme.is_nonempty()) { |
417 *scheme = url_parse::Component( | 423 *scheme = url_parse::Component( |
418 after_scheme_and_colon + real_parts.scheme.begin, | 424 after_scheme_and_colon + real_parts.scheme.begin, |
419 real_parts.scheme.len); | 425 real_parts.scheme.len); |
420 } else { | 426 } else { |
421 scheme->reset(); | 427 scheme->reset(); |
422 } | 428 } |
423 if (real_parts.host.is_nonempty()) { | 429 if (real_parts.host.is_nonempty()) { |
424 *host = url_parse::Component( | 430 *host = url_parse::Component( |
425 after_scheme_and_colon + real_parts.host.begin, | 431 after_scheme_and_colon + real_parts.host.begin, |
426 real_parts.host.len); | 432 real_parts.host.len); |
427 } else { | 433 } else { |
428 host->reset(); | 434 host->reset(); |
429 } | 435 } |
430 } | 436 } |
431 } | 437 } |
432 } | 438 } |
433 | 439 |
434 // static | 440 // static |
435 std::wstring AutocompleteInput::FormattedStringWithEquivalentMeaning( | 441 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
436 const GURL& url, | 442 const GURL& url, |
437 const std::wstring& formatted_url) { | 443 const string16& formatted_url) { |
438 if (!net::CanStripTrailingSlash(url)) | 444 if (!net::CanStripTrailingSlash(url)) |
439 return formatted_url; | 445 return formatted_url; |
440 const std::wstring url_with_path(formatted_url + L"/"); | 446 const string16 url_with_path(formatted_url + char16('/')); |
441 return (AutocompleteInput::Parse(formatted_url, std::wstring(), NULL, NULL, | 447 return (AutocompleteInput::Parse(formatted_url, string16(), NULL, NULL, |
442 NULL) == | 448 NULL) == |
443 AutocompleteInput::Parse(url_with_path, std::wstring(), NULL, NULL, | 449 AutocompleteInput::Parse(url_with_path, string16(), NULL, NULL, |
444 NULL)) ? | 450 NULL)) ? |
445 formatted_url : url_with_path; | 451 formatted_url : url_with_path; |
446 } | 452 } |
447 | 453 |
448 | 454 |
449 bool AutocompleteInput::Equals(const AutocompleteInput& other) const { | 455 bool AutocompleteInput::Equals(const AutocompleteInput& other) const { |
450 return (text_ == other.text_) && | 456 return (text_ == other.text_) && |
451 (type_ == other.type_) && | 457 (type_ == other.type_) && |
452 (desired_tld_ == other.desired_tld_) && | 458 (desired_tld_ == other.desired_tld_) && |
453 (scheme_ == other.scheme_) && | 459 (scheme_ == other.scheme_) && |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 } | 500 } |
495 | 501 |
496 void AutocompleteProvider::DeleteMatch(const AutocompleteMatch& match) { | 502 void AutocompleteProvider::DeleteMatch(const AutocompleteMatch& match) { |
497 } | 503 } |
498 | 504 |
499 AutocompleteProvider::~AutocompleteProvider() { | 505 AutocompleteProvider::~AutocompleteProvider() { |
500 Stop(); | 506 Stop(); |
501 } | 507 } |
502 | 508 |
503 // static | 509 // static |
504 bool AutocompleteProvider::HasHTTPScheme(const std::wstring& input) { | 510 bool AutocompleteProvider::HasHTTPScheme(const string16& input) { |
505 std::string utf8_input(WideToUTF8(input)); | 511 std::string utf8_input(UTF16ToUTF8(input)); |
506 url_parse::Component scheme; | 512 url_parse::Component scheme; |
507 if (url_util::FindAndCompareScheme(utf8_input, chrome::kViewSourceScheme, | 513 if (url_util::FindAndCompareScheme(utf8_input, chrome::kViewSourceScheme, |
508 &scheme)) | 514 &scheme)) |
509 utf8_input.erase(0, scheme.end() + 1); | 515 utf8_input.erase(0, scheme.end() + 1); |
510 return url_util::FindAndCompareScheme(utf8_input, chrome::kHttpScheme, NULL); | 516 return url_util::FindAndCompareScheme(utf8_input, chrome::kHttpScheme, NULL); |
511 } | 517 } |
512 | 518 |
513 void AutocompleteProvider::UpdateStarredStateOfMatches() { | 519 void AutocompleteProvider::UpdateStarredStateOfMatches() { |
514 if (matches_.empty()) | 520 if (matches_.empty()) |
515 return; | 521 return; |
516 | 522 |
517 if (!profile_) | 523 if (!profile_) |
518 return; | 524 return; |
519 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); | 525 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
520 if (!bookmark_model || !bookmark_model->IsLoaded()) | 526 if (!bookmark_model || !bookmark_model->IsLoaded()) |
521 return; | 527 return; |
522 | 528 |
523 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) | 529 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) |
524 i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url)); | 530 i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url)); |
525 } | 531 } |
526 | 532 |
527 std::wstring AutocompleteProvider::StringForURLDisplay(const GURL& url, | 533 string16 AutocompleteProvider::StringForURLDisplay(const GURL& url, |
528 bool check_accept_lang, | 534 bool check_accept_lang, |
529 bool trim_http) const { | 535 bool trim_http) const { |
530 std::string languages = (check_accept_lang && profile_) ? | 536 std::string languages = (check_accept_lang && profile_) ? |
531 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); | 537 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); |
532 return UTF16ToWideHack(net::FormatUrl( | 538 return net::FormatUrl( |
533 url, | 539 url, |
534 languages, | 540 languages, |
535 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), | 541 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), |
536 UnescapeRule::SPACES, NULL, NULL, NULL)); | 542 UnescapeRule::SPACES, NULL, NULL, NULL); |
537 } | 543 } |
538 | 544 |
539 // AutocompleteResult --------------------------------------------------------- | 545 // AutocompleteResult --------------------------------------------------------- |
540 | 546 |
541 // static | 547 // static |
542 const size_t AutocompleteResult::kMaxMatches = 6; | 548 const size_t AutocompleteResult::kMaxMatches = 6; |
543 | 549 |
544 void AutocompleteResult::Selection::Clear() { | 550 void AutocompleteResult::Selection::Clear() { |
545 destination_url = GURL(); | 551 destination_url = GURL(); |
546 provider_affinity = NULL; | 552 provider_affinity = NULL; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 } | 712 } |
707 | 713 |
708 void AutocompleteController::SetProfile(Profile* profile) { | 714 void AutocompleteController::SetProfile(Profile* profile) { |
709 Stop(true); | 715 Stop(true); |
710 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 716 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
711 (*i)->SetProfile(profile); | 717 (*i)->SetProfile(profile); |
712 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a | 718 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a |
713 // different profile. | 719 // different profile. |
714 } | 720 } |
715 | 721 |
716 void AutocompleteController::Start(const std::wstring& text, | 722 void AutocompleteController::Start(const string16& text, |
717 const std::wstring& desired_tld, | 723 const string16& desired_tld, |
718 bool prevent_inline_autocomplete, | 724 bool prevent_inline_autocomplete, |
719 bool prefer_keyword, | 725 bool prefer_keyword, |
720 bool allow_exact_keyword_match, | 726 bool allow_exact_keyword_match, |
721 bool synchronous_only) { | 727 bool synchronous_only) { |
722 const std::wstring old_input_text(input_.text()); | 728 const string16 old_input_text(input_.text()); |
723 const bool old_synchronous_only = input_.synchronous_only(); | 729 const bool old_synchronous_only = input_.synchronous_only(); |
724 input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete, | 730 input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete, |
725 prefer_keyword, allow_exact_keyword_match, synchronous_only); | 731 prefer_keyword, allow_exact_keyword_match, synchronous_only); |
726 | 732 |
727 // See if we can avoid rerunning autocomplete when the query hasn't changed | 733 // See if we can avoid rerunning autocomplete when the query hasn't changed |
728 // much. When the user presses or releases the ctrl key, the desired_tld | 734 // much. When the user presses or releases the ctrl key, the desired_tld |
729 // changes, and when the user finishes an IME composition, inline autocomplete | 735 // changes, and when the user finishes an IME composition, inline autocomplete |
730 // may no longer be prevented. In both these cases the text itself hasn't | 736 // may no longer be prevented. In both these cases the text itself hasn't |
731 // changed since the last query, and some providers can do much less work (and | 737 // changed since the last query, and some providers can do much less work (and |
732 // get matches back more quickly). Taking advantage of this reduces flicker. | 738 // get matches back more quickly). Taking advantage of this reduces flicker. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 void AutocompleteController::CheckIfDone() { | 894 void AutocompleteController::CheckIfDone() { |
889 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 895 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
890 ++i) { | 896 ++i) { |
891 if (!(*i)->done()) { | 897 if (!(*i)->done()) { |
892 done_ = false; | 898 done_ = false; |
893 return; | 899 return; |
894 } | 900 } |
895 } | 901 } |
896 done_ = true; | 902 done_ = true; |
897 } | 903 } |
OLD | NEW |