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/printing/cloud_print/cloud_print_setup_message_handler.
h" | 5 #include "chrome/browser/printing/cloud_print/cloud_print_setup_message_handler.
h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 void CloudPrintSetupMessageHandler::HandleSubmitAuth(const ListValue* args) { | 30 void CloudPrintSetupMessageHandler::HandleSubmitAuth(const ListValue* args) { |
31 std::string json; | 31 std::string json; |
32 bool ret = args->GetString(0, &json); | 32 bool ret = args->GetString(0, &json); |
33 std::string username, password, captcha, access_code; | 33 std::string username, password, captcha, access_code; |
34 if (!ret || json.empty()) { | 34 if (!ret || json.empty()) { |
35 NOTREACHED() << "Empty json string"; | 35 NOTREACHED() << "Empty json string"; |
36 return; | 36 return; |
37 } | 37 } |
38 | 38 |
39 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false)); | 39 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); |
40 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) { | 40 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) { |
41 NOTREACHED() << "Unable to parse auth data"; | 41 NOTREACHED() << "Unable to parse auth data"; |
42 return; | 42 return; |
43 } | 43 } |
44 | 44 |
45 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 45 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
46 if (!result->GetString("user", &username) || | 46 if (!result->GetString("user", &username) || |
47 !result->GetString("pass", &password) || | 47 !result->GetString("pass", &password) || |
48 !result->GetString("captcha", &captcha) || | 48 !result->GetString("captcha", &captcha) || |
49 !result->GetString("access_code", &access_code)) { | 49 !result->GetString("access_code", &access_code)) { |
50 NOTREACHED() << "Unable to parse auth data"; | 50 NOTREACHED() << "Unable to parse auth data"; |
51 return; | 51 return; |
52 } | 52 } |
53 | 53 |
54 // Pass the information to the flow. | 54 // Pass the information to the flow. |
55 if (flow_) | 55 if (flow_) |
56 flow_->OnUserSubmittedAuth(username, password, captcha, access_code); | 56 flow_->OnUserSubmittedAuth(username, password, captcha, access_code); |
57 } | 57 } |
58 | 58 |
59 void CloudPrintSetupMessageHandler::HandlePrintTestPage(const ListValue* args) { | 59 void CloudPrintSetupMessageHandler::HandlePrintTestPage(const ListValue* args) { |
60 if (flow_) | 60 if (flow_) |
61 flow_->OnUserClickedPrintTestPage(); | 61 flow_->OnUserClickedPrintTestPage(); |
62 } | 62 } |
63 | 63 |
64 void CloudPrintSetupMessageHandler::HandleLearnMore(const ListValue* args) { | 64 void CloudPrintSetupMessageHandler::HandleLearnMore(const ListValue* args) { |
65 if (flow_) | 65 if (flow_) |
66 flow_->OnUserClickedLearnMore(); | 66 flow_->OnUserClickedLearnMore(); |
67 } | 67 } |
OLD | NEW |