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.cc',
|
||||||
'atom/browser/api/atom_api_auto_updater.h',
|
'atom/browser/api/atom_api_auto_updater.h',
|
||||||
'atom/browser/api/atom_api_browser_ipc.cc',
|
'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_dialog.cc',
|
||||||
'atom/browser/api/atom_api_event.cc',
|
'atom/browser/api/atom_api_event.cc',
|
||||||
'atom/browser/api/atom_api_event.h',
|
'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
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_browser_ipc.h"
|
|
||||||
|
|
||||||
#include "atom/common/api/api_messages.h"
|
#include "atom/common/api/api_messages.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "atom/common/v8/native_type_conversions.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
|
|
||||||
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
using content::RenderViewHost;
|
using content::RenderViewHost;
|
||||||
|
|
||||||
namespace atom {
|
namespace {
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
|
bool Send(const string16& channel, int process_id, int routing_id,
|
||||||
|
const base:ListValue& arguments) {
|
||||||
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");
|
node::ThrowError("Invalid render view host");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
args.GetReturnValue().Set(render_view_host->Send(new AtomViewMsg_Message(
|
return render_view_host->Send(new AtomViewMsg_Message(routing_id, channel,
|
||||||
routing_id,
|
arguments));
|
||||||
channel,
|
|
||||||
*static_cast<base::ListValue*>(arguments.get()))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
void Initialize(v8::Handle<v8::Object> exports) {
|
||||||
void BrowserIPC::Initialize(v8::Handle<v8::Object> target) {
|
mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
|
||||||
NODE_SET_METHOD(target, "send", Send);
|
dict.SetMethod("send", &Send);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace
|
||||||
|
|
||||||
} // namespace atom
|
NODE_MODULE(atom_browser_ipc, Initialize)
|
||||||
|
|
||||||
NODE_MODULE(atom_browser_ipc, atom::api::BrowserIPC::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