Chromium Code Reviews| Index: chrome/renderer/dom_ui_bindings.cc |
| diff --git a/chrome/renderer/dom_ui_bindings.cc b/chrome/renderer/dom_ui_bindings.cc |
| index e71479ac2def40d84180197537de4d11aef7130e..bf7bf710b00ff93f500455a77ec47cdab40e151d 100644 |
| --- a/chrome/renderer/dom_ui_bindings.cc |
| +++ b/chrome/renderer/dom_ui_bindings.cc |
| @@ -5,12 +5,44 @@ |
| #include "chrome/renderer/dom_ui_bindings.h" |
| #include "base/json/json_writer.h" |
| +#include "base/scoped_ptr.h" |
| #include "base/stl_util-inl.h" |
| #include "base/values.h" |
| #include "chrome/common/render_messages.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| +namespace { |
| + |
| +// Creates a Value which is a copy of the CppVariant |value|. All Object are |
|
evanm
2011/01/25 18:24:56
typo: "All Object*s*"
|
| +// treated as Lists for now since CppVariant does not distinguish arrays in any |
| +// convenient way and we currently have no need of non array objects. |
| +Value* CreateValueFromCppVariant(const CppVariant& value) { |
| + if (value.isBool()) |
| + return Value::CreateBooleanValue(value.ToBoolean()); |
| + if (value.isDouble()) |
| + return Value::CreateRealValue(value.ToDouble()); |
| + if (value.isInt32()) |
| + return Value::CreateIntegerValue(value.ToInt32()); |
| + if (value.isString()) |
| + return Value::CreateStringValue(value.ToString()); |
| + |
| + if (value.isObject()) { |
| + // We currently assume all objects are arrays. |
|
evanm
2011/01/25 18:24:56
Can we check this assumption somehow? Even with j
arv (Not doing code reviews)
2011/01/26 00:50:32
One would need to evaluate JS (which can be done t
|
| + std::vector<CppVariant> vector = value.ToVector(); |
| + ListValue* list = new ListValue(); |
| + for (size_t i = 0; i < vector.size(); ++i) { |
| + list->Append(CreateValueFromCppVariant(vector[i])); |
| + } |
| + return list; |
| + } |
| + |
| + // Covers null and undefined. |
| + return Value::CreateNullValue(); |
| +} |
| + |
| +} // namespace |
| + |
| DOMBoundBrowserObject::DOMBoundBrowserObject() |
| : sender_(NULL), |
| routing_id_(0) { |
| @@ -42,12 +74,9 @@ void DOMUIBindings::send(const CppArgumentList& args, CppVariant* result) { |
| if (args.size() == 2) { |
| if (!args[1].isObject()) |
| return; |
| - std::vector<std::string> strings = args[1].ToStringVector(); |
| - ListValue value; |
| - for (size_t i = 0; i < strings.size(); ++i) { |
| - value.Append(Value::CreateStringValue(strings[i])); |
| - } |
| - base::JSONWriter::Write(&value, /* pretty_print= */ false, &content); |
| + |
| + scoped_ptr<Value> value(CreateValueFromCppVariant(args[1])); |
| + base::JSONWriter::Write(value.get(), /* pretty_print= */ false, &content); |
| } |
| // Retrieve the source frame's url |