Chromium Code Reviews| 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::GetFormatForSuggestionDisplay( |
| 575 AutocompleteMatch::FormatUrlForSuggestionDisplay( | 575 false /* trim_scheme */); |
| 576 destination_url, false /* trim_scheme */, nullptr)); | 576 base::string16 display_string(url_formatter::FormatUrl( |
| 577 destination_url, format_types, net::UnescapeRule::SPACES, nullptr, | |
| 578 nullptr, nullptr)); | |
| 577 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; | 579 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; |
| 578 match.fill_into_edit = | 580 match.fill_into_edit = |
| 579 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 581 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 580 destination_url, display_string, client()->GetSchemeClassifier()); | 582 destination_url, display_string, client()->GetSchemeClassifier()); |
| 581 // The what-you-typed match is generally only allowed to be default for | 583 // 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 | 584 // 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 | 585 // 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 | 586 // intranet site. In this case, |allowed_to_be_default_match| is revised in |
| 585 // FixupExactSuggestion().) | 587 // FixupExactSuggestion().) |
| 586 const bool has_default_search_provider = | 588 const bool has_default_search_provider = |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1134 | 1136 |
| 1135 const history::HistoryMatch& history_match = params.matches[match_number]; | 1137 const history::HistoryMatch& history_match = params.matches[match_number]; |
| 1136 const history::URLRow& info = history_match.url_info; | 1138 const history::URLRow& info = history_match.url_info; |
| 1137 AutocompleteMatch match(this, relevance, | 1139 AutocompleteMatch match(this, relevance, |
| 1138 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); | 1140 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); |
| 1139 match.typed_count = info.typed_count(); | 1141 match.typed_count = info.typed_count(); |
| 1140 match.destination_url = info.url(); | 1142 match.destination_url = info.url(); |
| 1141 DCHECK(match.destination_url.is_valid()); | 1143 DCHECK(match.destination_url.is_valid()); |
| 1142 size_t inline_autocomplete_offset = | 1144 size_t inline_autocomplete_offset = |
| 1143 history_match.input_location + params.input.text().length(); | 1145 history_match.input_location + params.input.text().length(); |
| 1144 const url_formatter::FormatUrlTypes format_types = | 1146 const url_formatter::FormatUrlTypes fill_into_edit_format_types = |
|
Peter Kasting
2017/06/29 01:05:44
I suspect what we want here might be:
const aut
tommycli
2017/06/29 16:46:46
Done. Yes, that makes sense. I missed the "formatt
| |
| 1145 url_formatter::kFormatUrlOmitAll & | 1147 url_formatter::kFormatUrlOmitAll & |
| 1146 ~((params.trim_http && !history_match.match_in_scheme) | 1148 ~((params.trim_http && !history_match.match_in_scheme) |
| 1147 ? 0 | 1149 ? 0 |
| 1148 : url_formatter::kFormatUrlOmitHTTP); | 1150 : url_formatter::kFormatUrlOmitHTTP); |
| 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 auto format_types = AutocompleteMatch::GetFormatForSuggestionDisplay( |
| 1177 info.url(), params.trim_http && !history_match.match_in_scheme, | 1179 params.trim_http && !history_match.match_in_scheme); |
| 1178 &match_start); | 1180 match.contents = url_formatter::FormatUrl(info.url(), format_types, |
| 1181 net::UnescapeRule::SPACES, nullptr, | |
| 1182 nullptr, &match_start); | |
| 1179 if ((match_start != base::string16::npos) && autocomplete_offset_valid && | 1183 if ((match_start != base::string16::npos) && autocomplete_offset_valid && |
| 1180 (inline_autocomplete_offset != match_start)) { | 1184 (inline_autocomplete_offset != match_start)) { |
| 1181 DCHECK(inline_autocomplete_offset > match_start); | 1185 DCHECK(inline_autocomplete_offset > match_start); |
| 1182 AutocompleteMatch::ClassifyLocationInString(match_start, | 1186 AutocompleteMatch::ClassifyLocationInString(match_start, |
| 1183 inline_autocomplete_offset - match_start, match.contents.length(), | 1187 inline_autocomplete_offset - match_start, match.contents.length(), |
| 1184 ACMatchClassification::URL, &match.contents_class); | 1188 ACMatchClassification::URL, &match.contents_class); |
| 1185 } else { | 1189 } else { |
| 1186 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1190 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1187 match.contents.length(), ACMatchClassification::URL, | 1191 match.contents.length(), ACMatchClassification::URL, |
| 1188 &match.contents_class); | 1192 &match.contents_class); |
| 1189 } | 1193 } |
| 1190 match.description = info.title(); | 1194 match.description = info.title(); |
| 1191 match.description_class = | 1195 match.description_class = |
| 1192 ClassifyDescription(params.input.text(), match.description); | 1196 ClassifyDescription(params.input.text(), match.description); |
| 1193 RecordAdditionalInfoFromUrlRow(info, &match); | 1197 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1194 return match; | 1198 return match; |
| 1195 } | 1199 } |
| OLD | NEW |