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

Side by Side Diff: chrome/browser/printing/cloud_print/cloud_print_setup_message_handler.cc

Issue 3450021: Cloud print proxy management UI. (Closed)
Patch Set: Fix nits. Created 10 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/printing/cloud_print/cloud_print_setup_message_handler. h"
6
7 #include "base/scoped_ptr.h"
8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h"
10 #include "chrome/browser/dom_ui/dom_ui_util.h"
11 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
12
13 DOMMessageHandler* CloudPrintSetupMessageHandler::Attach(DOMUI* dom_ui) {
14 // Pass the DOMUI object to the setup flow.
15 flow_->Attach(dom_ui);
16 return DOMMessageHandler::Attach(dom_ui);
17 }
18
19 void CloudPrintSetupMessageHandler::RegisterMessages() {
20 dom_ui_->RegisterMessageCallback("SubmitAuth",
21 NewCallback(this, &CloudPrintSetupMessageHandler::HandleSubmitAuth));
22 }
23
24 void CloudPrintSetupMessageHandler::HandleSubmitAuth(const ListValue* args) {
25 std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args));
26 std::string username, password, captcha;
27 if (json.empty())
28 return;
29
30 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
31 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) {
32 NOTREACHED() << "Unable to parse auth data";
33 return;
34 }
35
36 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
37 if (!result->GetString("user", &username) ||
38 !result->GetString("pass", &password) ||
39 !result->GetString("captcha", &captcha)) {
40 NOTREACHED() << "Unable to parse auth data";
41 return;
42 }
43
44 // Pass the information to the flow.
45 if (flow_)
46 flow_->OnUserSubmittedAuth(username, password, captcha);
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698