From b66b36d45eae4a50f294efe0d2a64096cc7000af Mon Sep 17 00:00:00 2001 From: Jihoon Chung Date: Sat, 22 Jun 2013 21:04:20 +0900 Subject: [PATCH] [Release] wrt-plugins-common_0.3.97 Change-Id: I400493767ab501170626cc1845046e888d6746e4 --- packaging/wrt-plugins-common.spec | 2 +- src/dispatch-event/dispatch_event_support.cpp | 38 ++++++++----- src/dispatch-event/dispatch_event_support.h | 7 ++- src/plugins-ipc-message/ipc_message_support.cpp | 71 ++++++++++++++++++------- src/standards/W3C/Widget/JSPreferences.cpp | 20 +++---- 5 files changed, 90 insertions(+), 48 deletions(-) diff --git a/packaging/wrt-plugins-common.spec b/packaging/wrt-plugins-common.spec index d1b93dc..22337b5 100644 --- a/packaging/wrt-plugins-common.spec +++ b/packaging/wrt-plugins-common.spec @@ -1,7 +1,7 @@ #git:framework/web/wrt-plugins-common Name: wrt-plugins-common Summary: wrt-plugins common library -Version: 0.3.95 +Version: 0.3.97 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 diff --git a/src/dispatch-event/dispatch_event_support.cpp b/src/dispatch-event/dispatch_event_support.cpp index 24c9f84..d9b4d2b 100644 --- a/src/dispatch-event/dispatch_event_support.cpp +++ b/src/dispatch-event/dispatch_event_support.cpp @@ -113,24 +113,38 @@ void dispatchSoftKeyboardChangeEvent(JSContextRef context, const std::string sta } } -void dispatchStorageEvent(JSContextRef context, const std::string key, const std::string oldValue, const std::string newValue, const std::string url) +void dispatchStorageEvent(JSContextRef context, + const DPL::Optional& key, + const DPL::Optional& oldValue, + const DPL::Optional& newValue, + const std::string& url) { - LogDebug("dispatchStorageEvent(" << context << ", " << key << ", " << oldValue << ", " << newValue << ", " << url << ")"); + LogDebug("dispatchStorageEvent(" << + context << ", " << + (key.IsNull() ? "null" : *key) << ", " << + (oldValue.IsNull() ? "null" : *oldValue) << ", " << + (newValue.IsNull() ? "null" : *newValue) << ", " << + url << ")"); if (context != NULL) { std::stringstream script; - script << "var __event = document.createEvent(\"CustomEvent\");\n" - << "__event.initCustomEvent(\"storage\", true, true);\n" - << "__event.key = \"" << key << "\";\n" - << "__event.oldValue = \"" << oldValue << "\";\n" - << "__event.newValue = \"" << newValue << "\";\n" - << "__event.url = \"" << url << "\";\n" - << "__event.storageArea = widget.preferences;\n" - << "document.dispatchEvent(__event);\n" - << "\n" - << "for (var i=0; i < window.frames.length; i++)\n" + auto toJSValue = + [](const DPL::Optional& value) -> std::string + { + return (value.IsNull() ? "null" : "\"" + *value + "\""); + }; + + script << "var __event = document.createEvent(\"CustomEvent\");" + << "__event.initCustomEvent(\"storage\", true, true);" + << "__event.key = " << toJSValue(key) << ";" + << "__event.oldValue = " << toJSValue(oldValue) << ";" + << "__event.newValue = " << toJSValue(newValue) << ";" + << "__event.url = \"" << url << "\";" + << "__event.storageArea = widget.preferences;" + << "document.dispatchEvent(__event);" + << "for (var i=0; i < window.frames.length; i++)" << "{ window.frames[i].document.dispatchEvent(__event); }"; diff --git a/src/dispatch-event/dispatch_event_support.h b/src/dispatch-event/dispatch_event_support.h index df74b4b..8a42e20 100644 --- a/src/dispatch-event/dispatch_event_support.h +++ b/src/dispatch-event/dispatch_event_support.h @@ -25,6 +25,7 @@ #define _DISPATCH_EVENT_SUPPORT_H_ #include +#include #include #include #include @@ -33,7 +34,11 @@ namespace DispatchEventSupport { void dispatchAppServiceEvent(JSContextRef context, const float scale, const std::string bundle); void dispatchSoftKeyboardChangeEvent(JSContextRef context, const std::string state, const int width, const int height); -void dispatchStorageEvent(JSContextRef context, const std::string key, const std::string oldValue, const std::string newValue, const std::string url); +void dispatchStorageEvent(JSContextRef context, + const DPL::Optional& key, + const DPL::Optional& oldValue, + const DPL::Optional& newValue, + const std::string& url); void dispatchHwKeyEvent(Evas_Object* ewkView, const std::string key); } #endif //_DISPATCH_EVENT_SUPPORT_H_ diff --git a/src/plugins-ipc-message/ipc_message_support.cpp b/src/plugins-ipc-message/ipc_message_support.cpp index fa36f8d..5d2f290 100644 --- a/src/plugins-ipc-message/ipc_message_support.cpp +++ b/src/plugins-ipc-message/ipc_message_support.cpp @@ -33,6 +33,9 @@ static WKBundleRef s_injectedBundleRef = NULL; static unsigned int s_xWindowHandle = 0; namespace { +const char* const TIZEN_GET_WINDOW_HANDLE = "tizen://getWindowHandle"; +const char* const TIZEN_CLEAR_ALL_COOKIES = "tizen://clearAllCookies"; + std::string toString(WKStringRef str) { if (WKStringIsEmpty(str)) { @@ -43,6 +46,48 @@ std::string toString(WKStringRef str) WKStringGetUTF8CString(str, buffer, size + 1); return buffer; } + +std::string sendSyncMessage(const char* name, const char* body) +{ + WKStringRef nameWKString = WKStringCreateWithUTF8CString(name); + WKStringRef bodyWKString = NULL; + if (body) { + bodyWKString = WKStringCreateWithUTF8CString(body); + } + WKTypeRef retWKType = NULL; + WKBundlePostSynchronousMessage(s_injectedBundleRef, + nameWKString, + bodyWKString, + &retWKType); + WKRelease(nameWKString); + if (bodyWKString) { + WKRelease(bodyWKString); + } + if (retWKType) { + std::string retString = toString(static_cast(retWKType)); + WKRelease(retWKType); + return retString; + } else { + return std::string(); + } +} + +void sendAsyncMessage(const char* name, const char* body) +{ + WKStringRef nameWKString = WKStringCreateWithUTF8CString(name); + WKStringRef bodyWKString = NULL; + if (body) { + bodyWKString = WKStringCreateWithUTF8CString(body); + } + WKTypeRef retWKType = NULL; + WKBundlePostMessage(s_injectedBundleRef, + nameWKString, + bodyWKString); + WKRelease(nameWKString); + if (bodyWKString) { + WKRelease(bodyWKString); + } +} } void IPCMessageSupport::setWKBundleRef(WKBundleRef bundleRef) @@ -75,7 +120,8 @@ const char* IPCMessageSupport::sendMessageToUiProcess( return NULL; } - if (!strcmp(name, "tizen://getWindowHandle")) { + // tizen://getWindowHandle + if (!strcmp(name, TIZEN_GET_WINDOW_HANDLE)) { if (s_xWindowHandle == 0) { return NULL; } else { @@ -86,26 +132,11 @@ const char* IPCMessageSupport::sendMessageToUiProcess( } } - WKStringRef bodyWKString = NULL; - WKStringRef nameWKString = WKStringCreateWithUTF8CString(name); - if (body) { - bodyWKString = WKStringCreateWithUTF8CString(body); - } - WKTypeRef retWKType = NULL; - WKBundlePostSynchronousMessage(s_injectedBundleRef, - nameWKString, - bodyWKString, - &retWKType); - WKRelease(nameWKString); - if (bodyWKString) { - WKRelease(bodyWKString); - } - if (retWKType) { - std::string retString = toString(static_cast(retWKType)); - WKRelease(retWKType); - return strdup(retString.c_str()); - } else { + // tizen://clearAllCookies + if (!strcmp(name, TIZEN_CLEAR_ALL_COOKIES)) { + sendAsyncMessage(name, body); return NULL; } + return NULL; } diff --git a/src/standards/W3C/Widget/JSPreferences.cpp b/src/standards/W3C/Widget/JSPreferences.cpp index 1f6326f..d3ba880 100644 --- a/src/standards/W3C/Widget/JSPreferences.cpp +++ b/src/standards/W3C/Widget/JSPreferences.cpp @@ -263,13 +263,8 @@ JSValueRef JSPreferences::removeItem(JSContextRef context, DPL::Optional newValue = getIStorage(thisObject)->getValue(key); JSContextRef g_context = JSContextGetGlobalContext(context); - std::string oldValueStr = ""; - std::string newValueStr = ""; - if (!!oldValue) { oldValueStr = *oldValue; } - if (!!newValue) { newValueStr = *newValue; } - - DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, ""); + DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValue, newValue, ""); LogDebug("end"); return JSValueMakeNull(context); @@ -303,13 +298,8 @@ JSValueRef JSPreferences::setItem(JSContextRef context, DPL::Optional newValue = getIStorage(thisObject)->getValue(key); JSContextRef g_context = JSContextGetGlobalContext(context); - std::string oldValueStr = ""; - std::string newValueStr = ""; - if (!!oldValue) { oldValueStr = *oldValue; } - if (!!newValue) { newValueStr = *newValue; } - - DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, ""); + DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValue, newValue, ""); LogDebug("end"); @@ -337,7 +327,9 @@ JSValueRef JSPreferences::clear(JSContextRef context, JSContextRef g_context = JSContextGetGlobalContext(context); - DispatchEventSupport::dispatchStorageEvent(g_context, "", "", "", ""); + const auto& null = DPL::Optional::Null; + + DispatchEventSupport::dispatchStorageEvent(g_context, null, null, null, ""); LogDebug("end"); @@ -523,7 +515,7 @@ bool JSPreferences::setProperty(JSContextRef context, if (!!oldValue) { oldValueStr = *oldValue; } if (!!newValue) { newValueStr = *newValue; } - + DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, ""); LogDebug("end"); -- 2.7.4