| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_WEBREQUEST_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Used in testing to allow chrome-extension URLs to be intercepted. | 106 // Used in testing to allow chrome-extension URLs to be intercepted. |
| 107 static void SetAllowChromeExtensionScheme(); | 107 static void SetAllowChromeExtensionScheme(); |
| 108 | 108 |
| 109 static ExtensionWebRequestEventRouter* GetInstance(); | 109 static ExtensionWebRequestEventRouter* GetInstance(); |
| 110 | 110 |
| 111 // Dispatches the OnBeforeRequest event to any extensions whose filters match | 111 // Dispatches the OnBeforeRequest event to any extensions whose filters match |
| 112 // the given request. Returns net::ERR_IO_PENDING if an extension is | 112 // the given request. Returns net::ERR_IO_PENDING if an extension is |
| 113 // intercepting the request, OK otherwise. | 113 // intercepting the request, OK otherwise. |
| 114 int OnBeforeRequest(ProfileId profile_id, | 114 int OnBeforeRequest(void* profile, |
| 115 ExtensionInfoMap* extension_info_map, | 115 ExtensionInfoMap* extension_info_map, |
| 116 net::URLRequest* request, | 116 net::URLRequest* request, |
| 117 net::CompletionCallback* callback, | 117 net::CompletionCallback* callback, |
| 118 GURL* new_url); | 118 GURL* new_url); |
| 119 | 119 |
| 120 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) | 120 // Dispatches the onBeforeSendHeaders event. This is fired for HTTP(s) |
| 121 // requests only, and allows modification of the outgoing request headers. | 121 // requests only, and allows modification of the outgoing request headers. |
| 122 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK | 122 // Returns net::ERR_IO_PENDING if an extension is intercepting the request, OK |
| 123 // otherwise. | 123 // otherwise. |
| 124 int OnBeforeSendHeaders(ProfileId profile_id, | 124 int OnBeforeSendHeaders(void* profile, |
| 125 ExtensionInfoMap* extension_info_map, | 125 ExtensionInfoMap* extension_info_map, |
| 126 net::URLRequest* request, | 126 net::URLRequest* request, |
| 127 net::CompletionCallback* callback, | 127 net::CompletionCallback* callback, |
| 128 net::HttpRequestHeaders* headers); | 128 net::HttpRequestHeaders* headers); |
| 129 | 129 |
| 130 // Dispatches the onRequestSent event. This is fired for HTTP(s) requests | 130 // Dispatches the onRequestSent event. This is fired for HTTP(s) requests |
| 131 // only. | 131 // only. |
| 132 void OnRequestSent(ProfileId profile_id, | 132 void OnRequestSent(void* profile, |
| 133 ExtensionInfoMap* extension_info_map, | 133 ExtensionInfoMap* extension_info_map, |
| 134 uint64 request_id, | 134 uint64 request_id, |
| 135 const net::HostPortPair& socket_address, | 135 const net::HostPortPair& socket_address, |
| 136 const net::HttpRequestHeaders& headers); | 136 const net::HttpRequestHeaders& headers); |
| 137 | 137 |
| 138 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests | 138 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests |
| 139 // only. | 139 // only. |
| 140 void OnBeforeRedirect(ProfileId profile_id, | 140 void OnBeforeRedirect(void* profile, |
| 141 ExtensionInfoMap* extension_info_map, | 141 ExtensionInfoMap* extension_info_map, |
| 142 net::URLRequest* request, | 142 net::URLRequest* request, |
| 143 const GURL& new_location); | 143 const GURL& new_location); |
| 144 | 144 |
| 145 // Dispatches the onResponseStarted event indicating that the first bytes of | 145 // Dispatches the onResponseStarted event indicating that the first bytes of |
| 146 // the response have arrived. | 146 // the response have arrived. |
| 147 void OnResponseStarted(ProfileId profile_id, | 147 void OnResponseStarted(void* profile, |
| 148 ExtensionInfoMap* extension_info_map, | 148 ExtensionInfoMap* extension_info_map, |
| 149 net::URLRequest* request); | 149 net::URLRequest* request); |
| 150 | 150 |
| 151 // Dispatches the onComplete event. | 151 // Dispatches the onComplete event. |
| 152 void OnCompleted(ProfileId profile_id, | 152 void OnCompleted(void* profile, |
| 153 ExtensionInfoMap* extension_info_map, | 153 ExtensionInfoMap* extension_info_map, |
| 154 net::URLRequest* request); | 154 net::URLRequest* request); |
| 155 | 155 |
| 156 // Dispatches an onErrorOccurred event. | 156 // Dispatches an onErrorOccurred event. |
| 157 void OnErrorOccurred(ProfileId profile_id, | 157 void OnErrorOccurred(void* profile, |
| 158 ExtensionInfoMap* extension_info_map, | 158 ExtensionInfoMap* extension_info_map, |
| 159 net::URLRequest* request); | 159 net::URLRequest* request); |
| 160 | 160 |
| 161 // Notifications when objects are going away. | 161 // Notifications when objects are going away. |
| 162 void OnURLRequestDestroyed(ProfileId profile_id, net::URLRequest* request); | 162 void OnURLRequestDestroyed(void* profile, net::URLRequest* request); |
| 163 void OnHttpTransactionDestroyed(ProfileId profile_id, uint64 request_id); | 163 void OnHttpTransactionDestroyed(void* profile, uint64 request_id); |
| 164 | 164 |
| 165 // Called when an event listener handles a blocking event and responds. | 165 // Called when an event listener handles a blocking event and responds. |
| 166 void OnEventHandled( | 166 void OnEventHandled( |
| 167 ProfileId profile_id, | 167 void* profile, |
| 168 const std::string& extension_id, | 168 const std::string& extension_id, |
| 169 const std::string& event_name, | 169 const std::string& event_name, |
| 170 const std::string& sub_event_name, | 170 const std::string& sub_event_name, |
| 171 uint64 request_id, | 171 uint64 request_id, |
| 172 EventResponse* response); | 172 EventResponse* response); |
| 173 | 173 |
| 174 // Adds a listener to the given event. |event_name| specifies the event being | 174 // Adds a listener to the given event. |event_name| specifies the event being |
| 175 // listened to. |sub_event_name| is an internal event uniquely generated in | 175 // listened to. |sub_event_name| is an internal event uniquely generated in |
| 176 // the extension process to correspond to the given filter and | 176 // the extension process to correspond to the given filter and |
| 177 // extra_info_spec. | 177 // extra_info_spec. |
| 178 void AddEventListener( | 178 void AddEventListener( |
| 179 ProfileId profile_id, | 179 void* profile, |
| 180 const std::string& extension_id, | 180 const std::string& extension_id, |
| 181 const std::string& event_name, | 181 const std::string& event_name, |
| 182 const std::string& sub_event_name, | 182 const std::string& sub_event_name, |
| 183 const RequestFilter& filter, | 183 const RequestFilter& filter, |
| 184 int extra_info_spec, | 184 int extra_info_spec, |
| 185 base::WeakPtr<IPC::Message::Sender> ipc_sender); | 185 base::WeakPtr<IPC::Message::Sender> ipc_sender); |
| 186 | 186 |
| 187 // Removes the listener for the given sub-event. | 187 // Removes the listener for the given sub-event. |
| 188 void RemoveEventListener( | 188 void RemoveEventListener( |
| 189 ProfileId profile_id, | 189 void* profile, |
| 190 const std::string& extension_id, | 190 const std::string& extension_id, |
| 191 const std::string& sub_event_name); | 191 const std::string& sub_event_name); |
| 192 | 192 |
| 193 // Called when an incognito profile is created or destroyed. | 193 // Called when an incognito profile is created or destroyed. |
| 194 void OnOTRProfileCreated(ProfileId original_profile_id, | 194 void OnOTRProfileCreated(void* original_profile, |
| 195 ProfileId otr_profile_id); | 195 void* otr_profile); |
| 196 void OnOTRProfileDestroyed(ProfileId original_profile_id, | 196 void OnOTRProfileDestroyed(void* original_profile, |
| 197 ProfileId otr_profile_id); | 197 void* otr_profile); |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; | 200 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; |
| 201 struct EventListener; | 201 struct EventListener; |
| 202 struct BlockedRequest; | 202 struct BlockedRequest; |
| 203 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; | 203 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; |
| 204 typedef std::map<ProfileId, ListenerMapForProfile> ListenerMap; | 204 typedef std::map<void*, ListenerMapForProfile> ListenerMap; |
| 205 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; | 205 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; |
| 206 typedef std::map<uint64, net::URLRequest*> HttpRequestMap; | 206 typedef std::map<uint64, net::URLRequest*> HttpRequestMap; |
| 207 // Map of request_id -> bit vector of EventTypes already signaled | 207 // Map of request_id -> bit vector of EventTypes already signaled |
| 208 typedef std::map<uint64, int> SignaledRequestMap; | 208 typedef std::map<uint64, int> SignaledRequestMap; |
| 209 typedef std::map<ProfileId, ProfileId> CrossProfileMap; | 209 typedef std::map<void*, void*> CrossProfileMap; |
| 210 | 210 |
| 211 ExtensionWebRequestEventRouter(); | 211 ExtensionWebRequestEventRouter(); |
| 212 ~ExtensionWebRequestEventRouter(); | 212 ~ExtensionWebRequestEventRouter(); |
| 213 | 213 |
| 214 bool DispatchEvent( | 214 bool DispatchEvent( |
| 215 ProfileId profile_id, | 215 void* profile, |
| 216 net::URLRequest* request, | 216 net::URLRequest* request, |
| 217 const std::vector<const EventListener*>& listeners, | 217 const std::vector<const EventListener*>& listeners, |
| 218 const ListValue& args); | 218 const ListValue& args); |
| 219 | 219 |
| 220 // Returns a list of event listeners that care about the given event, based | 220 // Returns a list of event listeners that care about the given event, based |
| 221 // on their filter parameters. |extra_info_spec| will contain the combined | 221 // on their filter parameters. |extra_info_spec| will contain the combined |
| 222 // set of extra_info_spec flags that every matching listener asked for. | 222 // set of extra_info_spec flags that every matching listener asked for. |
| 223 std::vector<const EventListener*> GetMatchingListeners( | 223 std::vector<const EventListener*> GetMatchingListeners( |
| 224 ProfileId profile_id, | 224 void* profile, |
| 225 ExtensionInfoMap* extension_info_map, | 225 ExtensionInfoMap* extension_info_map, |
| 226 const std::string& event_name, | 226 const std::string& event_name, |
| 227 const GURL& url, | 227 const GURL& url, |
| 228 int tab_id, | 228 int tab_id, |
| 229 int window_id, | 229 int window_id, |
| 230 ResourceType::Type resource_type, | 230 ResourceType::Type resource_type, |
| 231 int* extra_info_spec); | 231 int* extra_info_spec); |
| 232 | 232 |
| 233 // Same as above, but retrieves the filter parameters from the request. | 233 // Same as above, but retrieves the filter parameters from the request. |
| 234 std::vector<const EventListener*> GetMatchingListeners( | 234 std::vector<const EventListener*> GetMatchingListeners( |
| 235 ProfileId profile_id, | 235 void* profile, |
| 236 ExtensionInfoMap* extension_info_map, | 236 ExtensionInfoMap* extension_info_map, |
| 237 const std::string& event_name, | 237 const std::string& event_name, |
| 238 net::URLRequest* request, | 238 net::URLRequest* request, |
| 239 int* extra_info_spec); | 239 int* extra_info_spec); |
| 240 | 240 |
| 241 // Helper for the above functions. This is called twice: once for the profile | 241 // Helper for the above functions. This is called twice: once for the profile |
| 242 // of the event, the next time for the "cross" profile (i.e. the incognito | 242 // of the event, the next time for the "cross" profile (i.e. the incognito |
| 243 // profile if the event is originally for the normal profile, or vice versa). | 243 // profile if the event is originally for the normal profile, or vice versa). |
| 244 void GetMatchingListenersImpl( | 244 void GetMatchingListenersImpl( |
| 245 ProfileId profile_id, | 245 void* profile, |
| 246 ExtensionInfoMap* extension_info_map, | 246 ExtensionInfoMap* extension_info_map, |
| 247 bool crosses_incognito, | 247 bool crosses_incognito, |
| 248 const std::string& event_name, | 248 const std::string& event_name, |
| 249 const GURL& url, | 249 const GURL& url, |
| 250 int tab_id, | 250 int tab_id, |
| 251 int window_id, | 251 int window_id, |
| 252 ResourceType::Type resource_type, | 252 ResourceType::Type resource_type, |
| 253 int* extra_info_spec, | 253 int* extra_info_spec, |
| 254 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* | 254 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* |
| 255 matching_listeners); | 255 matching_listeners); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); | 297 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); |
| 298 }; | 298 }; |
| 299 | 299 |
| 300 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { | 300 class WebRequestEventHandled : public SyncIOThreadExtensionFunction { |
| 301 public: | 301 public: |
| 302 virtual bool RunImpl(); | 302 virtual bool RunImpl(); |
| 303 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); | 303 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); |
| 304 }; | 304 }; |
| 305 | 305 |
| 306 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ | 306 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ |
| OLD | NEW |