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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "components/metrics/proto/omnibox_input_type.pb.h" | 25 #include "components/metrics/proto/omnibox_input_type.pb.h" |
26 #include "components/omnibox/browser/autocomplete_match.h" | 26 #include "components/omnibox/browser/autocomplete_match.h" |
27 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
28 #include "components/omnibox/browser/autocomplete_result.h" | 28 #include "components/omnibox/browser/autocomplete_result.h" |
29 #include "components/omnibox/browser/in_memory_url_index_types.h" | 29 #include "components/omnibox/browser/in_memory_url_index_types.h" |
30 #include "components/omnibox/browser/omnibox_field_trial.h" | 30 #include "components/omnibox/browser/omnibox_field_trial.h" |
31 #include "components/omnibox/browser/scored_history_match.h" | 31 #include "components/omnibox/browser/scored_history_match.h" |
32 #include "components/omnibox/browser/url_prefix.h" | 32 #include "components/omnibox/browser/url_prefix.h" |
33 #include "components/search_engines/search_terms_data.h" | 33 #include "components/search_engines/search_terms_data.h" |
34 #include "components/search_engines/template_url_service.h" | 34 #include "components/search_engines/template_url_service.h" |
35 #include "components/url_fixer/url_fixer.h" | 35 #include "components/url_formatter/url_fixer.h" |
36 #include "net/base/net_util.h" | 36 #include "components/url_formatter/url_formatter.h" |
37 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 37 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
38 #include "url/gurl.h" | 38 #include "url/gurl.h" |
39 #include "url/third_party/mozilla/url_parse.h" | 39 #include "url/third_party/mozilla/url_parse.h" |
40 #include "url/url_util.h" | 40 #include "url/url_util.h" |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // Acts like the > operator for URLInfo classes. | 44 // Acts like the > operator for URLInfo classes. |
45 bool CompareHistoryMatch(const history::HistoryMatch& a, | 45 bool CompareHistoryMatch(const history::HistoryMatch& a, |
46 const history::HistoryMatch& b) { | 46 const history::HistoryMatch& b) { |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 (input.type() == metrics::OmniboxInputType::INVALID) || | 487 (input.type() == metrics::OmniboxInputType::INVALID) || |
488 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) | 488 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) |
489 return; | 489 return; |
490 | 490 |
491 // Do some fixup on the user input before matching against it, so we provide | 491 // Do some fixup on the user input before matching against it, so we provide |
492 // good results for local file paths, input with spaces, etc. | 492 // good results for local file paths, input with spaces, etc. |
493 const FixupReturn fixup_return(FixupUserInput(input)); | 493 const FixupReturn fixup_return(FixupUserInput(input)); |
494 if (!fixup_return.first) | 494 if (!fixup_return.first) |
495 return; | 495 return; |
496 url::Parsed parts; | 496 url::Parsed parts; |
497 url_fixer::SegmentURL(fixup_return.second, &parts); | 497 url_formatter::SegmentURL(fixup_return.second, &parts); |
498 AutocompleteInput fixed_up_input(input); | 498 AutocompleteInput fixed_up_input(input); |
499 fixed_up_input.UpdateText(fixup_return.second, base::string16::npos, parts); | 499 fixed_up_input.UpdateText(fixup_return.second, base::string16::npos, parts); |
500 | 500 |
501 // Create a match for what the user typed. | 501 // Create a match for what the user typed. |
502 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()); | 502 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()); |
503 AutocompleteMatch what_you_typed_match(SuggestExactInput( | 503 AutocompleteMatch what_you_typed_match(SuggestExactInput( |
504 fixed_up_input, fixed_up_input.canonicalized_url(), trim_http)); | 504 fixed_up_input, fixed_up_input.canonicalized_url(), trim_http)); |
505 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); | 505 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); |
506 | 506 |
507 // Add the WYT match as a fallback in case we can't get the history service or | 507 // Add the WYT match as a fallback in case we can't get the history service or |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 583 |
584 AutocompleteMatch match(this, 0, false, | 584 AutocompleteMatch match(this, 0, false, |
585 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 585 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
586 | 586 |
587 if (destination_url.is_valid()) { | 587 if (destination_url.is_valid()) { |
588 match.destination_url = destination_url; | 588 match.destination_url = destination_url; |
589 | 589 |
590 // Trim off "http://" if the user didn't type it. | 590 // Trim off "http://" if the user didn't type it. |
591 DCHECK(!trim_http || | 591 DCHECK(!trim_http || |
592 !AutocompleteInput::HasHTTPScheme(input.text())); | 592 !AutocompleteInput::HasHTTPScheme(input.text())); |
593 base::string16 display_string( | 593 base::string16 display_string(url_formatter::FormatUrl( |
594 net::FormatUrl(destination_url, std::string(), | 594 destination_url, std::string(), |
595 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitHTTP, | 595 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP, |
596 net::UnescapeRule::SPACES, NULL, NULL, NULL)); | 596 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); |
597 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; | 597 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; |
598 match.fill_into_edit = | 598 match.fill_into_edit = |
599 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 599 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
600 destination_url, display_string, client()->GetSchemeClassifier()); | 600 destination_url, display_string, client()->GetSchemeClassifier()); |
601 // The what-you-typed match is generally only allowed to be default for | 601 // The what-you-typed match is generally only allowed to be default for |
602 // URL inputs. (It's also allowed to be default for UNKNOWN inputs | 602 // URL inputs. (It's also allowed to be default for UNKNOWN inputs |
603 // where the destination is a known intranet site. In this case, | 603 // where the destination is a known intranet site. In this case, |
604 // |allowed_to_be_default_match| is revised in FixupExactSuggestion().) | 604 // |allowed_to_be_default_match| is revised in FixupExactSuggestion().) |
605 match.allowed_to_be_default_match = | 605 match.allowed_to_be_default_match = |
606 (input.type() == metrics::OmniboxInputType::URL) || | 606 (input.type() == metrics::OmniboxInputType::URL) || |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 const history::URLRow& info = history_match.url_info; | 1153 const history::URLRow& info = history_match.url_info; |
1154 AutocompleteMatch match(this, relevance, | 1154 AutocompleteMatch match(this, relevance, |
1155 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); | 1155 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); |
1156 match.typed_count = info.typed_count(); | 1156 match.typed_count = info.typed_count(); |
1157 match.destination_url = info.url(); | 1157 match.destination_url = info.url(); |
1158 DCHECK(match.destination_url.is_valid()); | 1158 DCHECK(match.destination_url.is_valid()); |
1159 size_t inline_autocomplete_offset = | 1159 size_t inline_autocomplete_offset = |
1160 history_match.input_location + params.input.text().length(); | 1160 history_match.input_location + params.input.text().length(); |
1161 std::string languages = (match_type == WHAT_YOU_TYPED) ? | 1161 std::string languages = (match_type == WHAT_YOU_TYPED) ? |
1162 std::string() : params.languages; | 1162 std::string() : params.languages; |
1163 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & | 1163 const url_formatter::FormatUrlTypes format_types = |
1164 ~((params.trim_http && !history_match.match_in_scheme) ? | 1164 url_formatter::kFormatUrlOmitAll & |
1165 0 : net::kFormatUrlOmitHTTP); | 1165 ~((params.trim_http && !history_match.match_in_scheme) |
| 1166 ? 0 |
| 1167 : url_formatter::kFormatUrlOmitHTTP); |
1166 match.fill_into_edit = | 1168 match.fill_into_edit = |
1167 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 1169 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
1168 info.url(), net::FormatUrl(info.url(), languages, format_types, | 1170 info.url(), |
1169 net::UnescapeRule::SPACES, NULL, NULL, | 1171 url_formatter::FormatUrl(info.url(), languages, format_types, |
1170 &inline_autocomplete_offset), | 1172 net::UnescapeRule::SPACES, nullptr, nullptr, |
| 1173 &inline_autocomplete_offset), |
1171 client()->GetSchemeClassifier()); | 1174 client()->GetSchemeClassifier()); |
1172 if (!params.prevent_inline_autocomplete && | 1175 if (!params.prevent_inline_autocomplete && |
1173 (inline_autocomplete_offset != base::string16::npos)) { | 1176 (inline_autocomplete_offset != base::string16::npos)) { |
1174 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1177 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
1175 match.inline_autocompletion = | 1178 match.inline_autocompletion = |
1176 match.fill_into_edit.substr(inline_autocomplete_offset); | 1179 match.fill_into_edit.substr(inline_autocomplete_offset); |
1177 } | 1180 } |
1178 // The latter part of the test effectively asks "is the inline completion | 1181 // The latter part of the test effectively asks "is the inline completion |
1179 // empty?" (i.e., is this match effectively the what-you-typed match?). | 1182 // empty?" (i.e., is this match effectively the what-you-typed match?). |
1180 match.allowed_to_be_default_match = !params.prevent_inline_autocomplete || | 1183 match.allowed_to_be_default_match = !params.prevent_inline_autocomplete || |
1181 ((inline_autocomplete_offset != base::string16::npos) && | 1184 ((inline_autocomplete_offset != base::string16::npos) && |
1182 (inline_autocomplete_offset >= match.fill_into_edit.length())); | 1185 (inline_autocomplete_offset >= match.fill_into_edit.length())); |
1183 | 1186 |
1184 size_t match_start = history_match.input_location; | 1187 size_t match_start = history_match.input_location; |
1185 match.contents = net::FormatUrl(info.url(), languages, | 1188 match.contents = url_formatter::FormatUrl(info.url(), languages, format_types, |
1186 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); | 1189 net::UnescapeRule::SPACES, nullptr, |
| 1190 nullptr, &match_start); |
1187 if ((match_start != base::string16::npos) && | 1191 if ((match_start != base::string16::npos) && |
1188 (inline_autocomplete_offset != base::string16::npos) && | 1192 (inline_autocomplete_offset != base::string16::npos) && |
1189 (inline_autocomplete_offset != match_start)) { | 1193 (inline_autocomplete_offset != match_start)) { |
1190 DCHECK(inline_autocomplete_offset > match_start); | 1194 DCHECK(inline_autocomplete_offset > match_start); |
1191 AutocompleteMatch::ClassifyLocationInString(match_start, | 1195 AutocompleteMatch::ClassifyLocationInString(match_start, |
1192 inline_autocomplete_offset - match_start, match.contents.length(), | 1196 inline_autocomplete_offset - match_start, match.contents.length(), |
1193 ACMatchClassification::URL, &match.contents_class); | 1197 ACMatchClassification::URL, &match.contents_class); |
1194 } else { | 1198 } else { |
1195 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1199 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
1196 match.contents.length(), ACMatchClassification::URL, | 1200 match.contents.length(), ACMatchClassification::URL, |
1197 &match.contents_class); | 1201 &match.contents_class); |
1198 } | 1202 } |
1199 match.description = info.title(); | 1203 match.description = info.title(); |
1200 match.description_class = | 1204 match.description_class = |
1201 ClassifyDescription(params.input.text(), match.description); | 1205 ClassifyDescription(params.input.text(), match.description); |
1202 RecordAdditionalInfoFromUrlRow(info, &match); | 1206 RecordAdditionalInfoFromUrlRow(info, &match); |
1203 return match; | 1207 return match; |
1204 } | 1208 } |
OLD | NEW |