Add pwrt electron interface object 40/170240/4
authorsurya.kumar7 <surya.kumar7@samsung.com>
Wed, 14 Feb 2018 14:41:33 +0000 (20:11 +0530)
committerjaekuk lee <juku1999@samsung.com>
Mon, 26 Feb 2018 06:52:53 +0000 (06:52 +0000)
Any necesssary implementations or functions needed by JS-WRT can be
facilitated through this private pwrt object so that the deviation
from electron model is minimized and isolated

Change-Id: I5653406dd04c360259ba35656f1e598ce05d1858

atom/browser/api/atom_api_pwrt.cc [new file with mode: 0644]
atom/browser/api/atom_api_pwrt.h [new file with mode: 0644]
atom/common/node_bindings.cc
filenames.gypi
lib/browser/api/module-list.js
lib/browser/api/pwrt.js [new file with mode: 0644]

diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc
new file mode 100644 (file)
index 0000000..334127d
--- /dev/null
@@ -0,0 +1,61 @@
+#include "atom/browser/api/atom_api_pwrt.h"
+
+#include "atom/browser/browser.h"
+#include "native_mate/dictionary.h"
+#include "base/logging.h"
+
+#include "atom/common/node_includes.h"
+
+namespace atom {
+
+namespace api {
+
+PWRT::PWRT(v8::Isolate* isolate) {
+  LOG(DEBUG) << "PWRT::PWRT";
+  Init(isolate);
+}
+
+PWRT::~PWRT() {
+  LOG(DEBUG) << "PWRT::~PWRT";
+}
+
+std::string PWRT::GetMessage() {
+  LOG(DEBUG) << "PWRT::GetMessage";
+  return "message from C++";
+}
+
+// static
+mate::Handle<PWRT> PWRT::Create(v8::Isolate* isolate) {
+  LOG(DEBUG) << "PWRT::Create";
+  return mate::CreateHandle(isolate, new PWRT(isolate));
+}
+
+// static
+void PWRT::BuildPrototype(
+    v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
+  LOG(DEBUG) << "PWRT::BuildPrototype";
+  prototype->SetClassName(mate::StringToV8(isolate, "PWRT"));
+  // TODO: Needs adding necessary interface methods
+  mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
+    .SetMethod("getMessage", &PWRT::GetMessage);
+}
+
+}  // namespace api
+
+}  // namespace atom
+
+
+namespace {
+
+void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
+                v8::Local<v8::Context> context, void* priv) {
+  LOG(DEBUG) << "PWRT::Initialize";
+  v8::Isolate* isolate = context->GetIsolate();
+  mate::Dictionary dict(isolate, exports);
+  // TODO: Expose this attribute only for Tizen web apps
+  dict.Set("pwrt", atom::api::PWRT::Create(isolate));
+}
+
+}  // namespace
+
+NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize)
diff --git a/atom/browser/api/atom_api_pwrt.h b/atom/browser/api/atom_api_pwrt.h
new file mode 100644 (file)
index 0000000..110eac0
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef ATOM_BROWSER_API_ATOM_API_PWRT_H_
+#define ATOM_BROWSER_API_ATOM_API_PWRT_H_
+
+#include "atom/browser/api/trackable_object.h"
+#include "base/compiler_specific.h"
+#include "native_mate/handle.h"
+
+namespace atom {
+
+namespace api {
+
+class PWRT : public mate::TrackableObject<PWRT> {
+ public:
+  static mate::Handle<PWRT> Create(v8::Isolate* isolate);
+
+  static void BuildPrototype(v8::Isolate* isolate,
+                             v8::Local<v8::FunctionTemplate> prototype);
+
+  std::string GetMessage();
+
+ protected:
+  explicit PWRT(v8::Isolate* isolate);
+  ~PWRT() override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(PWRT);
+};
+
+}  // namespace api
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_API_ATOM_API_PWRT_H_
index 4c8e82f..2a9c057 100644 (file)
@@ -47,6 +47,7 @@ REFERENCE_MODULE(atom_browser_net);
 REFERENCE_MODULE(atom_browser_power_monitor);
 REFERENCE_MODULE(atom_browser_power_save_blocker);
 REFERENCE_MODULE(atom_browser_protocol);
+REFERENCE_MODULE(atom_browser_pwrt);
 REFERENCE_MODULE(atom_browser_render_process_preferences);
 REFERENCE_MODULE(atom_browser_session);
 REFERENCE_MODULE(atom_browser_system_preferences);
index fc6d857..16fd220 100644 (file)
@@ -29,6 +29,7 @@
       'lib/browser/api/power-monitor.js',
       'lib/browser/api/power-save-blocker.js',
       'lib/browser/api/protocol.js',
+      'lib/browser/api/pwrt.js',
       'lib/browser/api/screen.js',
       'lib/browser/api/session.js',
       'lib/browser/api/system-preferences.js',
       'atom/browser/api/atom_api_power_save_blocker.h',
       'atom/browser/api/atom_api_protocol.cc',
       'atom/browser/api/atom_api_protocol.h',
+      'atom/browser/api/atom_api_pwrt.cc',
+      'atom/browser/api/atom_api_pwrt.h',
       'atom/browser/api/atom_api_render_process_preferences.cc',
       'atom/browser/api/atom_api_render_process_preferences.h',
       'atom/browser/api/atom_api_screen.cc',
index 64b2829..fcc07b3 100644 (file)
@@ -21,5 +21,6 @@ module.exports = [
   {name: 'Tray', file: 'tray'},
   {name: 'webContents', file: 'web-contents'},
   // The internal modules, invisible unless you know their names.
-  {name: 'NavigationController', file: 'navigation-controller', private: true}
+  {name: 'NavigationController', file: 'navigation-controller', private: true},
+  {name: 'pwrt', file: 'pwrt', private: true}
 ]
diff --git a/lib/browser/api/pwrt.js b/lib/browser/api/pwrt.js
new file mode 100644 (file)
index 0000000..0019884
--- /dev/null
@@ -0,0 +1,3 @@
+const {pwrt} = process.atomBinding('pwrt');
+
+module.exports = pwrt