| Index: chrome/browser/search_engines/template_url.h
|
| diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h
|
| index 025b88e31eb43dce7097799a84ab878fe5c1ad99..e339329e2dd126e26536c6ea6795b44779b53d86 100644
|
| --- a/chrome/browser/search_engines/template_url.h
|
| +++ b/chrome/browser/search_engines/template_url.h
|
| @@ -12,6 +12,7 @@
|
| #include "base/time.h"
|
| #include "chrome/browser/common/url_database/template_url_id.h"
|
| #include "googleurl/src/gurl.h"
|
| +#include "googleurl/src/url_parse.h"
|
|
|
| class Profile;
|
| class SearchTermsData;
|
| @@ -40,11 +41,13 @@ class TemplateURLRef {
|
| };
|
|
|
| // Which kind of URL within our owner we are. This allows us to get at the
|
| - // correct string field.
|
| + // correct string field. Use |INDEXED| to indicate that the numerical |index_|
|
| + // should be used instead.
|
| enum Type {
|
| SEARCH,
|
| SUGGEST,
|
| INSTANT,
|
| + INDEXED
|
| };
|
|
|
| // This struct encapsulates arguments passed to
|
| @@ -70,6 +73,7 @@ class TemplateURLRef {
|
| };
|
|
|
| TemplateURLRef(TemplateURL* owner, Type type);
|
| + TemplateURLRef(TemplateURL* owner, size_t index_in_owner);
|
| ~TemplateURLRef();
|
|
|
| // Returns the raw URL. None of the parameters will have been replaced.
|
| @@ -128,6 +132,12 @@ class TemplateURLRef {
|
| // {google:baseURL} or {google:baseSuggestURL}.
|
| bool HasGoogleBaseURLs() const;
|
|
|
| + // Use the alternate URLs and the search URL to match the provided |url|
|
| + // and extract |search_terms| from it. Returns false and an empty
|
| + // |search_terms| if no search terms can be matched.
|
| + bool ExtractSearchTermsFromURL(const GURL& url,
|
| + string16* search_terms) const;
|
| +
|
| private:
|
| friend class TemplateURL;
|
| FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse);
|
| @@ -206,12 +216,20 @@ class TemplateURLRef {
|
| void ParseHostAndSearchTermKey(
|
| const SearchTermsData& search_terms_data) const;
|
|
|
| + // Extract query key and host given a list of parameters coming from the URL
|
| + // query or ref.
|
| + void FindSearchTermsKey(const std::string& params) const;
|
| +
|
| // The TemplateURL that contains us. This should outlive us.
|
| TemplateURL* const owner_;
|
|
|
| // What kind of URL we are.
|
| const Type type_;
|
|
|
| + // If |type_| is |INDEXED|, this |index_| is used instead to refer to a URL
|
| + // within our owner.
|
| + const size_t index_in_owner_;
|
| +
|
| // Whether the URL has been parsed.
|
| mutable bool parsed_;
|
|
|
| @@ -229,11 +247,12 @@ class TemplateURLRef {
|
| // into the string, and may be empty.
|
| mutable Replacements replacements_;
|
|
|
| - // Host, path and key of the search term. These are only set if the url
|
| - // contains one search term.
|
| + // Host, path, key and location of the search term. These are only set if the
|
| + // url contains one search term.
|
| mutable std::string host_;
|
| mutable std::string path_;
|
| mutable std::string search_term_key_;
|
| + mutable url_parse::Parsed::ComponentType search_term_key_location_;
|
|
|
| // Whether the contained URL is a pre-populated URL.
|
| bool prepopulated_;
|
| @@ -265,6 +284,18 @@ struct TemplateURLData {
|
| void SetURL(const std::string& url);
|
| const std::string& url() const { return url_; }
|
|
|
| + // Alternate URL patterns that can be used to match search terms.
|
| + // The URLs must not contain commas.
|
| + const std::vector<std::string>& alternate_urls() const {
|
| + return alternate_urls_;
|
| + }
|
| +
|
| + // Returns a serialized version of |alternate_urls| as a comma separated list.
|
| + std::string SerializeAlternateURLs() const;
|
| +
|
| + // Deserialize a comma separated list of URLs into |alternate_urls|.
|
| + void DeserializeAndSetAlternateURLs(const std::string& alternate_urls);
|
| +
|
| // Optional additional raw URLs.
|
| std::string suggestions_url;
|
| std::string instant_url;
|
| @@ -326,10 +357,17 @@ struct TemplateURLData {
|
| std::string sync_guid;
|
|
|
| private:
|
| + FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SerializeAlternateURLs);
|
| +
|
| // Private so we can enforce using the setters and thus enforce that these
|
| // fields are never empty.
|
| string16 keyword_;
|
| std::string url_;
|
| +
|
| + // A list of URL patterns that can be used, in addition to |url_|, to extract
|
| + // search terms from a URL. Enforce use of a setter since |alternate_urls|
|
| + // cannot contain commas as they are serialized as a comma-separated list.
|
| + std::vector<std::string> alternate_urls_;
|
| };
|
|
|
|
|
| @@ -369,6 +407,9 @@ class TemplateURL {
|
| const std::string& url() const { return data_.url(); }
|
| const std::string& suggestions_url() const { return data_.suggestions_url; }
|
| const std::string& instant_url() const { return data_.instant_url; }
|
| + const std::vector<std::string>& alternate_urls() const {
|
| + return data_.alternate_urls();
|
| + }
|
| const GURL& favicon_url() const { return data_.favicon_url; }
|
|
|
| const GURL& originating_url() const { return data_.originating_url; }
|
| @@ -422,6 +463,28 @@ class TemplateURL {
|
| std::string GetExtensionId() const;
|
| bool IsExtensionKeyword() const;
|
|
|
| + // Returns a serialized version of |alternate_urls| as a comma separated list.
|
| + std::string SerializeAlternateURLs() const {
|
| + return data_.SerializeAlternateURLs();
|
| + }
|
| +
|
| + // Returns the total number of URLs comprised in this template, including
|
| + // search and alternate URLs.
|
| + size_t URLCount() const;
|
| +
|
| + // Obtain the URL given an |index|. Alternate URLS start at index 0, followed
|
| + // by the regular search URL. This allows us to prioritize some pattern, so if
|
| + // a search term is present both in the query and the ref, we can prioritize
|
| + // the ref one. The |index| must be less than URLCount().
|
| + const std::string& GetURL(size_t index) const;
|
| +
|
| + // Use the alternate URLs and the search URL to match the provided |url|
|
| + // and extract |search_terms| from it. Returns false and an empty
|
| + // |search_terms| if no search terms can be matched or if this is not an
|
| + // instant extended URL.
|
| + bool ExtractSearchTermsFromInstantExtendedURL(const GURL& url,
|
| + string16* search_terms);
|
| +
|
| private:
|
| friend class TemplateURLService;
|
|
|
|
|