| 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 "chrome/browser/ui/auto_login_info_bar_delegate.h" | 5 #include "chrome/browser/ui/auto_login_info_bar_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 116 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void AutoLoginRedirector::OnUbertokenFailure( | 119 void AutoLoginRedirector::OnUbertokenFailure( |
| 120 const GoogleServiceAuthError& error) { | 120 const GoogleServiceAuthError& error) { |
| 121 LOG(WARNING) << "AutoLoginRedirector: token request failed"; | 121 LOG(WARNING) << "AutoLoginRedirector: token request failed"; |
| 122 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 122 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void AutoLoginRedirector::RedirectToMergeSession(const std::string& token) { | 125 void AutoLoginRedirector::RedirectToMergeSession(const std::string& token) { |
| 126 // The args are URL encoded, so we need to decode them before use. | |
| 127 std::string unescaped_args = | |
| 128 net::UnescapeURLComponent(args_, net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 129 // TODO(rogerta): what is the correct page transition? | 126 // TODO(rogerta): what is the correct page transition? |
| 130 navigation_controller_->LoadURL( | 127 navigation_controller_->LoadURL( |
| 131 GURL(GaiaUrls::GetInstance()->merge_session_url() + | 128 GURL(GaiaUrls::GetInstance()->merge_session_url() + |
| 132 "?source=chrome&uberauth=" + token + "&" + unescaped_args), | 129 "?source=chrome&uberauth=" + token + "&" + args_), |
| 133 content::Referrer(), content::PAGE_TRANSITION_AUTO_BOOKMARK, | 130 content::Referrer(), content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 134 std::string()); | 131 std::string()); |
| 135 } | 132 } |
| 136 | 133 |
| 137 } // namepsace | 134 } // namepsace |
| 138 | 135 |
| 139 | 136 |
| 140 // AutoLoginInfoBarDelegate --------------------------------------------------- | 137 // AutoLoginInfoBarDelegate --------------------------------------------------- |
| 141 | 138 |
| 139 // AutoLoginInfoBarDelegate::Params ------------------------------------------- |
| 140 |
| 141 AutoLoginInfoBarDelegate::Params::Params() {} |
| 142 AutoLoginInfoBarDelegate::Params::~Params() {} |
| 143 |
| 142 AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate( | 144 AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate( |
| 143 InfoBarTabHelper* owner, | 145 InfoBarTabHelper* owner, |
| 144 const std::string& username, | 146 const Params& params) |
| 145 const std::string& args) | |
| 146 : ConfirmInfoBarDelegate(owner), | 147 : ConfirmInfoBarDelegate(owner), |
| 147 username_(username), | 148 params_(params), |
| 148 args_(args), | |
| 149 button_pressed_(false) { | 149 button_pressed_(false) { |
| 150 RecordHistogramAction(HISTOGRAM_SHOWN); | 150 RecordHistogramAction(HISTOGRAM_SHOWN); |
| 151 } | 151 } |
| 152 | 152 |
| 153 AutoLoginInfoBarDelegate::~AutoLoginInfoBarDelegate() { | 153 AutoLoginInfoBarDelegate::~AutoLoginInfoBarDelegate() { |
| 154 if (!button_pressed_) | 154 if (!button_pressed_) |
| 155 RecordHistogramAction(HISTOGRAM_IGNORED); | 155 RecordHistogramAction(HISTOGRAM_IGNORED); |
| 156 } | 156 } |
| 157 | 157 |
| 158 AutoLoginInfoBarDelegate* |
| 159 AutoLoginInfoBarDelegate::AsAutoLoginInfoBarDelegate() { |
| 160 return this; |
| 161 } |
| 162 |
| 158 void AutoLoginInfoBarDelegate::InfoBarDismissed() { | 163 void AutoLoginInfoBarDelegate::InfoBarDismissed() { |
| 159 RecordHistogramAction(HISTOGRAM_DISMISSED); | 164 RecordHistogramAction(HISTOGRAM_DISMISSED); |
| 160 button_pressed_ = true; | 165 button_pressed_ = true; |
| 161 } | 166 } |
| 162 | 167 |
| 163 gfx::Image* AutoLoginInfoBarDelegate::GetIcon() const { | 168 gfx::Image* AutoLoginInfoBarDelegate::GetIcon() const { |
| 164 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 169 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 165 IDR_INFOBAR_AUTOLOGIN); | 170 IDR_INFOBAR_AUTOLOGIN); |
| 166 } | 171 } |
| 167 | 172 |
| 168 InfoBarDelegate::Type AutoLoginInfoBarDelegate::GetInfoBarType() const { | 173 InfoBarDelegate::Type AutoLoginInfoBarDelegate::GetInfoBarType() const { |
| 169 return PAGE_ACTION_TYPE; | 174 return PAGE_ACTION_TYPE; |
| 170 } | 175 } |
| 171 | 176 |
| 172 string16 AutoLoginInfoBarDelegate::GetMessageText() const { | 177 string16 AutoLoginInfoBarDelegate::GetMessageText() const { |
| 173 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, | 178 return GetMessageText(params_.username); |
| 174 UTF8ToUTF16(username_)); | |
| 175 } | 179 } |
| 176 | 180 |
| 177 string16 AutoLoginInfoBarDelegate::GetButtonLabel( | 181 string16 AutoLoginInfoBarDelegate::GetButtonLabel( |
| 178 InfoBarButton button) const { | 182 InfoBarButton button) const { |
| 179 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 183 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 180 IDS_AUTOLOGIN_INFOBAR_OK_BUTTON : IDS_AUTOLOGIN_INFOBAR_CANCEL_BUTTON); | 184 IDS_AUTOLOGIN_INFOBAR_OK_BUTTON : IDS_AUTOLOGIN_INFOBAR_CANCEL_BUTTON); |
| 181 } | 185 } |
| 182 | 186 |
| 183 bool AutoLoginInfoBarDelegate::Accept() { | 187 bool AutoLoginInfoBarDelegate::Accept() { |
| 184 // AutoLoginRedirector deletes itself. | 188 // AutoLoginRedirector deletes itself. |
| 185 new AutoLoginRedirector(&owner()->web_contents()->GetController(), args_); | 189 new AutoLoginRedirector(&owner()->web_contents()->GetController(), |
| 190 params_.args); |
| 186 RecordHistogramAction(HISTOGRAM_ACCEPTED); | 191 RecordHistogramAction(HISTOGRAM_ACCEPTED); |
| 187 button_pressed_ = true; | 192 button_pressed_ = true; |
| 188 return true; | 193 return true; |
| 189 } | 194 } |
| 190 | 195 |
| 191 bool AutoLoginInfoBarDelegate::Cancel() { | 196 bool AutoLoginInfoBarDelegate::Cancel() { |
| 192 PrefService* pref_service = TabContents::FromWebContents( | 197 PrefService* pref_service = TabContents::FromWebContents( |
| 193 owner()->web_contents())->profile()->GetPrefs(); | 198 owner()->web_contents())->profile()->GetPrefs(); |
| 194 pref_service->SetBoolean(prefs::kAutologinEnabled, false); | 199 pref_service->SetBoolean(prefs::kAutologinEnabled, false); |
| 195 RecordHistogramAction(HISTOGRAM_REJECTED); | 200 RecordHistogramAction(HISTOGRAM_REJECTED); |
| 196 button_pressed_ = true; | 201 button_pressed_ = true; |
| 197 return true; | 202 return true; |
| 198 } | 203 } |
| 199 | 204 |
| 205 string16 AutoLoginInfoBarDelegate::GetMessageText( |
| 206 const std::string& username) const { |
| 207 return l10n_util::GetStringFUTF16(IDS_AUTOLOGIN_INFOBAR_MESSAGE, |
| 208 UTF8ToUTF16(username)); |
| 209 } |
| 210 |
| 200 void AutoLoginInfoBarDelegate::RecordHistogramAction(int action) { | 211 void AutoLoginInfoBarDelegate::RecordHistogramAction(int action) { |
| 201 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Regular", action, HISTOGRAM_MAX); | 212 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Regular", action, HISTOGRAM_MAX); |
| 202 } | 213 } |
| OLD | NEW |