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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Converts the specified term in our owner's encoding to a string16. | 133 // Converts the specified term in our owner's encoding to a string16. |
134 string16 SearchTermToString16(const std::string& term) const; | 134 string16 SearchTermToString16(const std::string& term) const; |
135 | 135 |
136 // Returns true if this TemplateURLRef has a replacement term of | 136 // Returns true if this TemplateURLRef has a replacement term of |
137 // {google:baseURL} or {google:baseSuggestURL}. | 137 // {google:baseURL} or {google:baseSuggestURL}. |
138 bool HasGoogleBaseURLs() const; | 138 bool HasGoogleBaseURLs() const; |
139 | 139 |
140 // Use the pattern referred to by this TemplateURLRef to match the provided | 140 // Use the pattern referred to by this TemplateURLRef to match the provided |
141 // |url| and extract |search_terms| from it. Returns true if the pattern | 141 // |url| and extract |search_terms| from it. Returns true if the pattern |
142 // matches, even if |search_terms| is empty. Returns false and an empty | 142 // matches, even if |search_terms| is empty. Returns false and an empty |
143 // |search_terms| if the pattern does not match. | 143 // |search_terms| if the pattern does not match. If |need_instant_extended| |
| 144 // is true, then a match will only be returned if the instant extended |
| 145 // parameter is found and non-zero, moreover, the instant extended parameter |
| 146 // must be found in the same region as the search term (the query or the ref). |
144 bool ExtractSearchTermsFromURL(const GURL& url, | 147 bool ExtractSearchTermsFromURL(const GURL& url, |
145 string16* search_terms) const; | 148 string16* search_terms, |
| 149 bool needs_instant_extended) const; |
146 | 150 |
147 private: | 151 private: |
148 friend class TemplateURL; | 152 friend class TemplateURL; |
149 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse); | 153 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse); |
150 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); | 154 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); |
151 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); | 155 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); |
152 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); | 156 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); |
153 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); | 157 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); |
154 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); | 158 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); |
155 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); | 159 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 size_t URLCount() const; | 474 size_t URLCount() const; |
471 | 475 |
472 // Gets the search URL at the given index. The alternate URLs, if any, are | 476 // Gets the search URL at the given index. The alternate URLs, if any, are |
473 // numbered starting at 0, and the primary search URL follows. This is used | 477 // numbered starting at 0, and the primary search URL follows. This is used |
474 // to decode the search term given a search URL (see | 478 // to decode the search term given a search URL (see |
475 // ExtractSearchTermsFromURL()). | 479 // ExtractSearchTermsFromURL()). |
476 const std::string& GetURL(size_t index) const; | 480 const std::string& GetURL(size_t index) const; |
477 | 481 |
478 // Use the alternate URLs and the search URL to match the provided |url| | 482 // Use the alternate URLs and the search URL to match the provided |url| |
479 // and extract |search_terms| from it. Returns false and an empty | 483 // and extract |search_terms| from it. Returns false and an empty |
480 // |search_terms| if no search terms can be matched. The order in which the | 484 // |search_terms| if no search terms can be matched. The method also returns |
481 // alternate URLs are listed dictates their priority, the URL at index 0 | 485 // false if |needs_instant_extended| is true and the query or ref parameter |
482 // is treated as the highest priority and the primary search URL is treated | 486 // corresponding to search_terms_replacement_key() is not found or is 0. |
483 // as the lowest priority (see GetURL()). For example, if a TemplateURL has | 487 // The order in which the alternate URLs are listed dictates their priority, |
484 // alternate URL "http://foo/#q={searchTerms}" and search URL | 488 // the URL at index 0 is treated as the highest priority and the primary |
485 // "http://foo/?q={searchTerms}", and the URL to be decoded is | 489 // search URL is treated as the lowest priority (see GetURL()). For example, |
| 490 // if a TemplateURL has alternate URL "http://foo/#q={searchTerms}" and search |
| 491 // URL "http://foo/?q={searchTerms}", and the URL to be decoded is |
486 // "http://foo/?q=a#q=b", the alternate URL will match first and the decoded | 492 // "http://foo/?q=a#q=b", the alternate URL will match first and the decoded |
487 // search term will be "b". | 493 // search term will be "b". |
488 bool ExtractSearchTermsFromURL(const GURL& url, string16* search_terms); | 494 bool ExtractSearchTermsFromURL(const GURL& url, |
| 495 string16* search_terms, |
| 496 bool needs_instant_extended); |
489 | 497 |
490 private: | 498 private: |
491 friend class TemplateURLService; | 499 friend class TemplateURLService; |
492 | 500 |
493 void CopyFrom(const TemplateURL& other); | 501 void CopyFrom(const TemplateURL& other); |
494 | 502 |
495 void SetURL(const std::string& url); | 503 void SetURL(const std::string& url); |
496 void SetPrepopulateId(int id); | 504 void SetPrepopulateId(int id); |
497 | 505 |
498 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. | 506 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. |
499 // The |force| parameter is useful when the existing keyword is known to be | 507 // The |force| parameter is useful when the existing keyword is known to be |
500 // a placeholder. The resulting keyword is generated using | 508 // a placeholder. The resulting keyword is generated using |
501 // TemplateURLService::GenerateSearchURL() and | 509 // TemplateURLService::GenerateSearchURL() and |
502 // TemplateURLService::GenerateKeyword(). | 510 // TemplateURLService::GenerateKeyword(). |
503 void ResetKeywordIfNecessary(bool force); | 511 void ResetKeywordIfNecessary(bool force); |
504 | 512 |
505 Profile* profile_; | 513 Profile* profile_; |
506 TemplateURLData data_; | 514 TemplateURLData data_; |
507 TemplateURLRef url_ref_; | 515 TemplateURLRef url_ref_; |
508 TemplateURLRef suggestions_url_ref_; | 516 TemplateURLRef suggestions_url_ref_; |
509 TemplateURLRef instant_url_ref_; | 517 TemplateURLRef instant_url_ref_; |
510 | 518 |
511 // TODO(sky): Add date last parsed OSD file. | 519 // TODO(sky): Add date last parsed OSD file. |
512 | 520 |
513 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 521 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
514 }; | 522 }; |
515 | 523 |
516 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 524 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |