| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 // Returns a string representation of this TemplateURLRef suitable for | 115 // Returns a string representation of this TemplateURLRef suitable for |
| 116 // display. The display format is the same as the format used by Firefox. | 116 // display. The display format is the same as the format used by Firefox. |
| 117 string16 DisplayURL() const; | 117 string16 DisplayURL() const; |
| 118 | 118 |
| 119 // Converts a string as returned by DisplayURL back into a string as | 119 // Converts a string as returned by DisplayURL back into a string as |
| 120 // understood by TemplateURLRef. | 120 // understood by TemplateURLRef. |
| 121 static std::string DisplayURLToURLRef(const string16& display_url); | 121 static std::string DisplayURLToURLRef(const string16& display_url); |
| 122 | 122 |
| 123 // If this TemplateURLRef is valid and contains one search term, this returns | 123 // If this TemplateURLRef is valid and contains one search term, this returns |
| 124 // the scheme/host/path of the URL, otherwise this returns an empty string. | 124 // the host/path of the URL, otherwise this returns an empty string. |
| 125 const std::string& GetScheme() const; | |
| 126 const std::string& GetHost() const; | 125 const std::string& GetHost() const; |
| 127 const std::string& GetPath() const; | 126 const std::string& GetPath() const; |
| 128 | 127 |
| 129 // If this TemplateURLRef is valid and contains one search term, this returns | 128 // If this TemplateURLRef is valid and contains one search term, this returns |
| 130 // the key of the search term, otherwise this returns an empty string. | 129 // the key of the search term, otherwise this returns an empty string. |
| 131 const std::string& GetSearchTermKey() const; | 130 const std::string& GetSearchTermKey() const; |
| 132 | 131 |
| 133 // Converts the specified term in our owner's encoding to a string16. | 132 // Converts the specified term in our owner's encoding to a string16. |
| 134 string16 SearchTermToString16(const std::string& term) const; | 133 string16 SearchTermToString16(const std::string& term) const; |
| 135 | 134 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // replacements_ giving the index of the terms to replace. | 244 // replacements_ giving the index of the terms to replace. |
| 246 mutable std::string parsed_url_; | 245 mutable std::string parsed_url_; |
| 247 | 246 |
| 248 // Do we support replacement? | 247 // Do we support replacement? |
| 249 mutable bool supports_replacements_; | 248 mutable bool supports_replacements_; |
| 250 | 249 |
| 251 // The replaceable parts of url (parsed_url_). These are ordered by index | 250 // The replaceable parts of url (parsed_url_). These are ordered by index |
| 252 // into the string, and may be empty. | 251 // into the string, and may be empty. |
| 253 mutable Replacements replacements_; | 252 mutable Replacements replacements_; |
| 254 | 253 |
| 255 // Scheme, host, path, key and location of the search term. These are only set | 254 // Host, path, key and location of the search term. These are only set if the |
| 256 // if the url contains one search term. | 255 // url contains one search term. |
| 257 mutable std::string scheme_; | |
| 258 mutable std::string host_; | 256 mutable std::string host_; |
| 259 mutable std::string path_; | 257 mutable std::string path_; |
| 260 mutable std::string search_term_key_; | 258 mutable std::string search_term_key_; |
| 261 mutable url_parse::Parsed::ComponentType search_term_key_location_; | 259 mutable url_parse::Parsed::ComponentType search_term_key_location_; |
| 262 | 260 |
| 263 // Whether the contained URL is a pre-populated URL. | 261 // Whether the contained URL is a pre-populated URL. |
| 264 bool prepopulated_; | 262 bool prepopulated_; |
| 265 | 263 |
| 266 DISALLOW_COPY_AND_ASSIGN(TemplateURLRef); | 264 DISALLOW_COPY_AND_ASSIGN(TemplateURLRef); |
| 267 }; | 265 }; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 bool ExtractSearchTermsFromURL(const GURL& url, string16* search_terms); | 484 bool ExtractSearchTermsFromURL(const GURL& url, string16* search_terms); |
| 487 | 485 |
| 488 // Returns true if the specified |url| contains the search terms replacement | 486 // Returns true if the specified |url| contains the search terms replacement |
| 489 // key in either the query or the ref. This method does not verify anything | 487 // key in either the query or the ref. This method does not verify anything |
| 490 // else about the URL. In particular, it does not check that the domain | 488 // else about the URL. In particular, it does not check that the domain |
| 491 // matches that of this TemplateURL. | 489 // matches that of this TemplateURL. |
| 492 // TODO(beaudoin): Rename this to reflect that it really checks for an | 490 // TODO(beaudoin): Rename this to reflect that it really checks for an |
| 493 // InstantExtended capable URL. | 491 // InstantExtended capable URL. |
| 494 bool HasSearchTermsReplacementKey(const GURL& url) const; | 492 bool HasSearchTermsReplacementKey(const GURL& url) const; |
| 495 | 493 |
| 496 // Returns true if the specified |url| matches the search, alternates, or | |
| 497 // instant url in scheme, domain, and path. In addition, the search term | |
| 498 // replacement key must be present in the |url|. | |
| 499 // This predicate is used for site isolation purposes, so has security | |
| 500 // implications. Seek security review if changing it. | |
| 501 bool IsInstantURL(const GURL& url); | |
| 502 | |
| 503 private: | 494 private: |
| 504 friend class TemplateURLService; | 495 friend class TemplateURLService; |
| 505 | 496 |
| 506 void CopyFrom(const TemplateURL& other); | 497 void CopyFrom(const TemplateURL& other); |
| 507 | 498 |
| 508 void SetURL(const std::string& url); | 499 void SetURL(const std::string& url); |
| 509 void SetPrepopulateId(int id); | 500 void SetPrepopulateId(int id); |
| 510 | 501 |
| 511 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. | 502 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. |
| 512 // The |force| parameter is useful when the existing keyword is known to be | 503 // The |force| parameter is useful when the existing keyword is known to be |
| 513 // a placeholder. The resulting keyword is generated using | 504 // a placeholder. The resulting keyword is generated using |
| 514 // TemplateURLService::GenerateSearchURL() and | 505 // TemplateURLService::GenerateSearchURL() and |
| 515 // TemplateURLService::GenerateKeyword(). | 506 // TemplateURLService::GenerateKeyword(). |
| 516 void ResetKeywordIfNecessary(bool force); | 507 void ResetKeywordIfNecessary(bool force); |
| 517 | 508 |
| 518 Profile* profile_; | 509 Profile* profile_; |
| 519 TemplateURLData data_; | 510 TemplateURLData data_; |
| 520 TemplateURLRef url_ref_; | 511 TemplateURLRef url_ref_; |
| 521 TemplateURLRef suggestions_url_ref_; | 512 TemplateURLRef suggestions_url_ref_; |
| 522 TemplateURLRef instant_url_ref_; | 513 TemplateURLRef instant_url_ref_; |
| 523 | 514 |
| 524 // TODO(sky): Add date last parsed OSD file. | 515 // TODO(sky): Add date last parsed OSD file. |
| 525 | 516 |
| 526 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 517 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
| 527 }; | 518 }; |
| 528 | 519 |
| 529 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 520 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| OLD | NEW |