OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 done_ = true; | 61 done_ = true; |
62 | 62 |
63 if (params_) | 63 if (params_) |
64 params_->cancel = true; | 64 params_->cancel = true; |
65 } | 65 } |
66 | 66 |
67 void HistoryURLProvider::DeleteMatch(const AutocompleteMatch& match) { | 67 void HistoryURLProvider::DeleteMatch(const AutocompleteMatch& match) { |
68 DCHECK(done_); | 68 DCHECK(done_); |
69 | 69 |
70 // Delete the match from the history DB. | 70 // Delete the match from the history DB. |
71 HistoryService* history_service = | 71 HistoryService* const history_service = |
72 profile_ ? profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : | 72 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
73 history_service_; | |
74 GURL selected_url(match.destination_url); | 73 GURL selected_url(match.destination_url); |
75 if (!history_service || !selected_url.is_valid()) { | 74 if (!history_service || !selected_url.is_valid()) { |
76 NOTREACHED() << "Can't delete requested URL"; | 75 NOTREACHED() << "Can't delete requested URL"; |
77 return; | 76 return; |
78 } | 77 } |
79 history_service->DeleteURL(selected_url); | 78 history_service->DeleteURL(selected_url); |
80 | 79 |
81 // Delete the match from the current set of matches. | 80 // Delete the match from the current set of matches. |
82 bool found = false; | 81 bool found = false; |
83 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { | 82 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) { |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 // we'll run this again in DoAutocomplete() and use that result instead. | 620 // we'll run this again in DoAutocomplete() and use that result instead. |
622 const bool trim_http = !url_util::FindAndCompareScheme( | 621 const bool trim_http = !url_util::FindAndCompareScheme( |
623 WideToUTF8(input.text()), chrome::kHttpScheme, NULL); | 622 WideToUTF8(input.text()), chrome::kHttpScheme, NULL); |
624 // Don't do this for queries -- while we can sometimes mark up a match for | 623 // Don't do this for queries -- while we can sometimes mark up a match for |
625 // this, it's not what the user wants, and just adds noise. | 624 // this, it's not what the user wants, and just adds noise. |
626 if ((input.type() != AutocompleteInput::QUERY) && | 625 if ((input.type() != AutocompleteInput::QUERY) && |
627 input.canonicalized_url().is_valid()) | 626 input.canonicalized_url().is_valid()) |
628 matches_.push_back(SuggestExactInput(input, trim_http)); | 627 matches_.push_back(SuggestExactInput(input, trim_http)); |
629 | 628 |
630 // We'll need the history service to run both passes, so try to obtain it. | 629 // We'll need the history service to run both passes, so try to obtain it. |
631 HistoryService* const history_service = profile_ ? | 630 HistoryService* const history_service = |
632 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : history_service_; | 631 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
633 if (!history_service) | 632 if (!history_service) |
634 return; | 633 return; |
635 | 634 |
636 // Create the data structure for the autocomplete passes. We'll save this off | 635 // Create the data structure for the autocomplete passes. We'll save this off |
637 // onto the |params_| member for later deletion below if we need to run pass | 636 // onto the |params_| member for later deletion below if we need to run pass |
638 // 2. | 637 // 2. |
639 const std::wstring& languages = profile_ ? | 638 std::wstring languages(languages_); |
640 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::wstring(); | 639 if (languages.empty() && profile_) |
| 640 languages = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
641 scoped_ptr<HistoryURLProviderParams> params( | 641 scoped_ptr<HistoryURLProviderParams> params( |
642 new HistoryURLProviderParams(input, trim_http, languages)); | 642 new HistoryURLProviderParams(input, trim_http, languages)); |
643 | 643 |
644 if (fixup_input_and_run_pass_1) { | 644 if (fixup_input_and_run_pass_1) { |
645 // Do some fixup on the user input before matching against it, so we provide | 645 // Do some fixup on the user input before matching against it, so we provide |
646 // good results for local file paths, input with spaces, etc. | 646 // good results for local file paths, input with spaces, etc. |
647 // NOTE: This purposefully doesn't take input.desired_tld() into account; if | 647 // NOTE: This purposefully doesn't take input.desired_tld() into account; if |
648 // it did, then holding "ctrl" would change all the results from the | 648 // it did, then holding "ctrl" would change all the results from the |
649 // HistoryURLProvider provider, not just the What You Typed Result. | 649 // HistoryURLProvider provider, not just the What You Typed Result. |
650 const std::wstring fixed_text(FixupUserInput(input)); | 650 const std::wstring fixed_text(FixupUserInput(input)); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 HistoryURLProviderParams* params, | 819 HistoryURLProviderParams* params, |
820 const HistoryMatch& history_match, | 820 const HistoryMatch& history_match, |
821 MatchType match_type, | 821 MatchType match_type, |
822 size_t match_number) { | 822 size_t match_number) { |
823 const history::URLRow& info = history_match.url_info; | 823 const history::URLRow& info = history_match.url_info; |
824 AutocompleteMatch match(this, | 824 AutocompleteMatch match(this, |
825 CalculateRelevance(params->input.type(), match_type, match_number), | 825 CalculateRelevance(params->input.type(), match_type, match_number), |
826 !!info.visit_count(), AutocompleteMatch::HISTORY_URL); | 826 !!info.visit_count(), AutocompleteMatch::HISTORY_URL); |
827 match.destination_url = info.url(); | 827 match.destination_url = info.url(); |
828 DCHECK(match.destination_url.is_valid()); | 828 DCHECK(match.destination_url.is_valid()); |
| 829 size_t inline_autocomplete_offset = |
| 830 history_match.input_location + params->input.text().length(); |
829 match.fill_into_edit = net::FormatUrl(info.url(), | 831 match.fill_into_edit = net::FormatUrl(info.url(), |
830 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages); | 832 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, true, |
831 if (!params->input.prevent_inline_autocomplete()) { | 833 UnescapeRule::SPACES, NULL, NULL, &inline_autocomplete_offset); |
832 match.inline_autocomplete_offset = | |
833 history_match.input_location + params->input.text().length(); | |
834 } | |
835 size_t offset = 0; | 834 size_t offset = 0; |
836 if (params->trim_http && !history_match.match_in_scheme) { | 835 if (params->trim_http && !history_match.match_in_scheme) { |
837 offset = TrimHttpPrefix(&match.fill_into_edit); | 836 offset = TrimHttpPrefix(&match.fill_into_edit); |
838 if (match.inline_autocomplete_offset != std::wstring::npos) { | 837 if (inline_autocomplete_offset != std::wstring::npos) { |
839 DCHECK(match.inline_autocomplete_offset >= offset); | 838 DCHECK(inline_autocomplete_offset >= offset); |
840 match.inline_autocomplete_offset -= offset; | 839 inline_autocomplete_offset -= offset; |
841 } | 840 } |
842 } | 841 } |
| 842 if (!params->input.prevent_inline_autocomplete()) |
| 843 match.inline_autocomplete_offset = inline_autocomplete_offset; |
843 DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || | 844 DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || |
844 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); | 845 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); |
845 | 846 |
846 match.contents = match.fill_into_edit; | 847 size_t match_start = history_match.input_location; |
847 AutocompleteMatch::ClassifyLocationInString( | 848 match.contents = net::FormatUrl(info.url(), |
848 history_match.input_location - offset, params->input.text().length(), | 849 match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, true, |
849 match.contents.length(), ACMatchClassification::URL, | 850 UnescapeRule::SPACES, NULL, NULL, &match_start); |
850 &match.contents_class); | 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) && |
| 859 (inline_autocomplete_offset != std::wstring::npos) && |
| 860 (inline_autocomplete_offset != match_start)) { |
| 861 DCHECK(inline_autocomplete_offset > match_start); |
| 862 AutocompleteMatch::ClassifyLocationInString(match_start, |
| 863 inline_autocomplete_offset - match_start, match.contents.length(), |
| 864 ACMatchClassification::URL, &match.contents_class); |
| 865 } else { |
| 866 AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, |
| 867 match.contents.length(), ACMatchClassification::URL, |
| 868 &match.contents_class); |
| 869 } |
851 match.description = info.title(); | 870 match.description = info.title(); |
852 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 871 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), |
853 ACMatchClassification::NONE, | 872 ACMatchClassification::NONE, |
854 &match.description_class); | 873 &match.description_class); |
855 | 874 |
856 return match; | 875 return match; |
857 } | 876 } |
OLD | NEW |