extension_manager->GetRuntimeVariable(key, value, value_len);
}
+ static void* RuntimeGetWindowObject() {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ return extension_manager->GetWindowObject();
+ }
+
+ static void RuntimeAddWindowEventListener(XW_Instance instance,
+ WindowEvent event) {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ extension_manager->AddWindowEventListener(instance, event);
+ }
+
+ static void RuntimeRemoveWindowEventListener(XW_Instance instance) {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ extension_manager->RemoveWindowEventListener(instance);
+ }
+
+ static void RuntimeSendKeyEvent(const char* event, const char* key_code) {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ extension_manager->SendKeyEvent(event, key_code);
+ }
+
+ static void RuntimeSendMouseEvent(const char* event, int btn, int x, int y) {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ extension_manager->SendMouseEvent(event, btn, x, y);
+ }
+
+ static const char* RuntimeGetMetadataValue(const char* key) {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ auto value = extension_manager->GetMetadataValue(key);
+ return value.c_str();
+ }
+
static int PermissionsCheckAPIAccessControl(
XW_Extension xw_extension, const char* api_name) {
XWalkExtension* extension = GetExtension(xw_extension);
return &runtimeInterface1;
}
+ if (interface_name == XW_INTERNAL_WINDOW_INTERFACE) {
+ static const XW_Internal_WindowInterface window_interface = {
+ Interface::RuntimeGetWindowObject,
+ Interface::RuntimeAddWindowEventListener,
+ Interface::RuntimeRemoveWindowEventListener,
+ Interface::RuntimeSendKeyEvent,
+ Interface::RuntimeSendMouseEvent,
+ Interface::RuntimeGetMetadataValue
+ };
+ return &window_interface;
+ }
+
if (interface_name == XW_INTERNAL_PERMISSIONS_INTERFACE_1) {
static const XW_Internal_PermissionsInterface_1 permissionsInterface1 = {
Interface::PermissionsCheckAPIAccessControl,
delegate_->GetRuntimeVariable(key, value, value_len);
}
+void* XWalkExtensionManager::GetWindowObject() {
+ base::AutoLock lock(xmanager_instance_lock);
+ return delegate_? delegate_->GetWindowObject() : nullptr;
+}
+
+void XWalkExtensionManager::AddWindowEventListener(XW_Instance instance,
+ WindowEvent event) {
+ base::AutoLock lock(xmanager_instance_lock);
+ if (delegate_)
+ delegate_->AddWindowEventListener(instance, event);
+}
+
+void XWalkExtensionManager::RemoveWindowEventListener(XW_Instance instance) {
+ base::AutoLock lock(xmanager_instance_lock);
+ if (delegate_)
+ delegate_->RemoveWindowEventListener(instance);
+}
+
+void XWalkExtensionManager::NotifyWindowEvent(const std::string& event_name,
+ const std::string& event_value) {
+ LOG(INFO) << "event : " << event_name << ", value : " << event_value;
+ base::AutoLock lock(xmanager_instance_lock);
+ if (delegate_)
+ delegate_->NotifyWindowEvent(event_name, event_value);
+}
+
+void XWalkExtensionManager::SendKeyEvent(const std::string& event,
+ const std::string& key_code) {
+ LOG(INFO) << "event : " << event << ", key_code : " << key_code;
+ if (delegate_)
+ delegate_->SendKeyEvent(event, key_code);
+}
+
+void XWalkExtensionManager::SendMouseEvent(const std::string& event, int button,
+ int x, int y) {
+ LOG(INFO) << "event : " << event << ", x : " << x << ", y : " << y;
+ if (delegate_)
+ delegate_->SendMouseEvent(event, button, x, y);
+}
+
+std::string XWalkExtensionManager::GetMetadataValue(const std::string& key) {
+ base::AutoLock lock(xmanager_instance_lock);
+ return delegate_ ? delegate_->GetMetadataValue(key) : std::string();
+}
+
+bool XWalkExtensionManager::IsAliveInstance(XW_Instance instance) {
+ base::AutoLock lock(xmanager_instance_lock);
+ auto it = instances_.find(instance);
+ return it != instances_.end();
+}
+
std::string XWalkExtensionManager::GetUpgradableLibPath(
const std::string& name) {
return delegate_ ? delegate_->GetUpgradableLibPath(name) : std::string();
void UnregisterInstance(XWalkExtension::Instance* instance);
// product specific features
+ void* GetWindowObject();
+ void AddWindowEventListener(XW_Instance instance, WindowEvent event);
+ bool IsAliveInstance(XW_Instance instance);
+ void NotifyWindowEvent(const std::string& event_name,
+ const std::string& event_value);
+ void RemoveWindowEventListener(XW_Instance instance);
void RegisterUpgradableExtensions();
+ void SendKeyEvent(const std::string& event, const std::string& key_code);
+ void SendMouseEvent(const std::string& event, int button, int x, int y);
+ std::string GetMetadataValue(const std::string& name);
std::string GetUpgradableLibPath(const std::string& name);
protected:
#include <string>
+#include "tizen_src/chromium_impl/components/xwalk_extensions/public/XW_Extension.h"
+
namespace wrt {
+typedef void (*WindowEvent)(const char* event_name, const char* event_value);
+
class XWalkExtensionBrowserDelegate {
public:
XWalkExtensionBrowserDelegate() {}
// product specific functions
virtual void RegisterUpgradableExtensions() {}
+ virtual std::string GetMetadataValue(const std::string& key) {
+ return std::string();
+ }
virtual std::string GetUpgradableLibPath(const std::string& name) {
return std::string();
}
virtual bool NeedClearLibHandle() { return true; }
+ virtual void* GetWindowObject() { return nullptr; }
+ virtual void AddWindowEventListener(XW_Instance instance,
+ WindowEvent event) {}
+ virtual void RemoveWindowEventListener(XW_Instance instance) {}
+ virtual void NotifyWindowEvent(const std::string& event_name,
+ const std::string& event_value) {}
+ virtual void SendKeyEvent(const std::string& event,
+ const std::string& key_code) {}
+ virtual void SendMouseEvent(const std::string& event, int button,
+ int x, int y) {}
};
} // namespace wrt
typedef struct XW_Internal_RuntimeInterface_1
XW_Internal_RuntimeInterface;
+#define XW_INTERNAL_WINDOW_INTERFACE "XW_Internal_WindowInterface"
+
+typedef void (*WindowEvent)(const char* event_name, const char* event_value);
+typedef struct XW_Internal_WindowInterface_ {
+ void* (*GetWindowObject)(void);
+ void (*AddWindowEventListener)(XW_Instance instance, WindowEvent event);
+ void (*RemoveWindowEventListener)(XW_Instance instance);
+ void (*SendKeyEvent)(const char* event, const char* key_code);
+ void (*SendMouseEvent)(const char* event, int button, int x, int y);
+ const char* (*GetMetadataValue)(const char* key);
+} XW_Internal_WindowInterface;
+
#ifdef __cplusplus
} // extern "C"
#endif
#if !defined(WRT_JS_BRINGUP)
#include "tizen_src/chromium_impl/chrome/browser/net/proxy_config_monitor.h"
#endif
+#include "tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h"
#include "tizen_src/chromium_impl/tizen/vconf_handle.h"
#include "ui/ozone/platform/efl/efl_screen.h"
#include "ui/platform_window/platform_window.h"
else
VisibilityChangedAsBackground();
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ extension_manager->NotifyWindowEvent("visibility", visibility_state_);
+
#if defined(THREAD_BOOSTER_SERVICE)
if (visible)
suspend_resume::NotifyStateChange(suspend_resume::State::RESUMED);
}
LOG(INFO) << "degree : " << degree << " (" << screen_width << "x"
<< screen_height << ")";
+
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ extension_manager->NotifyWindowEvent("orientation", std::to_string(degree));
}
void WRTNativeWindowTV::ScreenSaverResetTimeout(void) {
#include "electron/shell/browser/browser.h"
#include "electron/shell/browser/window_list.h"
#include "tizen_src/chromium_impl/components/xwalk_extensions/browser/xwalk_extension_manager.h"
+#include "tizen_src/chromium_impl/ui/ozone/platform/efl/efl_event_handler.h"
#include "wrt/src/browser/native_web_runtime.h"
#include "wrt/src/browser/tv/input_device_manager.h"
#include "wrt/src/browser/tv/native_web_runtime_delegate_tv.h"
}
}
+void* WRTXWalkExtensionBrowserTV::GetWindowObject() {
+ return WRTNativeWindow::GetTopWindow();
+}
+
+void WRTXWalkExtensionBrowserTV::AddWindowEventListener(
+ XW_Instance instance, WindowEvent event_listener) {
+ event_listeners_[instance] = event_listener;
+}
+
+void WRTXWalkExtensionBrowserTV::RemoveWindowEventListener(
+ XW_Instance instance) {
+ event_listeners_.erase(instance);
+}
+
+void WRTXWalkExtensionBrowserTV::NotifyWindowEvent(
+ const std::string& event_name, const std::string& event_value) {
+ auto* extension_manager = XWalkExtensionManager::GetInstance();
+ std::vector<XW_Instance> dead_instances;
+ for (const auto& event : event_listeners_) {
+ auto instance_id = event.first;
+ if (extension_manager->IsAliveInstance(instance_id)) {
+ auto callback = event.second;
+ callback(event_name.c_str(), event_value.c_str());
+ } else {
+ dead_instances.push_back(instance_id);
+ }
+ }
+ for (const auto instance_id : dead_instances) {
+ RemoveWindowEventListener(instance_id);
+ }
+}
+
+void WRTXWalkExtensionBrowserTV::SendKeyEvent(const std::string& event,
+ const std::string& key_code) {
+ LOG(INFO) << "event : " << event << ", key_code : " << key_code;
+}
+
+void WRTXWalkExtensionBrowserTV::SendMouseEvent(const std::string& event,
+ int button, int x, int y) {
+ LOG(INFO) << "event : " << event;
+ auto event_handler = InputDeviceManager::GetInstance()->GetEventHandler();
+ if (event == "mount-in") {
+ event_handler->SendMouseIn();
+ } else if (event == "mouse-out") {
+ event_handler->SendMouseOut();
+ } else if (event == "mouse-down") {
+ event_handler->SendMouseDown(button, x, y);
+ } else if (event == "mouse-up") {
+ event_handler->SendMouseUp(button, x, y);
+ } else if (event == "mouse-move") {
+ event_handler->SendMouseMove(x, y);
+ } else {
+ LOG(INFO) << "Unsupported mouse event";
+ }
+}
+
+std::string WRTXWalkExtensionBrowserTV::GetMetadataValue(
+ const std::string& key) {
+ return ApplicationData::GetInstance().GetMetadata(key);
+}
+
} // namespace wrt
private:
// XWalkExtensionBrowserDelegate
+ void* GetWindowObject() override;
void LoadUIAppExtensions() override;
void PreloadExtensions() override;
void RegisterUpgradableExtensions() override;
+ void AddWindowEventListener(XW_Instance instance,
+ WindowEvent event_listener) override;
+ void RemoveWindowEventListener(XW_Instance instance) override;
+ void NotifyWindowEvent(const std::string& event_name,
+ const std::string& event_value) override;
+ void SendKeyEvent(const std::string& event,
+ const std::string& key_code) override;
+ void SendMouseEvent(const std::string& event, int button,
+ int x, int y) override;
+ std::string GetMetadataValue(const std::string& key) override;
std::string GetUpgradableLibPath(const std::string& name) override;
std::string HandleRuntimeMessageInternal(
const std::string& type, const std::string& value) override;
void* tizen_common_dlhandle_ = nullptr;
bool is_ui_app_ = false;
std::map<std::string, std::string> lazyload_extensions_;
+ std::map<XW_Extension, WindowEvent> event_listeners_;
};
} // namespace wrt