| 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_url_provider.h" | 5 #include "chrome/browser/autocomplete/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 20 matching lines...) Expand all Loading... |
| 31 #include "components/history/core/browser/history_service.h" | 31 #include "components/history/core/browser/history_service.h" |
| 32 #include "components/history/core/browser/history_types.h" | 32 #include "components/history/core/browser/history_types.h" |
| 33 #include "components/metrics/proto/omnibox_input_type.pb.h" | 33 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 34 #include "components/omnibox/autocomplete_match.h" | 34 #include "components/omnibox/autocomplete_match.h" |
| 35 #include "components/omnibox/autocomplete_provider_listener.h" | 35 #include "components/omnibox/autocomplete_provider_listener.h" |
| 36 #include "components/omnibox/autocomplete_result.h" | 36 #include "components/omnibox/autocomplete_result.h" |
| 37 #include "components/omnibox/omnibox_field_trial.h" | 37 #include "components/omnibox/omnibox_field_trial.h" |
| 38 #include "components/omnibox/url_prefix.h" | 38 #include "components/omnibox/url_prefix.h" |
| 39 #include "components/search_engines/template_url_service.h" | 39 #include "components/search_engines/template_url_service.h" |
| 40 #include "components/url_fixer/url_fixer.h" | 40 #include "components/url_fixer/url_fixer.h" |
| 41 #include "components/url_formatter/url_formatter.h" |
| 41 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 42 #include "net/base/net_util.h" | |
| 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 44 #include "url/gurl.h" | 44 #include "url/gurl.h" |
| 45 #include "url/third_party/mozilla/url_parse.h" | 45 #include "url/third_party/mozilla/url_parse.h" |
| 46 #include "url/url_util.h" | 46 #include "url/url_util.h" |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 // Acts like the > operator for URLInfo classes. | 50 // Acts like the > operator for URLInfo classes. |
| 51 bool CompareHistoryMatch(const history::HistoryMatch& a, | 51 bool CompareHistoryMatch(const history::HistoryMatch& a, |
| 52 const history::HistoryMatch& b) { | 52 const history::HistoryMatch& b) { |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 !content::BrowserThread::IsThreadInitialized(content::BrowserThread::UI)); | 603 !content::BrowserThread::IsThreadInitialized(content::BrowserThread::UI)); |
| 604 | 604 |
| 605 AutocompleteMatch match(this, 0, false, | 605 AutocompleteMatch match(this, 0, false, |
| 606 AutocompleteMatchType::URL_WHAT_YOU_TYPED); | 606 AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 607 | 607 |
| 608 if (destination_url.is_valid()) { | 608 if (destination_url.is_valid()) { |
| 609 match.destination_url = destination_url; | 609 match.destination_url = destination_url; |
| 610 | 610 |
| 611 // Trim off "http://" if the user didn't type it. | 611 // Trim off "http://" if the user didn't type it. |
| 612 DCHECK(!trim_http || !AutocompleteInput::HasHTTPScheme(text)); | 612 DCHECK(!trim_http || !AutocompleteInput::HasHTTPScheme(text)); |
| 613 base::string16 display_string( | 613 base::string16 display_string(url_formatter::FormatUrl( |
| 614 net::FormatUrl(destination_url, std::string(), | 614 destination_url, std::string(), |
| 615 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitHTTP, | 615 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP, |
| 616 net::UnescapeRule::SPACES, NULL, NULL, NULL)); | 616 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); |
| 617 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; | 617 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; |
| 618 match.fill_into_edit = | 618 match.fill_into_edit = |
| 619 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 619 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 620 destination_url, | 620 destination_url, |
| 621 display_string, | 621 display_string, |
| 622 ChromeAutocompleteSchemeClassifier(profile_)); | 622 ChromeAutocompleteSchemeClassifier(profile_)); |
| 623 match.allowed_to_be_default_match = true; | 623 match.allowed_to_be_default_match = true; |
| 624 // NOTE: Don't set match.inline_autocompletion to something non-empty here; | 624 // NOTE: Don't set match.inline_autocompletion to something non-empty here; |
| 625 // it's surprising and annoying. | 625 // it's surprising and annoying. |
| 626 | 626 |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 const history::URLRow& info = history_match.url_info; | 1136 const history::URLRow& info = history_match.url_info; |
| 1137 AutocompleteMatch match(this, relevance, | 1137 AutocompleteMatch match(this, relevance, |
| 1138 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); | 1138 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); |
| 1139 match.typed_count = info.typed_count(); | 1139 match.typed_count = info.typed_count(); |
| 1140 match.destination_url = info.url(); | 1140 match.destination_url = info.url(); |
| 1141 DCHECK(match.destination_url.is_valid()); | 1141 DCHECK(match.destination_url.is_valid()); |
| 1142 size_t inline_autocomplete_offset = | 1142 size_t inline_autocomplete_offset = |
| 1143 history_match.input_location + params.input.text().length(); | 1143 history_match.input_location + params.input.text().length(); |
| 1144 std::string languages = (match_type == WHAT_YOU_TYPED) ? | 1144 std::string languages = (match_type == WHAT_YOU_TYPED) ? |
| 1145 std::string() : params.languages; | 1145 std::string() : params.languages; |
| 1146 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & | 1146 const url_formatter::FormatUrlTypes format_types = |
| 1147 ~((params.trim_http && !history_match.match_in_scheme) ? | 1147 url_formatter::kFormatUrlOmitAll & |
| 1148 0 : net::kFormatUrlOmitHTTP); | 1148 ~((params.trim_http && !history_match.match_in_scheme) |
| 1149 ? 0 |
| 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 net::FormatUrl(info.url(), languages, format_types, | 1154 url_formatter::FormatUrl(info.url(), languages, format_types, |
| 1153 net::UnescapeRule::SPACES, NULL, NULL, | 1155 net::UnescapeRule::SPACES, nullptr, nullptr, |
| 1154 &inline_autocomplete_offset), | 1156 &inline_autocomplete_offset), |
| 1155 ChromeAutocompleteSchemeClassifier(profile_)); | 1157 ChromeAutocompleteSchemeClassifier(profile_)); |
| 1156 if (!params.prevent_inline_autocomplete && | 1158 if (!params.prevent_inline_autocomplete && |
| 1157 (inline_autocomplete_offset != base::string16::npos)) { | 1159 (inline_autocomplete_offset != base::string16::npos)) { |
| 1158 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1160 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| 1159 match.inline_autocompletion = | 1161 match.inline_autocompletion = |
| 1160 match.fill_into_edit.substr(inline_autocomplete_offset); | 1162 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 1161 } | 1163 } |
| 1162 // The latter part of the test effectively asks "is the inline completion | 1164 // The latter part of the test effectively asks "is the inline completion |
| 1163 // empty?" (i.e., is this match effectively the what-you-typed match?). | 1165 // empty?" (i.e., is this match effectively the what-you-typed match?). |
| 1164 match.allowed_to_be_default_match = !params.prevent_inline_autocomplete || | 1166 match.allowed_to_be_default_match = !params.prevent_inline_autocomplete || |
| 1165 ((inline_autocomplete_offset != base::string16::npos) && | 1167 ((inline_autocomplete_offset != base::string16::npos) && |
| 1166 (inline_autocomplete_offset >= match.fill_into_edit.length())); | 1168 (inline_autocomplete_offset >= match.fill_into_edit.length())); |
| 1167 | 1169 |
| 1168 size_t match_start = history_match.input_location; | 1170 size_t match_start = history_match.input_location; |
| 1169 match.contents = net::FormatUrl(info.url(), languages, | 1171 match.contents = url_formatter::FormatUrl(info.url(), languages, format_types, |
| 1170 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); | 1172 net::UnescapeRule::SPACES, nullptr, |
| 1173 nullptr, &match_start); |
| 1171 if ((match_start != base::string16::npos) && | 1174 if ((match_start != base::string16::npos) && |
| 1172 (inline_autocomplete_offset != base::string16::npos) && | 1175 (inline_autocomplete_offset != base::string16::npos) && |
| 1173 (inline_autocomplete_offset != match_start)) { | 1176 (inline_autocomplete_offset != match_start)) { |
| 1174 DCHECK(inline_autocomplete_offset > match_start); | 1177 DCHECK(inline_autocomplete_offset > match_start); |
| 1175 AutocompleteMatch::ClassifyLocationInString(match_start, | 1178 AutocompleteMatch::ClassifyLocationInString(match_start, |
| 1176 inline_autocomplete_offset - match_start, match.contents.length(), | 1179 inline_autocomplete_offset - match_start, match.contents.length(), |
| 1177 ACMatchClassification::URL, &match.contents_class); | 1180 ACMatchClassification::URL, &match.contents_class); |
| 1178 } else { | 1181 } else { |
| 1179 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1182 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1180 match.contents.length(), ACMatchClassification::URL, | 1183 match.contents.length(), ACMatchClassification::URL, |
| 1181 &match.contents_class); | 1184 &match.contents_class); |
| 1182 } | 1185 } |
| 1183 match.description = info.title(); | 1186 match.description = info.title(); |
| 1184 match.description_class = | 1187 match.description_class = |
| 1185 ClassifyDescription(params.input.text(), match.description); | 1188 ClassifyDescription(params.input.text(), match.description); |
| 1186 RecordAdditionalInfoFromUrlRow(info, &match); | 1189 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1187 return match; | 1190 return match; |
| 1188 } | 1191 } |
| OLD | NEW |