[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 3a5a3020bd69483810a071055c7aa3b8a4336299..272a0435babb79f3eccd9e876efab95e9257cb22 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 1ef284d401c57eb11e4c9e609d36bb77e33357be..dc1135a183686030353c54c5dd69160c12a40c62 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 920503532f6562b350de96f19531dc435a1f95f6..62a83855a1c5b606f895150c9c0c606038451a5e 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 e56b027b6de0a15bd76044cdf580d9386503365a..1156ed338992b9fabd5e6d86592e8179e599c575 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 36b1f0d6b25d2d937bad29c8e96a8bf3a54e1e8e..5bc40cca5a0c8a45b0d7ab500616fc7bdca0cf63 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 8f157fee8ffe30fe0891bf5f9364d5585bf1d111..7128cb0a2ed755229bccf85ecf4a8c9a360301c9 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 751d0ac969660a06f7dd0f2a095b03ef9202dfa6..589e4779054a2a218336b32429529fe0248dbdcc 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 d8cdb7f6543b1ff64cb3074abc8c32e7aadbd8e0..da96e28518e4f5e8d0489bc72930c912407662df 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 e21e36077e9dcb3df5eb7e7c946b34a3e6c75036..3ce1d82a1e6646456d0e2044f1ae1550c5800349 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 5bd3eabed0ddd795d9801ea7ea04ca1e7bc96143..5d1af2fb08e20214d972dfe70eb46059af667fde 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 8f08efd3f4e8814066b658af42acbf7d40a5ca17..5b9798e05e550b1738b4c5a2e014e1e86b7f9d0c 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 b4f1f09abd0d6ab3fa2fb8ee60e1575b840ed00b..3e88ecc0f999b95a61f845d8f451387d974d7bad 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 a8ac618844d4de159cc2a9363fbdd2fa7015cf8b..59229ddc691e8dd8cbbac2bfd8302b394f6bd785 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 7e54aa48e9ad15d7bd6d96780a3d566297dfe81a..af5c19de59bcac0eeecd35ad6de194b902d8095f 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 c09845c6cc37280b79178789291990a04a70f294..61f8348f45f0c64f1d1619ce75328382c443030f 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 c0b90a35029f1abe2666ab0df4d454a7d5d5ffe4..1d0f5f92e4f2effc456f22b40e79ec422a7e27ee 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 ef9bf4acdf85855e9eb355fc5610344c0391823d..b732b7b5d7b606188fd239e657a6a627b0cbeaf9 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 9fce8809b68694bfc0e752632aae62342573dca9..83d8f5768bc59c711304cee59b4df3cc8eb4e59f 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 fbc669b09da560c3568c65c958a78a148ffb20d7..7a5a378d64936e86fc84d0e87544a5565867c310 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 9cc39a591bd51adce802ca1637518e06e900cab7..1be32d020cbb019267f08906a9cbd13c6c56102f 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 9c49be7fd17c51b0388061cc96eebb81029161a4..9e89aa6043ca12f9fbb80943b66342b7cff8141b 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 3092ead48b7bff72141cb81cf7cd3aa908230cd1..cd53454117b307893dc7fa2f07df24b0918faaf6 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 9d2a2fe0134b4b2a2e0f47cfd0a4faf437f3b7b8..339ea01013dfd420ec1c4c63ccff6919fb17eecd 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 e8f8e1e1f6767e14631955ac5902864a26be87de..87e2e78eca96b720adc63cd6e91cfd46c360a4ea 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 3c0b21db0bd79056cc27d9683bbb8e9bd1b9295b..e65e98f3847fe1818b5199c6be2e8f84fcc2b8ba 100644 (file)
@@ -7,6 +7,9 @@
     {
       'target_name': 'tizen_messaging',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
             'msg-service',
index c868701f2f74c7ad77bf6a978dd9885197954102..f441d57c4a003939ca155350683b035f3188c972 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_networkbearerselection',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
           'icu-i18n',
index 53a67fcbf5df28a83f3b2ab7c7084886aa96f97a..7fce11cf630f6843e9ce062bfb5606786bfdfb3a 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 908fa320ed1fb9b3617e1604c85e96d82fe53623..2d7e10d0cbe0f3c122f75e0b1cc1b3d3cf1ea351 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 3d2121375ef16d2ea3e01d43f87fac1e10cdaeb5..bd95af3dfb56d62bc699c6b2ec35f449907cf446 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 5c24a1c0e22f79ad7cc274df31251e574a82a16a..8b6c10ffe99c72c7416d13fb9e91c21ff650815d 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 119223055f4f3617b8d8477e84c4c2fa217597f8..317c0a693e3833a9c6a188c8e157704a6300781b 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 a0d18785e800641f176c5c9cb0dc3dc488224d31..79d37d5998dc61a2b8d23f587a54a24fd25f7552 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 64433572414aacaf94342d9274ab88c2b2fc4a92..a302c6a30c990f1fa79704fdc7bad2fe791a2054 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 d60eccf5503ba55398209e3017c6d82eec48ca6b..22c3fd7bb300bfbad93e316fb4fcb5674cee4ef1 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 c67c33101be61913cc142a8db7136ec221e0e330..e4210895722de19781b56d0c300388cfad7433a4 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_sound',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
           'icu-i18n',
index 067591122e2b6e27b9e9d10c8fdd43aa6a2b440e..9137bd957128260379a2129ea5fdab19acf664df 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 1b455ba59d2b82c071034dc79bf909a0a1bdee35..815fed4f33dff7df08fe1e6d5b03948cb9c82db9 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 1e4fa4b811f8ef6ba9206757096f1f6a5de3f11c..a7a2d263f385d777a6c876094c3bc35b824780e9 100644 (file)
@@ -6,6 +6,9 @@
     {
       'target_name': 'tizen_time',
       'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
       'variables': {
         'packages': [
           'icu-i18n',
index e25042ec7d547e68217132547f8272aa10aa618b..0c73f5d76d2e491e37059abd1fe9411d816e9cee 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 fe811e8dc70a4b1e8b58c44ee3dd01ca6ed304e1..df68e91d55adfb29e10454eb584b892c09fffa94 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 5d8f7230f10ffc729c4fa038133adcfd5858f72a..1ccd1f554490cdc9c59b425de562074524252ed1 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 ddc2af36aa5bf6bd3acdd3977fe9265c5d37d88d..233578d84fcdba62c994e595169f11c8bdb675f2 100644 (file)
@@ -12,6 +12,7 @@
         ],
       },
       'dependencies': [
+        '../common/common.gyp:tizen_common',
         '../tizen/tizen.gyp:tizen',
       ],
       'includes': [
index 8e61c7432091426c09c2e4c747a184337be9eb7c..d56c01abba3e077e01f597f01dd6bae1fbfd4a01 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 c0201fa1e001e5b35002ad6b3c6255ca19875143..d404756d624d5054ea6783ffce235dd3dc98f70a 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 93e84eed4332e65a878053aa62695a371f9dd04f..7fa8917bed744c5393dcbfcb631b3b9ead8eb21a 100644 (file)
@@ -12,6 +12,7 @@
         ],
       },
       'dependencies': [
+        '../common/common.gyp:tizen_common',
         '../tizen/tizen.gyp:tizen',
       ],
       'includes': [
index 0a79b49bb56b1a29d27424cef179daee8f1d4f9c..a6f1c77bcef281ceadf468862ee8460c0bdfde5a 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 20e4d184db8de0d2ed9adf79452483927faaa89b..b20a873663237ab6a702714ab5b87ccb79a4de56 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 8bb5674cac6bfc0c8c8095cc7711a371a1d0c71a..80102155e3b64edf4fa719078e954ff234ea212c 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 113d0f61f10450d30cae333c9aeb2b67b5aa9629..4f2ee0a4bb9aba4fb303ed16c9377bfb0f427c72 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 e6a1f9a13e5b2fdc1d2547123f77b59e4cfcb821..96c28e64d92de8b5a7cfa96659a8441fbc7ee766 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 2964147be2149185fba0d30c30f3f47621397d50..19335c14c9928cd2fc4fcecb3566af8a28744ce9 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(