Chromium Code Reviews| Index: components/url_matcher/url_matcher.h |
| diff --git a/components/url_matcher/url_matcher.h b/components/url_matcher/url_matcher.h |
| index 53c393a9d736ec69188071b023f47320d167a56f..28db9c16b1f597c1a08a44c2625c0c208a39edcf 100644 |
| --- a/components/url_matcher/url_matcher.h |
| +++ b/components/url_matcher/url_matcher.h |
| @@ -193,6 +193,11 @@ class URL_MATCHER_EXPORT URLMatcherConditionFactory { |
| // Prepends a "." to the hostname if it does not start with one. |
| std::string CanonicalizeHostname(const std::string& hostname) const; |
| + // Convert the query string to canonical form suitable for key token search. |
| + std::string CanonicalizeQuery(std::string query, |
| + bool prepend_beginning_of_query_component, |
| + bool append_end_of_query_component) const; |
| + |
| // Counter that ensures that all created StringPatterns have unique IDs. |
| // Note that substring patterns and regex patterns will use different IDs. |
| int id_counter_; |
| @@ -213,6 +218,43 @@ class URL_MATCHER_EXPORT URLMatcherConditionFactory { |
| DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory); |
| }; |
| +// This class represents a single URL query matching condition. The query |
| +// matching is done as a search for a key and optionally a value. |
| +// The matching makes use of CanonicalizeURLForComponentSearches to ensure that |
| +// the key starts and ends (optionally) with the right marker. |
| +class URL_MATCHER_EXPORT URLQueryElementMatcherCondition { |
| + public: |
| + enum Type { MATCH_ANY, MATCH_FIRST, MATCH_LAST, MATCH_ALL }; |
|
battre
2014/04/08 10:51:21
Please add a comment that multiple query parameter
kaliamoorthi
2014/04/08 12:14:24
Done.
|
| + enum QueryValueMatchType { |
| + QUERY_VALUE_MATCH_EXACT, |
| + QUERY_VALUE_MATCH_PREFIX |
| + }; |
| + enum QueryElementType { ELEMENT_TYPE_KEY_VALUE, ELEMENT_TYPE_KEY }; |
| + |
| + URLQueryElementMatcherCondition(const std::string& key, |
| + const std::string& value, |
| + QueryValueMatchType query_value_match_type, |
| + QueryElementType query_element_type, |
| + Type match_type, |
| + URLMatcherConditionFactory* factory); |
| + ~URLQueryElementMatcherCondition(); |
| + |
| + bool operator<(const URLQueryElementMatcherCondition& rhs) const; |
| + |
| + // Verifies if the URL query contains the key value pair. |
|
battre
2014/04/08 10:51:21
// Returns whether the URL...
kaliamoorthi
2014/04/08 12:14:24
Done.
|
| + bool IsMatch(const std::string& canonical_url_query) const; |
| + |
| + const StringPattern* string_pattern() const { return string_pattern_; } |
| + |
| + private: |
| + Type match_type_; |
| + std::string key_; |
| + std::string value_; |
| + size_t key_length_; |
| + size_t value_length_; |
| + const StringPattern* string_pattern_; |
| +}; |
| + |
| // This class represents a filter for the URL scheme to be hooked up into a |
| // URLMatcherConditionSet. |
| class URL_MATCHER_EXPORT URLMatcherSchemeFilter { |
| @@ -256,6 +298,7 @@ class URL_MATCHER_EXPORT URLMatcherConditionSet |
| public: |
| typedef int ID; |
| typedef std::set<URLMatcherCondition> Conditions; |
| + typedef std::set<URLQueryElementMatcherCondition> QueryConditions; |
| typedef std::vector<scoped_refptr<URLMatcherConditionSet> > Vector; |
| // Matches if all conditions in |conditions| are fulfilled. |
| @@ -268,17 +311,33 @@ class URL_MATCHER_EXPORT URLMatcherConditionSet |
| scoped_ptr<URLMatcherSchemeFilter> scheme_filter, |
| scoped_ptr<URLMatcherPortFilter> port_filter); |
| + // Matches if all conditions in |conditions|, |query_conditions|, |
| + // |scheme_filter| and |port_filter| are fulfilled. |scheme_filter| and |
| + // |port_filter| may be NULL, in which case, no restrictions are imposed on |
| + // the scheme/port of a URL. |
| + URLMatcherConditionSet(ID id, |
| + const Conditions& conditions, |
| + const QueryConditions& query_conditions, |
| + scoped_ptr<URLMatcherSchemeFilter> scheme_filter, |
| + scoped_ptr<URLMatcherPortFilter> port_filter); |
| + |
| ID id() const { return id_; } |
| const Conditions& conditions() const { return conditions_; } |
| + const QueryConditions& query_conditions() const { return query_conditions_; } |
| bool IsMatch(const std::set<StringPattern::ID>& matching_patterns, |
| const GURL& url) const; |
| + bool IsMatch(const std::set<StringPattern::ID>& matching_patterns, |
| + const GURL& url, |
| + const std::string& url_for_component_searches) const; |
| + |
| private: |
| friend class base::RefCounted<URLMatcherConditionSet>; |
| ~URLMatcherConditionSet(); |
| ID id_; |
| Conditions conditions_; |
| + QueryConditions query_conditions_; |
| scoped_ptr<URLMatcherSchemeFilter> scheme_filter_; |
| scoped_ptr<URLMatcherPortFilter> port_filter_; |