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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 bool DomAutomationController::SendMsg(const gin::Arguments& args) { | 84 bool DomAutomationController::SendMsg(const gin::Arguments& args) { |
85 if (!render_frame()) | 85 if (!render_frame()) |
86 return false; | 86 return false; |
87 | 87 |
88 if (automation_id_ == MSG_ROUTING_NONE) | 88 if (automation_id_ == MSG_ROUTING_NONE) |
89 return false; | 89 return false; |
90 | 90 |
91 std::string json; | 91 std::string json; |
92 JSONStringValueSerializer serializer(&json); | 92 JSONStringValueSerializer serializer(&json); |
93 scoped_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() || | 102 (args.PeekNext()->IsString() || args.PeekNext()->IsBoolean() || |
103 args.PeekNext()->IsNumber())) { | 103 args.PeekNext()->IsNumber())) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return Send( | 138 return Send( |
139 new FrameHostMsg_DomOperationResponse(routing_id(), str)); | 139 new FrameHostMsg_DomOperationResponse(routing_id(), str)); |
140 } | 140 } |
141 | 141 |
142 bool DomAutomationController::SetAutomationId(int automation_id) { | 142 bool DomAutomationController::SetAutomationId(int automation_id) { |
143 automation_id_ = automation_id; | 143 automation_id_ = automation_id; |
144 return true; | 144 return true; |
145 } | 145 } |
146 | 146 |
147 } // namespace content | 147 } // namespace content |
OLD | NEW |