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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 // different port and/or path) before. | 416 // different port and/or path) before. |
| 417 url_row_ = history::URLRow(url); | 417 url_row_ = history::URLRow(url); |
| 418 type_ = UNVISITED_INTRANET; | 418 type_ = UNVISITED_INTRANET; |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 | 421 |
| 422 HistoryURLProviderParams::HistoryURLProviderParams( | 422 HistoryURLProviderParams::HistoryURLProviderParams( |
| 423 const AutocompleteInput& input, | 423 const AutocompleteInput& input, |
| 424 bool trim_http, | 424 bool trim_http, |
| 425 const AutocompleteMatch& what_you_typed_match, | 425 const AutocompleteMatch& what_you_typed_match, |
| 426 const std::string& languages, | |
| 427 TemplateURL* default_search_provider, | 426 TemplateURL* default_search_provider, |
| 428 const SearchTermsData& search_terms_data) | 427 const SearchTermsData& search_terms_data) |
| 429 : message_loop(base::MessageLoop::current()), | 428 : message_loop(base::MessageLoop::current()), |
| 430 input(input), | 429 input(input), |
| 431 prevent_inline_autocomplete(input.prevent_inline_autocomplete()), | 430 prevent_inline_autocomplete(input.prevent_inline_autocomplete()), |
| 432 trim_http(trim_http), | 431 trim_http(trim_http), |
| 433 what_you_typed_match(what_you_typed_match), | 432 what_you_typed_match(what_you_typed_match), |
| 434 failed(false), | 433 failed(false), |
| 435 exact_suggestion_is_in_history(false), | 434 exact_suggestion_is_in_history(false), |
| 436 promote_type(NEITHER), | 435 promote_type(NEITHER), |
| 437 languages(languages), | |
| 438 default_search_provider(default_search_provider ? | 436 default_search_provider(default_search_provider ? |
| 439 new TemplateURL(default_search_provider->data()) : NULL), | 437 new TemplateURL(default_search_provider->data()) : NULL), |
| 440 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { | 438 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { |
| 441 } | 439 } |
| 442 | 440 |
| 443 HistoryURLProviderParams::~HistoryURLProviderParams() { | 441 HistoryURLProviderParams::~HistoryURLProviderParams() { |
| 444 } | 442 } |
| 445 | 443 |
| 446 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, | 444 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, |
| 447 AutocompleteProviderListener* listener) | 445 AutocompleteProviderListener* listener) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 // thread. |template_url_service| can be NULL when testing. | 509 // thread. |template_url_service| can be NULL when testing. |
| 512 TemplateURLService* template_url_service = client()->GetTemplateURLService(); | 510 TemplateURLService* template_url_service = client()->GetTemplateURLService(); |
| 513 TemplateURL* default_search_provider = template_url_service ? | 511 TemplateURL* default_search_provider = template_url_service ? |
| 514 template_url_service->GetDefaultSearchProvider() : NULL; | 512 template_url_service->GetDefaultSearchProvider() : NULL; |
| 515 | 513 |
| 516 // Create the data structure for the autocomplete passes. We'll save this off | 514 // Create the data structure for the autocomplete passes. We'll save this off |
| 517 // onto the |params_| member for later deletion below if we need to run pass | 515 // onto the |params_| member for later deletion below if we need to run pass |
| 518 // 2. | 516 // 2. |
| 519 scoped_ptr<HistoryURLProviderParams> params(new HistoryURLProviderParams( | 517 scoped_ptr<HistoryURLProviderParams> params(new HistoryURLProviderParams( |
| 520 fixed_up_input, trim_http, what_you_typed_match, | 518 fixed_up_input, trim_http, what_you_typed_match, |
| 521 client()->GetAcceptLanguages(), default_search_provider, | 519 default_search_provider, client()->GetSearchTermsData())); |
| 522 client()->GetSearchTermsData())); | |
| 523 // Note that we use the non-fixed-up input here, since fixup may strip | 520 // Note that we use the non-fixed-up input here, since fixup may strip |
| 524 // trailing whitespace. | 521 // trailing whitespace. |
| 525 params->prevent_inline_autocomplete = PreventInlineAutocomplete(input); | 522 params->prevent_inline_autocomplete = PreventInlineAutocomplete(input); |
| 526 | 523 |
| 527 // Pass 1: Get the in-memory URL database, and use it to find and promote | 524 // Pass 1: Get the in-memory URL database, and use it to find and promote |
| 528 // the inline autocomplete match, if any. | 525 // the inline autocomplete match, if any. |
| 529 history::URLDatabase* url_db = history_service->InMemoryDatabase(); | 526 history::URLDatabase* url_db = history_service->InMemoryDatabase(); |
| 530 // url_db can be NULL if it hasn't finished initializing (or failed to | 527 // url_db can be NULL if it hasn't finished initializing (or failed to |
| 531 // initialize). In this case all we can do is fall back on the second | 528 // initialize). In this case all we can do is fall back on the second |
| 532 // pass. | 529 // pass. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 AutocompleteMatch match(this, 0, false, | 570 AutocompleteMatch match(this, 0, false, |
| 574 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 571 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 575 | 572 |
| 576 if (destination_url.is_valid()) { | 573 if (destination_url.is_valid()) { |
| 577 match.destination_url = destination_url; | 574 match.destination_url = destination_url; |
| 578 | 575 |
| 579 // Trim off "http://" if the user didn't type it. | 576 // Trim off "http://" if the user didn't type it. |
| 580 DCHECK(!trim_http || | 577 DCHECK(!trim_http || |
| 581 !AutocompleteInput::HasHTTPScheme(input.text())); | 578 !AutocompleteInput::HasHTTPScheme(input.text())); |
| 582 base::string16 display_string(url_formatter::FormatUrl( | 579 base::string16 display_string(url_formatter::FormatUrl( |
| 583 destination_url, std::string(), | 580 destination_url, |
| 584 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP, | 581 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP, |
| 585 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); | 582 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); |
| 586 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; | 583 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; |
| 587 match.fill_into_edit = | 584 match.fill_into_edit = |
| 588 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 585 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 589 destination_url, display_string, client()->GetSchemeClassifier()); | 586 destination_url, display_string, client()->GetSchemeClassifier()); |
| 590 // The what-you-typed match is generally only allowed to be default for | 587 // The what-you-typed match is generally only allowed to be default for |
| 591 // URL inputs. (It's also allowed to be default for UNKNOWN inputs | 588 // URL inputs. (It's also allowed to be default for UNKNOWN inputs |
| 592 // where the destination is a known intranet site. In this case, | 589 // where the destination is a known intranet site. In this case, |
| 593 // |allowed_to_be_default_match| is revised in FixupExactSuggestion().) | 590 // |allowed_to_be_default_match| is revised in FixupExactSuggestion().) |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 next = matches->erase(next); | 1126 next = matches->erase(next); |
| 1130 if (static_cast<size_t>(next - matches->begin()) < next_index) | 1127 if (static_cast<size_t>(next - matches->begin()) < next_index) |
| 1131 --next_index; | 1128 --next_index; |
| 1132 } | 1129 } |
| 1133 return next_index; | 1130 return next_index; |
| 1134 } | 1131 } |
| 1135 | 1132 |
| 1136 AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( | 1133 AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( |
| 1137 const HistoryURLProviderParams& params, | 1134 const HistoryURLProviderParams& params, |
| 1138 size_t match_number, | 1135 size_t match_number, |
| 1139 MatchType match_type, | 1136 MatchType match_type, |
|
Peter Kasting
2016/04/05 02:42:32
This parameter is no longer needed.
jungshik at Google
2016/04/05 18:56:19
Done.
| |
| 1140 int relevance) { | 1137 int relevance) { |
| 1141 // The FormattedStringWithEquivalentMeaning() call below requires callers to | 1138 // The FormattedStringWithEquivalentMeaning() call below requires callers to |
| 1142 // be on the main thread. | 1139 // be on the main thread. |
| 1143 DCHECK(thread_checker_.CalledOnValidThread()); | 1140 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1144 | 1141 |
| 1145 const history::HistoryMatch& history_match = params.matches[match_number]; | 1142 const history::HistoryMatch& history_match = params.matches[match_number]; |
| 1146 const history::URLRow& info = history_match.url_info; | 1143 const history::URLRow& info = history_match.url_info; |
| 1147 AutocompleteMatch match(this, relevance, | 1144 AutocompleteMatch match(this, relevance, |
| 1148 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); | 1145 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); |
| 1149 match.typed_count = info.typed_count(); | 1146 match.typed_count = info.typed_count(); |
| 1150 match.destination_url = info.url(); | 1147 match.destination_url = info.url(); |
| 1151 DCHECK(match.destination_url.is_valid()); | 1148 DCHECK(match.destination_url.is_valid()); |
| 1152 size_t inline_autocomplete_offset = | 1149 size_t inline_autocomplete_offset = |
| 1153 history_match.input_location + params.input.text().length(); | 1150 history_match.input_location + params.input.text().length(); |
| 1154 std::string languages = (match_type == WHAT_YOU_TYPED) ? | |
| 1155 std::string() : params.languages; | |
| 1156 const url_formatter::FormatUrlTypes format_types = | 1151 const url_formatter::FormatUrlTypes format_types = |
| 1157 url_formatter::kFormatUrlOmitAll & | 1152 url_formatter::kFormatUrlOmitAll & |
| 1158 ~((params.trim_http && !history_match.match_in_scheme) | 1153 ~((params.trim_http && !history_match.match_in_scheme) |
| 1159 ? 0 | 1154 ? 0 |
| 1160 : url_formatter::kFormatUrlOmitHTTP); | 1155 : url_formatter::kFormatUrlOmitHTTP); |
| 1161 match.fill_into_edit = | 1156 match.fill_into_edit = |
| 1162 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 1157 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 1163 info.url(), | 1158 info.url(), |
| 1164 url_formatter::FormatUrl(info.url(), languages, format_types, | 1159 url_formatter::FormatUrl(info.url(), format_types, |
| 1165 net::UnescapeRule::SPACES, nullptr, nullptr, | 1160 net::UnescapeRule::SPACES, nullptr, nullptr, |
| 1166 &inline_autocomplete_offset), | 1161 &inline_autocomplete_offset), |
| 1167 client()->GetSchemeClassifier()); | 1162 client()->GetSchemeClassifier()); |
| 1168 // |inline_autocomplete_offset| was guaranteed not to be npos before the call | 1163 // |inline_autocomplete_offset| was guaranteed not to be npos before the call |
| 1169 // to FormatUrl(). If it is npos now, that means the represented location no | 1164 // to FormatUrl(). If it is npos now, that means the represented location no |
| 1170 // longer exists as such in the formatted string, e.g. if the offset pointed | 1165 // longer exists as such in the formatted string, e.g. if the offset pointed |
| 1171 // into the middle of a punycode sequence fixed up to Unicode. In this case, | 1166 // into the middle of a punycode sequence fixed up to Unicode. In this case, |
| 1172 // there can be no inline autocompletion, and the match must not be allowed to | 1167 // there can be no inline autocompletion, and the match must not be allowed to |
| 1173 // be default. | 1168 // be default. |
| 1174 const bool autocomplete_offset_valid = | 1169 const bool autocomplete_offset_valid = |
| 1175 inline_autocomplete_offset != base::string16::npos; | 1170 inline_autocomplete_offset != base::string16::npos; |
| 1176 if (!params.prevent_inline_autocomplete && autocomplete_offset_valid) { | 1171 if (!params.prevent_inline_autocomplete && autocomplete_offset_valid) { |
| 1177 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1172 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| 1178 match.inline_autocompletion = | 1173 match.inline_autocompletion = |
| 1179 match.fill_into_edit.substr(inline_autocomplete_offset); | 1174 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 1180 } | 1175 } |
| 1181 // The latter part of the test effectively asks "is the inline completion | 1176 // The latter part of the test effectively asks "is the inline completion |
| 1182 // empty?" (i.e., is this match effectively the what-you-typed match?). | 1177 // empty?" (i.e., is this match effectively the what-you-typed match?). |
| 1183 match.allowed_to_be_default_match = autocomplete_offset_valid && | 1178 match.allowed_to_be_default_match = autocomplete_offset_valid && |
| 1184 (!params.prevent_inline_autocomplete || | 1179 (!params.prevent_inline_autocomplete || |
| 1185 (inline_autocomplete_offset >= match.fill_into_edit.length())); | 1180 (inline_autocomplete_offset >= match.fill_into_edit.length())); |
| 1186 | 1181 |
| 1187 size_t match_start = history_match.input_location; | 1182 size_t match_start = history_match.input_location; |
| 1188 match.contents = url_formatter::FormatUrl(info.url(), languages, format_types, | 1183 match.contents = url_formatter::FormatUrl(info.url(), format_types, |
| 1189 net::UnescapeRule::SPACES, nullptr, | 1184 net::UnescapeRule::SPACES, nullptr, |
| 1190 nullptr, &match_start); | 1185 nullptr, &match_start); |
| 1191 if ((match_start != base::string16::npos) && autocomplete_offset_valid && | 1186 if ((match_start != base::string16::npos) && autocomplete_offset_valid && |
| 1192 (inline_autocomplete_offset != match_start)) { | 1187 (inline_autocomplete_offset != match_start)) { |
| 1193 DCHECK(inline_autocomplete_offset > match_start); | 1188 DCHECK(inline_autocomplete_offset > match_start); |
| 1194 AutocompleteMatch::ClassifyLocationInString(match_start, | 1189 AutocompleteMatch::ClassifyLocationInString(match_start, |
| 1195 inline_autocomplete_offset - match_start, match.contents.length(), | 1190 inline_autocomplete_offset - match_start, match.contents.length(), |
| 1196 ACMatchClassification::URL, &match.contents_class); | 1191 ACMatchClassification::URL, &match.contents_class); |
| 1197 } else { | 1192 } else { |
| 1198 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1193 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1199 match.contents.length(), ACMatchClassification::URL, | 1194 match.contents.length(), ACMatchClassification::URL, |
| 1200 &match.contents_class); | 1195 &match.contents_class); |
| 1201 } | 1196 } |
| 1202 match.description = info.title(); | 1197 match.description = info.title(); |
| 1203 match.description_class = | 1198 match.description_class = |
| 1204 ClassifyDescription(params.input.text(), match.description); | 1199 ClassifyDescription(params.input.text(), match.description); |
| 1205 RecordAdditionalInfoFromUrlRow(info, &match); | 1200 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1206 return match; | 1201 return match; |
| 1207 } | 1202 } |
| OLD | NEW |