| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/autocomplete_provider.h" | 5 #include "components/omnibox/browser/autocomplete_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/omnibox/browser/autocomplete_input.h" | 9 #include "components/omnibox/browser/autocomplete_input.h" |
| 10 #include "components/omnibox/browser/autocomplete_match.h" | 10 #include "components/omnibox/browser/autocomplete_match.h" |
| 11 #include "components/url_fixer/url_fixer.h" | 11 #include "components/url_formatter/url_fixer.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 const size_t AutocompleteProvider::kMaxMatches = 3; | 16 const size_t AutocompleteProvider::kMaxMatches = 3; |
| 17 | 17 |
| 18 AutocompleteProvider::AutocompleteProvider(Type type) | 18 AutocompleteProvider::AutocompleteProvider(Type type) |
| 19 : done_(true), | 19 : done_(true), |
| 20 type_(type) { | 20 type_(type) { |
| 21 } | 21 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 AutocompleteProvider::FixupReturn AutocompleteProvider::FixupUserInput( | 98 AutocompleteProvider::FixupReturn AutocompleteProvider::FixupUserInput( |
| 99 const AutocompleteInput& input) { | 99 const AutocompleteInput& input) { |
| 100 const base::string16& input_text = input.text(); | 100 const base::string16& input_text = input.text(); |
| 101 const FixupReturn failed(false, input_text); | 101 const FixupReturn failed(false, input_text); |
| 102 | 102 |
| 103 // Fixup and canonicalize user input. | 103 // Fixup and canonicalize user input. |
| 104 const GURL canonical_gurl( | 104 const GURL canonical_gurl( |
| 105 url_fixer::FixupURL(base::UTF16ToUTF8(input_text), std::string())); | 105 url_formatter::FixupURL(base::UTF16ToUTF8(input_text), std::string())); |
| 106 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); | 106 std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); |
| 107 if (canonical_gurl_str.empty()) { | 107 if (canonical_gurl_str.empty()) { |
| 108 // This probably won't happen, but there are no guarantees. | 108 // This probably won't happen, but there are no guarantees. |
| 109 return failed; | 109 return failed; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // If the user types a number, GURL will convert it to a dotted quad. | 112 // If the user types a number, GURL will convert it to a dotted quad. |
| 113 // However, if the parser did not mark this as a URL, then the user probably | 113 // However, if the parser did not mark this as a URL, then the user probably |
| 114 // didn't intend this interpretation. Since this can break history matching | 114 // didn't intend this interpretation. Since this can break history matching |
| 115 // for hostname beginning with numbers (e.g. input of "17173" will be matched | 115 // for hostname beginning with numbers (e.g. input of "17173" will be matched |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 DCHECK_NE(base::string16::npos, scheme_pos); | 177 DCHECK_NE(base::string16::npos, scheme_pos); |
| 178 | 178 |
| 179 // Erase scheme plus up to two slashes. | 179 // Erase scheme plus up to two slashes. |
| 180 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; | 180 size_t prefix_end = scheme_pos + strlen(url::kHttpScheme) + 1; |
| 181 const size_t after_slashes = std::min(url->length(), prefix_end + 2); | 181 const size_t after_slashes = std::min(url->length(), prefix_end + 2); |
| 182 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) | 182 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) |
| 183 ++prefix_end; | 183 ++prefix_end; |
| 184 url->erase(scheme_pos, prefix_end - scheme_pos); | 184 url->erase(scheme_pos, prefix_end - scheme_pos); |
| 185 return (scheme_pos == 0) ? prefix_end : 0; | 185 return (scheme_pos == 0) ? prefix_end : 0; |
| 186 } | 186 } |
| OLD | NEW |