destroyed_instance_callback_(NULL),
shutdown_callback_(NULL),
handle_msg_callback_(NULL),
- handle_sync_msg_callback_(NULL) {
+ handle_sync_msg_callback_(NULL),
+ handle_binary_msg_callback_(NULL) {
}
XWalkExtension::XWalkExtension(const std::string& path,
destroyed_instance_callback_(NULL),
shutdown_callback_(NULL),
handle_msg_callback_(NULL),
- handle_sync_msg_callback_(NULL) {
+ handle_sync_msg_callback_(NULL),
+ handle_binary_msg_callback_(NULL) {
}
XWalkExtension::~XWalkExtension() {
#include "extensions/common/xwalk_extension_instance.h"
#include "extensions/public/XW_Extension.h"
#include "extensions/public/XW_Extension_SyncMessage.h"
+#include "extensions/public/XW_Extension_Message_2.h"
namespace extensions {
XW_ShutdownCallback shutdown_callback_;
XW_HandleMessageCallback handle_msg_callback_;
XW_HandleSyncMessageCallback handle_sync_msg_callback_;
+ XW_HandleBinaryMessageCallback handle_binary_msg_callback_;
};
} // namespace extensions
return &messagingInterface1;
}
+ if (!strcmp(name, XW_MESSAGING_INTERFACE_2)) {
+ static const XW_MessagingInterface_2 messagingInterface2 = {
+ MessagingRegister,
+ MessagingPostMessage,
+ MessagingRegisterBinaryMessageCallback,
+ MessagingPostBinaryMessage
+ };
+ return &messagingInterface2;
+ }
+
if (!strcmp(name, XW_INTERNAL_SYNC_MESSAGING_INTERFACE_1)) {
static const XW_Internal_SyncMessagingInterface_1
syncMessagingInterface1 = {
return XW_ERROR;
}
+void XWalkExtensionAdapter::MessagingRegisterBinaryMessageCallback(
+ XW_Extension xw_extension, XW_HandleBinaryMessageCallback handle_message) {
+ XWalkExtension* extension = GetExtension(xw_extension);
+ CHECK(extension, xw_extension);
+ RETURN_IF_INITIALIZED(extension);
+ extension->handle_binary_msg_callback_ = handle_message;
+}
+
+void XWalkExtensionAdapter::MessagingPostBinaryMessage(
+ XW_Instance xw_instance, const char* message, size_t size) {
+ XWalkExtensionInstance* instance = GetExtensionInstance(xw_instance);
+ CHECK(instance, xw_instance);
+ instance->PostMessageToJS(message);
+}
+
#undef CHECK
#undef RETURN_IF_INITIALIZED
#include "extensions/public/XW_Extension_Permissions.h"
#include "extensions/public/XW_Extension_Runtime.h"
#include "extensions/public/XW_Extension_SyncMessage.h"
+#include "extensions/public/XW_Extension_Message_2.h"
namespace extensions {
XW_Extension xw_extension, const char* api_name);
static int PermissionsRegisterPermissions(
XW_Extension xw_extension, const char* perm_table);
+ static void MessagingRegisterBinaryMessageCallback(
+ XW_Extension xw_extension, XW_HandleBinaryMessageCallback handle_message);
+ static void MessagingPostBinaryMessage(
+ XW_Instance xw_instance, const char* message, size_t size);
ExtensionMap extension_map_;
InstanceMap instance_map_;
#include <glob.h>
#include <dlfcn.h>
+#include <sys/utsname.h>
#include <fstream>
#include <set>
NULL
};
+const char kUserPluginsDirectory[] = "plugin/";
+const char kArchArmv7l[] = "armv7l";
+const char kArchI586[] = "i586";
+const char kArchDefault[] = "default";
+
} // namespace
XWalkExtensionManager::XWalkExtensionManager() {
}
}
+void XWalkExtensionManager::LoadUserExtensions(const std::string app_path) {
+ if (app_path.empty()) {
+ LOGGER(ERROR) << "Failed to get package root path";
+ return;
+ }
+ LOGGER(DEBUG) << "app path is : " <<app_path;
+ std::string app_ext_pattern(app_path);
+ app_ext_pattern.append(kUserPluginsDirectory);
+ struct utsname u;
+ if (0 == uname(&u)) {
+ std::string machine = u.machine;
+ if (!machine.empty()) {
+ if (machine == kArchArmv7l) {
+ app_ext_pattern.append(kArchArmv7l);
+ } else if (machine == kArchI586) {
+ app_ext_pattern.append(kArchI586);
+ } else {
+ app_ext_pattern.append(kArchDefault);
+ }
+ } else {
+ LOGGER(ERROR) << "cannot get machine info";
+ app_ext_pattern.append(kArchDefault);
+ }
+ app_ext_pattern.append("/");
+ }
+ app_ext_pattern.append("*");
+ app_ext_pattern.append(kExtensionSuffix);
+
+ LOGGER(DEBUG) << "plugins directory : " << app_ext_pattern;
+ StringSet files;
+ {
+ glob_t glob_result;
+ glob(app_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]);
+ }
+ }
+ for (auto it = files.begin(); it != files.end(); ++it) {
+ XWalkExtension* ext = new XWalkExtension(*it, this);
+ RegisterExtension(ext);
+ }
+ LOGGER(DEBUG) << "finish load user extension plugins";
+}
+
void XWalkExtensionManager::UnloadExtensions() {
for (auto it = extensions_.begin(); it != extensions_.end(); ++it) {
delete it->second;
ExtensionMap extensions() const { return extensions_; }
void LoadExtensions(bool meta_only = true);
+ void LoadUserExtensions(const std::string app_path);
void PreloadExtensions();
void UnloadExtensions();
eina_stringshare_del(extension_name);
}
+void XWalkExtensionServer::LoadUserExtensions(const std::string app_path) {
+ manager_.LoadUserExtensions(app_path);
+}
} // namespace extensions
void HandleIPCMessage(Ewk_IPC_Wrt_Message_Data* data);
void Shutdown();
+ void LoadUserExtensions(const std::string app_path);
private:
XWalkExtensionServer();
--- /dev/null
+// Copyright (c) 2015 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef XWALK_EXTENSIONS_PUBLIC_XW_EXTENSION_MESSAGE_2_H_
+#define XWALK_EXTENSIONS_PUBLIC_XW_EXTENSION_MESSAGE_2_H_
+
+#ifndef XWALK_EXTENSIONS_PUBLIC_XW_EXTENSION_H_
+#error "You should include XW_Extension.h before this file"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define XW_MESSAGING_INTERFACE_2 "XW_MessagingInterface_2"
+
+typedef void (*XW_HandleBinaryMessageCallback)(XW_Instance instance,
+ const char* message,
+ const size_t size);
+
+struct XW_MessagingInterface_2 {
+ // Register a callback to be called when the JavaScript code associated
+ // with the extension posts a message. Note that the callback will be called
+ // with the XW_Instance that posted the message as well as the message
+ // contents.
+ void (*Register)(XW_Extension extension,
+ XW_HandleMessageCallback handle_message);
+
+ // Post a message to the web content associated with the instance. To
+ // receive this message the extension's JavaScript code should set a
+ // listener using extension.setMessageListener() function.
+ //
+ // This function is thread-safe and can be called until the instance is
+ // destroyed.
+ void (*PostMessage)(XW_Instance instance, const char* message);
+
+ // Register a callback to be called when the JavaScript code associated
+ // with the extension posts a binary message (ArrayBuffer object).
+ // Note that the callback will be called with the XW_Instance that posted
+ // the message as well as the message contents.
+ void (*RegisterBinaryMesssageCallback)(
+ XW_Extension extension,
+ XW_HandleBinaryMessageCallback handle_message);
+
+ // Post a binary message to the web content associated with the instance. To
+ // receive this message the extension's JavaScript code should set a
+ // listener using extension.setMessageListener() function.
+ // The JavaScript message listener function would receive the binary message
+ // in an ArrayBuffer object.
+ //
+ // This function is thread-safe and can be called until the instance is
+ // destroyed.
+ void (*PostBinaryMessage)(XW_Instance instance,
+ const char* message, size_t size);
+};
+
+typedef struct XW_MessagingInterface_2 XW_MessagingInterface2;
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // XWALK_EXTENSIONS_PUBLIC_XW_EXTENSION_MESSAGE_2_H_
it->second->HandleMessageFromNative(msg);
}
+void XWalkExtensionClient::LoadUserExtensions(const std::string app_path) {
+ XWalkExtensionServer* server = XWalkExtensionServer::GetInstance();
+ server->LoadUserExtensions(app_path);
+}
} // namespace extensions
void OnReceivedIPCMessage(const std::string& instance_id,
const std::string& msg);
+ void LoadUserExtensions(const std::string app_path);
struct ExtensionCodePoints {
std::string api;
void XWalkExtensionRendererController::InitializeExtensionClient() {
extensions_client_->Initialize();
}
+void XWalkExtensionRendererController::LoadUserExtensions(
+ const std::string app_path) {
+ extensions_client_->LoadUserExtensions(app_path);
+}
} // namespace extensions
void OnReceivedIPCMessage(const Ewk_IPC_Wrt_Message_Data* data);
void InitializeExtensionClient();
+ void LoadUserExtensions(const std::string app_path);
private:
XWalkExtensionRendererController();
ecore_init();
runtime::BundleGlobalData::GetInstance()->Initialize(tizen_id);
+ extensions::XWalkExtensionRendererController& controller =
+ extensions::XWalkExtensionRendererController::GetInstance();
+ auto appdata_manager = common::ApplicationDataManager::GetInstance();
+ common::ApplicationData* app_data =
+ appdata_manager->GetApplicationData(tizen_id);
+ controller.LoadUserExtensions(app_data->application_path());
}
extern "C" void DynamicPluginStartSession(const char* tizen_id,