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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.h

Issue 10831008: Refactor and fix declarative webRequest API permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 8 years, 4 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) 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 7
8 #include <list> 8 #include <list>
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/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h" 17 #include "chrome/browser/extensions/api/declarative_webrequest/request_stages.h"
18 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" 18 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
19 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h"
19 #include "chrome/browser/extensions/extension_function.h" 20 #include "chrome/browser/extensions/extension_function.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/extensions/url_pattern_set.h" 22 #include "chrome/common/extensions/url_pattern_set.h"
22 #include "ipc/ipc_sender.h" 23 #include "ipc/ipc_sender.h"
23 #include "net/base/completion_callback.h" 24 #include "net/base/completion_callback.h"
24 #include "net/base/network_delegate.h" 25 #include "net/base/network_delegate.h"
25 #include "net/http/http_request_headers.h" 26 #include "net/http/http_request_headers.h"
26 #include "webkit/glue/resource_type.h" 27 #include "webkit/glue/resource_type.h"
27 28
28 class ExtensionInfoMap; 29 class ExtensionInfoMap;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders> 126 scoped_ptr<extension_web_request_api_helpers::ResponseHeaders>
126 response_headers; 127 response_headers;
127 128
128 scoped_ptr<net::AuthCredentials> auth_credentials; 129 scoped_ptr<net::AuthCredentials> auth_credentials;
129 130
130 DISALLOW_COPY_AND_ASSIGN(EventResponse); 131 DISALLOW_COPY_AND_ASSIGN(EventResponse);
131 }; 132 };
132 133
133 static ExtensionWebRequestEventRouter* GetInstance(); 134 static ExtensionWebRequestEventRouter* GetInstance();
134 135
136 // Registers a rule registry. Pass null for |rules_registry| to unregister
137 // the rule registry for |profile|.
135 void RegisterRulesRegistry( 138 void RegisterRulesRegistry(
139 void* profile,
136 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry); 140 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry);
137 141
138 // Dispatches the OnBeforeRequest event to any extensions whose filters match 142 // Dispatches the OnBeforeRequest event to any extensions whose filters match
139 // the given request. Returns net::ERR_IO_PENDING if an extension is 143 // the given request. Returns net::ERR_IO_PENDING if an extension is
140 // intercepting the request, OK otherwise. 144 // intercepting the request, OK otherwise.
141 int OnBeforeRequest(void* profile, 145 int OnBeforeRequest(void* profile,
142 ExtensionInfoMap* extension_info_map, 146 ExtensionInfoMap* extension_info_map,
143 net::URLRequest* request, 147 net::URLRequest* request,
144 const net::CompletionCallback& callback, 148 const net::CompletionCallback& callback,
145 GURL* new_url); 149 GURL* new_url);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 263
260 private: 264 private:
261 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>; 265 friend struct DefaultSingletonTraits<ExtensionWebRequestEventRouter>;
262 266
263 struct EventListener; 267 struct EventListener;
264 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; 268 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile;
265 typedef std::map<void*, ListenerMapForProfile> ListenerMap; 269 typedef std::map<void*, ListenerMapForProfile> ListenerMap;
266 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; 270 typedef std::map<uint64, BlockedRequest> BlockedRequestMap;
267 // Map of request_id -> bit vector of EventTypes already signaled 271 // Map of request_id -> bit vector of EventTypes already signaled
268 typedef std::map<uint64, int> SignaledRequestMap; 272 typedef std::map<uint64, int> SignaledRequestMap;
269 typedef std::map<void*, void*> CrossProfileMap;
270 typedef std::list<base::Closure> CallbacksForPageLoad; 273 typedef std::list<base::Closure> CallbacksForPageLoad;
271 274
272 ExtensionWebRequestEventRouter(); 275 ExtensionWebRequestEventRouter();
273 ~ExtensionWebRequestEventRouter(); 276 ~ExtensionWebRequestEventRouter();
274 277
275 // Ensures that future callbacks for |request| are ignored so that it can be 278 // Ensures that future callbacks for |request| are ignored so that it can be
276 // destroyed safely. 279 // destroyed safely.
277 void ClearPendingCallbacks(net::URLRequest* request); 280 void ClearPendingCallbacks(net::URLRequest* request);
278 281
279 bool DispatchEvent( 282 bool DispatchEvent(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ListenerMap listeners_; 371 ListenerMap listeners_;
369 372
370 // A map of network requests that are waiting for at least one event handler 373 // A map of network requests that are waiting for at least one event handler
371 // to respond. 374 // to respond.
372 BlockedRequestMap blocked_requests_; 375 BlockedRequestMap blocked_requests_;
373 376
374 // A map of request ids to a bitvector indicating which events have been 377 // A map of request ids to a bitvector indicating which events have been
375 // signaled and should not be sent again. 378 // signaled and should not be sent again.
376 SignaledRequestMap signaled_requests_; 379 SignaledRequestMap signaled_requests_;
377 380
378 // A map of original profile -> corresponding incognito profile (and vice
379 // versa).
380 CrossProfileMap cross_profile_map_;
381
382 // Keeps track of time spent waiting on extensions using the blocking 381 // Keeps track of time spent waiting on extensions using the blocking
383 // webRequest API. 382 // webRequest API.
384 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_; 383 scoped_ptr<ExtensionWebRequestTimeTracker> request_time_tracker_;
385 384
386 CallbacksForPageLoad callbacks_for_page_load_; 385 CallbacksForPageLoad callbacks_for_page_load_;
387 386
388 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry_; 387 // Maps each profile (and OTRProfile) to its respective rules registry.
388 std::map<void*, scoped_refptr<extensions::WebRequestRulesRegistry> >
389 rules_registries_;
390
391 WebRequestPermissions permissions_;
389 392
390 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter); 393 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestEventRouter);
391 }; 394 };
392 395
393 class WebRequestAddEventListener : public SyncIOThreadExtensionFunction { 396 class WebRequestAddEventListener : public SyncIOThreadExtensionFunction {
394 public: 397 public:
395 DECLARE_EXTENSION_FUNCTION_NAME("webRequestInternal.addEventListener"); 398 DECLARE_EXTENSION_FUNCTION_NAME("webRequestInternal.addEventListener");
396 399
397 protected: 400 protected:
398 virtual ~WebRequestAddEventListener() {} 401 virtual ~WebRequestAddEventListener() {}
(...skipping 28 matching lines...) Expand all
427 virtual void OnQuotaExceeded() OVERRIDE; 430 virtual void OnQuotaExceeded() OVERRIDE;
428 virtual bool RunImpl() OVERRIDE; 431 virtual bool RunImpl() OVERRIDE;
429 }; 432 };
430 433
431 // Send updates to |host| with information about what webRequest-related 434 // Send updates to |host| with information about what webRequest-related
432 // extensions are installed. 435 // extensions are installed.
433 // TODO(mpcomplete): remove. http://crbug.com/100411 436 // TODO(mpcomplete): remove. http://crbug.com/100411
434 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host); 437 void SendExtensionWebRequestStatusToHost(content::RenderProcessHost* host);
435 438
436 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_ 439 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698