OLD | NEW |
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 Loading... |
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 STRIPPED_URL_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 IsStrippedUrlRegexCondition() 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 Loading... |
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 "CreateStrippedURLMatchesCondition" searches. |
| 164 std::string CanonicalizeURLForStrippedUrlRegexSearches(const GURL& url) const; |
158 | 165 |
159 URLMatcherCondition CreateURLPrefixCondition(const std::string& prefix); | 166 URLMatcherCondition CreateURLPrefixCondition(const std::string& prefix); |
160 URLMatcherCondition CreateURLSuffixCondition(const std::string& suffix); | 167 URLMatcherCondition CreateURLSuffixCondition(const std::string& suffix); |
161 URLMatcherCondition CreateURLContainsCondition(const std::string& str); | 168 URLMatcherCondition CreateURLContainsCondition(const std::string& str); |
162 URLMatcherCondition CreateURLEqualsCondition(const std::string& str); | 169 URLMatcherCondition CreateURLEqualsCondition(const std::string& str); |
163 | 170 |
164 URLMatcherCondition CreateURLMatchesCondition(const std::string& regex); | 171 URLMatcherCondition CreateURLMatchesCondition(const std::string& regex); |
| 172 URLMatcherCondition CreateStrippedURLMatchesCondition( |
| 173 const std::string& regex); |
165 | 174 |
166 // Removes all patterns from |pattern_singletons_| that are not listed in | 175 // Removes all patterns from |pattern_singletons_| that are not listed in |
167 // |used_patterns|. These patterns are not referenced any more and get | 176 // |used_patterns|. These patterns are not referenced any more and get |
168 // freed. | 177 // freed. |
169 void ForgetUnusedPatterns( | 178 void ForgetUnusedPatterns( |
170 const std::set<StringPattern::ID>& used_patterns); | 179 const std::set<StringPattern::ID>& used_patterns); |
171 | 180 |
172 // Returns true if this object retains no allocated data. Only for debugging. | 181 // Returns true if this object retains no allocated data. Only for debugging. |
173 bool IsEmpty() const; | 182 bool IsEmpty() const; |
174 | 183 |
(...skipping 15 matching lines...) Expand all Loading... |
190 // StringPatterns. | 199 // StringPatterns. |
191 struct StringPatternPointerCompare { | 200 struct StringPatternPointerCompare { |
192 bool operator()(StringPattern* lhs, StringPattern* rhs) const; | 201 bool operator()(StringPattern* lhs, StringPattern* rhs) const; |
193 }; | 202 }; |
194 // Set to ensure that we generate only one StringPattern for each content | 203 // Set to ensure that we generate only one StringPattern for each content |
195 // of StringPattern::pattern(). | 204 // of StringPattern::pattern(). |
196 typedef std::set<StringPattern*, StringPatternPointerCompare> | 205 typedef std::set<StringPattern*, StringPatternPointerCompare> |
197 PatternSingletons; | 206 PatternSingletons; |
198 PatternSingletons substring_pattern_singletons_; | 207 PatternSingletons substring_pattern_singletons_; |
199 PatternSingletons regex_pattern_singletons_; | 208 PatternSingletons regex_pattern_singletons_; |
| 209 PatternSingletons stripped_url_regex_pattern_singletons_; |
200 | 210 |
201 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory); | 211 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionFactory); |
202 }; | 212 }; |
203 | 213 |
204 // This class represents a filter for the URL scheme to be hooked up into a | 214 // This class represents a filter for the URL scheme to be hooked up into a |
205 // URLMatcherConditionSet. | 215 // URLMatcherConditionSet. |
206 class URLMatcherSchemeFilter { | 216 class URLMatcherSchemeFilter { |
207 public: | 217 public: |
208 explicit URLMatcherSchemeFilter(const std::string& filter); | 218 explicit URLMatcherSchemeFilter(const std::string& filter); |
209 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters); | 219 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 335 |
326 // Maps a StringPattern ID to the URLMatcherConditions that need to | 336 // Maps a StringPattern ID to the URLMatcherConditions that need to |
327 // be triggered in case of a StringPattern match. | 337 // be triggered in case of a StringPattern match. |
328 typedef std::map<StringPattern::ID, std::set<URLMatcherConditionSet::ID> > | 338 typedef std::map<StringPattern::ID, std::set<URLMatcherConditionSet::ID> > |
329 StringPatternTriggers; | 339 StringPatternTriggers; |
330 StringPatternTriggers substring_match_triggers_; | 340 StringPatternTriggers substring_match_triggers_; |
331 | 341 |
332 SubstringSetMatcher full_url_matcher_; | 342 SubstringSetMatcher full_url_matcher_; |
333 SubstringSetMatcher url_component_matcher_; | 343 SubstringSetMatcher url_component_matcher_; |
334 RegexSetMatcher regex_set_matcher_; | 344 RegexSetMatcher regex_set_matcher_; |
| 345 RegexSetMatcher stripped_url_regex_set_matcher_; |
335 std::set<const StringPattern*> registered_full_url_patterns_; | 346 std::set<const StringPattern*> registered_full_url_patterns_; |
336 std::set<const StringPattern*> registered_url_component_patterns_; | 347 std::set<const StringPattern*> registered_url_component_patterns_; |
337 | 348 |
338 DISALLOW_COPY_AND_ASSIGN(URLMatcher); | 349 DISALLOW_COPY_AND_ASSIGN(URLMatcher); |
339 }; | 350 }; |
340 | 351 |
341 } // namespace extensions | 352 } // namespace extensions |
342 | 353 |
343 #endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ | 354 #endif // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_H_ |
OLD | NEW |