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/automation/automation_provider_json.h" | 5 #include "chrome/browser/automation/automation_provider_json.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 AutomationJSONReply::~AutomationJSONReply() { | 29 AutomationJSONReply::~AutomationJSONReply() { |
30 DCHECK(!message_) << "JSON automation request not replied!"; | 30 DCHECK(!message_) << "JSON automation request not replied!"; |
31 } | 31 } |
32 | 32 |
33 void AutomationJSONReply::SendSuccess(const Value* value) { | 33 void AutomationJSONReply::SendSuccess(const Value* value) { |
34 DCHECK(message_) << "Resending reply for JSON automation request"; | 34 DCHECK(message_) << "Resending reply for JSON automation request"; |
35 std::string json_string = "{}"; | 35 std::string json_string = "{}"; |
36 if (value) | 36 if (value) |
37 base::JSONWriter::Write(value, false, &json_string); | 37 base::JSONWriter::Write(value, &json_string); |
38 AutomationMsg_SendJSONRequest::WriteReplyParams( | 38 AutomationMsg_SendJSONRequest::WriteReplyParams( |
39 message_, json_string, true); | 39 message_, json_string, true); |
40 provider_->Send(message_); | 40 provider_->Send(message_); |
41 message_ = NULL; | 41 message_ = NULL; |
42 } | 42 } |
43 | 43 |
44 void AutomationJSONReply::SendError(const std::string& error_message) { | 44 void AutomationJSONReply::SendError(const std::string& error_message) { |
45 SendError(Error(error_message)); | 45 SendError(Error(error_message)); |
46 } | 46 } |
47 | 47 |
48 void AutomationJSONReply::SendErrorCode(ErrorCode code) { | 48 void AutomationJSONReply::SendErrorCode(ErrorCode code) { |
49 SendError(Error(code)); | 49 SendError(Error(code)); |
50 } | 50 } |
51 | 51 |
52 void AutomationJSONReply::SendError(const Error& error) { | 52 void AutomationJSONReply::SendError(const Error& error) { |
53 DCHECK(message_) << "Resending reply for JSON automation request"; | 53 DCHECK(message_) << "Resending reply for JSON automation request"; |
54 | 54 |
55 base::DictionaryValue dict; | 55 base::DictionaryValue dict; |
56 dict.SetString("error", error.message()); | 56 dict.SetString("error", error.message()); |
57 dict.SetInteger("code", error.code()); | 57 dict.SetInteger("code", error.code()); |
58 std::string json; | 58 std::string json; |
59 base::JSONWriter::Write(&dict, false /* pretty_print */, &json); | 59 base::JSONWriter::Write(&dict, &json); |
60 | 60 |
61 AutomationMsg_SendJSONRequest::WriteReplyParams(message_, json, false); | 61 AutomationMsg_SendJSONRequest::WriteReplyParams(message_, json, false); |
62 provider_->Send(message_); | 62 provider_->Send(message_); |
63 message_ = NULL; | 63 message_ = NULL; |
64 } | 64 } |
65 | 65 |
66 bool GetBrowserFromJSONArgs( | 66 bool GetBrowserFromJSONArgs( |
67 DictionaryValue* args, | 67 DictionaryValue* args, |
68 Browser** browser, | 68 Browser** browser, |
69 std::string* error) { | 69 std::string* error) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 bool GetEnabledExtensionFromJSONArgs( | 225 bool GetEnabledExtensionFromJSONArgs( |
226 base::DictionaryValue* args, | 226 base::DictionaryValue* args, |
227 const std::string& key, | 227 const std::string& key, |
228 Profile* profile, | 228 Profile* profile, |
229 const Extension** extension, | 229 const Extension** extension, |
230 std::string* error) { | 230 std::string* error) { |
231 return GetExtensionFromJSONArgsHelper( | 231 return GetExtensionFromJSONArgsHelper( |
232 args, key, profile, false /* include_disabled */, extension, error); | 232 args, key, profile, false /* include_disabled */, extension, error); |
233 } | 233 } |
OLD | NEW |