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 | |
15 namespace net { | |
16 class URLRequest; | |
17 } | |
18 | |
19 namespace extensions { | |
20 namespace declarative_webrequest{ | |
21 class WebRequestRule; | |
Matt Perry
2012/03/22 01:34:43
nit: just move this into the namespace block below
battre
2012/03/26 18:35:51
Done.
| |
22 } | |
23 } | |
24 | |
25 namespace extensions { | |
26 namespace declarative_webrequest{ | |
Matt Perry
2012/03/22 01:34:43
We shouldn't go overboard with namespaces. I think
battre
2012/03/26 18:35:51
Done.
| |
27 | |
28 // The WebRequestRulesRegistry is responsible for managing | |
29 // the internal representation of rules for the Declarative Web Request API. | |
30 // | |
31 // Here is the high level overview of this functionality: | |
32 // | |
33 // RulesRegistry::Rule consists of Conditions and Actions, these are | |
34 // represented as a WebRequestRule with WebRequestConditions and | |
35 // WebRequestRuleActions. | |
36 // | |
37 // WebRequestConditions represent JSON dictionaries as the following: | |
38 // { | |
39 // 'instanceType': 'URLMatcher', | |
40 // 'host_suffix': 'example.com', | |
41 // 'path_prefix': '/query', | |
42 // 'schema': 'http' | |
Matt Perry
2012/03/22 23:07:25
schema -> scheme
battre
2012/03/26 18:35:51
Done.
| |
43 // } | |
44 // | |
45 // The evaluation of URL related condition attributes (http_suffix, path_prefix) | |
Matt Perry
2012/03/22 01:34:43
host_suffix*
battre
2012/03/26 18:35:51
Done.
| |
46 // is delegated to a URLMatcher, because this is capable of evaluating many | |
47 // of such URL related condition attributes in parallel. | |
48 // | |
49 // For this, the URLRequestCondition has a URLMatcherConditionSet, which | |
50 // represents the {'host_suffix': 'example.com', 'path_prefix': '/query'} part. | |
51 // We will then ask the URLMatcher, whether a given URL | |
52 // "http://www.example.com/query/" has any matches, and the URLMatcher | |
53 // will respond with the URLMatcherConditionSet::ID. We can map this | |
54 // to the WebRequestRule and check whether also the other conditions (in this | |
55 // example 'schema': 'http') are fulfilled. | |
Matt Perry
2012/03/22 01:34:43
I just started reviewing and don't have the full p
battre
2012/03/26 18:35:51
I have changed the example to 'has_cookie': {'name
| |
56 class WebRequestRulesRegistry : public RulesRegistryWithCache { | |
57 public: | |
58 typedef std::string ExtensionId; | |
59 typedef std::string RuleId; | |
60 typedef std::pair<ExtensionId, RuleId> GlobalRuleId; | |
61 | |
62 WebRequestRulesRegistry(); | |
63 ~WebRequestRulesRegistry(); | |
64 | |
65 // TODO(battre): This will become an implementation detail, because we need | |
66 // a way to also execute the actions of the rules. | |
67 std::set<GlobalRuleId> GetMatches(net::URLRequest* request); | |
68 | |
69 // Implementation of RulesRegistryWithCache: | |
70 virtual std::string AddRulesImpl( | |
71 const std::string& extension_id, | |
72 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; | |
73 virtual std::string RemoveRulesImpl( | |
74 const std::string& extension_id, | |
75 const std::vector<std::string>& rule_identifiers) OVERRIDE; | |
76 virtual std::string RemoveAllRulesImpl( | |
77 const std::string& extension_id) OVERRIDE; | |
78 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; | |
79 | |
80 private: | |
81 // Checking which rules match for a URLRequest is a two staged process. | |
82 // First we check all condition attributes regarding the URL. Each Rule is | |
83 // associated with URLMatcherConditionSets for these attributes. In case | |
84 // of a match, we also test the remaining condition attributes. | |
85 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; | |
86 RuleTriggers rule_triggers_; | |
87 | |
88 typedef std::map<GlobalRuleId, linked_ptr<WebRequestRule> > RulesMap; | |
89 RulesMap webrequest_rules_; | |
90 | |
91 std::map<WebRequestRule*, GlobalRuleId> rule_ids_; | |
Matt Perry
2012/03/22 23:07:25
You could avoid needing this by having RuleTrigger
battre
2012/03/26 18:35:51
Done.
| |
92 | |
93 URLMatcher url_matcher_; | |
94 }; | |
95 | |
96 } // namespace declarative_webrequest | |
97 } // namespace extensions | |
98 | |
99 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES _REGISTRY_H_ | |
OLD | NEW |