| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // the host/path of the URL, otherwise this returns an empty string. | 254 // the host/path of the URL, otherwise this returns an empty string. |
| 255 const std::string& GetHost(const SearchTermsData& search_terms_data) const; | 255 const std::string& GetHost(const SearchTermsData& search_terms_data) const; |
| 256 const std::string& GetPath(const SearchTermsData& search_terms_data) const; | 256 const std::string& GetPath(const SearchTermsData& search_terms_data) const; |
| 257 | 257 |
| 258 // If this TemplateURLRef is valid and contains one search term | 258 // If this TemplateURLRef is valid and contains one search term |
| 259 // in its query or ref, this returns the key of the search term, | 259 // in its query or ref, this returns the key of the search term, |
| 260 // otherwise this returns an empty string. | 260 // otherwise this returns an empty string. |
| 261 const std::string& GetSearchTermKey( | 261 const std::string& GetSearchTermKey( |
| 262 const SearchTermsData& search_terms_data) const; | 262 const SearchTermsData& search_terms_data) const; |
| 263 | 263 |
| 264 // If this TemplateURLRef is valid and contains one search term | |
| 265 // in its path, this returns the length of the subpath before the search term, | |
| 266 // otherwise this returns std::string::npos. | |
| 267 size_t GetSearchTermPositionInPath( | |
| 268 const SearchTermsData& search_terms_data) const; | |
| 269 | |
| 270 // If this TemplateURLRef is valid and contains one search term, | 264 // If this TemplateURLRef is valid and contains one search term, |
| 271 // this returns the location of the search term, | 265 // this returns the location of the search term, |
| 272 // otherwise this returns url::Parsed::QUERY. | 266 // otherwise this returns url::Parsed::QUERY. |
| 273 url::Parsed::ComponentType GetSearchTermKeyLocation( | 267 url::Parsed::ComponentType GetSearchTermKeyLocation( |
| 274 const SearchTermsData& search_terms_data) const; | 268 const SearchTermsData& search_terms_data) const; |
| 275 | 269 |
| 270 // If this TemplateURLRef is valid and contains one search term, |
| 271 // this returns the fixed prefix of the value of the search term, |
| 272 // otherwise this returns an empty string. |
| 273 const std::string& GetSearchTermValuePrefix( |
| 274 const SearchTermsData& search_terms_data) const; |
| 275 |
| 276 // If this TemplateURLRef is valid and contains one search term, |
| 277 // this returns the fixed suffix of the value of the search term, |
| 278 // otherwise this returns an empty string. |
| 279 const std::string& GetSearchTermValueSuffix( |
| 280 const SearchTermsData& search_terms_data) const; |
| 281 |
| 276 // Converts the specified term in our owner's encoding to a base::string16. | 282 // Converts the specified term in our owner's encoding to a base::string16. |
| 277 base::string16 SearchTermToString16(const std::string& term) const; | 283 base::string16 SearchTermToString16(const std::string& term) const; |
| 278 | 284 |
| 279 // Returns true if this TemplateURLRef has a replacement term of | 285 // Returns true if this TemplateURLRef has a replacement term of |
| 280 // {google:baseURL} or {google:baseSuggestURL}. | 286 // {google:baseURL} or {google:baseSuggestURL}. |
| 281 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; | 287 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; |
| 282 | 288 |
| 283 // Use the pattern referred to by this TemplateURLRef to match the provided | 289 // Use the pattern referred to by this TemplateURLRef to match the provided |
| 284 // |url| and extract |search_terms| from it. Returns true if the pattern | 290 // |url| and extract |search_terms| from it. Returns true if the pattern |
| 285 // matches, even if |search_terms| is empty. In this case | 291 // matches, even if |search_terms| is empty. In this case |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 struct PostParam { | 368 struct PostParam { |
| 363 std::string name; | 369 std::string name; |
| 364 std::string value; | 370 std::string value; |
| 365 std::string content_type; | 371 std::string content_type; |
| 366 }; | 372 }; |
| 367 | 373 |
| 368 // The list of elements to replace. | 374 // The list of elements to replace. |
| 369 typedef std::vector<struct Replacement> Replacements; | 375 typedef std::vector<struct Replacement> Replacements; |
| 370 typedef std::vector<PostParam> PostParams; | 376 typedef std::vector<PostParam> PostParams; |
| 371 | 377 |
| 378 // Checks that |path| matches to this TemplateURLRef's path and |
| 379 // extracts the position of the search terms inside |path|. |
| 380 // This is a helper function for extracting search terms from URL. |
| 381 bool ExtractSearchTermsFromPath(const std::string& path, |
| 382 url::Component* search_terms_position) const; |
| 383 |
| 372 // TemplateURLRef internally caches values to make replacement quick. This | 384 // TemplateURLRef internally caches values to make replacement quick. This |
| 373 // method invalidates any cached values. | 385 // method invalidates any cached values. |
| 374 void InvalidateCachedValues() const; | 386 void InvalidateCachedValues() const; |
| 375 | 387 |
| 376 // Parses the parameter in url at the specified offset. start/end specify the | 388 // Parses the parameter in url at the specified offset. start/end specify the |
| 377 // range of the parameter in the url, including the braces. If the parameter | 389 // range of the parameter in the url, including the braces. If the parameter |
| 378 // is valid, url is updated to reflect the appropriate parameter. If | 390 // is valid, url is updated to reflect the appropriate parameter. If |
| 379 // the parameter is one of the known parameters an element is added to | 391 // the parameter is one of the known parameters an element is added to |
| 380 // replacements indicating the type and range of the element. The original | 392 // replacements indicating the type and range of the element. The original |
| 381 // parameter is erased from the url. | 393 // parameter is erased from the url. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // The replaceable parts of url (parsed_url_). These are ordered by index | 470 // The replaceable parts of url (parsed_url_). These are ordered by index |
| 459 // into the string, and may be empty. | 471 // into the string, and may be empty. |
| 460 mutable Replacements replacements_; | 472 mutable Replacements replacements_; |
| 461 | 473 |
| 462 // Host, port, path, key and location of the search term. These are only set | 474 // Host, port, path, key and location of the search term. These are only set |
| 463 // if the url contains one search term. | 475 // if the url contains one search term. |
| 464 mutable std::string host_; | 476 mutable std::string host_; |
| 465 mutable std::string port_; | 477 mutable std::string port_; |
| 466 mutable std::string path_; | 478 mutable std::string path_; |
| 467 mutable std::string search_term_key_; | 479 mutable std::string search_term_key_; |
| 468 mutable size_t search_term_position_in_path_; | |
| 469 mutable url::Parsed::ComponentType search_term_key_location_; | 480 mutable url::Parsed::ComponentType search_term_key_location_; |
| 470 mutable std::string search_term_value_prefix_; | 481 mutable std::string search_term_value_prefix_; |
| 471 mutable std::string search_term_value_suffix_; | 482 mutable std::string search_term_value_suffix_; |
| 472 | 483 |
| 473 mutable PostParams post_params_; | 484 mutable PostParams post_params_; |
| 474 | 485 |
| 475 // Whether the contained URL is a pre-populated URL. | 486 // Whether the contained URL is a pre-populated URL. |
| 476 bool prepopulated_; | 487 bool prepopulated_; |
| 477 }; | 488 }; |
| 478 | 489 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 TemplateURLRef new_tab_url_ref_; | 759 TemplateURLRef new_tab_url_ref_; |
| 749 TemplateURLRef contextual_search_url_ref_; | 760 TemplateURLRef contextual_search_url_ref_; |
| 750 std::unique_ptr<AssociatedExtensionInfo> extension_info_; | 761 std::unique_ptr<AssociatedExtensionInfo> extension_info_; |
| 751 | 762 |
| 752 // TODO(sky): Add date last parsed OSD file. | 763 // TODO(sky): Add date last parsed OSD file. |
| 753 | 764 |
| 754 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 765 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
| 755 }; | 766 }; |
| 756 | 767 |
| 757 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 768 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| OLD | NEW |