Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: components/url_matcher/url_matcher.h

Issue 219613002: Add support for matching query parameters in URLMatcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds the complete query element match framework to URL matcher Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_URL_MATCHER_URL_MATCHER_H_ 5 #ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_H_
6 #define COMPONENTS_URL_MATCHER_URL_MATCHER_H_ 6 #define COMPONENTS_URL_MATCHER_URL_MATCHER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 private: 186 private:
187 // Creates a URLMatcherCondition according to the parameters passed. 187 // Creates a URLMatcherCondition according to the parameters passed.
188 // The URLMatcherCondition will refer to a StringPattern that is 188 // The URLMatcherCondition will refer to a StringPattern that is
189 // owned by |pattern_singletons_|. 189 // owned by |pattern_singletons_|.
190 URLMatcherCondition CreateCondition(URLMatcherCondition::Criterion criterion, 190 URLMatcherCondition CreateCondition(URLMatcherCondition::Criterion criterion,
191 const std::string& pattern); 191 const std::string& pattern);
192 192
193 // Prepends a "." to the hostname if it does not start with one. 193 // Prepends a "." to the hostname if it does not start with one.
194 std::string CanonicalizeHostname(const std::string& hostname) const; 194 std::string CanonicalizeHostname(const std::string& hostname) const;
195 195
196 // Convert the query string to canonical form suitable for key token search.
197 std::string CanonicalizeQuery(std::string query,
198 bool prepend_beginning_of_query_component,
199 bool append_end_of_query_component) const;
200
196 // Counter that ensures that all created StringPatterns have unique IDs. 201 // Counter that ensures that all created StringPatterns have unique IDs.
197 // Note that substring patterns and regex patterns will use different IDs. 202 // Note that substring patterns and regex patterns will use different IDs.
198 int id_counter_; 203 int id_counter_;
199 204
200 // This comparison considers only the pattern() value of the 205 // This comparison considers only the pattern() value of the
201 // StringPatterns. 206 // StringPatterns.
202 struct StringPatternPointerCompare { 207 struct StringPatternPointerCompare {
203 bool operator()(StringPattern* lhs, StringPattern* rhs) const; 208 bool operator()(StringPattern* lhs, StringPattern* rhs) const;
204 }; 209 };
205 // Set to ensure that we generate only one StringPattern for each content 210 // Set to ensure that we generate only one StringPattern for each content
206 // of StringPattern::pattern(). 211 // of StringPattern::pattern().
207 typedef std::set<StringPattern*, StringPatternPointerCompare> 212 typedef std::set<StringPattern*, StringPatternPointerCompare>
208 PatternSingletons; 213 PatternSingletons;
209 PatternSingletons substring_pattern_singletons_; 214 PatternSingletons substring_pattern_singletons_;
210 PatternSingletons regex_pattern_singletons_; 215 PatternSingletons regex_pattern_singletons_;
211 PatternSingletons origin_and_path_regex_pattern_singletons_; 216 PatternSingletons origin_and_path_regex_pattern_singletons_;
212 217
213 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory); 218 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory);
214 }; 219 };
215 220
221 // This class represents a single URL query matching condition. The query
222 // matching is done as a search for a key and optionally a value.
223 // The matching makes use of CanonicalizeURLForComponentSearches to ensure that
224 // the key starts and ends (optionally) with the right marker.
225 class URL_MATCHER_EXPORT URLQueryElementMatcherCondition {
226 public:
227 enum Type { MATCH_ANY, MATCH_FIRST, MATCH_LAST, MATCH_ALL };
228 enum QueryValueMatchType {
229 QUERY_VALUE_MATCH_EXACT,
230 QUERY_VALUE_MATCH_PREFIX
231 };
232 enum QueryElementType { ELEMENT_TYPE_KEY_VALUE, ELEMENT_TYPE_KEY };
233
234 URLQueryElementMatcherCondition(const std::string& key,
235 const std::string& value,
236 QueryValueMatchType query_value_match_type,
237 QueryElementType query_element_type,
238 Type match_type,
239 URLMatcherConditionFactory* factory);
240 ~URLQueryElementMatcherCondition();
241
242 bool operator<(const URLQueryElementMatcherCondition& rhs) const;
243
244 // Verifies if the URL query contains the key value pair.
245 bool IsMatch(const std::string& canonical_url_query) const;
246
247 const StringPattern* string_pattern() const { return string_pattern_; }
248
249 private:
250 Type match_type_;
251 std::string key_;
252 std::string value_;
253 size_t key_length_;
254 size_t value_length_;
255 const StringPattern* string_pattern_;
256 };
257
216 // This class represents a filter for the URL scheme to be hooked up into a 258 // This class represents a filter for the URL scheme to be hooked up into a
217 // URLMatcherConditionSet. 259 // URLMatcherConditionSet.
218 class URL_MATCHER_EXPORT URLMatcherSchemeFilter { 260 class URL_MATCHER_EXPORT URLMatcherSchemeFilter {
219 public: 261 public:
220 explicit URLMatcherSchemeFilter(const std::string& filter); 262 explicit URLMatcherSchemeFilter(const std::string& filter);
221 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters); 263 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters);
222 ~URLMatcherSchemeFilter(); 264 ~URLMatcherSchemeFilter();
223 bool IsMatch(const GURL& url) const; 265 bool IsMatch(const GURL& url) const;
224 266
225 private: 267 private:
(...skipping 23 matching lines...) Expand all
249 DISALLOW_COPY_AND_ASSIGN(URLMatcherPortFilter); 291 DISALLOW_COPY_AND_ASSIGN(URLMatcherPortFilter);
250 }; 292 };
251 293
252 // This class represents a set of conditions that all need to match on a 294 // This class represents a set of conditions that all need to match on a
253 // given URL in order to be considered a match. 295 // given URL in order to be considered a match.
254 class URL_MATCHER_EXPORT URLMatcherConditionSet 296 class URL_MATCHER_EXPORT URLMatcherConditionSet
255 : public base::RefCounted<URLMatcherConditionSet> { 297 : public base::RefCounted<URLMatcherConditionSet> {
256 public: 298 public:
257 typedef int ID; 299 typedef int ID;
258 typedef std::set<URLMatcherCondition> Conditions; 300 typedef std::set<URLMatcherCondition> Conditions;
301 typedef std::set<URLQueryElementMatcherCondition> QueryConditions;
259 typedef std::vector<scoped_refptr<URLMatcherConditionSet> > Vector; 302 typedef std::vector<scoped_refptr<URLMatcherConditionSet> > Vector;
260 303
261 // Matches if all conditions in |conditions| are fulfilled. 304 // Matches if all conditions in |conditions| are fulfilled.
262 URLMatcherConditionSet(ID id, const Conditions& conditions); 305 URLMatcherConditionSet(ID id, const Conditions& conditions);
263 306
264 // Matches if all conditions in |conditions|, |scheme_filter| and 307 // Matches if all conditions in |conditions|, |scheme_filter| and
265 // |port_filter| are fulfilled. |scheme_filter| and |port_filter| may be NULL, 308 // |port_filter| are fulfilled. |scheme_filter| and |port_filter| may be NULL,
266 // in which case, no restrictions are imposed on the scheme/port of a URL. 309 // in which case, no restrictions are imposed on the scheme/port of a URL.
267 URLMatcherConditionSet(ID id, const Conditions& conditions, 310 URLMatcherConditionSet(ID id, const Conditions& conditions,
268 scoped_ptr<URLMatcherSchemeFilter> scheme_filter, 311 scoped_ptr<URLMatcherSchemeFilter> scheme_filter,
269 scoped_ptr<URLMatcherPortFilter> port_filter); 312 scoped_ptr<URLMatcherPortFilter> port_filter);
270 313
314 // Matches if all conditions in |conditions|, |query_conditions|,
315 // |scheme_filter| and |port_filter| are fulfilled. |scheme_filter| and
316 // |port_filter| may be NULL, in which case, no restrictions are imposed on
317 // the scheme/port of a URL.
318 URLMatcherConditionSet(ID id,
319 const Conditions& conditions,
320 const QueryConditions& query_conditions,
321 scoped_ptr<URLMatcherSchemeFilter> scheme_filter,
322 scoped_ptr<URLMatcherPortFilter> port_filter);
323
271 ID id() const { return id_; } 324 ID id() const { return id_; }
272 const Conditions& conditions() const { return conditions_; } 325 const Conditions& conditions() const { return conditions_; }
326 const QueryConditions& query_conditions() const { return query_conditions_; }
273 327
274 bool IsMatch(const std::set<StringPattern::ID>& matching_patterns, 328 bool IsMatch(const std::set<StringPattern::ID>& matching_patterns,
275 const GURL& url) const; 329 const GURL& url) const;
276 330
331 bool IsMatch(const std::set<StringPattern::ID>& matching_patterns,
332 const GURL& url,
333 const std::string url_for_component_searches) const;
Joao da Silva 2014/04/07 15:12:39 const std::string&
kaliamoorthi 2014/04/08 09:28:53 Done.
334
277 private: 335 private:
278 friend class base::RefCounted<URLMatcherConditionSet>; 336 friend class base::RefCounted<URLMatcherConditionSet>;
279 ~URLMatcherConditionSet(); 337 ~URLMatcherConditionSet();
280 ID id_; 338 ID id_;
281 Conditions conditions_; 339 Conditions conditions_;
340 QueryConditions query_conditions_;
282 scoped_ptr<URLMatcherSchemeFilter> scheme_filter_; 341 scoped_ptr<URLMatcherSchemeFilter> scheme_filter_;
283 scoped_ptr<URLMatcherPortFilter> port_filter_; 342 scoped_ptr<URLMatcherPortFilter> port_filter_;
284 343
285 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionSet); 344 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionSet);
286 }; 345 };
287 346
288 // This class allows matching one URL against a large set of 347 // This class allows matching one URL against a large set of
289 // URLMatcherConditionSets at the same time. 348 // URLMatcherConditionSets at the same time.
290 class URL_MATCHER_EXPORT URLMatcher { 349 class URL_MATCHER_EXPORT URLMatcher {
291 public: 350 public:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 RegexSetMatcher origin_and_path_regex_set_matcher_; 407 RegexSetMatcher origin_and_path_regex_set_matcher_;
349 std::set<const StringPattern*> registered_full_url_patterns_; 408 std::set<const StringPattern*> registered_full_url_patterns_;
350 std::set<const StringPattern*> registered_url_component_patterns_; 409 std::set<const StringPattern*> registered_url_component_patterns_;
351 410
352 DISALLOW_COPY_AND_ASSIGN(URLMatcher); 411 DISALLOW_COPY_AND_ASSIGN(URLMatcher);
353 }; 412 };
354 413
355 } // namespace url_matcher 414 } // namespace url_matcher
356 415
357 #endif // COMPONENTS_URL_MATCHER_URL_MATCHER_H_ 416 #endif // COMPONENTS_URL_MATCHER_URL_MATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | components/url_matcher/url_matcher.cc » ('j') | components/url_matcher/url_matcher_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698