| 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 4241f529d46fc025ec40df4b17eca3fd4d4a5bc7..3c8cd60e3155d1efbe5ce75c5cf2b5345b591c1d 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/search_engines/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,10 @@ class TemplateURLRef {
|
| // {google:baseURL} or {google:baseSuggestURL}.
|
| bool HasGoogleBaseURLs() const;
|
|
|
| + // Extract keywords from the provided |url| using the template URL referred
|
| + // to. In case of failure, an empty string is returned.
|
| + string16 ExtractSearchTermsFromURL(const GURL& url) const;
|
| +
|
| private:
|
| friend class TemplateURL;
|
| FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse);
|
| @@ -206,12 +214,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 +245,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 +282,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 +355,18 @@ 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_| and
|
| + // |instant_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_;
|
| };
|
|
|
|
|
| @@ -422,6 +459,21 @@ class TemplateURL {
|
| std::string GetExtensionId() const;
|
| bool IsExtensionKeyword() const;
|
|
|
| + // Returns the total number of URL comprised in this template, including
|
| + // search, instant and alternate URLs.
|
| + size_t URLCount() const;
|
| +
|
| + // Obtain the URL given an |index|. Alternate URLS start at index 0, followed
|
| + // by instant and then 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 various URL comprised in this template to match the provided |url|
|
| + // and extract keywords from it. If successful the search terms are rerturned.
|
| + // In case of failure, an empty string is returned.
|
| + string16 ExtractSearchTermsFromURL(const GURL& url);
|
| +
|
| private:
|
| friend class TemplateURLService;
|
|
|
|
|