 Chromium Code Reviews
 Chromium Code Reviews Issue 8015004:
  webRequest.onAuthRequired listeners can provide authentication credentials.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 8015004:
  webRequest.onAuthRequired listeners can provide authentication credentials.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: net/url_request/url_request.cc | 
| diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc | 
| index 02667b5afe128d4eba237b2ecfc56c3dddff1767..dee35fae43f15028907219da722fd5f43dd34d46 100644 | 
| --- a/net/url_request/url_request.cc | 
| +++ b/net/url_request/url_request.cc | 
| @@ -9,6 +9,7 @@ | 
| #include "base/message_loop.h" | 
| #include "base/metrics/stats_counters.h" | 
| #include "base/synchronization/lock.h" | 
| +#include "net/base/auth.h" | 
| #include "net/base/host_port_pair.h" | 
| #include "net/base/load_flags.h" | 
| #include "net/base/net_errors.h" | 
| @@ -144,7 +145,10 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate) | 
| blocked_on_delegate_(false), | 
| ALLOW_THIS_IN_INITIALIZER_LIST( | 
| before_request_callback_(this, &URLRequest::BeforeRequestComplete)), | 
| - has_notified_completion_(false) { | 
| + has_notified_completion_(false), | 
| + ALLOW_THIS_IN_INITIALIZER_LIST( | 
| + auth_required_callback_( | 
| + this, &URLRequest::NotifyAuthRequiredComplete)) { | 
| SIMPLE_STATS_COUNTER("URLRequestCount"); | 
| // Sanity check out environment. | 
| @@ -770,11 +774,45 @@ void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { | 
| // URLRequestTestHTTP.BasicAuthWithCookies. In both cases we observe a | 
| // call sequence of OnBeforeSendHeaders -> OnSendHeaders -> | 
| // OnBeforeSendHeaders. | 
| 
battre
2011/09/24 13:17:55
i think this comment becomes obsolete now. Could y
 | 
| - if (context_ && context_->network_delegate()) | 
| - context_->network_delegate()->NotifyAuthRequired(this, *auth_info); | 
| + int rv = OK; | 
| + auth_info_ = auth_info; | 
| + if (context_ && context_->network_delegate()) { | 
| + rv = context_->network_delegate()->NotifyAuthRequired( | 
| + this, *auth_info, &auth_required_callback_, &auth_credentials_); | 
| + } | 
| + | 
| + if (rv == ERR_IO_PENDING) { | 
| + SetBlockedOnDelegate(); | 
| 
battre
2011/09/24 13:17:55
the corresponding SetUnblockedOnDelegate(); is mis
 
cbentzel
2011/09/26 21:13:36
Done.
 | 
| + } else { | 
| + NotifyAuthRequiredComplete(rv); | 
| + } | 
| +} | 
| + | 
| +void URLRequest::NotifyAuthRequiredComplete(int result) { | 
| + // NotifyAuthRequired may be called multiple times, such as | 
| + // when an authentication attempt fails. Clear out the data | 
| + // so it can be reset on another round. | 
| + AuthCredentials credentials = auth_credentials_; | 
| + auth_credentials_ = AuthCredentials(); | 
| + scoped_refptr<AuthChallengeInfo> auth_info; | 
| + auth_info.swap(auth_info_); | 
| + | 
| + if (result != OK) | 
| + return; | 
| + | 
| + // TODO(cbentzel): Should the ERR_EMPTY_RESPONSE be handled? This might | 
| + // be equivalent to canceling authentication, | 
| 
battre
2011/09/24 13:17:55
probably yes
 
cbentzel
2011/09/26 21:13:36
Done.
 | 
| + | 
| + // If the NetworkDelegate provided a username and password, try | 
| + // using that. | 
| + if (credentials.is_valid) { | 
| + SetAuth(credentials.username, credentials.password); | 
| + return; | 
| + } | 
| + // Otherwise, defer to the URLRequest Delegate. | 
| if (delegate_) | 
| - delegate_->OnAuthRequired(this, auth_info); | 
| + delegate_->OnAuthRequired(this, auth_info.get()); | 
| } | 
| void URLRequest::NotifyCertificateRequested( |