2013-04-23 04:18:07 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/api/atom_api_browser_ipc.h"
|
2013-04-23 04:18:07 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/api/api_messages.h"
|
|
|
|
#include "atom/common/v8/node_common.h"
|
|
|
|
#include "atom/common/v8/native_type_conversions.h"
|
2013-04-23 04:18:07 +00:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
|
|
|
|
using content::RenderViewHost;
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
// static
|
2013-12-11 07:48:19 +00:00
|
|
|
void BrowserIPC::Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2013-09-24 01:41:54 +00:00
|
|
|
string16 channel;
|
|
|
|
int process_id, routing_id;
|
2013-12-05 15:47:07 +00:00
|
|
|
scoped_ptr<base::Value> arguments;
|
|
|
|
if (!FromV8Arguments(args, &channel, &process_id, &routing_id, &arguments))
|
2013-04-23 04:18:07 +00:00
|
|
|
return node::ThrowTypeError("Bad argument");
|
|
|
|
|
2013-12-05 15:47:07 +00:00
|
|
|
DCHECK(arguments && arguments->IsType(base::Value::TYPE_LIST));
|
|
|
|
|
2013-04-23 04:18:07 +00:00
|
|
|
RenderViewHost* render_view_host(RenderViewHost::FromID(
|
|
|
|
process_id, routing_id));
|
|
|
|
if (!render_view_host)
|
|
|
|
return node::ThrowError("Invalid render view host");
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
args.GetReturnValue().Set(render_view_host->Send(new AtomViewMsg_Message(
|
2013-04-23 04:18:07 +00:00
|
|
|
routing_id,
|
|
|
|
channel,
|
2013-12-11 07:48:19 +00:00
|
|
|
*static_cast<base::ListValue*>(arguments.get()))));
|
2013-04-23 04:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void BrowserIPC::Initialize(v8::Handle<v8::Object> target) {
|
2013-12-11 07:48:19 +00:00
|
|
|
NODE_SET_METHOD(target, "send", Send);
|
2013-04-23 04:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
NODE_MODULE(atom_browser_ipc, atom::api::BrowserIPC::Initialize)
|