Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/search_engines/template_url.h" | 5 #include "chrome/browser/search_engines/template_url.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 bool TemplateURLRef::HasGoogleBaseURLs() const { | 461 bool TemplateURLRef::HasGoogleBaseURLs() const { |
| 462 ParseIfNecessary(); | 462 ParseIfNecessary(); |
| 463 for (size_t i = 0; i < replacements_.size(); ++i) { | 463 for (size_t i = 0; i < replacements_.size(); ++i) { |
| 464 if ((replacements_[i].type == GOOGLE_BASE_URL) || | 464 if ((replacements_[i].type == GOOGLE_BASE_URL) || |
| 465 (replacements_[i].type == GOOGLE_BASE_SUGGEST_URL)) | 465 (replacements_[i].type == GOOGLE_BASE_SUGGEST_URL)) |
| 466 return true; | 466 return true; |
| 467 } | 467 } |
| 468 return false; | 468 return false; |
| 469 } | 469 } |
| 470 | 470 |
| 471 bool TemplateURLRef::HasGoogleInstantExtendedParam() const { | |
| 472 ParseIfNecessary(); | |
| 473 for (size_t i = 0; i < replacements_.size(); ++i) | |
|
samarth
2013/01/14 23:37:04
Braces here please.
Jered
2013/01/14 23:57:27
Done.
| |
| 474 if (replacements_[i].type == GOOGLE_INSTANT_EXTENDED_ENABLED) | |
| 475 return true; | |
| 476 return false; | |
| 477 } | |
| 478 | |
| 471 bool TemplateURLRef::ExtractSearchTermsFromURL(const GURL& url, | 479 bool TemplateURLRef::ExtractSearchTermsFromURL(const GURL& url, |
| 472 string16* search_terms) const { | 480 string16* search_terms) const { |
| 473 DCHECK(search_terms); | 481 DCHECK(search_terms); |
| 474 search_terms->clear(); | 482 search_terms->clear(); |
| 475 | 483 |
| 476 ParseIfNecessary(); | 484 ParseIfNecessary(); |
| 477 | 485 |
| 478 // We need a search term in the template URL to extract something. | 486 // We need a search term in the template URL to extract something. |
| 479 if (search_term_key_.empty()) | 487 if (search_term_key_.empty()) |
| 480 return false; | 488 return false; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 const SearchTermsData& search_terms_data) const { | 802 const SearchTermsData& search_terms_data) const { |
| 795 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); | 803 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); |
| 796 } | 804 } |
| 797 | 805 |
| 798 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { | 806 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const { |
| 799 return !IsExtensionKeyword() && url_ref_.HasGoogleBaseURLs() && | 807 return !IsExtensionKeyword() && url_ref_.HasGoogleBaseURLs() && |
| 800 google_util::IsGoogleHostname(UTF16ToUTF8(data_.keyword()), | 808 google_util::IsGoogleHostname(UTF16ToUTF8(data_.keyword()), |
| 801 google_util::DISALLOW_SUBDOMAIN); | 809 google_util::DISALLOW_SUBDOMAIN); |
| 802 } | 810 } |
| 803 | 811 |
| 812 bool TemplateURL::SupportsInstantExtendedParam() const { | |
| 813 // TODO: Extend this to support other providers. | |
| 814 return instant_url_ref_.HasGoogleInstantExtendedParam(); | |
| 815 } | |
| 816 | |
| 804 bool TemplateURL::HasSameKeywordAs(const TemplateURL& other) const { | 817 bool TemplateURL::HasSameKeywordAs(const TemplateURL& other) const { |
| 805 return (data_.keyword() == other.data_.keyword()) || | 818 return (data_.keyword() == other.data_.keyword()) || |
| 806 (IsGoogleSearchURLWithReplaceableKeyword() && | 819 (IsGoogleSearchURLWithReplaceableKeyword() && |
| 807 other.IsGoogleSearchURLWithReplaceableKeyword()); | 820 other.IsGoogleSearchURLWithReplaceableKeyword()); |
| 808 } | 821 } |
| 809 | 822 |
| 810 std::string TemplateURL::GetExtensionId() const { | 823 std::string TemplateURL::GetExtensionId() const { |
| 811 DCHECK(IsExtensionKeyword()); | 824 DCHECK(IsExtensionKeyword()); |
| 812 return GURL(data_.url()).host(); | 825 return GURL(data_.url()).host(); |
| 813 } | 826 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 } | 909 } |
| 897 | 910 |
| 898 void TemplateURL::ResetKeywordIfNecessary(bool force) { | 911 void TemplateURL::ResetKeywordIfNecessary(bool force) { |
| 899 if (IsGoogleSearchURLWithReplaceableKeyword() || force) { | 912 if (IsGoogleSearchURLWithReplaceableKeyword() || force) { |
| 900 DCHECK(!IsExtensionKeyword()); | 913 DCHECK(!IsExtensionKeyword()); |
| 901 GURL url(TemplateURLService::GenerateSearchURL(this)); | 914 GURL url(TemplateURLService::GenerateSearchURL(this)); |
| 902 if (url.is_valid()) | 915 if (url.is_valid()) |
| 903 data_.SetKeyword(TemplateURLService::GenerateKeyword(url)); | 916 data_.SetKeyword(TemplateURLService::GenerateKeyword(url)); |
| 904 } | 917 } |
| 905 } | 918 } |
| OLD | NEW |