Add the RemoteObject API in renderer. (not implemented yet)

This commit is contained in:
Cheng Zhao 2013-04-22 09:13:25 +08:00
Родитель ebf5bf2d19
Коммит 3ae0c99ca9
6 изменённых файлов: 134 добавлений и 1 удалений

Просмотреть файл

@ -9,6 +9,7 @@
'browser/api/lib/atom.coffee',
'browser/api/lib/window.coffee',
'browser/atom/atom.coffee',
'renderer/api/lib/remote_object.coffee',
],
'lib_sources': [
'app/atom_main_delegate.cc',
@ -52,6 +53,8 @@
'common/options_switches.h',
'common/v8_value_converter_impl.cc',
'common/v8_value_converter_impl.h',
'renderer/api/atom_api_remote_object.cc',
'renderer/api/atom_api_remote_object.h',
'renderer/atom_render_view_observer.cc',
'renderer/atom_render_view_observer.h',
'renderer/atom_renderer_client.cc',

Просмотреть файл

@ -10,4 +10,6 @@ NODE_EXT_LIST_START
NODE_EXT_LIST_ITEM(atom_browser_window)
NODE_EXT_LIST_ITEM(atom_renderer_remote_object)
NODE_EXT_LIST_END

Просмотреть файл

@ -0,0 +1,78 @@
// 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.
#include "renderer/api/atom_api_remote_object.h"
#include "base/logging.h"
namespace atom {
namespace api {
RemoteObject::RemoteObject(v8::Handle<v8::Object> wrapper,
const std::string& type)
: id_(-1) {
// TODO apply for new object in browser.
Wrap(wrapper);
}
RemoteObject::RemoteObject(v8::Handle<v8::Object> wrapper, int id)
: id_(id) {
Wrap(wrapper);
}
RemoteObject::~RemoteObject() {
Destroy();
}
void RemoteObject::Destroy() {
DCHECK(id_ > 0);
// TODO release me in browser.
}
// static
v8::Handle<v8::Value> RemoteObject::New(const v8::Arguments &args) {
v8::HandleScope scope;
if (args[0]->IsString())
new RemoteObject(args.This(), *v8::String::Utf8Value(args[0]));
else if (args[0]->IsNumber())
new RemoteObject(args.This(), args[0]->IntegerValue());
else
return node::ThrowTypeError("Bad argument");
return args.This();
}
// static
v8::Handle<v8::Value> RemoteObject::Destroy(const v8::Arguments &args) {
RemoteObject* self = ObjectWrap::Unwrap<RemoteObject>(args.This());
// TODO try to call remote object's destroy method first.
delete self;
return v8::Undefined();
}
// static
void RemoteObject::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::Local<v8::FunctionTemplate> t =
v8::FunctionTemplate::New(RemoteObject::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(v8::String::NewSymbol("RemoteObject"));
NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy);
target->Set(v8::String::NewSymbol("RemoteObject"), t->GetFunction());
}
} // namespace api
} // namespace atom
NODE_MODULE(atom_renderer_remote_object, atom::api::RemoteObject::Initialize)

Просмотреть файл

@ -0,0 +1,47 @@
// 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_RENDERER_ATOM_API_REMOTE_OBJECT_H_
#define ATOM_RENDERER_ATOM_API_REMOTE_OBJECT_H_
#include <iosfwd>
#include "base/basictypes.h"
#include "vendor/node/src/node_object_wrap.h"
namespace atom {
namespace api {
// Every instance of RemoteObject represents an object in browser.
class RemoteObject : public node::ObjectWrap {
public:
virtual ~RemoteObject();
static void Initialize(v8::Handle<v8::Object> target);
// Tell browser to destroy this object.
void Destroy();
int id() const { return id_; }
protected:
explicit RemoteObject(v8::Handle<v8::Object> wrapper,
const std::string& type);
explicit RemoteObject(v8::Handle<v8::Object> wrapper, int id);
private:
static v8::Handle<v8::Value> New(const v8::Arguments &args);
static v8::Handle<v8::Value> Destroy(const v8::Arguments &args);
int id_;
DISALLOW_COPY_AND_ASSIGN(RemoteObject);
};
} // namespace api
} // namespace atom
#endif // ATOM_RENDERER_ATOM_API_REMOTE_OBJECT_H_

Просмотреть файл

@ -0,0 +1,3 @@
RemoteObject = process.atom_binding('remote_object').RemoteObject
module.exports = RemoteObject

2
vendor/node поставляемый

@ -1 +1 @@
Subproject commit bfdcb5bae8f01b877fbad84bb260a53ba7ca1e92
Subproject commit 027d18bde8c24534215095aadceb78e7a61b2b5c