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 "net/base/url_constants.h" |
15 #include "url/url_canon_ip.h" | 16 #include "url/url_canon_ip.h" |
16 #include "url/url_util.h" | 17 #include "url/url_util.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, | 21 void AdjustCursorPositionIfNecessary(size_t num_leading_chars_removed, |
21 size_t* cursor_position) { | 22 size_t* cursor_position) { |
22 if (*cursor_position == base::string16::npos) | 23 if (*cursor_position == base::string16::npos) |
23 return; | 24 return; |
24 if (num_leading_chars_removed < *cursor_position) | 25 if (num_leading_chars_removed < *cursor_position) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return URL; | 173 return URL; |
173 } | 174 } |
174 | 175 |
175 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it | 176 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it |
176 // well enough that we can fall through to the heuristics below. If it's | 177 // well enough that we can fall through to the heuristics below. If it's |
177 // something else, we can just determine our action based on what we do with | 178 // something else, we can just determine our action based on what we do with |
178 // any input of this scheme. In theory we could do better with some schemes | 179 // any input of this scheme. In theory we could do better with some schemes |
179 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that | 180 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that |
180 // until I run into some cases that really need it. | 181 // until I run into some cases that really need it. |
181 if (parts->scheme.is_nonempty() && | 182 if (parts->scheme.is_nonempty() && |
182 !LowerCaseEqualsASCII(parsed_scheme, content::kHttpScheme) && | 183 !LowerCaseEqualsASCII(parsed_scheme, net::kHttpScheme) && |
183 !LowerCaseEqualsASCII(parsed_scheme, content::kHttpsScheme)) { | 184 !LowerCaseEqualsASCII(parsed_scheme, net::kHttpsScheme)) { |
184 // See if we know how to handle the URL internally. There are some schemes | 185 // See if we know how to handle the URL internally. There are some schemes |
185 // that we convert to other things before they reach the renderer or else | 186 // that we convert to other things before they reach the renderer or else |
186 // the renderer handles internally without reaching the net::URLRequest | 187 // the renderer handles internally without reaching the net::URLRequest |
187 // logic. They thus won't be listed as "handled protocols", but we should | 188 // logic. They thus won't be listed as "handled protocols", but we should |
188 // still claim to handle them. | 189 // still claim to handle them. |
189 if (ProfileIOData::IsHandledProtocol(base::UTF16ToASCII(parsed_scheme)) || | 190 if (ProfileIOData::IsHandledProtocol(base::UTF16ToASCII(parsed_scheme)) || |
190 LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) || | 191 LowerCaseEqualsASCII(parsed_scheme, content::kViewSourceScheme) || |
191 LowerCaseEqualsASCII(parsed_scheme, content::kJavaScriptScheme) || | 192 LowerCaseEqualsASCII(parsed_scheme, content::kJavaScriptScheme) || |
192 LowerCaseEqualsASCII(parsed_scheme, content::kDataScheme)) | 193 LowerCaseEqualsASCII(parsed_scheme, content::kDataScheme)) |
193 return return_value_for_non_http_url; | 194 return return_value_for_non_http_url; |
(...skipping 15 matching lines...) Expand all Loading... |
209 return return_value_for_non_http_url; | 210 return return_value_for_non_http_url; |
210 | 211 |
211 case ExternalProtocolHandler::BLOCK: | 212 case ExternalProtocolHandler::BLOCK: |
212 // If we don't want the user to open the URL, don't let it be navigated | 213 // If we don't want the user to open the URL, don't let it be navigated |
213 // to at all. | 214 // to at all. |
214 return QUERY; | 215 return QUERY; |
215 | 216 |
216 default: { | 217 default: { |
217 // We don't know about this scheme. It might be that the user typed a | 218 // We don't know about this scheme. It might be that the user typed a |
218 // URL of the form "username:password@foo.com". | 219 // URL of the form "username:password@foo.com". |
219 const base::string16 http_scheme_prefix = | 220 const base::string16 http_scheme_prefix = base::ASCIIToUTF16( |
220 base::ASCIIToUTF16(std::string(content::kHttpScheme) + | 221 std::string(net::kHttpScheme) + content::kStandardSchemeSeparator); |
221 content::kStandardSchemeSeparator); | |
222 url_parse::Parsed http_parts; | 222 url_parse::Parsed http_parts; |
223 base::string16 http_scheme; | 223 base::string16 http_scheme; |
224 GURL http_canonicalized_url; | 224 GURL http_canonicalized_url; |
225 Type http_type = Parse(http_scheme_prefix + text, desired_tld, | 225 Type http_type = Parse(http_scheme_prefix + text, desired_tld, |
226 &http_parts, &http_scheme, | 226 &http_parts, &http_scheme, |
227 &http_canonicalized_url); | 227 &http_canonicalized_url); |
228 DCHECK_EQ(std::string(content::kHttpScheme), | 228 DCHECK_EQ(std::string(net::kHttpScheme), |
229 base::UTF16ToUTF8(http_scheme)); | 229 base::UTF16ToUTF8(http_scheme)); |
230 | 230 |
231 if ((http_type == URL) && http_parts.username.is_nonempty() && | 231 if ((http_type == URL) && http_parts.username.is_nonempty() && |
232 http_parts.password.is_nonempty()) { | 232 http_parts.password.is_nonempty()) { |
233 // Manually re-jigger the parsed parts to match |text| (without the | 233 // Manually re-jigger the parsed parts to match |text| (without the |
234 // http scheme added). | 234 // http scheme added). |
235 http_parts.scheme.reset(); | 235 http_parts.scheme.reset(); |
236 url_parse::Component* components[] = { | 236 url_parse::Component* components[] = { |
237 &http_parts.username, | 237 &http_parts.username, |
238 &http_parts.password, | 238 &http_parts.password, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 return num_nonhost_components; | 505 return num_nonhost_components; |
506 } | 506 } |
507 | 507 |
508 // static | 508 // static |
509 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) { | 509 bool AutocompleteInput::HasHTTPScheme(const base::string16& input) { |
510 std::string utf8_input(base::UTF16ToUTF8(input)); | 510 std::string utf8_input(base::UTF16ToUTF8(input)); |
511 url_parse::Component scheme; | 511 url_parse::Component scheme; |
512 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, | 512 if (url_util::FindAndCompareScheme(utf8_input, content::kViewSourceScheme, |
513 &scheme)) | 513 &scheme)) |
514 utf8_input.erase(0, scheme.end() + 1); | 514 utf8_input.erase(0, scheme.end() + 1); |
515 return url_util::FindAndCompareScheme(utf8_input, content::kHttpScheme, NULL); | 515 return url_util::FindAndCompareScheme(utf8_input, net::kHttpScheme, NULL); |
516 } | 516 } |
517 | 517 |
518 void AutocompleteInput::UpdateText(const base::string16& text, | 518 void AutocompleteInput::UpdateText(const base::string16& text, |
519 size_t cursor_position, | 519 size_t cursor_position, |
520 const url_parse::Parsed& parts) { | 520 const url_parse::Parsed& parts) { |
521 DCHECK(cursor_position <= text.length() || | 521 DCHECK(cursor_position <= text.length() || |
522 cursor_position == base::string16::npos) | 522 cursor_position == base::string16::npos) |
523 << "Text: '" << text << "', cp: " << cursor_position; | 523 << "Text: '" << text << "', cp: " << cursor_position; |
524 text_ = text; | 524 text_ = text; |
525 cursor_position_ = cursor_position; | 525 cursor_position_ = cursor_position; |
526 parts_ = parts; | 526 parts_ = parts; |
527 } | 527 } |
528 | 528 |
529 void AutocompleteInput::Clear() { | 529 void AutocompleteInput::Clear() { |
530 text_.clear(); | 530 text_.clear(); |
531 cursor_position_ = base::string16::npos; | 531 cursor_position_ = base::string16::npos; |
532 current_url_ = GURL(); | 532 current_url_ = GURL(); |
533 current_page_classification_ = AutocompleteInput::INVALID_SPEC; | 533 current_page_classification_ = AutocompleteInput::INVALID_SPEC; |
534 type_ = INVALID; | 534 type_ = INVALID; |
535 parts_ = url_parse::Parsed(); | 535 parts_ = url_parse::Parsed(); |
536 scheme_.clear(); | 536 scheme_.clear(); |
537 canonicalized_url_ = GURL(); | 537 canonicalized_url_ = GURL(); |
538 prevent_inline_autocomplete_ = false; | 538 prevent_inline_autocomplete_ = false; |
539 prefer_keyword_ = false; | 539 prefer_keyword_ = false; |
540 allow_exact_keyword_match_ = false; | 540 allow_exact_keyword_match_ = false; |
541 want_asynchronous_matches_ = true; | 541 want_asynchronous_matches_ = true; |
542 } | 542 } |
OLD | NEW |