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_ACTION_H _ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _ |
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTION_H _ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" | 14 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" |
15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h " | 15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h " |
16 #include "chrome/common/extensions/api/events.h" | 16 #include "chrome/common/extensions/api/events.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 #include "unicode/regex.h" | 18 #include "unicode/regex.h" |
19 | 19 |
20 class WebRequestPermission; | |
21 | |
20 namespace base { | 22 namespace base { |
21 class DictionaryValue; | 23 class DictionaryValue; |
22 class Time; | 24 class Time; |
23 class Value; | 25 class Value; |
24 } | 26 } |
25 | 27 |
26 namespace extension_web_request_api_helpers { | 28 namespace extension_web_request_api_helpers { |
27 struct EventResponseDelta; | 29 struct EventResponseDelta; |
28 } | 30 } |
29 | 31 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 // contains a 1 for each request stage during which the condition can be | 67 // contains a 1 for each request stage during which the condition can be |
66 // tested. | 68 // tested. |
67 virtual int GetStages() const = 0; | 69 virtual int GetStages() const = 0; |
68 | 70 |
69 virtual Type GetType() const = 0; | 71 virtual Type GetType() const = 0; |
70 | 72 |
71 // Returns the minimum priority of rules that may be evaluated after | 73 // Returns the minimum priority of rules that may be evaluated after |
72 // this rule. Defaults to MIN_INT. | 74 // this rule. Defaults to MIN_INT. |
73 virtual int GetMinimumPriority() const; | 75 virtual int GetMinimumPriority() const; |
74 | 76 |
75 // Returns whether |extension| has permission to execute this action | 77 // Returns whether the specified extension has permission to execute this |
76 // on |request|. Defaults to checking the host permission. | 78 // action on |request|. Checks the host permission if |
77 // |extension| may only be NULL for during testing, in which case | 79 // GetEnforceHostPermissions instructs to do that. |
78 // host permissions are ignored. | 80 // |permissions| and |extension_info_map| may only be NULL for during testing, |
79 virtual bool HasPermission(const extensions::Extension* extension, | 81 // in which case host permissions are ignored. |crosses_incognito| specifies |
80 const net::URLRequest* request) const; | 82 // whether the request comes from a different profile than |extension_id| |
83 // but was processed because the extension is in spanning mode. | |
84 virtual bool HasPermission(const WebRequestPermissions* permissions, | |
85 const ExtensionInfoMap* extension_info_map, | |
86 const std::string& extension_id, | |
87 const net::URLRequest* request, | |
88 bool crosses_incognito) const; | |
89 | |
90 // Returns whether host permissions shall be enforced by this actions. | |
91 // Used by the standard implementation of HasPermission. Defaults to true. | |
92 virtual bool GetEnforceHostPermissions() const; | |
Matt Perry
2012/07/25 21:27:56
nit: ShouldEnforceHostPermissions?
battre
2012/07/26 16:38:43
Done.
| |
81 | 93 |
82 // Factory method that instantiates a concrete WebRequestAction | 94 // Factory method that instantiates a concrete WebRequestAction |
83 // implementation according to |json_action|, the representation of the | 95 // implementation according to |json_action|, the representation of the |
84 // WebRequestAction as received from the extension API. | 96 // WebRequestAction as received from the extension API. |
85 // Sets |error| and returns NULL in case of a semantic error that cannot | 97 // Sets |error| and returns NULL in case of a semantic error that cannot |
86 // be caught by schema validation. Sets |bad_message| and returns NULL | 98 // be caught by schema validation. Sets |bad_message| and returns NULL |
87 // in case the input is syntactically unexpected. | 99 // in case the input is syntactically unexpected. |
88 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, | 100 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, |
89 std::string* error, | 101 std::string* error, |
90 bool* bad_message); | 102 bool* bad_message); |
(...skipping 25 matching lines...) Expand all Loading... | |
116 // |actions| which represents the array of actions received from the | 128 // |actions| which represents the array of actions received from the |
117 // extension API. | 129 // extension API. |
118 static scoped_ptr<WebRequestActionSet> Create(const AnyVector& actions, | 130 static scoped_ptr<WebRequestActionSet> Create(const AnyVector& actions, |
119 std::string* error, | 131 std::string* error, |
120 bool* bad_message); | 132 bool* bad_message); |
121 | 133 |
122 // Returns a description of the modifications to |request| caused by the | 134 // Returns a description of the modifications to |request| caused by the |
123 // |actions_| that can be executed at |request_stage|. If |extension| | 135 // |actions_| that can be executed at |request_stage|. If |extension| |
124 // is not NULL, permissions of extensions are checked. | 136 // is not NULL, permissions of extensions are checked. |
125 std::list<LinkedPtrEventResponseDelta> CreateDeltas( | 137 std::list<LinkedPtrEventResponseDelta> CreateDeltas( |
126 const extensions::Extension* extension, | 138 const WebRequestPermissions* permissions, |
139 const ExtensionInfoMap* extension_info_map, | |
140 const std::string& extension_id, | |
127 net::URLRequest* request, | 141 net::URLRequest* request, |
142 bool crosses_incognito, | |
128 RequestStages request_stage, | 143 RequestStages request_stage, |
129 const WebRequestRule::OptionalRequestData& optional_request_data, | 144 const WebRequestRule::OptionalRequestData& optional_request_data, |
130 const std::string& extension_id, | |
131 const base::Time& extension_install_time) const; | 145 const base::Time& extension_install_time) const; |
132 | 146 |
133 // Returns the minimum priority of rules that may be evaluated after | 147 // Returns the minimum priority of rules that may be evaluated after |
134 // this rule. Defaults to MIN_INT. | 148 // this rule. Defaults to MIN_INT. |
135 int GetMinimumPriority() const; | 149 int GetMinimumPriority() const; |
136 | 150 |
137 const Actions& actions() const { return actions_; } | 151 const Actions& actions() const { return actions_; } |
138 | 152 |
139 private: | 153 private: |
140 Actions actions_; | 154 Actions actions_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 204 |
191 // Action that instructs to redirect a network request to a transparent image. | 205 // Action that instructs to redirect a network request to a transparent image. |
192 class WebRequestRedirectToTransparentImageAction : public WebRequestAction { | 206 class WebRequestRedirectToTransparentImageAction : public WebRequestAction { |
193 public: | 207 public: |
194 WebRequestRedirectToTransparentImageAction(); | 208 WebRequestRedirectToTransparentImageAction(); |
195 virtual ~WebRequestRedirectToTransparentImageAction(); | 209 virtual ~WebRequestRedirectToTransparentImageAction(); |
196 | 210 |
197 // Implementation of WebRequestAction: | 211 // Implementation of WebRequestAction: |
198 virtual int GetStages() const OVERRIDE; | 212 virtual int GetStages() const OVERRIDE; |
199 virtual Type GetType() const OVERRIDE; | 213 virtual Type GetType() const OVERRIDE; |
200 virtual bool HasPermission(const extensions::Extension* extension, | 214 virtual bool GetEnforceHostPermissions() const OVERRIDE; |
201 const net::URLRequest* request) const OVERRIDE; | |
202 virtual LinkedPtrEventResponseDelta CreateDelta( | 215 virtual LinkedPtrEventResponseDelta CreateDelta( |
203 net::URLRequest* request, | 216 net::URLRequest* request, |
204 RequestStages request_stage, | 217 RequestStages request_stage, |
205 const WebRequestRule::OptionalRequestData& optional_request_data, | 218 const WebRequestRule::OptionalRequestData& optional_request_data, |
206 const std::string& extension_id, | 219 const std::string& extension_id, |
207 const base::Time& extension_install_time) const OVERRIDE; | 220 const base::Time& extension_install_time) const OVERRIDE; |
208 | 221 |
209 private: | 222 private: |
210 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToTransparentImageAction); | 223 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToTransparentImageAction); |
211 }; | 224 }; |
212 | 225 |
213 | 226 |
214 // Action that instructs to redirect a network request to an empty document. | 227 // Action that instructs to redirect a network request to an empty document. |
215 class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction { | 228 class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction { |
216 public: | 229 public: |
217 WebRequestRedirectToEmptyDocumentAction(); | 230 WebRequestRedirectToEmptyDocumentAction(); |
218 virtual ~WebRequestRedirectToEmptyDocumentAction(); | 231 virtual ~WebRequestRedirectToEmptyDocumentAction(); |
219 | 232 |
220 // Implementation of WebRequestAction: | 233 // Implementation of WebRequestAction: |
221 virtual int GetStages() const OVERRIDE; | 234 virtual int GetStages() const OVERRIDE; |
222 virtual Type GetType() const OVERRIDE; | 235 virtual Type GetType() const OVERRIDE; |
223 virtual bool HasPermission(const extensions::Extension* extension, | 236 virtual bool GetEnforceHostPermissions() const OVERRIDE; |
224 const net::URLRequest* request) const OVERRIDE; | |
225 virtual LinkedPtrEventResponseDelta CreateDelta( | 237 virtual LinkedPtrEventResponseDelta CreateDelta( |
226 net::URLRequest* request, | 238 net::URLRequest* request, |
227 RequestStages request_stage, | 239 RequestStages request_stage, |
228 const WebRequestRule::OptionalRequestData& optional_request_data, | 240 const WebRequestRule::OptionalRequestData& optional_request_data, |
229 const std::string& extension_id, | 241 const std::string& extension_id, |
230 const base::Time& extension_install_time) const OVERRIDE; | 242 const base::Time& extension_install_time) const OVERRIDE; |
231 | 243 |
232 private: | 244 private: |
233 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); | 245 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); |
234 }; | 246 }; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 // Action that instructs to ignore rules below a certain priority. | 371 // Action that instructs to ignore rules below a certain priority. |
360 class WebRequestIgnoreRulesAction : public WebRequestAction { | 372 class WebRequestIgnoreRulesAction : public WebRequestAction { |
361 public: | 373 public: |
362 explicit WebRequestIgnoreRulesAction(int minimum_priority); | 374 explicit WebRequestIgnoreRulesAction(int minimum_priority); |
363 virtual ~WebRequestIgnoreRulesAction(); | 375 virtual ~WebRequestIgnoreRulesAction(); |
364 | 376 |
365 // Implementation of WebRequestAction: | 377 // Implementation of WebRequestAction: |
366 virtual int GetStages() const OVERRIDE; | 378 virtual int GetStages() const OVERRIDE; |
367 virtual Type GetType() const OVERRIDE; | 379 virtual Type GetType() const OVERRIDE; |
368 virtual int GetMinimumPriority() const OVERRIDE; | 380 virtual int GetMinimumPriority() const OVERRIDE; |
369 virtual bool HasPermission(const extensions::Extension* extension, | 381 virtual bool GetEnforceHostPermissions() const OVERRIDE; |
370 const net::URLRequest* request) const OVERRIDE; | |
371 virtual LinkedPtrEventResponseDelta CreateDelta( | 382 virtual LinkedPtrEventResponseDelta CreateDelta( |
372 net::URLRequest* request, | 383 net::URLRequest* request, |
373 RequestStages request_stage, | 384 RequestStages request_stage, |
374 const WebRequestRule::OptionalRequestData& optional_request_data, | 385 const WebRequestRule::OptionalRequestData& optional_request_data, |
375 const std::string& extension_id, | 386 const std::string& extension_id, |
376 const base::Time& extension_install_time) const OVERRIDE; | 387 const base::Time& extension_install_time) const OVERRIDE; |
377 | 388 |
378 private: | 389 private: |
379 int minimum_priority_; | 390 int minimum_priority_; |
380 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction); | 391 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction); |
381 }; | 392 }; |
382 | 393 |
383 // TODO(battre) Implement further actions: | 394 // TODO(battre) Implement further actions: |
384 // Redirect by RegEx, Cookie manipulations, ... | 395 // Redirect by RegEx, Cookie manipulations, ... |
385 | 396 |
386 } // namespace extensions | 397 } // namespace extensions |
387 | 398 |
388 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ | 399 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ |
OLD | NEW |