| 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 CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_URL_MATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_URL_MATCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_URL_MATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_URL_MATCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters); | 187 explicit URLMatcherSchemeFilter(const std::vector<std::string>& filters); |
| 188 ~URLMatcherSchemeFilter(); | 188 ~URLMatcherSchemeFilter(); |
| 189 bool IsMatch(const GURL& url) const; | 189 bool IsMatch(const GURL& url) const; |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 std::vector<std::string> filters_; | 192 std::vector<std::string> filters_; |
| 193 | 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(URLMatcherSchemeFilter); | 194 DISALLOW_COPY_AND_ASSIGN(URLMatcherSchemeFilter); |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 // This class represents a filter for port numbers to be hooked up into a |
| 198 // URLMatcherConditionSet. |
| 199 class URLMatcherPortFilter { |
| 200 public: |
| 201 // Boundaries of a port range (both ends are included). |
| 202 typedef std::pair<int, int> Range; |
| 203 explicit URLMatcherPortFilter(const std::vector<Range>& ranges); |
| 204 ~URLMatcherPortFilter(); |
| 205 bool IsMatch(const GURL& url) const; |
| 206 |
| 207 // Creates a port range [from, to]; both ends are included. |
| 208 static Range CreateRange(int from, int to); |
| 209 // Creates a port range containing a single port. |
| 210 static Range CreateRange(int port); |
| 211 |
| 212 private: |
| 213 std::vector<Range> ranges_; |
| 214 |
| 215 DISALLOW_COPY_AND_ASSIGN(URLMatcherPortFilter); |
| 216 }; |
| 217 |
| 197 // This class represents a set of conditions that all need to match on a | 218 // This class represents a set of conditions that all need to match on a |
| 198 // given URL in order to be considered a match. | 219 // given URL in order to be considered a match. |
| 199 class URLMatcherConditionSet : public base::RefCounted<URLMatcherConditionSet> { | 220 class URLMatcherConditionSet : public base::RefCounted<URLMatcherConditionSet> { |
| 200 public: | 221 public: |
| 201 typedef int ID; | 222 typedef int ID; |
| 202 typedef std::set<URLMatcherCondition> Conditions; | 223 typedef std::set<URLMatcherCondition> Conditions; |
| 203 typedef std::vector<scoped_refptr<URLMatcherConditionSet> > Vector; | 224 typedef std::vector<scoped_refptr<URLMatcherConditionSet> > Vector; |
| 204 | 225 |
| 205 // Matches if all conditions in |conditions| are fulfilled. | 226 // Matches if all conditions in |conditions| are fulfilled. |
| 206 URLMatcherConditionSet(ID id, const Conditions& conditions); | 227 URLMatcherConditionSet(ID id, const Conditions& conditions); |
| 207 | 228 |
| 208 // Matches if all conditions in |conditions| and |scheme_filter| are | 229 // Matches if all conditions in |conditions|, |scheme_filter| and |
| 209 // fulfilled. |scheme_filter| may be NULL, in which case, no restrictions | 230 // |port_filter| are fulfilled. |scheme_filter| and |port_filter| may be NULL, |
| 210 // are imposed on the scheme of a URL. | 231 // in which case, no restrictions are imposed on the scheme/port of a URL. |
| 211 URLMatcherConditionSet(ID id, const Conditions& conditions, | 232 URLMatcherConditionSet(ID id, const Conditions& conditions, |
| 212 scoped_ptr<URLMatcherSchemeFilter> scheme_filter); | 233 scoped_ptr<URLMatcherSchemeFilter> scheme_filter, |
| 234 scoped_ptr<URLMatcherPortFilter> port_filter); |
| 213 | 235 |
| 214 ID id() const { return id_; } | 236 ID id() const { return id_; } |
| 215 const Conditions& conditions() const { return conditions_; } | 237 const Conditions& conditions() const { return conditions_; } |
| 216 | 238 |
| 217 bool IsMatch( | 239 bool IsMatch( |
| 218 const std::set<SubstringPattern::ID>& matching_substring_patterns, | 240 const std::set<SubstringPattern::ID>& matching_substring_patterns, |
| 219 const GURL& url) const; | 241 const GURL& url) const; |
| 220 | 242 |
| 221 private: | 243 private: |
| 222 friend class base::RefCounted<URLMatcherConditionSet>; | 244 friend class base::RefCounted<URLMatcherConditionSet>; |
| 223 ~URLMatcherConditionSet(); | 245 ~URLMatcherConditionSet(); |
| 224 ID id_; | 246 ID id_; |
| 225 Conditions conditions_; | 247 Conditions conditions_; |
| 226 scoped_ptr<URLMatcherSchemeFilter> scheme_filter_; | 248 scoped_ptr<URLMatcherSchemeFilter> scheme_filter_; |
| 249 scoped_ptr<URLMatcherPortFilter> port_filter_; |
| 227 | 250 |
| 228 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionSet); | 251 DISALLOW_COPY_AND_ASSIGN(URLMatcherConditionSet); |
| 229 }; | 252 }; |
| 230 | 253 |
| 231 // This class allows matching one URL against a large set of | 254 // This class allows matching one URL against a large set of |
| 232 // URLMatcherConditionSets at the same time. | 255 // URLMatcherConditionSets at the same time. |
| 233 class URLMatcher { | 256 class URLMatcher { |
| 234 public: | 257 public: |
| 235 URLMatcher(); | 258 URLMatcher(); |
| 236 ~URLMatcher(); | 259 ~URLMatcher(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 SubstringSetMatcher url_component_matcher_; | 310 SubstringSetMatcher url_component_matcher_; |
| 288 std::set<const SubstringPattern*> registered_full_url_patterns_; | 311 std::set<const SubstringPattern*> registered_full_url_patterns_; |
| 289 std::set<const SubstringPattern*> registered_url_component_patterns_; | 312 std::set<const SubstringPattern*> registered_url_component_patterns_; |
| 290 | 313 |
| 291 DISALLOW_COPY_AND_ASSIGN(URLMatcher); | 314 DISALLOW_COPY_AND_ASSIGN(URLMatcher); |
| 292 }; | 315 }; |
| 293 | 316 |
| 294 } // namespace extensions | 317 } // namespace extensions |
| 295 | 318 |
| 296 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_URL_MATCHER_H_ | 319 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_URL_MATCHER_H_ |
| OLD | NEW |