From 19e59e9ec460ee5ae83daf2fc4cc9548fd6077a5 Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Fri, 5 Feb 2016 09:28:22 +0900 Subject: [PATCH] Move extension loader to the renderer process Remove the xwalk-extension process and load extensions in the renderer process. --- .../{extension => common}/xwalk_extension.cc | 11 +- extensions/{extension => common}/xwalk_extension.h | 22 +- .../xwalk_extension_adapter.cc | 2 +- .../xwalk_extension_adapter.h | 4 +- .../xwalk_extension_instance.cc | 4 +- .../xwalk_extension_instance.h | 0 extensions/common/xwalk_extension_manager.cc | 188 ++++++++ extensions/common/xwalk_extension_manager.h | 42 ++ extensions/extension/xwalk_extension_process.cc | 51 --- extensions/extension/xwalk_extension_server.cc | 472 --------------------- extensions/extension/xwalk_extension_server.h | 82 ---- extensions/extensions.gyp | 41 +- extensions/renderer/xwalk_extension_client.cc | 218 ++++------ extensions/renderer/xwalk_extension_client.h | 30 +- extensions/renderer/xwalk_extension_module.cc | 28 +- extensions/renderer/xwalk_extension_module.h | 4 +- .../xwalk_extension_renderer_controller.cc | 19 +- .../renderer/xwalk_extension_renderer_controller.h | 2 +- extensions/renderer/xwalk_module_system.cc | 28 +- packaging/crosswalk-tizen.spec | 4 - runtime/browser/runtime.cc | 14 - runtime/common/constants.cc | 1 - runtime/common/constants.h | 1 - runtime/renderer/injected_bundle.cc | 2 +- runtime/runtime.gyp | 2 +- 25 files changed, 384 insertions(+), 888 deletions(-) rename extensions/{extension => common}/xwalk_extension.cc (94%) rename extensions/{extension => common}/xwalk_extension.h (81%) rename extensions/{extension => common}/xwalk_extension_adapter.cc (99%) rename extensions/{extension => common}/xwalk_extension_adapter.h (96%) rename extensions/{extension => common}/xwalk_extension_instance.cc (94%) rename extensions/{extension => common}/xwalk_extension_instance.h (100%) create mode 100644 extensions/common/xwalk_extension_manager.cc create mode 100644 extensions/common/xwalk_extension_manager.h delete mode 100644 extensions/extension/xwalk_extension_process.cc delete mode 100644 extensions/extension/xwalk_extension_server.cc delete mode 100644 extensions/extension/xwalk_extension_server.h diff --git a/extensions/extension/xwalk_extension.cc b/extensions/common/xwalk_extension.cc similarity index 94% rename from extensions/extension/xwalk_extension.cc rename to extensions/common/xwalk_extension.cc index 43c2279..0110bb2 100644 --- a/extensions/extension/xwalk_extension.cc +++ b/extensions/common/xwalk_extension.cc @@ -3,13 +3,13 @@ // 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 "extensions/common/xwalk_extension.h" #include #include #include "common/logger.h" -#include "extensions/extension/xwalk_extension_adapter.h" +#include "extensions/common/xwalk_extension_adapter.h" #include "extensions/public/XW_Extension.h" namespace extensions { @@ -19,7 +19,6 @@ XWalkExtension::XWalkExtension(const std::string& path, : initialized_(false), library_path_(path), xw_extension_(0), - use_trampoline_(true), lazy_loading_(false), delegate_(delegate), created_instance_callback_(NULL), @@ -38,7 +37,6 @@ XWalkExtension::XWalkExtension(const std::string& path, xw_extension_(0), name_(name), entry_points_(entry_points), - use_trampoline_(true), lazy_loading_(true), delegate_(delegate), created_instance_callback_(NULL), @@ -100,6 +98,11 @@ XWalkExtensionInstance* XWalkExtension::CreateInstance() { 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_) { diff --git a/extensions/extension/xwalk_extension.h b/extensions/common/xwalk_extension.h similarity index 81% rename from extensions/extension/xwalk_extension.h rename to extensions/common/xwalk_extension.h index b5abe3c..85af14c 100644 --- a/extensions/extension/xwalk_extension.h +++ b/extensions/common/xwalk_extension.h @@ -9,7 +9,7 @@ #include #include -#include "extensions/extension/xwalk_extension_instance.h" +#include "extensions/common/xwalk_extension_instance.h" #include "extensions/public/XW_Extension.h" #include "extensions/public/XW_Extension_SyncMessage.h" @@ -37,35 +37,18 @@ class XWalkExtension { bool Initialize(); XWalkExtensionInstance* CreateInstance(); + std::string GetJavascriptCode(); 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; @@ -81,7 +64,6 @@ class XWalkExtension { std::string name_; std::string javascript_api_; StringVector entry_points_; - bool use_trampoline_; bool lazy_loading_; XWalkExtensionDelegate* delegate_; diff --git a/extensions/extension/xwalk_extension_adapter.cc b/extensions/common/xwalk_extension_adapter.cc similarity index 99% rename from extensions/extension/xwalk_extension_adapter.cc rename to extensions/common/xwalk_extension_adapter.cc index 0303b03..391a130 100644 --- a/extensions/extension/xwalk_extension_adapter.cc +++ b/extensions/common/xwalk_extension_adapter.cc @@ -3,7 +3,7 @@ // 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 "extensions/common/xwalk_extension_adapter.h" #include diff --git a/extensions/extension/xwalk_extension_adapter.h b/extensions/common/xwalk_extension_adapter.h similarity index 96% rename from extensions/extension/xwalk_extension_adapter.h rename to extensions/common/xwalk_extension_adapter.h index 776d003..3c350d1 100644 --- a/extensions/extension/xwalk_extension_adapter.h +++ b/extensions/common/xwalk_extension_adapter.h @@ -8,8 +8,8 @@ #include -#include "extensions/extension/xwalk_extension.h" -#include "extensions/extension/xwalk_extension_instance.h" +#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" diff --git a/extensions/extension/xwalk_extension_instance.cc b/extensions/common/xwalk_extension_instance.cc similarity index 94% rename from extensions/extension/xwalk_extension_instance.cc rename to extensions/common/xwalk_extension_instance.cc index 834be77..c86bb59 100644 --- a/extensions/extension/xwalk_extension_instance.cc +++ b/extensions/common/xwalk_extension_instance.cc @@ -3,9 +3,9 @@ // 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/common/xwalk_extension_instance.h" -#include "extensions/extension/xwalk_extension_adapter.h" +#include "extensions/common/xwalk_extension_adapter.h" #include "extensions/public/XW_Extension_SyncMessage.h" namespace extensions { diff --git a/extensions/extension/xwalk_extension_instance.h b/extensions/common/xwalk_extension_instance.h similarity index 100% rename from extensions/extension/xwalk_extension_instance.h rename to extensions/common/xwalk_extension_instance.h diff --git a/extensions/common/xwalk_extension_manager.cc b/extensions/common/xwalk_extension_manager.cc new file mode 100644 index 0000000..87817d2 --- /dev/null +++ b/extensions/common/xwalk_extension_manager.cc @@ -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 + +#include +#include +#include +#include + +#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()) { + auto& plugins = metadata.get(); + for (auto plugin = plugins.begin(); plugin != plugins.end(); ++plugin) { + if (!plugin->is()) + 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 entries; + auto& entry_points_value = plugin->get("entry_points"); + if (entry_points_value.is()) { + auto& entry_points = entry_points_value.get(); + 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 index 0000000..8a0cd78 --- /dev/null +++ b/extensions/common/xwalk_extension_manager.h @@ -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 +#include +#include + +#include "extensions/common/xwalk_extension.h" + +namespace extensions { + +class XWalkExtensionManager : public XWalkExtension::XWalkExtensionDelegate { + public: + typedef std::set StringSet; + typedef std::map 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_process.cc b/extensions/extension/xwalk_extension_process.cc deleted file mode 100644 index edbcccc..0000000 --- a/extensions/extension/xwalk_extension_process.cc +++ /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 - -#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 index 075110d..0000000 --- a/extensions/extension/xwalk_extension_server.cc +++ /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 -#include - -#include -#include -#include - -#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[] = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - -void LoadFrequentlyUsedModules( - const std::map& 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()) { - auto& plugins = metadata.get(); - for (auto plugin = plugins.begin(); plugin != plugins.end(); ++plugin) { - if (!plugin->is()) - 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 entries; - auto& entry_points_value = plugin->get("entry_points"); - if (entry_points_value.is()) { - auto& entry_points = entry_points_value.get(); - 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 index 854e534..0000000 --- a/extensions/extension/xwalk_extension_server.h +++ /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 -#include -#include -#include - -#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 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 StringSet; - StringSet extension_symbols_; - - typedef std::map ExtensionMap; - ExtensionMap extensions_; - - typedef std::map InstanceMap; - InstanceMap instances_; -}; - -} // namespace extensions - -#endif // XWALK_EXTENSIONS_XWALK_EXTENSION_SERVER_H_ diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 871cd6e..0f95748 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -4,39 +4,6 @@ ], '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', 'dependencies': [ @@ -45,6 +12,14 @@ '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', diff --git a/extensions/renderer/xwalk_extension_client.cc b/extensions/renderer/xwalk_extension_client.cc index f14e38d..8423d03 100644 --- a/extensions/renderer/xwalk_extension_client.cc +++ b/extensions/renderer/xwalk_extension_client.cc @@ -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 diff --git a/extensions/renderer/xwalk_extension_client.h b/extensions/renderer/xwalk_extension_client.h index bba39ef..9d46444 100644 --- a/extensions/renderer/xwalk_extension_client.h +++ b/extensions/renderer/xwalk_extension_client.h @@ -11,12 +11,17 @@ #include #include -#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 ExtensionMap; + typedef std::map 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 entry_points; - }; - - typedef std::map 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 handlers_; - common::DBusClient dbus_extension_client_; + XWalkExtensionManager manager_; + InstanceMap instances_; }; } // namespace extensions diff --git a/extensions/renderer/xwalk_extension_module.cc b/extensions/renderer/xwalk_extension_module.cc index 82e22c1..232fb7d 100644 --- a/extensions/renderer/xwalk_extension_module.cc +++ b/extensions/renderer/xwalk_extension_module.cc @@ -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 function_data = v8::Object::New(isolate); @@ -270,12 +268,22 @@ v8::Handle RunString(const std::string& code, void XWalkExtensionModule::LoadExtensionCode( v8::Handle context, v8::Handle 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 result = RunString(wrapped_api_code, &exception); if (!result->IsFunction()) { diff --git a/extensions/renderer/xwalk_extension_module.h b/extensions/renderer/xwalk_extension_module.h index 1076f0f..eea3d01 100644 --- a/extensions/renderer/xwalk_extension_module.h +++ b/extensions/renderer/xwalk_extension_module.h @@ -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, and @@ -72,7 +71,6 @@ class XWalkExtensionModule : public XWalkExtensionClient::InstanceHandler { v8::Persistent message_listener_; std::string extension_name_; - std::string extension_code_; XWalkExtensionClient* client_; XWalkModuleSystem* module_system_; diff --git a/extensions/renderer/xwalk_extension_renderer_controller.cc b/extensions/renderer/xwalk_extension_renderer_controller.cc index 1e6395d..71230a4 100644 --- a/extensions/renderer/xwalk_extension_renderer_controller.cc +++ b/extensions/renderer/xwalk_extension_renderer_controller.cc @@ -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 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 diff --git a/extensions/renderer/xwalk_extension_renderer_controller.h b/extensions/renderer/xwalk_extension_renderer_controller.h index c8937e7..37f2863 100644 --- a/extensions/renderer/xwalk_extension_renderer_controller.h +++ b/extensions/renderer/xwalk_extension_renderer_controller.h @@ -21,7 +21,7 @@ class XWalkExtensionRendererController { void DidCreateScriptContext(v8::Handle context); void WillReleaseScriptContext(v8::Handle context); - bool InitializeExtensions(const std::string& appid); + void InitializeExtensions(); private: XWalkExtensionRendererController(); diff --git a/extensions/renderer/xwalk_module_system.cc b/extensions/renderer/xwalk_module_system.cc index 176ab84..5cd4453 100644 --- a/extensions/renderer/xwalk_module_system.cc +++ b/extensions/renderer/xwalk_module_system.cc @@ -317,8 +317,6 @@ void XWalkModuleSystem::Initialize() { v8::Handle 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; } } diff --git a/packaging/crosswalk-tizen.spec b/packaging/crosswalk-tizen.spec index 5d13f34..c8ffe5c 100644 --- a/packaging/crosswalk-tizen.spec +++ b/packaging/crosswalk-tizen.spec @@ -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 diff --git a/runtime/browser/runtime.cc b/runtime/browser/runtime.cc index 1701b63..5efc880 100644 --- a/runtime/browser/runtime.cc +++ b/runtime/browser/runtime.cc @@ -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"); diff --git a/runtime/common/constants.cc b/runtime/common/constants.cc index d378403..edde736 100644 --- a/runtime/common/constants.cc +++ b/runtime/common/constants.cc @@ -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"; diff --git a/runtime/common/constants.h b/runtime/common/constants.h index 460d1fa..72f6ac0 100644 --- a/runtime/common/constants.h +++ b/runtime/common/constants.h @@ -20,7 +20,6 @@ namespace runtime { extern const char kRuntimeExecName[]; -extern const char kExtensionExecPath[]; extern const char kAppDBRuntimeSection[]; extern const char kAppDBRuntimeAppID[]; diff --git a/runtime/renderer/injected_bundle.cc b/runtime/renderer/injected_bundle.cc index f2c8b0c..d7f5da7 100755 --- a/runtime/renderer/injected_bundle.cc +++ b/runtime/renderer/injected_bundle.cc @@ -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"); } diff --git a/runtime/runtime.gyp b/runtime/runtime.gyp index b827529..b9b9e77 100644 --- a/runtime/runtime.gyp +++ b/runtime/runtime.gyp @@ -43,8 +43,8 @@ 'chromium-efl', 'ecore', 'ecore-wayland', - 'efl-extension', 'elementary', + 'efl-extension', 'deviced', 'manifest-parser', 'wgt-manifest-handlers', -- 2.7.4