Chromium Code Reviews| 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> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 ACTION_REMOVE_RESPONSE_HEADER, | 64 ACTION_REMOVE_RESPONSE_HEADER, |
| 65 ACTION_IGNORE_RULES, | 65 ACTION_IGNORE_RULES, |
| 66 ACTION_MODIFY_REQUEST_COOKIE, | 66 ACTION_MODIFY_REQUEST_COOKIE, |
| 67 ACTION_MODIFY_RESPONSE_COOKIE, | 67 ACTION_MODIFY_RESPONSE_COOKIE, |
| 68 ACTION_SEND_MESSAGE_TO_EXTENSION, | 68 ACTION_SEND_MESSAGE_TO_EXTENSION, |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // Strategies for checking host permissions. | 71 // Strategies for checking host permissions. |
| 72 enum HostPermissionsStrategy { | 72 enum HostPermissionsStrategy { |
| 73 STRATEGY_NONE, // Do not check host permissions. | 73 STRATEGY_NONE, // Do not check host permissions. |
| 74 STRATEGY_DEFAULT, // Check host permissions in HasPermission, | 74 STRATEGY_DEFAULT, // Check for host permissions for all URLs before |
| 75 // before creating the delta. | 75 // creating the delta. |
| 76 STRATEGY_ALLOW_SAME_DOMAIN, // Skip host permission checks if the request | 76 STRATEGY_HOST, // Check that host permissions match the URL of the request. |
| 77 // URL and new URL have the same domain. | |
| 78 // Do these checks in DeltaHasPermission, | |
| 79 // after creating the delta. | |
| 80 }; | 77 }; |
| 81 | 78 |
| 82 // Information necessary to decide how to apply a WebRequestAction | 79 // Information necessary to decide how to apply a WebRequestAction |
| 83 // inside a matching rule. | 80 // inside a matching rule. |
| 84 struct ApplyInfo { | 81 struct ApplyInfo { |
| 85 const ExtensionInfoMap* extension_info_map; | 82 const ExtensionInfoMap* extension_info_map; |
| 86 const WebRequestData& request_data; | 83 const WebRequestData& request_data; |
| 87 bool crosses_incognito; | 84 bool crosses_incognito; |
| 88 // Modified by each applied action: | 85 // Modified by each applied action: |
| 89 std::list<LinkedPtrEventResponseDelta>* deltas; | 86 std::list<LinkedPtrEventResponseDelta>* deltas; |
| 90 std::set<std::string>* ignored_tags; | 87 std::set<std::string>* ignored_tags; |
| 91 }; | 88 }; |
| 92 | 89 |
| 93 WebRequestAction(); | 90 WebRequestAction(); |
|
Matt Perry
2013/04/19 21:55:28
Can the default constructor be removed?
vabr (Chromium)
2013/04/25 19:08:03
Done.
| |
| 91 explicit WebRequestAction(HostPermissionsStrategy strategy); | |
| 94 virtual ~WebRequestAction(); | 92 virtual ~WebRequestAction(); |
| 95 | 93 |
| 96 // Returns a bit vector representing extensions::RequestStage. The bit vector | 94 // Returns a bit vector representing extensions::RequestStage. The bit vector |
| 97 // contains a 1 for each request stage during which the condition can be | 95 // contains a 1 for each request stage during which the condition can be |
| 98 // tested. | 96 // tested. |
| 99 virtual int GetStages() const = 0; | 97 virtual int GetStages() const = 0; |
| 100 | 98 |
| 101 virtual Type GetType() const = 0; | 99 virtual Type GetType() const = 0; |
| 102 | 100 |
| 103 // Returns the minimum priority of rules that may be evaluated after | 101 // Returns the minimum priority of rules that may be evaluated after |
| 104 // this rule. Defaults to MIN_INT. | 102 // this rule. Defaults to MIN_INT. |
| 105 virtual int GetMinimumPriority() const; | 103 virtual int GetMinimumPriority() const; |
| 106 | 104 |
| 107 // Returns whether host permissions checks depend on the resulting delta | 105 HostPermissionsStrategy host_permissions_strategy() const { |
| 108 // and therefore must be checked in DeltaHasPermission, after the delta | 106 return host_permissions_strategy_; |
| 109 // is created, rather than in HasPermission, before it is created. | 107 } |
| 110 // Defaults to STRATEGY_DEFAULT. | |
| 111 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const; | |
| 112 | 108 |
| 113 // Returns whether the specified extension has permission to execute this | 109 // Returns whether the specified extension has permission to execute this |
| 114 // action on |request|. Checks the host permission if the host permissions | 110 // action on |request|. Checks the host permission if the host permissions |
| 115 // strategy is STRATEGY_DEFAULT. | 111 // strategy is STRATEGY_DEFAULT. |
| 116 // |extension_info_map| may only be NULL for during testing, in which case | 112 // |extension_info_map| may only be NULL for during testing, in which case |
| 117 // host permissions are ignored. |crosses_incognito| specifies | 113 // host permissions are ignored. |crosses_incognito| specifies |
| 118 // whether the request comes from a different profile than |extension_id| | 114 // whether the request comes from a different profile than |extension_id| |
| 119 // but was processed because the extension is in spanning mode. | 115 // but was processed because the extension is in spanning mode. |
| 120 virtual bool HasPermission(const ExtensionInfoMap* extension_info_map, | 116 virtual bool HasPermission(const ExtensionInfoMap* extension_info_map, |
| 121 const std::string& extension_id, | 117 const std::string& extension_id, |
| 122 const net::URLRequest* request, | 118 const net::URLRequest* request, |
| 123 bool crosses_incognito) const; | 119 bool crosses_incognito) const; |
| 124 | 120 |
| 125 // Returns whether the specified extension has permission to modify the | |
| 126 // |request| with this |delta|. This check is in addition to HasPermission; | |
| 127 // if either fails, the request will not be modified. Unlike HasPermission, | |
| 128 // it runs after the change is created, so it can use the full information | |
| 129 // about what the change would be. Checks the host permission if the strategy | |
| 130 // is STRATEGY_ALLOW_SAME_DOMAIN. | |
| 131 virtual bool DeltaHasPermission( | |
| 132 const ExtensionInfoMap* extension_info_map, | |
| 133 const std::string& extension_id, | |
| 134 const net::URLRequest* request, | |
| 135 bool crosses_incognito, | |
| 136 const LinkedPtrEventResponseDelta& delta) const; | |
| 137 | |
| 138 // Factory method that instantiates a concrete WebRequestAction | 121 // Factory method that instantiates a concrete WebRequestAction |
| 139 // implementation according to |json_action|, the representation of the | 122 // implementation according to |json_action|, the representation of the |
| 140 // WebRequestAction as received from the extension API. | 123 // WebRequestAction as received from the extension API. |
| 141 // Sets |error| and returns NULL in case of a semantic error that cannot | 124 // Sets |error| and returns NULL in case of a semantic error that cannot |
| 142 // be caught by schema validation. Sets |bad_message| and returns NULL | 125 // be caught by schema validation. Sets |bad_message| and returns NULL |
| 143 // in case the input is syntactically unexpected. | 126 // in case the input is syntactically unexpected. |
| 144 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, | 127 static scoped_ptr<WebRequestAction> Create(const base::Value& json_action, |
| 145 std::string* error, | 128 std::string* error, |
| 146 bool* bad_message); | 129 bool* bad_message); |
| 147 | 130 |
| 148 // Returns a description of the modification to the request caused by | 131 // Returns a description of the modification to the request caused by |
| 149 // this action. | 132 // this action. |
| 150 virtual LinkedPtrEventResponseDelta CreateDelta( | 133 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 151 const WebRequestData& request_data, | 134 const WebRequestData& request_data, |
| 152 const std::string& extension_id, | 135 const std::string& extension_id, |
| 153 const base::Time& extension_install_time) const = 0; | 136 const base::Time& extension_install_time) const = 0; |
| 154 | 137 |
| 155 // Applies this action to a request, recording the results into | 138 // Applies this action to a request, recording the results into |
| 156 // apply_info.deltas. | 139 // apply_info.deltas. |
| 157 void Apply(const std::string& extension_id, | 140 void Apply(const std::string& extension_id, |
| 158 base::Time extension_install_time, | 141 base::Time extension_install_time, |
| 159 ApplyInfo* apply_info) const; | 142 ApplyInfo* apply_info) const; |
| 143 | |
| 144 private: | |
| 145 // Defaults to STRATEGY_DEFAULT. | |
| 146 const HostPermissionsStrategy host_permissions_strategy_; | |
| 160 }; | 147 }; |
| 161 | 148 |
| 162 typedef DeclarativeActionSet<WebRequestAction> WebRequestActionSet; | 149 typedef DeclarativeActionSet<WebRequestAction> WebRequestActionSet; |
| 163 | 150 |
| 164 // | 151 // |
| 165 // The following are concrete actions. | 152 // The following are concrete actions. |
| 166 // | 153 // |
| 167 | 154 |
| 168 // Action that instructs to cancel a network request. | 155 // Action that instructs to cancel a network request. |
| 169 class WebRequestCancelAction : public WebRequestAction { | 156 class WebRequestCancelAction : public WebRequestAction { |
| 170 public: | 157 public: |
| 171 WebRequestCancelAction(); | 158 WebRequestCancelAction(); |
| 172 virtual ~WebRequestCancelAction(); | 159 virtual ~WebRequestCancelAction(); |
| 173 | 160 |
| 174 // Implementation of WebRequestAction: | 161 // Implementation of WebRequestAction: |
| 175 virtual int GetStages() const OVERRIDE; | 162 virtual int GetStages() const OVERRIDE; |
| 176 virtual Type GetType() const OVERRIDE; | 163 virtual Type GetType() const OVERRIDE; |
| 177 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const OVERRIDE; | |
| 178 virtual LinkedPtrEventResponseDelta CreateDelta( | 164 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 179 const WebRequestData& request_data, | 165 const WebRequestData& request_data, |
| 180 const std::string& extension_id, | 166 const std::string& extension_id, |
| 181 const base::Time& extension_install_time) const OVERRIDE; | 167 const base::Time& extension_install_time) const OVERRIDE; |
| 182 | 168 |
| 183 private: | 169 private: |
| 184 DISALLOW_COPY_AND_ASSIGN(WebRequestCancelAction); | 170 DISALLOW_COPY_AND_ASSIGN(WebRequestCancelAction); |
| 185 }; | 171 }; |
| 186 | 172 |
| 187 // Action that instructs to redirect a network request. | 173 // Action that instructs to redirect a network request. |
| 188 class WebRequestRedirectAction : public WebRequestAction { | 174 class WebRequestRedirectAction : public WebRequestAction { |
| 189 public: | 175 public: |
| 190 explicit WebRequestRedirectAction(const GURL& redirect_url); | 176 explicit WebRequestRedirectAction(const GURL& redirect_url); |
| 191 virtual ~WebRequestRedirectAction(); | 177 virtual ~WebRequestRedirectAction(); |
| 192 | 178 |
| 193 // Implementation of WebRequestAction: | 179 // Implementation of WebRequestAction: |
| 194 virtual int GetStages() const OVERRIDE; | 180 virtual int GetStages() const OVERRIDE; |
| 195 virtual Type GetType() const OVERRIDE; | 181 virtual Type GetType() const OVERRIDE; |
| 196 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const OVERRIDE; | |
| 197 virtual LinkedPtrEventResponseDelta CreateDelta( | 182 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 198 const WebRequestData& request_data, | 183 const WebRequestData& request_data, |
| 199 const std::string& extension_id, | 184 const std::string& extension_id, |
| 200 const base::Time& extension_install_time) const OVERRIDE; | 185 const base::Time& extension_install_time) const OVERRIDE; |
| 201 | 186 |
| 202 private: | 187 private: |
| 203 GURL redirect_url_; // Target to which the request shall be redirected. | 188 GURL redirect_url_; // Target to which the request shall be redirected. |
| 204 | 189 |
| 205 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectAction); | 190 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectAction); |
| 206 }; | 191 }; |
| 207 | 192 |
| 208 // Action that instructs to redirect a network request to a transparent image. | 193 // Action that instructs to redirect a network request to a transparent image. |
| 209 class WebRequestRedirectToTransparentImageAction : public WebRequestAction { | 194 class WebRequestRedirectToTransparentImageAction : public WebRequestAction { |
| 210 public: | 195 public: |
| 211 WebRequestRedirectToTransparentImageAction(); | 196 WebRequestRedirectToTransparentImageAction(); |
| 212 virtual ~WebRequestRedirectToTransparentImageAction(); | 197 virtual ~WebRequestRedirectToTransparentImageAction(); |
| 213 | 198 |
| 214 // Implementation of WebRequestAction: | 199 // Implementation of WebRequestAction: |
| 215 virtual int GetStages() const OVERRIDE; | 200 virtual int GetStages() const OVERRIDE; |
| 216 virtual Type GetType() const OVERRIDE; | 201 virtual Type GetType() const OVERRIDE; |
| 217 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const OVERRIDE; | |
| 218 virtual LinkedPtrEventResponseDelta CreateDelta( | 202 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 219 const WebRequestData& request_data, | 203 const WebRequestData& request_data, |
| 220 const std::string& extension_id, | 204 const std::string& extension_id, |
| 221 const base::Time& extension_install_time) const OVERRIDE; | 205 const base::Time& extension_install_time) const OVERRIDE; |
| 222 | 206 |
| 223 private: | 207 private: |
| 224 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToTransparentImageAction); | 208 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToTransparentImageAction); |
| 225 }; | 209 }; |
| 226 | 210 |
| 227 | 211 |
| 228 // Action that instructs to redirect a network request to an empty document. | 212 // Action that instructs to redirect a network request to an empty document. |
| 229 class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction { | 213 class WebRequestRedirectToEmptyDocumentAction : public WebRequestAction { |
| 230 public: | 214 public: |
| 231 WebRequestRedirectToEmptyDocumentAction(); | 215 WebRequestRedirectToEmptyDocumentAction(); |
| 232 virtual ~WebRequestRedirectToEmptyDocumentAction(); | 216 virtual ~WebRequestRedirectToEmptyDocumentAction(); |
| 233 | 217 |
| 234 // Implementation of WebRequestAction: | 218 // Implementation of WebRequestAction: |
| 235 virtual int GetStages() const OVERRIDE; | 219 virtual int GetStages() const OVERRIDE; |
| 236 virtual Type GetType() const OVERRIDE; | 220 virtual Type GetType() const OVERRIDE; |
| 237 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const OVERRIDE; | |
| 238 virtual LinkedPtrEventResponseDelta CreateDelta( | 221 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 239 const WebRequestData& request_data, | 222 const WebRequestData& request_data, |
| 240 const std::string& extension_id, | 223 const std::string& extension_id, |
| 241 const base::Time& extension_install_time) const OVERRIDE; | 224 const base::Time& extension_install_time) const OVERRIDE; |
| 242 | 225 |
| 243 private: | 226 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); | 227 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectToEmptyDocumentAction); |
| 245 }; | 228 }; |
| 246 | 229 |
| 247 // Action that instructs to redirect a network request. | 230 // Action that instructs to redirect a network request. |
| 248 class WebRequestRedirectByRegExAction : public WebRequestAction { | 231 class WebRequestRedirectByRegExAction : public WebRequestAction { |
| 249 public: | 232 public: |
| 250 // The |to_pattern| has to be passed in RE2 syntax with the exception that | 233 // The |to_pattern| has to be passed in RE2 syntax with the exception that |
| 251 // capture groups are referenced in Perl style ($1, $2, ...). | 234 // capture groups are referenced in Perl style ($1, $2, ...). |
| 252 explicit WebRequestRedirectByRegExAction(scoped_ptr<re2::RE2> from_pattern, | 235 explicit WebRequestRedirectByRegExAction(scoped_ptr<re2::RE2> from_pattern, |
| 253 const std::string& to_pattern); | 236 const std::string& to_pattern); |
| 254 virtual ~WebRequestRedirectByRegExAction(); | 237 virtual ~WebRequestRedirectByRegExAction(); |
| 255 | 238 |
| 256 // Conversion of capture group styles between Perl style ($1, $2, ...) and | 239 // Conversion of capture group styles between Perl style ($1, $2, ...) and |
| 257 // RE2 (\1, \2, ...). | 240 // RE2 (\1, \2, ...). |
| 258 static std::string PerlToRe2Style(const std::string& perl); | 241 static std::string PerlToRe2Style(const std::string& perl); |
| 259 | 242 |
| 260 // Implementation of WebRequestAction: | 243 // Implementation of WebRequestAction: |
| 261 virtual int GetStages() const OVERRIDE; | 244 virtual int GetStages() const OVERRIDE; |
| 262 virtual Type GetType() const OVERRIDE; | 245 virtual Type GetType() const OVERRIDE; |
| 263 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const OVERRIDE; | |
| 264 virtual LinkedPtrEventResponseDelta CreateDelta( | 246 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 265 const WebRequestData& request_data, | 247 const WebRequestData& request_data, |
| 266 const std::string& extension_id, | 248 const std::string& extension_id, |
| 267 const base::Time& extension_install_time) const OVERRIDE; | 249 const base::Time& extension_install_time) const OVERRIDE; |
| 268 | 250 |
| 269 private: | 251 private: |
| 270 scoped_ptr<re2::RE2> from_pattern_; | 252 scoped_ptr<re2::RE2> from_pattern_; |
| 271 std::string to_pattern_; | 253 std::string to_pattern_; |
| 272 | 254 |
| 273 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectByRegExAction); | 255 DISALLOW_COPY_AND_ASSIGN(WebRequestRedirectByRegExAction); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 class WebRequestIgnoreRulesAction : public WebRequestAction { | 343 class WebRequestIgnoreRulesAction : public WebRequestAction { |
| 362 public: | 344 public: |
| 363 explicit WebRequestIgnoreRulesAction(int minimum_priority, | 345 explicit WebRequestIgnoreRulesAction(int minimum_priority, |
| 364 const std::string& ignore_tag); | 346 const std::string& ignore_tag); |
| 365 virtual ~WebRequestIgnoreRulesAction(); | 347 virtual ~WebRequestIgnoreRulesAction(); |
| 366 | 348 |
| 367 // Implementation of WebRequestAction: | 349 // Implementation of WebRequestAction: |
| 368 virtual int GetStages() const OVERRIDE; | 350 virtual int GetStages() const OVERRIDE; |
| 369 virtual Type GetType() const OVERRIDE; | 351 virtual Type GetType() const OVERRIDE; |
| 370 virtual int GetMinimumPriority() const OVERRIDE; | 352 virtual int GetMinimumPriority() const OVERRIDE; |
| 371 virtual HostPermissionsStrategy GetHostPermissionsStrategy() const OVERRIDE; | |
| 372 virtual LinkedPtrEventResponseDelta CreateDelta( | 353 virtual LinkedPtrEventResponseDelta CreateDelta( |
| 373 const WebRequestData& request_data, | 354 const WebRequestData& request_data, |
| 374 const std::string& extension_id, | 355 const std::string& extension_id, |
| 375 const base::Time& extension_install_time) const OVERRIDE; | 356 const base::Time& extension_install_time) const OVERRIDE; |
| 376 const std::string& ignore_tag() const { return ignore_tag_; } | 357 const std::string& ignore_tag() const { return ignore_tag_; } |
| 377 | 358 |
| 378 private: | 359 private: |
| 379 int minimum_priority_; | 360 int minimum_priority_; |
| 380 // Rules are ignored if they have a tag matching |ignore_tag_| and | 361 // Rules are ignored if they have a tag matching |ignore_tag_| and |
| 381 // |ignore_tag_| is non-empty. | 362 // |ignore_tag_| is non-empty. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 const base::Time& extension_install_time) const OVERRIDE; | 426 const base::Time& extension_install_time) const OVERRIDE; |
| 446 | 427 |
| 447 private: | 428 private: |
| 448 std::string message_; | 429 std::string message_; |
| 449 DISALLOW_COPY_AND_ASSIGN(WebRequestSendMessageToExtensionAction); | 430 DISALLOW_COPY_AND_ASSIGN(WebRequestSendMessageToExtensionAction); |
| 450 }; | 431 }; |
| 451 | 432 |
| 452 } // namespace extensions | 433 } // namespace extensions |
| 453 | 434 |
| 454 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ | 435 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_ACTIO N_H_ |
| OLD | NEW |