| 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 <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| 14 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.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_rule.h
" |
| 19 #include "chrome/browser/extensions/extension_info_map.h" | 20 #include "chrome/browser/extensions/extension_info_map.h" |
| 20 #include "chrome/common/extensions/matcher/url_matcher.h" | 21 #include "chrome/common/extensions/matcher/url_matcher.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // "http://www.example.com/query/" has any matches, and the URLMatcher | 62 // "http://www.example.com/query/" has any matches, and the URLMatcher |
| 62 // will respond with the URLMatcherConditionSet::ID. We can map this | 63 // will respond with the URLMatcherConditionSet::ID. We can map this |
| 63 // to the WebRequestRule and check whether also the other conditions (in this | 64 // to the WebRequestRule and check whether also the other conditions (in this |
| 64 // example 'scheme': 'http') are fulfilled. | 65 // example 'scheme': 'http') are fulfilled. |
| 65 class WebRequestRulesRegistry : public RulesRegistryWithCache { | 66 class WebRequestRulesRegistry : public RulesRegistryWithCache { |
| 66 public: | 67 public: |
| 67 WebRequestRulesRegistry(Profile* profile, Delegate* delegate); | 68 WebRequestRulesRegistry(Profile* profile, Delegate* delegate); |
| 68 | 69 |
| 69 // TODO(battre): This will become an implementation detail, because we need | 70 // TODO(battre): This will become an implementation detail, because we need |
| 70 // a way to also execute the actions of the rules. | 71 // a way to also execute the actions of the rules. |
| 71 std::set<WebRequestRule::GlobalRuleId> GetMatches( | 72 std::set<const WebRequestRule*> GetMatches( |
| 72 const WebRequestRule::RequestData& request_data); | 73 const WebRequestRule::RequestData& request_data); |
| 73 | 74 |
| 74 // Returns which modifications should be executed on the network request | 75 // Returns which modifications should be executed on the network request |
| 75 // according to the rules registered in this registry. | 76 // according to the rules registered in this registry. |
| 76 std::list<LinkedPtrEventResponseDelta> CreateDeltas( | 77 std::list<LinkedPtrEventResponseDelta> CreateDeltas( |
| 77 const ExtensionInfoMap* extension_info_map, | 78 const ExtensionInfoMap* extension_info_map, |
| 78 const WebRequestRule::RequestData& request_data, | 79 const WebRequestRule::RequestData& request_data, |
| 79 bool crosses_incognito); | 80 bool crosses_incognito); |
| 80 | 81 |
| 81 // Implementation of RulesRegistryWithCache: | 82 // Implementation of RulesRegistryWithCache: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 bool IsEmpty() const; | 94 bool IsEmpty() const; |
| 94 | 95 |
| 95 protected: | 96 protected: |
| 96 virtual ~WebRequestRulesRegistry(); | 97 virtual ~WebRequestRulesRegistry(); |
| 97 | 98 |
| 98 // Virtual for testing: | 99 // Virtual for testing: |
| 99 virtual base::Time GetExtensionInstallationTime( | 100 virtual base::Time GetExtensionInstallationTime( |
| 100 const std::string& extension_id) const; | 101 const std::string& extension_id) const; |
| 101 virtual void ClearCacheOnNavigation(); | 102 virtual void ClearCacheOnNavigation(); |
| 102 | 103 |
| 104 const std::set<const WebRequestRule*>& |
| 105 rules_with_untriggered_conditions_for_test() const { |
| 106 return rules_with_untriggered_conditions_; |
| 107 } |
| 108 |
| 103 private: | 109 private: |
| 104 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; | 110 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; |
| 105 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > | 111 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > |
| 106 RulesMap; | 112 RulesMap; |
| 107 | 113 |
| 108 // Map that tells us which WebRequestRule may match under the condition that | 114 // Map that tells us which WebRequestRule may match under the condition that |
| 109 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. | 115 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. |
| 110 RuleTriggers rule_triggers_; | 116 RuleTriggers rule_triggers_; |
| 111 | 117 |
| 118 // 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 |
| 120 // separately. |
| 121 std::set<const WebRequestRule*> rules_with_untriggered_conditions_; |
| 122 |
| 112 RulesMap webrequest_rules_; | 123 RulesMap webrequest_rules_; |
| 113 | 124 |
| 114 URLMatcher url_matcher_; | 125 URLMatcher url_matcher_; |
| 115 | 126 |
| 116 scoped_refptr<ExtensionInfoMap> extension_info_map_; | 127 scoped_refptr<ExtensionInfoMap> extension_info_map_; |
| 117 }; | 128 }; |
| 118 | 129 |
| 119 } // namespace extensions | 130 } // namespace extensions |
| 120 | 131 |
| 121 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES
_REGISTRY_H_ | 132 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES
_REGISTRY_H_ |
| OLD | NEW |