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

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

Issue 8015004: webRequest.onAuthRequired listeners can provide authentication credentials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_webrequest_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/extensions/extension_function.h" 16 #include "chrome/browser/extensions/extension_function.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/extensions/url_pattern_set.h" 18 #include "chrome/common/extensions/url_pattern_set.h"
19 #include "ipc/ipc_message.h" 19 #include "ipc/ipc_message.h"
20 #include "net/base/completion_callback.h" 20 #include "net/base/completion_callback.h"
21 #include "net/base/network_delegate.h"
21 #include "net/http/http_request_headers.h" 22 #include "net/http/http_request_headers.h"
22 #include "webkit/glue/resource_type.h" 23 #include "webkit/glue/resource_type.h"
23 24
24 class ExtensionInfoMap; 25 class ExtensionInfoMap;
25 class ExtensionWebRequestTimeTracker; 26 class ExtensionWebRequestTimeTracker;
26 class GURL; 27 class GURL;
27 28
28 namespace base { 29 namespace base {
29 class DictionaryValue; 30 class DictionaryValue;
30 class ListValue; 31 class ListValue;
31 class StringValue; 32 class StringValue;
32 } 33 }
33 34
34 namespace net { 35 namespace net {
36 class AuthCredentials;
35 class AuthChallengeInfo; 37 class AuthChallengeInfo;
36 class HostPortPair; 38 class HostPortPair;
37 class HttpRequestHeaders; 39 class HttpRequestHeaders;
38 class HttpResponseHeaders; 40 class HttpResponseHeaders;
39 class URLRequest; 41 class URLRequest;
40 } 42 }
41 43
42 // This class observes network events and routes them to the appropriate 44 // This class observes network events and routes them to the appropriate
43 // extensions listening to those events. All methods must be called on the IO 45 // extensions listening to those events. All methods must be called on the IO
44 // thread unless otherwise specified. 46 // thread unless otherwise specified.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // precedence in case multiple extensions respond with conflicting 99 // precedence in case multiple extensions respond with conflicting
98 // decisions. 100 // decisions.
99 base::Time extension_install_time; 101 base::Time extension_install_time;
100 102
101 // Response values. These are mutually exclusive. 103 // Response values. These are mutually exclusive.
102 bool cancel; 104 bool cancel;
103 GURL new_url; 105 GURL new_url;
104 scoped_ptr<net::HttpRequestHeaders> request_headers; 106 scoped_ptr<net::HttpRequestHeaders> request_headers;
105 // Contains all header lines after the status line, lines are \n separated. 107 // Contains all header lines after the status line, lines are \n separated.
106 std::string response_headers_string; 108 std::string response_headers_string;
109 scoped_ptr<net::AuthCredentials> auth_credentials;
107 110
108 EventResponse(const std::string& extension_id, 111 EventResponse(const std::string& extension_id,
109 const base::Time& extension_install_time); 112 const base::Time& extension_install_time);
110 ~EventResponse(); 113 ~EventResponse();
111 114
112 DISALLOW_COPY_AND_ASSIGN(EventResponse); 115 DISALLOW_COPY_AND_ASSIGN(EventResponse);
113 }; 116 };
114 117
115 // Contains the modification an extension wants to perform on an event. 118 // Contains the modification an extension wants to perform on an event.
116 struct EventResponseDelta { 119 struct EventResponseDelta {
(...skipping 11 matching lines...) Expand all
128 131
129 // Newly introduced or overridden request headers. 132 // Newly introduced or overridden request headers.
130 net::HttpRequestHeaders modified_request_headers; 133 net::HttpRequestHeaders modified_request_headers;
131 134
132 // Keys of request headers to be deleted. 135 // Keys of request headers to be deleted.
133 std::vector<std::string> deleted_request_headers; 136 std::vector<std::string> deleted_request_headers;
134 137
135 // Complete set of response headers that will replace the original ones. 138 // Complete set of response headers that will replace the original ones.
136 scoped_refptr<net::HttpResponseHeaders> new_response_headers; 139 scoped_refptr<net::HttpResponseHeaders> new_response_headers;
137 140
141 // Authentication Credentials to use.
142 scoped_ptr<net::AuthCredentials> auth_credentials;
143
138 EventResponseDelta(const std::string& extension_id, 144 EventResponseDelta(const std::string& extension_id,
139 const base::Time& extension_install_time); 145 const base::Time& extension_install_time);
140 ~EventResponseDelta(); 146 ~EventResponseDelta();
141 147
142 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); 148 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta);
143 }; 149 };
144 150
145 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas; 151 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas;
146 152
147 // Used in testing to allow chrome-extension URLs to be intercepted. 153 // Used in testing to allow chrome-extension URLs to be intercepted.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Do not modify |original_response_headers| directly but write new ones 191 // Do not modify |original_response_headers| directly but write new ones
186 // into |override_response_headers|. 192 // into |override_response_headers|.
187 int OnHeadersReceived( 193 int OnHeadersReceived(
188 void* profile, 194 void* profile,
189 ExtensionInfoMap* extension_info_map, 195 ExtensionInfoMap* extension_info_map,
190 net::URLRequest* request, 196 net::URLRequest* request,
191 net::OldCompletionCallback* callback, 197 net::OldCompletionCallback* callback,
192 net::HttpResponseHeaders* original_response_headers, 198 net::HttpResponseHeaders* original_response_headers,
193 scoped_refptr<net::HttpResponseHeaders>* override_response_headers); 199 scoped_refptr<net::HttpResponseHeaders>* override_response_headers);
194 200
195 // Dispatches the onAuthRequired event. 201 // Dispatches the OnAuthRequired event to any extensions whose filters match
196 void OnAuthRequired(void* profile, 202 // the given request. If the listener is not registered as "blocking", then
203 // AUTH_REQUIRED_RESPONSE_OK is returned. Otherwise,
204 // AUTH_REQUIRED_RESPONSE_IO_PENDING is returned and |callback| will be
205 // invoked later.
206 net::NetworkDelegate::AuthRequiredResponse OnAuthRequired(
207 void* profile,
197 ExtensionInfoMap* extension_info_map, 208 ExtensionInfoMap* extension_info_map,
198 net::URLRequest* request, 209 net::URLRequest* request,
199 const net::AuthChallengeInfo& auth_info); 210 const net::AuthChallengeInfo& auth_info,
211 const net::NetworkDelegate::AuthCallback& callback,
212 net::AuthCredentials* credentials);
200 213
201 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests 214 // Dispatches the onBeforeRedirect event. This is fired for HTTP(s) requests
202 // only. 215 // only.
203 void OnBeforeRedirect(void* profile, 216 void OnBeforeRedirect(void* profile,
204 ExtensionInfoMap* extension_info_map, 217 ExtensionInfoMap* extension_info_map,
205 net::URLRequest* request, 218 net::URLRequest* request,
206 const GURL& new_location); 219 const GURL& new_location);
207 220
208 // Dispatches the onResponseStarted event indicating that the first bytes of 221 // Dispatches the onResponseStarted event indicating that the first bytes of
209 // the response have arrived. 222 // the response have arrived.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 void MergeOnBeforeRequestResponses( 353 void MergeOnBeforeRequestResponses(
341 BlockedRequest* request, 354 BlockedRequest* request,
342 std::list<std::string>* conflicting_extensions) const; 355 std::list<std::string>* conflicting_extensions) const;
343 void MergeOnBeforeSendHeadersResponses( 356 void MergeOnBeforeSendHeadersResponses(
344 BlockedRequest* request, 357 BlockedRequest* request,
345 std::list<std::string>* conflicting_extensions) const; 358 std::list<std::string>* conflicting_extensions) const;
346 void MergeOnHeadersReceivedResponses( 359 void MergeOnHeadersReceivedResponses(
347 BlockedRequest* request, 360 BlockedRequest* request,
348 std::list<std::string>* conflicting_extensions) const; 361 std::list<std::string>* conflicting_extensions) const;
349 362
363 // Merge the responses of blocked onAuthRequired handlers. The first
364 // registered listener that supplies authentication credentials in a response,
365 // if any, will have its authentication credentials used. |request| must be
366 // non-NULL, and contain |deltas| that are sorted in decreasing order of
367 // precedence.
368 // Returns whether authentication credentials are set.
369 bool MergeOnAuthRequiredResponses(
370 BlockedRequest* request,
371 std::list<std::string>* conflicting_extensions) const;
372
350 // A map for each profile that maps an event name to a set of extensions that 373 // A map for each profile that maps an event name to a set of extensions that
351 // are listening to that event. 374 // are listening to that event.
352 ListenerMap listeners_; 375 ListenerMap listeners_;
353 376
354 // A map of network requests that are waiting for at least one event handler 377 // A map of network requests that are waiting for at least one event handler
355 // to respond. 378 // to respond.
356 BlockedRequestMap blocked_requests_; 379 BlockedRequestMap blocked_requests_;
357 380
358 // A map of request ids to a bitvector indicating which events have been 381 // A map of request ids to a bitvector indicating which events have been
359 // signaled and should not be sent again. 382 // signaled and should not be sent again.
(...skipping 23 matching lines...) Expand all
383 }; 406 };
384 407
385 class WebRequestHandlerBehaviorChanged : public AsyncExtensionFunction { 408 class WebRequestHandlerBehaviorChanged : public AsyncExtensionFunction {
386 public: 409 public:
387 virtual bool RunImpl(); 410 virtual bool RunImpl();
388 DECLARE_EXTENSION_FUNCTION_NAME( 411 DECLARE_EXTENSION_FUNCTION_NAME(
389 "experimental.webRequest.handlerBehaviorChanged"); 412 "experimental.webRequest.handlerBehaviorChanged");
390 }; 413 };
391 414
392 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ 415 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_webrequest_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698