OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/histogram.h" | 10 #include "base/histogram.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 AutocompleteMatch HistoryURLProvider::SuggestExactInput( | 249 AutocompleteMatch HistoryURLProvider::SuggestExactInput( |
250 const AutocompleteInput& input, | 250 const AutocompleteInput& input, |
251 bool trim_http) { | 251 bool trim_http) { |
252 AutocompleteMatch match(this, | 252 AutocompleteMatch match(this, |
253 CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, | 253 CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, |
254 AutocompleteMatch::URL_WHAT_YOU_TYPED); | 254 AutocompleteMatch::URL_WHAT_YOU_TYPED); |
255 | 255 |
256 const GURL& url = input.canonicalized_url(); | 256 const GURL& url = input.canonicalized_url(); |
257 if (url.is_valid()) { | 257 if (url.is_valid()) { |
258 match.destination_url = url; | 258 match.destination_url = url; |
259 match.fill_into_edit = StringForURLDisplay(url, false); | 259 match.fill_into_edit = StringForURLDisplay(url, false, trim_http); |
260 // NOTE: Don't set match.input_location (to allow inline autocompletion) | 260 // NOTE: Don't set match.input_location (to allow inline autocompletion) |
261 // here, it's surprising and annoying. | 261 // here, it's surprising and annoying. |
262 // Trim off "http://" if the user didn't type it. | |
263 const size_t offset = trim_http ? TrimHttpPrefix(&match.fill_into_edit) : 0; | |
264 | 262 |
265 // Try to highlight "innermost" match location. If we fix up "w" into | 263 // Try to highlight "innermost" match location. If we fix up "w" into |
266 // "www.w.com", we want to highlight the fifth character, not the first. | 264 // "www.w.com", we want to highlight the fifth character, not the first. |
267 // This relies on match.destination_url being the non-prefix-trimmed version | 265 // This relies on match.destination_url being the non-prefix-trimmed version |
268 // of match.contents. | 266 // of match.contents. |
269 match.contents = match.fill_into_edit; | 267 match.contents = match.fill_into_edit; |
270 const Prefix* best_prefix = BestPrefix(match.destination_url, input.text()); | 268 const Prefix* best_prefix = BestPrefix(match.destination_url, input.text()); |
271 // Because of the vagaries of GURL, it's possible for match.destination_url | 269 // Because of the vagaries of GURL, it's possible for match.destination_url |
272 // to not contain the user's input at all. In this case don't mark anything | 270 // to not contain the user's input at all. In this case don't mark anything |
273 // as a match. | 271 // as a match. |
274 const size_t match_location = (best_prefix == NULL) ? | 272 const size_t match_location = (best_prefix == NULL) ? |
275 std::wstring::npos : best_prefix->prefix.length() - offset; | 273 std::wstring::npos : best_prefix->prefix.length(); |
276 AutocompleteMatch::ClassifyLocationInString(match_location, | 274 AutocompleteMatch::ClassifyLocationInString(match_location, |
277 input.text().length(), | 275 input.text().length(), |
278 match.contents.length(), | 276 match.contents.length(), |
279 ACMatchClassification::URL, | 277 ACMatchClassification::URL, |
280 &match.contents_class); | 278 &match.contents_class); |
281 | 279 |
282 match.is_history_what_you_typed_match = true; | 280 match.is_history_what_you_typed_match = true; |
283 } | 281 } |
284 | 282 |
285 return match; | 283 return match; |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 MatchType match_type, | 819 MatchType match_type, |
822 size_t match_number) { | 820 size_t match_number) { |
823 const history::URLRow& info = history_match.url_info; | 821 const history::URLRow& info = history_match.url_info; |
824 AutocompleteMatch match(this, | 822 AutocompleteMatch match(this, |
825 CalculateRelevance(params->input.type(), match_type, match_number), | 823 CalculateRelevance(params->input.type(), match_type, match_number), |
826 !!info.visit_count(), AutocompleteMatch::HISTORY_URL); | 824 !!info.visit_count(), AutocompleteMatch::HISTORY_URL); |
827 match.destination_url = info.url(); | 825 match.destination_url = info.url(); |
828 DCHECK(match.destination_url.is_valid()); | 826 DCHECK(match.destination_url.is_valid()); |
829 size_t inline_autocomplete_offset = | 827 size_t inline_autocomplete_offset = |
830 history_match.input_location + params->input.text().length(); | 828 history_match.input_location + params->input.text().length(); |
| 829 const net::FormatUrlTypes format_types = |
| 830 (params->trim_http && !history_match.match_in_scheme) ? |
| 831 net::kFormatUrlOmitAll : net::kFormatUrlOmitUsernamePassword; |
831 match.fill_into_edit = net::FormatUrl(info.url(), | 832 match.fill_into_edit = net::FormatUrl(info.url(), |
832 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, true, | 833 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, |
833 UnescapeRule::SPACES, NULL, NULL, &inline_autocomplete_offset); | 834 format_types, UnescapeRule::SPACES, NULL, NULL, |
834 size_t offset = 0; | 835 &inline_autocomplete_offset); |
835 if (params->trim_http && !history_match.match_in_scheme) { | |
836 offset = TrimHttpPrefix(&match.fill_into_edit); | |
837 if (inline_autocomplete_offset != std::wstring::npos) { | |
838 DCHECK(inline_autocomplete_offset >= offset); | |
839 inline_autocomplete_offset -= offset; | |
840 } | |
841 } | |
842 if (!params->input.prevent_inline_autocomplete()) | 836 if (!params->input.prevent_inline_autocomplete()) |
843 match.inline_autocomplete_offset = inline_autocomplete_offset; | 837 match.inline_autocomplete_offset = inline_autocomplete_offset; |
844 DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || | 838 DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || |
845 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); | 839 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); |
846 | 840 |
847 size_t match_start = history_match.input_location; | 841 size_t match_start = history_match.input_location; |
848 match.contents = net::FormatUrl(info.url(), | 842 match.contents = net::FormatUrl(info.url(), |
849 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, true, | 843 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, |
850 UnescapeRule::SPACES, NULL, NULL, &match_start); | 844 format_types, UnescapeRule::SPACES, NULL, NULL, &match_start); |
851 if (offset) { | |
852 TrimHttpPrefix(&match.contents); | |
853 if (match_start != std::wstring::npos) { | |
854 DCHECK(match_start >= offset); | |
855 match_start -= offset; | |
856 } | |
857 } | |
858 if ((match_start != std::wstring::npos) && | 845 if ((match_start != std::wstring::npos) && |
859 (inline_autocomplete_offset != std::wstring::npos) && | 846 (inline_autocomplete_offset != std::wstring::npos) && |
860 (inline_autocomplete_offset != match_start)) { | 847 (inline_autocomplete_offset != match_start)) { |
861 DCHECK(inline_autocomplete_offset > match_start); | 848 DCHECK(inline_autocomplete_offset > match_start); |
862 AutocompleteMatch::ClassifyLocationInString(match_start, | 849 AutocompleteMatch::ClassifyLocationInString(match_start, |
863 inline_autocomplete_offset - match_start, match.contents.length(), | 850 inline_autocomplete_offset - match_start, match.contents.length(), |
864 ACMatchClassification::URL, &match.contents_class); | 851 ACMatchClassification::URL, &match.contents_class); |
865 } else { | 852 } else { |
866 AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, | 853 AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, |
867 match.contents.length(), ACMatchClassification::URL, | 854 match.contents.length(), ACMatchClassification::URL, |
868 &match.contents_class); | 855 &match.contents_class); |
869 } | 856 } |
870 match.description = info.title(); | 857 match.description = info.title(); |
871 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 858 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), |
872 ACMatchClassification::NONE, | 859 ACMatchClassification::NONE, |
873 &match.description_class); | 860 &match.description_class); |
874 | 861 |
875 return match; | 862 return match; |
876 } | 863 } |
OLD | NEW |