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

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

Issue 1577673002: WebRequest API cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: copy GetSocketAddress().host instead of & to resolve win failure Created 4 years, 11 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
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 EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ 5 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_
6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 class AuthChallengeInfo; 50 class AuthChallengeInfo;
51 class AuthCredentials; 51 class AuthCredentials;
52 class HttpRequestHeaders; 52 class HttpRequestHeaders;
53 class HttpResponseHeaders; 53 class HttpResponseHeaders;
54 class URLRequest; 54 class URLRequest;
55 } 55 }
56 56
57 namespace extensions { 57 namespace extensions {
58 58
59 class InfoMap; 59 class InfoMap;
60 class WebRequestEventDetails;
60 class WebRequestRulesRegistry; 61 class WebRequestRulesRegistry;
61 class WebRequestEventRouterDelegate; 62 class WebRequestEventRouterDelegate;
62 63
63 // Support class for the WebRequest API. Lives on the UI thread. Most of the 64 // Support class for the WebRequest API. Lives on the UI thread. Most of the
64 // work is done by ExtensionWebRequestEventRouter below. This class observes 65 // work is done by ExtensionWebRequestEventRouter below. This class observes
65 // extensions::EventRouter to deal with event listeners. There is one instance 66 // extensions::EventRouter to deal with event listeners. There is one instance
66 // per BrowserContext which is shared with incognito. 67 // per BrowserContext which is shared with incognito.
67 class WebRequestAPI : public BrowserContextKeyedAPI, 68 class WebRequestAPI : public BrowserContextKeyedAPI,
68 public EventRouter::Observer { 69 public EventRouter::Observer {
69 public: 70 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // an error message is provided, otherwise the error is internal (and 121 // an error message is provided, otherwise the error is internal (and
121 // unexpected). 122 // unexpected).
122 bool InitFromValue(const base::DictionaryValue& value, std::string* error); 123 bool InitFromValue(const base::DictionaryValue& value, std::string* error);
123 124
124 extensions::URLPatternSet urls; 125 extensions::URLPatternSet urls;
125 std::vector<content::ResourceType> types; 126 std::vector<content::ResourceType> types;
126 int tab_id; 127 int tab_id;
127 int window_id; 128 int window_id;
128 }; 129 };
129 130
130 // Internal representation of the extraInfoSpec parameter on webRequest
131 // events, used to specify extra information to be included with network
132 // events.
133 struct ExtraInfoSpec {
134 enum Flags {
135 REQUEST_HEADERS = 1<<0,
136 RESPONSE_HEADERS = 1<<1,
137 BLOCKING = 1<<2,
138 ASYNC_BLOCKING = 1<<3,
139 REQUEST_BODY = 1<<4,
140 };
141
142 static bool InitFromValue(const base::ListValue& value,
143 int* extra_info_spec);
144 };
145
146 // Contains an extension's response to a blocking event. 131 // Contains an extension's response to a blocking event.
147 struct EventResponse { 132 struct EventResponse {
148 EventResponse(const std::string& extension_id, 133 EventResponse(const std::string& extension_id,
149 const base::Time& extension_install_time); 134 const base::Time& extension_install_time);
150 ~EventResponse(); 135 ~EventResponse();
151 136
152 // ID of the extension that sent this response. 137 // ID of the extension that sent this response.
153 std::string extension_id; 138 std::string extension_id;
154 139
155 // The time that the extension was installed. Used for deciding order of 140 // The time that the extension was installed. Used for deciding order of
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 using CrossBrowserContextMap = std::map<void*, std::pair<bool, void*>>; 314 using CrossBrowserContextMap = std::map<void*, std::pair<bool, void*>>;
330 using CallbacksForPageLoad = std::list<base::Closure>; 315 using CallbacksForPageLoad = std::list<base::Closure>;
331 316
332 ExtensionWebRequestEventRouter(); 317 ExtensionWebRequestEventRouter();
333 ~ExtensionWebRequestEventRouter(); 318 ~ExtensionWebRequestEventRouter();
334 319
335 // Ensures that future callbacks for |request| are ignored so that it can be 320 // Ensures that future callbacks for |request| are ignored so that it can be
336 // destroyed safely. 321 // destroyed safely.
337 void ClearPendingCallbacks(const net::URLRequest* request); 322 void ClearPendingCallbacks(const net::URLRequest* request);
338 323
339 bool DispatchEvent( 324 bool DispatchEvent(void* browser_context,
340 void* browser_context, 325 net::URLRequest* request,
341 net::URLRequest* request, 326 const std::vector<const EventListener*>& listeners,
342 const std::vector<const EventListener*>& listeners, 327 scoped_ptr<WebRequestEventDetails> event_details);
343 const base::ListValue& args);
344 328
345 void DispatchEventToListeners( 329 void DispatchEventToListeners(
346 void* browser_context, 330 void* browser_context,
347 scoped_ptr<std::vector<EventListener>> listeners, 331 scoped_ptr<std::vector<EventListener>> listeners,
348 base::DictionaryValue* dict, 332 scoped_ptr<WebRequestEventDetails> event_details);
349 int extension_api_frame_id,
350 int extension_api_parent_frame_id);
351 333
352 // Returns a list of event listeners that care about the given event, based 334 // Returns a list of event listeners that care about the given event, based
353 // on their filter parameters. |extra_info_spec| will contain the combined 335 // on their filter parameters. |extra_info_spec| will contain the combined
354 // set of extra_info_spec flags that every matching listener asked for. 336 // set of extra_info_spec flags that every matching listener asked for.
355 std::vector<const EventListener*> GetMatchingListeners( 337 std::vector<const EventListener*> GetMatchingListeners(
356 void* browser_context, 338 void* browser_context,
357 const extensions::InfoMap* extension_info_map, 339 const extensions::InfoMap* extension_info_map,
358 const std::string& event_name, 340 const std::string& event_name,
359 const net::URLRequest* request, 341 const net::URLRequest* request,
360 int* extra_info_spec); 342 int* extra_info_spec);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 void SendMessages( 409 void SendMessages(
428 void* browser_context, const BlockedRequest& blocked_request); 410 void* browser_context, const BlockedRequest& blocked_request);
429 411
430 // Called when the RulesRegistry is ready to unblock a request that was 412 // Called when the RulesRegistry is ready to unblock a request that was
431 // waiting for said event. 413 // waiting for said event.
432 void OnRulesRegistryReady(void* browser_context, 414 void OnRulesRegistryReady(void* browser_context,
433 const std::string& event_name, 415 const std::string& event_name,
434 uint64_t request_id, 416 uint64_t request_id,
435 extensions::RequestStage request_stage); 417 extensions::RequestStage request_stage);
436 418
437 // Extracts from |request| information for the keys requestId, url, method, 419 // Returns event details for a given request.
438 // frameId, tabId, type, and timeStamp and writes these into |out| to be 420 scoped_ptr<WebRequestEventDetails> CreateEventDetails(
439 // passed on to extensions. 421 const net::URLRequest* request,
440 void ExtractRequestInfo(const net::URLRequest* request, 422 int extra_info_spec);
441 base::DictionaryValue* out);
442 423
443 // Sets the flag that |event_type| has been signaled for |request_id|. 424 // Sets the flag that |event_type| has been signaled for |request_id|.
444 // Returns the value of the flag before setting it. 425 // Returns the value of the flag before setting it.
445 bool GetAndSetSignaled(uint64_t request_id, EventTypes event_type); 426 bool GetAndSetSignaled(uint64_t request_id, EventTypes event_type);
446 427
447 // Clears the flag that |event_type| has been signaled for |request_id|. 428 // Clears the flag that |event_type| has been signaled for |request_id|.
448 void ClearSignaled(uint64_t request_id, EventTypes event_type); 429 void ClearSignaled(uint64_t request_id, EventTypes event_type);
449 430
450 // Returns whether |request| represents a top level window navigation. 431 // Returns whether |request| represents a top level window navigation.
451 bool IsPageLoad(const net::URLRequest* request) const; 432 bool IsPageLoad(const net::URLRequest* request) const;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 extensions::QuotaLimitHeuristics* heuristics) const override; 543 extensions::QuotaLimitHeuristics* heuristics) const override;
563 // Handle quota exceeded gracefully: Only warn the user but still execute the 544 // Handle quota exceeded gracefully: Only warn the user but still execute the
564 // function. 545 // function.
565 void OnQuotaExceeded(const std::string& error) override; 546 void OnQuotaExceeded(const std::string& error) override;
566 bool RunSync() override; 547 bool RunSync() override;
567 }; 548 };
568 549
569 } // namespace extensions 550 } // namespace extensions
570 551
571 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_ 552 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698