| 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/ui/autologin_infobar_delegate.h" | 5 #include "chrome/browser/ui/autologin_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 AutoLoginRedirector(TabContentsWrapper* tab_contents_wrapper, | 45 AutoLoginRedirector(TabContentsWrapper* tab_contents_wrapper, |
| 46 const std::string& args); | 46 const std::string& args); |
| 47 virtual ~AutoLoginRedirector(); | 47 virtual ~AutoLoginRedirector(); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 // NotificationObserver override. | 50 // NotificationObserver override. |
| 51 virtual void Observe(int type, | 51 virtual void Observe(int type, |
| 52 const NotificationSource& source, | 52 const NotificationSource& source, |
| 53 const NotificationDetails& details) OVERRIDE; | 53 const NotificationDetails& details) OVERRIDE; |
| 54 | 54 |
| 55 // Redirect tab to TokenAuth URL, logging the user in and navigating | 55 // Redirect tab to MergeSession URL, logging the user in and navigating |
| 56 // to the desired page. | 56 // to the desired page. |
| 57 void RedirectToTokenAuth(const std::string& token); | 57 void RedirectToMergeSession(const std::string& token); |
| 58 | 58 |
| 59 TabContentsWrapper* tab_contents_wrapper_; | 59 TabContentsWrapper* tab_contents_wrapper_; |
| 60 const std::string args_; | 60 const std::string args_; |
| 61 NotificationRegistrar registrar_; | 61 NotificationRegistrar registrar_; |
| 62 | 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(AutoLoginRedirector); | 63 DISALLOW_COPY_AND_ASSIGN(AutoLoginRedirector); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 AutoLoginRedirector::AutoLoginRedirector( | 66 AutoLoginRedirector::AutoLoginRedirector( |
| 67 TabContentsWrapper* tab_contents_wrapper, const std::string& args) | 67 TabContentsWrapper* tab_contents_wrapper, const std::string& args) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 88 const NotificationDetails& details) { | 88 const NotificationDetails& details) { |
| 89 DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE || | 89 DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE || |
| 90 type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED); | 90 type == chrome::NOTIFICATION_TOKEN_REQUEST_FAILED); |
| 91 | 91 |
| 92 // We are only interested in GAIA tokens. | 92 // We are only interested in GAIA tokens. |
| 93 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { | 93 if (type == chrome::NOTIFICATION_TOKEN_AVAILABLE) { |
| 94 TokenService::TokenAvailableDetails* tok_details = | 94 TokenService::TokenAvailableDetails* tok_details = |
| 95 Details<TokenService::TokenAvailableDetails>(details).ptr(); | 95 Details<TokenService::TokenAvailableDetails>(details).ptr(); |
| 96 | 96 |
| 97 if (tok_details->service() == GaiaConstants::kGaiaService) { | 97 if (tok_details->service() == GaiaConstants::kGaiaService) { |
| 98 RedirectToTokenAuth(tok_details->token()); | 98 RedirectToMergeSession(tok_details->token()); |
| 99 delete this; | 99 delete this; |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 } else { | 102 } else { |
| 103 TokenService::TokenRequestFailedDetails* tok_details = | 103 TokenService::TokenRequestFailedDetails* tok_details = |
| 104 Details<TokenService::TokenRequestFailedDetails>(details).ptr(); | 104 Details<TokenService::TokenRequestFailedDetails>(details).ptr(); |
| 105 | 105 |
| 106 if (tok_details->service() == GaiaConstants::kGaiaService) { | 106 if (tok_details->service() == GaiaConstants::kGaiaService) { |
| 107 LOG(WARNING) << "AutoLoginRedirector: token request failed"; | 107 LOG(WARNING) << "AutoLoginRedirector: token request failed"; |
| 108 delete this; | 108 delete this; |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void AutoLoginRedirector::RedirectToTokenAuth(const std::string& token) { | 114 void AutoLoginRedirector::RedirectToMergeSession(const std::string& token) { |
| 115 // The args are URL encoded, so we need to decode them before use. | 115 // The args are URL encoded, so we need to decode them before use. |
| 116 url_canon::RawCanonOutputT<char16> output; | 116 url_canon::RawCanonOutputT<char16> output; |
| 117 url_util::DecodeURLEscapeSequences(args_.c_str(), args_.length(), &output); | 117 url_util::DecodeURLEscapeSequences(args_.c_str(), args_.length(), &output); |
| 118 std::string unescaped_args; | 118 std::string unescaped_args; |
| 119 UTF16ToUTF8(output.data(), output.length(), &unescaped_args); | 119 UTF16ToUTF8(output.data(), output.length(), &unescaped_args); |
| 120 | 120 |
| 121 const char kUrlFormat[] = "%s?" | 121 const char kUrlFormat[] = "%s?" |
| 122 "source=chrome&" | 122 "source=chrome&" |
| 123 "auth=%s&" | 123 "uberauth=%s&" |
| 124 "%s"; | 124 "%s"; |
| 125 const std::string url_string = GaiaUrls::GetInstance()->token_auth_url(); | 125 const std::string url_string = GaiaUrls::GetInstance()->merge_session_url(); |
| 126 std::string url = base::StringPrintf(kUrlFormat, | 126 std::string url = base::StringPrintf(kUrlFormat, |
| 127 url_string.c_str(), | 127 url_string.c_str(), |
| 128 token.c_str(), | 128 token.c_str(), |
| 129 unescaped_args.c_str()); | 129 unescaped_args.c_str()); |
| 130 | 130 |
| 131 // TODO(rogerta): what is the correct page transition? | 131 // TODO(rogerta): what is the correct page transition? |
| 132 tab_contents_wrapper_->tab_contents()->controller().LoadURL(GURL(url), | 132 tab_contents_wrapper_->tab_contents()->controller().LoadURL(GURL(url), |
| 133 GURL(), PageTransition::AUTO_BOOKMARK); | 133 GURL(), PageTransition::AUTO_BOOKMARK); |
| 134 } | 134 } |
| 135 | 135 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 new AutoLoginRedirector(tab_contents_wrapper_, args_); | 284 new AutoLoginRedirector(tab_contents_wrapper_, args_); |
| 285 return true; | 285 return true; |
| 286 } | 286 } |
| 287 | 287 |
| 288 bool AutoLoginInfoBarDelegate::Cancel() { | 288 bool AutoLoginInfoBarDelegate::Cancel() { |
| 289 PrefService* user_prefs = tab_contents_wrapper_->profile()->GetPrefs(); | 289 PrefService* user_prefs = tab_contents_wrapper_->profile()->GetPrefs(); |
| 290 user_prefs->SetBoolean(prefs::kAutologinEnabled, false); | 290 user_prefs->SetBoolean(prefs::kAutologinEnabled, false); |
| 291 user_prefs->ScheduleSavePersistentPrefs(); | 291 user_prefs->ScheduleSavePersistentPrefs(); |
| 292 return true; | 292 return true; |
| 293 } | 293 } |
| OLD | NEW |