Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/extensions/extension_webrequest_api.h

Issue 6698009: Add request_id to HttpRequestInfo and pass it to the NetworkDelegate for events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: delegate callbcak Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/singleton.h" 14 #include "base/singleton.h"
15 #include "chrome/browser/extensions/extension_function.h" 15 #include "chrome/browser/extensions/extension_function.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
18 #include "net/base/completion_callback.h" 18 #include "net/base/completion_callback.h"
19 19
20 class ExtensionEventRouterForwarder; 20 class ExtensionEventRouterForwarder;
21 class GURL; 21 class GURL;
22 22
23 namespace net { 23 namespace net {
24 class HttpRequestHeaders;
24 class URLRequest; 25 class URLRequest;
25 } 26 }
26 27
27 // This class observes network events and routes them to the appropriate 28 // This class observes network events and routes them to the appropriate
28 // extensions listening to those events. All methods must be called on the IO 29 // extensions listening to those events. All methods must be called on the IO
29 // thread unless otherwise specified. 30 // thread unless otherwise specified.
30 class ExtensionWebRequestEventRouter { 31 class ExtensionWebRequestEventRouter {
31 public: 32 public:
32 struct RequestFilter; 33 struct RequestFilter;
33 struct ExtraInfoSpec; 34 struct ExtraInfoSpec;
34 35
35 static ExtensionWebRequestEventRouter* GetInstance(); 36 static ExtensionWebRequestEventRouter* GetInstance();
36 37
37 // Dispatches the OnBeforeRequest event to any extensions whose filters match 38 // Dispatches the OnBeforeRequest event to any extensions whose filters match
38 // the given request. Returns true if an extension wants to pause the request. 39 // the given request. Returns true if an extension wants to pause the request.
39 bool OnBeforeRequest(ProfileId profile_id, 40 bool OnBeforeRequest(ProfileId profile_id,
40 ExtensionEventRouterForwarder* event_router, 41 ExtensionEventRouterForwarder* event_router,
41 net::URLRequest* request, 42 net::URLRequest* request,
42 net::CompletionCallback* callback); 43 net::CompletionCallback* callback);
43 44
45 // Same as above, but for HTTP(s) requests. This version includes the request
46 // headers about to be sent.
47 bool OnBeforeSendHeaders(ProfileId profile_id,
48 ExtensionEventRouterForwarder* event_router,
49 uint64 request_id,
50 net::HttpRequestHeaders* headers,
51 net::CompletionCallback* callback);
52
44 // Called when an event listener handles a blocking event and responds. 53 // Called when an event listener handles a blocking event and responds.
45 // TODO(mpcomplete): modify request 54 // TODO(mpcomplete): modify request
46 void OnEventHandled( 55 void OnEventHandled(
47 ProfileId profile_id, 56 ProfileId profile_id,
48 const std::string& extension_id, 57 const std::string& extension_id,
49 const std::string& event_name, 58 const std::string& event_name,
50 const std::string& sub_event_name, 59 const std::string& sub_event_name,
51 uint64 request_id, 60 uint64 request_id,
52 bool cancel); 61 bool cancel);
53 62
(...skipping 12 matching lines...) Expand all
66 // Removes the listener for the given sub-event. 75 // Removes the listener for the given sub-event.
67 void RemoveEventListener( 76 void RemoveEventListener(
68 ProfileId profile_id, 77 ProfileId profile_id,
69 const std::string& extension_id, 78 const std::string& extension_id,
70 const std::string& sub_event_name); 79 const std::string& sub_event_name);
71 80
72 private: 81 private:
73 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; 82 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>;
74 struct EventListener; 83 struct EventListener;
75 struct BlockedRequest; 84 struct BlockedRequest;
85 class TrackedRequest;
86 friend class TrackedRequest;
76 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; 87 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile;
77 typedef std::map<ProfileId, ListenerMapForProfile> ListenerMap; 88 typedef std::map<ProfileId, ListenerMapForProfile> ListenerMap;
78 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; 89 typedef std::map<uint64, BlockedRequest> BlockedRequestMap;
90 typedef std::map<uint64, TrackedRequest*> HttpRequestMap;
79 91
80 ExtensionWebRequestEventRouter(); 92 ExtensionWebRequestEventRouter();
81 ~ExtensionWebRequestEventRouter(); 93 ~ExtensionWebRequestEventRouter();
82 94
95 bool DispatchEvent(
96 ProfileId profile_id,
97 ExtensionEventRouterForwarder* event_router,
98 net::URLRequest* request,
99 net::CompletionCallback* callback,
100 const std::vector<const EventListener*>& listeners,
101 const ListValue& args);
102
83 // Returns a list of event listeners that care about the given event, based 103 // Returns a list of event listeners that care about the given event, based
84 // on their filter parameters. 104 // on their filter parameters.
85 std::vector<const EventListener*> GetMatchingListeners( 105 std::vector<const EventListener*> GetMatchingListeners(
86 ProfileId profile_id, const std::string& event_name, const GURL& url); 106 ProfileId profile_id, const std::string& event_name, const GURL& url);
87 107
108 // Same as above, but retrieves the filter parameters from the request.
109 std::vector<const EventListener*> GetMatchingListeners(
110 ProfileId profile_id,
111 const std::string& event_name,
112 net::URLRequest* request);
113
88 // Decrements the count of event handlers blocking the given request. When the 114 // Decrements the count of event handlers blocking the given request. When the
89 // count reaches 0 (or immediately if the request is being cancelled), we 115 // count reaches 0 (or immediately if the request is being cancelled), we
90 // stop blocking the request and either resume or cancel it. 116 // stop blocking the request and either resume or cancel it.
91 void DecrementBlockCount(uint64 request_id, bool cancel); 117 void DecrementBlockCount(uint64 request_id, bool cancel);
92 118
119 void OnRequestDeleted(net::URLRequest* request);
120
93 // A map for each profile that maps an event name to a set of extensions that 121 // A map for each profile that maps an event name to a set of extensions that
94 // are listening to that event. 122 // are listening to that event.
95 ListenerMap listeners_; 123 ListenerMap listeners_;
96 124
97 // A map of network requests that are waiting for at least one event handler 125 // A map of network requests that are waiting for at least one event handler
98 // to respond. 126 // to respond.
99 BlockedRequestMap blocked_requests_; 127 BlockedRequestMap blocked_requests_;
100 128
129 // A map of HTTP(s) network requests. We don't dispatch onBeforeRequest for
130 // these requests until headers are available.
131 HttpRequestMap http_requests_;
132
101 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); 133 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter);
102 }; 134 };
103 135
104 class WebRequestAddEventListener : public SyncExtensionFunction { 136 class WebRequestAddEventListener : public SyncExtensionFunction {
105 public: 137 public:
106 virtual bool RunImpl(); 138 virtual bool RunImpl();
107 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener"); 139 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.addEventListener");
108 }; 140 };
109 141
110 class WebRequestEventHandled : public SyncExtensionFunction { 142 class WebRequestEventHandled : public SyncExtensionFunction {
111 public: 143 public:
112 virtual bool RunImpl(); 144 virtual bool RunImpl();
113 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled"); 145 DECLARE_EXTENSION_FUNCTION_NAME("experimental.webRequest.eventHandled");
114 }; 146 };
115 147
116 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ 148 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698