| 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/history_provider.h" | 5 #include "chrome/browser/autocomplete/history_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const url_parse::Parsed& parts = | 88 const url_parse::Parsed& parts = |
| 89 canonical_gurl.parsed_for_possibly_invalid_spec(); | 89 canonical_gurl.parsed_for_possibly_invalid_spec(); |
| 90 // parts.host must not be empty when HostIsIPAddress() is true. | 90 // parts.host must not be empty when HostIsIPAddress() is true. |
| 91 DCHECK(parts.host.is_nonempty()); | 91 DCHECK(parts.host.is_nonempty()); |
| 92 canonical_gurl_str.replace(parts.host.begin, parts.host.len, | 92 canonical_gurl_str.replace(parts.host.begin, parts.host.len, |
| 93 original_hostname); | 93 original_hostname); |
| 94 } | 94 } |
| 95 string16 output = UTF8ToUTF16(canonical_gurl_str); | 95 string16 output = UTF8ToUTF16(canonical_gurl_str); |
| 96 // Don't prepend a scheme when the user didn't have one. Since the fixer | 96 // Don't prepend a scheme when the user didn't have one. Since the fixer |
| 97 // upper only prepends the "http" scheme, that's all we need to check for. | 97 // upper only prepends the "http" scheme, that's all we need to check for. |
| 98 if (!HasHTTPScheme(input_text)) | 98 if (!AutocompleteInput::HasHTTPScheme(input_text)) |
| 99 TrimHttpPrefix(&output); | 99 TrimHttpPrefix(&output); |
| 100 | 100 |
| 101 // Make the number of trailing slashes on the output exactly match the input. | 101 // Make the number of trailing slashes on the output exactly match the input. |
| 102 // Examples of why not doing this would matter: | 102 // Examples of why not doing this would matter: |
| 103 // * The user types "a" and has this fixed up to "a/". Now no other sites | 103 // * The user types "a" and has this fixed up to "a/". Now no other sites |
| 104 // beginning with "a" will match. | 104 // beginning with "a" will match. |
| 105 // * The user types "file:" and has this fixed up to "file://". Now inline | 105 // * The user types "file:" and has this fixed up to "file://". Now inline |
| 106 // autocomplete will append too few slashes, resulting in e.g. "file:/b..." | 106 // autocomplete will append too few slashes, resulting in e.g. "file:/b..." |
| 107 // instead of "file:///b..." | 107 // instead of "file:///b..." |
| 108 // * The user types "http:/" and has this fixed up to "http:". Now inline | 108 // * The user types "http:/" and has this fixed up to "http:". Now inline |
| (...skipping 19 matching lines...) Expand all Loading... |
| 128 | 128 |
| 129 url_parse::Parsed parts; | 129 url_parse::Parsed parts; |
| 130 URLFixerUpper::SegmentURL(output, &parts); | 130 URLFixerUpper::SegmentURL(output, &parts); |
| 131 input->UpdateText(output, string16::npos, parts); | 131 input->UpdateText(output, string16::npos, parts); |
| 132 return !output.empty(); | 132 return !output.empty(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // static | 135 // static |
| 136 size_t HistoryProvider::TrimHttpPrefix(string16* url) { | 136 size_t HistoryProvider::TrimHttpPrefix(string16* url) { |
| 137 // Find any "http:". | 137 // Find any "http:". |
| 138 if (!HasHTTPScheme(*url)) | 138 if (!AutocompleteInput::HasHTTPScheme(*url)) |
| 139 return 0; | 139 return 0; |
| 140 size_t scheme_pos = | 140 size_t scheme_pos = |
| 141 url->find(ASCIIToUTF16(content::kHttpScheme) + char16(':')); | 141 url->find(ASCIIToUTF16(content::kHttpScheme) + char16(':')); |
| 142 DCHECK_NE(string16::npos, scheme_pos); | 142 DCHECK_NE(string16::npos, scheme_pos); |
| 143 | 143 |
| 144 // Erase scheme plus up to two slashes. | 144 // Erase scheme plus up to two slashes. |
| 145 size_t prefix_end = scheme_pos + strlen(content::kHttpScheme) + 1; | 145 size_t prefix_end = scheme_pos + strlen(content::kHttpScheme) + 1; |
| 146 const size_t after_slashes = std::min(url->length(), prefix_end + 2); | 146 const size_t after_slashes = std::min(url->length(), prefix_end + 2); |
| 147 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) | 147 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) |
| 148 ++prefix_end; | 148 ++prefix_end; |
| 149 url->erase(scheme_pos, prefix_end - scheme_pos); | 149 url->erase(scheme_pos, prefix_end - scheme_pos); |
| 150 return (scheme_pos == 0) ? prefix_end : 0; | 150 return (scheme_pos == 0) ? prefix_end : 0; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // static | 153 // static |
| 154 bool HistoryProvider::PreventInlineAutocomplete( | 154 bool HistoryProvider::PreventInlineAutocomplete( |
| 155 const AutocompleteInput& input) { | 155 const AutocompleteInput& input) { |
| 156 return input.prevent_inline_autocomplete() || | 156 return input.prevent_inline_autocomplete() || |
| 157 (!input.text().empty() && | 157 (!input.text().empty() && |
| 158 IsWhitespace(input.text()[input.text().length() - 1])); | 158 IsWhitespace(input.text()[input.text().length() - 1])); |
| 159 } | 159 } |
| OLD | NEW |