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 "content/renderer/dom_automation_controller.h" | 5 #include "content/renderer/dom_automation_controller.h" |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/child/v8_value_converter_impl.h" | 9 #include "content/child/v8_value_converter_impl.h" |
10 #include "content/common/child_process_messages.h" | 10 #include "content/common/child_process_messages.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 std::string json; | 91 std::string json; |
92 JSONStringValueSerializer serializer(&json); | 92 JSONStringValueSerializer serializer(&json); |
93 std::unique_ptr<base::Value> value; | 93 std::unique_ptr<base::Value> value; |
94 | 94 |
95 // Warning: note that JSON officially requires the root-level object to be | 95 // Warning: note that JSON officially requires the root-level object to be |
96 // an object (e.g. {foo:3}) or an array, while here we're serializing | 96 // an object (e.g. {foo:3}) or an array, while here we're serializing |
97 // strings, bools, etc. to "JSON". This only works because (a) the JSON | 97 // strings, bools, etc. to "JSON". This only works because (a) the JSON |
98 // writer is lenient, and (b) on the receiving side we wrap the JSON string | 98 // writer is lenient, and (b) on the receiving side we wrap the JSON string |
99 // in square brackets, converting it to an array, then parsing it and | 99 // in square brackets, converting it to an array, then parsing it and |
100 // grabbing the 0th element to get the value out. | 100 // grabbing the 0th element to get the value out. |
101 if (!args.PeekNext().IsEmpty() && | 101 if (!args.PeekNext().IsEmpty()) { |
102 (args.PeekNext()->IsString() || args.PeekNext()->IsBoolean() || | |
103 args.PeekNext()->IsNumber())) { | |
104 V8ValueConverterImpl conv; | 102 V8ValueConverterImpl conv; |
105 value = | 103 value = |
106 conv.FromV8Value(args.PeekNext(), args.isolate()->GetCurrentContext()); | 104 conv.FromV8Value(args.PeekNext(), args.isolate()->GetCurrentContext()); |
107 } else { | 105 } else { |
| 106 NOTREACHED() << "No arguments passed to domAutomationController.send"; |
108 return false; | 107 return false; |
109 } | 108 } |
110 | 109 |
111 if (!serializer.Serialize(*value)) | 110 if (!value || !serializer.Serialize(*value)) |
112 return false; | 111 return false; |
113 | 112 |
114 bool succeeded = Send(new FrameHostMsg_DomOperationResponse( | 113 bool succeeded = Send(new FrameHostMsg_DomOperationResponse( |
115 routing_id(), json)); | 114 routing_id(), json)); |
116 | 115 |
117 automation_id_ = MSG_ROUTING_NONE; | 116 automation_id_ = MSG_ROUTING_NONE; |
118 return succeeded; | 117 return succeeded; |
119 } | 118 } |
120 | 119 |
121 bool DomAutomationController::SendJSON(const std::string& json) { | 120 bool DomAutomationController::SendJSON(const std::string& json) { |
(...skipping 16 matching lines...) Expand all Loading... |
138 return Send( | 137 return Send( |
139 new FrameHostMsg_DomOperationResponse(routing_id(), str)); | 138 new FrameHostMsg_DomOperationResponse(routing_id(), str)); |
140 } | 139 } |
141 | 140 |
142 bool DomAutomationController::SetAutomationId(int automation_id) { | 141 bool DomAutomationController::SetAutomationId(int automation_id) { |
143 automation_id_ = automation_id; | 142 automation_id_ = automation_id; |
144 return true; | 143 return true; |
145 } | 144 } |
146 | 145 |
147 } // namespace content | 146 } // namespace content |
OLD | NEW |