| 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 "components/omnibox/base_search_provider.h" | 5 #include "components/omnibox/base_search_provider.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/metrics/proto/omnibox_event.pb.h" | 10 #include "components/metrics/proto/omnibox_event.pb.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; | 98 return match.GetAdditionalInfo(kShouldPrefetchKey) == kTrue; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // static | 101 // static |
| 102 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( | 102 AutocompleteMatch BaseSearchProvider::CreateSearchSuggestion( |
| 103 const base::string16& suggestion, | 103 const base::string16& suggestion, |
| 104 AutocompleteMatchType::Type type, | 104 AutocompleteMatchType::Type type, |
| 105 bool from_keyword_provider, | 105 bool from_keyword_provider, |
| 106 const TemplateURL* template_url, | 106 const TemplateURL* template_url, |
| 107 const SearchTermsData& search_terms_data) { | 107 const SearchTermsData& search_terms_data) { |
| 108 // This call uses a number of default values. For instance, it assumes that | 108 // These calls use a number of default values. For instance, they assume |
| 109 // if this match is from a keyword provider than the user is in keyword mode. | 109 // that if this match is from a keyword provider, then the user is in keyword |
| 110 // mode. They also assume the caller knows what it's doing and we set |
| 111 // this match to look as if it was received/created synchronously. |
| 112 SearchSuggestionParser::SuggestResult suggest_result( |
| 113 suggestion, type, suggestion, base::string16(), base::string16(), |
| 114 base::string16(), base::string16(), std::string(), std::string(), |
| 115 from_keyword_provider, 0, false, false, base::string16()); |
| 116 suggest_result.set_received_after_last_keystroke(false); |
| 110 return CreateSearchSuggestion( | 117 return CreateSearchSuggestion( |
| 111 NULL, AutocompleteInput(), from_keyword_provider, | 118 NULL, AutocompleteInput(), from_keyword_provider, suggest_result, |
| 112 SearchSuggestionParser::SuggestResult( | |
| 113 suggestion, type, suggestion, base::string16(), base::string16(), | |
| 114 base::string16(), base::string16(), std::string(), std::string(), | |
| 115 from_keyword_provider, 0, false, false, base::string16()), | |
| 116 template_url, search_terms_data, 0, false); | 119 template_url, search_terms_data, 0, false); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { | 122 void BaseSearchProvider::DeleteMatch(const AutocompleteMatch& match) { |
| 120 DCHECK(match.deletable); | 123 DCHECK(match.deletable); |
| 121 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { | 124 if (!match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey).empty()) { |
| 122 deletion_handlers_.push_back(new SuggestionDeletionHandler( | 125 deletion_handlers_.push_back(new SuggestionDeletionHandler( |
| 123 match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey), | 126 match.GetAdditionalInfo(BaseSearchProvider::kDeletionUrlKey), |
| 124 client_->RequestContext(), | 127 client_->RequestContext(), |
| 125 base::Bind(&BaseSearchProvider::OnDeletionComplete, | 128 base::Bind(&BaseSearchProvider::OnDeletionComplete, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 (base::CollapseWhitespace(input.text(), false) == | 229 (base::CollapseWhitespace(input.text(), false) == |
| 227 suggestion.match_contents()); | 230 suggestion.match_contents()); |
| 228 | 231 |
| 229 // When the user forced a query, we need to make sure all the fill_into_edit | 232 // When the user forced a query, we need to make sure all the fill_into_edit |
| 230 // values preserve that property. Otherwise, if the user starts editing a | 233 // values preserve that property. Otherwise, if the user starts editing a |
| 231 // suggestion, non-Search results will suddenly appear. | 234 // suggestion, non-Search results will suddenly appear. |
| 232 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) | 235 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) |
| 233 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); | 236 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); |
| 234 if (suggestion.from_keyword_provider()) | 237 if (suggestion.from_keyword_provider()) |
| 235 match.fill_into_edit.append(match.keyword + base::char16(' ')); | 238 match.fill_into_edit.append(match.keyword + base::char16(' ')); |
| 239 // We only allow inlinable navsuggestions that were received before the |
| 240 // last keystroke because we don't want asynchronous inline autocompletions. |
| 236 if (!input.prevent_inline_autocomplete() && | 241 if (!input.prevent_inline_autocomplete() && |
| 242 !suggestion.received_after_last_keystroke() && |
| 237 (!in_keyword_mode || suggestion.from_keyword_provider()) && | 243 (!in_keyword_mode || suggestion.from_keyword_provider()) && |
| 238 StartsWith(suggestion.suggestion(), input.text(), false)) { | 244 StartsWith(suggestion.suggestion(), input.text(), false)) { |
| 239 match.inline_autocompletion = | 245 match.inline_autocompletion = |
| 240 suggestion.suggestion().substr(input.text().length()); | 246 suggestion.suggestion().substr(input.text().length()); |
| 241 match.allowed_to_be_default_match = true; | 247 match.allowed_to_be_default_match = true; |
| 242 } | 248 } |
| 243 match.fill_into_edit.append(suggestion.suggestion()); | 249 match.fill_into_edit.append(suggestion.suggestion()); |
| 244 | 250 |
| 245 const TemplateURLRef& search_url = template_url->url_ref(); | 251 const TemplateURLRef& search_url = template_url->url_ref(); |
| 246 DCHECK(search_url.SupportsReplacement(search_terms_data)); | 252 DCHECK(search_url.SupportsReplacement(search_terms_data)); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 460 } |
| 455 | 461 |
| 456 void BaseSearchProvider::OnDeletionComplete( | 462 void BaseSearchProvider::OnDeletionComplete( |
| 457 bool success, SuggestionDeletionHandler* handler) { | 463 bool success, SuggestionDeletionHandler* handler) { |
| 458 RecordDeletionResult(success); | 464 RecordDeletionResult(success); |
| 459 SuggestionDeletionHandlers::iterator it = std::find( | 465 SuggestionDeletionHandlers::iterator it = std::find( |
| 460 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 466 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 461 DCHECK(it != deletion_handlers_.end()); | 467 DCHECK(it != deletion_handlers_.end()); |
| 462 deletion_handlers_.erase(it); | 468 deletion_handlers_.erase(it); |
| 463 } | 469 } |
| OLD | NEW |