OLD | NEW |
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/autocomplete_input.h" | 5 #include "chrome/browser/autocomplete/autocomplete_input.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 9 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
10 #include "chrome/browser/profiles/profile_io_data.h" | 10 #include "chrome/browser/profiles/profile_io_data.h" |
11 #include "chrome/common/net/url_fixer_upper.h" | 11 #include "chrome/common/net/url_fixer_upper.h" |
12 #include "content/public/common/url_constants.h" | 12 #include "content/public/common/url_constants.h" |
13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
15 #include "url/url_canon_ip.h" | 15 #include "url/url_canon_ip.h" |
16 #include "url/url_util.h" | 16 #include "url/url_util.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, | 20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, |
21 size_t* cursor_position) { | 21 size_t* cursor_position) { |
22 if (*cursor_position == string16::npos) | 22 if (*cursor_position == base::string16::npos) |
23 return; | 23 return; |
24 if (num_leading_chars_removed < *cursor_position) | 24 if (num_leading_chars_removed < *cursor_position) |
25 *cursor_position -= num_leading_chars_removed; | 25 *cursor_position -= num_leading_chars_removed; |
26 else | 26 else |
27 *cursor_position = 0; | 27 *cursor_position = 0; |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 AutocompleteInput::AutocompleteInput() | 32 AutocompleteInput::AutocompleteInput() |
33 : cursor_position_(string16::npos), | 33 : cursor_position_(base::string16::npos), |
34 current_page_classification_(AutocompleteInput::INVALID_SPEC), | 34 current_page_classification_(AutocompleteInput::INVALID_SPEC), |
35 type_(INVALID), | 35 type_(INVALID), |
36 prevent_inline_autocomplete_(false), | 36 prevent_inline_autocomplete_(false), |
37 prefer_keyword_(false), | 37 prefer_keyword_(false), |
38 allow_exact_keyword_match_(true), | 38 allow_exact_keyword_match_(true), |
39 matches_requested_(ALL_MATCHES) { | 39 matches_requested_(ALL_MATCHES) { |
40 } | 40 } |
41 | 41 |
42 AutocompleteInput::AutocompleteInput( | 42 AutocompleteInput::AutocompleteInput( |
43 const string16& text, | 43 const base::string16& text, |
44 size_t cursor_position, | 44 size_t cursor_position, |
45 const string16& desired_tld, | 45 const base::string16& desired_tld, |
46 const GURL& current_url, | 46 const GURL& current_url, |
47 AutocompleteInput::PageClassification current_page_classification, | 47 AutocompleteInput::PageClassification current_page_classification, |
48 bool prevent_inline_autocomplete, | 48 bool prevent_inline_autocomplete, |
49 bool prefer_keyword, | 49 bool prefer_keyword, |
50 bool allow_exact_keyword_match, | 50 bool allow_exact_keyword_match, |
51 MatchesRequested matches_requested) | 51 MatchesRequested matches_requested) |
52 : cursor_position_(cursor_position), | 52 : cursor_position_(cursor_position), |
53 current_url_(current_url), | 53 current_url_(current_url), |
54 current_page_classification_(current_page_classification), | 54 current_page_classification_(current_page_classification), |
55 prevent_inline_autocomplete_(prevent_inline_autocomplete), | 55 prevent_inline_autocomplete_(prevent_inline_autocomplete), |
56 prefer_keyword_(prefer_keyword), | 56 prefer_keyword_(prefer_keyword), |
57 allow_exact_keyword_match_(allow_exact_keyword_match), | 57 allow_exact_keyword_match_(allow_exact_keyword_match), |
58 matches_requested_(matches_requested) { | 58 matches_requested_(matches_requested) { |
59 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos) | 59 DCHECK(cursor_position <= text.length() || |
| 60 cursor_position == base::string16::npos) |
60 << "Text: '" << text << "', cp: " << cursor_position; | 61 << "Text: '" << text << "', cp: " << cursor_position; |
61 // None of the providers care about leading white space so we always trim it. | 62 // None of the providers care about leading white space so we always trim it. |
62 // Providers that care about trailing white space handle trimming themselves. | 63 // Providers that care about trailing white space handle trimming themselves. |
63 if ((TrimWhitespace(text, TRIM_LEADING, &text_) & TRIM_LEADING) != 0) | 64 if ((TrimWhitespace(text, TRIM_LEADING, &text_) & TRIM_LEADING) != 0) |
64 AdjustCursorPositionIfNecessary(text.length() - text_.length(), | 65 AdjustCursorPositionIfNecessary(text.length() - text_.length(), |
65 &cursor_position_); | 66 &cursor_position_); |
66 | 67 |
67 GURL canonicalized_url; | 68 GURL canonicalized_url; |
68 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); | 69 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); |
69 | 70 |
70 if (type_ == INVALID) | 71 if (type_ == INVALID) |
71 return; | 72 return; |
72 | 73 |
73 if (((type_ == UNKNOWN) || (type_ == URL)) && | 74 if (((type_ == UNKNOWN) || (type_ == URL)) && |
74 canonicalized_url.is_valid() && | 75 canonicalized_url.is_valid() && |
75 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || | 76 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || |
76 canonicalized_url.SchemeIsFileSystem() || | 77 canonicalized_url.SchemeIsFileSystem() || |
77 !canonicalized_url.host().empty())) | 78 !canonicalized_url.host().empty())) |
78 canonicalized_url_ = canonicalized_url; | 79 canonicalized_url_ = canonicalized_url; |
79 | 80 |
80 size_t chars_removed = RemoveForcedQueryStringIfNecessary(type_, &text_); | 81 size_t chars_removed = RemoveForcedQueryStringIfNecessary(type_, &text_); |
81 AdjustCursorPositionIfNecessary(chars_removed, &cursor_position_); | 82 AdjustCursorPositionIfNecessary(chars_removed, &cursor_position_); |
82 if (chars_removed) { | 83 if (chars_removed) { |
83 // Remove spaces between opening question mark and first actual character. | 84 // Remove spaces between opening question mark and first actual character. |
84 string16 trimmed_text; | 85 base::string16 trimmed_text; |
85 if ((TrimWhitespace(text_, TRIM_LEADING, &trimmed_text) & TRIM_LEADING) != | 86 if ((TrimWhitespace(text_, TRIM_LEADING, &trimmed_text) & TRIM_LEADING) != |
86 0) { | 87 0) { |
87 AdjustCursorPositionIfNecessary(text_.length() - trimmed_text.length(), | 88 AdjustCursorPositionIfNecessary(text_.length() - trimmed_text.length(), |
88 &cursor_position_); | 89 &cursor_position_); |
89 text_ = trimmed_text; | 90 text_ = trimmed_text; |
90 } | 91 } |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 AutocompleteInput::~AutocompleteInput() { | 95 AutocompleteInput::~AutocompleteInput() { |
95 } | 96 } |
96 | 97 |
97 // static | 98 // static |
98 size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary(Type type, | 99 size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
99 string16* text) { | 100 Type type, |
| 101 base::string16* text) { |
100 if (type != FORCED_QUERY || text->empty() || (*text)[0] != L'?') | 102 if (type != FORCED_QUERY || text->empty() || (*text)[0] != L'?') |
101 return 0; | 103 return 0; |
102 // Drop the leading '?'. | 104 // Drop the leading '?'. |
103 text->erase(0, 1); | 105 text->erase(0, 1); |
104 return 1; | 106 return 1; |
105 } | 107 } |
106 | 108 |
107 // static | 109 // static |
108 std::string AutocompleteInput::TypeToString(Type type) { | 110 std::string AutocompleteInput::TypeToString(Type type) { |
109 switch (type) { | 111 switch (type) { |
(...skipping 10 matching lines...) Expand all Loading... |
120 } | 122 } |
121 | 123 |
122 // static | 124 // static |
123 AutocompleteInput::Type AutocompleteInput::Parse( | 125 AutocompleteInput::Type AutocompleteInput::Parse( |
124 const base::string16& text, | 126 const base::string16& text, |
125 const base::string16& desired_tld, | 127 const base::string16& desired_tld, |
126 url_parse::Parsed* parts, | 128 url_parse::Parsed* parts, |
127 base::string16* scheme, | 129 base::string16* scheme, |
128 GURL* canonicalized_url) { | 130 GURL* canonicalized_url) { |
129 size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0); | 131 size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0); |
130 if (first_non_white == string16::npos) | 132 if (first_non_white == base::string16::npos) |
131 return INVALID; // All whitespace. | 133 return INVALID; // All whitespace. |
132 | 134 |
133 if (text.at(first_non_white) == L'?') { | 135 if (text.at(first_non_white) == L'?') { |
134 // If the first non-whitespace character is a '?', we magically treat this | 136 // If the first non-whitespace character is a '?', we magically treat this |
135 // as a query. | 137 // as a query. |
136 return FORCED_QUERY; | 138 return FORCED_QUERY; |
137 } | 139 } |
138 | 140 |
139 // Ask our parsing back-end to help us understand what the user typed. We | 141 // Ask our parsing back-end to help us understand what the user typed. We |
140 // use the URLFixerUpper here because we want to be smart about what we | 142 // use the URLFixerUpper here because we want to be smart about what we |
141 // consider a scheme. For example, we shouldn't consider www.google.com:80 | 143 // consider a scheme. For example, we shouldn't consider www.google.com:80 |
142 // to have a scheme. | 144 // to have a scheme. |
143 url_parse::Parsed local_parts; | 145 url_parse::Parsed local_parts; |
144 if (!parts) | 146 if (!parts) |
145 parts = &local_parts; | 147 parts = &local_parts; |
146 const string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); | 148 const base::string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); |
147 if (scheme) | 149 if (scheme) |
148 *scheme = parsed_scheme; | 150 *scheme = parsed_scheme; |
149 if (canonicalized_url) { | 151 if (canonicalized_url) { |
150 *canonicalized_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), | 152 *canonicalized_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), |
151 UTF16ToUTF8(desired_tld)); | 153 UTF16ToUTF8(desired_tld)); |
152 } | 154 } |
153 | 155 |
154 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { | 156 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { |
155 // A user might or might not type a scheme when entering a file URL. In | 157 // A user might or might not type a scheme when entering a file URL. In |
156 // either case, |parsed_scheme| will tell us that this is a file URL, but | 158 // either case, |parsed_scheme| will tell us that this is a file URL, but |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return URL; | 203 return URL; |
202 | 204 |
203 case ExternalProtocolHandler::BLOCK: | 205 case ExternalProtocolHandler::BLOCK: |
204 // If we don't want the user to open the URL, don't let it be navigated | 206 // If we don't want the user to open the URL, don't let it be navigated |
205 // to at all. | 207 // to at all. |
206 return QUERY; | 208 return QUERY; |
207 | 209 |
208 default: { | 210 default: { |
209 // We don't know about this scheme. It might be that the user typed a | 211 // We don't know about this scheme. It might be that the user typed a |
210 // URL of the form "username:password@foo.com". | 212 // URL of the form "username:password@foo.com". |
211 const string16 http_scheme_prefix = | 213 const base::string16 http_scheme_prefix = |
212 ASCIIToUTF16(std::string(content::kHttpScheme) + | 214 ASCIIToUTF16(std::string(content::kHttpScheme) + |
213 content::kStandardSchemeSeparator); | 215 content::kStandardSchemeSeparator); |
214 url_parse::Parsed http_parts; | 216 url_parse::Parsed http_parts; |
215 string16 http_scheme; | 217 base::string16 http_scheme; |
216 GURL http_canonicalized_url; | 218 GURL http_canonicalized_url; |
217 Type http_type = Parse(http_scheme_prefix + text, desired_tld, | 219 Type http_type = Parse(http_scheme_prefix + text, desired_tld, |
218 &http_parts, &http_scheme, | 220 &http_parts, &http_scheme, |
219 &http_canonicalized_url); | 221 &http_canonicalized_url); |
220 DCHECK_EQ(std::string(content::kHttpScheme), UTF16ToUTF8(http_scheme)); | 222 DCHECK_EQ(std::string(content::kHttpScheme), UTF16ToUTF8(http_scheme)); |
221 | 223 |
222 if (http_type == URL && | 224 if (http_type == URL && |
223 http_parts.username.is_nonempty() && | 225 http_parts.username.is_nonempty() && |
224 http_parts.password.is_nonempty()) { | 226 http_parts.password.is_nonempty()) { |
225 // Manually re-jigger the parsed parts to match |text| (without the | 227 // Manually re-jigger the parsed parts to match |text| (without the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 // Either the user didn't type a scheme, in which case we need to distinguish | 264 // Either the user didn't type a scheme, in which case we need to distinguish |
263 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which | 265 // between an HTTP URL and a query, or the scheme is HTTP or HTTPS, in which |
264 // case we should reject invalid formulations. | 266 // case we should reject invalid formulations. |
265 | 267 |
266 // If we have an empty host it can't be a URL. | 268 // If we have an empty host it can't be a URL. |
267 if (!parts->host.is_nonempty()) | 269 if (!parts->host.is_nonempty()) |
268 return QUERY; | 270 return QUERY; |
269 | 271 |
270 // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also | 272 // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also |
271 // use the registry length later below.) | 273 // use the registry length later below.) |
272 const string16 host(text.substr(parts->host.begin, parts->host.len)); | 274 const base::string16 host(text.substr(parts->host.begin, parts->host.len)); |
273 const size_t registry_length = | 275 const size_t registry_length = |
274 net::registry_controlled_domains::GetRegistryLength( | 276 net::registry_controlled_domains::GetRegistryLength( |
275 UTF16ToUTF8(host), | 277 UTF16ToUTF8(host), |
276 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 278 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
277 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 279 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
278 if (registry_length == std::string::npos) { | 280 if (registry_length == std::string::npos) { |
279 // Try to append the desired_tld. | 281 // Try to append the desired_tld. |
280 if (!desired_tld.empty()) { | 282 if (!desired_tld.empty()) { |
281 string16 host_with_tld(host); | 283 base::string16 host_with_tld(host); |
282 if (host[host.length() - 1] != '.') | 284 if (host[host.length() - 1] != '.') |
283 host_with_tld += '.'; | 285 host_with_tld += '.'; |
284 host_with_tld += desired_tld; | 286 host_with_tld += desired_tld; |
285 const size_t tld_length = | 287 const size_t tld_length = |
286 net::registry_controlled_domains::GetRegistryLength( | 288 net::registry_controlled_domains::GetRegistryLength( |
287 UTF16ToUTF8(host_with_tld), | 289 UTF16ToUTF8(host_with_tld), |
288 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 290 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
289 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 291 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
290 if (tld_length != std::string::npos) | 292 if (tld_length != std::string::npos) |
291 return URL; // Something like "99999999999" that looks like a bad IP | 293 return URL; // Something like "99999999999" that looks like a bad IP |
(...skipping 25 matching lines...) Expand all Loading... |
317 // Note that we explicitly excluded hosts with spaces above so that | 319 // Note that we explicitly excluded hosts with spaces above so that |
318 // "toys at amazon.com" will be treated as a search. | 320 // "toys at amazon.com" will be treated as a search. |
319 // * The user is typing some garbage string. Return QUERY. | 321 // * The user is typing some garbage string. Return QUERY. |
320 // | 322 // |
321 // Thus we fall down in the following cases: | 323 // Thus we fall down in the following cases: |
322 // * Trying to navigate to a hostname with spaces | 324 // * Trying to navigate to a hostname with spaces |
323 // * Trying to navigate to a hostname with invalid characters and an unknown | 325 // * Trying to navigate to a hostname with invalid characters and an unknown |
324 // TLD | 326 // TLD |
325 // These are rare, though probably possible in intranets. | 327 // These are rare, though probably possible in intranets. |
326 return (parts->scheme.is_nonempty() || | 328 return (parts->scheme.is_nonempty() || |
327 ((registry_length != 0) && (host.find(' ') == string16::npos))) ? | 329 ((registry_length != 0) && |
328 UNKNOWN : QUERY; | 330 (host.find(' ') == base::string16::npos))) ? UNKNOWN : QUERY; |
329 } | 331 } |
330 | 332 |
331 // A port number is a good indicator that this is a URL. However, it might | 333 // A port number is a good indicator that this is a URL. However, it might |
332 // also be a query like "1.66:1" that looks kind of like an IP address and | 334 // also be a query like "1.66:1" that looks kind of like an IP address and |
333 // port number. So here we only check for "port numbers" that are illegal and | 335 // port number. So here we only check for "port numbers" that are illegal and |
334 // thus mean this can't be navigated to (e.g. "1.2.3.4:garbage"), and we save | 336 // thus mean this can't be navigated to (e.g. "1.2.3.4:garbage"), and we save |
335 // handling legal port numbers until after the "IP address" determination | 337 // handling legal port numbers until after the "IP address" determination |
336 // below. | 338 // below. |
337 if (url_parse::ParsePort(text.c_str(), parts->port) == | 339 if (url_parse::ParsePort(text.c_str(), parts->port) == |
338 url_parse::PORT_INVALID) | 340 url_parse::PORT_INVALID) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 // * A "URL-like" string that's not really a URL (like | 418 // * A "URL-like" string that's not really a URL (like |
417 // "browser.tabs.closeButtons" or "java.awt.event.*"). This is ideally a | 419 // "browser.tabs.closeButtons" or "java.awt.event.*"). This is ideally a |
418 // QUERY. Since this is indistinguishable from the case above, and this | 420 // QUERY. Since this is indistinguishable from the case above, and this |
419 // case is much more likely, claim these are UNKNOWN, which should default | 421 // case is much more likely, claim these are UNKNOWN, which should default |
420 // to the right thing and let users correct us on a case-by-case basis. | 422 // to the right thing and let users correct us on a case-by-case basis. |
421 return UNKNOWN; | 423 return UNKNOWN; |
422 } | 424 } |
423 | 425 |
424 // static | 426 // static |
425 void AutocompleteInput::ParseForEmphasizeComponents( | 427 void AutocompleteInput::ParseForEmphasizeComponents( |
426 const string16& text, | 428 const base::string16& text, |
427 url_parse::Component* scheme, | 429 url_parse::Component* scheme, |
428 url_parse::Component* host) { | 430 url_parse::Component* host) { |
429 url_parse::Parsed parts; | 431 url_parse::Parsed parts; |
430 string16 scheme_str; | 432 base::string16 scheme_str; |
431 Parse(text, string16(), &parts, &scheme_str, NULL); | 433 Parse(text, base::string16(), &parts, &scheme_str, NULL); |
432 | 434 |
433 *scheme = parts.scheme; | 435 *scheme = parts.scheme; |
434 *host = parts.host; | 436 *host = parts.host; |
435 | 437 |
436 int after_scheme_and_colon = parts.scheme.end() + 1; | 438 int after_scheme_and_colon = parts.scheme.end() + 1; |
437 // For the view-source scheme, we should emphasize the scheme and host of the | 439 // For the view-source scheme, we should emphasize the scheme and host of the |
438 // URL qualified by the view-source prefix. | 440 // URL qualified by the view-source prefix. |
439 if (LowerCaseEqualsASCII(scheme_str, content::kViewSourceScheme) && | 441 if (LowerCaseEqualsASCII(scheme_str, content::kViewSourceScheme) && |
440 (static_cast<int>(text.length()) > after_scheme_and_colon)) { | 442 (static_cast<int>(text.length()) > after_scheme_and_colon)) { |
441 // Obtain the URL prefixed by view-source and parse it. | 443 // Obtain the URL prefixed by view-source and parse it. |
442 string16 real_url(text.substr(after_scheme_and_colon)); | 444 base::string16 real_url(text.substr(after_scheme_and_colon)); |
443 url_parse::Parsed real_parts; | 445 url_parse::Parsed real_parts; |
444 AutocompleteInput::Parse(real_url, string16(), &real_parts, NULL, NULL); | 446 AutocompleteInput::Parse(real_url, base::string16(), &real_parts, NULL, NULL
); |
445 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { | 447 if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { |
446 if (real_parts.scheme.is_nonempty()) { | 448 if (real_parts.scheme.is_nonempty()) { |
447 *scheme = url_parse::Component( | 449 *scheme = url_parse::Component( |
448 after_scheme_and_colon + real_parts.scheme.begin, | 450 after_scheme_and_colon + real_parts.scheme.begin, |
449 real_parts.scheme.len); | 451 real_parts.scheme.len); |
450 } else { | 452 } else { |
451 scheme->reset(); | 453 scheme->reset(); |
452 } | 454 } |
453 if (real_parts.host.is_nonempty()) { | 455 if (real_parts.host.is_nonempty()) { |
454 *host = url_parse::Component( | 456 *host = url_parse::Component( |
455 after_scheme_and_colon + real_parts.host.begin, | 457 after_scheme_and_colon + real_parts.host.begin, |
456 real_parts.host.len); | 458 real_parts.host.len); |
457 } else { | 459 } else { |
458 host->reset(); | 460 host->reset(); |
459 } | 461 } |
460 } | 462 } |
461 } else if (LowerCaseEqualsASCII(scheme_str, chrome::kFileSystemScheme) && | 463 } else if (LowerCaseEqualsASCII(scheme_str, chrome::kFileSystemScheme) && |
462 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { | 464 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { |
463 *host = parts.inner_parsed()->host; | 465 *host = parts.inner_parsed()->host; |
464 } | 466 } |
465 } | 467 } |
466 | 468 |
467 // static | 469 // static |
468 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 470 base::string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
469 const GURL& url, | 471 const GURL& url, |
470 const string16& formatted_url) { | 472 const base::string16& formatted_url) { |
471 if (!net::CanStripTrailingSlash(url)) | 473 if (!net::CanStripTrailingSlash(url)) |
472 return formatted_url; | 474 return formatted_url; |
473 const string16 url_with_path(formatted_url + char16('/')); | 475 const base::string16 url_with_path(formatted_url + char16('/')); |
474 return (AutocompleteInput::Parse(formatted_url, string16(), NULL, NULL, | 476 return (AutocompleteInput::Parse(formatted_url, base::string16(), NULL, NULL, |
475 NULL) == | 477 NULL) == |
476 AutocompleteInput::Parse(url_with_path, string16(), NULL, NULL, | 478 AutocompleteInput::Parse(url_with_path, base::string16(), NULL, NULL, |
477 NULL)) ? | 479 NULL)) ? |
478 formatted_url : url_with_path; | 480 formatted_url : url_with_path; |
479 } | 481 } |
480 | 482 |
481 // static | 483 // static |
482 int AutocompleteInput::NumNonHostComponents(const url_parse::Parsed& parts) { | 484 int AutocompleteInput::NumNonHostComponents(const url_parse::Parsed& parts) { |
483 int num_nonhost_components = 0; | 485 int num_nonhost_components = 0; |
484 if (parts.scheme.is_nonempty()) | 486 if (parts.scheme.is_nonempty()) |
485 ++num_nonhost_components; | 487 ++num_nonhost_components; |
486 if (parts.username.is_nonempty()) | 488 if (parts.username.is_nonempty()) |
487 ++num_nonhost_components; | 489 ++num_nonhost_components; |
488 if (parts.password.is_nonempty()) | 490 if (parts.password.is_nonempty()) |
489 ++num_nonhost_components; | 491 ++num_nonhost_components; |
490 if (parts.port.is_nonempty()) | 492 if (parts.port.is_nonempty()) |
491 ++num_nonhost_components; | 493 ++num_nonhost_components; |
492 if (parts.path.is_nonempty()) | 494 if (parts.path.is_nonempty()) |
493 ++num_nonhost_components; | 495 ++num_nonhost_components; |
494 if (parts.query.is_nonempty()) | 496 if (parts.query.is_nonempty()) |
495 ++num_nonhost_components; | 497 ++num_nonhost_components; |
496 if (parts.ref.is_nonempty()) | 498 if (parts.ref.is_nonempty()) |
497 ++num_nonhost_components; | 499 ++num_nonhost_components; |
498 return num_nonhost_components; | 500 return num_nonhost_components; |
499 } | 501 } |
500 | 502 |
501 // static | 503 // static |
502 bool AutocompleteInput::HasHTTPScheme(const string16& input) { | 504 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) { |
503 std::string utf8_input(UTF16ToUTF8(input)); | 505 std::string utf8_input(UTF16ToUTF8(input)); |
504 url_parse::Component scheme; | 506 url_parse::Component scheme; |
505 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, | 507 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, |
506 &scheme)) | 508 &scheme)) |
507 utf8_input.erase(0, scheme.end() + 1); | 509 utf8_input.erase(0, scheme.end() + 1); |
508 return url_util::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL); | 510 return url_util::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL); |
509 } | 511 } |
510 | 512 |
511 void AutocompleteInput::UpdateText(const string16& text, | 513 void AutocompleteInput::UpdateText(const base::string16& text, |
512 size_t cursor_position, | 514 size_t cursor_position, |
513 const url_parse::Parsed& parts) { | 515 const url_parse::Parsed& parts) { |
514 DCHECK(cursor_position <= text.length() || cursor_position == string16::npos) | 516 DCHECK(cursor_position <= text.length() || |
| 517 cursor_position == base::string16::npos) |
515 << "Text: '" << text << "', cp: " << cursor_position; | 518 << "Text: '" << text << "', cp: " << cursor_position; |
516 text_ = text; | 519 text_ = text; |
517 cursor_position_ = cursor_position; | 520 cursor_position_ = cursor_position; |
518 parts_ = parts; | 521 parts_ = parts; |
519 } | 522 } |
520 | 523 |
521 void AutocompleteInput::Clear() { | 524 void AutocompleteInput::Clear() { |
522 text_.clear(); | 525 text_.clear(); |
523 cursor_position_ = string16::npos; | 526 cursor_position_ = base::string16::npos; |
524 current_url_ = GURL(); | 527 current_url_ = GURL(); |
525 current_page_classification_ = AutocompleteInput::INVALID_SPEC; | 528 current_page_classification_ = AutocompleteInput::INVALID_SPEC; |
526 type_ = INVALID; | 529 type_ = INVALID; |
527 parts_ = url_parse::Parsed(); | 530 parts_ = url_parse::Parsed(); |
528 scheme_.clear(); | 531 scheme_.clear(); |
529 canonicalized_url_ = GURL(); | 532 canonicalized_url_ = GURL(); |
530 prevent_inline_autocomplete_ = false; | 533 prevent_inline_autocomplete_ = false; |
531 prefer_keyword_ = false; | 534 prefer_keyword_ = false; |
532 allow_exact_keyword_match_ = false; | 535 allow_exact_keyword_match_ = false; |
533 matches_requested_ = ALL_MATCHES; | 536 matches_requested_ = ALL_MATCHES; |
534 } | 537 } |
OLD | NEW |