From: Pawel Andruszkiewicz Date: Tue, 24 Mar 2015 09:28:17 +0000 (+0100) Subject: [Common] Common code has been extracted to a separate library. X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~211 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d12414ab36495e0e79017ab7451e408371b19638;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Common code has been extracted to a separate library. Change-Id: Ibd1223378a367b8cb9ec05a052e575c90a4bea80 --- diff --git a/src/account/account.gyp b/src/account/account.gyp index 3a5a3020..272a0435 100644 --- a/src/account/account.gyp +++ b/src/account/account.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_account', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'account_api.js', 'account_extension.cc', diff --git a/src/alarm/alarm.gyp b/src/alarm/alarm.gyp index 1ef284d4..dc1135a1 100644 --- a/src/alarm/alarm.gyp +++ b/src/alarm/alarm.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_alarm', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'alarm_api.js', 'alarm_extension.cc', diff --git a/src/application/application.gyp b/src/application/application.gyp index 92050353..62a83855 100644 --- a/src/application/application.gyp +++ b/src/application/application.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_application', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'application_api.js', 'application_extension.cc', diff --git a/src/application/application_extension.cc b/src/application/application_extension.cc index e56b027b..1156ed33 100644 --- a/src/application/application_extension.cc +++ b/src/application/application_extension.cc @@ -14,19 +14,21 @@ extern const char kSource_application_api[]; common::Extension* CreateExtension() { - std::string app_id = common::Extension::GetRuntimeVariable("app_id", 64); - LoggerD("app_id: %s", app_id.c_str()); + ApplicationExtension* e = new ApplicationExtension(); - if (app_id.empty()) { + if (e->app_id().empty()) { LoggerD("Application extension will not be created."); - return NULL; + delete e; + return nullptr; } - return new ApplicationExtension(app_id); + return e; } -ApplicationExtension::ApplicationExtension(const std::string& app_id) { - app_id_ = app_id; +ApplicationExtension::ApplicationExtension() { + app_id_ = GetRuntimeVariable("app_id", 64); + + LoggerD("app_id: %s", app_id_.c_str()); SetExtensionName("tizen.application"); SetJavaScriptAPI(kSource_application_api); diff --git a/src/application/application_extension.h b/src/application/application_extension.h index 36b1f0d6..5bc40cca 100644 --- a/src/application/application_extension.h +++ b/src/application/application_extension.h @@ -11,9 +11,11 @@ class ApplicationExtension : public common::Extension { public: - explicit ApplicationExtension(const std::string& app_id); + ApplicationExtension(); virtual ~ApplicationExtension(); + std::string app_id() const { return app_id_; } + private: std::string app_id_; // common::Extension implementation. diff --git a/src/application/application_instance.cc b/src/application/application_instance.cc index 8f157fee..7128cb0a 100644 --- a/src/application/application_instance.cc +++ b/src/application/application_instance.cc @@ -1805,7 +1805,7 @@ void ApplicationInstance::AppMgrRemoveAppInfoEventListener( void ApplicationInstance::AppGetRequestedAppControl( const picojson::value& args, picojson::object& out) { std::string bundle_str = - common::Extension::GetRuntimeVariable("encoded_bundle", 1024); + common::GetCurrentExtension()->GetRuntimeVariable("encoded_bundle", 1024); if (bundle_str.empty()) { LoggerE("Getting encoded_bundle is failed"); ReportError(UnknownException("Gettng encoded_bundle is failed"), out); diff --git a/src/archive/archive.gyp b/src/archive/archive.gyp index 751d0ac9..589e4779 100644 --- a/src/archive/archive.gyp +++ b/src/archive/archive.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_archive', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'archive_api.js', 'archive_extension.cc', diff --git a/src/badge/badge.gyp b/src/badge/badge.gyp index d8cdb7f6..da96e285 100644 --- a/src/badge/badge.gyp +++ b/src/badge/badge.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_badge', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'badge_api.js', 'badge_extension.cc', diff --git a/src/bluetooth/bluetooth.gyp b/src/bluetooth/bluetooth.gyp index e21e3607..3ce1d82a 100644 --- a/src/bluetooth/bluetooth.gyp +++ b/src/bluetooth/bluetooth.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_bluetooth', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'bluetooth_api.js', 'bluetooth_adapter.cc', diff --git a/src/bookmark/bookmark.gyp b/src/bookmark/bookmark.gyp index 5bd3eabe..5d1af2fb 100644 --- a/src/bookmark/bookmark.gyp +++ b/src/bookmark/bookmark.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_bookmark', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'bookmark_api.js', 'bookmark_extension.cc', diff --git a/src/calendar/calendar.gyp b/src/calendar/calendar.gyp index 8f08efd3..5b9798e0 100644 --- a/src/calendar/calendar.gyp +++ b/src/calendar/calendar.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_calendar', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'calendar_api.js', 'calendar_extension.cc', diff --git a/src/callhistory/callhistory.gyp b/src/callhistory/callhistory.gyp index b4f1f09a..3e88ecc0 100644 --- a/src/callhistory/callhistory.gyp +++ b/src/callhistory/callhistory.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_callhistory', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'callhistory_api.js', 'callhistory.cc', diff --git a/src/common/XW_Extension.cc b/src/common/XW_Extension.cc new file mode 100644 index 00000000..507a92be --- /dev/null +++ b/src/common/XW_Extension.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2013 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is compiled into each plugin, hence its size should be minimized. + +#include "common/extension.h" + +namespace { + +common::Extension* g_extension = nullptr; + +} // namespace + +namespace common { + +Extension* GetCurrentExtension() { + assert(g_extension); + return g_extension; +} + +class Extension::Detail { + private: + friend int32_t (::XW_Initialize)(XW_Extension extension, + XW_GetInterface get_interface); + + static int32_t XW_Initialize(XW_Extension extension, XW_GetInterface get_interface); + + // XW_Extension callbacks. + static void OnInstanceCreated(XW_Instance xw_instance); + static void OnShutdown(XW_Extension); +}; + +int32_t Extension::Detail::XW_Initialize(XW_Extension extension, XW_GetInterface get_interface) { + g_extension = CreateExtension(); + if (!g_extension) { + std::cerr << "Can't initialize extension: " + << "CreateExtension() returned NULL.\n"; + return XW_ERROR; + } + return XW_OK; +} + +void Extension::Detail::OnInstanceCreated(XW_Instance xw_instance) { + if (!g_extension) { + return; + } + Instance* instance = g_extension->CreateInstance(); + if (!instance) { + return; + } + Extension::OnInstanceCreated(xw_instance, instance); +} + +void Extension::Detail::OnShutdown(XW_Extension) { + delete g_extension; + g_extension = nullptr; +} + +} // namespace common + +// Entry point for CrossWalk plugin +extern "C" int32_t XW_Initialize(XW_Extension extension, XW_GetInterface get_interface) { + return common::Extension::XW_Initialize(extension, get_interface, + common::Extension::Detail::XW_Initialize, + common::Extension::Detail::OnInstanceCreated, + common::Extension::Detail::OnShutdown); +} diff --git a/src/common/common.gyp b/src/common/common.gyp new file mode 100644 index 00000000..d0e4e0cd --- /dev/null +++ b/src/common/common.gyp @@ -0,0 +1,89 @@ +{ + 'includes':[ + '../common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_common', + 'type': 'loadable_module', + 'sources': [ + 'converter.cc', + 'converter.h', + 'current_application.cc', + 'current_application.h', + 'extension.cc', + 'extension.h', + 'filter-utils.cc', + 'filter-utils.h', + 'picojson.h', + 'utils.h', + 'logger.cc', + 'logger.h', + 'platform_exception.cc', + 'platform_exception.h', + 'dbus_operation.cc', + 'dbus_operation.h', + 'XW_Extension.h', + 'XW_Extension_EntryPoints.h', + 'XW_Extension_Permissions.h', + 'XW_Extension_Runtime.h', + 'XW_Extension_SyncMessage.h', + 'scope_exit.h', + 'task-queue.cpp', + 'task-queue.h', + 'callback_user_data.cc', + 'callback_user_data.h', + 'optional.h', + #'multi_callback_user_data.cc', + #'multi_callback_user_data.h', + 'platform_result.cc', + 'platform_result.h', + 'assert.h' + ], + 'cflags': [ + '-fvisibility=default', + ], + 'conditions': [ + ['tizen == 1', { + 'variables': { + 'packages': [ + 'capi-appfw-app-manager', + 'capi-appfw-package-manager', + ] + }, + 'conditions': [ + ['privilege_engine == "DB"', { + 'defines': ['PRIVILEGE_USE_DB'], + 'variables': { + 'packages': [ + 'sqlite3', + ], + }, + }], + ['privilege_engine == "ACE"', { + 'defines': ['PRIVILEGE_USE_ACE'], + 'variables': { + 'packages': [ + 'sqlite3', + 'security-client', + ], + }, + }], + ['privilege_engine == "CYNARA"', { + 'defines': ['PRIVILEGE_USE_CYNARA'], + 'variables': { + 'packages': [ + ], + }, + }], + ], + }], + ], + 'direct_dependent_settings': { + 'libraries' : [ + '-ltizen_common', + ], + }, + }, + ], +} diff --git a/src/common/common.gypi b/src/common/common.gypi index a8ac6188..59229ddc 100644 --- a/src/common/common.gypi +++ b/src/common/common.gypi @@ -25,36 +25,8 @@ 'dbus-1', 'dlog', 'glib-2.0', - 'capi-appfw-app-manager', - 'capi-appfw-package-manager', ] }, - 'conditions': [ - ['privilege_engine == "DB"', { - 'defines': ['PRIVILEGE_USE_DB'], - 'variables': { - 'packages': [ - 'sqlite3', - ], - }, - }], - ['privilege_engine == "ACE"', { - 'defines': ['PRIVILEGE_USE_ACE'], - 'variables': { - 'packages': [ - 'sqlite3', - 'security-client', - ], - }, - }], - ['privilege_engine == "CYNARA"', { - 'defines': ['PRIVILEGE_USE_CYNARA'], - 'variables': { - 'packages': [ - ], - }, - }], - ], }, { 'sources/': [['exclude', '_tizen\\.cc$|tizen/']], 'includes/': [['exclude', '_tizen\\.gypi$|tizen/']], @@ -97,43 +69,16 @@ '<(SHARED_INTERMEDIATE_DIR)', ], 'sources': [ - 'converter.cc', - 'converter.h', - 'current_application.cc', - 'current_application.h', - 'extension.cc', - 'extension.h', - 'filter-utils.cc', - 'filter-utils.h', - 'picojson.h', - 'utils.h', - 'logger.cc', - 'logger.h', - 'platform_exception.cc', - 'platform_exception.h', - 'dbus_operation.cc', - 'dbus_operation.h', - 'XW_Extension.h', - 'XW_Extension_EntryPoints.h', - 'XW_Extension_Permissions.h', - 'XW_Extension_Runtime.h', - 'XW_Extension_SyncMessage.h', - 'scope_exit.h', - 'task-queue.cpp', - 'task-queue.h', - 'callback_user_data.cc', - 'callback_user_data.h', - 'optional.h', - #'multi_callback_user_data.cc', - #'multi_callback_user_data.h', - 'platform_result.cc', - 'platform_result.h', - 'assert.h' + 'XW_Extension.cc', ], 'cflags': [ '-std=c++0x', '-fPIC', '-fvisibility=hidden', ], + 'libraries' : [ + '-L .', + '-Wl,-rpath=/usr/lib/tizen-extensions-crosswalk', + ], }, } diff --git a/src/common/extension.cc b/src/common/extension.cc index 7e54aa48..af5c19de 100644 --- a/src/common/extension.cc +++ b/src/common/extension.cc @@ -23,10 +23,19 @@ #include "common/logger.h" #include "common/scope_exit.h" +// This function is hidden, because each plugin needs to have own implementation. +__attribute__ ((visibility ("hidden"))) common::Extension* CreateExtension() { + common::Extension* e = new common::Extension(); + e->SetExtensionName("common"); + return e; +} + namespace { -common::Extension* g_extension = NULL; -XW_Extension g_xw_extension = 0; +// this variable is valid only during Extension::XW_Initialize() call +// do not use !!! +// it's here, so we don't have to modify the interface of CreateExtension(), Extension(), etc. +XW_Extension g_xw_extension_ = 0; const XW_CoreInterface* g_core = NULL; const XW_MessagingInterface* g_messaging = NULL; @@ -36,49 +45,55 @@ const XW_Internal_RuntimeInterface* g_runtime = NULL; const XW_Internal_PermissionsInterface* g_permission = NULL; bool InitializeInterfaces(XW_GetInterface get_interface) { - g_core = reinterpret_cast( - get_interface(XW_CORE_INTERFACE)); - if (!g_core) { - std::cerr << "Can't initialize extension: error getting Core interface.\n"; - return false; - } + static bool initialized = false; - g_messaging = reinterpret_cast( - get_interface(XW_MESSAGING_INTERFACE)); - if (!g_messaging) { - std::cerr << - "Can't initialize extension: error getting Messaging interface.\n"; - return false; - } + if (!initialized) { + g_core = reinterpret_cast( + get_interface(XW_CORE_INTERFACE)); + if (!g_core) { + std::cerr << "Can't initialize extension: error getting Core interface.\n"; + return false; + } - g_sync_messaging = - reinterpret_cast( - get_interface(XW_INTERNAL_SYNC_MESSAGING_INTERFACE)); - if (!g_sync_messaging) { - std::cerr << - "Can't initialize extension: error getting SyncMessaging interface.\n"; - return false; - } + g_messaging = reinterpret_cast( + get_interface(XW_MESSAGING_INTERFACE)); + if (!g_messaging) { + std::cerr << + "Can't initialize extension: error getting Messaging interface.\n"; + return false; + } - g_entry_points = reinterpret_cast( - get_interface(XW_INTERNAL_ENTRY_POINTS_INTERFACE)); - if (!g_entry_points) { - std::cerr << "NOTE: Entry points interface not available in this version " - << "of Crosswalk, ignoring entry point data for extensions.\n"; - } + g_sync_messaging = + reinterpret_cast( + get_interface(XW_INTERNAL_SYNC_MESSAGING_INTERFACE)); + if (!g_sync_messaging) { + std::cerr << + "Can't initialize extension: error getting SyncMessaging interface.\n"; + return false; + } - g_runtime = reinterpret_cast( - get_interface(XW_INTERNAL_RUNTIME_INTERFACE)); - if (!g_runtime) { - std::cerr << "NOTE: runtime interface not available in this version " - << "of Crosswalk, ignoring runtime variables for extensions.\n"; - } + g_entry_points = reinterpret_cast( + get_interface(XW_INTERNAL_ENTRY_POINTS_INTERFACE)); + if (!g_entry_points) { + std::cerr << "NOTE: Entry points interface not available in this version " + << "of Crosswalk, ignoring entry point data for extensions.\n"; + } - g_permission = reinterpret_cast( - get_interface(XW_INTERNAL_PERMISSIONS_INTERFACE)); - if (!g_permission) { - std::cerr << "NOTE: permission interface not available in this version " - << "of Crosswalk, ignoring permission for extensions.\n"; + g_runtime = reinterpret_cast( + get_interface(XW_INTERNAL_RUNTIME_INTERFACE)); + if (!g_runtime) { + std::cerr << "NOTE: runtime interface not available in this version " + << "of Crosswalk, ignoring runtime variables for extensions.\n"; + } + + g_permission = reinterpret_cast( + get_interface(XW_INTERNAL_PERMISSIONS_INTERFACE)); + if (!g_permission) { + std::cerr << "NOTE: permission interface not available in this version " + << "of Crosswalk, ignoring permission for extensions.\n"; + } + + initialized = true; } return true; @@ -86,58 +101,35 @@ bool InitializeInterfaces(XW_GetInterface get_interface) { } // namespace -int32_t XW_Initialize(XW_Extension extension, XW_GetInterface get_interface) { - assert(extension); - g_xw_extension = extension; - - if (!InitializeInterfaces(get_interface)) - return XW_ERROR; - - g_extension = CreateExtension(); - if (!g_extension) { - std::cerr << "Can't initialize extension: " - << "create extension returned NULL.\n"; - return XW_ERROR; - } - - using common::Extension; - g_core->RegisterShutdownCallback(g_xw_extension, Extension::OnShutdown); - g_core->RegisterInstanceCallbacks( - g_xw_extension, Extension::OnInstanceCreated, - Extension::OnInstanceDestroyed); - g_messaging->Register(g_xw_extension, Extension::HandleMessage); - g_sync_messaging->Register(g_xw_extension, Extension::HandleSyncMessage); - return XW_OK; -} - namespace common { -Extension::Extension() {} +Extension::Extension() : xw_extension_(g_xw_extension_) { +} Extension::~Extension() {} void Extension::SetExtensionName(const char* name) { - g_core->SetExtensionName(g_xw_extension, name); + g_core->SetExtensionName(xw_extension_, name); } void Extension::SetJavaScriptAPI(const char* api) { - g_core->SetJavaScriptAPI(g_xw_extension, api); + g_core->SetJavaScriptAPI(xw_extension_, api); } void Extension::SetExtraJSEntryPoints(const char** entry_points) { if (g_entry_points) - g_entry_points->SetExtraJSEntryPoints(g_xw_extension, entry_points); + g_entry_points->SetExtraJSEntryPoints(xw_extension_, entry_points); } bool Extension::RegisterPermissions(const char* perm_table) { if (g_permission) - return g_permission->RegisterPermissions(g_xw_extension, perm_table); + return g_permission->RegisterPermissions(xw_extension_, perm_table); return false; } bool Extension::CheckAPIAccessControl(const char* api_name) { if (g_permission) - return g_permission->CheckAPIAccessControl(g_xw_extension, api_name); + return g_permission->CheckAPIAccessControl(xw_extension_, api_name); return false; } @@ -150,20 +142,13 @@ std::string Extension::GetRuntimeVariable(const char* var_name, unsigned len) { return ""; std::vector res(len + 1, 0); - g_runtime->GetRuntimeVariableString(g_xw_extension, var_name, &res[0], len); + g_runtime->GetRuntimeVariableString(xw_extension_, var_name, &res[0], len); return std::string(res.begin(), res.end()); } // static -void Extension::OnShutdown(XW_Extension) { - delete g_extension; - g_extension = NULL; -} - -// static -void Extension::OnInstanceCreated(XW_Instance xw_instance) { +void Extension::OnInstanceCreated(XW_Instance xw_instance, Instance* instance) { assert(!g_core->GetInstanceData(xw_instance)); - Instance* instance = g_extension->CreateInstance(); if (!instance) return; instance->xw_instance_ = xw_instance; @@ -199,6 +184,36 @@ void Extension::HandleSyncMessage(XW_Instance xw_instance, const char* msg) { instance->HandleSyncMessage(msg); } +//static +int32_t Extension::XW_Initialize(XW_Extension extension, + XW_GetInterface get_interface, + XW_Initialize_Func initialize, + XW_CreatedInstanceCallback created_instance, + XW_ShutdownCallback shutdown) { + assert(extension); + + if (!InitializeInterfaces(get_interface)) { + return XW_ERROR; + } + + g_xw_extension_ = extension; + + if (XW_ERROR == initialize(extension, get_interface)) { + return XW_ERROR; + } + + g_xw_extension_ = 0; + + using common::Extension; + g_core->RegisterShutdownCallback(extension, shutdown); + g_core->RegisterInstanceCallbacks(extension, created_instance, + Extension::OnInstanceDestroyed); + g_messaging->Register(extension, Extension::HandleMessage); + g_sync_messaging->Register(extension, Extension::HandleSyncMessage); + return XW_OK; +} + + Instance::Instance() : xw_instance_(0) {} @@ -376,7 +391,7 @@ class AccessControlImpl { const char* kQuery = "select name from WidgetFeature where app_id = " "(select app_id from WidgetInfo where tizen_appid = ?)" " and rejected = 0"; - const std::string app_id = common::Extension::GetRuntimeVariable("app_id", 64); + const std::string app_id = common::GetCurrentExtension()->GetRuntimeVariable("app_id", 64); sqlite3_stmt* stmt = nullptr; ret = sqlite3_prepare_v2(db, kQuery, -1, &stmt, nullptr); @@ -441,7 +456,7 @@ class AccessControlImpl { } const char* kQuery = "select app_id from WidgetInfo where tizen_appid = ?"; - const std::string app_id = common::Extension::GetRuntimeVariable("app_id", 64); + const std::string app_id = common::GetCurrentExtension()->GetRuntimeVariable("app_id", 64); sqlite3_stmt* stmt = nullptr; ret = sqlite3_prepare_v2(db, kQuery, -1, &stmt, nullptr); diff --git a/src/common/extension.h b/src/common/extension.h index c09845c6..61f8348f 100644 --- a/src/common/extension.h +++ b/src/common/extension.h @@ -42,9 +42,13 @@ class Extension; // an appropriate Extension subclass. common::Extension* CreateExtension(); - namespace common { +// implemented in XW_Extension.cc +// can be called only after the extension is fully created +// (CreateExtension() has been called) +Extension* GetCurrentExtension(); + class Extension { public: Extension(); @@ -61,18 +65,27 @@ class Extension { virtual Instance* CreateInstance(); - static std::string GetRuntimeVariable(const char* var_name, unsigned len); + std::string GetRuntimeVariable(const char* var_name, unsigned len); private: friend int32_t (::XW_Initialize)(XW_Extension extension, - XW_GetInterface get_interface); + XW_GetInterface get_interface); + + static int32_t XW_Initialize(XW_Extension extension, + XW_GetInterface get_interface, + XW_Initialize_Func initialize, + XW_CreatedInstanceCallback created_instance, + XW_ShutdownCallback shutdown); // XW_Extension callbacks. - static void OnShutdown(XW_Extension xw_extension); - static void OnInstanceCreated(XW_Instance xw_instance); + static void OnInstanceCreated(XW_Instance xw_instance, Instance* instance); // modified static void OnInstanceDestroyed(XW_Instance xw_instance); static void HandleMessage(XW_Instance xw_instance, const char* msg); static void HandleSyncMessage(XW_Instance xw_instance, const char* msg); + + XW_Extension xw_extension_; + + class Detail; }; class Instance { diff --git a/src/contact/contact.gyp b/src/contact/contact.gyp index c0b90a35..1d0f5f92 100644 --- a/src/contact/contact.gyp +++ b/src/contact/contact.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_contact', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'contact_api.js', 'contact_extension.cc', diff --git a/src/content/content.gyp b/src/content/content.gyp index ef9bf4ac..b732b7b5 100755 --- a/src/content/content.gyp +++ b/src/content/content.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_content', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'content_api.js', 'content_extension.cc', diff --git a/src/datacontrol/datacontrol.gyp b/src/datacontrol/datacontrol.gyp index 9fce8809..83d8f576 100644 --- a/src/datacontrol/datacontrol.gyp +++ b/src/datacontrol/datacontrol.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_datacontrol', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'datacontrol_api.js', 'datacontrol_extension.cc', diff --git a/src/download/download.gyp b/src/download/download.gyp index fbc669b0..7a5a378d 100644 --- a/src/download/download.gyp +++ b/src/download/download.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_download', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'download_api.js', 'download_extension.cc', @@ -17,8 +20,8 @@ ['tizen == 1', { 'variables': { 'packages': [ - 'capi-web-url-download', - 'capi-system-info' + 'capi-web-url-download', + 'capi-system-info' ] }, }], diff --git a/src/exif/exif.gyp b/src/exif/exif.gyp index 9cc39a59..1be32d02 100644 --- a/src/exif/exif.gyp +++ b/src/exif/exif.gyp @@ -9,6 +9,9 @@ 'includes': [ '../common/pkg-config.gypi', ], + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'exif_api.js', 'exif_extension.cc', diff --git a/src/filesystem/filesystem.gyp b/src/filesystem/filesystem.gyp index 9c49be7f..9e89aa60 100644 --- a/src/filesystem/filesystem.gyp +++ b/src/filesystem/filesystem.gyp @@ -12,6 +12,9 @@ 'storage', ], }, + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'filesystem_api.js', 'filesystem_extension.cc', @@ -31,7 +34,11 @@ ], 'conditions': [ [ 'tizen == 1', { - 'variables': { 'packages': ['vconf'] }, + 'variables': { 'packages': [ + 'vconf', + 'capi-appfw-app-manager', + 'capi-appfw-package-manager', + ] }, }], ], }, diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc index 3092ead4..cd534541 100644 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -256,7 +256,7 @@ void FilesystemManager::StatPath( } static std::string getAppRoot() { - std::string appId = common::Extension::GetRuntimeVariable("app_id", 64); + std::string appId = common::GetCurrentExtension()->GetRuntimeVariable("app_id", 64); app_info_h app_info; int err = app_info_create(appId.c_str(), &app_info); if (err != APP_MANAGER_ERROR_NONE) { diff --git a/src/mediakey/mediakey.gyp b/src/mediakey/mediakey.gyp index 9d2a2fe0..339ea010 100644 --- a/src/mediakey/mediakey.gyp +++ b/src/mediakey/mediakey.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_mediakey', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'mediakey_api.js', 'mediakey_extension.cc', diff --git a/src/messageport/messageport.gyp b/src/messageport/messageport.gyp index e8f8e1e1..87e2e78e 100644 --- a/src/messageport/messageport.gyp +++ b/src/messageport/messageport.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_messageport', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'messageport_api.js', 'messageport_extension.cc', diff --git a/src/messaging/messaging.gyp b/src/messaging/messaging.gyp index 3c0b21db..e65e98f3 100644 --- a/src/messaging/messaging.gyp +++ b/src/messaging/messaging.gyp @@ -7,6 +7,9 @@ { 'target_name': 'tizen_messaging', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'variables': { 'packages': [ 'msg-service', diff --git a/src/networkbearerselection/networkbearerselection.gyp b/src/networkbearerselection/networkbearerselection.gyp index c868701f..f441d57c 100644 --- a/src/networkbearerselection/networkbearerselection.gyp +++ b/src/networkbearerselection/networkbearerselection.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_networkbearerselection', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'variables': { 'packages': [ 'icu-i18n', diff --git a/src/nfc/nfc.gyp b/src/nfc/nfc.gyp index 53a67fcb..7fce11cf 100644 --- a/src/nfc/nfc.gyp +++ b/src/nfc/nfc.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_nfc', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'nfc_api.js', 'nfc_extension.cc', diff --git a/src/notification/notification.gyp b/src/notification/notification.gyp index 908fa320..2d7e10d0 100755 --- a/src/notification/notification.gyp +++ b/src/notification/notification.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_notification', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'notification_api.js', 'notification_extension.cc', diff --git a/src/package/package.gyp b/src/package/package.gyp index 3d212137..bd95af3d 100644 --- a/src/package/package.gyp +++ b/src/package/package.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_package', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'package_api.js', 'package_extension.cc', diff --git a/src/power/power.gyp b/src/power/power.gyp index 5c24a1c0..8b6c10ff 100755 --- a/src/power/power.gyp +++ b/src/power/power.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_power', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'power_api.js', 'power_extension.cc', diff --git a/src/push/push.gyp b/src/push/push.gyp index 11922305..317c0a69 100644 --- a/src/push/push.gyp +++ b/src/push/push.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_push', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'push_api.js', 'push_extension.cc', diff --git a/src/radio/radio.gyp b/src/radio/radio.gyp index a0d18785..79d37d59 100644 --- a/src/radio/radio.gyp +++ b/src/radio/radio.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_fmradio', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'radio_api.js', 'radio_extension.cc', diff --git a/src/secureelement/secureelement.gyp b/src/secureelement/secureelement.gyp index 64433572..a302c6a3 100644 --- a/src/secureelement/secureelement.gyp +++ b/src/secureelement/secureelement.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_secureelement', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'secureelement_api.js', 'secureelement_extension.cc', diff --git a/src/sensor/sensor.gyp b/src/sensor/sensor.gyp index d60eccf5..22c3fd7b 100644 --- a/src/sensor/sensor.gyp +++ b/src/sensor/sensor.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_sensor', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'sensor_api.js', 'sensor_extension.cc', diff --git a/src/sound/sound.gyp b/src/sound/sound.gyp index c67c3310..e4210895 100644 --- a/src/sound/sound.gyp +++ b/src/sound/sound.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_sound', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'variables': { 'packages': [ 'icu-i18n', diff --git a/src/systeminfo/systeminfo.gyp b/src/systeminfo/systeminfo.gyp index 06759112..9137bd95 100644 --- a/src/systeminfo/systeminfo.gyp +++ b/src/systeminfo/systeminfo.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_systeminfo', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'systeminfo_api.js', 'systeminfo_extension.cc', diff --git a/src/systemsetting/systemsetting.gyp b/src/systemsetting/systemsetting.gyp index 1b455ba5..815fed4f 100644 --- a/src/systemsetting/systemsetting.gyp +++ b/src/systemsetting/systemsetting.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_systemsetting', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'systemsetting_api.js', 'systemsetting_extension.cc', diff --git a/src/time/time.gyp b/src/time/time.gyp index 1e4fa4b8..a7a2d263 100644 --- a/src/time/time.gyp +++ b/src/time/time.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_time', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'variables': { 'packages': [ 'icu-i18n', diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index e25042ec..0c73f5d7 100755 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -8,6 +8,7 @@ 'target_name': 'build_all_tizen_extensions', 'type': 'none', 'dependencies': [ + 'common/common.gyp:*', 'tizen/tizen.gyp:*', 'utils/utils.gyp:*', ], diff --git a/src/tizen/tizen.gyp b/src/tizen/tizen.gyp index fe811e8d..df68e91d 100644 --- a/src/tizen/tizen.gyp +++ b/src/tizen/tizen.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'tizen.h', 'tizen_api.js', diff --git a/src/tvaudio/tvaudio.gyp b/src/tvaudio/tvaudio.gyp index 5d8f7230..1ccd1f55 100644 --- a/src/tvaudio/tvaudio.gyp +++ b/src/tvaudio/tvaudio.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_tvaudio', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'tvaudio_api.js', 'tvaudio_extension.cc', diff --git a/src/tvchannel/tvchannel.gyp b/src/tvchannel/tvchannel.gyp index ddc2af36..233578d8 100644 --- a/src/tvchannel/tvchannel.gyp +++ b/src/tvchannel/tvchannel.gyp @@ -12,6 +12,7 @@ ], }, 'dependencies': [ + '../common/common.gyp:tizen_common', '../tizen/tizen.gyp:tizen', ], 'includes': [ diff --git a/src/tvdisplay/tvdisplay.gyp b/src/tvdisplay/tvdisplay.gyp index 8e61c743..d56c01ab 100644 --- a/src/tvdisplay/tvdisplay.gyp +++ b/src/tvdisplay/tvdisplay.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_tvdisplay', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'includes': [ '../common/pkg-config.gypi', ], diff --git a/src/tvinputdevice/tvinputdevice.gyp b/src/tvinputdevice/tvinputdevice.gyp index c0201fa1..d404756d 100644 --- a/src/tvinputdevice/tvinputdevice.gyp +++ b/src/tvinputdevice/tvinputdevice.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_tvinputdevice', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'tvinputdevice_api.js', 'tvinputdevice_extension.cc', diff --git a/src/tvwindow/tvwindow.gyp b/src/tvwindow/tvwindow.gyp index 93e84eed..7fa8917b 100644 --- a/src/tvwindow/tvwindow.gyp +++ b/src/tvwindow/tvwindow.gyp @@ -12,6 +12,7 @@ ], }, 'dependencies': [ + '../common/common.gyp:tizen_common', '../tizen/tizen.gyp:tizen', ], 'includes': [ diff --git a/src/utils/utils.gyp b/src/utils/utils.gyp index 0a79b49b..a6f1c77b 100644 --- a/src/utils/utils.gyp +++ b/src/utils/utils.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_utils', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'utils_api.js', 'utils_extension.cc', diff --git a/src/websetting/websetting.gyp b/src/websetting/websetting.gyp index 20e4d184..b20a8736 100644 --- a/src/websetting/websetting.gyp +++ b/src/websetting/websetting.gyp @@ -6,6 +6,9 @@ { 'target_name': 'tizen_websetting', 'type': 'loadable_module', + 'dependencies': [ + '../common/common.gyp:tizen_common', + ], 'sources': [ 'websetting.cc', 'websetting.h', diff --git a/src/websetting/websetting.h b/src/websetting/websetting.h index 8bb5674c..80102155 100644 --- a/src/websetting/websetting.h +++ b/src/websetting/websetting.h @@ -16,6 +16,8 @@ class WebSetting { explicit WebSetting(const std::string& app_id); ~WebSetting(); + std::string app_id() const { return app_id_; } + std::unique_ptr RemoveAllCookies(); std::unique_ptr SetUserAgentString( const std::string& user_agent); diff --git a/src/websetting/websetting_extension.cc b/src/websetting/websetting_extension.cc index 113d0f61..4f2ee0a4 100644 --- a/src/websetting/websetting_extension.cc +++ b/src/websetting/websetting_extension.cc @@ -9,19 +9,27 @@ #include "websetting/websetting.h" #include "websetting/websetting_instance.h" +#include "common/logger.h" + extern const char kSource_websetting_api[]; common::Extension* CreateExtension() { - std::string env_app_id = common::Extension::GetRuntimeVariable("app_id", 64); - std::string app_id = env_app_id.substr(1, env_app_id.rfind('"') - 1); - if (app_id.empty()) { - std::cerr << "Got invalid application ID." << std::endl; + WebSettingExtension* e = new WebSettingExtension(); + + if (e->current_app()->app_id().empty()) { + LoggerE("Got invalid application ID."); + delete e; return nullptr; } - return new WebSettingExtension(app_id); + + return e; } -WebSettingExtension::WebSettingExtension(const std::string& app_id) { +WebSettingExtension::WebSettingExtension() { + std::string app_id = GetRuntimeVariable("app_id", 64); + + LoggerD("app_id: %s", app_id.c_str()); + current_app_.reset(new WebSetting(app_id)); SetExtensionName("tizen.websetting"); SetJavaScriptAPI(kSource_websetting_api); diff --git a/src/websetting/websetting_extension.h b/src/websetting/websetting_extension.h index e6a1f9a1..96c28e64 100644 --- a/src/websetting/websetting_extension.h +++ b/src/websetting/websetting_extension.h @@ -12,7 +12,7 @@ class WebSettingExtension : public common::Extension { public: - explicit WebSettingExtension(const std::string& app_id); + WebSettingExtension(); virtual ~WebSettingExtension(); WebSetting* current_app() { return current_app_.get(); } diff --git a/src/websetting/websetting_instance.cc b/src/websetting/websetting_instance.cc index 2964147b..19335c14 100644 --- a/src/websetting/websetting_instance.cc +++ b/src/websetting/websetting_instance.cc @@ -52,7 +52,7 @@ void WebSettingInstance::WebSettingManagerSetUserAgentString( const double callback_id = args.get("callbackId").get(); auto get = [=](const std::shared_ptr& response) -> void { const char* runtime_name = - common::Extension::GetRuntimeVariable("runtime_name", 64).c_str(); + common::GetCurrentExtension()->GetRuntimeVariable("runtime_name", 64).c_str(); LoggerD("runtime_name: %s", runtime_name); if (strcmp(runtime_name, kWrtServiceName) == 0) { ReportError( @@ -87,7 +87,7 @@ void WebSettingInstance::WebSettingManagerRemoveAllCookies( const double callback_id = args.get("callbackId").get(); auto get = [=](const std::shared_ptr& response) -> void { const char* runtime_name = - common::Extension::GetRuntimeVariable("runtime_name", 64).c_str(); + common::GetCurrentExtension()->GetRuntimeVariable("runtime_name", 64).c_str(); LoggerD("runtime_name: %s", runtime_name); if (strcmp(runtime_name, kWrtServiceName) == 0) { ReportError(