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_provider.h" | 5 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // This probably won't happen, but there are no guarantees. | 147 // This probably won't happen, but there are no guarantees. |
148 return failed; | 148 return failed; |
149 } | 149 } |
150 | 150 |
151 // If the user types a number, GURL will convert it to a dotted quad. | 151 // If the user types a number, GURL will convert it to a dotted quad. |
152 // However, if the parser did not mark this as a URL, then the user probably | 152 // However, if the parser did not mark this as a URL, then the user probably |
153 // didn't intend this interpretation. Since this can break history matching | 153 // didn't intend this interpretation. Since this can break history matching |
154 // for hostname beginning with numbers (e.g. input of "17173" will be matched | 154 // for hostname beginning with numbers (e.g. input of "17173" will be matched |
155 // against "0.0.67.21" instead of the original "17173", failing to find | 155 // against "0.0.67.21" instead of the original "17173", failing to find |
156 // "17173.com"), swap the original hostname in for the fixed-up one. | 156 // "17173.com"), swap the original hostname in for the fixed-up one. |
157 if ((input.type() != metrics::OmniboxInputType::URL) && | 157 if ((input.type() != AutocompleteInput::URL) && |
158 canonical_gurl.HostIsIPAddress()) { | 158 canonical_gurl.HostIsIPAddress()) { |
159 std::string original_hostname = | 159 std::string original_hostname = |
160 base::UTF16ToUTF8(input_text.substr(input.parts().host.begin, | 160 base::UTF16ToUTF8(input_text.substr(input.parts().host.begin, |
161 input.parts().host.len)); | 161 input.parts().host.len)); |
162 const url::Parsed& parts = | 162 const url::Parsed& parts = |
163 canonical_gurl.parsed_for_possibly_invalid_spec(); | 163 canonical_gurl.parsed_for_possibly_invalid_spec(); |
164 // parts.host must not be empty when HostIsIPAddress() is true. | 164 // parts.host must not be empty when HostIsIPAddress() is true. |
165 DCHECK(parts.host.is_nonempty()); | 165 DCHECK(parts.host.is_nonempty()); |
166 canonical_gurl_str.replace(parts.host.begin, parts.host.len, | 166 canonical_gurl_str.replace(parts.host.begin, parts.host.len, |
167 original_hostname); | 167 original_hostname); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 // Erase scheme plus up to two slashes. | 218 // Erase scheme plus up to two slashes. |
219 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; | 219 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; |
220 const size_t after_slashes = std::min(url->length(), prefix_end + 2); | 220 const size_t after_slashes = std::min(url->length(), prefix_end + 2); |
221 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) | 221 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) |
222 ++prefix_end; | 222 ++prefix_end; |
223 url->erase(scheme_pos, prefix_end - scheme_pos); | 223 url->erase(scheme_pos, prefix_end - scheme_pos); |
224 return (scheme_pos == 0) ? prefix_end : 0; | 224 return (scheme_pos == 0) ? prefix_end : 0; |
225 } | 225 } |
226 | 226 |
OLD | NEW |