OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES_RE
GISTRY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES_RE
GISTRY_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/memory/linked_ptr.h" |
| 12 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" |
| 13 #include "chrome/browser/extensions/api/declarative/url_matcher.h" |
| 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h
" |
| 15 |
| 16 namespace net { |
| 17 class URLRequest; |
| 18 } |
| 19 |
| 20 namespace extensions { |
| 21 |
| 22 class WebRequestRule; |
| 23 |
| 24 // The WebRequestRulesRegistry is responsible for managing |
| 25 // the internal representation of rules for the Declarative Web Request API. |
| 26 // |
| 27 // Here is the high level overview of this functionality: |
| 28 // |
| 29 // RulesRegistry::Rule consists of Conditions and Actions, these are |
| 30 // represented as a WebRequestRule with WebRequestConditions and |
| 31 // WebRequestRuleActions. |
| 32 // |
| 33 // WebRequestConditions represent JSON dictionaries as the following: |
| 34 // { |
| 35 // 'instanceType': 'URLMatcher', |
| 36 // 'host_suffix': 'example.com', |
| 37 // 'path_prefix': '/query', |
| 38 // 'scheme': 'http' |
| 39 // } |
| 40 // |
| 41 // The evaluation of URL related condition attributes (host_suffix, path_prefix) |
| 42 // is delegated to a URLMatcher, because this is capable of evaluating many |
| 43 // of such URL related condition attributes in parallel. |
| 44 // |
| 45 // For this, the URLRequestCondition has a URLMatcherConditionSet, which |
| 46 // represents the {'host_suffix': 'example.com', 'path_prefix': '/query'} part. |
| 47 // We will then ask the URLMatcher, whether a given URL |
| 48 // "http://www.example.com/query/" has any matches, and the URLMatcher |
| 49 // will respond with the URLMatcherConditionSet::ID. We can map this |
| 50 // to the WebRequestRule and check whether also the other conditions (in this |
| 51 // example 'scheme': 'http') are fulfilled. |
| 52 class WebRequestRulesRegistry : public RulesRegistryWithCache { |
| 53 public: |
| 54 WebRequestRulesRegistry(); |
| 55 virtual ~WebRequestRulesRegistry(); |
| 56 |
| 57 // TODO(battre): This will become an implementation detail, because we need |
| 58 // a way to also execute the actions of the rules. |
| 59 std::set<WebRequestRule::GlobalRuleId> GetMatches(net::URLRequest* request); |
| 60 |
| 61 // Implementation of RulesRegistryWithCache: |
| 62 virtual std::string AddRulesImpl( |
| 63 const std::string& extension_id, |
| 64 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; |
| 65 virtual std::string RemoveRulesImpl( |
| 66 const std::string& extension_id, |
| 67 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 68 virtual std::string RemoveAllRulesImpl( |
| 69 const std::string& extension_id) OVERRIDE; |
| 70 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; |
| 71 |
| 72 private: |
| 73 // Map that tells us which WebRequestRule may match under the condition that |
| 74 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. |
| 75 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; |
| 76 RuleTriggers rule_triggers_; |
| 77 |
| 78 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > |
| 79 RulesMap; |
| 80 RulesMap webrequest_rules_; |
| 81 |
| 82 URLMatcher url_matcher_; |
| 83 }; |
| 84 |
| 85 } // namespace extensions |
| 86 |
| 87 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES
_REGISTRY_H_ |
OLD | NEW |