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(ERROR) << "PWRT::PWRT";
22 LOG(ERROR) << "PWRT::~PWRT";
25 std::string PWRT::GetMessage() {
26 LOG(ERROR) << "PWRT::GetMessage";
27 return "message from C++";
30 std::string PWRT::GetPath() {
31 LOG(ERROR) << "PWRT::GetPath";
32 common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
34 std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron");
35 auto appdata_manager = common::ApplicationDataManager::GetInstance();
36 common::ApplicationData* app_data = appdata_manager->GetApplicationData(appid);
37 // TODO: Use resource-manager's GetStartResource() for localized urls
38 std::string app_path = "file://" + app_data->application_path() + app_data->content_info()->src();
44 bool PWRT::isTizenWebApp() {
45 LOG(ERROR) << "PWRT::isTizenWebApp";
46 common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
47 std::string appid = runtime_cmd->GetAppIdFromCommandLine("/usr/bin/electron");
48 if (appid != "electron") { // TODO: Any better distinguishing feature?
55 void PWRT::Log(const std::string& message) {
56 std::string output = "[JS LOG] " + message;
57 dlog_print(DLOG_INFO, "WRT", output.c_str());
61 mate::Handle<PWRT> PWRT::Create(v8::Isolate* isolate) {
62 LOG(ERROR) << "PWRT::Create";
63 return mate::CreateHandle(isolate, new PWRT(isolate));
67 void PWRT::BuildPrototype(
68 v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
69 LOG(ERROR) << "PWRT::BuildPrototype";
70 prototype->SetClassName(mate::StringToV8(isolate, "PWRT"));
71 // TODO: Needs adding necessary interface methods
72 mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
73 .SetMethod("getMessage", &PWRT::GetMessage)
74 .SetMethod("getPath", &PWRT::GetPath)
75 .SetMethod("isTizenWebApp", &PWRT::isTizenWebApp)
76 .SetMethod("log", &PWRT::Log);
86 void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
87 v8::Local<v8::Context> context, void* priv) {
88 LOG(ERROR) << "PWRT::Initialize";
89 v8::Isolate* isolate = context->GetIsolate();
90 mate::Dictionary dict(isolate, exports);
91 // TODO: Expose this attribute only for Tizen web apps
92 dict.Set("pwrt", atom::api::PWRT::Create(isolate));
97 NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_pwrt, Initialize)