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 "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.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)) { |
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 ExternalProtocolHandler::BlockState block_state = |
| 180 ExternalProtocolHandler::GetBlockState(UTF16ToUTF8(parsed_scheme)); |
| 181 switch (block_state) { |
179 case ExternalProtocolHandler::DONT_BLOCK: | 182 case ExternalProtocolHandler::DONT_BLOCK: |
180 return URL; | 183 return URL; |
181 | 184 |
182 case ExternalProtocolHandler::BLOCK: | 185 case ExternalProtocolHandler::BLOCK: |
183 // If we don't want the user to open the URL, don't let it be navigated | 186 // If we don't want the user to open the URL, don't let it be navigated |
184 // to at all. | 187 // to at all. |
185 return QUERY; | 188 return QUERY; |
186 | 189 |
187 default: { | 190 default: { |
188 // We don't know about this scheme. It might be that the user typed a | 191 // We don't know about this scheme. It might be that the user typed a |
189 // URL of the form "username:password@foo.com". | 192 // URL of the form "username:password@foo.com". |
190 const std::wstring http_scheme_prefix = L"http://"; | 193 const string16 http_scheme_prefix = |
| 194 ASCIIToUTF16(std::string(chrome::kHttpScheme) + |
| 195 chrome::kStandardSchemeSeparator); |
191 url_parse::Parsed http_parts; | 196 url_parse::Parsed http_parts; |
192 std::wstring http_scheme; | 197 string16 http_scheme; |
193 GURL http_canonicalized_url; | 198 GURL http_canonicalized_url; |
194 Type http_type = Parse(http_scheme_prefix + text, desired_tld, | 199 Type http_type = Parse(http_scheme_prefix + text, desired_tld, |
195 &http_parts, &http_scheme, | 200 &http_parts, &http_scheme, |
196 &http_canonicalized_url); | 201 &http_canonicalized_url); |
197 DCHECK_EQ("http", WideToUTF8(http_scheme)); | 202 DCHECK_EQ(std::string(chrome::kHttpScheme), UTF16ToUTF8(http_scheme)); |
198 | 203 |
199 if ((http_type == URL || http_type == REQUESTED_URL) && | 204 if ((http_type == URL || http_type == REQUESTED_URL) && |
200 http_parts.username.is_nonempty() && | 205 http_parts.username.is_nonempty() && |
201 http_parts.password.is_nonempty()) { | 206 http_parts.password.is_nonempty()) { |
202 // Manually re-jigger the parsed parts to match |text| (without the | 207 // Manually re-jigger the parsed parts to match |text| (without the |
203 // http scheme added). | 208 // http scheme added). |
204 http_parts.scheme.reset(); | 209 http_parts.scheme.reset(); |
205 url_parse::Component* components[] = { | 210 url_parse::Component* components[] = { |
206 &http_parts.username, | 211 &http_parts.username, |
207 &http_parts.password, | 212 &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 | 244 // 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 | 245 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which |
241 // case we should reject invalid formulations. | 246 // case we should reject invalid formulations. |
242 | 247 |
243 // If we have an empty host it can't be a URL. | 248 // If we have an empty host it can't be a URL. |
244 if (!parts->host.is_nonempty()) | 249 if (!parts->host.is_nonempty()) |
245 return QUERY; | 250 return QUERY; |
246 | 251 |
247 // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also | 252 // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also |
248 // use the registry length later below.) | 253 // use the registry length later below.) |
249 const std::wstring host(text.substr(parts->host.begin, parts->host.len)); | 254 const string16 host(text.substr(parts->host.begin, parts->host.len)); |
250 const size_t registry_length = | 255 const size_t registry_length = |
251 net::RegistryControlledDomainService::GetRegistryLength(host, false); | 256 net::RegistryControlledDomainService::GetRegistryLength(UTF16ToUTF8(host), |
252 if (registry_length == std::wstring::npos) { | 257 false); |
| 258 if (registry_length == std::string::npos) { |
253 // Try to append the desired_tld. | 259 // Try to append the desired_tld. |
254 if (!desired_tld.empty()) { | 260 if (!desired_tld.empty()) { |
255 std::wstring host_with_tld(host); | 261 string16 host_with_tld(host); |
256 if (host[host.length() - 1] != '.') | 262 if (host[host.length() - 1] != '.') |
257 host_with_tld += '.'; | 263 host_with_tld += '.'; |
258 host_with_tld += desired_tld; | 264 host_with_tld += desired_tld; |
259 if (net::RegistryControlledDomainService::GetRegistryLength( | 265 if (net::RegistryControlledDomainService::GetRegistryLength( |
260 host_with_tld, false) != std::wstring::npos) | 266 UTF16ToUTF8(host_with_tld), false) != std::string::npos) |
261 return REQUESTED_URL; // Something like "99999999999" that looks like a | 267 return REQUESTED_URL; // Something like "99999999999" that looks like a |
262 // bad IP address, but becomes valid on attaching | 268 // bad IP address, but becomes valid on attaching |
263 // a TLD. | 269 // a TLD. |
264 } | 270 } |
265 return QUERY; // Could be a broken IP address, etc. | 271 return QUERY; // Could be a broken IP address, etc. |
266 } | 272 } |
267 | 273 |
268 | 274 |
269 // See if the hostname is valid. While IE and GURL allow hostnames to contain | 275 // 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 | 276 // 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 | 277 // unlikely that a user would be trying to type those in for anything other |
272 // than a search query. | 278 // than a search query. |
273 url_canon::CanonHostInfo host_info; | 279 url_canon::CanonHostInfo host_info; |
274 const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); | 280 const std::string canonicalized_host(net::CanonicalizeHost(UTF16ToUTF8(host), |
| 281 &host_info)); |
275 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && | 282 if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && |
276 !net::IsCanonicalizedHostCompliant(canonicalized_host, | 283 !net::IsCanonicalizedHostCompliant(canonicalized_host, |
277 WideToUTF8(desired_tld))) { | 284 UTF16ToUTF8(desired_tld))) { |
278 // Invalid hostname. There are several possible cases: | 285 // Invalid hostname. There are several possible cases: |
279 // * Our checker is too strict and the user pasted in a real-world URL | 286 // * 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 | 287 // 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 | 288 // the user explicitly typed a scheme, so we'll still search by default |
282 // but we'll show the accidental search infobar if necessary. | 289 // 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 | 290 // * 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. | 291 // 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 | 292 // * 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. | 293 // 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 | 294 // Note that we explicitly excluded hosts with spaces above so that |
288 // "toys at amazon.com" will be treated as a search. | 295 // "toys at amazon.com" will be treated as a search. |
289 // * The user is typing some garbage string. Return QUERY. | 296 // * The user is typing some garbage string. Return QUERY. |
290 // | 297 // |
291 // Thus we fall down in the following cases: | 298 // Thus we fall down in the following cases: |
292 // * Trying to navigate to a hostname with spaces | 299 // * Trying to navigate to a hostname with spaces |
293 // * Trying to navigate to a hostname with invalid characters and an unknown | 300 // * Trying to navigate to a hostname with invalid characters and an unknown |
294 // TLD | 301 // TLD |
295 // These are rare, though probably possible in intranets. | 302 // These are rare, though probably possible in intranets. |
296 return (parts->scheme.is_nonempty() || | 303 return (parts->scheme.is_nonempty() || |
297 ((registry_length != 0) && (host.find(' ') == std::wstring::npos))) ? | 304 ((registry_length != 0) && (host.find(' ') == string16::npos))) ? |
298 UNKNOWN : QUERY; | 305 UNKNOWN : QUERY; |
299 } | 306 } |
300 | 307 |
301 // A port number is a good indicator that this is a URL. However, it might | 308 // 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 | 309 // 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 | 310 // 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 | 311 // 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 | 312 // handling legal port numbers until after the "IP address" determination |
306 // below. | 313 // below. |
307 if (parts->port.is_nonempty()) { | 314 if (parts->port.is_nonempty()) { |
308 int port; | 315 int port; |
309 if (!base::StringToInt(WideToUTF8( | 316 if (!base::StringToInt(text.substr(parts->port.begin, parts->port.len), |
310 text.substr(parts->port.begin, parts->port.len)), &port) || | 317 &port) || |
311 (port < 0) || (port > 65535)) | 318 (port < 0) || (port > 65535)) |
312 return QUERY; | 319 return QUERY; |
313 } | 320 } |
314 | 321 |
315 // Now that we've ruled out all schemes other than http or https and done a | 322 // 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 | 323 // little more sanity checking, the presence of a scheme means this is likely |
317 // a URL. | 324 // a URL. |
318 if (parts->scheme.is_nonempty()) | 325 if (parts->scheme.is_nonempty()) |
319 return URL; | 326 return URL; |
320 | 327 |
(...skipping 28 matching lines...) Expand all Loading... |
349 if (parts->path.is_nonempty()) { | 356 if (parts->path.is_nonempty()) { |
350 // Most inputs with paths are URLs, even ones without known registries (e.g. | 357 // 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 | 358 // 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 | 359 // 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 | 360 // (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 | 361 // 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 | 362 // them if users have typed them in the past, but we default to searching |
356 // since that's the common case. | 363 // since that's the common case. |
357 return ((registry_length == 0) && | 364 return ((registry_length == 0) && |
358 (text.substr(parts->path.begin, parts->path.len).find(' ') != | 365 (text.substr(parts->path.begin, parts->path.len).find(' ') != |
359 std::wstring::npos)) ? UNKNOWN : URL; | 366 string16::npos)) ? UNKNOWN : URL; |
360 } | 367 } |
361 | 368 |
362 // If we reach here with a username, our input looks like "user@host". | 369 // 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 | 370 // 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 | 371 // 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. | 372 // default and let users correct us on a case-by-case basis. |
366 if (parts->username.is_nonempty()) | 373 if (parts->username.is_nonempty()) |
367 return UNKNOWN; | 374 return UNKNOWN; |
368 | 375 |
369 // We have a bare host string. If it has a known TLD, it's probably a URL. | 376 // 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 | 392 // "browser.tabs.closeButtons" or "java.awt.event.*"). This is ideally a |
386 // QUERY. Since the above case and this one are indistinguishable, and this | 393 // 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, | 394 // 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 | 395 // which should default to the right thing and let users correct us on a |
389 // case-by-case basis. | 396 // case-by-case basis. |
390 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; | 397 return desired_tld.empty() ? UNKNOWN : REQUESTED_URL; |
391 } | 398 } |
392 | 399 |
393 // static | 400 // static |
394 void AutocompleteInput::ParseForEmphasizeComponents( | 401 void AutocompleteInput::ParseForEmphasizeComponents( |
395 const std::wstring& text, | 402 const string16& text, |
396 const std::wstring& desired_tld, | 403 const string16& desired_tld, |
397 url_parse::Component* scheme, | 404 url_parse::Component* scheme, |
398 url_parse::Component* host) { | 405 url_parse::Component* host) { |
399 url_parse::Parsed parts; | 406 url_parse::Parsed parts; |
400 std::wstring scheme_str; | 407 string16 scheme_str; |
401 Parse(text, desired_tld, &parts, &scheme_str, NULL); | 408 Parse(text, desired_tld, &parts, &scheme_str, NULL); |
402 | 409 |
403 *scheme = parts.scheme; | 410 *scheme = parts.scheme; |
404 *host = parts.host; | 411 *host = parts.host; |
405 | 412 |
406 int after_scheme_and_colon = parts.scheme.end() + 1; | 413 int after_scheme_and_colon = parts.scheme.end() + 1; |
407 // For the view-source scheme, we should emphasize the scheme and host of the | 414 // For the view-source scheme, we should emphasize the scheme and host of the |
408 // URL qualified by the view-source prefix. | 415 // URL qualified by the view-source prefix. |
409 if (LowerCaseEqualsASCII(scheme_str, chrome::kViewSourceScheme) && | 416 if (LowerCaseEqualsASCII(scheme_str, chrome::kViewSourceScheme) && |
410 (static_cast<int>(text.length()) > after_scheme_and_colon)) { | 417 (static_cast<int>(text.length()) > after_scheme_and_colon)) { |
411 // Obtain the URL prefixed by view-source and parse it. | 418 // Obtain the URL prefixed by view-source and parse it. |
412 std::wstring real_url(text.substr(after_scheme_and_colon)); | 419 string16 real_url(text.substr(after_scheme_and_colon)); |
413 url_parse::Parsed real_parts; | 420 url_parse::Parsed real_parts; |
414 AutocompleteInput::Parse(real_url, desired_tld, &real_parts, NULL, NULL); | 421 AutocompleteInput::Parse(real_url, desired_tld, &real_parts, NULL, NULL); |
415 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { | 422 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { |
416 if (real_parts.scheme.is_nonempty()) { | 423 if (real_parts.scheme.is_nonempty()) { |
417 *scheme = url_parse::Component( | 424 *scheme = url_parse::Component( |
418 after_scheme_and_colon + real_parts.scheme.begin, | 425 after_scheme_and_colon + real_parts.scheme.begin, |
419 real_parts.scheme.len); | 426 real_parts.scheme.len); |
420 } else { | 427 } else { |
421 scheme->reset(); | 428 scheme->reset(); |
422 } | 429 } |
423 if (real_parts.host.is_nonempty()) { | 430 if (real_parts.host.is_nonempty()) { |
424 *host = url_parse::Component( | 431 *host = url_parse::Component( |
425 after_scheme_and_colon + real_parts.host.begin, | 432 after_scheme_and_colon + real_parts.host.begin, |
426 real_parts.host.len); | 433 real_parts.host.len); |
427 } else { | 434 } else { |
428 host->reset(); | 435 host->reset(); |
429 } | 436 } |
430 } | 437 } |
431 } | 438 } |
432 } | 439 } |
433 | 440 |
434 // static | 441 // static |
435 std::wstring AutocompleteInput::FormattedStringWithEquivalentMeaning( | 442 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
436 const GURL& url, | 443 const GURL& url, |
437 const std::wstring& formatted_url) { | 444 const string16& formatted_url) { |
438 if (!net::CanStripTrailingSlash(url)) | 445 if (!net::CanStripTrailingSlash(url)) |
439 return formatted_url; | 446 return formatted_url; |
440 const std::wstring url_with_path(formatted_url + L"/"); | 447 const string16 url_with_path(formatted_url + char16('/')); |
441 return (AutocompleteInput::Parse(formatted_url, std::wstring(), NULL, NULL, | 448 return (AutocompleteInput::Parse(formatted_url, string16(), NULL, NULL, |
442 NULL) == | 449 NULL) == |
443 AutocompleteInput::Parse(url_with_path, std::wstring(), NULL, NULL, | 450 AutocompleteInput::Parse(url_with_path, string16(), NULL, NULL, |
444 NULL)) ? | 451 NULL)) ? |
445 formatted_url : url_with_path; | 452 formatted_url : url_with_path; |
446 } | 453 } |
447 | 454 |
448 | 455 |
449 bool AutocompleteInput::Equals(const AutocompleteInput& other) const { | 456 bool AutocompleteInput::Equals(const AutocompleteInput& other) const { |
450 return (text_ == other.text_) && | 457 return (text_ == other.text_) && |
451 (type_ == other.type_) && | 458 (type_ == other.type_) && |
452 (desired_tld_ == other.desired_tld_) && | 459 (desired_tld_ == other.desired_tld_) && |
453 (scheme_ == other.scheme_) && | 460 (scheme_ == other.scheme_) && |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 501 } |
495 | 502 |
496 void AutocompleteProvider::DeleteMatch(const AutocompleteMatch& match) { | 503 void AutocompleteProvider::DeleteMatch(const AutocompleteMatch& match) { |
497 } | 504 } |
498 | 505 |
499 AutocompleteProvider::~AutocompleteProvider() { | 506 AutocompleteProvider::~AutocompleteProvider() { |
500 Stop(); | 507 Stop(); |
501 } | 508 } |
502 | 509 |
503 // static | 510 // static |
504 bool AutocompleteProvider::HasHTTPScheme(const std::wstring& input) { | 511 bool AutocompleteProvider::HasHTTPScheme(const string16& input) { |
505 std::string utf8_input(WideToUTF8(input)); | 512 std::string utf8_input(UTF16ToUTF8(input)); |
506 url_parse::Component scheme; | 513 url_parse::Component scheme; |
507 if (url_util::FindAndCompareScheme(utf8_input, chrome::kViewSourceScheme, | 514 if (url_util::FindAndCompareScheme(utf8_input, chrome::kViewSourceScheme, |
508 &scheme)) | 515 &scheme)) |
509 utf8_input.erase(0, scheme.end() + 1); | 516 utf8_input.erase(0, scheme.end() + 1); |
510 return url_util::FindAndCompareScheme(utf8_input, chrome::kHttpScheme, NULL); | 517 return url_util::FindAndCompareScheme(utf8_input, chrome::kHttpScheme, NULL); |
511 } | 518 } |
512 | 519 |
513 void AutocompleteProvider::UpdateStarredStateOfMatches() { | 520 void AutocompleteProvider::UpdateStarredStateOfMatches() { |
514 if (matches_.empty()) | 521 if (matches_.empty()) |
515 return; | 522 return; |
516 | 523 |
517 if (!profile_) | 524 if (!profile_) |
518 return; | 525 return; |
519 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); | 526 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
520 if (!bookmark_model || !bookmark_model->IsLoaded()) | 527 if (!bookmark_model || !bookmark_model->IsLoaded()) |
521 return; | 528 return; |
522 | 529 |
523 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) | 530 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) |
524 i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url)); | 531 i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url)); |
525 } | 532 } |
526 | 533 |
527 std::wstring AutocompleteProvider::StringForURLDisplay(const GURL& url, | 534 string16 AutocompleteProvider::StringForURLDisplay(const GURL& url, |
528 bool check_accept_lang, | 535 bool check_accept_lang, |
529 bool trim_http) const { | 536 bool trim_http) const { |
530 std::string languages = (check_accept_lang && profile_) ? | 537 std::string languages = (check_accept_lang && profile_) ? |
531 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); | 538 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); |
532 return UTF16ToWideHack(net::FormatUrl( | 539 return net::FormatUrl( |
533 url, | 540 url, |
534 languages, | 541 languages, |
535 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), | 542 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), |
536 UnescapeRule::SPACES, NULL, NULL, NULL)); | 543 UnescapeRule::SPACES, NULL, NULL, NULL); |
537 } | 544 } |
538 | 545 |
539 // AutocompleteResult --------------------------------------------------------- | 546 // AutocompleteResult --------------------------------------------------------- |
540 | 547 |
541 // static | 548 // static |
542 const size_t AutocompleteResult::kMaxMatches = 6; | 549 const size_t AutocompleteResult::kMaxMatches = 6; |
543 | 550 |
544 void AutocompleteResult::Selection::Clear() { | 551 void AutocompleteResult::Selection::Clear() { |
545 destination_url = GURL(); | 552 destination_url = GURL(); |
546 provider_affinity = NULL; | 553 provider_affinity = NULL; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 } | 713 } |
707 | 714 |
708 void AutocompleteController::SetProfile(Profile* profile) { | 715 void AutocompleteController::SetProfile(Profile* profile) { |
709 Stop(true); | 716 Stop(true); |
710 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 717 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
711 (*i)->SetProfile(profile); | 718 (*i)->SetProfile(profile); |
712 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a | 719 input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a |
713 // different profile. | 720 // different profile. |
714 } | 721 } |
715 | 722 |
716 void AutocompleteController::Start(const std::wstring& text, | 723 void AutocompleteController::Start(const string16& text, |
717 const std::wstring& desired_tld, | 724 const string16& desired_tld, |
718 bool prevent_inline_autocomplete, | 725 bool prevent_inline_autocomplete, |
719 bool prefer_keyword, | 726 bool prefer_keyword, |
720 bool allow_exact_keyword_match, | 727 bool allow_exact_keyword_match, |
721 bool synchronous_only) { | 728 bool synchronous_only) { |
722 const std::wstring old_input_text(input_.text()); | 729 const string16 old_input_text(input_.text()); |
723 const bool old_synchronous_only = input_.synchronous_only(); | 730 const bool old_synchronous_only = input_.synchronous_only(); |
724 input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete, | 731 input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete, |
725 prefer_keyword, allow_exact_keyword_match, synchronous_only); | 732 prefer_keyword, allow_exact_keyword_match, synchronous_only); |
726 | 733 |
727 // See if we can avoid rerunning autocomplete when the query hasn't changed | 734 // 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 | 735 // 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 | 736 // 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 | 737 // 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 | 738 // 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. | 739 // 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() { | 895 void AutocompleteController::CheckIfDone() { |
889 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 896 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
890 ++i) { | 897 ++i) { |
891 if (!(*i)->done()) { | 898 if (!(*i)->done()) { |
892 done_ = false; | 899 done_ = false; |
893 return; | 900 return; |
894 } | 901 } |
895 } | 902 } |
896 done_ = true; | 903 done_ = true; |
897 } | 904 } |
OLD | NEW |