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

Side by Side Diff: extensions/common/matcher/url_matcher.h

Issue 13699007: Provide a mechanism to the decl. WebRequest API to match URLs without the query against a RegEx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ 5 #ifndef EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_
6 #define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ 6 #define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 QUERY_SUFFIX, 46 QUERY_SUFFIX,
47 QUERY_CONTAINS, 47 QUERY_CONTAINS,
48 QUERY_EQUALS, 48 QUERY_EQUALS,
49 HOST_SUFFIX_PATH_PREFIX, 49 HOST_SUFFIX_PATH_PREFIX,
50 HOST_EQUALS_PATH_PREFIX, 50 HOST_EQUALS_PATH_PREFIX,
51 URL_PREFIX, 51 URL_PREFIX,
52 URL_SUFFIX, 52 URL_SUFFIX,
53 URL_CONTAINS, 53 URL_CONTAINS,
54 URL_EQUALS, 54 URL_EQUALS,
55 URL_MATCHES, 55 URL_MATCHES,
56 ORIGIN_AND_PATH_MATCHES, // Matches the URL minus its query string.
56 }; 57 };
57 58
58 URLMatcherCondition(); 59 URLMatcherCondition();
59 ~URLMatcherCondition(); 60 ~URLMatcherCondition();
60 URLMatcherCondition(Criterion criterion, 61 URLMatcherCondition(Criterion criterion,
61 const StringPattern* substring_pattern); 62 const StringPattern* substring_pattern);
62 URLMatcherCondition(const URLMatcherCondition& rhs); 63 URLMatcherCondition(const URLMatcherCondition& rhs);
63 URLMatcherCondition& operator=(const URLMatcherCondition& rhs); 64 URLMatcherCondition& operator=(const URLMatcherCondition& rhs);
64 bool operator<(const URLMatcherCondition& rhs) const; 65 bool operator<(const URLMatcherCondition& rhs) const;
65 66
66 Criterion criterion() const { return criterion_; } 67 Criterion criterion() const { return criterion_; }
67 const StringPattern* string_pattern() const { 68 const StringPattern* string_pattern() const {
68 return string_pattern_; 69 return string_pattern_;
69 } 70 }
70 71
71 // Returns whether this URLMatcherCondition needs to be executed on a 72 // Returns whether this URLMatcherCondition needs to be executed on a
72 // full URL rather than the individual components (see 73 // full URL rather than the individual components (see
73 // URLMatcherConditionFactory). 74 // URLMatcherConditionFactory).
74 bool IsFullURLCondition() const; 75 bool IsFullURLCondition() const;
75 76
76 // Returns whether this URLMatcherCondition is a regular expression to be 77 // Returns whether this URLMatcherCondition is a regular expression to be
77 // handled by a regex matcher instead of a substring matcher. 78 // handled by a regex matcher instead of a substring matcher.
78 bool IsRegexCondition() const; 79 bool IsRegexCondition() const;
79 80
81 // Returns whether this URLMatcherCondition is a regular expression that shall
82 // be evaluated on the URL without the query parameter.
83 bool IsOriginAndPathRegexCondition() const;
84
80 // Returns whether this condition is fulfilled according to 85 // Returns whether this condition is fulfilled according to
81 // |matching_patterns| and |url|. 86 // |matching_patterns| and |url|.
82 bool IsMatch(const std::set<StringPattern::ID>& matching_patterns, 87 bool IsMatch(const std::set<StringPattern::ID>& matching_patterns,
83 const GURL& url) const; 88 const GURL& url) const;
84 89
85 private: 90 private:
86 // |criterion_| and |string_pattern_| describe together what property a URL 91 // |criterion_| and |string_pattern_| describe together what property a URL
87 // needs to fulfill to be considered a match. 92 // needs to fulfill to be considered a match.
88 Criterion criterion_; 93 Criterion criterion_;
89 94
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const std::string& path_prefix); 153 const std::string& path_prefix);
149 URLMatcherCondition CreateHostEqualsPathPrefixCondition( 154 URLMatcherCondition CreateHostEqualsPathPrefixCondition(
150 const std::string& host, 155 const std::string& host,
151 const std::string& path_prefix); 156 const std::string& path_prefix);
152 157
153 // Canonicalizes a URL for "CreateURL*Condition" searches. 158 // Canonicalizes a URL for "CreateURL*Condition" searches.
154 std::string CanonicalizeURLForFullSearches(const GURL& url) const; 159 std::string CanonicalizeURLForFullSearches(const GURL& url) const;
155 160
156 // Canonicalizes a URL for "CreateURLMatchesCondition" searches. 161 // Canonicalizes a URL for "CreateURLMatchesCondition" searches.
157 std::string CanonicalizeURLForRegexSearches(const GURL& url) const; 162 std::string CanonicalizeURLForRegexSearches(const GURL& url) const;
163 // Canonicalizes a URL for "CreateOriginAndPathMatchesCondition" searches.
164 std::string CanonicalizeURLForOriginAndPathRegexSearches(
165 const GURL& url) const;
158 166
159 URLMatcherCondition CreateURLPrefixCondition(const std::string& prefix); 167 URLMatcherCondition CreateURLPrefixCondition(const std::string& prefix);
160 URLMatcherCondition CreateURLSuffixCondition(const std::string& suffix); 168 URLMatcherCondition CreateURLSuffixCondition(const std::string& suffix);
161 URLMatcherCondition CreateURLContainsCondition(const std::string& str); 169 URLMatcherCondition CreateURLContainsCondition(const std::string& str);
162 URLMatcherCondition CreateURLEqualsCondition(const std::string& str); 170 URLMatcherCondition CreateURLEqualsCondition(const std::string& str);
163 171
164 URLMatcherCondition CreateURLMatchesCondition(const std::string& regex); 172 URLMatcherCondition CreateURLMatchesCondition(const std::string& regex);
173 URLMatcherCondition CreateOriginAndPathMatchesCondition(
174 const std::string& regex);
165 175
166 // Removes all patterns from |pattern_singletons_| that are not listed in 176 // Removes all patterns from |pattern_singletons_| that are not listed in
167 // |used_patterns|. These patterns are not referenced any more and get 177 // |used_patterns|. These patterns are not referenced any more and get
168 // freed. 178 // freed.
169 void ForgetUnusedPatterns( 179 void ForgetUnusedPatterns(
170 const std::set<StringPattern::ID>& used_patterns); 180 const std::set<StringPattern::ID>& used_patterns);
171 181
172 // Returns true if this object retains no allocated data. Only for debugging. 182 // Returns true if this object retains no allocated data. Only for debugging.
173 bool IsEmpty() const; 183 bool IsEmpty() const;
174 184
(...skipping 15 matching lines...) Expand all
190 // StringPatterns. 200 // StringPatterns.
191 struct StringPatternPointerCompare { 201 struct StringPatternPointerCompare {
192 bool operator()(StringPattern* lhs, StringPattern* rhs) const; 202 bool operator()(StringPattern* lhs, StringPattern* rhs) const;
193 }; 203 };
194 // Set to ensure that we generate only one StringPattern for each content 204 // Set to ensure that we generate only one StringPattern for each content
195 // of StringPattern::pattern(). 205 // of StringPattern::pattern().
196 typedef std::set<StringPattern*, StringPatternPointerCompare> 206 typedef std::set<StringPattern*, StringPatternPointerCompare>
197 PatternSingletons; 207 PatternSingletons;
198 PatternSingletons substring_pattern_singletons_; 208 PatternSingletons substring_pattern_singletons_;
199 PatternSingletons regex_pattern_singletons_; 209 PatternSingletons regex_pattern_singletons_;
210 PatternSingletons origin_and_path_regex_pattern_singletons_;
200 211
201 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory); 212 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory);
202 }; 213 };
203 214
204 // This class represents a filter for the URL scheme to be hooked up into a 215 // This class represents a filter for the URL scheme to be hooked up into a
205 // URLMatcherConditionSet. 216 // URLMatcherConditionSet.
206 class URLMatcherSchemeFilter { 217 class URLMatcherSchemeFilter {
207 public: 218 public:
208 explicit URLMatcherSchemeFilter(const std::string& filter); 219 explicit URLMatcherSchemeFilter(const std::string& filter);
209 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters); 220 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 336
326 // Maps a StringPattern ID to the URLMatcherConditions that need to 337 // Maps a StringPattern ID to the URLMatcherConditions that need to
327 // be triggered in case of a StringPattern match. 338 // be triggered in case of a StringPattern match.
328 typedef std::map<StringPattern::ID, std::set<URLMatcherConditionSet::ID> > 339 typedef std::map<StringPattern::ID, std::set<URLMatcherConditionSet::ID> >
329 StringPatternTriggers; 340 StringPatternTriggers;
330 StringPatternTriggers substring_match_triggers_; 341 StringPatternTriggers substring_match_triggers_;
331 342
332 SubstringSetMatcher full_url_matcher_; 343 SubstringSetMatcher full_url_matcher_;
333 SubstringSetMatcher url_component_matcher_; 344 SubstringSetMatcher url_component_matcher_;
334 RegexSetMatcher regex_set_matcher_; 345 RegexSetMatcher regex_set_matcher_;
346 RegexSetMatcher origin_and_path_regex_set_matcher_;
335 std::set<const StringPattern*> registered_full_url_patterns_; 347 std::set<const StringPattern*> registered_full_url_patterns_;
336 std::set<const StringPattern*> registered_url_component_patterns_; 348 std::set<const StringPattern*> registered_url_component_patterns_;
337 349
338 DISALLOW_COPY_AND_ASSIGN(URLMatcher); 350 DISALLOW_COPY_AND_ASSIGN(URLMatcher);
339 }; 351 };
340 352
341 } // namespace extensions 353 } // namespace extensions
342 354
343 #endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ 355 #endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_
OLDNEW
« no previous file with comments | « extensions/common/matcher/regex_set_matcher.cc ('k') | extensions/common/matcher/url_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698