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 // ShouldEnforceHostPermissions instructs to do that. |
78 // host permissions are ignored. | 80 // |extension_info_map| may only be NULL for during testing, in which case |
79 virtual bool HasPermission(const extensions::Extension* extension, | 81 // 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 ExtensionInfoMap* extension_info_map, |
| 85 const std::string& extension_id, |
| 86 const net::URLRequest* request, |
| 87 bool crosses_incognito) const; |
| 88 |
| 89 // Returns whether host permissions shall be enforced by this actions. |
| 90 // Used by the standard implementation of HasPermission. Defaults to true. |
| 91 virtual bool ShouldEnforceHostPermissions() const; |
81 | 92 |
82 // Factory method that instantiates a concrete WebRequestAction | 93 // Factory method that instantiates a concrete WebRequestAction |
83 // implementation according to |json_action|, the representation of the | 94 // implementation according to |json_action|, the representation of the |
84 // WebRequestAction as received from the extension API. | 95 // WebRequestAction as received from the extension API. |
85 // Sets |error| and returns NULL in case of a semantic error that cannot | 96 // 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 | 97 // be caught by schema validation. Sets |bad_message| and returns NULL |
87 // in case the input is syntactically unexpected. | 98 // in case the input is syntactically unexpected. |
88 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, | 99 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, |
89 std::string* error, | 100 std::string* error, |
90 bool* bad_message); | 101 bool* bad_message); |
(...skipping 25 matching lines...) Expand all Loading... |
116 // |actions| which represents the array of actions received from the | 127 // |actions| which represents the array of actions received from the |
117 // extension API. | 128 // extension API. |
118 static scoped_ptr<WebRequestActionSet> Create(const AnyVector& actions, | 129 static scoped_ptr<WebRequestActionSet> Create(const AnyVector& actions, |
119 std::string* error, | 130 std::string* error, |
120 bool* bad_message); | 131 bool* bad_message); |
121 | 132 |
122 // Returns a description of the modifications to |request| caused by the | 133 // Returns a description of the modifications to |request| caused by the |
123 // |actions_| that can be executed at |request_stage|. If |extension| | 134 // |actions_| that can be executed at |request_stage|. If |extension| |
124 // is not NULL, permissions of extensions are checked. | 135 // is not NULL, permissions of extensions are checked. |
125 std::list<LinkedPtrEventResponseDelta> CreateDeltas( | 136 std::list<LinkedPtrEventResponseDelta> CreateDeltas( |
126 const extensions::Extension* extension, | 137 const ExtensionInfoMap* extension_info_map, |
| 138 const std::string& extension_id, |
127 net::URLRequest* request, | 139 net::URLRequest* request, |
| 140 bool crosses_incognito, |
128 RequestStages request_stage, | 141 RequestStages request_stage, |
129 const WebRequestRule::OptionalRequestData& optional_request_data, | 142 const WebRequestRule::OptionalRequestData& optional_request_data, |
130 const std::string& extension_id, | |
131 const base::Time& extension_install_time) const; | 143 const base::Time& extension_install_time) const; |
132 | 144 |
133 // Returns the minimum priority of rules that may be evaluated after | 145 // Returns the minimum priority of rules that may be evaluated after |
134 // this rule. Defaults to MIN_INT. | 146 // this rule. Defaults to MIN_INT. |
135 int GetMinimumPriority() const; | 147 int GetMinimumPriority() const; |
136 | 148 |
137 const Actions& actions() const { return actions_; } | 149 const Actions& actions() const { return actions_; } |
138 | 150 |
139 private: | 151 private: |
140 Actions actions_; | 152 Actions actions_; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 202 |
191 // Action that instructs to redirect a network request to a transparent image. | 203 // Action that instructs to redirect a network request to a transparent image. |
192 class WebRequestRedirectToTransparentImageAction : public WebRequestAction { | 204 class WebRequestRedirectToTransparentImageAction : public WebRequestAction { |
193 public: | 205 public: |
194 WebRequestRedirectToTransparentImageAction(); | 206 WebRequestRedirectToTransparentImageAction(); |
195 virtual ~WebRequestRedirectToTransparentImageAction(); | 207 virtual ~WebRequestRedirectToTransparentImageAction(); |
196 | 208 |
197 // Implementation of WebRequestAction: | 209 // Implementation of WebRequestAction: |
198 virtual int GetStages() const OVERRIDE; | 210 virtual int GetStages() const OVERRIDE; |
199 virtual Type GetType() const OVERRIDE; | 211 virtual Type GetType() const OVERRIDE; |
200 virtual bool HasPermission(const extensions::Extension* extension, | 212 virtual bool ShouldEnforceHostPermissions() const OVERRIDE; |
201 const net::URLRequest* request) const OVERRIDE; | |
202 virtual LinkedPtrEventResponseDelta CreateDelta( | 213 virtual LinkedPtrEventResponseDelta CreateDelta( |
203 net::URLRequest* request, | 214 net::URLRequest* request, |
204 RequestStages request_stage, | 215 RequestStages request_stage, |
205 const WebRequestRule::OptionalRequestData& optional_request_data, | 216 const WebRequestRule::OptionalRequestData& optional_request_data, |
206 const std::string& extension_id, | 217 const std::string& extension_id, |
207 const base::Time& extension_install_time) const OVERRIDE; | 218 const base::Time& extension_install_time) const OVERRIDE; |
208 | 219 |
209 private: | 220 private: |
210 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToTransparentImageAction); | 221 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToTransparentImageAction); |
211 }; | 222 }; |
212 | 223 |
213 | 224 |
214 // Action that instructs to redirect a network request to an empty document. | 225 // Action that instructs to redirect a network request to an empty document. |
215 class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction { | 226 class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction { |
216 public: | 227 public: |
217 WebRequestRedirectToEmptyDocumentAction(); | 228 WebRequestRedirectToEmptyDocumentAction(); |
218 virtual ~WebRequestRedirectToEmptyDocumentAction(); | 229 virtual ~WebRequestRedirectToEmptyDocumentAction(); |
219 | 230 |
220 // Implementation of WebRequestAction: | 231 // Implementation of WebRequestAction: |
221 virtual int GetStages() const OVERRIDE; | 232 virtual int GetStages() const OVERRIDE; |
222 virtual Type GetType() const OVERRIDE; | 233 virtual Type GetType() const OVERRIDE; |
223 virtual bool HasPermission(const extensions::Extension* extension, | 234 virtual bool ShouldEnforceHostPermissions() const OVERRIDE; |
224 const net::URLRequest* request) const OVERRIDE; | |
225 virtual LinkedPtrEventResponseDelta CreateDelta( | 235 virtual LinkedPtrEventResponseDelta CreateDelta( |
226 net::URLRequest* request, | 236 net::URLRequest* request, |
227 RequestStages request_stage, | 237 RequestStages request_stage, |
228 const WebRequestRule::OptionalRequestData& optional_request_data, | 238 const WebRequestRule::OptionalRequestData& optional_request_data, |
229 const std::string& extension_id, | 239 const std::string& extension_id, |
230 const base::Time& extension_install_time) const OVERRIDE; | 240 const base::Time& extension_install_time) const OVERRIDE; |
231 | 241 |
232 private: | 242 private: |
233 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); | 243 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); |
234 }; | 244 }; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 // Action that instructs to ignore rules below a certain priority. | 369 // Action that instructs to ignore rules below a certain priority. |
360 class WebRequestIgnoreRulesAction : public WebRequestAction { | 370 class WebRequestIgnoreRulesAction : public WebRequestAction { |
361 public: | 371 public: |
362 explicit WebRequestIgnoreRulesAction(int minimum_priority); | 372 explicit WebRequestIgnoreRulesAction(int minimum_priority); |
363 virtual ~WebRequestIgnoreRulesAction(); | 373 virtual ~WebRequestIgnoreRulesAction(); |
364 | 374 |
365 // Implementation of WebRequestAction: | 375 // Implementation of WebRequestAction: |
366 virtual int GetStages() const OVERRIDE; | 376 virtual int GetStages() const OVERRIDE; |
367 virtual Type GetType() const OVERRIDE; | 377 virtual Type GetType() const OVERRIDE; |
368 virtual int GetMinimumPriority() const OVERRIDE; | 378 virtual int GetMinimumPriority() const OVERRIDE; |
369 virtual bool HasPermission(const extensions::Extension* extension, | 379 virtual bool ShouldEnforceHostPermissions() const OVERRIDE; |
370 const net::URLRequest* request) const OVERRIDE; | |
371 virtual LinkedPtrEventResponseDelta CreateDelta( | 380 virtual LinkedPtrEventResponseDelta CreateDelta( |
372 net::URLRequest* request, | 381 net::URLRequest* request, |
373 RequestStages request_stage, | 382 RequestStages request_stage, |
374 const WebRequestRule::OptionalRequestData& optional_request_data, | 383 const WebRequestRule::OptionalRequestData& optional_request_data, |
375 const std::string& extension_id, | 384 const std::string& extension_id, |
376 const base::Time& extension_install_time) const OVERRIDE; | 385 const base::Time& extension_install_time) const OVERRIDE; |
377 | 386 |
378 private: | 387 private: |
379 int minimum_priority_; | 388 int minimum_priority_; |
380 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction); | 389 DISALLOW_COPY_AND_ASSIGN(WebRequestIgnoreRulesAction); |
381 }; | 390 }; |
382 | 391 |
383 // TODO(battre) Implement further actions: | 392 // TODO(battre) Implement further actions: |
384 // Redirect by RegEx, Cookie manipulations, ... | 393 // Redirect by RegEx, Cookie manipulations, ... |
385 | 394 |
386 } // namespace extensions | 395 } // namespace extensions |
387 | 396 |
388 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO
N_H_ | 397 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO
N_H_ |
OLD | NEW |