| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // to have a scheme. | 146 // to have a scheme. |
| 146 url_parse::Parsed local_parts; | 147 url_parse::Parsed local_parts; |
| 147 if (!parts) | 148 if (!parts) |
| 148 parts = &local_parts; | 149 parts = &local_parts; |
| 149 const string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); | 150 const string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); |
| 150 if (scheme) | 151 if (scheme) |
| 151 *scheme = parsed_scheme; | 152 *scheme = parsed_scheme; |
| 152 if (canonicalized_url) { | 153 if (canonicalized_url) { |
| 153 *canonicalized_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), | 154 *canonicalized_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), |
| 154 UTF16ToUTF8(desired_tld)); | 155 UTF16ToUTF8(desired_tld)); |
| 156 return URL; |
| 155 } | 157 } |
| 156 | 158 |
| 157 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { | 159 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { |
| 158 // A user might or might not type a scheme when entering a file URL. In | 160 // 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 | 161 // 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". | 162 // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". |
| 161 return URL; | 163 return URL; |
| 162 } | 164 } |
| 163 | 165 |
| 166 if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileSystemScheme)) { |
| 167 // This could theoretically be a strange search, but let's check. |
| 168 ParseFileSystemURL(text.data(), text.length(), parts); |
| 169 // If it's got an inner_url with a scheme, it's a URL, whether it's valid or |
| 170 // not. |
| 171 if (parts->inner_parsed() && parts->inner_parsed()->scheme.is_valid()) |
| 172 return URL; |
| 173 } |
| 174 |
| 164 // If the user typed a scheme, and it's HTTP or HTTPS, we know how to parse it | 175 // 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 | 176 // 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 | 177 // 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 | 178 // 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 | 179 // (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. | 180 // until I run into some cases that really need it. |
| 170 if (parts->scheme.is_nonempty() && | 181 if (parts->scheme.is_nonempty() && |
| 171 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpScheme) && | 182 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpScheme) && |
| 172 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpsScheme)) { | 183 !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpsScheme)) { |
| 173 // See if we know how to handle the URL internally. | 184 // 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(); | 454 scheme->reset(); |
| 444 } | 455 } |
| 445 if (real_parts.host.is_nonempty()) { | 456 if (real_parts.host.is_nonempty()) { |
| 446 *host = url_parse::Component( | 457 *host = url_parse::Component( |
| 447 after_scheme_and_colon + real_parts.host.begin, | 458 after_scheme_and_colon + real_parts.host.begin, |
| 448 real_parts.host.len); | 459 real_parts.host.len); |
| 449 } else { | 460 } else { |
| 450 host->reset(); | 461 host->reset(); |
| 451 } | 462 } |
| 452 } | 463 } |
| 464 } else if (LowerCaseEqualsASCII(scheme_str, chrome::kFileSystemScheme) && |
| 465 parts.inner_parsed() && parts.inner_parsed()->scheme.is_valid()) { |
| 466 *host = parts.inner_parsed()->host; |
| 453 } | 467 } |
| 454 } | 468 } |
| 455 | 469 |
| 456 // static | 470 // static |
| 457 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 471 string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 458 const GURL& url, | 472 const GURL& url, |
| 459 const string16& formatted_url) { | 473 const string16& formatted_url) { |
| 460 if (!net::CanStripTrailingSlash(url)) | 474 if (!net::CanStripTrailingSlash(url)) |
| 461 return formatted_url; | 475 return formatted_url; |
| 462 const string16 url_with_path(formatted_url + char16('/')); | 476 const string16 url_with_path(formatted_url + char16('/')); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 } | 1071 } |
| 1058 done_ = true; | 1072 done_ = true; |
| 1059 } | 1073 } |
| 1060 | 1074 |
| 1061 void AutocompleteController::StartExpireTimer() { | 1075 void AutocompleteController::StartExpireTimer() { |
| 1062 if (result_.HasCopiedMatches()) | 1076 if (result_.HasCopiedMatches()) |
| 1063 expire_timer_.Start(FROM_HERE, | 1077 expire_timer_.Start(FROM_HERE, |
| 1064 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 1078 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
| 1065 this, &AutocompleteController::ExpireCopiedEntries); | 1079 this, &AutocompleteController::ExpireCopiedEntries); |
| 1066 } | 1080 } |
| OLD | NEW |