Add pwrt electron interface object
[platform/framework/web/crosswalk-tizen.git] / atom / browser / api / atom_api_pwrt.cc
1 #include "atom/browser/api/atom_api_pwrt.h"
2
3 #include "atom/browser/browser.h"
4 #include "native_mate/dictionary.h"
5 #include "base/logging.h"
6
7 #include "atom/common/node_includes.h"
8
9 namespace atom {
10
11 namespace api {
12
13 PWRT::PWRT(v8::Isolate* isolate) {
14   LOG(DEBUG) << "PWRT::PWRT";
15   Init(isolate);
16 }
17
18 PWRT::~PWRT() {
19   LOG(DEBUG) << "PWRT::~PWRT";
20 }
21
22 std::string PWRT::GetMessage() {
23   LOG(DEBUG) << "PWRT::GetMessage";
24   return "message from C++";
25 }
26
27 // static
28 mate::Handle<PWRT> PWRT::Create(v8::Isolate* isolate) {
29   LOG(DEBUG) << "PWRT::Create";
30   return mate::CreateHandle(isolate, new PWRT(isolate));
31 }
32
33 // static
34 void PWRT::BuildPrototype(
35     v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
36   LOG(DEBUG) << "PWRT::BuildPrototype";
37   prototype->SetClassName(mate::StringToV8(isolate, "PWRT"));
38   // TODO: Needs adding necessary interface methods
39   mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
40     .SetMethod("getMessage", &PWRT::GetMessage);
41 }
42
43 }  // namespace api
44
45 }  // namespace atom
46
47
48 namespace {
49
50 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
51                 v8::Local<v8::Context> context, void* priv) {
52   LOG(DEBUG) << "PWRT::Initialize";
53   v8::Isolate* isolate = context->GetIsolate();
54   mate::Dictionary dict(isolate, exports);
55   // TODO: Expose this attribute only for Tizen web apps
56   dict.Set("pwrt", atom::api::PWRT::Create(isolate));
57 }
58
59 }  // namespace
60
61 NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize)