Get rid of manually converting to base::Value when possible.

This commit is contained in:
Cheng Zhao 2013-12-05 23:47:07 +08:00
parent e5afa72b4d
commit 4a1ee39156
8 changed files with 13 additions and 37 deletions

View file

@ -4,10 +4,8 @@
#include "browser/api/atom_api_browser_ipc.h" #include "browser/api/atom_api_browser_ipc.h"
#include "base/values.h"
#include "common/api/api_messages.h" #include "common/api/api_messages.h"
#include "common/v8_conversions.h" #include "common/v8_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "vendor/node/src/node.h" #include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h" #include "vendor/node/src/node_internals.h"
@ -25,26 +23,17 @@ v8::Handle<v8::Value> BrowserIPC::Send(const v8::Arguments &args) {
string16 channel; string16 channel;
int process_id, routing_id; int process_id, routing_id;
if (!FromV8Arguments(args, &channel, &process_id, &routing_id)) scoped_ptr<base::Value> arguments;
if (!FromV8Arguments(args, &channel, &process_id, &routing_id, &arguments))
return node::ThrowTypeError("Bad argument"); return node::ThrowTypeError("Bad argument");
DCHECK(arguments && arguments->IsType(base::Value::TYPE_LIST));
RenderViewHost* render_view_host(RenderViewHost::FromID( RenderViewHost* render_view_host(RenderViewHost::FromID(
process_id, routing_id)); process_id, routing_id));
if (!render_view_host) if (!render_view_host)
return node::ThrowError("Invalid render view host"); return node::ThrowError("Invalid render view host");
// Convert Arguments to Array, so we can use V8ValueConverter to convert it
// to ListValue.
v8::Local<v8::Array> v8_args = v8::Array::New(args.Length() - 3);
for (int i = 0; i < args.Length() - 3; ++i)
v8_args->Set(i, args[i + 3]);
scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
scoped_ptr<base::Value> arguments(
converter->FromV8Value(v8_args, v8::Context::GetCurrent()));
DCHECK(arguments && arguments->IsType(base::Value::TYPE_LIST));
render_view_host->Send(new AtomViewMsg_Message( render_view_host->Send(new AtomViewMsg_Message(
routing_id, routing_id,
channel, channel,

View file

@ -7,10 +7,8 @@
#include <vector> #include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "browser/api/atom_api_event.h" #include "browser/api/atom_api_event.h"
#include "common/v8_value_converter_impl.h" #include "common/v8_conversions.h"
#include "vendor/node/src/node.h" #include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h" #include "vendor/node/src/node_internals.h"
@ -49,7 +47,7 @@ bool EventEmitter::Emit(const std::string& name, base::ListValue* args) {
// Generate arguments for calling handle.emit. // Generate arguments for calling handle.emit.
std::vector<v8::Handle<v8::Value>> v8_args; std::vector<v8::Handle<v8::Value>> v8_args;
v8_args.reserve(args->GetSize() + 2); v8_args.reserve(args->GetSize() + 2);
v8_args.push_back(v8::String::New(name.c_str(), name.size())); v8_args.push_back(ToV8Value(name));
v8_args.push_back(v8_event); v8_args.push_back(v8_event);
for (size_t i = 0; i < args->GetSize(); i++) { for (size_t i = 0; i < args->GetSize(); i++) {
base::Value* value = NULL; base::Value* value = NULL;

View file

@ -5,19 +5,15 @@
#include "browser/api/atom_api_window.h" #include "browser/api/atom_api_window.h"
#include "base/process_util.h" #include "base/process_util.h"
#include "base/values.h"
#include "browser/native_window.h" #include "browser/native_window.h"
#include "common/v8_conversions.h" #include "common/v8_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
#include "vendor/node/src/node_buffer.h" #include "vendor/node/src/node_buffer.h"
using content::V8ValueConverter;
using content::NavigationController; using content::NavigationController;
using node::ObjectWrap; using node::ObjectWrap;
@ -105,15 +101,12 @@ v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
if (!args.IsConstructCall()) if (!args.IsConstructCall())
return node::ThrowError("Require constructor call"); return node::ThrowError("Require constructor call");
if (!args[0]->IsObject()) scoped_ptr<base::Value> options;
return node::ThrowTypeError("Need options creating Window"); if (!FromV8Arguments(args, &options))
return node::ThrowTypeError("Bad argument");
scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
scoped_ptr<base::Value> options(
converter->FromV8Value(args[0], v8::Context::GetCurrent()));
if (!options || !options->IsType(base::Value::TYPE_DICTIONARY)) if (!options || !options->IsType(base::Value::TYPE_DICTIONARY))
return node::ThrowTypeError("Invalid options"); return node::ThrowTypeError("Options must be dictionary");
new Window(args.This(), static_cast<base::DictionaryValue*>(options.get())); new Window(args.This(), static_cast<base::DictionaryValue*>(options.get()));

View file

@ -7,10 +7,8 @@
#include <vector> #include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/values.h"
#include "browser/api/atom_api_event.h" #include "browser/api/atom_api_event.h"
#include "common/v8_conversions.h" #include "common/v8_conversions.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "vendor/node/src/node.h" #include "vendor/node/src/node.h"
#include "vendor/node/src/node_internals.h" #include "vendor/node/src/node_internals.h"

View file

@ -8,7 +8,7 @@ sendWrap = (channel, processId, routingId, args...) ->
processId = window.getProcessId() processId = window.getProcessId()
routingId = window.getRoutingId() routingId = window.getRoutingId()
send channel, processId, routingId, args... send channel, processId, routingId, [args...]
class Ipc extends EventEmitter class Ipc extends EventEmitter
constructor: -> constructor: ->

View file

@ -15,6 +15,7 @@
#include "base/values.h" #include "base/values.h"
#include "browser/api/atom_api_window.h" #include "browser/api/atom_api_window.h"
#include "common/swap_or_assign.h" #include "common/swap_or_assign.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/renderer/v8_value_converter.h" #include "content/public/renderer/v8_value_converter.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
@ -66,7 +67,7 @@ struct FromV8Value {
operator scoped_ptr<base::Value>() { operator scoped_ptr<base::Value>() {
scoped_ptr<content::V8ValueConverter> converter( scoped_ptr<content::V8ValueConverter> converter(
content::V8ValueConverter::create()); new atom::V8ValueConverterImpl);
return scoped_ptr<base::Value>( return scoped_ptr<base::Value>(
converter->FromV8Value(value_, v8::Context::GetCurrent())); converter->FromV8Value(value_, v8::Context::GetCurrent()));
} }

View file

@ -12,7 +12,6 @@
#include "vendor/node/src/node.h" #include "vendor/node/src/node.h"
using content::RenderView; using content::RenderView;
using content::V8ValueConverter;
using WebKit::WebFrame; using WebKit::WebFrame;
using WebKit::WebView; using WebKit::WebView;

View file

@ -7,10 +7,8 @@
#include <vector> #include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "base/values.h"
#include "common/v8_conversions.h" #include "common/v8_conversions.h"
#include "content/public/renderer/render_view.h" #include "content/public/renderer/render_view.h"
#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "vendor/node/src/node.h" #include "vendor/node/src/node.h"