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