OLD | NEW |
1 // Copyright (c) 2010 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_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/i18n/break_iterator.h" | 8 #include "base/i18n/break_iterator.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 return; | 45 return; |
46 | 46 |
47 autocomplete_input_ = input; | 47 autocomplete_input_ = input; |
48 trim_http_ = !HasHTTPScheme(input.text()); | 48 trim_http_ = !HasHTTPScheme(input.text()); |
49 | 49 |
50 // Do some fixup on the user input before matching against it, so we provide | 50 // Do some fixup on the user input before matching against it, so we provide |
51 // good results for local file paths, input with spaces, etc. | 51 // good results for local file paths, input with spaces, etc. |
52 // NOTE: This purposefully doesn't take input.desired_tld() into account; if | 52 // NOTE: This purposefully doesn't take input.desired_tld() into account; if |
53 // it did, then holding "ctrl" would change all the results from the | 53 // it did, then holding "ctrl" would change all the results from the |
54 // HistoryQuickProvider provider, not just the What You Typed Result. | 54 // HistoryQuickProvider provider, not just the What You Typed Result. |
55 const std::wstring fixed_text(FixupUserInput(input)); | 55 const string16 fixed_text(FixupUserInput(input)); |
56 if (fixed_text.empty()) { | 56 if (fixed_text.empty()) { |
57 // Conceivably fixup could result in an empty string (although I don't | 57 // Conceivably fixup could result in an empty string (although I don't |
58 // have cases where this happens offhand). We can't do anything with | 58 // have cases where this happens offhand). We can't do anything with |
59 // empty input, so just bail; otherwise we'd crash later. | 59 // empty input, so just bail; otherwise we'd crash later. |
60 return; | 60 return; |
61 } | 61 } |
62 autocomplete_input_.set_text(fixed_text); | 62 autocomplete_input_.set_text(fixed_text); |
63 | 63 |
64 // TODO(pkasting): We should just block here until this loads. Any time | 64 // TODO(pkasting): We should just block here until this loads. Any time |
65 // someone unloads the history backend, we'll get inconsistent inline | 65 // someone unloads the history backend, we'll get inconsistent inline |
66 // autocomplete behavior here. | 66 // autocomplete behavior here. |
67 if (GetIndex()) { | 67 if (GetIndex()) { |
68 DoAutocomplete(); | 68 DoAutocomplete(); |
69 UpdateStarredStateOfMatches(); | 69 UpdateStarredStateOfMatches(); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 // HistoryQuickProvider matches are currently not deletable. | 73 // HistoryQuickProvider matches are currently not deletable. |
74 // TODO(mrossetti): Determine when a match should be deletable. | 74 // TODO(mrossetti): Determine when a match should be deletable. |
75 void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} | 75 void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} |
76 | 76 |
77 void HistoryQuickProvider::DoAutocomplete() { | 77 void HistoryQuickProvider::DoAutocomplete() { |
78 // Get the matching URLs from the DB. | 78 // Get the matching URLs from the DB. |
79 string16 term_string(WideToUTF16(autocomplete_input_.text())); | 79 string16 term_string = autocomplete_input_.text(); |
80 term_string = UnescapeURLComponent(term_string, | 80 term_string = UnescapeURLComponent(term_string, |
81 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 81 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
82 history::InMemoryURLIndex::String16Vector terms( | 82 history::InMemoryURLIndex::String16Vector terms( |
83 HistoryQuickProvider::WordVectorFromString16(term_string)); | 83 HistoryQuickProvider::WordVectorFromString16(term_string)); |
84 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(terms); | 84 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(terms); |
85 | 85 |
86 size_t match_num = matches.size() - 1; | 86 size_t match_num = matches.size() - 1; |
87 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); | 87 for (ScoredHistoryMatches::const_iterator match_iter = matches.begin(); |
88 match_iter != matches.end(); ++match_iter, --match_num) { | 88 match_iter != matches.end(); ++match_iter, --match_num) { |
89 const ScoredHistoryMatch& history_match(*match_iter); | 89 const ScoredHistoryMatch& history_match(*match_iter); |
(...skipping 17 matching lines...) Expand all Loading... |
107 DCHECK(match.destination_url.is_valid()); | 107 DCHECK(match.destination_url.is_valid()); |
108 size_t inline_autocomplete_offset = | 108 size_t inline_autocomplete_offset = |
109 history_match.input_location + autocomplete_input_.text().length(); | 109 history_match.input_location + autocomplete_input_.text().length(); |
110 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & | 110 const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & |
111 ~((trim_http_ && !history_match.match_in_scheme) ? | 111 ~((trim_http_ && !history_match.match_in_scheme) ? |
112 0 : net::kFormatUrlOmitHTTP); | 112 0 : net::kFormatUrlOmitHTTP); |
113 std::string languages = | 113 std::string languages = |
114 match_type == WHAT_YOU_TYPED ? std::string() : languages_; | 114 match_type == WHAT_YOU_TYPED ? std::string() : languages_; |
115 match.fill_into_edit = | 115 match.fill_into_edit = |
116 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), | 116 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), |
117 UTF16ToWide(net::FormatUrl(info.url(), languages, format_types, | 117 net::FormatUrl(info.url(), languages, format_types, |
118 UnescapeRule::SPACES, NULL, NULL, | 118 UnescapeRule::SPACES, NULL, NULL, |
119 &inline_autocomplete_offset))); | 119 &inline_autocomplete_offset)); |
120 if (!autocomplete_input_.prevent_inline_autocomplete()) | 120 if (!autocomplete_input_.prevent_inline_autocomplete()) |
121 match.inline_autocomplete_offset = inline_autocomplete_offset; | 121 match.inline_autocomplete_offset = inline_autocomplete_offset; |
122 DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || | 122 DCHECK((match.inline_autocomplete_offset == string16::npos) || |
123 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); | 123 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); |
124 | 124 |
125 size_t match_start = history_match.input_location; | 125 size_t match_start = history_match.input_location; |
126 match.contents = | 126 match.contents = net::FormatUrl(info.url(), languages, format_types, |
127 UTF16ToWide(net::FormatUrl(info.url(), languages, format_types, | 127 UnescapeRule::SPACES, NULL, NULL, |
128 UnescapeRule::SPACES, NULL, NULL, | 128 &match_start); |
129 &match_start)); | 129 if ((match_start != string16::npos) && |
130 if ((match_start != std::wstring::npos) && | 130 (inline_autocomplete_offset != string16::npos) && |
131 (inline_autocomplete_offset != std::wstring::npos) && | |
132 (inline_autocomplete_offset != match_start)) { | 131 (inline_autocomplete_offset != match_start)) { |
133 DCHECK(inline_autocomplete_offset > match_start); | 132 DCHECK(inline_autocomplete_offset > match_start); |
134 AutocompleteMatch::ClassifyLocationInString(match_start, | 133 AutocompleteMatch::ClassifyLocationInString(match_start, |
135 inline_autocomplete_offset - match_start, match.contents.length(), | 134 inline_autocomplete_offset - match_start, match.contents.length(), |
136 ACMatchClassification::URL, &match.contents_class); | 135 ACMatchClassification::URL, &match.contents_class); |
137 } else { | 136 } else { |
138 AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, | 137 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, |
139 match.contents.length(), ACMatchClassification::URL, | 138 match.contents.length(), ACMatchClassification::URL, |
140 &match.contents_class); | 139 &match.contents_class); |
141 } | 140 } |
142 match.description = UTF16ToWide(info.title()); | 141 match.description = info.title(); |
143 AutocompleteMatch::ClassifyMatchInString(autocomplete_input_.text(), | 142 AutocompleteMatch::ClassifyMatchInString(autocomplete_input_.text(), |
144 UTF16ToWide(info.title()), | 143 info.title(), |
145 ACMatchClassification::NONE, | 144 ACMatchClassification::NONE, |
146 &match.description_class); | 145 &match.description_class); |
147 | 146 |
148 return match; | 147 return match; |
149 } | 148 } |
150 | 149 |
151 history::InMemoryURLIndex* HistoryQuickProvider::GetIndex() { | 150 history::InMemoryURLIndex* HistoryQuickProvider::GetIndex() { |
152 if (index_for_testing_.get()) | 151 if (index_for_testing_.get()) |
153 return index_for_testing_.get(); | 152 return index_for_testing_.get(); |
154 | 153 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 case INLINE_AUTOCOMPLETE: | 189 case INLINE_AUTOCOMPLETE: |
191 return 1400; | 190 return 1400; |
192 | 191 |
193 case WHAT_YOU_TYPED: | 192 case WHAT_YOU_TYPED: |
194 return 1200; | 193 return 1200; |
195 | 194 |
196 default: | 195 default: |
197 return 900 + static_cast<int>(match_number); | 196 return 900 + static_cast<int>(match_number); |
198 } | 197 } |
199 } | 198 } |
OLD | NEW |