| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> |
| 10 #include <map> |
| 11 #include <set> |
| 9 #include <vector> | 12 #include <vector> |
| 10 #include <list> | |
| 11 | 13 |
| 12 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 13 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" | 15 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" |
| 14 #include "chrome/browser/extensions/api/declarative/url_matcher.h" | 16 #include "chrome/browser/extensions/api/declarative/url_matcher.h" |
| 15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" | 17 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" |
| 16 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h
" | 18 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h
" |
| 17 | 19 |
| 18 namespace extension_web_request_api_helpers { | 20 namespace extension_web_request_api_helpers { |
| 19 struct EventResponseDelta; | 21 struct EventResponseDelta; |
| 20 } | 22 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // For this, the URLRequestCondition has a URLMatcherConditionSet, which | 54 // For this, the URLRequestCondition has a URLMatcherConditionSet, which |
| 53 // represents the {'host_suffix': 'example.com', 'path_prefix': '/query'} part. | 55 // represents the {'host_suffix': 'example.com', 'path_prefix': '/query'} part. |
| 54 // We will then ask the URLMatcher, whether a given URL | 56 // We will then ask the URLMatcher, whether a given URL |
| 55 // "http://www.example.com/query/" has any matches, and the URLMatcher | 57 // "http://www.example.com/query/" has any matches, and the URLMatcher |
| 56 // will respond with the URLMatcherConditionSet::ID. We can map this | 58 // will respond with the URLMatcherConditionSet::ID. We can map this |
| 57 // to the WebRequestRule and check whether also the other conditions (in this | 59 // to the WebRequestRule and check whether also the other conditions (in this |
| 58 // example 'scheme': 'http') are fulfilled. | 60 // example 'scheme': 'http') are fulfilled. |
| 59 class WebRequestRulesRegistry : public RulesRegistryWithCache { | 61 class WebRequestRulesRegistry : public RulesRegistryWithCache { |
| 60 public: | 62 public: |
| 61 WebRequestRulesRegistry(); | 63 WebRequestRulesRegistry(); |
| 62 virtual ~WebRequestRulesRegistry(); | |
| 63 | 64 |
| 64 // TODO(battre): This will become an implementation detail, because we need | 65 // TODO(battre): This will become an implementation detail, because we need |
| 65 // a way to also execute the actions of the rules. | 66 // a way to also execute the actions of the rules. |
| 66 std::set<WebRequestRule::GlobalRuleId> GetMatches( | 67 std::set<WebRequestRule::GlobalRuleId> GetMatches( |
| 67 net::URLRequest* request, | 68 net::URLRequest* request, |
| 68 RequestStages request_stage); | 69 RequestStages request_stage); |
| 69 | 70 |
| 70 // Returns which modifications should be executed on the network request | 71 // Returns which modifications should be executed on the network request |
| 71 // according to the rules registered in this registry. | 72 // according to the rules registered in this registry. |
| 72 std::list<LinkedPtrEventResponseDelta> CreateDeltas( | 73 std::list<LinkedPtrEventResponseDelta> CreateDeltas( |
| 73 net::URLRequest* request, RequestStages request_stage); | 74 net::URLRequest* request, RequestStages request_stage); |
| 74 | 75 |
| 75 // Implementation of RulesRegistryWithCache: | 76 // Implementation of RulesRegistryWithCache: |
| 76 virtual std::string AddRulesImpl( | 77 virtual std::string AddRulesImpl( |
| 77 const std::string& extension_id, | 78 const std::string& extension_id, |
| 78 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; | 79 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; |
| 79 virtual std::string RemoveRulesImpl( | 80 virtual std::string RemoveRulesImpl( |
| 80 const std::string& extension_id, | 81 const std::string& extension_id, |
| 81 const std::vector<std::string>& rule_identifiers) OVERRIDE; | 82 const std::vector<std::string>& rule_identifiers) OVERRIDE; |
| 82 virtual std::string RemoveAllRulesImpl( | 83 virtual std::string RemoveAllRulesImpl( |
| 83 const std::string& extension_id) OVERRIDE; | 84 const std::string& extension_id) OVERRIDE; |
| 84 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; | 85 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; |
| 85 | 86 |
| 86 // Returns true if this object retains no allocated data. Only for debugging. | 87 // Returns true if this object retains no allocated data. Only for debugging. |
| 87 bool IsEmpty() const; | 88 bool IsEmpty() const; |
| 88 | 89 |
| 89 private: | 90 private: |
| 91 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; |
| 92 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > |
| 93 RulesMap; |
| 94 |
| 95 virtual ~WebRequestRulesRegistry(); |
| 96 |
| 90 // Map that tells us which WebRequestRule may match under the condition that | 97 // Map that tells us which WebRequestRule may match under the condition that |
| 91 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. | 98 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. |
| 92 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; | |
| 93 RuleTriggers rule_triggers_; | 99 RuleTriggers rule_triggers_; |
| 94 | 100 |
| 95 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > | |
| 96 RulesMap; | |
| 97 RulesMap webrequest_rules_; | 101 RulesMap webrequest_rules_; |
| 98 | 102 |
| 99 URLMatcher url_matcher_; | 103 URLMatcher url_matcher_; |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 } // namespace extensions | 106 } // namespace extensions |
| 103 | 107 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES
_REGISTRY_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES
_REGISTRY_H_ |
| OLD | NEW |