Move extension loader to the renderer process
authorWonYoung Choi <wy80.choi@samsung.com>
Fri, 5 Feb 2016 00:28:22 +0000 (09:28 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Mon, 15 Feb 2016 23:55:05 +0000 (08:55 +0900)
Remove the xwalk-extension process and load extensions in the
renderer process.

31 files changed:
extensions/common/xwalk_extension.cc [new file with mode: 0644]
extensions/common/xwalk_extension.h [new file with mode: 0644]
extensions/common/xwalk_extension_adapter.cc [new file with mode: 0644]
extensions/common/xwalk_extension_adapter.h [new file with mode: 0644]
extensions/common/xwalk_extension_instance.cc [new file with mode: 0644]
extensions/common/xwalk_extension_instance.h [new file with mode: 0644]
extensions/common/xwalk_extension_manager.cc [new file with mode: 0644]
extensions/common/xwalk_extension_manager.h [new file with mode: 0644]
extensions/extension/xwalk_extension.cc [deleted file]
extensions/extension/xwalk_extension.h [deleted file]
extensions/extension/xwalk_extension_adapter.cc [deleted file]
extensions/extension/xwalk_extension_adapter.h [deleted file]
extensions/extension/xwalk_extension_instance.cc [deleted file]
extensions/extension/xwalk_extension_instance.h [deleted file]
extensions/extension/xwalk_extension_process.cc [deleted file]
extensions/extension/xwalk_extension_server.cc [deleted file]
extensions/extension/xwalk_extension_server.h [deleted file]
extensions/extensions.gyp
extensions/renderer/xwalk_extension_client.cc
extensions/renderer/xwalk_extension_client.h
extensions/renderer/xwalk_extension_module.cc
extensions/renderer/xwalk_extension_module.h
extensions/renderer/xwalk_extension_renderer_controller.cc
extensions/renderer/xwalk_extension_renderer_controller.h
extensions/renderer/xwalk_module_system.cc
packaging/crosswalk-tizen.spec
runtime/browser/runtime.cc
runtime/common/constants.cc
runtime/common/constants.h
runtime/renderer/injected_bundle.cc
runtime/runtime.gyp

diff --git a/extensions/common/xwalk_extension.cc b/extensions/common/xwalk_extension.cc
new file mode 100644 (file)
index 0000000..0110bb2
--- /dev/null
@@ -0,0 +1,123 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/xwalk_extension.h"
+
+#include <dlfcn.h>
+#include <string>
+
+#include "common/logger.h"
+#include "extensions/common/xwalk_extension_adapter.h"
+#include "extensions/public/XW_Extension.h"
+
+namespace extensions {
+
+XWalkExtension::XWalkExtension(const std::string& path,
+                               XWalkExtensionDelegate* delegate)
+  : initialized_(false),
+    library_path_(path),
+    xw_extension_(0),
+    lazy_loading_(false),
+    delegate_(delegate),
+    created_instance_callback_(NULL),
+    destroyed_instance_callback_(NULL),
+    shutdown_callback_(NULL),
+    handle_msg_callback_(NULL),
+    handle_sync_msg_callback_(NULL) {
+}
+
+XWalkExtension::XWalkExtension(const std::string& path,
+                               const std::string& name,
+                               const StringVector& entry_points,
+                               XWalkExtensionDelegate* delegate)
+  : initialized_(false),
+    library_path_(path),
+    xw_extension_(0),
+    name_(name),
+    entry_points_(entry_points),
+    lazy_loading_(true),
+    delegate_(delegate),
+    created_instance_callback_(NULL),
+    destroyed_instance_callback_(NULL),
+    shutdown_callback_(NULL),
+    handle_msg_callback_(NULL),
+    handle_sync_msg_callback_(NULL) {
+}
+
+XWalkExtension::~XWalkExtension() {
+  if (!initialized_)
+    return;
+
+  if (shutdown_callback_)
+    shutdown_callback_(xw_extension_);
+  XWalkExtensionAdapter::GetInstance()->UnregisterExtension(this);
+}
+
+bool XWalkExtension::Initialize() {
+  if (initialized_)
+    return true;
+
+  void* handle = dlopen(library_path_.c_str(), RTLD_LAZY);
+  if (!handle) {
+    LOGGER(ERROR) << "Error loading extension '"
+                  << library_path_ << "' : " << dlerror();
+    return false;
+  }
+
+  XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>(
+      dlsym(handle, "XW_Initialize"));
+  if (!initialize) {
+    LOGGER(ERROR) << "Error loading extension '" << library_path_
+                  << "' : couldn't get XW_Initialize function.";
+    dlclose(handle);
+    return false;
+  }
+
+  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
+  xw_extension_ = adapter->GetNextXWExtension();
+  adapter->RegisterExtension(this);
+
+  int ret = initialize(xw_extension_, XWalkExtensionAdapter::GetInterface);
+  if (ret != XW_OK) {
+    LOGGER(ERROR) << "Error loading extension '" << library_path_
+                  << "' : XW_Initialize() returned error value.";
+    dlclose(handle);
+    return false;
+  }
+
+  initialized_ = true;
+  return true;
+}
+
+XWalkExtensionInstance* XWalkExtension::CreateInstance() {
+  Initialize();
+  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
+  XW_Instance xw_instance = adapter->GetNextXWInstance();
+  return new XWalkExtensionInstance(this, xw_instance);
+}
+
+std::string XWalkExtension::GetJavascriptCode() {
+  Initialize();
+  return javascript_api_;
+}
+
+void XWalkExtension::GetRuntimeVariable(const char* key, char* value,
+    size_t value_len) {
+  if (delegate_) {
+    delegate_->GetRuntimeVariable(key, value, value_len);
+  }
+}
+int XWalkExtension::CheckAPIAccessControl(const char* /*api_name*/) {
+  // Not Supported
+  return XW_OK;
+}
+
+int XWalkExtension::RegisterPermissions(const char* /*perm_table*/) {
+  // Not Supported
+  return XW_OK;
+}
+
+}  // namespace extensions
+
diff --git a/extensions/common/xwalk_extension.h b/extensions/common/xwalk_extension.h
new file mode 100644 (file)
index 0000000..85af14c
--- /dev/null
@@ -0,0 +1,80 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_H_
+#define XWALK_EXTENSIONS_XWALK_EXTENSION_H_
+
+#include <string>
+#include <vector>
+
+#include "extensions/common/xwalk_extension_instance.h"
+#include "extensions/public/XW_Extension.h"
+#include "extensions/public/XW_Extension_SyncMessage.h"
+
+namespace extensions {
+
+class XWalkExtensionAdapter;
+class XWalkExtensionInstance;
+
+class XWalkExtension {
+ public:
+  typedef std::vector<std::string> StringVector;
+
+  class XWalkExtensionDelegate {
+   public:
+    virtual void GetRuntimeVariable(const char* key, char* value,
+        size_t value_len) = 0;
+  };
+
+  XWalkExtension(const std::string& path, XWalkExtensionDelegate* delegate);
+  XWalkExtension(const std::string& path,
+                 const std::string& name,
+                 const StringVector& entry_points,
+                 XWalkExtensionDelegate* delegate);
+  virtual ~XWalkExtension();
+
+  bool Initialize();
+  XWalkExtensionInstance* CreateInstance();
+  std::string GetJavascriptCode();
+
+  std::string name() const { return name_; }
+
+  const StringVector& entry_points() const {
+    return entry_points_;
+  }
+
+  bool lazy_loading() const {
+    return lazy_loading_;
+  }
+
+ private:
+  friend class XWalkExtensionAdapter;
+  friend class XWalkExtensionInstance;
+
+  void GetRuntimeVariable(const char* key, char* value, size_t value_len);
+  int CheckAPIAccessControl(const char* api_name);
+  int RegisterPermissions(const char* perm_table);
+
+  bool initialized_;
+  std::string library_path_;
+  XW_Extension xw_extension_;
+
+  std::string name_;
+  std::string javascript_api_;
+  StringVector entry_points_;
+  bool lazy_loading_;
+
+  XWalkExtensionDelegate* delegate_;
+
+  XW_CreatedInstanceCallback created_instance_callback_;
+  XW_DestroyedInstanceCallback destroyed_instance_callback_;
+  XW_ShutdownCallback shutdown_callback_;
+  XW_HandleMessageCallback handle_msg_callback_;
+  XW_HandleSyncMessageCallback handle_sync_msg_callback_;
+};
+
+}  // namespace extensions
+
+#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_H_
diff --git a/extensions/common/xwalk_extension_adapter.cc b/extensions/common/xwalk_extension_adapter.cc
new file mode 100644 (file)
index 0000000..391a130
--- /dev/null
@@ -0,0 +1,294 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/xwalk_extension_adapter.h"
+
+#include <string>
+
+#include "common/logger.h"
+
+namespace extensions {
+
+XWalkExtensionAdapter::XWalkExtensionAdapter()
+  : next_xw_extension_(1),
+    next_xw_instance_(1) {
+}
+
+XWalkExtensionAdapter::~XWalkExtensionAdapter() {
+}
+
+XWalkExtensionAdapter* XWalkExtensionAdapter::GetInstance() {
+  static XWalkExtensionAdapter self;
+  return &self;
+}
+
+XW_Extension XWalkExtensionAdapter::GetNextXWExtension() {
+  return next_xw_extension_++;
+}
+
+XW_Instance XWalkExtensionAdapter::GetNextXWInstance() {
+  return next_xw_instance_++;
+}
+
+void XWalkExtensionAdapter::RegisterExtension(XWalkExtension* extension) {
+  XW_Extension xw_extension = extension->xw_extension_;
+  if (!(xw_extension > 0 && xw_extension < next_xw_extension_)) {
+    LOGGER(WARN) << "xw_extension (" << xw_extension << ") is invalid.";
+    return;
+  }
+  if (extension_map_.find(xw_extension) == extension_map_.end())
+    extension_map_[xw_extension] = extension;
+}
+
+void XWalkExtensionAdapter::UnregisterExtension(XWalkExtension* extension) {
+  XW_Extension xw_extension = extension->xw_extension_;
+  if (!(xw_extension > 0 && xw_extension < next_xw_extension_)) {
+    LOGGER(WARN) << "xw_extension (" << xw_extension << ") is invalid.";
+    return;
+  }
+  if (extension_map_.find(xw_extension) != extension_map_.end())
+    extension_map_.erase(xw_extension);
+}
+
+void XWalkExtensionAdapter::RegisterInstance(
+    XWalkExtensionInstance* instance) {
+  XW_Instance xw_instance = instance->xw_instance_;
+  if (!(xw_instance > 0 && xw_instance < next_xw_instance_)) {
+    LOGGER(WARN) << "xw_instance (" << xw_instance << ") is invalid.";
+    return;
+  }
+  if (instance_map_.find(xw_instance) == instance_map_.end())
+    instance_map_[xw_instance] = instance;
+}
+
+void XWalkExtensionAdapter::UnregisterInstance(
+    XWalkExtensionInstance* instance) {
+  XW_Instance xw_instance = instance->xw_instance_;
+  if (!(xw_instance > 0 && xw_instance < next_xw_instance_)) {
+    LOGGER(WARN) << "xw_instance (" << xw_instance << ") is invalid.";
+    return;
+  }
+  if (instance_map_.find(xw_instance) != instance_map_.end())
+    instance_map_.erase(xw_instance);
+}
+
+const void* XWalkExtensionAdapter::GetInterface(const char* name) {
+  if (!strcmp(name, XW_CORE_INTERFACE_1)) {
+    static const XW_CoreInterface_1 coreInterface1 = {
+      CoreSetExtensionName,
+      CoreSetJavaScriptAPI,
+      CoreRegisterInstanceCallbacks,
+      CoreRegisterShutdownCallback,
+      CoreSetInstanceData,
+      CoreGetInstanceData
+    };
+    return &coreInterface1;
+  }
+
+  if (!strcmp(name, XW_MESSAGING_INTERFACE_1)) {
+    static const XW_MessagingInterface_1 messagingInterface1 = {
+      MessagingRegister,
+      MessagingPostMessage
+    };
+    return &messagingInterface1;
+  }
+
+  if (!strcmp(name, XW_INTERNAL_SYNC_MESSAGING_INTERFACE_1)) {
+    static const XW_Internal_SyncMessagingInterface_1
+        syncMessagingInterface1 = {
+      SyncMessagingRegister,
+      SyncMessagingSetSyncReply
+    };
+    return &syncMessagingInterface1;
+  }
+
+  if (!strcmp(name, XW_INTERNAL_ENTRY_POINTS_INTERFACE_1)) {
+    static const XW_Internal_EntryPointsInterface_1 entryPointsInterface1 = {
+      EntryPointsSetExtraJSEntryPoints
+    };
+    return &entryPointsInterface1;
+  }
+
+  if (!strcmp(name, XW_INTERNAL_RUNTIME_INTERFACE_1)) {
+    static const XW_Internal_RuntimeInterface_1 runtimeInterface1 = {
+      RuntimeGetStringVariable
+    };
+    return &runtimeInterface1;
+  }
+
+  if (!strcmp(name, XW_INTERNAL_PERMISSIONS_INTERFACE_1)) {
+    static const XW_Internal_PermissionsInterface_1 permissionsInterface1 = {
+      PermissionsCheckAPIAccessControl,
+      PermissionsRegisterPermissions
+    };
+    return &permissionsInterface1;
+  }
+
+  LOGGER(WARN) << "Interface '" << name << "' is not supported.";
+  return NULL;
+}
+
+XWalkExtension* XWalkExtensionAdapter::GetExtension(XW_Extension xw_extension) {
+  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
+  ExtensionMap::iterator it = adapter->extension_map_.find(xw_extension);
+  if (it == adapter->extension_map_.end())
+    return NULL;
+  return it->second;
+}
+
+XWalkExtensionInstance* XWalkExtensionAdapter::GetExtensionInstance(
+    XW_Instance xw_instance) {
+  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
+  InstanceMap::iterator it = adapter->instance_map_.find(xw_instance);
+  if (it == adapter->instance_map_.end())
+    return NULL;
+  return it->second;
+}
+
+#define CHECK(x, xw) \
+  if (!x) { \
+    LOGGER(WARN) << "Ignoring call. Invalid " << #xw << " = " << xw; \
+    return; \
+  }
+
+#define RETURN_IF_INITIALIZED(x) \
+  if (x->initialized_) \
+    return;
+
+void XWalkExtensionAdapter::CoreSetExtensionName(
+    XW_Extension xw_extension,
+    const char* name) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+  extension->name_ = name;
+}
+
+void XWalkExtensionAdapter::CoreSetJavaScriptAPI(
+    XW_Extension xw_extension,
+    const char* javascript_api) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+  extension->javascript_api_ = javascript_api;
+}
+
+void XWalkExtensionAdapter::CoreRegisterInstanceCallbacks(
+    XW_Extension xw_extension,
+    XW_CreatedInstanceCallback created,
+    XW_DestroyedInstanceCallback destroyed) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+  extension->created_instance_callback_ = created;
+  extension->destroyed_instance_callback_ = destroyed;
+}
+
+void XWalkExtensionAdapter::CoreRegisterShutdownCallback(
+    XW_Extension xw_extension,
+    XW_ShutdownCallback shutdown) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+  extension->shutdown_callback_ = shutdown;
+}
+
+void XWalkExtensionAdapter::CoreSetInstanceData(
+    XW_Instance xw_instance,
+    void* data) {
+  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
+  CHECK(instance, xw_instance);
+  instance->instance_data_ = data;
+}
+
+void* XWalkExtensionAdapter::CoreGetInstanceData(
+    XW_Instance xw_instance) {
+  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
+  if (instance)
+    return instance->instance_data_;
+  else
+    return NULL;
+}
+
+void XWalkExtensionAdapter::MessagingRegister(
+    XW_Extension xw_extension,
+    XW_HandleMessageCallback handle_message) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+  extension->handle_msg_callback_ = handle_message;
+}
+
+void XWalkExtensionAdapter::MessagingPostMessage(
+    XW_Instance xw_instance,
+    const char* message) {
+  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
+  CHECK(instance, xw_instance);
+  instance->PostMessageToJS(message);
+}
+
+void XWalkExtensionAdapter::SyncMessagingRegister(
+    XW_Extension xw_extension,
+    XW_HandleSyncMessageCallback handle_sync_message) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+  extension->handle_sync_msg_callback_ = handle_sync_message;
+}
+
+void XWalkExtensionAdapter::SyncMessagingSetSyncReply(
+    XW_Instance xw_instance,
+    const char* reply) {
+  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
+  CHECK(instance, xw_instance);
+  instance->SyncReplyToJS(reply);
+}
+
+void XWalkExtensionAdapter::EntryPointsSetExtraJSEntryPoints(
+    XW_Extension xw_extension,
+    const char** entry_points) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  RETURN_IF_INITIALIZED(extension);
+
+  for (int i=0; entry_points[i]; ++i) {
+    extension->entry_points_.push_back(std::string(entry_points[i]));
+  }
+}
+
+void XWalkExtensionAdapter::RuntimeGetStringVariable(
+    XW_Extension xw_extension,
+    const char* key,
+    char* value,
+    unsigned int value_len) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  CHECK(extension, xw_extension);
+  extension->GetRuntimeVariable(key, value, value_len);
+}
+
+int XWalkExtensionAdapter::PermissionsCheckAPIAccessControl(
+    XW_Extension xw_extension,
+    const char* api_name) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  if (extension)
+    return extension->CheckAPIAccessControl(api_name);
+  else
+    return XW_ERROR;
+}
+
+int XWalkExtensionAdapter::PermissionsRegisterPermissions(
+    XW_Extension xw_extension,
+    const char* perm_table) {
+  XWalkExtension* extension = GetExtension(xw_extension);
+  if (extension)
+    return extension->RegisterPermissions(perm_table);
+  else
+    return XW_ERROR;
+}
+
+#undef CHECK
+#undef RETURN_IF_INITIALIZED
+
+}  // namespace extensions
diff --git a/extensions/common/xwalk_extension_adapter.h b/extensions/common/xwalk_extension_adapter.h
new file mode 100644 (file)
index 0000000..3c350d1
--- /dev/null
@@ -0,0 +1,91 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_ADAPTER_H_
+#define XWALK_EXTENSIONS_XWALK_EXTENSION_ADAPTER_H_
+
+#include <map>
+
+#include "extensions/common/xwalk_extension.h"
+#include "extensions/common/xwalk_extension_instance.h"
+#include "extensions/public/XW_Extension.h"
+#include "extensions/public/XW_Extension_EntryPoints.h"
+#include "extensions/public/XW_Extension_Permissions.h"
+#include "extensions/public/XW_Extension_Runtime.h"
+#include "extensions/public/XW_Extension_SyncMessage.h"
+
+namespace extensions {
+
+class XWalkExtensionAdapter {
+ public:
+  typedef std::map<XW_Extension, XWalkExtension*> ExtensionMap;
+  typedef std::map<XW_Instance, XWalkExtensionInstance*> InstanceMap;
+
+  static XWalkExtensionAdapter* GetInstance();
+
+  XW_Extension GetNextXWExtension();
+  XW_Instance GetNextXWInstance();
+
+  void RegisterExtension(XWalkExtension* extension);
+  void UnregisterExtension(XWalkExtension* extension);
+
+  void RegisterInstance(XWalkExtensionInstance* instance);
+  void UnregisterInstance(XWalkExtensionInstance* instance);
+
+  // Returns the correct struct according to interface asked. This is
+  // passed to external extensions in XW_Initialize() call.
+  static const void* GetInterface(const char* name);
+
+ private:
+  XWalkExtensionAdapter();
+  virtual ~XWalkExtensionAdapter();
+
+  static XWalkExtension* GetExtension(XW_Extension xw_extension);
+  static XWalkExtensionInstance* GetExtensionInstance(XW_Instance xw_instance);
+
+  static void CoreSetExtensionName(
+      XW_Extension xw_extension, const char* name);
+  static void CoreSetJavaScriptAPI(
+      XW_Extension xw_extension, const char* javascript_api);
+  static void CoreRegisterInstanceCallbacks(
+      XW_Extension xw_extension,
+      XW_CreatedInstanceCallback created,
+      XW_DestroyedInstanceCallback destroyed);
+  static void CoreRegisterShutdownCallback(
+      XW_Extension xw_extension,
+      XW_ShutdownCallback shutdown);
+  static void CoreSetInstanceData(
+      XW_Instance xw_instance, void* data);
+  static void* CoreGetInstanceData(XW_Instance xw_instance);
+  static void MessagingRegister(
+      XW_Extension xw_extension,
+      XW_HandleMessageCallback handle_message);
+  static void MessagingPostMessage(
+      XW_Instance xw_instance, const char* message);
+  static void SyncMessagingRegister(
+      XW_Extension xw_extension,
+      XW_HandleSyncMessageCallback handle_sync_message);
+  static void SyncMessagingSetSyncReply(
+      XW_Instance xw_instance, const char* reply);
+  static void EntryPointsSetExtraJSEntryPoints(
+      XW_Extension xw_extension, const char** entry_points);
+  static void RuntimeGetStringVariable(
+      XW_Extension xw_extension,
+      const char* key, char* value, unsigned int value_len);
+  static int PermissionsCheckAPIAccessControl(
+      XW_Extension xw_extension, const char* api_name);
+  static int PermissionsRegisterPermissions(
+      XW_Extension xw_extension, const char* perm_table);
+
+  ExtensionMap extension_map_;
+  InstanceMap instance_map_;
+
+  XW_Extension next_xw_extension_;
+  XW_Instance next_xw_instance_;
+};
+
+}  // namespace extensions
+
+#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_ADAPTER_H_
diff --git a/extensions/common/xwalk_extension_instance.cc b/extensions/common/xwalk_extension_instance.cc
new file mode 100644 (file)
index 0000000..c86bb59
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/xwalk_extension_instance.h"
+
+#include "extensions/common/xwalk_extension_adapter.h"
+#include "extensions/public/XW_Extension_SyncMessage.h"
+
+namespace extensions {
+
+XWalkExtensionInstance::XWalkExtensionInstance(
+    XWalkExtension* extension, XW_Instance xw_instance)
+  : extension_(extension),
+    xw_instance_(xw_instance),
+    instance_data_(NULL) {
+  XWalkExtensionAdapter::GetInstance()->RegisterInstance(this);
+  XW_CreatedInstanceCallback callback = extension_->created_instance_callback_;
+  if (callback)
+    callback(xw_instance_);
+}
+
+XWalkExtensionInstance::~XWalkExtensionInstance() {
+  XW_DestroyedInstanceCallback callback =
+      extension_->destroyed_instance_callback_;
+  if (callback)
+    callback(xw_instance_);
+  XWalkExtensionAdapter::GetInstance()->UnregisterInstance(this);
+}
+
+void XWalkExtensionInstance::HandleMessage(const std::string& msg) {
+  XW_HandleMessageCallback callback = extension_->handle_msg_callback_;
+  if (callback)
+    callback(xw_instance_, msg.c_str());
+}
+
+void XWalkExtensionInstance::HandleSyncMessage(const std::string& msg) {
+  XW_HandleSyncMessageCallback callback = extension_->handle_sync_msg_callback_;
+  if (callback) {
+    callback(xw_instance_, msg.c_str());
+  }
+}
+
+void XWalkExtensionInstance::SetPostMessageCallback(
+    MessageCallback callback) {
+  post_message_callback_ = callback;
+}
+
+void XWalkExtensionInstance::SetSendSyncReplyCallback(
+    MessageCallback callback) {
+  send_sync_reply_callback_ = callback;
+}
+
+void XWalkExtensionInstance::PostMessageToJS(const std::string& msg) {
+  post_message_callback_(msg);
+}
+
+void XWalkExtensionInstance::SyncReplyToJS(const std::string& reply) {
+  send_sync_reply_callback_(reply);
+}
+
+}  // namespace extensions
diff --git a/extensions/common/xwalk_extension_instance.h b/extensions/common/xwalk_extension_instance.h
new file mode 100644 (file)
index 0000000..9efe2db
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_INSTANCE_H_
+#define XWALK_EXTENSIONS_XWALK_EXTENSION_INSTANCE_H_
+
+#include <functional>
+#include <string>
+
+#include "extensions/public/XW_Extension.h"
+
+namespace extensions {
+
+class XWalkExtension;
+
+class XWalkExtensionInstance {
+ public:
+  typedef std::function<void(const std::string&)> MessageCallback;
+
+  XWalkExtensionInstance(XWalkExtension* extension, XW_Instance xw_instance);
+  virtual ~XWalkExtensionInstance();
+
+  void HandleMessage(const std::string& msg);
+  void HandleSyncMessage(const std::string& msg);
+
+  void SetPostMessageCallback(MessageCallback callback);
+  void SetSendSyncReplyCallback(MessageCallback callback);
+
+ private:
+  friend class XWalkExtensionAdapter;
+
+  void PostMessageToJS(const std::string& msg);
+  void SyncReplyToJS(const std::string& reply);
+
+  XWalkExtension* extension_;
+  XW_Instance xw_instance_;
+  void* instance_data_;
+
+  MessageCallback post_message_callback_;
+  MessageCallback send_sync_reply_callback_;
+};
+
+}  // namespace extensions
+
+#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_INSTANCE_H_
diff --git a/extensions/common/xwalk_extension_manager.cc b/extensions/common/xwalk_extension_manager.cc
new file mode 100644 (file)
index 0000000..87817d2
--- /dev/null
@@ -0,0 +1,188 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/xwalk_extension_manager.h"
+
+#include <glob.h>
+
+#include <fstream>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "common/app_db.h"
+#include "common/logger.h"
+#include "common/picojson.h"
+#include "common/file_utils.h"
+#include "common/string_utils.h"
+
+#include "extensions/common/constants.h"
+#include "extensions/common/xwalk_extension.h"
+
+namespace extensions {
+
+namespace {
+
+const char kAppDBRuntimeSection[] = "Runtime";
+
+const char kExtensionPrefix[] = "lib";
+const char kExtensionSuffix[] = ".so";
+const char kExtensionMetadataSuffix[] = ".json";
+
+}  // namespace
+
+XWalkExtensionManager::XWalkExtensionManager() {
+}
+
+XWalkExtensionManager::~XWalkExtensionManager() {
+}
+
+void XWalkExtensionManager::LoadExtensions(bool meta_only) {
+  if (!extensions_.empty()) {
+    return;
+  }
+
+#ifdef EXTENSION_PATH
+  std::string extension_path(EXTENSION_PATH);
+#else
+  #error EXTENSION_PATH is not set.
+#endif
+  // Gets all extension files in the EXTENSION_PATH
+  std::string ext_pattern(extension_path);
+  ext_pattern.append("/");
+  ext_pattern.append(kExtensionPrefix);
+  ext_pattern.append("*");
+  ext_pattern.append(kExtensionSuffix);
+  StringSet files;
+  {
+    glob_t glob_result;
+    glob(ext_pattern.c_str(), GLOB_TILDE, NULL, &glob_result);
+    for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
+      files.insert(glob_result.gl_pathv[i]);
+    }
+  }
+
+  // Gets all metadata files in the EXTENSION_PATH
+  // Loads information from the metadata files and remove the loaded file from
+  // the set 'files'
+  std::string meta_pattern(extension_path);
+  meta_pattern.append("/");
+  meta_pattern.append("*");
+  meta_pattern.append(kExtensionMetadataSuffix);
+  {
+    glob_t glob_result;
+    glob(meta_pattern.c_str(), GLOB_TILDE, NULL, &glob_result);
+    for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
+      RegisterExtensionsByMeta(glob_result.gl_pathv[i], &files);
+    }
+  }
+
+  // Load extensions in the remained files of the set 'files'
+  if (!meta_only) {
+    for (auto it = files.begin(); it != files.end(); ++it) {
+      XWalkExtension* ext = new XWalkExtension(*it, this);
+      RegisterExtension(ext);
+    }
+  }
+}
+
+bool XWalkExtensionManager::RegisterSymbols(XWalkExtension* extension) {
+  std::string name = extension->name();
+
+  if (extension_symbols_.find(name) != extension_symbols_.end()) {
+    LOGGER(WARN) << "Ignoring extension with name already registred. '"
+                 << name << "'";
+    return false;
+  }
+
+  XWalkExtension::StringVector entry_points = extension->entry_points();
+  for (auto it = entry_points.begin(); it != entry_points.end(); ++it) {
+    if (extension_symbols_.find(*it) != extension_symbols_.end()) {
+      LOGGER(WARN) << "Ignoring extension with entry_point already registred. '"
+                   << (*it) << "'";
+      return false;
+    }
+  }
+
+  for (auto it = entry_points.begin(); it != entry_points.end(); ++it) {
+    extension_symbols_.insert(*it);
+  }
+
+  extension_symbols_.insert(name);
+
+  return true;
+}
+
+void XWalkExtensionManager::RegisterExtension(XWalkExtension* extension) {
+  if (!extension->lazy_loading() && !extension->Initialize()) {
+    delete extension;
+    return;
+  }
+
+  if (!RegisterSymbols(extension)) {
+    delete extension;
+    return;
+  }
+
+  extensions_[extension->name()] = extension;
+  LOGGER(DEBUG) << extension->name() << " is registered.";
+}
+
+void XWalkExtensionManager::RegisterExtensionsByMeta(
+    const std::string& meta_path, StringSet* files) {
+#ifdef EXTENSION_PATH
+  std::string extension_path(EXTENSION_PATH);
+#else
+  #error EXTENSION_PATH is not set.
+#endif
+
+  std::ifstream metafile(meta_path.c_str());
+  if (!metafile.is_open()) {
+    LOGGER(ERROR) << "Fail to open the plugin metadata file :" << meta_path;
+    return;
+  }
+
+  picojson::value metadata;
+  metafile >> metadata;
+    if (metadata.is<picojson::array>()) {
+    auto& plugins = metadata.get<picojson::array>();
+    for (auto plugin = plugins.begin(); plugin != plugins.end(); ++plugin) {
+      if (!plugin->is<picojson::object>())
+        continue;
+
+      std::string name = plugin->get("name").to_str();
+      std::string lib = plugin->get("lib").to_str();
+      if (!common::utils::StartsWith(lib, "/")) {
+        lib = extension_path + "/" + lib;
+      }
+
+      std::vector<std::string> entries;
+      auto& entry_points_value = plugin->get("entry_points");
+      if (entry_points_value.is<picojson::array>()) {
+        auto& entry_points = entry_points_value.get<picojson::array>();
+        for (auto entry = entry_points.begin(); entry != entry_points.end();
+             ++entry) {
+          entries.push_back(entry->to_str());
+        }
+      }
+      XWalkExtension* extension = new XWalkExtension(lib, name, entries, this);
+      RegisterExtension(extension);
+      files->erase(lib);
+    }
+  } else {
+    LOGGER(ERROR) << meta_path << " is not a valid metadata file.";
+  }
+  metafile.close();
+}
+
+// override
+void XWalkExtensionManager::GetRuntimeVariable(
+    const char* key, char* value, size_t value_len) {
+  common::AppDB* db = common::AppDB::GetInstance();
+  std::string ret = db->Get(kAppDBRuntimeSection, key);
+  strncpy(value, ret.c_str(), value_len);
+}
+
+
+}  // namespace extensions
diff --git a/extensions/common/xwalk_extension_manager.h b/extensions/common/xwalk_extension_manager.h
new file mode 100644 (file)
index 0000000..8a0cd78
--- /dev/null
@@ -0,0 +1,42 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_MANAGER_H_
+#define XWALK_EXTENSIONS_XWALK_EXTENSION_MANAGER_H_
+
+#include <string>
+#include <set>
+#include <map>
+
+#include "extensions/common/xwalk_extension.h"
+
+namespace extensions {
+
+class XWalkExtensionManager : public XWalkExtension::XWalkExtensionDelegate {
+ public:
+  typedef std::set<std::string> StringSet;
+  typedef std::map<std::string, XWalkExtension*> ExtensionMap;
+
+  XWalkExtensionManager();
+  ~XWalkExtensionManager();
+
+  ExtensionMap extensions() const { return extensions_; }
+
+  void LoadExtensions(bool meta_only = true);
+ private:
+  // override
+  void GetRuntimeVariable(const char* key, char* value, size_t value_len);
+
+  bool RegisterSymbols(XWalkExtension* extension);
+  void RegisterExtension(XWalkExtension* extension);
+  void RegisterExtensionsByMeta(const std::string& meta_path,
+                                StringSet* files);
+
+  StringSet extension_symbols_;
+  ExtensionMap extensions_;
+};
+
+}  // namespace extensions
+
+#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_MANAGER_H_
diff --git a/extensions/extension/xwalk_extension.cc b/extensions/extension/xwalk_extension.cc
deleted file mode 100644 (file)
index 43c2279..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "extensions/extension/xwalk_extension.h"
-
-#include <dlfcn.h>
-#include <string>
-
-#include "common/logger.h"
-#include "extensions/extension/xwalk_extension_adapter.h"
-#include "extensions/public/XW_Extension.h"
-
-namespace extensions {
-
-XWalkExtension::XWalkExtension(const std::string& path,
-                               XWalkExtensionDelegate* delegate)
-  : initialized_(false),
-    library_path_(path),
-    xw_extension_(0),
-    use_trampoline_(true),
-    lazy_loading_(false),
-    delegate_(delegate),
-    created_instance_callback_(NULL),
-    destroyed_instance_callback_(NULL),
-    shutdown_callback_(NULL),
-    handle_msg_callback_(NULL),
-    handle_sync_msg_callback_(NULL) {
-}
-
-XWalkExtension::XWalkExtension(const std::string& path,
-                               const std::string& name,
-                               const StringVector& entry_points,
-                               XWalkExtensionDelegate* delegate)
-  : initialized_(false),
-    library_path_(path),
-    xw_extension_(0),
-    name_(name),
-    entry_points_(entry_points),
-    use_trampoline_(true),
-    lazy_loading_(true),
-    delegate_(delegate),
-    created_instance_callback_(NULL),
-    destroyed_instance_callback_(NULL),
-    shutdown_callback_(NULL),
-    handle_msg_callback_(NULL),
-    handle_sync_msg_callback_(NULL) {
-}
-
-XWalkExtension::~XWalkExtension() {
-  if (!initialized_)
-    return;
-
-  if (shutdown_callback_)
-    shutdown_callback_(xw_extension_);
-  XWalkExtensionAdapter::GetInstance()->UnregisterExtension(this);
-}
-
-bool XWalkExtension::Initialize() {
-  if (initialized_)
-    return true;
-
-  void* handle = dlopen(library_path_.c_str(), RTLD_LAZY);
-  if (!handle) {
-    LOGGER(ERROR) << "Error loading extension '"
-                  << library_path_ << "' : " << dlerror();
-    return false;
-  }
-
-  XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>(
-      dlsym(handle, "XW_Initialize"));
-  if (!initialize) {
-    LOGGER(ERROR) << "Error loading extension '" << library_path_
-                  << "' : couldn't get XW_Initialize function.";
-    dlclose(handle);
-    return false;
-  }
-
-  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
-  xw_extension_ = adapter->GetNextXWExtension();
-  adapter->RegisterExtension(this);
-
-  int ret = initialize(xw_extension_, XWalkExtensionAdapter::GetInterface);
-  if (ret != XW_OK) {
-    LOGGER(ERROR) << "Error loading extension '" << library_path_
-                  << "' : XW_Initialize() returned error value.";
-    dlclose(handle);
-    return false;
-  }
-
-  initialized_ = true;
-  return true;
-}
-
-XWalkExtensionInstance* XWalkExtension::CreateInstance() {
-  Initialize();
-  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
-  XW_Instance xw_instance = adapter->GetNextXWInstance();
-  return new XWalkExtensionInstance(this, xw_instance);
-}
-
-void XWalkExtension::GetRuntimeVariable(const char* key, char* value,
-    size_t value_len) {
-  if (delegate_) {
-    delegate_->GetRuntimeVariable(key, value, value_len);
-  }
-}
-int XWalkExtension::CheckAPIAccessControl(const char* /*api_name*/) {
-  // Not Supported
-  return XW_OK;
-}
-
-int XWalkExtension::RegisterPermissions(const char* /*perm_table*/) {
-  // Not Supported
-  return XW_OK;
-}
-
-}  // namespace extensions
-
diff --git a/extensions/extension/xwalk_extension.h b/extensions/extension/xwalk_extension.h
deleted file mode 100644 (file)
index b5abe3c..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_H_
-#define XWALK_EXTENSIONS_XWALK_EXTENSION_H_
-
-#include <string>
-#include <vector>
-
-#include "extensions/extension/xwalk_extension_instance.h"
-#include "extensions/public/XW_Extension.h"
-#include "extensions/public/XW_Extension_SyncMessage.h"
-
-namespace extensions {
-
-class XWalkExtensionAdapter;
-class XWalkExtensionInstance;
-
-class XWalkExtension {
- public:
-  typedef std::vector<std::string> StringVector;
-
-  class XWalkExtensionDelegate {
-   public:
-    virtual void GetRuntimeVariable(const char* key, char* value,
-        size_t value_len) = 0;
-  };
-
-  XWalkExtension(const std::string& path, XWalkExtensionDelegate* delegate);
-  XWalkExtension(const std::string& path,
-                 const std::string& name,
-                 const StringVector& entry_points,
-                 XWalkExtensionDelegate* delegate);
-  virtual ~XWalkExtension();
-
-  bool Initialize();
-  XWalkExtensionInstance* CreateInstance();
-
-  std::string name() const { return name_; }
-
-  std::string javascript_api() const { return javascript_api_; }
-
-  const StringVector& entry_points() const {
-    return entry_points_;
-  }
-
-  bool use_trampoline() const {
-    return use_trampoline_;
-  }
-
-  bool lazy_loading() const {
-    return lazy_loading_;
-  }
-
-  void set_name(const std::string& name) {
-    name_ = name;
-  }
-
-  void set_javascript_api(const std::string& javascript_api) {
-    javascript_api_ = javascript_api;
-  }
-
-  void set_use_trampoline(bool use_trampoline) {
-    use_trampoline_ = use_trampoline;
-  }
-
- private:
-  friend class XWalkExtensionAdapter;
-  friend class XWalkExtensionInstance;
-
-  void GetRuntimeVariable(const char* key, char* value, size_t value_len);
-  int CheckAPIAccessControl(const char* api_name);
-  int RegisterPermissions(const char* perm_table);
-
-  bool initialized_;
-  std::string library_path_;
-  XW_Extension xw_extension_;
-
-  std::string name_;
-  std::string javascript_api_;
-  StringVector entry_points_;
-  bool use_trampoline_;
-  bool lazy_loading_;
-
-  XWalkExtensionDelegate* delegate_;
-
-  XW_CreatedInstanceCallback created_instance_callback_;
-  XW_DestroyedInstanceCallback destroyed_instance_callback_;
-  XW_ShutdownCallback shutdown_callback_;
-  XW_HandleMessageCallback handle_msg_callback_;
-  XW_HandleSyncMessageCallback handle_sync_msg_callback_;
-};
-
-}  // namespace extensions
-
-#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_H_
diff --git a/extensions/extension/xwalk_extension_adapter.cc b/extensions/extension/xwalk_extension_adapter.cc
deleted file mode 100644 (file)
index 0303b03..0000000
+++ /dev/null
@@ -1,294 +0,0 @@
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "extensions/extension/xwalk_extension_adapter.h"
-
-#include <string>
-
-#include "common/logger.h"
-
-namespace extensions {
-
-XWalkExtensionAdapter::XWalkExtensionAdapter()
-  : next_xw_extension_(1),
-    next_xw_instance_(1) {
-}
-
-XWalkExtensionAdapter::~XWalkExtensionAdapter() {
-}
-
-XWalkExtensionAdapter* XWalkExtensionAdapter::GetInstance() {
-  static XWalkExtensionAdapter self;
-  return &self;
-}
-
-XW_Extension XWalkExtensionAdapter::GetNextXWExtension() {
-  return next_xw_extension_++;
-}
-
-XW_Instance XWalkExtensionAdapter::GetNextXWInstance() {
-  return next_xw_instance_++;
-}
-
-void XWalkExtensionAdapter::RegisterExtension(XWalkExtension* extension) {
-  XW_Extension xw_extension = extension->xw_extension_;
-  if (!(xw_extension > 0 && xw_extension < next_xw_extension_)) {
-    LOGGER(WARN) << "xw_extension (" << xw_extension << ") is invalid.";
-    return;
-  }
-  if (extension_map_.find(xw_extension) == extension_map_.end())
-    extension_map_[xw_extension] = extension;
-}
-
-void XWalkExtensionAdapter::UnregisterExtension(XWalkExtension* extension) {
-  XW_Extension xw_extension = extension->xw_extension_;
-  if (!(xw_extension > 0 && xw_extension < next_xw_extension_)) {
-    LOGGER(WARN) << "xw_extension (" << xw_extension << ") is invalid.";
-    return;
-  }
-  if (extension_map_.find(xw_extension) != extension_map_.end())
-    extension_map_.erase(xw_extension);
-}
-
-void XWalkExtensionAdapter::RegisterInstance(
-    XWalkExtensionInstance* instance) {
-  XW_Instance xw_instance = instance->xw_instance_;
-  if (!(xw_instance > 0 && xw_instance < next_xw_instance_)) {
-    LOGGER(WARN) << "xw_instance (" << xw_instance << ") is invalid.";
-    return;
-  }
-  if (instance_map_.find(xw_instance) == instance_map_.end())
-    instance_map_[xw_instance] = instance;
-}
-
-void XWalkExtensionAdapter::UnregisterInstance(
-    XWalkExtensionInstance* instance) {
-  XW_Instance xw_instance = instance->xw_instance_;
-  if (!(xw_instance > 0 && xw_instance < next_xw_instance_)) {
-    LOGGER(WARN) << "xw_instance (" << xw_instance << ") is invalid.";
-    return;
-  }
-  if (instance_map_.find(xw_instance) != instance_map_.end())
-    instance_map_.erase(xw_instance);
-}
-
-const void* XWalkExtensionAdapter::GetInterface(const char* name) {
-  if (!strcmp(name, XW_CORE_INTERFACE_1)) {
-    static const XW_CoreInterface_1 coreInterface1 = {
-      CoreSetExtensionName,
-      CoreSetJavaScriptAPI,
-      CoreRegisterInstanceCallbacks,
-      CoreRegisterShutdownCallback,
-      CoreSetInstanceData,
-      CoreGetInstanceData
-    };
-    return &coreInterface1;
-  }
-
-  if (!strcmp(name, XW_MESSAGING_INTERFACE_1)) {
-    static const XW_MessagingInterface_1 messagingInterface1 = {
-      MessagingRegister,
-      MessagingPostMessage
-    };
-    return &messagingInterface1;
-  }
-
-  if (!strcmp(name, XW_INTERNAL_SYNC_MESSAGING_INTERFACE_1)) {
-    static const XW_Internal_SyncMessagingInterface_1
-        syncMessagingInterface1 = {
-      SyncMessagingRegister,
-      SyncMessagingSetSyncReply
-    };
-    return &syncMessagingInterface1;
-  }
-
-  if (!strcmp(name, XW_INTERNAL_ENTRY_POINTS_INTERFACE_1)) {
-    static const XW_Internal_EntryPointsInterface_1 entryPointsInterface1 = {
-      EntryPointsSetExtraJSEntryPoints
-    };
-    return &entryPointsInterface1;
-  }
-
-  if (!strcmp(name, XW_INTERNAL_RUNTIME_INTERFACE_1)) {
-    static const XW_Internal_RuntimeInterface_1 runtimeInterface1 = {
-      RuntimeGetStringVariable
-    };
-    return &runtimeInterface1;
-  }
-
-  if (!strcmp(name, XW_INTERNAL_PERMISSIONS_INTERFACE_1)) {
-    static const XW_Internal_PermissionsInterface_1 permissionsInterface1 = {
-      PermissionsCheckAPIAccessControl,
-      PermissionsRegisterPermissions
-    };
-    return &permissionsInterface1;
-  }
-
-  LOGGER(WARN) << "Interface '" << name << "' is not supported.";
-  return NULL;
-}
-
-XWalkExtension* XWalkExtensionAdapter::GetExtension(XW_Extension xw_extension) {
-  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
-  ExtensionMap::iterator it = adapter->extension_map_.find(xw_extension);
-  if (it == adapter->extension_map_.end())
-    return NULL;
-  return it->second;
-}
-
-XWalkExtensionInstance* XWalkExtensionAdapter::GetExtensionInstance(
-    XW_Instance xw_instance) {
-  XWalkExtensionAdapter* adapter = XWalkExtensionAdapter::GetInstance();
-  InstanceMap::iterator it = adapter->instance_map_.find(xw_instance);
-  if (it == adapter->instance_map_.end())
-    return NULL;
-  return it->second;
-}
-
-#define CHECK(x, xw) \
-  if (!x) { \
-    LOGGER(WARN) << "Ignoring call. Invalid " << #xw << " = " << xw; \
-    return; \
-  }
-
-#define RETURN_IF_INITIALIZED(x) \
-  if (x->initialized_) \
-    return;
-
-void XWalkExtensionAdapter::CoreSetExtensionName(
-    XW_Extension xw_extension,
-    const char* name) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-  extension->name_ = name;
-}
-
-void XWalkExtensionAdapter::CoreSetJavaScriptAPI(
-    XW_Extension xw_extension,
-    const char* javascript_api) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-  extension->javascript_api_ = javascript_api;
-}
-
-void XWalkExtensionAdapter::CoreRegisterInstanceCallbacks(
-    XW_Extension xw_extension,
-    XW_CreatedInstanceCallback created,
-    XW_DestroyedInstanceCallback destroyed) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-  extension->created_instance_callback_ = created;
-  extension->destroyed_instance_callback_ = destroyed;
-}
-
-void XWalkExtensionAdapter::CoreRegisterShutdownCallback(
-    XW_Extension xw_extension,
-    XW_ShutdownCallback shutdown) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-  extension->shutdown_callback_ = shutdown;
-}
-
-void XWalkExtensionAdapter::CoreSetInstanceData(
-    XW_Instance xw_instance,
-    void* data) {
-  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
-  CHECK(instance, xw_instance);
-  instance->instance_data_ = data;
-}
-
-void* XWalkExtensionAdapter::CoreGetInstanceData(
-    XW_Instance xw_instance) {
-  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
-  if (instance)
-    return instance->instance_data_;
-  else
-    return NULL;
-}
-
-void XWalkExtensionAdapter::MessagingRegister(
-    XW_Extension xw_extension,
-    XW_HandleMessageCallback handle_message) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-  extension->handle_msg_callback_ = handle_message;
-}
-
-void XWalkExtensionAdapter::MessagingPostMessage(
-    XW_Instance xw_instance,
-    const char* message) {
-  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
-  CHECK(instance, xw_instance);
-  instance->PostMessageToJS(message);
-}
-
-void XWalkExtensionAdapter::SyncMessagingRegister(
-    XW_Extension xw_extension,
-    XW_HandleSyncMessageCallback handle_sync_message) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-  extension->handle_sync_msg_callback_ = handle_sync_message;
-}
-
-void XWalkExtensionAdapter::SyncMessagingSetSyncReply(
-    XW_Instance xw_instance,
-    const char* reply) {
-  XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
-  CHECK(instance, xw_instance);
-  instance->SyncReplyToJS(reply);
-}
-
-void XWalkExtensionAdapter::EntryPointsSetExtraJSEntryPoints(
-    XW_Extension xw_extension,
-    const char** entry_points) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  RETURN_IF_INITIALIZED(extension);
-
-  for (int i=0; entry_points[i]; ++i) {
-    extension->entry_points_.push_back(std::string(entry_points[i]));
-  }
-}
-
-void XWalkExtensionAdapter::RuntimeGetStringVariable(
-    XW_Extension xw_extension,
-    const char* key,
-    char* value,
-    unsigned int value_len) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  CHECK(extension, xw_extension);
-  extension->GetRuntimeVariable(key, value, value_len);
-}
-
-int XWalkExtensionAdapter::PermissionsCheckAPIAccessControl(
-    XW_Extension xw_extension,
-    const char* api_name) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  if (extension)
-    return extension->CheckAPIAccessControl(api_name);
-  else
-    return XW_ERROR;
-}
-
-int XWalkExtensionAdapter::PermissionsRegisterPermissions(
-    XW_Extension xw_extension,
-    const char* perm_table) {
-  XWalkExtension* extension = GetExtension(xw_extension);
-  if (extension)
-    return extension->RegisterPermissions(perm_table);
-  else
-    return XW_ERROR;
-}
-
-#undef CHECK
-#undef RETURN_IF_INITIALIZED
-
-}  // namespace extensions
diff --git a/extensions/extension/xwalk_extension_adapter.h b/extensions/extension/xwalk_extension_adapter.h
deleted file mode 100644 (file)
index 776d003..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_ADAPTER_H_
-#define XWALK_EXTENSIONS_XWALK_EXTENSION_ADAPTER_H_
-
-#include <map>
-
-#include "extensions/extension/xwalk_extension.h"
-#include "extensions/extension/xwalk_extension_instance.h"
-#include "extensions/public/XW_Extension.h"
-#include "extensions/public/XW_Extension_EntryPoints.h"
-#include "extensions/public/XW_Extension_Permissions.h"
-#include "extensions/public/XW_Extension_Runtime.h"
-#include "extensions/public/XW_Extension_SyncMessage.h"
-
-namespace extensions {
-
-class XWalkExtensionAdapter {
- public:
-  typedef std::map<XW_Extension, XWalkExtension*> ExtensionMap;
-  typedef std::map<XW_Instance, XWalkExtensionInstance*> InstanceMap;
-
-  static XWalkExtensionAdapter* GetInstance();
-
-  XW_Extension GetNextXWExtension();
-  XW_Instance GetNextXWInstance();
-
-  void RegisterExtension(XWalkExtension* extension);
-  void UnregisterExtension(XWalkExtension* extension);
-
-  void RegisterInstance(XWalkExtensionInstance* instance);
-  void UnregisterInstance(XWalkExtensionInstance* instance);
-
-  // Returns the correct struct according to interface asked. This is
-  // passed to external extensions in XW_Initialize() call.
-  static const void* GetInterface(const char* name);
-
- private:
-  XWalkExtensionAdapter();
-  virtual ~XWalkExtensionAdapter();
-
-  static XWalkExtension* GetExtension(XW_Extension xw_extension);
-  static XWalkExtensionInstance* GetExtensionInstance(XW_Instance xw_instance);
-
-  static void CoreSetExtensionName(
-      XW_Extension xw_extension, const char* name);
-  static void CoreSetJavaScriptAPI(
-      XW_Extension xw_extension, const char* javascript_api);
-  static void CoreRegisterInstanceCallbacks(
-      XW_Extension xw_extension,
-      XW_CreatedInstanceCallback created,
-      XW_DestroyedInstanceCallback destroyed);
-  static void CoreRegisterShutdownCallback(
-      XW_Extension xw_extension,
-      XW_ShutdownCallback shutdown);
-  static void CoreSetInstanceData(
-      XW_Instance xw_instance, void* data);
-  static void* CoreGetInstanceData(XW_Instance xw_instance);
-  static void MessagingRegister(
-      XW_Extension xw_extension,
-      XW_HandleMessageCallback handle_message);
-  static void MessagingPostMessage(
-      XW_Instance xw_instance, const char* message);
-  static void SyncMessagingRegister(
-      XW_Extension xw_extension,
-      XW_HandleSyncMessageCallback handle_sync_message);
-  static void SyncMessagingSetSyncReply(
-      XW_Instance xw_instance, const char* reply);
-  static void EntryPointsSetExtraJSEntryPoints(
-      XW_Extension xw_extension, const char** entry_points);
-  static void RuntimeGetStringVariable(
-      XW_Extension xw_extension,
-      const char* key, char* value, unsigned int value_len);
-  static int PermissionsCheckAPIAccessControl(
-      XW_Extension xw_extension, const char* api_name);
-  static int PermissionsRegisterPermissions(
-      XW_Extension xw_extension, const char* perm_table);
-
-  ExtensionMap extension_map_;
-  InstanceMap instance_map_;
-
-  XW_Extension next_xw_extension_;
-  XW_Instance next_xw_instance_;
-};
-
-}  // namespace extensions
-
-#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_ADAPTER_H_
diff --git a/extensions/extension/xwalk_extension_instance.cc b/extensions/extension/xwalk_extension_instance.cc
deleted file mode 100644 (file)
index 834be77..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "extensions/extension/xwalk_extension_instance.h"
-
-#include "extensions/extension/xwalk_extension_adapter.h"
-#include "extensions/public/XW_Extension_SyncMessage.h"
-
-namespace extensions {
-
-XWalkExtensionInstance::XWalkExtensionInstance(
-    XWalkExtension* extension, XW_Instance xw_instance)
-  : extension_(extension),
-    xw_instance_(xw_instance),
-    instance_data_(NULL) {
-  XWalkExtensionAdapter::GetInstance()->RegisterInstance(this);
-  XW_CreatedInstanceCallback callback = extension_->created_instance_callback_;
-  if (callback)
-    callback(xw_instance_);
-}
-
-XWalkExtensionInstance::~XWalkExtensionInstance() {
-  XW_DestroyedInstanceCallback callback =
-      extension_->destroyed_instance_callback_;
-  if (callback)
-    callback(xw_instance_);
-  XWalkExtensionAdapter::GetInstance()->UnregisterInstance(this);
-}
-
-void XWalkExtensionInstance::HandleMessage(const std::string& msg) {
-  XW_HandleMessageCallback callback = extension_->handle_msg_callback_;
-  if (callback)
-    callback(xw_instance_, msg.c_str());
-}
-
-void XWalkExtensionInstance::HandleSyncMessage(const std::string& msg) {
-  XW_HandleSyncMessageCallback callback = extension_->handle_sync_msg_callback_;
-  if (callback) {
-    callback(xw_instance_, msg.c_str());
-  }
-}
-
-void XWalkExtensionInstance::SetPostMessageCallback(
-    MessageCallback callback) {
-  post_message_callback_ = callback;
-}
-
-void XWalkExtensionInstance::SetSendSyncReplyCallback(
-    MessageCallback callback) {
-  send_sync_reply_callback_ = callback;
-}
-
-void XWalkExtensionInstance::PostMessageToJS(const std::string& msg) {
-  post_message_callback_(msg);
-}
-
-void XWalkExtensionInstance::SyncReplyToJS(const std::string& reply) {
-  send_sync_reply_callback_(reply);
-}
-
-}  // namespace extensions
diff --git a/extensions/extension/xwalk_extension_instance.h b/extensions/extension/xwalk_extension_instance.h
deleted file mode 100644 (file)
index 9efe2db..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2013 Intel Corporation. All rights reserved.
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_INSTANCE_H_
-#define XWALK_EXTENSIONS_XWALK_EXTENSION_INSTANCE_H_
-
-#include <functional>
-#include <string>
-
-#include "extensions/public/XW_Extension.h"
-
-namespace extensions {
-
-class XWalkExtension;
-
-class XWalkExtensionInstance {
- public:
-  typedef std::function<void(const std::string&)> MessageCallback;
-
-  XWalkExtensionInstance(XWalkExtension* extension, XW_Instance xw_instance);
-  virtual ~XWalkExtensionInstance();
-
-  void HandleMessage(const std::string& msg);
-  void HandleSyncMessage(const std::string& msg);
-
-  void SetPostMessageCallback(MessageCallback callback);
-  void SetSendSyncReplyCallback(MessageCallback callback);
-
- private:
-  friend class XWalkExtensionAdapter;
-
-  void PostMessageToJS(const std::string& msg);
-  void SyncReplyToJS(const std::string& reply);
-
-  XWalkExtension* extension_;
-  XW_Instance xw_instance_;
-  void* instance_data_;
-
-  MessageCallback post_message_callback_;
-  MessageCallback send_sync_reply_callback_;
-};
-
-}  // namespace extensions
-
-#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_INSTANCE_H_
diff --git a/extensions/extension/xwalk_extension_process.cc b/extensions/extension/xwalk_extension_process.cc
deleted file mode 100644 (file)
index edbcccc..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <Ecore.h>
-
-#include "common/command_line.h"
-#include "common/logger.h"
-#include "extensions/extension/xwalk_extension_server.h"
-
-Ecore_Event_Handler* quit_handler = NULL;
-
-int main(int argc, char* argv[]) {
-  ecore_init();
-
-  // Register Quit Signal Handlers
-  auto quit_callback = [](void*, int, void*) -> Eina_Bool {
-    ecore_main_loop_quit();
-    return EINA_TRUE;
-  };
-  ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
-                          quit_callback, NULL);
-
-  common::CommandLine::Init(argc, argv);
-  common::CommandLine* cmd = common::CommandLine::ForCurrentProcess();
-
-  // TODO(wy80.choi): Receive extension paths for user defined extensions.
-
-  // Receive appid from arguments.
-  if (cmd->arguments().size() < 1) {
-    LOGGER(ERROR) << "appid is required.";
-    return false;
-  }
-  std::string appid = cmd->arguments()[0];
-
-  // Start ExtensionServer
-  extensions::XWalkExtensionServer server(appid);
-  if (!server.Start()) {
-    LOGGER(ERROR) << "Failed to start extension server.";
-    return false;
-  }
-
-  LOGGER(INFO) << "extension process has been started.";
-  ecore_main_loop_glib_integrate();
-  ecore_main_loop_begin();
-
-  LOGGER(INFO) << "extension process is exiting.";
-  ecore_shutdown();
-
-  return true;
-}
diff --git a/extensions/extension/xwalk_extension_server.cc b/extensions/extension/xwalk_extension_server.cc
deleted file mode 100644 (file)
index 075110d..0000000
+++ /dev/null
@@ -1,472 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "extensions/extension/xwalk_extension_server.h"
-
-#include <glib.h>
-#include <glob.h>
-
-#include <fstream>
-#include <string>
-#include <vector>
-
-#include "common/app_db.h"
-#include "common/file_utils.h"
-#include "common/logger.h"
-#include "common/picojson.h"
-#include "common/string_utils.h"
-
-#include "extensions/common/constants.h"
-#include "extensions/extension/xwalk_extension.h"
-
-namespace extensions {
-
-namespace {
-
-const char kAppDBRuntimeSection[] = "Runtime";
-
-const char kExtensionPrefix[] = "lib";
-const char kExtensionSuffix[] = ".so";
-const char kExtensionMetadataSuffix[] = ".json";
-
-const char kDBusIntrospectionXML[] =
-  "<node>"
-  "  <interface name='org.tizen.xwalk.Extension'>"
-  "    <method name='GetExtensions'>"
-  "      <arg name='extensions' type='a(ssas)' direction='out' />"
-  "    </method>"
-  "    <method name='GetJavascriptCode'>"
-  "      <arg name='extension_name' type='s' direction='in' />"
-  "      <arg name='code' type='s' direction='out' />"
-  "    </method>"
-  "    <method name='CreateInstance'>"
-  "      <arg name='extension_name' type='s' direction='in' />"
-  "      <arg name='instance_id' type='s' direction='out' />"
-  "    </method>"
-  "    <method name='DestroyInstance'>"
-  "      <arg name='instance_id' type='s' direction='in' />"
-  "      <arg name='instance_id' type='s' direction='out' />"
-  "    </method>"
-  "    <method name='PostMessage'>"
-  "      <arg name='instance_id' type='s' direction='in' />"
-  "      <arg name='msg' type='s' direction='in' />"
-  "    </method>"
-  "    <method name='SendSyncMessage'>"
-  "      <arg name='instance_id' type='s' direction='in' />"
-  "      <arg name='msg' type='s' direction='in' />"
-  "      <arg name='reply' type='s' direction='out' />"
-  "    </method>"
-  "    <signal name='OnMessageToJS'>"
-  "      <arg name='instance_id' type='s' />"
-  "      <arg name='msg' type='s' />"
-  "    </signal>"
-  "  </interface>"
-  "</node>";
-
-void LoadFrequentlyUsedModules(
-    const std::map<std::string, XWalkExtension*>& modules) {
-  auto it = modules.find("tizen");
-  if (it != modules.end()) {
-    it->second->Initialize();
-  }
-  it = modules.find("xwalk.utils");
-  if (it != modules.end()) {
-    it->second->Initialize();
-  }
-}
-
-}  // namespace
-
-XWalkExtensionServer::XWalkExtensionServer(const std::string& appid)
-    : appid_(appid) {
-}
-
-XWalkExtensionServer::~XWalkExtensionServer() {
-}
-
-bool XWalkExtensionServer::Start() {
-  return Start(StringVector());
-}
-
-bool XWalkExtensionServer::Start(const StringVector& paths) {
-  // Register system extensions to support Tizen Device APIs
-#ifdef PLUGIN_LAZY_LOADING
-  RegisterSystemExtensionsByMetadata();
-#else
-  RegisterSystemExtensions();
-#endif
-
-  // Register user extensions
-  for (auto it = paths.begin(); it != paths.end(); ++it) {
-    if (common::utils::Exists(*it)) {
-      RegisterExtension(*it);
-    }
-  }
-
-  // Start DBusServer
-  using std::placeholders::_1;
-  using std::placeholders::_2;
-  using std::placeholders::_3;
-  using std::placeholders::_4;
-  dbus_server_.SetIntrospectionXML(kDBusIntrospectionXML);
-  dbus_server_.SetMethodCallback(
-      kDBusInterfaceNameForExtension,
-      std::bind(&XWalkExtensionServer::HandleDBusMethod, this, _1, _2, _3, _4));
-  dbus_server_.Start(appid_ + "." + std::string(kDBusNameForExtension));
-
-#ifdef PLUGIN_LAZY_LOADING
-  LoadFrequentlyUsedModules(extensions_);
-#endif
-
-  return true;
-}
-
-void XWalkExtensionServer::RegisterExtension(const std::string& path) {
-  XWalkExtension* ext = new XWalkExtension(path, this);
-  if (!ext->Initialize() || !RegisterSymbols(ext)) {
-    delete ext;
-    return;
-  }
-  extensions_[ext->name()] = ext;
-  LOGGER(DEBUG) << ext->name() << " is registered.";
-}
-
-void XWalkExtensionServer::RegisterExtension(XWalkExtension* extension) {
-  if (!extension->lazy_loading() && !extension->Initialize()) {
-    delete extension;
-    return;
-  }
-
-  if (!RegisterSymbols(extension)) {
-    delete extension;
-    return;
-  }
-
-  extensions_[extension->name()] = extension;
-  LOGGER(DEBUG) << extension->name() << " is registered.";
-}
-
-void XWalkExtensionServer::RegisterSystemExtensions() {
-#ifdef EXTENSION_PATH
-  std::string extension_path(EXTENSION_PATH);
-#else
-  #error EXTENSION_PATH is not set.
-#endif
-  extension_path.append("/");
-  extension_path.append(kExtensionPrefix);
-  extension_path.append("*");
-  extension_path.append(kExtensionSuffix);
-
-  glob_t glob_result;
-  glob(extension_path.c_str(), GLOB_TILDE, NULL, &glob_result);
-  for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
-    RegisterExtension(glob_result.gl_pathv[i]);
-  }
-}
-
-void XWalkExtensionServer::RegisterSystemExtensionsByMetadata() {
-#ifdef EXTENSION_PATH
-  std::string extension_path(EXTENSION_PATH);
-#else
-  #error EXTENSION_PATH is not set.
-#endif
-  extension_path.append("/");
-  extension_path.append("*");
-  extension_path.append(kExtensionMetadataSuffix);
-
-  glob_t glob_result;
-  glob(extension_path.c_str(), GLOB_TILDE, NULL, &glob_result);
-  for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) {
-    RegisterSystemExtensionsByMetadata(glob_result.gl_pathv[i]);
-  }
-  if (glob_result.gl_pathc == 0) {
-    RegisterSystemExtensions();
-  }
-}
-
-void XWalkExtensionServer::RegisterSystemExtensionsByMetadata(
-    const std::string& metadata_path) {
-#ifdef EXTENSION_PATH
-  std::string extension_path(EXTENSION_PATH);
-#else
-  #error EXTENSION_PATH is not set.
-#endif
-
-  std::ifstream metafile(metadata_path.c_str());
-  if (!metafile.is_open()) {
-    LOGGER(ERROR) << "Fail to open the plugin metadata file :" << metadata_path;
-    return;
-  }
-
-  picojson::value metadata;
-  metafile >> metadata;
-    if (metadata.is<picojson::array>()) {
-    auto& plugins = metadata.get<picojson::array>();
-    for (auto plugin = plugins.begin(); plugin != plugins.end(); ++plugin) {
-      if (!plugin->is<picojson::object>())
-        continue;
-
-      std::string name = plugin->get("name").to_str();
-      std::string lib = plugin->get("lib").to_str();
-      if (!common::utils::StartsWith(lib, "/")) {
-        lib = extension_path + "/" + lib;
-      }
-
-      std::vector<std::string> entries;
-      auto& entry_points_value = plugin->get("entry_points");
-      if (entry_points_value.is<picojson::array>()) {
-        auto& entry_points = entry_points_value.get<picojson::array>();
-        for (auto entry = entry_points.begin(); entry != entry_points.end();
-             ++entry) {
-          entries.push_back(entry->to_str());
-        }
-      }
-      XWalkExtension* extension = new XWalkExtension(lib, name, entries, this);
-      RegisterExtension(extension);
-    }
-  } else {
-    SLOGE("%s is not plugin metadata", metadata_path.c_str());
-  }
-  metafile.close();
-}
-
-
-bool XWalkExtensionServer::RegisterSymbols(XWalkExtension* extension) {
-  std::string name = extension->name();
-
-  if (extension_symbols_.find(name) != extension_symbols_.end()) {
-    LOGGER(WARN) << "Ignoring extension with name already registred. '"
-                 << name << "'";
-    return false;
-  }
-
-  XWalkExtension::StringVector entry_points = extension->entry_points();
-  for (auto it = entry_points.begin(); it != entry_points.end(); ++it) {
-    if (extension_symbols_.find(*it) != extension_symbols_.end()) {
-      LOGGER(WARN) << "Ignoring extension with entry_point already registred. '"
-                   << (*it) << "'";
-      return false;
-    }
-  }
-
-  for (auto it = entry_points.begin(); it != entry_points.end(); ++it) {
-    extension_symbols_.insert(*it);
-  }
-
-  extension_symbols_.insert(name);
-
-  return true;
-}
-
-void XWalkExtensionServer::GetRuntimeVariable(const char* key, char* value,
-    size_t value_len) {
-  common::AppDB* db = common::AppDB::GetInstance();
-  std::string ret = db->Get(kAppDBRuntimeSection, key);
-  strncpy(value, ret.c_str(), value_len);
-}
-
-void XWalkExtensionServer::HandleDBusMethod(GDBusConnection* connection,
-                                       const std::string& method_name,
-                                       GVariant* parameters,
-                                       GDBusMethodInvocation* invocation) {
-  if (method_name == kMethodGetExtensions) {
-    OnGetExtensions(invocation);
-  } else if (method_name == kMethodCreateInstance) {
-    gchar* extension_name;
-    g_variant_get(parameters, "(&s)", &extension_name);
-    OnCreateInstance(connection, extension_name, invocation);
-  } else if (method_name == kMethodDestroyInstance) {
-    gchar* instance_id;
-    g_variant_get(parameters, "(&s)", &instance_id);
-    OnDestroyInstance(instance_id, invocation);
-  } else if (method_name == kMethodSendSyncMessage) {
-    gchar* instance_id;
-    gchar* msg;
-    g_variant_get(parameters, "(&s&s)", &instance_id, &msg);
-    OnSendSyncMessage(instance_id, msg, invocation);
-  } else if (method_name == kMethodPostMessage) {
-    gchar* instance_id;
-    gchar* msg;
-    g_variant_get(parameters, "(&s&s)", &instance_id, &msg);
-    OnPostMessage(instance_id, msg);
-  } else if (method_name == kMethodGetJavascriptCode) {
-    gchar* extension_name;
-    g_variant_get(parameters, "(&s)", &extension_name);
-    OnGetJavascriptCode(connection, extension_name, invocation);
-  }
-}
-
-void XWalkExtensionServer::OnGetExtensions(GDBusMethodInvocation* invocation) {
-  GVariantBuilder builder;
-
-  g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
-
-  // build an array of extensions
-  auto it = extensions_.begin();
-  for ( ; it != extensions_.end(); ++it) {
-    XWalkExtension* ext = it->second;
-    // open container for extension
-    g_variant_builder_open(&builder, G_VARIANT_TYPE("(ssas)"));
-    g_variant_builder_add(&builder, "s", ext->name().c_str());
-    g_variant_builder_add(&builder, "s", ext->javascript_api().c_str());
-
-    // open container for entry_point
-    g_variant_builder_open(&builder, G_VARIANT_TYPE("as"));
-    auto it_entry = ext->entry_points().begin();
-    for ( ; it_entry != ext->entry_points().end(); ++it_entry) {
-      g_variant_builder_add(&builder, "s", (*it_entry).c_str());
-    }
-    // close container('as') for entry_point
-    g_variant_builder_close(&builder);
-    // close container('(ssas)') for extension
-    g_variant_builder_close(&builder);
-  }
-
-  GVariant* reply = NULL;
-  if (extensions_.size() == 0) {
-    reply = g_variant_new_array(G_VARIANT_TYPE("(ssas)"), NULL, 0);
-  } else {
-    reply = g_variant_builder_end(&builder);
-  }
-
-  g_dbus_method_invocation_return_value(
-      invocation, g_variant_new_tuple(&reply, 1));
-}
-
-void XWalkExtensionServer::OnCreateInstance(
-    GDBusConnection* connection, const std::string& extension_name,
-    GDBusMethodInvocation* invocation) {
-  std::string instance_id = common::utils::GenerateUUID();
-
-  // find extension with given the extension name
-  auto it = extensions_.find(extension_name);
-  if (it == extensions_.end()) {
-    LOGGER(ERROR) << "Failed to find extension '" << extension_name << "'";
-    g_dbus_method_invocation_return_error(
-        invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
-        "Not found extension %s", extension_name.c_str());
-    return;
-  }
-
-  // create instance
-  XWalkExtensionInstance* instance = it->second->CreateInstance();
-  if (!instance) {
-    LOGGER(ERROR) << "Failed to create instance of extension '"
-                  << extension_name << "'";
-    g_dbus_method_invocation_return_error(
-        invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
-        "Failed to create instance of extension %s", extension_name.c_str());
-    return;
-  }
-
-  // set callbacks
-  using std::placeholders::_1;
-  instance->SetPostMessageCallback(
-      std::bind(&XWalkExtensionServer::PostMessageToJSCallback,
-                this, connection, instance_id, _1));
-
-  instances_[instance_id] = instance;
-  g_dbus_method_invocation_return_value(
-      invocation, g_variant_new("(s)", instance_id.c_str()));
-}
-
-void XWalkExtensionServer::OnDestroyInstance(
-    const std::string& instance_id, GDBusMethodInvocation* invocation) {
-  // find instance with the given instance id
-  auto it = instances_.find(instance_id);
-  if (it == instances_.end()) {
-    LOGGER(ERROR) << "Failed to find instance '" << instance_id << "'";
-    g_dbus_method_invocation_return_error(
-        invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
-        "Not found instance %s", instance_id.c_str());
-    return;
-  }
-
-  // destroy the instance
-  XWalkExtensionInstance* instance = it->second;
-  delete instance;
-
-  instances_.erase(it);
-
-  g_dbus_method_invocation_return_value(
-      invocation, g_variant_new("(s)", instance_id.c_str()));
-}
-
-void XWalkExtensionServer::OnSendSyncMessage(
-    const std::string& instance_id, const std::string& msg,
-    GDBusMethodInvocation* invocation) {
-  // find instance with the given instance id
-  auto it = instances_.find(instance_id);
-  if (it == instances_.end()) {
-    LOGGER(ERROR) << "Failed to find instance '" << instance_id << "'";
-    g_dbus_method_invocation_return_error(
-        invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
-        "Not found instance %s", instance_id.c_str());
-    return;
-  }
-
-  XWalkExtensionInstance* instance = it->second;
-
-  using std::placeholders::_1;
-  instance->SetSendSyncReplyCallback(
-      std::bind(&XWalkExtensionServer::SyncReplyCallback,
-                this, _1, invocation));
-
-  instance->HandleSyncMessage(msg);
-}
-
-// async
-void XWalkExtensionServer::OnPostMessage(
-    const std::string& instance_id, const std::string& msg) {
-  auto it = instances_.find(instance_id);
-  if (it == instances_.end()) {
-    LOGGER(ERROR) << "Failed to find instance '" << instance_id << "'";
-    return;
-  }
-
-  XWalkExtensionInstance* instance = it->second;
-  instance->HandleMessage(msg);
-}
-
-void XWalkExtensionServer::OnGetJavascriptCode(GDBusConnection* connection,
-                        const std::string& extension_name,
-                        GDBusMethodInvocation* invocation) {
-  // find extension with given the extension name
-  auto it = extensions_.find(extension_name);
-  if (it == extensions_.end()) {
-    LOGGER(ERROR) << "Failed to find extension '" << extension_name << "'";
-    g_dbus_method_invocation_return_error(
-        invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
-        "Not found extension %s", extension_name.c_str());
-    return;
-  }
-
-  it->second->Initialize();
-  g_dbus_method_invocation_return_value(
-      invocation, g_variant_new("(s)", it->second->javascript_api().c_str()));
-}
-
-void XWalkExtensionServer::SyncReplyCallback(
-    const std::string& reply, GDBusMethodInvocation* invocation) {
-  g_dbus_method_invocation_return_value(
-      invocation, g_variant_new("(s)", reply.c_str()));
-}
-
-void XWalkExtensionServer::PostMessageToJSCallback(
-    GDBusConnection* connection, const std::string& instance_id,
-    const std::string& msg) {
-  if (!connection || g_dbus_connection_is_closed(connection)) {
-    LOGGER(ERROR) << "Client connection is closed already.";
-    return;
-  }
-
-  dbus_server_.SendSignal(connection,
-                          kDBusInterfaceNameForExtension,
-                          kSignalOnMessageToJS,
-                          g_variant_new("(ss)",
-                                        instance_id.c_str(),
-                                        msg.c_str()));
-}
-
-}  // namespace extensions
diff --git a/extensions/extension/xwalk_extension_server.h b/extensions/extension/xwalk_extension_server.h
deleted file mode 100644 (file)
index 854e534..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef XWALK_EXTENSIONS_XWALK_EXTENSION_SERVER_H_
-#define XWALK_EXTENSIONS_XWALK_EXTENSION_SERVER_H_
-
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "common/dbus_client.h"
-#include "common/dbus_server.h"
-#include "extensions/extension/xwalk_extension.h"
-
-namespace extensions {
-
-class XWalkExtensionServer : public XWalkExtension::XWalkExtensionDelegate {
- public:
-  typedef std::vector<std::string> StringVector;
-
-  explicit XWalkExtensionServer(const std::string& appid);
-  virtual ~XWalkExtensionServer();
-
-  bool Start();
-  bool Start(const StringVector& paths);
-
- private:
-  void RegisterExtension(const std::string& path);
-  void RegisterExtension(XWalkExtension* extension);
-  void RegisterSystemExtensions();
-  void RegisterSystemExtensionsByMetadata();
-  void RegisterSystemExtensionsByMetadata(const std::string& metadata_path);
-  bool RegisterSymbols(XWalkExtension* extension);
-
-  void GetRuntimeVariable(const char* key, char* value, size_t value_len);
-
-  void HandleDBusMethod(GDBusConnection* connection,
-                        const std::string& method_name,
-                        GVariant* parameters,
-                        GDBusMethodInvocation* invocation);
-
-  void OnGetExtensions(GDBusMethodInvocation* invocation);
-  void OnCreateInstance(GDBusConnection* connection,
-                        const std::string& extension_name,
-                        GDBusMethodInvocation* invocation);
-  void OnDestroyInstance(const std::string& instance_id,
-                         GDBusMethodInvocation* invocation);
-  void OnSendSyncMessage(const std::string& instance_id,
-                         const std::string& msg,
-                         GDBusMethodInvocation* invocation);
-  void OnPostMessage(const std::string& instance_id,
-                     const std::string& msg);
-
-  void SyncReplyCallback(const std::string& reply,
-                         GDBusMethodInvocation* invocation);
-
-  void PostMessageToJSCallback(GDBusConnection* connection,
-                               const std::string& instance_id,
-                               const std::string& msg);
-  void OnGetJavascriptCode(GDBusConnection* connection,
-                        const std::string& extension_name,
-                        GDBusMethodInvocation* invocation);
-
-  std::string appid_;
-  common::DBusServer dbus_server_;
-  common::DBusClient dbus_application_client_;
-
-  typedef std::set<std::string> StringSet;
-  StringSet extension_symbols_;
-
-  typedef std::map<std::string, XWalkExtension*> ExtensionMap;
-  ExtensionMap extensions_;
-
-  typedef std::map<std::string, XWalkExtensionInstance*> InstanceMap;
-  InstanceMap instances_;
-};
-
-}  // namespace extensions
-
-#endif  // XWALK_EXTENSIONS_XWALK_EXTENSION_SERVER_H_
index 871cd6edb6e3c6b7ea39c6c843991af5d20c93b5..0f9574849df7c6452f733218a7fca77a6d7f2e7e 100644 (file)
@@ -3,39 +3,6 @@
     '../build/common.gypi',
   ],
   'targets': [
-    {
-      'target_name': 'xwalk_extension',
-      'type': 'executable',
-      'dependencies': [
-        '../common/common.gyp:xwalk_tizen_common',
-      ],
-      'sources': [
-        'common/constants.h',
-        'common/constants.cc',
-        'extension/xwalk_extension.h',
-        'extension/xwalk_extension.cc',
-        'extension/xwalk_extension_instance.h',
-        'extension/xwalk_extension_instance.cc',
-        'extension/xwalk_extension_adapter.h',
-        'extension/xwalk_extension_adapter.cc',
-        'extension/xwalk_extension_server.h',
-        'extension/xwalk_extension_server.cc',
-        'extension/xwalk_extension_process.cc',
-      ],
-      'defines': [
-        'PLUGIN_LAZY_LOADING',
-      ],
-      'variables': {
-        'packages': [
-          'ecore',
-        ],
-      },
-      'link_settings': {
-        'ldflags': [
-          '-ldl',
-        ],
-      },
-    }, # end of target 'xwalk_extension'
     {
       'target_name': 'xwalk_extension_renderer',
       'type': 'static_library',
       'sources': [
         'common/constants.h',
         'common/constants.cc',
+        'common/xwalk_extension.h',
+        'common/xwalk_extension.cc',
+        'common/xwalk_extension_instance.h',
+        'common/xwalk_extension_instance.cc',
+        'common/xwalk_extension_adapter.h',
+        'common/xwalk_extension_adapter.cc',
+        'common/xwalk_extension_manager.h',
+        'common/xwalk_extension_manager.cc',
         'renderer/xwalk_extension_client.h',
         'renderer/xwalk_extension_client.cc',
         'renderer/xwalk_extension_module.h',
index f14e38d66eee111305d6863f09f33d29bcca8aa1..8423d038e4b452a0b54028611375d16f8e9633ec 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "common/logger.h"
 #include "common/profiler.h"
+#include "common/string_utils.h"
 #include "extensions/common/constants.h"
 
 namespace extensions {
@@ -21,180 +22,107 @@ XWalkExtensionClient::XWalkExtensionClient() {
 }
 
 XWalkExtensionClient::~XWalkExtensionClient() {
-  auto it = extension_apis_.begin();
-  for ( ; it != extension_apis_.end(); ++it) {
-    delete it->second;
-  }
 }
 
-std::string XWalkExtensionClient::CreateInstance(
-    const std::string& extension_name, InstanceHandler* handler) {
-  GVariant* value = dbus_extension_client_.Call(
-      kDBusInterfaceNameForExtension, kMethodCreateInstance,
-      g_variant_new("(s)", extension_name.c_str()),
-      G_VARIANT_TYPE("(s)"));
-
-  if (!value) {
-    LOGGER(ERROR) << "Failed to create instance for extension "
-                  << extension_name;
-    return std::string();
-  }
-
-  gchar* instance_id;
-  g_variant_get(value, "(&s)", &instance_id);
-
-  std::string ret(instance_id);
-  handlers_[ret] = handler;
-
-  g_variant_unref(value);
-  return ret;
+void XWalkExtensionClient::Initialize() {
+  manager_.LoadExtensions();
 }
 
-void XWalkExtensionClient::DestroyInstance(const std::string& instance_id) {
-  GVariant* value = dbus_extension_client_.Call(
-      kDBusInterfaceNameForExtension, kMethodDestroyInstance,
-      g_variant_new("(s)", instance_id.c_str()),
-      G_VARIANT_TYPE("(s)"));
-
-  if (!value) {
-    LOGGER(ERROR) << "Failed to destroy instance " << instance_id;
-    return;
+XWalkExtension* XWalkExtensionClient::GetExtension(
+    const std::string& extension_name) {
+  // find extension with given the extension name
+  ExtensionMap extensions = manager_.extensions();
+  auto it = extensions.find(extension_name);
+  if (it == extensions.end()) {
+    LOGGER(ERROR) << "No such extension '" << extension_name << "'";
+    return nullptr;
   }
 
-  auto it = handlers_.find(instance_id);
-  if (it != handlers_.end()) {
-    handlers_.erase(it);
-  }
-
-  g_variant_unref(value);
+  return it->second;
 }
 
-void XWalkExtensionClient::PostMessageToNative(
-    const std::string& instance_id, const std::string& msg) {
-  dbus_extension_client_.Call(
-      kDBusInterfaceNameForExtension, kMethodPostMessage,
-      g_variant_new("(ss)", instance_id.c_str(), msg.c_str()),
-      NULL);
+XWalkExtensionClient::ExtensionMap XWalkExtensionClient::GetExtensions() {
+  return manager_.extensions();
 }
 
-std::string XWalkExtensionClient::SendSyncMessageToNative(
-    const std::string& instance_id, const std::string& msg) {
-  GVariant* value = dbus_extension_client_.Call(
-      kDBusInterfaceNameForExtension, kMethodSendSyncMessage,
-      g_variant_new("(ss)", instance_id.c_str(), msg.c_str()),
-      G_VARIANT_TYPE("(s)"));
+std::string XWalkExtensionClient::CreateInstance(
+    const std::string& extension_name, InstanceHandler* handler) {
+  std::string instance_id = common::utils::GenerateUUID();
 
-  if (!value) {
-    LOGGER(ERROR) << "Failed to send synchronous message to ExtensionServer.";
+  // find extension with given the extension name
+  ExtensionMap extensions = manager_.extensions();
+  auto it = extensions.find(extension_name);
+  if (it == extensions.end()) {
+    LOGGER(ERROR) << "No such extension '" << extension_name << "'";
     return std::string();
   }
 
-  gchar* reply;
-  g_variant_get(value, "(&s)", &reply);
-
-  std::string ret(reply);
-  g_variant_unref(value);
-
-  return ret;
-}
-
-bool XWalkExtensionClient::Initialize(const std::string& appid) {
-  STEP_PROFILE_START("Connect ExtensionServer");
-  // Retry connecting to ExtensionServer
-  // ExtensionServer can not be ready at this time yet.
-  const int retry_max = 20;
-  bool connected = false;
-  for (int i=0; i < retry_max; i++) {
-    connected = dbus_extension_client_.ConnectByName(
-        appid + "." + std::string(kDBusNameForExtension));
-    if (connected) break;
-    LOGGER(WARN) << "Failed to connect to ExtensionServer. retry "
-                 << (i+1) << "/" << retry_max;
-    usleep(50*1000);
-  }
-  STEP_PROFILE_END("Connect ExtensionServer");
-
-  if (!connected) {
-    LOGGER(ERROR) << "Failed to connect to the dbus server for Extension.";
-    return false;
+  // create instance
+  XWalkExtensionInstance* instance = it->second->CreateInstance();
+  if (!instance) {
+    LOGGER(ERROR) << "Failed to create instance of extension '"
+                  << extension_name << "'";
+    return std::string();
   }
 
-  // Set signal handler
+  // set callbacks
   using std::placeholders::_1;
-  using std::placeholders::_2;
-  dbus_extension_client_.SetSignalCallback(
-      kDBusInterfaceNameForExtension,
-      std::bind(&XWalkExtensionClient::HandleSignal, this, _1, _2));
-
-  // get extensions from ExtensionServer
-  GVariant* value = dbus_extension_client_.Call(
-      kDBusInterfaceNameForExtension, kMethodGetExtensions,
-      NULL,
-      G_VARIANT_TYPE("(a(ssas))"));
-
-  if (!value) {
-    LOGGER(ERROR) << "Failed to get extension list from ExtensionServer.";
-    return false;
-  }
-
-  gchar* name;
-  gchar* jsapi;
-  gchar* entry_point;
-  GVariantIter *it;
-  GVariantIter* entry_it;
-
-  g_variant_get(value, "(a(ssas))", &it);
-  while (g_variant_iter_loop(it, "(ssas)", &name, &jsapi, &entry_it)) {
-    ExtensionCodePoints* code = new ExtensionCodePoints;
-    code->api = std::string(jsapi);
-    while (g_variant_iter_loop(entry_it, "s", &entry_point)) {
-      code->entry_points.push_back(std::string(entry_point));
+  instance->SetPostMessageCallback([handler](const std::string& msg) {
+    if (handler) {
+      handler->HandleMessageFromNative(msg);
     }
-    extension_apis_.insert(std::make_pair(std::string(name), code));
+  });
+
+  instances_[instance_id] = instance;
+  return instance_id;
+}
+
+void XWalkExtensionClient::DestroyInstance(const std::string& instance_id) {
+  // find instance with the given instance id
+  auto it = instances_.find(instance_id);
+  if (it == instances_.end()) {
+    LOGGER(ERROR) << "No such instance '" << instance_id << "'";
+    return;
   }
 
-  g_variant_unref(value);
+  // destroy the instance
+  XWalkExtensionInstance* instance = it->second;
+  delete instance;
 
-  return true;
+  instances_.erase(it);
 }
 
-void XWalkExtensionClient::HandleSignal(
-    const std::string& signal_name, GVariant* parameters) {
-  if (signal_name == kSignalOnMessageToJS) {
-    gchar* instance_id;
-    gchar* msg;
-    g_variant_get(parameters, "(&s&s)", &instance_id, &msg);
-    auto it = handlers_.find(instance_id);
-    if (it != handlers_.end()) {
-      InstanceHandler* handler = it->second;
-      if (handler) {
-        handler->HandleMessageFromNative(msg);
-      }
-    }
+void XWalkExtensionClient::PostMessageToNative(
+    const std::string& instance_id, const std::string& msg) {
+  // find instance with the given instance id
+  auto it = instances_.find(instance_id);
+  if (it == instances_.end()) {
+    LOGGER(ERROR) << "No such instance '" << instance_id << "'";
+    return;
   }
-}
 
-std::string XWalkExtensionClient::GetExtensionJavascriptAPICode(
-    const std::string& name) {
+  // Post a message
+  XWalkExtensionInstance* instance = it->second;
+  instance->HandleMessage(msg);
+}
 
-  auto extension_code_point = extension_apis_.find(name);
-  if (extension_code_point == extension_apis_.end())
+std::string XWalkExtensionClient::SendSyncMessageToNative(
+    const std::string& instance_id, const std::string& msg) {
+  // find instance with the given instance id
+  auto it = instances_.find(instance_id);
+  if (it == instances_.end()) {
+    LOGGER(ERROR) << "No such instance '" << instance_id << "'";
     return std::string();
-
-  ExtensionCodePoints* code_points = extension_code_point->second;
-  if (!code_points->api.empty()) {
-    return code_points->api;
   }
 
-  GVariant* value = dbus_extension_client_.Call(
-      kDBusInterfaceNameForExtension, kMethodGetJavascriptCode,
-      g_variant_new("(s)", name.c_str()),
-      G_VARIANT_TYPE("(s)"));
-  gchar* api;
-  g_variant_get(value, "(&s)", &api);
-  code_points->api = std::string(api);
-  g_variant_unref(value);
-  return code_points->api;
+  // Post a message and receive a reply message
+  std::string reply;
+  XWalkExtensionInstance* instance = it->second;
+  instance->SetSendSyncReplyCallback([&reply](const std::string& msg) {
+    reply = msg;
+  });
+  instance->HandleSyncMessage(msg);
+  return reply;
 }
 
 }  // namespace extensions
index bba39eff702c7d019edab12fbe3f170b478161e2..9d464440fde42c0c0b9310364c414ed125040dc9 100644 (file)
 #include <string>
 #include <vector>
 
-#include "common/dbus_client.h"
+#include "extensions/common/xwalk_extension.h"
+#include "extensions/common/xwalk_extension_instance.h"
+#include "extensions/common/xwalk_extension_manager.h"
 
 namespace extensions {
 
 class XWalkExtensionClient {
  public:
+  typedef std::map<std::string, XWalkExtension*> ExtensionMap;
+  typedef std::map<std::string, XWalkExtensionInstance*> InstanceMap;
+
   struct InstanceHandler {
     virtual void HandleMessageFromNative(const std::string& msg) = 0;
    protected:
@@ -26,6 +31,11 @@ class XWalkExtensionClient {
   XWalkExtensionClient();
   virtual ~XWalkExtensionClient();
 
+  void Initialize();
+
+  XWalkExtension* GetExtension(const std::string& extension_name);
+  ExtensionMap GetExtensions();
+
   std::string CreateInstance(const std::string& extension_name,
                              InstanceHandler* handler);
   void DestroyInstance(const std::string& instance_id);
@@ -35,23 +45,9 @@ class XWalkExtensionClient {
   std::string SendSyncMessageToNative(const std::string& instance_id,
                                       const std::string& msg);
 
-  bool Initialize(const std::string& appid);
-
-  struct ExtensionCodePoints {
-    std::string api;
-    std::vector<std::string> entry_points;
-  };
-
-  typedef std::map<std::string, ExtensionCodePoints*> ExtensionAPIMap;
-  const ExtensionAPIMap& extension_apis() const { return extension_apis_; }
-  std::string GetExtensionJavascriptAPICode(const std::string& name);
-
  private:
-  void HandleSignal(const std::string& signal_name, GVariant* parameters);
-
-  ExtensionAPIMap extension_apis_;
-  std::map<std::string, InstanceHandler*> handlers_;
-  common::DBusClient dbus_extension_client_;
+  XWalkExtensionManager manager_;
+  InstanceMap instances_;
 };
 
 }  // namespace extensions
index 82e22c1ea3a591df6b4d7dc5ce6a334935f4b238..232fb7d44442b8f980751bba0afa12e86040e15a 100644 (file)
@@ -48,12 +48,10 @@ const char* kXWalkExtensionModule = "kXWalkExtensionModule";
 
 XWalkExtensionModule::XWalkExtensionModule(XWalkExtensionClient* client,
                                            XWalkModuleSystem* module_system,
-                                           const std::string& extension_name,
-                                           const std::string& extension_code)
-    : extension_name_(extension_name),
-      extension_code_(extension_code),
-      client_(client),
-      module_system_(module_system) {
+                                           const std::string& extension_name) :
+    extension_name_(extension_name),
+    client_(client),
+    module_system_(module_system) {
   v8::Isolate* isolate = v8::Isolate::GetCurrent();
   v8::HandleScope handle_scope(isolate);
   v8::Handle<v8::Object> function_data = v8::Object::New(isolate);
@@ -270,12 +268,22 @@ v8::Handle<v8::Value> RunString(const std::string& code,
 void XWalkExtensionModule::LoadExtensionCode(
     v8::Handle<v8::Context> context, v8::Handle<v8::Function> require_native) {
   instance_id_ = client_->CreateInstance(extension_name_, this);
+  if (instance_id_.empty()) {
+    LOGGER(ERROR) << "Failed to create an instance of " << extension_name_;
+    return;
+  }
 
-  std::string exception;
-  if (extension_code_.empty()) {
-    extension_code_ = client_->GetExtensionJavascriptAPICode(extension_name_);
+
+
+  XWalkExtension* ext = client_->GetExtension(extension_name_);
+  if (ext == nullptr) {
+    LOGGER(ERROR) << "Failed to get an extension " << extension_name_;
+    return;
   }
-  std::string wrapped_api_code = WrapAPICode(extension_code_, extension_name_);
+  std::string wrapped_api_code =
+      WrapAPICode(ext->GetJavascriptCode(), extension_name_);
+
+  std::string exception;
   v8::Handle<v8::Value> result = RunString(wrapped_api_code, &exception);
 
   if (!result->IsFunction()) {
index 1076f0fa7b0a0a0d1f1a46766c15a5b84b81329f..eea3d0156f8e3a3bfb0510ff3ae7e68d1dec4d20 100644 (file)
@@ -28,8 +28,7 @@ class XWalkExtensionModule : public XWalkExtensionClient::InstanceHandler {
  public:
   XWalkExtensionModule(XWalkExtensionClient* client,
                   XWalkModuleSystem* module_system,
-                  const std::string& extension_name,
-                  const std::string& extension_code);
+                  const std::string& extension_name);
   virtual ~XWalkExtensionModule();
 
   // TODO(cmarcelo): Make this return a v8::Handle<v8::Object>, and
@@ -72,7 +71,6 @@ class XWalkExtensionModule : public XWalkExtensionClient::InstanceHandler {
   v8::Persistent<v8::Function> message_listener_;
 
   std::string extension_name_;
-  std::string extension_code_;
 
   XWalkExtensionClient* client_;
   XWalkModuleSystem* module_system_;
index 1e6395d1ba903249ddc2411404919ae2cae6240c..71230a4d1ea28ab908a97c55eb00f04486840021 100644 (file)
@@ -25,19 +25,13 @@ namespace {
 void CreateExtensionModules(XWalkExtensionClient* client,
                             XWalkModuleSystem* module_system) {
   SCOPE_PROFILE();
-  const XWalkExtensionClient::ExtensionAPIMap& extensions =
-      client->extension_apis();
-  auto it = extensions.begin();
-  for (; it != extensions.end(); ++it) {
-    XWalkExtensionClient::ExtensionCodePoints* codepoint = it->second;
 
+  auto extensions = client->GetExtensions();
+  for (auto it = extensions.begin(); it != extensions.end(); ++it) {
     std::unique_ptr<XWalkExtensionModule> module(
-        new XWalkExtensionModule(client,
-              module_system,
-              it->first,
-              codepoint->api));
+        new XWalkExtensionModule(client, module_system, it->first));
     module_system->RegisterExtensionModule(
-        std::move(module), codepoint->entry_points);
+        std::move(module), it->second->entry_points());
   }
 }
 
@@ -83,9 +77,8 @@ void XWalkExtensionRendererController::WillReleaseScriptContext(
   XWalkModuleSystem::ResetModuleSystemFromContext(context);
 }
 
-bool XWalkExtensionRendererController::InitializeExtensions(
-    const std::string& appid) {
-  return extensions_client_->Initialize(appid);
+void XWalkExtensionRendererController::InitializeExtensions() {
+  extensions_client_->Initialize();
 }
 
 }  // namespace extensions
index c8937e79c4285bebdba747461d48b0f3c1352c02..37f286362f343092233a39b4bcec8daa61693dd1 100644 (file)
@@ -21,7 +21,7 @@ class XWalkExtensionRendererController {
   void DidCreateScriptContext(v8::Handle<v8::Context> context);
   void WillReleaseScriptContext(v8::Handle<v8::Context> context);
 
-  bool InitializeExtensions(const std::string& appid);
+  void InitializeExtensions();
 
  private:
   XWalkExtensionRendererController();
index 176ab84e4d7fed3f4eba771ae1d3325e25fea55e..5cd44538ec7b33a32e7c059bbb9d172f030da3a7 100644 (file)
@@ -317,8 +317,6 @@ void XWalkModuleSystem::Initialize() {
   v8::Handle<v8::Function> require_native =
       require_native_template->GetFunction();
 
-
-
   MarkModulesWithTrampoline();
 
   auto it = extension_modules_.begin();
@@ -467,19 +465,29 @@ bool XWalkModuleSystem::ExtensionModuleEntry::IsPrefix(
 // will. So we'll only load code for "tizen" extension.
 void XWalkModuleSystem::MarkModulesWithTrampoline() {
   std::sort(extension_modules_.begin(), extension_modules_.end());
-
-  ExtensionModules::iterator it = extension_modules_.begin();
-  while (it != extension_modules_.end()) {
-    const std::string& n = (*it).name;
-    // Top level modules won't be mared with trampoline
-    if (std::find(n.begin(), n.end(), '.') != n.end()) {
+  {
+    ExtensionModules::iterator it = extension_modules_.begin();
+    while (it != extension_modules_.end()) {
       it = std::adjacent_find(it, extension_modules_.end(),
                               &ExtensionModuleEntry::IsPrefix);
       if (it == extension_modules_.end())
         break;
+      it->use_trampoline = false;
+      ++it;
+    }
+  }
+
+  // NOTE: Special Case for Security Reason
+  // xwalk module should not be trampolined even it does not have any children.
+  {
+    ExtensionModules::iterator it = extension_modules_.begin();
+    while (it != extension_modules_.end()) {
+      if ("xwalk" == (*it).name) {
+        it->use_trampoline = false;
+        break;
+      }
+      ++it;
     }
-    it->use_trampoline = false;
-    ++it;
   }
 }
 
index 5d13f343a6bd92d6da4bc5e9dd5ab4e4d74c51ab..c8ffe5c4fd7905413cceaf38180c0fc47398fadb 100644 (file)
@@ -95,9 +95,6 @@ cat LICENSE.BSD >> %{buildroot}%{_datadir}/license/%{name}
 # xwalk_common
 install -p -m 644 out/Default/lib/libxwalk_tizen_common.so %{buildroot}%{_libdir}
 
-# xwalk_extension
-install -p -m 755 out/Default/xwalk_extension %{buildroot}%{_bindir}
-
 # widget_plugin
 install -p -m 644 out/Default/lib/libwidget_plugin.so %{buildroot}%{extension_path}
 install -p -m 644 out/Default/gen/widget.json %{buildroot}%{extension_path}
@@ -133,6 +130,5 @@ rm -fr %{buildroot}
 %attr(644,root,root) %{extension_path}/widget.json
 %attr(644,root,root) %{extension_path}/libsplash_screen_plugin.so
 %attr(644,root,root) %{extension_path}/splash_screen.json
-%attr(755,root,root) %{_bindir}/xwalk_extension
 %attr(755,root,root) %{_bindir}/xwalk_runtime
 %attr(755,root,root) %{_bindir}/wrt
index 1701b635585765adac1437b2175e819534e57d18..5efc8802de63e5a96487faa2f992d0c5b1746183 100644 (file)
@@ -41,17 +41,6 @@ static NativeWindow* CreateNativeWindow() {
   return window;
 }
 
-static void ExecExtensionProcess(const std::string& appid) {
-  pid_t pid = -1;
-  if ((pid = fork()) < 0) {
-    LOGGER(ERROR) << "Failed to fork child process for extension process.";
-  }
-  if (pid == 0) {
-    execl(kExtensionExecPath,
-          kExtensionExecPath, appid.c_str(), NULL);
-  }
-}
-
 }  // namespace
 
 Runtime::Runtime()
@@ -89,9 +78,6 @@ bool Runtime::OnCreate() {
   appdb->Set(kAppDBRuntimeSection, kAppDBRuntimeAppID, appid);
   appdb->Remove(kAppDBRuntimeSection, kAppDBRuntimeBundle);
 
-  // Exec ExtensionProcess
-  ExecExtensionProcess(appid);
-
   // Init WebApplication
   native_window_ = CreateNativeWindow();
   STEP_PROFILE_START("WebApplication Create");
index d378403b604de87adcd35a5ac8998edaf66753c3..edde73635427832b421328bfd90c956424ce29d1 100644 (file)
@@ -19,7 +19,6 @@
 namespace runtime {
 
 const char kRuntimeExecName[] = "xwalk_runtime";
-const char kExtensionExecPath[] = "/usr/bin/xwalk_extension";
 
 const char kAppDBRuntimeSection[] = "Runtime";
 const char kAppDBRuntimeAppID[] = "app_id";
index 460d1fa9f1947997308d40b4fa94212f446103eb..72f6ac08cb704d46e0a7ccf568aee479a646b997 100644 (file)
@@ -20,7 +20,6 @@
 namespace runtime {
 
 extern const char kRuntimeExecName[];
-extern const char kExtensionExecPath[];
 
 extern const char kAppDBRuntimeSection[];
 extern const char kAppDBRuntimeAppID[];
index f2c8b0c2919b2ade2e4dac7c339961eb0ab101bc..d7f5da7b8cada267e1ad2459cf375b4e253ba90c 100755 (executable)
@@ -82,7 +82,7 @@ extern "C" void DynamicSetWidgetInfo(const char* tizen_id) {
   STEP_PROFILE_START("Initialize XWalkExtensionRendererController");
   extensions::XWalkExtensionRendererController& controller =
       extensions::XWalkExtensionRendererController::GetInstance();
-  controller.InitializeExtensions(tizen_id);
+  controller.InitializeExtensions();
   STEP_PROFILE_END("Initialize XWalkExtensionRendererController");
 }
 
index b8275291bb407ba8d2c9fafb8a1464dadf64aca6..b9b9e77df7457ce2ccc2375ececdd1c07e844bfd 100644 (file)
@@ -43,8 +43,8 @@
           'chromium-efl',
           'ecore',
           'ecore-wayland',
-          'efl-extension',
           'elementary',
+          'efl-extension',
           'deviced',
           'manifest-parser',
           'wgt-manifest-handlers',