X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fstandards%2FW3C%2FWidget%2FJSPreferences.cpp;h=1f6326f5e2b15aa5ea0b24ce472b1af6655c9ecf;hb=9a8d606f7b3f1f9f6c590758eea72c7527b265f5;hp=2f962f0f63aa741eba5623c7c97d61d1b713181e;hpb=3bc0da80d96841aca4227c3db5681f3d50150b4b;p=platform%2Fframework%2Fweb%2Fwrt-plugins-common.git diff --git a/src/standards/W3C/Widget/JSPreferences.cpp b/src/standards/W3C/Widget/JSPreferences.cpp index 2f962f0..1f6326f 100644 --- a/src/standards/W3C/Widget/JSPreferences.cpp +++ b/src/standards/W3C/Widget/JSPreferences.cpp @@ -30,8 +30,10 @@ #include #include #include -#include -#include +#include + +// import temporarily from JSContextRefPrivate.h +extern "C" JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx); using namespace std; using namespace WrtDeviceApis; @@ -256,17 +258,18 @@ JSValueRef JSPreferences::removeItem(JSContextRef context, std::string key = converter.toString(arguments[0]); - auto event = modifyItemAndCreateEvent(ModificationType::RemoveItem, - thisObject, - key); - - auto iframe = IFrameSupport:: - getIFrameObjectForWidget(getWidgetObject(thisObject)); + DPL::Optional oldValue = getIStorage(thisObject)->getValue(key); + getIStorage(thisObject)->removeItem(key); + DPL::Optional newValue = getIStorage(thisObject)->getValue(key); - Assert(iframe && "Iframe is NULL"); + JSContextRef g_context = JSContextGetGlobalContext(context); + std::string oldValueStr = ""; + std::string newValueStr = ""; - AddEventListenerSupport:: - CallStorageListenersFromDifferentIFrames(iframe, event); + if (!!oldValue) { oldValueStr = *oldValue; } + if (!!newValue) { newValueStr = *newValue; } + + DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, ""); LogDebug("end"); return JSValueMakeNull(context); @@ -295,17 +298,18 @@ JSValueRef JSPreferences::setItem(JSContextRef context, std::string key = converter.toString(arguments[0]); std::string value = converter.tryString(arguments[1]); - auto event = modifyItemAndCreateEvent(ModificationType::SetItem, - thisObject, - key, - value); + DPL::Optional oldValue = getIStorage(thisObject)->getValue(key); + getIStorage(thisObject)->setItem(key, value, false); + DPL::Optional newValue = getIStorage(thisObject)->getValue(key); - auto iframe = IFrameSupport:: - getIFrameObjectForWidget(getWidgetObject(thisObject)); - Assert(iframe && "Iframe is NULL"); + JSContextRef g_context = JSContextGetGlobalContext(context); + std::string oldValueStr = ""; + std::string newValueStr = ""; - AddEventListenerSupport:: - CallStorageListenersFromDifferentIFrames(iframe, event); + if (!!oldValue) { oldValueStr = *oldValue; } + if (!!newValue) { newValueStr = *newValue; } + + DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, ""); LogDebug("end"); @@ -331,16 +335,9 @@ JSValueRef JSPreferences::clear(JSContextRef context, Try { getIStorage(thisObject)->clear(false); - auto iframe = IFrameSupport:: - getIFrameObjectForWidget(getWidgetObject(thisObject)); - - Assert(iframe && "Iframe is NULL"); - - //create event object - IStorageEventPtr storageEvent = getStorageEvent(); + JSContextRef g_context = JSContextGetGlobalContext(context); - AddEventListenerSupport:: - CallStorageListenersFromDifferentIFrames(iframe, storageEvent); + DispatchEventSupport::dispatchStorageEvent(g_context, "", "", "", ""); LogDebug("end"); @@ -516,17 +513,18 @@ bool JSPreferences::setProperty(JSContextRef context, std::string key = converter.toString(propertyName); std::string value = converter.toString(jvalue); - auto event = modifyItemAndCreateEvent(ModificationType::SetItem, - object, - key, - value); + DPL::Optional oldValue = getIStorage(object)->getValue(key); + getIStorage(object)->setItem(key, value, false); + DPL::Optional newValue = getIStorage(object)->getValue(key); - auto iframe = IFrameSupport:: - getIFrameObjectForWidget(getWidgetObject(object)); - Assert(iframe && "Iframe is NULL"); + JSContextRef g_context = JSContextGetGlobalContext(context); + std::string oldValueStr = ""; + std::string newValueStr = ""; - AddEventListenerSupport:: - CallStorageListenersFromDifferentIFrames(iframe, event); + if (!!oldValue) { oldValueStr = *oldValue; } + if (!!newValue) { newValueStr = *newValue; } + + DispatchEventSupport::dispatchStorageEvent(g_context, key, oldValueStr, newValueStr, ""); LogDebug("end");