| 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 23 matching lines...) Expand all Loading... |
| 34 #include "components/url_fixer/url_fixer.h" | 34 #include "components/url_fixer/url_fixer.h" |
| 35 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
| 36 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
| 37 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
| 38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 39 #include "net/http/http_response_headers.h" | 39 #include "net/http/http_response_headers.h" |
| 40 #include "net/url_request/url_fetcher.h" | 40 #include "net/url_request/url_fetcher.h" |
| 41 #include "net/url_request/url_fetcher_delegate.h" | 41 #include "net/url_request/url_fetcher_delegate.h" |
| 42 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 43 | 43 |
| 44 using metrics::OmniboxEventProto; |
| 45 |
| 44 namespace { | 46 namespace { |
| 45 | 47 |
| 46 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { | 48 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
| 47 if (type == "ENTITY") | 49 if (type == "ENTITY") |
| 48 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; | 50 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
| 49 if (type == "INFINITE") | 51 if (type == "INFINITE") |
| 50 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; | 52 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
| 51 if (type == "PERSONALIZED_QUERY") | 53 if (type == "PERSONALIZED_QUERY") |
| 52 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; | 54 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
| 53 if (type == "PROFILE") | 55 if (type == "PROFILE") |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 if (error_code == 0) | 580 if (error_code == 0) |
| 579 return data.Pass(); | 581 return data.Pass(); |
| 580 } | 582 } |
| 581 return scoped_ptr<base::Value>(); | 583 return scoped_ptr<base::Value>(); |
| 582 } | 584 } |
| 583 | 585 |
| 584 // static | 586 // static |
| 585 bool BaseSearchProvider::ZeroSuggestEnabled( | 587 bool BaseSearchProvider::ZeroSuggestEnabled( |
| 586 const GURL& suggest_url, | 588 const GURL& suggest_url, |
| 587 const TemplateURL* template_url, | 589 const TemplateURL* template_url, |
| 588 AutocompleteInput::PageClassification page_classification, | 590 OmniboxEventProto::PageClassification page_classification, |
| 589 Profile* profile) { | 591 Profile* profile) { |
| 590 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) | 592 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) |
| 591 return false; | 593 return false; |
| 592 | 594 |
| 593 // Make sure we are sending the suggest request through HTTPS to prevent | 595 // Make sure we are sending the suggest request through HTTPS to prevent |
| 594 // exposing the current page URL or personalized results without encryption. | 596 // exposing the current page URL or personalized results without encryption. |
| 595 if (!suggest_url.SchemeIs(url::kHttpsScheme)) | 597 if (!suggest_url.SchemeIs(url::kHttpsScheme)) |
| 596 return false; | 598 return false; |
| 597 | 599 |
| 598 // Don't show zero suggest on the NTP. | 600 // Don't show zero suggest on the NTP. |
| 599 // TODO(hfung): Experiment with showing MostVisited zero suggest on NTP | 601 // TODO(hfung): Experiment with showing MostVisited zero suggest on NTP |
| 600 // under the conditions described in crbug.com/305366. | 602 // under the conditions described in crbug.com/305366. |
| 601 if ((page_classification == | 603 if ((page_classification == |
| 602 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) || | 604 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) || |
| 603 (page_classification == | 605 (page_classification == |
| 604 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS)) | 606 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS)) |
| 605 return false; | 607 return false; |
| 606 | 608 |
| 607 // Don't run if there's no profile or in incognito mode. | 609 // Don't run if there's no profile or in incognito mode. |
| 608 if (profile == NULL || profile->IsOffTheRecord()) | 610 if (profile == NULL || profile->IsOffTheRecord()) |
| 609 return false; | 611 return false; |
| 610 | 612 |
| 611 // Don't run if we can't get preferences or search suggest is not enabled. | 613 // Don't run if we can't get preferences or search suggest is not enabled. |
| 612 PrefService* prefs = profile->GetPrefs(); | 614 PrefService* prefs = profile->GetPrefs(); |
| 613 if (!prefs->GetBoolean(prefs::kSearchSuggestEnabled)) | 615 if (!prefs->GetBoolean(prefs::kSearchSuggestEnabled)) |
| 614 return false; | 616 return false; |
| 615 | 617 |
| 616 // Only make the request if we know that the provider supports zero suggest | 618 // Only make the request if we know that the provider supports zero suggest |
| 617 // (currently only the prepopulated Google provider). | 619 // (currently only the prepopulated Google provider). |
| 618 UIThreadSearchTermsData search_terms_data(profile); | 620 UIThreadSearchTermsData search_terms_data(profile); |
| 619 if (template_url == NULL || | 621 if (template_url == NULL || |
| 620 !template_url->SupportsReplacement(search_terms_data) || | 622 !template_url->SupportsReplacement(search_terms_data) || |
| 621 TemplateURLPrepopulateData::GetEngineType( | 623 TemplateURLPrepopulateData::GetEngineType( |
| 622 *template_url, search_terms_data) != SEARCH_ENGINE_GOOGLE) | 624 *template_url, search_terms_data) != SEARCH_ENGINE_GOOGLE) |
| 623 return false; | 625 return false; |
| 624 | 626 |
| 625 return true; | 627 return true; |
| 626 } | 628 } |
| 627 | 629 |
| 628 // static | 630 // static |
| 629 bool BaseSearchProvider::CanSendURL( | 631 bool BaseSearchProvider::CanSendURL( |
| 630 const GURL& current_page_url, | 632 const GURL& current_page_url, |
| 631 const GURL& suggest_url, | 633 const GURL& suggest_url, |
| 632 const TemplateURL* template_url, | 634 const TemplateURL* template_url, |
| 633 AutocompleteInput::PageClassification page_classification, | 635 OmniboxEventProto::PageClassification page_classification, |
| 634 Profile* profile) { | 636 Profile* profile) { |
| 635 if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, | 637 if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, |
| 636 profile)) | 638 profile)) |
| 637 return false; | 639 return false; |
| 638 | 640 |
| 639 if (!current_page_url.is_valid()) | 641 if (!current_page_url.is_valid()) |
| 640 return false; | 642 return false; |
| 641 | 643 |
| 642 // Only allow HTTP URLs or HTTPS URLs for the same domain as the search | 644 // Only allow HTTP URLs or HTTPS URLs for the same domain as the search |
| 643 // provider. | 645 // provider. |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 } | 978 } |
| 977 | 979 |
| 978 void BaseSearchProvider::OnDeletionComplete( | 980 void BaseSearchProvider::OnDeletionComplete( |
| 979 bool success, SuggestionDeletionHandler* handler) { | 981 bool success, SuggestionDeletionHandler* handler) { |
| 980 RecordDeletionResult(success); | 982 RecordDeletionResult(success); |
| 981 SuggestionDeletionHandlers::iterator it = std::find( | 983 SuggestionDeletionHandlers::iterator it = std::find( |
| 982 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 984 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 983 DCHECK(it != deletion_handlers_.end()); | 985 DCHECK(it != deletion_handlers_.end()); |
| 984 deletion_handlers_.erase(it); | 986 deletion_handlers_.erase(it); |
| 985 } | 987 } |
| OLD | NEW |