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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/common/net/url_fixer_upper.h" | 26 #include "chrome/common/net/url_fixer_upper.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "components/sync_driver/sync_prefs.h" | 28 #include "components/sync_driver/sync_prefs.h" |
29 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
30 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
31 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 32 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
33 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
34 #include "net/url_request/url_fetcher_delegate.h" | 34 #include "net/url_request/url_fetcher_delegate.h" |
35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 36 #include "url/url_constants.h" |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { | 40 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
40 if (type == "ENTITY") | 41 if (type == "ENTITY") |
41 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; | 42 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
42 if (type == "INFINITE") | 43 if (type == "INFINITE") |
43 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; | 44 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
44 if (type == "PERSONALIZED_QUERY") | 45 if (type == "PERSONALIZED_QUERY") |
45 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; | 46 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 bool BaseSearchProvider::ZeroSuggestEnabled( | 536 bool BaseSearchProvider::ZeroSuggestEnabled( |
536 const GURL& suggest_url, | 537 const GURL& suggest_url, |
537 const TemplateURL* template_url, | 538 const TemplateURL* template_url, |
538 AutocompleteInput::PageClassification page_classification, | 539 AutocompleteInput::PageClassification page_classification, |
539 Profile* profile) { | 540 Profile* profile) { |
540 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) | 541 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) |
541 return false; | 542 return false; |
542 | 543 |
543 // Make sure we are sending the suggest request through HTTPS to prevent | 544 // Make sure we are sending the suggest request through HTTPS to prevent |
544 // exposing the current page URL or personalized results without encryption. | 545 // exposing the current page URL or personalized results without encryption. |
545 if (!suggest_url.SchemeIs(content::kHttpsScheme)) | 546 if (!suggest_url.SchemeIs(url::kHttpsScheme)) |
546 return false; | 547 return false; |
547 | 548 |
548 // Don't show zero suggest on the NTP. | 549 // Don't show zero suggest on the NTP. |
549 // TODO(hfung): Experiment with showing MostVisited zero suggest on NTP | 550 // TODO(hfung): Experiment with showing MostVisited zero suggest on NTP |
550 // under the conditions described in crbug.com/305366. | 551 // under the conditions described in crbug.com/305366. |
551 if ((page_classification == | 552 if ((page_classification == |
552 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) || | 553 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) || |
553 (page_classification == | 554 (page_classification == |
554 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS)) | 555 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS)) |
555 return false; | 556 return false; |
(...skipping 26 matching lines...) Expand all Loading... |
582 Profile* profile) { | 583 Profile* profile) { |
583 if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, | 584 if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, |
584 profile)) | 585 profile)) |
585 return false; | 586 return false; |
586 | 587 |
587 if (!current_page_url.is_valid()) | 588 if (!current_page_url.is_valid()) |
588 return false; | 589 return false; |
589 | 590 |
590 // Only allow HTTP URLs or HTTPS URLs for the same domain as the search | 591 // Only allow HTTP URLs or HTTPS URLs for the same domain as the search |
591 // provider. | 592 // provider. |
592 if ((current_page_url.scheme() != content::kHttpScheme) && | 593 if ((current_page_url.scheme() != url::kHttpScheme) && |
593 ((current_page_url.scheme() != content::kHttpsScheme) || | 594 ((current_page_url.scheme() != url::kHttpsScheme) || |
594 !net::registry_controlled_domains::SameDomainOrHost( | 595 !net::registry_controlled_domains::SameDomainOrHost( |
595 current_page_url, suggest_url, | 596 current_page_url, suggest_url, |
596 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES))) | 597 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES))) |
597 return false; | 598 return false; |
598 | 599 |
599 // Check field trials and settings allow sending the URL on suggest requests. | 600 // Check field trials and settings allow sending the URL on suggest requests. |
600 ProfileSyncService* service = | 601 ProfileSyncService* service = |
601 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 602 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
602 sync_driver::SyncPrefs sync_prefs(profile->GetPrefs()); | 603 sync_driver::SyncPrefs sync_prefs(profile->GetPrefs()); |
603 if (service == NULL || | 604 if (service == NULL || |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 } | 899 } |
899 | 900 |
900 void BaseSearchProvider::OnDeletionComplete( | 901 void BaseSearchProvider::OnDeletionComplete( |
901 bool success, SuggestionDeletionHandler* handler) { | 902 bool success, SuggestionDeletionHandler* handler) { |
902 RecordDeletionResult(success); | 903 RecordDeletionResult(success); |
903 SuggestionDeletionHandlers::iterator it = std::find( | 904 SuggestionDeletionHandlers::iterator it = std::find( |
904 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 905 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
905 DCHECK(it != deletion_handlers_.end()); | 906 DCHECK(it != deletion_handlers_.end()); |
906 deletion_handlers_.erase(it); | 907 deletion_handlers_.erase(it); |
907 } | 908 } |
OLD | NEW |