#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
}
}
-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<std::string>& key,
+ const DPL::Optional<std::string>& oldValue,
+ const DPL::Optional<std::string>& 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<std::string>& 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); }";
#define _DISPATCH_EVENT_SUPPORT_H_
#include <string>
+#include <dpl/optional.h>
#include <dpl/log/log.h>
#include <EWebKit2.h>
#include <JavaScriptCore/JavaScript.h>
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<std::string>& key,
+ const DPL::Optional<std::string>& oldValue,
+ const DPL::Optional<std::string>& newValue,
+ const std::string& url);
void dispatchHwKeyEvent(Evas_Object* ewkView, const std::string key);
}
#endif //_DISPATCH_EVENT_SUPPORT_H_
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)) {
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<WKStringRef>(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)
return NULL;
}
- if (!strcmp(name, "tizen://getWindowHandle")) {
+ // tizen://getWindowHandle
+ if (!strcmp(name, TIZEN_GET_WINDOW_HANDLE)) {
if (s_xWindowHandle == 0) {
return NULL;
} else {
}
}
- 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<WKStringRef>(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;
}
DPL::Optional<std::string> 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);
DPL::Optional<std::string> 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");
JSContextRef g_context = JSContextGetGlobalContext(context);
- DispatchEventSupport::dispatchStorageEvent(g_context, "", "", "", "");
+ const auto& null = DPL::Optional<std::string>::Null;
+
+ DispatchEventSupport::dispatchStorageEvent(g_context, null, null, null, "");
LogDebug("end");
if (!!oldValue) { oldValueStr = *oldValue; }
if (!!newValue) { newValueStr = *newValue; }
-
+
DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, "");
LogDebug("end");