| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 // Converts a string as returned by DisplayURL back into a string as | 249 // Converts a string as returned by DisplayURL back into a string as |
| 250 // understood by TemplateURLRef. | 250 // understood by TemplateURLRef. |
| 251 static std::string DisplayURLToURLRef(const base::string16& display_url); | 251 static std::string DisplayURLToURLRef(const base::string16& display_url); |
| 252 | 252 |
| 253 // If this TemplateURLRef is valid and contains one search term, this returns | 253 // If this TemplateURLRef is valid and contains one search term, this returns |
| 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, this returns |
| 259 // whether its path ends with text "{google:ignorePathEnding}", otherwise this |
| 260 // returns false. |
| 261 bool GetIgnorePathEnding(const SearchTermsData& search_terms_data) const; |
| 262 |
| 258 // If this TemplateURLRef is valid and contains one search term | 263 // If this TemplateURLRef is valid and contains one search term |
| 259 // in its query or ref, this returns the key of the search term, | 264 // in its query or ref, this returns the key of the search term, |
| 260 // otherwise this returns an empty string. | 265 // otherwise this returns an empty string. |
| 261 const std::string& GetSearchTermKey( | 266 const std::string& GetSearchTermKey( |
| 262 const SearchTermsData& search_terms_data) const; | 267 const SearchTermsData& search_terms_data) const; |
| 263 | 268 |
| 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, | 269 // If this TemplateURLRef is valid and contains one search term, |
| 271 // this returns the location of the search term, | 270 // this returns the location of the search term, |
| 272 // otherwise this returns url::Parsed::QUERY. | 271 // otherwise this returns url::Parsed::QUERY. |
| 273 url::Parsed::ComponentType GetSearchTermKeyLocation( | 272 url::Parsed::ComponentType GetSearchTermKeyLocation( |
| 274 const SearchTermsData& search_terms_data) const; | 273 const SearchTermsData& search_terms_data) const; |
| 275 | 274 |
| 275 // If this TemplateURLRef is valid and contains one search term, |
| 276 // this returns the fixed prefix of the value of the search term, |
| 277 // otherwise this returns an empty string. |
| 278 const std::string& GetSearchTermValuePrefix( |
| 279 const SearchTermsData& search_terms_data) const; |
| 280 |
| 281 // If this TemplateURLRef is valid and contains one search term, |
| 282 // this returns the fixed suffix of the value of the search term, |
| 283 // otherwise this returns an empty string. |
| 284 const std::string& GetSearchTermValueSuffix( |
| 285 const SearchTermsData& search_terms_data) const; |
| 286 |
| 276 // Converts the specified term in our owner's encoding to a base::string16. | 287 // Converts the specified term in our owner's encoding to a base::string16. |
| 277 base::string16 SearchTermToString16(const std::string& term) const; | 288 base::string16 SearchTermToString16(const std::string& term) const; |
| 278 | 289 |
| 279 // Returns true if this TemplateURLRef has a replacement term of | 290 // Returns true if this TemplateURLRef has a replacement term of |
| 280 // {google:baseURL} or {google:baseSuggestURL}. | 291 // {google:baseURL} or {google:baseSuggestURL}. |
| 281 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; | 292 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; |
| 282 | 293 |
| 283 // Use the pattern referred to by this TemplateURLRef to match the provided | 294 // 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 | 295 // |url| and extract |search_terms| from it. Returns true if the pattern |
| 285 // matches, even if |search_terms| is empty. In this case | 296 // 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 { | 373 struct PostParam { |
| 363 std::string name; | 374 std::string name; |
| 364 std::string value; | 375 std::string value; |
| 365 std::string content_type; | 376 std::string content_type; |
| 366 }; | 377 }; |
| 367 | 378 |
| 368 // The list of elements to replace. | 379 // The list of elements to replace. |
| 369 typedef std::vector<struct Replacement> Replacements; | 380 typedef std::vector<struct Replacement> Replacements; |
| 370 typedef std::vector<PostParam> PostParams; | 381 typedef std::vector<PostParam> PostParams; |
| 371 | 382 |
| 383 // Checks that |path| matches to this TemplateURLRef's path. |
| 384 // This is a helper function for extracting search terms from URL. |
| 385 bool MatchPath(const std::string& path) const; |
| 386 |
| 387 // Checks that |path| matches to this TemplateURLRef's path and |
| 388 // extracts the position of the search terms inside |path|. |
| 389 // This is a helper function for extracting search terms from URL. |
| 390 bool MatchPathWithSearchTerms(const std::string& path, |
| 391 url::Component* search_terms_position) const; |
| 392 |
| 372 // TemplateURLRef internally caches values to make replacement quick. This | 393 // TemplateURLRef internally caches values to make replacement quick. This |
| 373 // method invalidates any cached values. | 394 // method invalidates any cached values. |
| 374 void InvalidateCachedValues() const; | 395 void InvalidateCachedValues() const; |
| 375 | 396 |
| 376 // Parses the parameter in url at the specified offset. start/end specify the | 397 // 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 | 398 // 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 | 399 // 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 | 400 // 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 | 401 // replacements indicating the type and range of the element. The original |
| 381 // parameter is erased from the url. | 402 // parameter is erased from the url. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 | 478 |
| 458 // The replaceable parts of url (parsed_url_). These are ordered by index | 479 // The replaceable parts of url (parsed_url_). These are ordered by index |
| 459 // into the string, and may be empty. | 480 // into the string, and may be empty. |
| 460 mutable Replacements replacements_; | 481 mutable Replacements replacements_; |
| 461 | 482 |
| 462 // Host, port, path, key and location of the search term. These are only set | 483 // Host, port, path, key and location of the search term. These are only set |
| 463 // if the url contains one search term. | 484 // if the url contains one search term. |
| 464 mutable std::string host_; | 485 mutable std::string host_; |
| 465 mutable std::string port_; | 486 mutable std::string port_; |
| 466 mutable std::string path_; | 487 mutable std::string path_; |
| 488 mutable bool ignore_path_ending_; |
| 467 mutable std::string search_term_key_; | 489 mutable std::string search_term_key_; |
| 468 mutable size_t search_term_position_in_path_; | |
| 469 mutable url::Parsed::ComponentType search_term_key_location_; | 490 mutable url::Parsed::ComponentType search_term_key_location_; |
| 470 mutable std::string search_term_value_prefix_; | 491 mutable std::string search_term_value_prefix_; |
| 471 mutable std::string search_term_value_suffix_; | 492 mutable std::string search_term_value_suffix_; |
| 472 | 493 |
| 473 mutable PostParams post_params_; | 494 mutable PostParams post_params_; |
| 474 | 495 |
| 475 // Whether the contained URL is a pre-populated URL. | 496 // Whether the contained URL is a pre-populated URL. |
| 476 bool prepopulated_; | 497 bool prepopulated_; |
| 477 }; | 498 }; |
| 478 | 499 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 TemplateURLRef new_tab_url_ref_; | 769 TemplateURLRef new_tab_url_ref_; |
| 749 TemplateURLRef contextual_search_url_ref_; | 770 TemplateURLRef contextual_search_url_ref_; |
| 750 std::unique_ptr<AssociatedExtensionInfo> extension_info_; | 771 std::unique_ptr<AssociatedExtensionInfo> extension_info_; |
| 751 | 772 |
| 752 // TODO(sky): Add date last parsed OSD file. | 773 // TODO(sky): Add date last parsed OSD file. |
| 753 | 774 |
| 754 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 775 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
| 755 }; | 776 }; |
| 756 | 777 |
| 757 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 778 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
| OLD | NEW |