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

Side by Side Diff: chrome/browser/sync/sync_setup_flow.cc

Issue 389017: Implement the gaia captcha state and unlock capability in the sync setup wiza... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/sync/sync_setup_flow.h ('k') | chrome/browser/sync/sync_setup_wizard.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/sync/sync_setup_flow.h" 5 #include "chrome/browser/sync/sync_setup_flow.h"
6 6
7 #include "app/gfx/font.h" 7 #include "app/gfx/font.h"
8 #include "app/gfx/font_util.h" 8 #include "app/gfx/font_util.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return result; 48 return result;
49 } 49 }
50 50
51 void FlowHandler::RegisterMessages() { 51 void FlowHandler::RegisterMessages() {
52 dom_ui_->RegisterMessageCallback("SubmitAuth", 52 dom_ui_->RegisterMessageCallback("SubmitAuth",
53 NewCallback(this, &FlowHandler::HandleSubmitAuth)); 53 NewCallback(this, &FlowHandler::HandleSubmitAuth));
54 dom_ui_->RegisterMessageCallback("SubmitMergeAndSync", 54 dom_ui_->RegisterMessageCallback("SubmitMergeAndSync",
55 NewCallback(this, &FlowHandler::HandleSubmitMergeAndSync)); 55 NewCallback(this, &FlowHandler::HandleSubmitMergeAndSync));
56 } 56 }
57 57
58 static bool GetUsernameAndPassword(const std::string& json, 58 static bool GetAuthData(const std::string& json,
59 std::string* username, std::string* password) { 59 std::string* username, std::string* password, std::string* captcha) {
60 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); 60 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
61 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) 61 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY))
62 return false; 62 return false;
63 63
64 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); 64 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
65 if (!result->GetString(L"user", username) || 65 if (!result->GetString(L"user", username) ||
66 !result->GetString(L"pass", password)) { 66 !result->GetString(L"pass", password) ||
67 !result->GetString(L"captcha", captcha)) {
67 return false; 68 return false;
68 } 69 }
69 return true; 70 return true;
70 } 71 }
71 72
72 void FlowHandler::HandleSubmitAuth(const Value* value) { 73 void FlowHandler::HandleSubmitAuth(const Value* value) {
73 std::string json(GetJsonResponse(value)); 74 std::string json(GetJsonResponse(value));
74 std::string username, password; 75 std::string username, password, captcha;
75 if (json.empty()) 76 if (json.empty())
76 return; 77 return;
77 78
78 if (!GetUsernameAndPassword(json, &username, &password)) { 79 if (!GetAuthData(json, &username, &password, &captcha)) {
79 // The page sent us something that we didn't understand. 80 // The page sent us something that we didn't understand.
80 // This probably indicates a programming error. 81 // This probably indicates a programming error.
81 NOTREACHED(); 82 NOTREACHED();
82 return; 83 return;
83 } 84 }
84 85
85 if (flow_) 86 if (flow_)
86 flow_->OnUserSubmittedAuth(username, password); 87 flow_->OnUserSubmittedAuth(username, password, captcha);
87 } 88 }
88 89
89 void FlowHandler::HandleSubmitMergeAndSync(const Value* value) { 90 void FlowHandler::HandleSubmitMergeAndSync(const Value* value) {
90 if (flow_) 91 if (flow_)
91 flow_->OnUserAcceptedMergeAndSync(); 92 flow_->OnUserAcceptedMergeAndSync();
92 } 93 }
93 94
94 // Called by SyncSetupFlow::Advance. 95 // Called by SyncSetupFlow::Advance.
95 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) { 96 void FlowHandler::ShowGaiaLogin(const DictionaryValue& args) {
96 std::string json; 97 std::string json;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 DictionaryValue* args) { 217 DictionaryValue* args) {
217 const GoogleServiceAuthError& error = service->GetAuthError(); 218 const GoogleServiceAuthError& error = service->GetAuthError();
218 if (!service->last_attempted_user_email().empty()) { 219 if (!service->last_attempted_user_email().empty()) {
219 args->SetString(L"user", service->last_attempted_user_email()); 220 args->SetString(L"user", service->last_attempted_user_email());
220 args->SetInteger(L"error", error.state()); 221 args->SetInteger(L"error", error.state());
221 } else { 222 } else {
222 std::wstring user(UTF16ToWide(service->GetAuthenticatedUsername())); 223 std::wstring user(UTF16ToWide(service->GetAuthenticatedUsername()));
223 args->SetString(L"user", user); 224 args->SetString(L"user", user);
224 args->SetInteger(L"error", user.empty() ? 0 : error.state()); 225 args->SetInteger(L"error", user.empty() ? 0 : error.state());
225 } 226 }
227
228 args->SetString(L"captchaUrl", error.captcha().image_url.spec());
226 } 229 }
227 230
228 void SyncSetupFlow::GetDOMMessageHandlers( 231 void SyncSetupFlow::GetDOMMessageHandlers(
229 std::vector<DOMMessageHandler*>* handlers) const { 232 std::vector<DOMMessageHandler*>* handlers) const {
230 handlers->push_back(flow_handler_); 233 handlers->push_back(flow_handler_);
231 } 234 }
232 235
233 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) { 236 bool SyncSetupFlow::ShouldAdvance(SyncSetupWizard::State state) {
234 switch (state) { 237 switch (state) {
235 case SyncSetupWizard::GAIA_LOGIN: 238 case SyncSetupWizard::GAIA_LOGIN:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (!b) 305 if (!b)
303 return NULL; 306 return NULL;
304 307
305 FlowHandler* handler = new FlowHandler(); 308 FlowHandler* handler = new FlowHandler();
306 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args, 309 SyncSetupFlow* flow = new SyncSetupFlow(start, end, json_args,
307 container, handler, service); 310 container, handler, service);
308 handler->set_flow(flow); 311 handler->set_flow(flow);
309 b->BrowserShowHtmlDialog(flow, NULL); 312 b->BrowserShowHtmlDialog(flow, NULL);
310 return flow; 313 return flow;
311 } 314 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_setup_flow.h ('k') | chrome/browser/sync/sync_setup_wizard.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698