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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.h

Issue 11572061: Create DeclarativeConditionSet, DeclarativeActionSet, and DeclarativeRule templates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix kalman's nit Created 7 years, 11 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 CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES_RE GISTRY_H_ 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_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES_RE GISTRY_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "chrome/browser/extensions/api/declarative/declarative_rule.h"
17 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" 18 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h"
18 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" 19 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h"
19 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h " 20 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action .h"
21 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h"
20 #include "chrome/browser/extensions/extension_info_map.h" 22 #include "chrome/browser/extensions/extension_info_map.h"
21 #include "chrome/common/extensions/matcher/url_matcher.h" 23 #include "chrome/common/extensions/matcher/url_matcher.h"
22 24
23 class Profile; 25 class Profile;
24 class WebRequestPermissions; 26 class WebRequestPermissions;
25 27
26 namespace extension_web_request_api_helpers { 28 namespace extension_web_request_api_helpers {
27 struct EventResponseDelta; 29 struct EventResponseDelta;
28 } 30 }
29 31
30 namespace net { 32 namespace net {
31 class URLRequest; 33 class URLRequest;
32 } 34 }
33 35
34 namespace extensions { 36 namespace extensions {
35 37
36 class RulesRegistryService; 38 class RulesRegistryService;
37 39
40 typedef linked_ptr<extension_web_request_api_helpers::EventResponseDelta>
41 LinkedPtrEventResponseDelta;
42 typedef DeclarativeRule<WebRequestCondition, WebRequestAction> WebRequestRule;
43
38 // The WebRequestRulesRegistry is responsible for managing 44 // The WebRequestRulesRegistry is responsible for managing
39 // the internal representation of rules for the Declarative Web Request API. 45 // the internal representation of rules for the Declarative Web Request API.
40 // 46 //
41 // Here is the high level overview of this functionality: 47 // Here is the high level overview of this functionality:
42 // 48 //
43 // RulesRegistry::Rule consists of Conditions and Actions, these are 49 // RulesRegistry::Rule consists of Conditions and Actions, these are
44 // represented as a WebRequestRule with WebRequestConditions and 50 // represented as a WebRequestRule with WebRequestConditions and
45 // WebRequestRuleActions. 51 // WebRequestRuleActions.
46 // 52 //
47 // WebRequestConditions represent JSON dictionaries as the following: 53 // WebRequestConditions represent JSON dictionaries as the following:
(...skipping 15 matching lines...) Expand all
63 // will respond with the URLMatcherConditionSet::ID. We can map this 69 // will respond with the URLMatcherConditionSet::ID. We can map this
64 // to the WebRequestRule and check whether also the other conditions (in this 70 // to the WebRequestRule and check whether also the other conditions (in this
65 // example 'scheme': 'http') are fulfilled. 71 // example 'scheme': 'http') are fulfilled.
66 class WebRequestRulesRegistry : public RulesRegistryWithCache { 72 class WebRequestRulesRegistry : public RulesRegistryWithCache {
67 public: 73 public:
68 WebRequestRulesRegistry(Profile* profile, Delegate* delegate); 74 WebRequestRulesRegistry(Profile* profile, Delegate* delegate);
69 75
70 // TODO(battre): This will become an implementation detail, because we need 76 // TODO(battre): This will become an implementation detail, because we need
71 // a way to also execute the actions of the rules. 77 // a way to also execute the actions of the rules.
72 std::set<const WebRequestRule*> GetMatches( 78 std::set<const WebRequestRule*> GetMatches(
73 const WebRequestRule::RequestData& request_data); 79 const DeclarativeWebRequestData& request_data);
74 80
75 // Returns which modifications should be executed on the network request 81 // Returns which modifications should be executed on the network request
76 // according to the rules registered in this registry. 82 // according to the rules registered in this registry.
77 std::list<LinkedPtrEventResponseDelta> CreateDeltas( 83 std::list<LinkedPtrEventResponseDelta> CreateDeltas(
78 const ExtensionInfoMap* extension_info_map, 84 const ExtensionInfoMap* extension_info_map,
79 const WebRequestRule::RequestData& request_data, 85 const DeclarativeWebRequestData& request_data,
80 bool crosses_incognito); 86 bool crosses_incognito);
81 87
82 // Implementation of RulesRegistryWithCache: 88 // Implementation of RulesRegistryWithCache:
83 virtual std::string AddRulesImpl( 89 virtual std::string AddRulesImpl(
84 const std::string& extension_id, 90 const std::string& extension_id,
85 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; 91 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE;
86 virtual std::string RemoveRulesImpl( 92 virtual std::string RemoveRulesImpl(
87 const std::string& extension_id, 93 const std::string& extension_id,
88 const std::vector<std::string>& rule_identifiers) OVERRIDE; 94 const std::vector<std::string>& rule_identifiers) OVERRIDE;
89 virtual std::string RemoveAllRulesImpl( 95 virtual std::string RemoveAllRulesImpl(
(...skipping 10 matching lines...) Expand all
100 virtual base::Time GetExtensionInstallationTime( 106 virtual base::Time GetExtensionInstallationTime(
101 const std::string& extension_id) const; 107 const std::string& extension_id) const;
102 virtual void ClearCacheOnNavigation(); 108 virtual void ClearCacheOnNavigation();
103 109
104 const std::set<const WebRequestRule*>& 110 const std::set<const WebRequestRule*>&
105 rules_with_untriggered_conditions_for_test() const { 111 rules_with_untriggered_conditions_for_test() const {
106 return rules_with_untriggered_conditions_; 112 return rules_with_untriggered_conditions_;
107 } 113 }
108 114
109 private: 115 private:
116 // Checks whether the set of |conditions| and |actions| are consistent,
117 // meaning for example that we do not allow combining an |action| that needs
118 // to be executed before the |condition| can be fulfilled.
119 // Returns true in case of consistency and MUST set |error| otherwise.
120 static bool CheckConsistency(const WebRequestConditionSet* conditions,
121 const WebRequestActionSet* actions,
122 std::string* error);
123
110 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; 124 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers;
111 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > 125 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> >
112 RulesMap; 126 RulesMap;
113 127
114 // Map that tells us which WebRequestRule may match under the condition that 128 // Map that tells us which WebRequestRule may match under the condition that
115 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. 129 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|.
116 RuleTriggers rule_triggers_; 130 RuleTriggers rule_triggers_;
117 131
118 // These rules contain condition sets with conditions without URL attributes. 132 // These rules contain condition sets with conditions without URL attributes.
119 // Such conditions are not triggered by URL matcher, so we need to test them 133 // Such conditions are not triggered by URL matcher, so we need to test them
120 // separately. 134 // separately.
121 std::set<const WebRequestRule*> rules_with_untriggered_conditions_; 135 std::set<const WebRequestRule*> rules_with_untriggered_conditions_;
122 136
123 RulesMap webrequest_rules_; 137 RulesMap webrequest_rules_;
124 138
125 URLMatcher url_matcher_; 139 URLMatcher url_matcher_;
126 140
127 scoped_refptr<ExtensionInfoMap> extension_info_map_; 141 scoped_refptr<ExtensionInfoMap> extension_info_map_;
128 }; 142 };
129 143
130 } // namespace extensions 144 } // namespace extensions
131 145
132 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES _REGISTRY_H_ 146 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES _REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698