[Common] Common code has been extracted to a separate library.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 24 Mar 2015 09:28:17 +0000 (10:28 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 26 Mar 2015 10:30:01 +0000 (19:30 +0900)
Change-Id: Ibd1223378a367b8cb9ec05a052e575c90a4bea80

53 files changed:
src/account/account.gyp
src/alarm/alarm.gyp
src/application/application.gyp
src/application/application_extension.cc
src/application/application_extension.h
src/application/application_instance.cc
src/archive/archive.gyp
src/badge/badge.gyp
src/bluetooth/bluetooth.gyp
src/bookmark/bookmark.gyp
src/calendar/calendar.gyp
src/callhistory/callhistory.gyp
src/common/XW_Extension.cc [new file with mode: 0644]
src/common/common.gyp [new file with mode: 0644]
src/common/common.gypi
src/common/extension.cc
src/common/extension.h
src/contact/contact.gyp
src/content/content.gyp
src/datacontrol/datacontrol.gyp
src/download/download.gyp
src/exif/exif.gyp
src/filesystem/filesystem.gyp
src/filesystem/filesystem_manager.cc
src/mediakey/mediakey.gyp
src/messageport/messageport.gyp
src/messaging/messaging.gyp
src/networkbearerselection/networkbearerselection.gyp
src/nfc/nfc.gyp
src/notification/notification.gyp
src/package/package.gyp
src/power/power.gyp
src/push/push.gyp
src/radio/radio.gyp
src/secureelement/secureelement.gyp
src/sensor/sensor.gyp
src/sound/sound.gyp
src/systeminfo/systeminfo.gyp
src/systemsetting/systemsetting.gyp
src/time/time.gyp
src/tizen-wrt.gyp
src/tizen/tizen.gyp
src/tvaudio/tvaudio.gyp
src/tvchannel/tvchannel.gyp
src/tvdisplay/tvdisplay.gyp
src/tvinputdevice/tvinputdevice.gyp
src/tvwindow/tvwindow.gyp
src/utils/utils.gyp
src/websetting/websetting.gyp
src/websetting/websetting.h
src/websetting/websetting_extension.cc
src/websetting/websetting_extension.h
src/websetting/websetting_instance.cc

index 3a5a302..272a043 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_account',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'account_api.js',
         'account_extension.cc',
index 1ef284d..dc1135a 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_alarm',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'alarm_api.js',
         'alarm_extension.cc',
index 9205035..62a8385 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_application',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'application_api.js',
         'application_extension.cc',
index e56b027..1156ed3 100644 (file)
 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);
index 36b1f0d..5bc40cc 100644 (file)
 
 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.
index 8f157fe..7128cb0 100644 (file)
@@ -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);
index 751d0ac..589e477 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_archive',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'archive_api.js',
         'archive_extension.cc',
index d8cdb7f..da96e28 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_badge',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'badge_api.js',
         'badge_extension.cc',
index e21e360..3ce1d82 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_bluetooth',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'bluetooth_api.js',
         'bluetooth_adapter.cc',
index 5bd3eab..5d1af2f 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_bookmark',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'bookmark_api.js',
         'bookmark_extension.cc',
index 8f08efd..5b9798e 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_calendar',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'calendar_api.js',
         'calendar_extension.cc',
index b4f1f09..3e88ecc 100644 (file)
@@ -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 (file)
index 0000000..507a92b
--- /dev/null
@@ -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 (file)
index 0000000..d0e4e0c
--- /dev/null
@@ -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',
+        ],
+      },
+    },
+  ],
+}
index a8ac618..59229dd 100644 (file)
             '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/']],
       '<(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',
+    ],
   },
 }
index 7e54aa4..af5c19d 100644 (file)
 #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<const XW_CoreInterface*>(
-      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<const XW_MessagingInterface*>(
-      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<const XW_CoreInterface*>(
+        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<const XW_Internal_SyncMessagingInterface*>(
-          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<const XW_MessagingInterface*>(
+        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<const XW_Internal_EntryPointsInterface*>(
-      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<const XW_Internal_SyncMessagingInterface*>(
+            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<const XW_Internal_RuntimeInterface*>(
-      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<const XW_Internal_EntryPointsInterface*>(
+        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<const XW_Internal_PermissionsInterface*>(
-      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<const XW_Internal_RuntimeInterface*>(
+        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<const XW_Internal_PermissionsInterface*>(
+        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<char> 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);
index c09845c..61f8348 100644 (file)
@@ -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 {
index c0b90a3..1d0f5f9 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_contact',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'contact_api.js',
         'contact_extension.cc',
index ef9bf4a..b732b7b 100755 (executable)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_content',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'content_api.js',
         'content_extension.cc',
index 9fce880..83d8f57 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_datacontrol',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'datacontrol_api.js',
         'datacontrol_extension.cc',
index fbc669b..7a5a378 100644 (file)
@@ -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'
             ]
           },
         }],
index 9cc39a5..1be32d0 100644 (file)
@@ -9,6 +9,9 @@
       'includes': [
         '../common/pkg-config.gypi',
       ],
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'exif_api.js',
         'exif_extension.cc',
index 9c49be7..9e89aa6 100644 (file)
@@ -12,6 +12,9 @@
           'storage',
         ],
       },
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'filesystem_api.js',
         'filesystem_extension.cc',
       ],
       'conditions': [
         [ 'tizen == 1', {
-            'variables': { 'packages': ['vconf'] },
+            'variables': { 'packages': [
+              'vconf',
+              'capi-appfw-app-manager',
+              'capi-appfw-package-manager',
+            ] },
         }],
       ],
     },
index 3092ead..cd53454 100644 (file)
@@ -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) {
index 9d2a2fe..339ea01 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_mediakey',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'mediakey_api.js',
         'mediakey_extension.cc',
index e8f8e1e..87e2e78 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_messageport',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'messageport_api.js',
         'messageport_extension.cc',
index 3c0b21d..e65e98f 100644 (file)
@@ -7,6 +7,9 @@
     {
       'target_name': 'tizen_messaging',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
             'msg-service',
index c868701..f441d57 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_networkbearerselection',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
           'icu-i18n',
index 53a67fc..7fce11c 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_nfc',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'nfc_api.js',
         'nfc_extension.cc',
index 908fa32..2d7e10d 100755 (executable)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_notification',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'notification_api.js',
         'notification_extension.cc',
index 3d21213..bd95af3 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_package',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'package_api.js',
         'package_extension.cc',
index 5c24a1c..8b6c10f 100755 (executable)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_power',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'power_api.js',
         'power_extension.cc',
index 1192230..317c0a6 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_push',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'push_api.js',
         'push_extension.cc',
index a0d1878..79d37d5 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_fmradio',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'radio_api.js',
         'radio_extension.cc',
index 6443357..a302c6a 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_secureelement',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'secureelement_api.js',
         'secureelement_extension.cc',
index d60eccf..22c3fd7 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_sensor',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'sensor_api.js',
         'sensor_extension.cc',
index c67c331..e421089 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_sound',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
           'icu-i18n',
index 0675911..9137bd9 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_systeminfo',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'systeminfo_api.js',
         'systeminfo_extension.cc',
index 1b455ba..815fed4 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_systemsetting',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'systemsetting_api.js',
         'systemsetting_extension.cc',
index 1e4fa4b..a7a2d26 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_time',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
           'icu-i18n',
index e25042e..0c73f5d 100755 (executable)
@@ -8,6 +8,7 @@
       'target_name': 'build_all_tizen_extensions',
       'type': 'none',
       'dependencies': [
+        'common/common.gyp:*',
         'tizen/tizen.gyp:*',
         'utils/utils.gyp:*',
       ],
index fe811e8..df68e91 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'tizen.h',
         'tizen_api.js',
index 5d8f723..1ccd1f5 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_tvaudio',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'tvaudio_api.js',
         'tvaudio_extension.cc',
index ddc2af3..233578d 100644 (file)
@@ -12,6 +12,7 @@
         ],
       },
       'dependencies': [
+        '../common/common.gyp:tizen_common',
         '../tizen/tizen.gyp:tizen',
       ],
       'includes': [
index 8e61c74..d56c01a 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_tvdisplay',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'includes': [
         '../common/pkg-config.gypi',
       ],
index c0201fa..d404756 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_tvinputdevice',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'tvinputdevice_api.js',
         'tvinputdevice_extension.cc',
index 93e84ee..7fa8917 100644 (file)
@@ -12,6 +12,7 @@
         ],
       },
       'dependencies': [
+        '../common/common.gyp:tizen_common',
         '../tizen/tizen.gyp:tizen',
       ],
       'includes': [
index 0a79b49..a6f1c77 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_utils',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'utils_api.js',
         'utils_extension.cc',
index 20e4d18..b20a873 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_websetting',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'sources': [
         'websetting.cc',
         'websetting.h',
index 8bb5674..8010215 100644 (file)
@@ -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<picojson::value> RemoveAllCookies();
   std::unique_ptr<picojson::value> SetUserAgentString(
       const std::string& user_agent);
index 113d0f6..4f2ee0a 100644 (file)
@@ -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);
index e6a1f9a..96c28e6 100644 (file)
@@ -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(); }
index 2964147..19335c1 100644 (file)
@@ -52,7 +52,7 @@ void WebSettingInstance::WebSettingManagerSetUserAgentString(
   const double callback_id = args.get("callbackId").get<double>();
   auto get = [=](const std::shared_ptr<JsonValue>& 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<double>();
   auto get = [=](const std::shared_ptr<JsonValue>& 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(