| OLD | NEW |
| 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 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 5 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 14 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
| 15 #include "chrome/common/net/gaia/gaia_constants.h" | 15 #include "chrome/common/net/gaia/gaia_constants.h" |
| 16 #include "chrome/common/net/gaia/gaia_urls.h" | 16 #include "chrome/common/net/gaia/gaia_urls.h" |
| 17 #include "chrome/common/net/gaia/google_service_auth_error.h" | 17 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 18 #include "chrome/common/net/http_return.h" | 18 #include "chrome/common/net/http_return.h" |
| 19 #include "content/common/net/url_fetcher.h" |
| 19 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 20 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
| 21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 22 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
| 23 | 24 |
| 24 // TODO(chron): Add sourceless version of this formatter. | 25 // TODO(chron): Add sourceless version of this formatter. |
| 25 // static | 26 // static |
| 26 const char GaiaAuthFetcher::kClientLoginFormat[] = | 27 const char GaiaAuthFetcher::kClientLoginFormat[] = |
| 27 "Email=%s&" | 28 "Email=%s&" |
| 28 "Passwd=%s&" | 29 "Passwd=%s&" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 fetcher_.reset(); | 123 fetcher_.reset(); |
| 123 fetch_pending_ = false; | 124 fetch_pending_ = false; |
| 124 } | 125 } |
| 125 | 126 |
| 126 // static | 127 // static |
| 127 URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( | 128 URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( |
| 128 net::URLRequestContextGetter* getter, | 129 net::URLRequestContextGetter* getter, |
| 129 const std::string& body, | 130 const std::string& body, |
| 130 const GURL& gaia_gurl, | 131 const GURL& gaia_gurl, |
| 131 bool send_cookies, | 132 bool send_cookies, |
| 132 URLFetcher::Delegate* delegate) { | 133 content::URLFetcherDelegate* delegate) { |
| 133 | 134 |
| 134 URLFetcher* to_return = | 135 URLFetcher* to_return = |
| 135 URLFetcher::Create(0, | 136 URLFetcher::Create(0, |
| 136 gaia_gurl, | 137 gaia_gurl, |
| 137 URLFetcher::POST, | 138 URLFetcher::POST, |
| 138 delegate); | 139 delegate); |
| 139 to_return->set_request_context(getter); | 140 to_return->set_request_context(getter); |
| 140 to_return->set_upload_data("application/x-www-form-urlencoded", body); | 141 to_return->set_upload_data("application/x-www-form-urlencoded", body); |
| 141 | 142 |
| 142 // The Gaia token exchange requests do not require any cookie-based | 143 // The Gaia token exchange requests do not require any cookie-based |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 void GaiaAuthFetcher::OnMergeSessionFetched(const std::string& data, | 573 void GaiaAuthFetcher::OnMergeSessionFetched(const std::string& data, |
| 573 const net::URLRequestStatus& status, | 574 const net::URLRequestStatus& status, |
| 574 int response_code) { | 575 int response_code) { |
| 575 if (status.is_success() && response_code == RC_REQUEST_OK) { | 576 if (status.is_success() && response_code == RC_REQUEST_OK) { |
| 576 consumer_->OnMergeSessionSuccess(data); | 577 consumer_->OnMergeSessionSuccess(data); |
| 577 } else { | 578 } else { |
| 578 consumer_->OnMergeSessionFailure(GenerateAuthError(data, status)); | 579 consumer_->OnMergeSessionFailure(GenerateAuthError(data, status)); |
| 579 } | 580 } |
| 580 } | 581 } |
| 581 | 582 |
| 582 void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source, | 583 void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source) { |
| 583 const GURL& url, | |
| 584 const net::URLRequestStatus& status, | |
| 585 int response_code, | |
| 586 const net::ResponseCookies& cookies, | |
| 587 const std::string& data) { | |
| 588 fetch_pending_ = false; | 584 fetch_pending_ = false; |
| 585 const GURL& url = source->url(); |
| 586 const net::URLRequestStatus& status = source->status(); |
| 587 int response_code = source->response_code(); |
| 588 std::string data; |
| 589 source->GetResponseAsString(&data); |
| 589 if (url == client_login_gurl_) { | 590 if (url == client_login_gurl_) { |
| 590 OnClientLoginFetched(data, status, response_code); | 591 OnClientLoginFetched(data, status, response_code); |
| 591 } else if (url == issue_auth_token_gurl_) { | 592 } else if (url == issue_auth_token_gurl_) { |
| 592 OnIssueAuthTokenFetched(data, status, response_code); | 593 OnIssueAuthTokenFetched(data, status, response_code); |
| 593 } else if (url == get_user_info_gurl_) { | 594 } else if (url == get_user_info_gurl_) { |
| 594 OnGetUserInfoFetched(data, status, response_code); | 595 OnGetUserInfoFetched(data, status, response_code); |
| 595 } else if (url == token_auth_gurl_) { | 596 } else if (url == token_auth_gurl_) { |
| 596 OnTokenAuthFetched(data, status, response_code); | 597 OnTokenAuthFetched(data, status, response_code); |
| 597 } else if (url == merge_session_gurl_ || | 598 } else if (url == merge_session_gurl_ || |
| 598 (source && source->original_url() == merge_session_gurl_)) { | 599 (source && source->original_url() == merge_session_gurl_)) { |
| 599 // MergeSession may redirect, so check the original URL of the fetcher. | 600 // MergeSession may redirect, so check the original URL of the fetcher. |
| 600 OnMergeSessionFetched(data, status, response_code); | 601 OnMergeSessionFetched(data, status, response_code); |
| 601 } else { | 602 } else { |
| 602 NOTREACHED(); | 603 NOTREACHED(); |
| 603 } | 604 } |
| 604 } | 605 } |
| 605 | 606 |
| 606 // static | 607 // static |
| 607 bool GaiaAuthFetcher::IsSecondFactorSuccess( | 608 bool GaiaAuthFetcher::IsSecondFactorSuccess( |
| 608 const std::string& alleged_error) { | 609 const std::string& alleged_error) { |
| 609 return alleged_error.find(kSecondFactor) != | 610 return alleged_error.find(kSecondFactor) != |
| 610 std::string::npos; | 611 std::string::npos; |
| 611 } | 612 } |
| OLD | NEW |