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/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/search/instant_service_factory.h" | 22 #include "chrome/browser/search/instant_service_factory.h" |
23 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
24 #include "chrome/browser/search_engines/template_url.h" | 24 #include "chrome/browser/search_engines/template_url.h" |
25 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 25 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
26 #include "chrome/browser/search_engines/template_url_service.h" | 26 #include "chrome/browser/search_engines/template_url_service.h" |
27 #include "chrome/browser/search_engines/template_url_service_factory.h" | 27 #include "chrome/browser/search_engines/template_url_service_factory.h" |
28 #include "chrome/browser/sync/profile_sync_service.h" | 28 #include "chrome/browser/sync/profile_sync_service.h" |
29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
30 #include "chrome/common/net/url_fixer_upper.h" | 30 #include "chrome/common/net/url_fixer_upper.h" |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "components/metrics/proto/omnibox_input_type.pb.h" | |
33 #include "components/sync_driver/sync_prefs.h" | 32 #include "components/sync_driver/sync_prefs.h" |
34 #include "content/public/common/url_constants.h" | 33 #include "content/public/common/url_constants.h" |
35 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
36 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
37 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 36 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
38 #include "net/http/http_response_headers.h" | 37 #include "net/http/http_response_headers.h" |
39 #include "net/url_request/url_fetcher.h" | 38 #include "net/url_request/url_fetcher.h" |
40 #include "net/url_request/url_fetcher_delegate.h" | 39 #include "net/url_request/url_fetcher_delegate.h" |
41 #include "url/gurl.h" | 40 #include "url/gurl.h" |
42 | 41 |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 bool BaseSearchProvider::SuggestResult::IsInlineable( | 330 bool BaseSearchProvider::SuggestResult::IsInlineable( |
332 const base::string16& input) const { | 331 const base::string16& input) const { |
333 return StartsWith(suggestion_, input, false); | 332 return StartsWith(suggestion_, input, false); |
334 } | 333 } |
335 | 334 |
336 int BaseSearchProvider::SuggestResult::CalculateRelevance( | 335 int BaseSearchProvider::SuggestResult::CalculateRelevance( |
337 const AutocompleteInput& input, | 336 const AutocompleteInput& input, |
338 bool keyword_provider_requested) const { | 337 bool keyword_provider_requested) const { |
339 if (!from_keyword_provider_ && keyword_provider_requested) | 338 if (!from_keyword_provider_ && keyword_provider_requested) |
340 return 100; | 339 return 100; |
341 return ((input.type() == metrics::OmniboxInputType::URL) ? 300 : 600); | 340 return ((input.type() == AutocompleteInput::URL) ? 300 : 600); |
342 } | 341 } |
343 | 342 |
344 // BaseSearchProvider::NavigationResult ---------------------------------------- | 343 // BaseSearchProvider::NavigationResult ---------------------------------------- |
345 | 344 |
346 BaseSearchProvider::NavigationResult::NavigationResult( | 345 BaseSearchProvider::NavigationResult::NavigationResult( |
347 const AutocompleteProvider& provider, | 346 const AutocompleteProvider& provider, |
348 const GURL& url, | 347 const GURL& url, |
349 AutocompleteMatchType::Type type, | 348 AutocompleteMatchType::Type type, |
350 const base::string16& description, | 349 const base::string16& description, |
351 const std::string& deletion_url, | 350 const std::string& deletion_url, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 match.description = suggestion.annotation(); | 511 match.description = suggestion.annotation(); |
513 | 512 |
514 // suggestion.match_contents() should have already been collapsed. | 513 // suggestion.match_contents() should have already been collapsed. |
515 match.allowed_to_be_default_match = | 514 match.allowed_to_be_default_match = |
516 (base::CollapseWhitespace(input.text(), false) == | 515 (base::CollapseWhitespace(input.text(), false) == |
517 suggestion.match_contents()); | 516 suggestion.match_contents()); |
518 | 517 |
519 // When the user forced a query, we need to make sure all the fill_into_edit | 518 // When the user forced a query, we need to make sure all the fill_into_edit |
520 // values preserve that property. Otherwise, if the user starts editing a | 519 // values preserve that property. Otherwise, if the user starts editing a |
521 // suggestion, non-Search results will suddenly appear. | 520 // suggestion, non-Search results will suddenly appear. |
522 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY) | 521 if (input.type() == AutocompleteInput::FORCED_QUERY) |
523 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); | 522 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); |
524 if (suggestion.from_keyword_provider()) | 523 if (suggestion.from_keyword_provider()) |
525 match.fill_into_edit.append(match.keyword + base::char16(' ')); | 524 match.fill_into_edit.append(match.keyword + base::char16(' ')); |
526 if (!input.prevent_inline_autocomplete() && | 525 if (!input.prevent_inline_autocomplete() && |
527 StartsWith(suggestion.suggestion(), input.text(), false)) { | 526 StartsWith(suggestion.suggestion(), input.text(), false)) { |
528 match.inline_autocompletion = | 527 match.inline_autocompletion = |
529 suggestion.suggestion().substr(input.text().length()); | 528 suggestion.suggestion().substr(input.text().length()); |
530 match.allowed_to_be_default_match = true; | 529 match.allowed_to_be_default_match = true; |
531 } | 530 } |
532 match.fill_into_edit.append(suggestion.suggestion()); | 531 match.fill_into_edit.append(suggestion.suggestion()); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 } | 846 } |
848 | 847 |
849 // Clear the previous results now that new results are available. | 848 // Clear the previous results now that new results are available. |
850 results->suggest_results.clear(); | 849 results->suggest_results.clear(); |
851 results->navigation_results.clear(); | 850 results->navigation_results.clear(); |
852 | 851 |
853 base::string16 suggestion; | 852 base::string16 suggestion; |
854 std::string type; | 853 std::string type; |
855 int relevance = GetDefaultResultRelevance(); | 854 int relevance = GetDefaultResultRelevance(); |
856 // Prohibit navsuggest in FORCED_QUERY mode. Users wants queries, not URLs. | 855 // Prohibit navsuggest in FORCED_QUERY mode. Users wants queries, not URLs. |
857 const bool allow_navsuggest = | 856 const bool allow_navsuggest = input.type() != AutocompleteInput::FORCED_QUERY; |
858 input.type() != metrics::OmniboxInputType::FORCED_QUERY; | |
859 const std::string languages( | 857 const std::string languages( |
860 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 858 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
861 const base::string16& trimmed_input = | 859 const base::string16& trimmed_input = |
862 base::CollapseWhitespace(input.text(), false); | 860 base::CollapseWhitespace(input.text(), false); |
863 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) { | 861 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) { |
864 // Google search may return empty suggestions for weird input characters, | 862 // Google search may return empty suggestions for weird input characters, |
865 // they make no sense at all and can cause problems in our code. | 863 // they make no sense at all and can cause problems in our code. |
866 if (suggestion.empty()) | 864 if (suggestion.empty()) |
867 continue; | 865 continue; |
868 | 866 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 } | 966 } |
969 | 967 |
970 void BaseSearchProvider::OnDeletionComplete( | 968 void BaseSearchProvider::OnDeletionComplete( |
971 bool success, SuggestionDeletionHandler* handler) { | 969 bool success, SuggestionDeletionHandler* handler) { |
972 RecordDeletionResult(success); | 970 RecordDeletionResult(success); |
973 SuggestionDeletionHandlers::iterator it = std::find( | 971 SuggestionDeletionHandlers::iterator it = std::find( |
974 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 972 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
975 DCHECK(it != deletion_handlers_.end()); | 973 DCHECK(it != deletion_handlers_.end()); |
976 deletion_handlers_.erase(it); | 974 deletion_handlers_.erase(it); |
977 } | 975 } |
OLD | NEW |