From 8f49617801551b4425f6ec092f7f426321cb6939 Mon Sep 17 00:00:00 2001 From: "surya.kumar7" Date: Wed, 14 Feb 2018 20:11:33 +0530 Subject: [PATCH] Add pwrt electron interface object 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 | 61 +++++++++++++++++++++++++++++++++++++++ atom/browser/api/atom_api_pwrt.h | 33 +++++++++++++++++++++ atom/common/node_bindings.cc | 1 + filenames.gypi | 3 ++ lib/browser/api/module-list.js | 3 +- lib/browser/api/pwrt.js | 3 ++ 6 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 atom/browser/api/atom_api_pwrt.cc create mode 100644 atom/browser/api/atom_api_pwrt.h create mode 100644 lib/browser/api/pwrt.js diff --git a/atom/browser/api/atom_api_pwrt.cc b/atom/browser/api/atom_api_pwrt.cc new file mode 100644 index 0000000..334127d --- /dev/null +++ b/atom/browser/api/atom_api_pwrt.cc @@ -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::Create(v8::Isolate* isolate) { + LOG(DEBUG) << "PWRT::Create"; + return mate::CreateHandle(isolate, new PWRT(isolate)); +} + +// static +void PWRT::BuildPrototype( + v8::Isolate* isolate, v8::Local 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 exports, v8::Local unused, + v8::Local 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 index 0000000..110eac0 --- /dev/null +++ b/atom/browser/api/atom_api_pwrt.h @@ -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 { + public: + static mate::Handle Create(v8::Isolate* isolate); + + static void BuildPrototype(v8::Isolate* isolate, + v8::Local 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_ diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 4c8e82f..2a9c057 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -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); diff --git a/filenames.gypi b/filenames.gypi index fc6d857..16fd220 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -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', @@ -135,6 +136,8 @@ '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', diff --git a/lib/browser/api/module-list.js b/lib/browser/api/module-list.js index 64b2829..fcc07b3 100644 --- a/lib/browser/api/module-list.js +++ b/lib/browser/api/module-list.js @@ -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 index 0000000..0019884 --- /dev/null +++ b/lib/browser/api/pwrt.js @@ -0,0 +1,3 @@ +const {pwrt} = process.atomBinding('pwrt'); + +module.exports = pwrt -- 2.7.4