| 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 "components/omnibox/browser/history_url_provider.h" | 5 #include "components/omnibox/browser/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 564 |
| 565 AutocompleteMatch match(this, 0, false, | 565 AutocompleteMatch match(this, 0, false, |
| 566 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 566 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 567 | 567 |
| 568 if (destination_url.is_valid()) { | 568 if (destination_url.is_valid()) { |
| 569 match.destination_url = destination_url; | 569 match.destination_url = destination_url; |
| 570 | 570 |
| 571 // Trim off "http://" if the user didn't type it. | 571 // Trim off "http://" if the user didn't type it. |
| 572 DCHECK(!trim_http || | 572 DCHECK(!trim_http || |
| 573 !AutocompleteInput::HasHTTPScheme(input.text())); | 573 !AutocompleteInput::HasHTTPScheme(input.text())); |
| 574 base::string16 display_string( | 574 auto format_types = AutocompleteMatch::GetFormatTypes(false); |
| 575 AutocompleteMatch::FormatUrlForSuggestionDisplay( | 575 base::string16 display_string(url_formatter::FormatUrl( |
| 576 destination_url, false /* trim_scheme */, nullptr)); | 576 destination_url, format_types, net::UnescapeRule::SPACES, nullptr, |
| 577 nullptr, nullptr)); |
| 577 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; | 578 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; |
| 578 match.fill_into_edit = | 579 match.fill_into_edit = |
| 579 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 580 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 580 destination_url, display_string, client()->GetSchemeClassifier()); | 581 destination_url, display_string, client()->GetSchemeClassifier()); |
| 581 // The what-you-typed match is generally only allowed to be default for | 582 // The what-you-typed match is generally only allowed to be default for |
| 582 // URL inputs or when there is no default search provider. (It's also | 583 // URL inputs or when there is no default search provider. (It's also |
| 583 // allowed to be default for UNKNOWN inputs where the destination is a known | 584 // allowed to be default for UNKNOWN inputs where the destination is a known |
| 584 // intranet site. In this case, |allowed_to_be_default_match| is revised in | 585 // intranet site. In this case, |allowed_to_be_default_match| is revised in |
| 585 // FixupExactSuggestion().) | 586 // FixupExactSuggestion().) |
| 586 const bool has_default_search_provider = | 587 const bool has_default_search_provider = |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 | 1135 |
| 1135 const history::HistoryMatch& history_match = params.matches[match_number]; | 1136 const history::HistoryMatch& history_match = params.matches[match_number]; |
| 1136 const history::URLRow& info = history_match.url_info; | 1137 const history::URLRow& info = history_match.url_info; |
| 1137 AutocompleteMatch match(this, relevance, | 1138 AutocompleteMatch match(this, relevance, |
| 1138 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); | 1139 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); |
| 1139 match.typed_count = info.typed_count(); | 1140 match.typed_count = info.typed_count(); |
| 1140 match.destination_url = info.url(); | 1141 match.destination_url = info.url(); |
| 1141 DCHECK(match.destination_url.is_valid()); | 1142 DCHECK(match.destination_url.is_valid()); |
| 1142 size_t inline_autocomplete_offset = | 1143 size_t inline_autocomplete_offset = |
| 1143 history_match.input_location + params.input.text().length(); | 1144 history_match.input_location + params.input.text().length(); |
| 1144 const url_formatter::FormatUrlTypes format_types = | 1145 |
| 1145 url_formatter::kFormatUrlOmitAll & | 1146 auto format_types = AutocompleteMatch::GetFormatTypes( |
| 1146 ~((params.trim_http && !history_match.match_in_scheme) | 1147 params.trim_http && !history_match.match_in_scheme); |
| 1147 ? 0 | 1148 // Never omit HTTPS from fill_into_edit lest it be misinterpreted. |
| 1148 : url_formatter::kFormatUrlOmitHTTP); | 1149 auto fill_into_edit_format_types = |
| 1150 format_types & ~url_formatter::kFormatUrlExperimentalOmitHTTPS; |
| 1149 match.fill_into_edit = | 1151 match.fill_into_edit = |
| 1150 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 1152 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 1151 info.url(), | 1153 info.url(), |
| 1152 url_formatter::FormatUrl(info.url(), format_types, | 1154 url_formatter::FormatUrl(info.url(), fill_into_edit_format_types, |
| 1153 net::UnescapeRule::SPACES, nullptr, nullptr, | 1155 net::UnescapeRule::SPACES, nullptr, nullptr, |
| 1154 &inline_autocomplete_offset), | 1156 &inline_autocomplete_offset), |
| 1155 client()->GetSchemeClassifier()); | 1157 client()->GetSchemeClassifier()); |
| 1156 // |inline_autocomplete_offset| was guaranteed not to be npos before the call | 1158 // |inline_autocomplete_offset| was guaranteed not to be npos before the call |
| 1157 // to FormatUrl(). If it is npos now, that means the represented location no | 1159 // to FormatUrl(). If it is npos now, that means the represented location no |
| 1158 // longer exists as such in the formatted string, e.g. if the offset pointed | 1160 // longer exists as such in the formatted string, e.g. if the offset pointed |
| 1159 // into the middle of a punycode sequence fixed up to Unicode. In this case, | 1161 // into the middle of a punycode sequence fixed up to Unicode. In this case, |
| 1160 // there can be no inline autocompletion, and the match must not be allowed to | 1162 // there can be no inline autocompletion, and the match must not be allowed to |
| 1161 // be default. | 1163 // be default. |
| 1162 const bool autocomplete_offset_valid = | 1164 const bool autocomplete_offset_valid = |
| 1163 inline_autocomplete_offset != base::string16::npos; | 1165 inline_autocomplete_offset != base::string16::npos; |
| 1164 if (!params.prevent_inline_autocomplete && autocomplete_offset_valid) { | 1166 if (!params.prevent_inline_autocomplete && autocomplete_offset_valid) { |
| 1165 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1167 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| 1166 match.inline_autocompletion = | 1168 match.inline_autocompletion = |
| 1167 match.fill_into_edit.substr(inline_autocomplete_offset); | 1169 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 1168 } | 1170 } |
| 1169 // The latter part of the test effectively asks "is the inline completion | 1171 // The latter part of the test effectively asks "is the inline completion |
| 1170 // empty?" (i.e., is this match effectively the what-you-typed match?). | 1172 // empty?" (i.e., is this match effectively the what-you-typed match?). |
| 1171 match.allowed_to_be_default_match = autocomplete_offset_valid && | 1173 match.allowed_to_be_default_match = autocomplete_offset_valid && |
| 1172 (!params.prevent_inline_autocomplete || | 1174 (!params.prevent_inline_autocomplete || |
| 1173 (inline_autocomplete_offset >= match.fill_into_edit.length())); | 1175 (inline_autocomplete_offset >= match.fill_into_edit.length())); |
| 1174 | 1176 |
| 1175 size_t match_start = history_match.input_location; | 1177 size_t match_start = history_match.input_location; |
| 1176 match.contents = AutocompleteMatch::FormatUrlForSuggestionDisplay( | 1178 match.contents = url_formatter::FormatUrl(info.url(), format_types, |
| 1177 info.url(), params.trim_http && !history_match.match_in_scheme, | 1179 net::UnescapeRule::SPACES, nullptr, |
| 1178 &match_start); | 1180 nullptr, &match_start); |
| 1179 if ((match_start != base::string16::npos) && autocomplete_offset_valid && | 1181 if ((match_start != base::string16::npos) && autocomplete_offset_valid && |
| 1180 (inline_autocomplete_offset != match_start)) { | 1182 (inline_autocomplete_offset != match_start)) { |
| 1181 DCHECK(inline_autocomplete_offset > match_start); | 1183 DCHECK(inline_autocomplete_offset > match_start); |
| 1182 AutocompleteMatch::ClassifyLocationInString(match_start, | 1184 AutocompleteMatch::ClassifyLocationInString(match_start, |
| 1183 inline_autocomplete_offset - match_start, match.contents.length(), | 1185 inline_autocomplete_offset - match_start, match.contents.length(), |
| 1184 ACMatchClassification::URL, &match.contents_class); | 1186 ACMatchClassification::URL, &match.contents_class); |
| 1185 } else { | 1187 } else { |
| 1186 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1188 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1187 match.contents.length(), ACMatchClassification::URL, | 1189 match.contents.length(), ACMatchClassification::URL, |
| 1188 &match.contents_class); | 1190 &match.contents_class); |
| 1189 } | 1191 } |
| 1190 match.description = info.title(); | 1192 match.description = info.title(); |
| 1191 match.description_class = | 1193 match.description_class = |
| 1192 ClassifyDescription(params.input.text(), match.description); | 1194 ClassifyDescription(params.input.text(), match.description); |
| 1193 RecordAdditionalInfoFromUrlRow(info, &match); | 1195 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1194 return match; | 1196 return match; |
| 1195 } | 1197 } |
| OLD | NEW |