| OLD | NEW |
| 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 #include "net/http/http_auth_handler.h" | 5 #include "net/http/http_auth_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/http/http_auth_challenge_tokenizer.h" | 12 #include "net/http/http_auth_challenge_tokenizer.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 HttpAuthHandler::HttpAuthHandler() : target_(HttpAuth::AUTH_NONE) {} | 16 HttpAuthHandler::HttpAuthHandler() : target_(HttpAuth::AUTH_NONE) {} |
| 17 | 17 |
| 18 HttpAuthHandler::~HttpAuthHandler() { | 18 HttpAuthHandler::~HttpAuthHandler() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool HttpAuthHandler::InitFromChallenge( | 21 int HttpAuthHandler::HandleInitialChallenge( |
| 22 HttpAuthChallengeTokenizer* challenge, | 22 const HttpAuthChallengeTokenizer& challenge, |
| 23 HttpAuth::Target target, | 23 HttpAuth::Target target, |
| 24 const GURL& origin, | 24 const GURL& origin, |
| 25 const BoundNetLog& net_log) { | 25 const BoundNetLog& net_log) { |
| 26 origin_ = origin; | 26 origin_ = origin; |
| 27 target_ = target; | 27 target_ = target; |
| 28 net_log_ = net_log; | 28 net_log_ = net_log; |
| 29 | 29 |
| 30 auth_challenge_ = challenge->challenge_text(); | 30 auth_challenge_ = challenge.challenge_text(); |
| 31 bool ok = Init(challenge); | 31 int result = Init(challenge); |
| 32 | 32 |
| 33 // Init() is expected to set the scheme, realm, and properties. The realm may | 33 // Init() is expected to set the scheme, realm, score, and properties. The |
| 34 // be empty. | 34 // realm may be empty. |
| 35 DCHECK_IMPLIES(ok, | 35 DCHECK_IMPLIES(result == OK, HttpAuth::IsValidNormalizedScheme(auth_scheme_)); |
| 36 HttpUtil::IsToken(auth_scheme_.begin(), auth_scheme_.end()) && | 36 |
| 37 base::ToLowerASCII(auth_scheme_) == auth_scheme_); | 37 return result; |
| 38 return ok; | |
| 39 } | 38 } |
| 40 | 39 |
| 41 namespace { | 40 namespace { |
| 42 | 41 |
| 43 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { | 42 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { |
| 44 switch (target) { | 43 switch (target) { |
| 45 case HttpAuth::AUTH_PROXY: | 44 case HttpAuth::AUTH_PROXY: |
| 46 return NetLog::TYPE_AUTH_PROXY; | 45 return NetLog::TYPE_AUTH_PROXY; |
| 47 case HttpAuth::AUTH_SERVER: | 46 case HttpAuth::AUTH_SERVER: |
| 48 return NetLog::TYPE_AUTH_SERVER; | 47 return NetLog::TYPE_AUTH_SERVER; |
| 49 default: | 48 default: |
| 50 NOTREACHED(); | 49 NOTREACHED(); |
| 51 return NetLog::TYPE_CANCELLED; | 50 return NetLog::TYPE_CANCELLED; |
| 52 } | 51 } |
| 53 } | 52 } |
| 54 | 53 |
| 55 } // namespace | 54 } // namespace |
| 56 | 55 |
| 57 int HttpAuthHandler::GenerateAuthToken( | 56 int HttpAuthHandler::GenerateAuthToken(const AuthCredentials* credentials, |
| 58 const AuthCredentials* credentials, const HttpRequestInfo* request, | 57 const HttpRequestInfo& request, |
| 59 const CompletionCallback& callback, std::string* auth_token) { | 58 const CompletionCallback& callback, |
| 59 std::string* auth_token) { |
| 60 DCHECK(!callback.is_null()); | 60 DCHECK(!callback.is_null()); |
| 61 DCHECK(request); | |
| 62 DCHECK(credentials != NULL || AllowsDefaultCredentials()); | 61 DCHECK(credentials != NULL || AllowsDefaultCredentials()); |
| 63 DCHECK(auth_token != NULL); | 62 DCHECK(auth_token != NULL); |
| 64 DCHECK(callback_.is_null()); | 63 DCHECK(callback_.is_null()); |
| 65 callback_ = callback; | 64 callback_ = callback; |
| 66 net_log_.BeginEvent(EventTypeFromAuthTarget(target_)); | 65 net_log_.BeginEvent(EventTypeFromAuthTarget(target_)); |
| 67 int rv = GenerateAuthTokenImpl( | 66 int rv = GenerateAuthTokenImpl( |
| 68 credentials, request, | 67 credentials, request, |
| 69 base::Bind(&HttpAuthHandler::OnGenerateAuthTokenComplete, | 68 base::Bind(&HttpAuthHandler::OnGenerateAuthTokenComplete, |
| 70 base::Unretained(this)), | 69 base::Unretained(this)), |
| 71 auth_token); | 70 auth_token); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 93 callback.Run(rv); | 92 callback.Run(rv); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void HttpAuthHandler::FinishGenerateAuthToken() { | 95 void HttpAuthHandler::FinishGenerateAuthToken() { |
| 97 // TOOD(cbentzel): Should this be done in OK case only? | 96 // TOOD(cbentzel): Should this be done in OK case only? |
| 98 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); | 97 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); |
| 99 callback_.Reset(); | 98 callback_.Reset(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace net | 101 } // namespace net |
| OLD | NEW |