| 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/browser/chromeos/login/issue_response_handler.h" | 5 #include "chrome/browser/chromeos/login/issue_response_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/net/chrome_url_request_context.h" | 10 #include "chrome/browser/net/chrome_url_request_context.h" |
| 11 #include "chrome/common/net/gaia/gaia_urls.h" | 11 #include "chrome/common/net/gaia/gaia_urls.h" |
| 12 #include "content/common/url_fetcher.h" | 12 #include "content/common/url_fetcher.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 // Overridden from AuthResponseHandler. | 17 // Overridden from AuthResponseHandler. |
| 18 bool IssueResponseHandler::CanHandle(const GURL& url) { | 18 bool IssueResponseHandler::CanHandle(const GURL& url) { |
| 19 return (url.spec().find(GaiaUrls::GetInstance()->issue_auth_token_url()) != | 19 return (url.spec().find(GaiaUrls::GetInstance()->issue_auth_token_url()) != |
| 20 std::string::npos); | 20 std::string::npos); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // Overridden from AuthResponseHandler. | 23 // Overridden from AuthResponseHandler. |
| 24 URLFetcher* IssueResponseHandler::Handle( | 24 URLFetcher* IssueResponseHandler::Handle( |
| 25 const std::string& to_process, | 25 const std::string& to_process, |
| 26 URLFetcher::Delegate* catcher) { | 26 URLFetcher::Delegate* catcher) { |
| 27 VLOG(1) << "Handling IssueAuthToken response"; | 27 VLOG(1) << "Handling IssueAuthToken response"; |
| 28 token_url_.assign(base::StringPrintf("%s%s", | 28 token_url_.assign(BuildTokenAuthUrlWithToken(to_process)); |
| 29 GaiaUrls::GetInstance()->token_auth_url().c_str(), to_process.c_str())); | |
| 30 URLFetcher* fetcher = | 29 URLFetcher* fetcher = |
| 31 new URLFetcher(GURL(token_url_), URLFetcher::GET, catcher); | 30 new URLFetcher(GURL(token_url_), URLFetcher::GET, catcher); |
| 32 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); | 31 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); |
| 33 if (getter_) { | 32 if (getter_) { |
| 34 VLOG(1) << "Fetching " << GaiaUrls::GetInstance()->token_auth_url(); | 33 VLOG(1) << "Fetching " << GaiaUrls::GetInstance()->token_auth_url(); |
| 35 fetcher->set_request_context(getter_); | 34 fetcher->set_request_context(getter_); |
| 36 fetcher->Start(); | 35 fetcher->Start(); |
| 37 } | 36 } |
| 38 return fetcher; | 37 return fetcher; |
| 39 } | 38 } |
| 40 | 39 |
| 40 // static |
| 41 std::string IssueResponseHandler::BuildTokenAuthUrlWithToken( |
| 42 const std::string& token) { |
| 43 const char kUrlFormat[] = "%s?" |
| 44 "continue=http://www.google.com/webhp&" |
| 45 "source=chromeos&" |
| 46 "auth=%s"; |
| 47 return base::StringPrintf(kUrlFormat, |
| 48 GaiaUrls::GetInstance()->token_auth_url().c_str(), |
| 49 token.c_str()); |
| 50 } |
| 51 |
| 41 } // namespace chromeos | 52 } // namespace chromeos |
| OLD | NEW |