OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base_search_provider.h" | 5 #include "chrome/browser/autocomplete/base_search_provider.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | 109 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; |
110 } | 110 } |
111 | 111 |
112 // static | 112 // static |
113 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 113 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
114 const base::string16& suggestion, | 114 const base::string16& suggestion, |
115 AutocompleteMatchType::Type type, | 115 AutocompleteMatchType::Type type, |
116 bool from_keyword_provider, | 116 bool from_keyword_provider, |
117 const TemplateURL* template_url, | 117 const TemplateURL* template_url, |
118 const SearchTermsData& search_terms_data) { | 118 const SearchTermsData& search_terms_data) { |
119 // This call uses a number of default values. For instance, it assumes that | 119 // These calls use a number of default values. For instance, they assumes |
120 // if this match is from a keyword provider than the user is in keyword mode. | 120 // that if this match is from a keyword provider than the user is in keyword |
| 121 // mode. They also assume the caller knows what it's doing and we set |
| 122 // this match to look as if it was received/created synchronously. |
| 123 SearchSuggestionParser::SuggestResult suggest_result( |
| 124 suggestion, type, suggestion, base::string16(), base::string16(), |
| 125 base::string16(), base::string16(), std::string(), std::string(), |
| 126 from_keyword_provider, 0, false, false, base::string16()); |
| 127 suggest_result.set_received_after_last_keystroke(false); |
121 return CreateSearchSuggestion( | 128 return CreateSearchSuggestion( |
122 NULL, AutocompleteInput(), from_keyword_provider, | 129 NULL, AutocompleteInput(), from_keyword_provider, suggest_result, |
123 SearchSuggestionParser::SuggestResult( | |
124 suggestion, type, suggestion, base::string16(), base::string16(), | |
125 base::string16(), base::string16(), std::string(), std::string(), | |
126 from_keyword_provider, 0, false, false, base::string16()), | |
127 template_url, search_terms_data, 0, false); | 130 template_url, search_terms_data, 0, false); |
128 } | 131 } |
129 | 132 |
130 void BaseSearchProvider::Stop(bool clear_cached_results) { | 133 void BaseSearchProvider::Stop(bool clear_cached_results) { |
131 StopSuggest(); | 134 StopSuggest(); |
132 done_ = true; | 135 done_ = true; |
133 | 136 |
134 if (clear_cached_results) | 137 if (clear_cached_results) |
135 ClearAllResults(); | 138 ClearAllResults(); |
136 } | 139 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 (base::CollapseWhitespace(input.text(), false) == | 251 (base::CollapseWhitespace(input.text(), false) == |
249 suggestion.match_contents()); | 252 suggestion.match_contents()); |
250 | 253 |
251 // When the user forced a query, we need to make sure all the fill_into_edit | 254 // When the user forced a query, we need to make sure all the fill_into_edit |
252 // values preserve that property. Otherwise, if the user starts editing a | 255 // values preserve that property. Otherwise, if the user starts editing a |
253 // suggestion, non-Search results will suddenly appear. | 256 // suggestion, non-Search results will suddenly appear. |
254 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) | 257 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) |
255 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); | 258 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); |
256 if (suggestion.from_keyword_provider()) | 259 if (suggestion.from_keyword_provider()) |
257 match.fill_into_edit.append(match.keyword + base::char16(' ')); | 260 match.fill_into_edit.append(match.keyword + base::char16(' ')); |
| 261 // We only allow inlinable navsuggestions that were received before the |
| 262 // last keystroke because we don't want asynchronous inline autocompletions. |
258 if (!input.prevent_inline_autocomplete() && | 263 if (!input.prevent_inline_autocomplete() && |
| 264 !suggestion.received_after_last_keystroke() && |
259 (!in_keyword_mode || suggestion.from_keyword_provider()) && | 265 (!in_keyword_mode || suggestion.from_keyword_provider()) && |
260 StartsWith(suggestion.suggestion(), input.text(), false)) { | 266 StartsWith(suggestion.suggestion(), input.text(), false)) { |
261 match.inline_autocompletion = | 267 match.inline_autocompletion = |
262 suggestion.suggestion().substr(input.text().length()); | 268 suggestion.suggestion().substr(input.text().length()); |
263 match.allowed_to_be_default_match = true; | 269 match.allowed_to_be_default_match = true; |
264 } | 270 } |
265 match.fill_into_edit.append(suggestion.suggestion()); | 271 match.fill_into_edit.append(suggestion.suggestion()); |
266 | 272 |
267 const TemplateURLRef& search_url = template_url->url_ref(); | 273 const TemplateURLRef& search_url = template_url->url_ref(); |
268 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 274 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 } | 500 } |
495 | 501 |
496 void BaseSearchProvider::OnDeletionComplete( | 502 void BaseSearchProvider::OnDeletionComplete( |
497 bool success, SuggestionDeletionHandler* handler) { | 503 bool success, SuggestionDeletionHandler* handler) { |
498 RecordDeletionResult(success); | 504 RecordDeletionResult(success); |
499 SuggestionDeletionHandlers::iterator it = std::find( | 505 SuggestionDeletionHandlers::iterator it = std::find( |
500 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 506 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
501 DCHECK(it != deletion_handlers_.end()); | 507 DCHECK(it != deletion_handlers_.end()); |
502 deletion_handlers_.erase(it); | 508 deletion_handlers_.erase(it); |
503 } | 509 } |
OLD | NEW |