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..ce6ac0c5b1d9e61b0f0927dbebdf19ed994e4bf3 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_| |
dhollowa
2012/09/28 18:06:29
nit: |index_in_owner_|
beaudoin
2012/10/02 17:43:29
Good catch! :)
Done.
|
+ // 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 |
dhollowa
2012/09/28 18:06:29
nit: |index_in_owner_|
beaudoin
2012/10/02 17:43:29
Done.
|
+ // 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_; |
@@ -325,7 +344,13 @@ struct TemplateURLData { |
// regardless of whether they have been associated with Sync. |
std::string sync_guid; |
+ // A list of URL patterns that can be used, in addition to |url_|, to extract |
+ // search terms from a URL. |
+ std::vector<std::string> alternate_urls; |
+ |
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_; |
@@ -369,6 +394,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 +450,23 @@ class TemplateURL { |
std::string GetExtensionId() const; |
bool IsExtensionKeyword() const; |
+ // 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; |