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

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

Issue 10406013: Support extension precedences in declarative WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Matt's comments Created 8 years, 7 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 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/time.h"
14 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/ref_counted.h"
15 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h" 17 #include "chrome/browser/extensions/api/declarative/rules_registry_with_cache.h"
16 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" 18 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h"
17 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h " 19 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h "
20 #include "chrome/browser/extensions/extension_info_map.h"
18 #include "chrome/common/extensions/matcher/url_matcher.h" 21 #include "chrome/common/extensions/matcher/url_matcher.h"
19 22
23 class Profile;
24
20 namespace extension_web_request_api_helpers { 25 namespace extension_web_request_api_helpers {
21 struct EventResponseDelta; 26 struct EventResponseDelta;
22 } 27 }
23 28
24 namespace net { 29 namespace net {
25 class URLRequest; 30 class URLRequest;
26 } 31 }
27 32
28 namespace extensions { 33 namespace extensions {
29 34
(...skipping 23 matching lines...) Expand all
53 // 58 //
54 // For this, the URLRequestCondition has a URLMatcherConditionSet, which 59 // For this, the URLRequestCondition has a URLMatcherConditionSet, which
55 // represents the {'host_suffix': 'example.com', 'path_prefix': '/query'} part. 60 // represents the {'host_suffix': 'example.com', 'path_prefix': '/query'} part.
56 // We will then ask the URLMatcher, whether a given URL 61 // We will then ask the URLMatcher, whether a given URL
57 // "http://www.example.com/query/" has any matches, and the URLMatcher 62 // "http://www.example.com/query/" has any matches, and the URLMatcher
58 // will respond with the URLMatcherConditionSet::ID. We can map this 63 // will respond with the URLMatcherConditionSet::ID. We can map this
59 // 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
60 // example 'scheme': 'http') are fulfilled. 65 // example 'scheme': 'http') are fulfilled.
61 class WebRequestRulesRegistry : public RulesRegistryWithCache { 66 class WebRequestRulesRegistry : public RulesRegistryWithCache {
62 public: 67 public:
63 WebRequestRulesRegistry(); 68 explicit WebRequestRulesRegistry(Profile* profile);
64 69
65 // TODO(battre): This will become an implementation detail, because we need 70 // TODO(battre): This will become an implementation detail, because we need
66 // a way to also execute the actions of the rules. 71 // a way to also execute the actions of the rules.
67 std::set<WebRequestRule::GlobalRuleId> GetMatches( 72 std::set<WebRequestRule::GlobalRuleId> GetMatches(
68 net::URLRequest* request, 73 net::URLRequest* request,
69 RequestStages request_stage); 74 RequestStages request_stage);
70 75
71 // Returns which modifications should be executed on the network request 76 // Returns which modifications should be executed on the network request
72 // according to the rules registered in this registry. 77 // according to the rules registered in this registry.
73 std::list<LinkedPtrEventResponseDelta> CreateDeltas( 78 std::list<LinkedPtrEventResponseDelta> CreateDeltas(
74 net::URLRequest* request, RequestStages request_stage); 79 net::URLRequest* request, RequestStages request_stage);
75 80
76 // Implementation of RulesRegistryWithCache: 81 // Implementation of RulesRegistryWithCache:
77 virtual std::string AddRulesImpl( 82 virtual std::string AddRulesImpl(
78 const std::string& extension_id, 83 const std::string& extension_id,
79 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE; 84 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE;
80 virtual std::string RemoveRulesImpl( 85 virtual std::string RemoveRulesImpl(
81 const std::string& extension_id, 86 const std::string& extension_id,
82 const std::vector<std::string>& rule_identifiers) OVERRIDE; 87 const std::vector<std::string>& rule_identifiers) OVERRIDE;
83 virtual std::string RemoveAllRulesImpl( 88 virtual std::string RemoveAllRulesImpl(
84 const std::string& extension_id) OVERRIDE; 89 const std::string& extension_id) OVERRIDE;
85 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE; 90 virtual content::BrowserThread::ID GetOwnerThread() const OVERRIDE;
86 91
87 // Returns true if this object retains no allocated data. Only for debugging. 92 // Returns true if this object retains no allocated data. Only for debugging.
88 bool IsEmpty() const; 93 bool IsEmpty() const;
89 94
95 protected:
96 virtual ~WebRequestRulesRegistry();
97 virtual base::Time GetExtensionInstallationTime(
98 const std::string& extension_id) const;
99
90 private: 100 private:
91 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers; 101 typedef std::map<URLMatcherConditionSet::ID, WebRequestRule*> RuleTriggers;
92 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> > 102 typedef std::map<WebRequestRule::GlobalRuleId, linked_ptr<WebRequestRule> >
93 RulesMap; 103 RulesMap;
94 104
95 virtual ~WebRequestRulesRegistry();
96
97 // Map that tells us which WebRequestRule may match under the condition that 105 // Map that tells us which WebRequestRule may match under the condition that
98 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. 106 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|.
99 RuleTriggers rule_triggers_; 107 RuleTriggers rule_triggers_;
100 108
101 RulesMap webrequest_rules_; 109 RulesMap webrequest_rules_;
102 110
103 URLMatcher url_matcher_; 111 URLMatcher url_matcher_;
112
113 scoped_refptr<ExtensionInfoMap> extension_info_map_;
104 }; 114 };
105 115
106 } // namespace extensions 116 } // namespace extensions
107 117
108 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES _REGISTRY_H_ 118 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULES _REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698