| 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_WEB_REQUEST_WEB_REQUEST_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 kOnBeforeRedirect = 1 << 4, | 67 kOnBeforeRedirect = 1 << 4, |
| 68 kOnAuthRequired = 1 << 5, | 68 kOnAuthRequired = 1 << 5, |
| 69 kOnResponseStarted = 1 << 6, | 69 kOnResponseStarted = 1 << 6, |
| 70 kOnErrorOccurred = 1 << 7, | 70 kOnErrorOccurred = 1 << 7, |
| 71 kOnCompleted = 1 << 8, | 71 kOnCompleted = 1 << 8, |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Internal representation of the webRequest.RequestFilter type, used to | 74 // Internal representation of the webRequest.RequestFilter type, used to |
| 75 // filter what network events an extension cares about. | 75 // filter what network events an extension cares about. |
| 76 struct RequestFilter { | 76 struct RequestFilter { |
| 77 URLPatternSet urls; | |
| 78 std::vector<ResourceType::Type> types; | |
| 79 int tab_id; | |
| 80 int window_id; | |
| 81 | |
| 82 RequestFilter(); | 77 RequestFilter(); |
| 83 ~RequestFilter(); | 78 ~RequestFilter(); |
| 84 | 79 |
| 85 // Returns false if there was an error initializing. If it is a user error, | 80 // Returns false if there was an error initializing. If it is a user error, |
| 86 // an error message is provided, otherwise the error is internal (and | 81 // an error message is provided, otherwise the error is internal (and |
| 87 // unexpected). | 82 // unexpected). |
| 88 bool InitFromValue(const base::DictionaryValue& value, std::string* error); | 83 bool InitFromValue(const base::DictionaryValue& value, std::string* error); |
| 84 |
| 85 URLPatternSet urls; |
| 86 std::vector<ResourceType::Type> types; |
| 87 int tab_id; |
| 88 int window_id; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 // Internal representation of the extraInfoSpec parameter on webRequest | 91 // Internal representation of the extraInfoSpec parameter on webRequest |
| 92 // events, used to specify extra information to be included with network | 92 // events, used to specify extra information to be included with network |
| 93 // events. | 93 // events. |
| 94 struct ExtraInfoSpec { | 94 struct ExtraInfoSpec { |
| 95 enum Flags { | 95 enum Flags { |
| 96 REQUEST_HEADERS = 1<<0, | 96 REQUEST_HEADERS = 1<<0, |
| 97 RESPONSE_HEADERS = 1<<1, | 97 RESPONSE_HEADERS = 1<<1, |
| 98 BLOCKING = 1<<2, | 98 BLOCKING = 1<<2, |
| 99 ASYNC_BLOCKING = 1<<3, | 99 ASYNC_BLOCKING = 1<<3, |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 static bool InitFromValue(const base::ListValue& value, | 102 static bool InitFromValue(const base::ListValue& value, |
| 103 int* extra_info_spec); | 103 int* extra_info_spec); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Contains an extension's response to a blocking event. | 106 // Contains an extension's response to a blocking event. |
| 107 struct EventResponse { | 107 struct EventResponse { |
| 108 EventResponse(const std::string& extension_id, |
| 109 const base::Time& extension_install_time); |
| 110 ~EventResponse(); |
| 111 |
| 108 // ID of the extension that sent this response. | 112 // ID of the extension that sent this response. |
| 109 std::string extension_id; | 113 std::string extension_id; |
| 110 | 114 |
| 111 // The time that the extension was installed. Used for deciding order of | 115 // The time that the extension was installed. Used for deciding order of |
| 112 // precedence in case multiple extensions respond with conflicting | 116 // precedence in case multiple extensions respond with conflicting |
| 113 // decisions. | 117 // decisions. |
| 114 base::Time extension_install_time; | 118 base::Time extension_install_time; |
| 115 | 119 |
| 116 // Response values. These are mutually exclusive. | 120 // Response values. These are mutually exclusive. |
| 117 bool cancel; | 121 bool cancel; |
| 118 GURL new_url; | 122 GURL new_url; |
| 119 scoped_ptr<net::HttpRequestHeaders> request_headers; | 123 scoped_ptr<net::HttpRequestHeaders> request_headers; |
| 120 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders> | 124 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders> |
| 121 response_headers; | 125 response_headers; |
| 122 | 126 |
| 123 scoped_ptr<net::AuthCredentials> auth_credentials; | 127 scoped_ptr<net::AuthCredentials> auth_credentials; |
| 124 | 128 |
| 125 EventResponse(const std::string& extension_id, | |
| 126 const base::Time& extension_install_time); | |
| 127 ~EventResponse(); | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(EventResponse); | 129 DISALLOW_COPY_AND_ASSIGN(EventResponse); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 static ExtensionWebRequestEventRouter* GetInstance(); | 132 static ExtensionWebRequestEventRouter* GetInstance(); |
| 133 | 133 |
| 134 void RegisterRulesRegistry( | 134 void RegisterRulesRegistry( |
| 135 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); | 135 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); |
| 136 | 136 |
| 137 // Dispatches the OnBeforeRequest event to any extensions whose filters match | 137 // Dispatches the OnBeforeRequest event to any extensions whose filters match |
| 138 // the given request. Returns net::ERR_IO_PENDING if an extension is | 138 // the given request. Returns net::ERR_IO_PENDING if an extension is |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 void* otr_profile); | 251 void* otr_profile); |
| 252 void OnOTRProfileDestroyed(void* original_profile, | 252 void OnOTRProfileDestroyed(void* original_profile, |
| 253 void* otr_profile); | 253 void* otr_profile); |
| 254 | 254 |
| 255 // Registers a |callback| that is executed when the next page load happens. | 255 // Registers a |callback| that is executed when the next page load happens. |
| 256 // The callback is then deleted. | 256 // The callback is then deleted. |
| 257 void AddCallbackForPageLoad(const base::Closure& callback); | 257 void AddCallbackForPageLoad(const base::Closure& callback); |
| 258 | 258 |
| 259 private: | 259 private: |
| 260 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; | 260 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; |
| 261 |
| 261 struct EventListener; | 262 struct EventListener; |
| 262 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; | 263 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; |
| 263 typedef std::map<void*, ListenerMapForProfile> ListenerMap; | 264 typedef std::map<void*, ListenerMapForProfile> ListenerMap; |
| 264 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; | 265 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; |
| 265 // Map of request_id -> bit vector of EventTypes already signaled | 266 // Map of request_id -> bit vector of EventTypes already signaled |
| 266 typedef std::map<uint64, int> SignaledRequestMap; | 267 typedef std::map<uint64, int> SignaledRequestMap; |
| 267 typedef std::map<void*, void*> CrossProfileMap; | 268 typedef std::map<void*, void*> CrossProfileMap; |
| 268 typedef std::list<base::Closure> CallbacksForPageLoad; | 269 typedef std::list<base::Closure> CallbacksForPageLoad; |
| 269 | 270 |
| 270 ExtensionWebRequestEventRouter(); | 271 ExtensionWebRequestEventRouter(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 370 |
| 370 CallbacksForPageLoad callbacks_for_page_load_; | 371 CallbacksForPageLoad callbacks_for_page_load_; |
| 371 | 372 |
| 372 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry_; | 373 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry_; |
| 373 | 374 |
| 374 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); | 375 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); |
| 375 }; | 376 }; |
| 376 | 377 |
| 377 class WebRequestAddEventListener : public SyncIOThreadExtensionFunction { | 378 class WebRequestAddEventListener : public SyncIOThreadExtensionFunction { |
| 378 public: | 379 public: |
| 380 DECLARE_EXTENSION_FUNCTION_NAME("webRequest.addEventListener"); |
| 381 |
| 382 protected: |
| 383 virtual ~WebRequestAddEventListener() {} |
| 384 |
| 385 // ExtensionFunction: |
| 379 virtual bool RunImpl() OVERRIDE; | 386 virtual bool RunImpl() OVERRIDE; |
| 380 DECLARE_EXTENSION_FUNCTION_NAME("webRequest.addEventListener"); | |
| 381 }; | 387 }; |
| 382 | 388 |
| 383 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { | 389 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { |
| 384 public: | 390 public: |
| 391 DECLARE_EXTENSION_FUNCTION_NAME("webRequest.eventHandled"); |
| 392 |
| 393 protected: |
| 394 virtual ~WebRequestEventHandled() {} |
| 395 |
| 396 // ExtensionFunction: |
| 385 virtual bool RunImpl() OVERRIDE; | 397 virtual bool RunImpl() OVERRIDE; |
| 386 DECLARE_EXTENSION_FUNCTION_NAME("webRequest.eventHandled"); | |
| 387 }; | 398 }; |
| 388 | 399 |
| 389 class WebRequestHandlerBehaviorChanged : public SyncIOThreadExtensionFunction { | 400 class WebRequestHandlerBehaviorChanged : public SyncIOThreadExtensionFunction { |
| 390 public: | 401 public: |
| 391 virtual bool RunImpl() OVERRIDE; | 402 DECLARE_EXTENSION_FUNCTION_NAME("webRequest.handlerBehaviorChanged"); |
| 392 DECLARE_EXTENSION_FUNCTION_NAME( | |
| 393 "webRequest.handlerBehaviorChanged"); | |
| 394 | 403 |
| 395 private: | 404 protected: |
| 405 virtual ~WebRequestHandlerBehaviorChanged() {} |
| 406 |
| 407 // ExtensionFunction: |
| 396 virtual void GetQuotaLimitHeuristics( | 408 virtual void GetQuotaLimitHeuristics( |
| 397 QuotaLimitHeuristics* heuristics) const OVERRIDE; | 409 QuotaLimitHeuristics* heuristics) const OVERRIDE; |
| 398 // Handle quota exceeded gracefully: Only warn the user but still execute the | 410 // Handle quota exceeded gracefully: Only warn the user but still execute the |
| 399 // function. | 411 // function. |
| 400 virtual void OnQuotaExceeded() OVERRIDE; | 412 virtual void OnQuotaExceeded() OVERRIDE; |
| 413 virtual bool RunImpl() OVERRIDE; |
| 401 }; | 414 }; |
| 402 | 415 |
| 403 // Send updates to |host| with information about what webRequest-related | 416 // Send updates to |host| with information about what webRequest-related |
| 404 // extensions are installed. | 417 // extensions are installed. |
| 405 // TODO(mpcomplete): remove. http://crbug.com/100411 | 418 // TODO(mpcomplete): remove. http://crbug.com/100411 |
| 406 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); | 419 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); |
| 407 | 420 |
| 408 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ | 421 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ |
| OLD | NEW |