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

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

Issue 11572061: Create DeclarativeConditionSet, DeclarativeActionSet, and DeclarativeRule templates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 2 simple bugs 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_H_
7
8 #include <list>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/time.h"
13 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
14 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h"
15
16 class ExtensionInfoMap;
17 class WebRequestPermissions;
18
19 namespace extensions {
20 class Extension;
21 class URLMatcherConditionFactory;
22 class WebRequestActionSet;
23 class WebRequestConditionSet;
24 }
25
26 namespace extension_web_request_api_helpers {
27 struct EventResponseDelta;
28 }
29
30 namespace net {
31 class HttpResponseHeaders;
32 class URLRequest;
33 }
34
35 namespace extensions {
36
37 typedef linked_ptr<extension_web_request_api_helpers::EventResponseDelta>
38 LinkedPtrEventResponseDelta;
39
40 // Representation of a rule of the declarative Web Request API
41 class WebRequestRule {
42 public:
43 typedef std::string ExtensionId;
44 typedef std::string RuleId;
45 typedef std::pair<ExtensionId, RuleId> GlobalRuleId;
46 typedef int Priority;
47
48 struct RequestData {
49 RequestData(net::URLRequest* request, RequestStage stage)
50 : request(request), stage(stage),
51 original_response_headers(NULL) {}
52 RequestData(net::URLRequest* request, RequestStage stage,
53 const net::HttpResponseHeaders* original_response_headers)
54 : request(request), stage(stage),
55 original_response_headers(original_response_headers) {}
56 net::URLRequest* request;
57 RequestStage stage;
58 // Additional information about requests that is not
59 // available in all request stages.
60 const net::HttpResponseHeaders* original_response_headers;
61 };
62
63 WebRequestRule(const GlobalRuleId& id,
64 base::Time extension_installation_time,
65 scoped_ptr<WebRequestConditionSet> conditions,
66 scoped_ptr<WebRequestActionSet> actions,
67 Priority priority);
68 virtual ~WebRequestRule();
69
70 // If |error| is empty, the translation was successful and the returned
71 // rule is internally consistent.
72 static scoped_ptr<WebRequestRule> Create(
73 URLMatcherConditionFactory* url_matcher_condition_factory,
74 const std::string& extension_id,
75 base::Time extension_installation_time,
76 linked_ptr<RulesRegistry::Rule> rule,
77 std::string* error);
78
79 const GlobalRuleId& id() const { return id_; }
80 const std::string& extension_id() const { return id_.first; }
81 const WebRequestConditionSet& conditions() const { return *conditions_; }
82 const WebRequestActionSet& actions() const { return *actions_; }
83 Priority priority() const { return priority_; }
84
85 // Creates all deltas resulting from the ActionSet. This function should
86 // only be called when the conditions_ are fulfilled (from a semantic point
87 // of view; no harm is done if this function is called at other times for
88 // testing purposes).
89 // If |extension| is set, deltas are suppressed if the |extension| does not
90 // have have sufficient permissions to modify the request. The returned list
91 // may be empty in this case.
92 std::list<LinkedPtrEventResponseDelta> CreateDeltas(
93 const ExtensionInfoMap* extension_info_map,
94 const RequestData& request_data,
95 bool crosses_incognito) const;
96
97 // Returns the minimum priority of rules that may be evaluated after
98 // this rule. Defaults to MAX_INT. Only valid if the conditions of this rule
99 // are fulfilled.
100 Priority GetMinimumPriority() const;
101
102 private:
103 // Checks whether the set of |conditions| and |actions| are consistent,
104 // meaning for example that we do not allow combining an |action| that needs
105 // to be executed before the |condition| can be fulfilled.
106 // Returns true in case of consistency and MUST set |error| otherwise.
107 static bool CheckConsistency(WebRequestConditionSet* conditions,
108 WebRequestActionSet* actions,
109 std::string* error);
110
111 GlobalRuleId id_;
112 base::Time extension_installation_time_; // For precedences of rules.
113 scoped_ptr<WebRequestConditionSet> conditions_;
114 scoped_ptr<WebRequestActionSet> actions_;
115 Priority priority_;
116
117 DISALLOW_COPY_AND_ASSIGN(WebRequestRule);
118 };
119
120 } // namespace extensions
121
122 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_RULE_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698