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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 if (!sender_) { | 54 if (!sender_) { |
55 NOTREACHED(); | 55 NOTREACHED(); |
56 result->SetNull(); | 56 result->SetNull(); |
57 return; | 57 return; |
58 } | 58 } |
59 | 59 |
60 std::string json; | 60 std::string json; |
61 JSONStringValueSerializer serializer(&json); | 61 JSONStringValueSerializer serializer(&json); |
62 scoped_ptr<Value> value; | 62 scoped_ptr<base::Value> value; |
63 | 63 |
64 // Warning: note that JSON officially requires the root-level object to be | 64 // Warning: note that JSON officially requires the root-level object to be |
65 // an object (e.g. {foo:3}) or an array, while here we're serializing | 65 // an object (e.g. {foo:3}) or an array, while here we're serializing |
66 // strings, bools, etc. to "JSON". This only works because (a) the JSON | 66 // strings, bools, etc. to "JSON". This only works because (a) the JSON |
67 // writer is lenient, and (b) on the receiving side we wrap the JSON string | 67 // writer is lenient, and (b) on the receiving side we wrap the JSON string |
68 // in square brackets, converting it to an array, then parsing it and | 68 // in square brackets, converting it to an array, then parsing it and |
69 // grabbing the 0th element to get the value out. | 69 // grabbing the 0th element to get the value out. |
70 switch (args[0].type) { | 70 switch (args[0].type) { |
71 case NPVariantType_String: { | 71 case NPVariantType_String: { |
72 value.reset(Value::CreateStringValue(args[0].ToString())); | 72 value.reset(new base::StringValue(args[0].ToString())); |
73 break; | 73 break; |
74 } | 74 } |
75 case NPVariantType_Bool: { | 75 case NPVariantType_Bool: { |
76 value.reset(Value::CreateBooleanValue(args[0].ToBoolean())); | 76 value.reset(new base::FundamentalValue(args[0].ToBoolean())); |
77 break; | 77 break; |
78 } | 78 } |
79 case NPVariantType_Int32: { | 79 case NPVariantType_Int32: { |
80 value.reset(Value::CreateIntegerValue(args[0].ToInt32())); | 80 value.reset(new base::FundamentalValue(args[0].ToInt32())); |
81 break; | 81 break; |
82 } | 82 } |
83 case NPVariantType_Double: { | 83 case NPVariantType_Double: { |
84 // The value that is sent back is an integer while it is treated | 84 // The value that is sent back is an integer while it is treated |
85 // as a double in this binding. The reason being that KJS treats | 85 // as a double in this binding. The reason being that KJS treats |
86 // any number value as a double. Refer for more details, | 86 // any number value as a double. Refer for more details, |
87 // chrome/third_party/webkit/src/JavaScriptCore/bindings/c/c_utility.cpp | 87 // chrome/third_party/webkit/src/JavaScriptCore/bindings/c/c_utility.cpp |
88 value.reset(Value::CreateIntegerValue(args[0].ToInt32())); | 88 value.reset(new base::FundamentalValue(args[0].ToInt32())); |
89 break; | 89 break; |
90 } | 90 } |
91 default: { | 91 default: { |
92 result->SetNull(); | 92 result->SetNull(); |
93 return; | 93 return; |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 if (!serializer.Serialize(*value)) { | 97 if (!serializer.Serialize(*value)) { |
98 result->SetNull(); | 98 result->SetNull(); |
99 return; | 99 return; |
100 } | 100 } |
101 | 101 |
102 bool succeeded = sender_->Send( | 102 bool succeeded = sender_->Send( |
103 new ViewHostMsg_DomOperationResponse(routing_id_, json, automation_id_)); | 103 new ViewHostMsg_DomOperationResponse(routing_id_, json, automation_id_)); |
104 result->Set(succeeded); | 104 result->Set(succeeded); |
105 | 105 |
106 automation_id_ = MSG_ROUTING_NONE; | 106 automation_id_ = MSG_ROUTING_NONE; |
107 | |
108 } | 107 } |
109 | 108 |
110 void DomAutomationController::SendJSON(const CppArgumentList& args, | 109 void DomAutomationController::SendJSON(const CppArgumentList& args, |
111 CppVariant* result) { | 110 CppVariant* result) { |
112 if (args.size() != 1) { | 111 if (args.size() != 1) { |
113 result->SetNull(); | 112 result->SetNull(); |
114 return; | 113 return; |
115 } | 114 } |
116 | 115 |
117 if (automation_id_ == MSG_ROUTING_NONE) { | 116 if (automation_id_ == MSG_ROUTING_NONE) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return; | 207 return; |
209 } | 208 } |
210 | 209 |
211 std::string histogram_json; | 210 std::string histogram_json; |
212 sender_->Send(new ChildProcessHostMsg_GetBrowserHistogram( | 211 sender_->Send(new ChildProcessHostMsg_GetBrowserHistogram( |
213 args[0].ToString(), &histogram_json)); | 212 args[0].ToString(), &histogram_json)); |
214 result->Set(histogram_json); | 213 result->Set(histogram_json); |
215 } | 214 } |
216 | 215 |
217 } // namespace content | 216 } // namespace content |
OLD | NEW |