| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 // Converts the specified term in our owner's encoding to a string16. | 136 // Converts the specified term in our owner's encoding to a string16. |
| 137 string16 SearchTermToString16(const std::string& term) const; | 137 string16 SearchTermToString16(const std::string& term) const; |
| 138 | 138 |
| 139 // Returns true if this TemplateURLRef has a replacement term of | 139 // Returns true if this TemplateURLRef has a replacement term of |
| 140 // {google:baseURL} or {google:baseSuggestURL}. | 140 // {google:baseURL} or {google:baseSuggestURL}. |
| 141 bool HasGoogleBaseURLs() const; | 141 bool HasGoogleBaseURLs() const; |
| 142 | 142 |
| 143 // Use the pattern referred to by this TemplateURLRef to match the provided | 143 // Use the pattern referred to by this TemplateURLRef to match the provided |
| 144 // |url| and extract |search_terms| from it. Returns true if the pattern | 144 // |url| and extract |search_terms| from it. Returns true if the pattern |
| 145 // matches, even if |search_terms| is empty. Returns false and an empty | 145 // matches, even if |search_terms| is empty. In this case |
| 146 // |search_terms| if the pattern does not match. | 146 // |search_term_component|, if not NULL, indicates whether the search terms |
| 147 // were found in the query or the ref parameters; and |search_terms_position|, |
| 148 // if not NULL, contains the position of the search terms in the query or the |
| 149 // ref parameters. Returns false and an empty |search_terms| if the pattern |
| 150 // does not match. |
| 147 bool ExtractSearchTermsFromURL( | 151 bool ExtractSearchTermsFromURL( |
| 148 const GURL& url, | 152 const GURL& url, |
| 149 string16* search_terms, | 153 string16* search_terms, |
| 150 const SearchTermsData& search_terms_data) const; | 154 const SearchTermsData& search_terms_data, |
| 155 url_parse::Parsed::ComponentType* search_term_component, |
| 156 url_parse::Component* search_terms_position) const; |
| 151 | 157 |
| 152 private: | 158 private: |
| 153 friend class TemplateURL; | 159 friend class TemplateURL; |
| 154 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse); | 160 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse); |
| 155 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); | 161 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); |
| 156 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); | 162 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); |
| 157 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); | 163 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); |
| 158 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); | 164 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); |
| 159 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); | 165 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); |
| 160 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); | 166 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 const SearchTermsData& search_terms_data); | 514 const SearchTermsData& search_terms_data); |
| 509 | 515 |
| 510 // Returns true if the specified |url| contains the search terms replacement | 516 // Returns true if the specified |url| contains the search terms replacement |
| 511 // key in either the query or the ref. This method does not verify anything | 517 // key in either the query or the ref. This method does not verify anything |
| 512 // else about the URL. In particular, it does not check that the domain | 518 // else about the URL. In particular, it does not check that the domain |
| 513 // matches that of this TemplateURL. | 519 // matches that of this TemplateURL. |
| 514 // TODO(beaudoin): Rename this to reflect that it really checks for an | 520 // TODO(beaudoin): Rename this to reflect that it really checks for an |
| 515 // InstantExtended capable URL. | 521 // InstantExtended capable URL. |
| 516 bool HasSearchTermsReplacementKey(const GURL& url) const; | 522 bool HasSearchTermsReplacementKey(const GURL& url) const; |
| 517 | 523 |
| 524 // Given a |url| corresponding to this TemplateURL, identifies the search |
| 525 // terms and replaces them with the ones in |search_terms_args|, leaving the |
| 526 // other parameters untouched. If the replacement fails, returns false and |
| 527 // leaves |result| untouched. This is used by mobile ports to perform query |
| 528 // refinement. |
| 529 bool ReplaceSearchTermsInURL( |
| 530 const GURL& url, |
| 531 const TemplateURLRef::SearchTermsArgs& search_terms_args, |
| 532 GURL* result); |
| 533 |
| 534 // Encodes the search terms from |search_terms_args| so that we know the |
| 535 // |input_encoding|. Returns the |encoded_terms| and the |
| 536 // |encoded_original_query|. |encoded_terms| may be escaped as path or query |
| 537 // depending on |is_in_query|; |encoded_original_query| is always escaped as |
| 538 // query. |
| 539 void EncodeSearchTerms( |
| 540 const TemplateURLRef::SearchTermsArgs& search_terms_args, |
| 541 bool is_in_query, |
| 542 std::string* input_encoding, |
| 543 string16* encoded_terms, |
| 544 string16* encoded_original_query) const; |
| 545 |
| 518 private: | 546 private: |
| 519 friend class TemplateURLService; | 547 friend class TemplateURLService; |
| 520 | 548 |
| 521 void CopyFrom(const TemplateURL& other); | 549 void CopyFrom(const TemplateURL& other); |
| 522 | 550 |
| 523 void SetURL(const std::string& url); | 551 void SetURL(const std::string& url); |
| 524 void SetPrepopulateId(int id); | 552 void SetPrepopulateId(int id); |
| 525 | 553 |
| 526 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. | 554 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. |
| 527 // The |force| parameter is useful when the existing keyword is known to be | 555 // The |force| parameter is useful when the existing keyword is known to be |
| 528 // a placeholder. The resulting keyword is generated using | 556 // a placeholder. The resulting keyword is generated using |
| 529 // TemplateURLService::GenerateSearchURL() and | 557 // TemplateURLService::GenerateSearchURL() and |
| 530 // TemplateURLService::GenerateKeyword(). | 558 // TemplateURLService::GenerateKeyword(). |
| 531 void ResetKeywordIfNecessary(bool force); | 559 void ResetKeywordIfNecessary(bool force); |
| 532 | 560 |
| 561 // Uses the alternate URLs and the search URL to match the provided |url| |
| 562 // and extract |search_terms| from it as well as the |search_terms_component| |
| 563 // (either REF or QUERY) and |search_terms_component| at which the |
| 564 // |search_terms| are found in |url|. See also ExtractSearchTermsFromURL(). |
| 565 bool FindSearchTermsInURL( |
| 566 const GURL& url, |
| 567 const SearchTermsData& search_terms_data, |
| 568 string16* search_terms, |
| 569 url_parse::Parsed::ComponentType* search_terms_component, |
| 570 url_parse::Component* search_terms_position); |
| 571 |
| 533 Profile* profile_; | 572 Profile* profile_; |
| 534 TemplateURLData data_; | 573 TemplateURLData data_; |
| 535 TemplateURLRef url_ref_; | 574 TemplateURLRef url_ref_; |
| 536 TemplateURLRef suggestions_url_ref_; | 575 TemplateURLRef suggestions_url_ref_; |
| 537 TemplateURLRef instant_url_ref_; | 576 TemplateURLRef instant_url_ref_; |
| 538 | 577 |
| 539 // TODO(sky): Add date last parsed OSD file. | 578 // TODO(sky): Add date last parsed OSD file. |
| 540 | 579 |
| 541 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 580 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
| 542 }; | 581 }; |
| 543 | 582 |
| 544 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 583 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| OLD | NEW |