1 #include "atom/browser/api/atom_api_pwrt.h"
3 #include "atom/browser/browser.h"
4 #include "native_mate/dictionary.h"
5 #include "base/logging.h"
7 #include "atom/common/node_includes.h"
8 #include "tizen/common/application_data.h"
9 #include "tizen/common/command_line.h"
16 PWRT::PWRT(v8::Isolate* isolate) {
17 LOG(INFO) << "PWRT::PWRT";
22 LOG(INFO) << "PWRT::~PWRT";
25 std::string PWRT::GetMessage() {
26 LOG(INFO) << "PWRT::GetMessage";
27 return "message from C++";
30 std::string PWRT::GetPath() {
31 LOG(INFO) << "PWRT::GetPath";
32 common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
33 std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron");
34 auto appdata_manager = common::ApplicationDataManager::GetInstance();
35 common::ApplicationData* app_data = appdata_manager->GetApplicationData(appid);
36 // TODO: Use resource-manager's GetStartResource() for localized urls
37 std::string app_path = "file://" + app_data->application_path() + app_data->content_info()->src();
41 bool PWRT::isTizenWebApp() {
42 LOG(INFO) << "PWRT::isTizenWebApp";
43 common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
44 std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron");
45 if (appid != "electron") { // TODO: Any better distinguishing feature?
52 void PWRT::Log(const std::string& message) {
53 std::string output = "[JS LOG] " + message;
54 dlog_print(DLOG_INFO, "WRT", output.c_str());
58 mate::Handle<PWRT> PWRT::Create(v8::Isolate* isolate) {
59 LOG(INFO) << "PWRT::Create";
60 return mate::CreateHandle(isolate, new PWRT(isolate));
64 void PWRT::BuildPrototype(
65 v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
66 LOG(INFO) << "PWRT::BuildPrototype";
67 prototype->SetClassName(mate::StringToV8(isolate, "PWRT"));
68 // TODO: Needs adding necessary interface methods
69 mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
70 .SetMethod("getMessage", &PWRT::GetMessage)
71 .SetMethod("getPath", &PWRT::GetPath)
72 .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp)
73 .SetMethod("log", &PWRT::Log);
83 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
84 v8::Local<v8::Context> context, void* priv) {
85 LOG(INFO) << "PWRT::Initialize";
86 v8::Isolate* isolate = context->GetIsolate();
87 mate::Dictionary dict(isolate, exports);
88 // TODO: Expose this attribute only for Tizen web apps
89 dict.Set("pwrt", atom::api::PWRT::Create(isolate));
94 NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize)