Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_helper.cc

Issue 9592015: Added multi-login support to one-click signin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix member init order in ctor" Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/sync/one_click_signin_helper.h" 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/infobars/infobar_tab_helper.h" 10 #include "chrome/browser/infobars/infobar_tab_helper.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // The user clicked on the learn more link in the infobar. 55 // The user clicked on the learn more link in the infobar.
56 HISTOGRAM_LEARN_MORE, 56 HISTOGRAM_LEARN_MORE,
57 57
58 HISTOGRAM_MAX 58 HISTOGRAM_MAX
59 }; 59 };
60 60
61 // The infobar asking the user if they want to use one-click sign in. 61 // The infobar asking the user if they want to use one-click sign in.
62 class OneClickLoginInfoBarDelegate : public ConfirmInfoBarDelegate { 62 class OneClickLoginInfoBarDelegate : public ConfirmInfoBarDelegate {
63 public: 63 public:
64 OneClickLoginInfoBarDelegate(InfoBarTabHelper* owner, 64 OneClickLoginInfoBarDelegate(InfoBarTabHelper* owner,
65 const std::string& session_index,
65 const std::string& email, 66 const std::string& email,
66 const std::string& password); 67 const std::string& password);
67 virtual ~OneClickLoginInfoBarDelegate(); 68 virtual ~OneClickLoginInfoBarDelegate();
68 69
69 private: 70 private:
70 // ConfirmInfoBarDelegate overrides. 71 // ConfirmInfoBarDelegate overrides.
71 virtual void InfoBarDismissed() OVERRIDE; 72 virtual void InfoBarDismissed() OVERRIDE;
72 virtual gfx::Image* GetIcon() const OVERRIDE; 73 virtual gfx::Image* GetIcon() const OVERRIDE;
73 virtual Type GetInfoBarType() const OVERRIDE; 74 virtual Type GetInfoBarType() const OVERRIDE;
74 virtual string16 GetMessageText() const OVERRIDE; 75 virtual string16 GetMessageText() const OVERRIDE;
75 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 76 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
76 virtual bool Accept() OVERRIDE; 77 virtual bool Accept() OVERRIDE;
77 virtual bool Cancel() OVERRIDE; 78 virtual bool Cancel() OVERRIDE;
78 79
79 void RecordHistogramAction(int action); 80 void RecordHistogramAction(int action);
80 81
81 Profile* profile_; 82 Profile* profile_;
82 83
83 // Email address and password of the account that has just logged in. 84 // Information about the account that has just logged in.
85 std::string session_index_;
84 std::string email_; 86 std::string email_;
85 std::string password_; 87 std::string password_;
86 88
87 // Whether any UI controls in the infobar were pressed or not. 89 // Whether any UI controls in the infobar were pressed or not.
88 bool button_pressed_; 90 bool button_pressed_;
89 91
90 DISALLOW_COPY_AND_ASSIGN(OneClickLoginInfoBarDelegate); 92 DISALLOW_COPY_AND_ASSIGN(OneClickLoginInfoBarDelegate);
91 }; 93 };
92 94
93 OneClickLoginInfoBarDelegate::OneClickLoginInfoBarDelegate( 95 OneClickLoginInfoBarDelegate::OneClickLoginInfoBarDelegate(
94 InfoBarTabHelper* owner, 96 InfoBarTabHelper* owner,
97 const std::string& session_index,
95 const std::string& email, 98 const std::string& email,
96 const std::string& password) 99 const std::string& password)
97 : ConfirmInfoBarDelegate(owner), 100 : ConfirmInfoBarDelegate(owner),
98 profile_(Profile::FromBrowserContext( 101 profile_(Profile::FromBrowserContext(
99 owner->web_contents()->GetBrowserContext())), 102 owner->web_contents()->GetBrowserContext())),
103 session_index_(session_index),
100 email_(email), 104 email_(email),
101 password_(password), 105 password_(password),
102 button_pressed_(false) { 106 button_pressed_(false) {
103 DCHECK(profile_); 107 DCHECK(profile_);
104 RecordHistogramAction(HISTOGRAM_SHOWN); 108 RecordHistogramAction(HISTOGRAM_SHOWN);
105 } 109 }
106 110
107 OneClickLoginInfoBarDelegate::~OneClickLoginInfoBarDelegate() { 111 OneClickLoginInfoBarDelegate::~OneClickLoginInfoBarDelegate() {
108 if (!button_pressed_) 112 if (!button_pressed_)
109 RecordHistogramAction(HISTOGRAM_IGNORED); 113 RecordHistogramAction(HISTOGRAM_IGNORED);
(...skipping 18 matching lines...) Expand all
128 } 132 }
129 133
130 string16 OneClickLoginInfoBarDelegate::GetButtonLabel( 134 string16 OneClickLoginInfoBarDelegate::GetButtonLabel(
131 InfoBarButton button) const { 135 InfoBarButton button) const {
132 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 136 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
133 IDS_OK : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON); 137 IDS_OK : IDS_ONE_CLICK_SIGNIN_INFOBAR_CANCEL_BUTTON);
134 } 138 }
135 139
136 bool OneClickLoginInfoBarDelegate::Accept() { 140 bool OneClickLoginInfoBarDelegate::Accept() {
137 RecordHistogramAction(HISTOGRAM_ACCEPTED); 141 RecordHistogramAction(HISTOGRAM_ACCEPTED);
138 ShowOneClickSigninDialog(profile_, email_, password_); 142 ShowOneClickSigninDialog(profile_, session_index_, email_, password_);
139 button_pressed_ = true; 143 button_pressed_ = true;
140 return true; 144 return true;
141 } 145 }
142 146
143 bool OneClickLoginInfoBarDelegate::Cancel() { 147 bool OneClickLoginInfoBarDelegate::Cancel() {
144 PrefService* pref_service = 148 PrefService* pref_service =
145 TabContentsWrapper::GetCurrentWrapperForContents( 149 TabContentsWrapper::GetCurrentWrapperForContents(
146 owner()->web_contents())->profile()->GetPrefs(); 150 owner()->web_contents())->profile()->GetPrefs();
147 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false); 151 pref_service->SetBoolean(prefs::kReverseAutologinEnabled, false);
148 RecordHistogramAction(HISTOGRAM_REJECTED); 152 RecordHistogramAction(HISTOGRAM_REJECTED);
(...skipping 21 matching lines...) Expand all
170 request->GetResponseHeaderByName("X-Google-Accounts-SignIn", &value); 174 request->GetResponseHeaderByName("X-Google-Accounts-SignIn", &value);
171 if (value.empty()) 175 if (value.empty())
172 return; 176 return;
173 177
174 std::vector<std::pair<std::string, std::string> > pairs; 178 std::vector<std::pair<std::string, std::string> > pairs;
175 if (!base::SplitStringIntoKeyValuePairs(value, '=', ',', &pairs)) 179 if (!base::SplitStringIntoKeyValuePairs(value, '=', ',', &pairs))
176 return; 180 return;
177 181
178 // Parse the information from the value string. 182 // Parse the information from the value string.
179 std::string email; 183 std::string email;
184 std::string session_index;
180 for (size_t i = 0; i < pairs.size(); ++i) { 185 for (size_t i = 0; i < pairs.size(); ++i) {
181 const std::pair<std::string, std::string>& pair = pairs[i]; 186 const std::pair<std::string, std::string>& pair = pairs[i];
182 if (pair.first == "email") 187 if (pair.first == "email") {
183 TrimString(pair.second, "\"", &email); 188 TrimString(pair.second, "\"", &email);
189 } else if (pair.first == "sessionindex") {
190 session_index = pair.second;
191 }
184 } 192 }
185 193
186 if (email.empty()) 194 if (email.empty() || session_index.empty())
187 return; 195 return;
188 196
189 content::BrowserThread::PostTask( 197 content::BrowserThread::PostTask(
190 content::BrowserThread::UI, FROM_HERE, 198 content::BrowserThread::UI, FROM_HERE,
191 base::Bind(&OneClickSigninHelper::ShowInfoBarUIThread, email, 199 base::Bind(&OneClickSigninHelper::ShowInfoBarUIThread, session_index,
192 child_id, route_id)); 200 email, child_id, route_id));
193 } 201 }
194 202
195 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents) 203 OneClickSigninHelper::OneClickSigninHelper(content::WebContents* web_contents)
196 : content::WebContentsObserver(web_contents) { 204 : content::WebContentsObserver(web_contents) {
197 } 205 }
198 206
199 OneClickSigninHelper::~OneClickSigninHelper() { 207 OneClickSigninHelper::~OneClickSigninHelper() {
200 } 208 }
201 209
202 // static 210 // static
203 void OneClickSigninHelper::ShowInfoBarUIThread( 211 void OneClickSigninHelper::ShowInfoBarUIThread(
212 const std::string& session_index,
204 const std::string& email, 213 const std::string& email,
205 int child_id, 214 int child_id,
206 int route_id) { 215 int route_id) {
207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 216 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
208 217
209 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id, 218 content::WebContents* web_contents = tab_util::GetWebContentsByID(child_id,
210 route_id); 219 route_id);
211 if (!web_contents) 220 if (!web_contents)
212 return; 221 return;
213 222
(...skipping 16 matching lines...) Expand all
230 return; 239 return;
231 240
232 // TODO(rogerta): remove this #if once the dialog is fully implemented for 241 // TODO(rogerta): remove this #if once the dialog is fully implemented for
233 // mac and linux. 242 // mac and linux.
234 #if defined(ENABLE_ONE_CLICK_SIGNIN) 243 #if defined(ENABLE_ONE_CLICK_SIGNIN)
235 // Save the email in the one-click signin manager. The manager may 244 // Save the email in the one-click signin manager. The manager may
236 // not exist if the contents is incognito or if the profile is already 245 // not exist if the contents is incognito or if the profile is already
237 // connected to a Google account. 246 // connected to a Google account.
238 OneClickSigninHelper* helper = wrapper->one_click_signin_helper(); 247 OneClickSigninHelper* helper = wrapper->one_click_signin_helper();
239 if (helper) 248 if (helper)
240 helper->SaveEmail(email); 249 helper->SaveSessionIndexAndEmail(session_index, email);
241 #endif 250 #endif
242 } 251 }
243 252
244 void OneClickSigninHelper::DidNavigateAnyFrame( 253 void OneClickSigninHelper::DidNavigateAnyFrame(
245 const content::LoadCommittedDetails& details, 254 const content::LoadCommittedDetails& details,
246 const content::FrameNavigateParams& params) { 255 const content::FrameNavigateParams& params) {
247 if (params.password_form.origin.is_valid()) 256 if (params.password_form.origin.is_valid())
248 SavePassword(UTF16ToUTF8(params.password_form.password_value)); 257 SavePassword(UTF16ToUTF8(params.password_form.password_value));
249 } 258 }
250 259
251 void OneClickSigninHelper::DidStopLoading() { 260 void OneClickSigninHelper::DidStopLoading() {
252 if (email_.empty() || password_.empty()) 261 if (email_.empty() || password_.empty())
253 return; 262 return;
254 263
255 TabContentsWrapper* wrapper = 264 TabContentsWrapper* wrapper =
256 TabContentsWrapper::GetCurrentWrapperForContents(web_contents()); 265 TabContentsWrapper::GetCurrentWrapperForContents(web_contents());
257 266
258 wrapper->infobar_tab_helper()->AddInfoBar( 267 wrapper->infobar_tab_helper()->AddInfoBar(
259 new OneClickLoginInfoBarDelegate(wrapper->infobar_tab_helper(), 268 new OneClickLoginInfoBarDelegate(wrapper->infobar_tab_helper(),
260 email_, password_)); 269 session_index_, email_, password_));
261 270
262 email_.clear(); 271 email_.clear();
263 password_.clear(); 272 password_.clear();
264 } 273 }
265 274
266 void OneClickSigninHelper::SaveEmail(const std::string& email) { 275 void OneClickSigninHelper::SaveSessionIndexAndEmail(
267 // TODO(rogerta): validate that the email address is the same as set in 276 const std::string& session_index,
268 // the form? 277 const std::string& email) {
278 session_index_ = session_index;
269 email_ = email; 279 email_ = email;
270 } 280 }
271 281
272 void OneClickSigninHelper::SavePassword(const std::string& password) { 282 void OneClickSigninHelper::SavePassword(const std::string& password) {
273 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of 283 // TODO(rogerta): in the case of a 2-factor or captcha or some other type of
274 // challenge, its possible for the user to never complete the signin. 284 // challenge, its possible for the user to never complete the signin.
275 // Should have a way to detect this and clear the password member. 285 // Should have a way to detect this and clear the password member.
276 password_ = password; 286 password_ = password;
277 } 287 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/sync/one_click_signin_helper.h ('k') | chrome/browser/ui/sync/one_click_signin_sync_starter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698