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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 NORMAL_CONTROLLED_BY_EXTENSION, | 475 NORMAL_CONTROLLED_BY_EXTENSION, |
476 // The keyword associated with an extension that uses the Omnibox API. | 476 // The keyword associated with an extension that uses the Omnibox API. |
477 OMNIBOX_API_EXTENSION, | 477 OMNIBOX_API_EXTENSION, |
478 }; | 478 }; |
479 explicit TemplateURL(const TemplateURLData& data); | 479 explicit TemplateURL(const TemplateURLData& data); |
480 ~TemplateURL(); | 480 ~TemplateURL(); |
481 | 481 |
482 // Generates a favicon URL from the specified url. | 482 // Generates a favicon URL from the specified url. |
483 static GURL GenerateFaviconURL(const GURL& url); | 483 static GURL GenerateFaviconURL(const GURL& url); |
484 | 484 |
485 // Generates a suitable keyword for the specified url, which must be valid. | |
486 // This is guaranteed not to return an empty string, since TemplateURLs should | |
487 // never have an empty keyword. | |
488 static base::string16 GenerateKeyword(const GURL& url); | |
Peter Kasting
2014/06/19 17:41:59
Tiny nit: Given that the keyword member comes befo
hashimoto
2014/06/19 17:56:05
Makes sense.
Done.
| |
489 | |
485 // Returns true if |t_url| and |data| are equal in all meaningful respects. | 490 // Returns true if |t_url| and |data| are equal in all meaningful respects. |
486 // Static to allow either or both params to be NULL. | 491 // Static to allow either or both params to be NULL. |
487 static bool MatchesData(const TemplateURL* t_url, | 492 static bool MatchesData(const TemplateURL* t_url, |
488 const TemplateURLData* data, | 493 const TemplateURLData* data, |
489 const SearchTermsData& search_terms_data); | 494 const SearchTermsData& search_terms_data); |
490 | 495 |
491 const TemplateURLData& data() const { return data_; } | 496 const TemplateURLData& data() const { return data_; } |
492 | 497 |
493 const base::string16& short_name() const { return data_.short_name; } | 498 const base::string16& short_name() const { return data_.short_name; } |
494 // An accessor for the short_name, but adjusted so it can be appropriately | 499 // An accessor for the short_name, but adjusted so it can be appropriately |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 // |encoded_original_query|. |encoded_terms| may be escaped as path or query | 647 // |encoded_original_query|. |encoded_terms| may be escaped as path or query |
643 // depending on |is_in_query|; |encoded_original_query| is always escaped as | 648 // depending on |is_in_query|; |encoded_original_query| is always escaped as |
644 // query. | 649 // query. |
645 void EncodeSearchTerms( | 650 void EncodeSearchTerms( |
646 const TemplateURLRef::SearchTermsArgs& search_terms_args, | 651 const TemplateURLRef::SearchTermsArgs& search_terms_args, |
647 bool is_in_query, | 652 bool is_in_query, |
648 std::string* input_encoding, | 653 std::string* input_encoding, |
649 base::string16* encoded_terms, | 654 base::string16* encoded_terms, |
650 base::string16* encoded_original_query) const; | 655 base::string16* encoded_original_query) const; |
651 | 656 |
657 // Returns the search url for this template URL. | |
658 // Returns an empty GURL if this template URL has no url(). | |
659 GURL GenerateSearchURL(const SearchTermsData& search_terms_data) const; | |
660 | |
652 private: | 661 private: |
653 friend class TemplateURLService; | 662 friend class TemplateURLService; |
654 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ReflectsBookmarkBarPinned); | 663 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ReflectsBookmarkBarPinned); |
655 | 664 |
656 void CopyFrom(const TemplateURL& other); | 665 void CopyFrom(const TemplateURL& other); |
657 | 666 |
658 void SetURL(const std::string& url); | 667 void SetURL(const std::string& url); |
659 void SetPrepopulateId(int id); | 668 void SetPrepopulateId(int id); |
660 | 669 |
661 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. | 670 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. |
662 // The |force| parameter is useful when the existing keyword is known to be | 671 // The |force| parameter is useful when the existing keyword is known to be |
663 // a placeholder. The resulting keyword is generated using | 672 // a placeholder. The resulting keyword is generated using |
664 // TemplateURLService::GenerateSearchURL() and | 673 // GenerateSearchURL() and GenerateKeyword(). |
665 // TemplateURLService::GenerateKeyword(). | |
666 void ResetKeywordIfNecessary(const SearchTermsData& search_terms_data, | 674 void ResetKeywordIfNecessary(const SearchTermsData& search_terms_data, |
667 bool force); | 675 bool force); |
668 | 676 |
669 // Uses the alternate URLs and the search URL to match the provided |url| | 677 // Uses the alternate URLs and the search URL to match the provided |url| |
670 // and extract |search_terms| from it as well as the |search_terms_component| | 678 // and extract |search_terms| from it as well as the |search_terms_component| |
671 // (either REF or QUERY) and |search_terms_component| at which the | 679 // (either REF or QUERY) and |search_terms_component| at which the |
672 // |search_terms| are found in |url|. See also ExtractSearchTermsFromURL(). | 680 // |search_terms| are found in |url|. See also ExtractSearchTermsFromURL(). |
673 bool FindSearchTermsInURL(const GURL& url, | 681 bool FindSearchTermsInURL(const GURL& url, |
674 const SearchTermsData& search_terms_data, | 682 const SearchTermsData& search_terms_data, |
675 base::string16* search_terms, | 683 base::string16* search_terms, |
676 url::Parsed::ComponentType* search_terms_component, | 684 url::Parsed::ComponentType* search_terms_component, |
677 url::Component* search_terms_position); | 685 url::Component* search_terms_position); |
678 | 686 |
679 TemplateURLData data_; | 687 TemplateURLData data_; |
680 TemplateURLRef url_ref_; | 688 TemplateURLRef url_ref_; |
681 TemplateURLRef suggestions_url_ref_; | 689 TemplateURLRef suggestions_url_ref_; |
682 TemplateURLRef instant_url_ref_; | 690 TemplateURLRef instant_url_ref_; |
683 TemplateURLRef image_url_ref_; | 691 TemplateURLRef image_url_ref_; |
684 TemplateURLRef new_tab_url_ref_; | 692 TemplateURLRef new_tab_url_ref_; |
685 TemplateURLRef contextual_search_url_ref_; | 693 TemplateURLRef contextual_search_url_ref_; |
686 scoped_ptr<AssociatedExtensionInfo> extension_info_; | 694 scoped_ptr<AssociatedExtensionInfo> extension_info_; |
687 | 695 |
688 // TODO(sky): Add date last parsed OSD file. | 696 // TODO(sky): Add date last parsed OSD file. |
689 | 697 |
690 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 698 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
691 }; | 699 }; |
692 | 700 |
693 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 701 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |