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

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

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

Powered by Google App Engine
This is Rietveld 408576698