Simplify browser_ipc api.
This commit is contained in:
parent
5dae7b8658
commit
77cccc2db6
3 changed files with 18 additions and 60 deletions
1
atom.gyp
1
atom.gyp
|
@ -49,7 +49,6 @@
|
|||
'atom/browser/api/atom_api_auto_updater.cc',
|
||||
'atom/browser/api/atom_api_auto_updater.h',
|
||||
'atom/browser/api/atom_api_browser_ipc.cc',
|
||||
'atom/browser/api/atom_api_browser_ipc.h',
|
||||
'atom/browser/api/atom_api_dialog.cc',
|
||||
'atom/browser/api/atom_api_event.cc',
|
||||
'atom/browser/api/atom_api_event.h',
|
||||
|
|
|
@ -2,47 +2,35 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/api/atom_api_browser_ipc.h"
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/node_includes.h"
|
||||
#include "atom/common/v8/native_type_conversions.h"
|
||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
using content::RenderViewHost;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
// static
|
||||
void BrowserIPC::Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
string16 channel;
|
||||
int process_id, routing_id;
|
||||
scoped_ptr<base::Value> arguments;
|
||||
if (!FromV8Arguments(args, &channel, &process_id, &routing_id, &arguments))
|
||||
return node::ThrowTypeError("Bad argument");
|
||||
|
||||
DCHECK(arguments && arguments->IsType(base::Value::TYPE_LIST));
|
||||
namespace {
|
||||
|
||||
bool Send(const string16& channel, int process_id, int routing_id,
|
||||
const base:ListValue& arguments) {
|
||||
RenderViewHost* render_view_host(RenderViewHost::FromID(
|
||||
process_id, routing_id));
|
||||
if (!render_view_host)
|
||||
return node::ThrowError("Invalid render view host");
|
||||
|
||||
args.GetReturnValue().Set(render_view_host->Send(new AtomViewMsg_Message(
|
||||
routing_id,
|
||||
channel,
|
||||
*static_cast<base::ListValue*>(arguments.get()))));
|
||||
if (!render_view_host) {
|
||||
node::ThrowError("Invalid render view host");
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
void BrowserIPC::Initialize(v8::Handle<v8::Object> target) {
|
||||
NODE_SET_METHOD(target, "send", Send);
|
||||
return render_view_host->Send(new AtomViewMsg_Message(routing_id, channel,
|
||||
arguments));
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
void Initialize(v8::Handle<v8::Object> exports) {
|
||||
mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
|
||||
dict.SetMethod("send", &Send);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
} // namespace
|
||||
|
||||
NODE_MODULE(atom_browser_ipc, atom::api::BrowserIPC::Initialize)
|
||||
NODE_MODULE(atom_browser_ipc, Initialize)
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
// 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.
|
||||
|
||||
#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_IPC_H_
|
||||
#define ATOM_BROWSER_API_ATOM_API_BROWSER_IPC_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class BrowserIPC {
|
||||
public:
|
||||
static void Initialize(v8::Handle<v8::Object> target);
|
||||
|
||||
private:
|
||||
static void Send(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(BrowserIPC);
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_API_ATOM_API_BROWSER_IPC_H_
|
Loading…
Add table
Add a link
Reference in a new issue