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.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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 | 83 |
84 GURL canonicalized_url; | 84 GURL canonicalized_url; |
85 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); | 85 type_ = Parse(text_, desired_tld, &parts_, &scheme_, &canonicalized_url); |
86 | 86 |
87 if (type_ == INVALID) | 87 if (type_ == INVALID) |
88 return; | 88 return; |
89 | 89 |
90 if (((type_ == UNKNOWN) || (type_ == REQUESTED_URL) || (type_ == URL)) && | 90 if (((type_ == UNKNOWN) || (type_ == REQUESTED_URL) || (type_ == URL)) && |
91 canonicalized_url.is_valid() && | 91 canonicalized_url.is_valid() && |
92 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || | 92 (!canonicalized_url.IsStandard() || canonicalized_url.SchemeIsFile() || |
93 canonicalized_url.SchemeIsFileSystem() || | |
93 !canonicalized_url.host().empty())) | 94 !canonicalized_url.host().empty())) |
94 canonicalized_url_ = canonicalized_url; | 95 canonicalized_url_ = canonicalized_url; |
95 | 96 |
96 RemoveForcedQueryStringIfNecessary(type_, &text_); | 97 RemoveForcedQueryStringIfNecessary(type_, &text_); |
97 } | 98 } |
98 | 99 |
99 AutocompleteInput::~AutocompleteInput() { | 100 AutocompleteInput::~AutocompleteInput() { |
100 } | 101 } |
101 | 102 |
102 // static | 103 // static |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 UTF16ToUTF8(desired_tld)); | 155 UTF16ToUTF8(desired_tld)); |
155 } | 156 } |
156 | 157 |
157 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { | 158 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { |
158 // A user might or might not type a scheme when entering a file URL. In | 159 // A user might or might not type a scheme when entering a file URL. In |
159 // either case, |parsed_scheme| will tell us that this is a file URL, but | 160 // either case, |parsed_scheme| will tell us that this is a file URL, but |
160 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". | 161 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". |
161 return URL; | 162 return URL; |
162 } | 163 } |
163 | 164 |
165 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileSystemScheme)) { | |
166 // This could theoretically be a strange search, but let's check. | |
167 ParseFileSystemURL(text.data(), text.length(), parts); | |
sky
2012/02/16 15:43:26
Is it really safe to reuse parts here?
ericu
2012/02/22 00:00:51
It would be if I'd remembered to clear out inner_p
| |
168 // If it's got an inner_url with a scheme, it's a URL, whether it's valid or | |
169 // not. | |
170 if (parts->inner_parsed() && parts->inner_parsed()->scheme.is_valid()) | |
171 return URL; | |
172 } | |
173 | |
164 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it | 174 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it |
165 // well enough that we can fall through to the heuristics below. If it's | 175 // well enough that we can fall through to the heuristics below. If it's |
166 // something else, we can just determine our action based on what we do with | 176 // something else, we can just determine our action based on what we do with |
167 // any input of this scheme. In theory we could do better with some schemes | 177 // any input of this scheme. In theory we could do better with some schemes |
168 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that | 178 // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that |
169 // until I run into some cases that really need it. | 179 // until I run into some cases that really need it. |
170 if (parts->scheme.is_nonempty() && | 180 if (parts->scheme.is_nonempty() && |
171 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpScheme) && | 181 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpScheme) && |
172 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpsScheme)) { | 182 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpsScheme)) { |
173 // See if we know how to handle the URL internally. | 183 // See if we know how to handle the URL internally. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 scheme->reset(); | 453 scheme->reset(); |
444 } | 454 } |
445 if (real_parts.host.is_nonempty()) { | 455 if (real_parts.host.is_nonempty()) { |
446 *host = url_parse::Component( | 456 *host = url_parse::Component( |
447 after_scheme_and_colon + real_parts.host.begin, | 457 after_scheme_and_colon + real_parts.host.begin, |
448 real_parts.host.len); | 458 real_parts.host.len); |
449 } else { | 459 } else { |
450 host->reset(); | 460 host->reset(); |
451 } | 461 } |
452 } | 462 } |
463 } else if (LowerCaseEqualsASCII(scheme_str, chrome::kFileSystemScheme) && | |
464 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { | |
465 *host = parts.inner_parsed()->host; | |
453 } | 466 } |
454 } | 467 } |
455 | 468 |
456 // static | 469 // static |
457 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 470 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
458 const GURL& url, | 471 const GURL& url, |
459 const string16& formatted_url) { | 472 const string16& formatted_url) { |
460 if (!net::CanStripTrailingSlash(url)) | 473 if (!net::CanStripTrailingSlash(url)) |
461 return formatted_url; | 474 return formatted_url; |
462 const string16 url_with_path(formatted_url + char16('/')); | 475 const string16 url_with_path(formatted_url + char16('/')); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 const AutocompleteResult& result) | 1092 const AutocompleteResult& result) |
1080 : text(text), | 1093 : text(text), |
1081 input_type(input_type), | 1094 input_type(input_type), |
1082 selected_index(selected_index), | 1095 selected_index(selected_index), |
1083 tab_id(tab_id), | 1096 tab_id(tab_id), |
1084 elapsed_time_since_user_first_modified_omnibox( | 1097 elapsed_time_since_user_first_modified_omnibox( |
1085 elapsed_time_since_user_first_modified_omnibox), | 1098 elapsed_time_since_user_first_modified_omnibox), |
1086 inline_autocompleted_length(inline_autocompleted_length), | 1099 inline_autocompleted_length(inline_autocompleted_length), |
1087 result(result) { | 1100 result(result) { |
1088 } | 1101 } |
OLD | NEW |