From: Taejeong Lee Date: Wed, 22 May 2013 07:37:17 +0000 (+0900) Subject: Remove js_overlay_addEventListener X-Git-Tag: submit/tizen_2.2/20130927.091410^2~52 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fframework%2Fweb%2Fwrt-plugins-common.git;a=commitdiff_plain;h=9a8d606f7b3f1f9f6c590758eea72c7527b265f5 Remove js_overlay_addEventListener [Issue#] N/A [Problem] Stability. [Cause] Before custom event dispatch implementation was very complicated and instability, because it works by overlay type. It had very heavy operation on webkit with JSC. [Solution] So we have replaced that to very simple operation which is using dom dispatchEvent() api. Change-Id: Iecbc105d2aced7f8649e8504b62014e0cdb0c1b9 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3536d7a..8777310 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,8 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-loading ${CMAKE_CURRENT_SOURCE_DIR}/src/js-overlay ${CMAKE_CURRENT_SOURCE_DIR}/src/wrt-popup/ace/popup-runner - ${CMAKE_CURRENT_SOURCE_DIR}/src/plugins_ipc_message) + ${CMAKE_CURRENT_SOURCE_DIR}/src/plugins_ipc_message + ${CMAKE_CURRENT_SOURCE_DIR}/src/dispatch-event) ############################################################################## # Build type @@ -153,6 +154,7 @@ configure_and_install_pkg(wrt-popup-ace-runner.pc) configure_and_install_pkg(wrt-popup-wrt-runner.pc) configure_and_install_pkg(wrt-plugins-api-support.pc) configure_and_install_pkg(wrt-plugins-ipc-message.pc) +configure_and_install_pkg(wrt-dispatch-event.pc) ################################################################################ # Cache diff --git a/pkgconfigs/wrt-dispatch-event.pc.in b/pkgconfigs/wrt-dispatch-event.pc.in new file mode 100644 index 0000000..937bcaf --- /dev/null +++ b/pkgconfigs/wrt-dispatch-event.pc.in @@ -0,0 +1,12 @@ +prefix=/usr +project_name=@CMAKE_PROJECT_NAME@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include/wrt-dispatch-event + +Name: wrt dispatch event support +Description: Support to dispatch DOM event +Version: @CMAKE_PROJECT_VERSION@ +Requires: dpl-efl ewebkit2 +Libs: -L${libdir} -lwrt-dispatch-event +Cflags: -I${includedir} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 259b2da..5152f7e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,7 @@ add_subdirectory(plugin-loading) add_subdirectory(js-overlay) add_subdirectory(Commons) add_subdirectory(CommonsJavaScript) +add_subdirectory(dispatch-event) add_subdirectory(modules) add_subdirectory(standards) add_subdirectory(wrt-popup) diff --git a/src/dispatch-event/CMakeLists.txt b/src/dispatch-event/CMakeLists.txt new file mode 100644 index 0000000..3ba4072 --- /dev/null +++ b/src/dispatch-event/CMakeLists.txt @@ -0,0 +1,59 @@ +# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# @file CMakeLists.txt +# @author Tae-Jeong Lee (taejeong.lee@samsung.com) +# @version 1.0 +# + +pkg_search_module(webkit2 REQUIRED ewebkit2) +pkg_search_module(dpl REQUIRED dpl-efl) + +SET(TARGET_NAME wrt-dispatch-event) + +SET(SRCS + ${CMAKE_CURRENT_SOURCE_DIR}/dispatch_event_support.cpp +) + +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR} + ${webkit2_INCLUDE_DIRS} + ${dpl_INCLUDE_DIRS} +) + +ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS}) + +TARGET_LINK_LIBRARIES(${TARGET_NAME} + ${webkit2_LIBRARIES} + ${dpl_LIBRARIES} +) + +SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + COMPILE_FLAGS -fPIC + LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both" +) + +SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + SOVERSION ${CMAKE_PROJECT_API_VERSION} + VERSION ${CMAKE_PROJECT_VERSION} +) + +INSTALL(TARGETS ${TARGET_NAME} + DESTINATION ${DESTINATION_LIB_PREFIX} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +) + +INSTALL(FILES dispatch_event_support.h DESTINATION include/wrt-dispatch-event) \ No newline at end of file diff --git a/src/dispatch-event/dispatch_event_support.cpp b/src/dispatch-event/dispatch_event_support.cpp new file mode 100644 index 0000000..14aa01a --- /dev/null +++ b/src/dispatch-event/dispatch_event_support.cpp @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file dispatch_event_support.cpp + * @author Tae-Jeong Lee (taejeong.lee@samsung.com) + * @version 0.1 + * @brief + */ + +#ifndef _DISPATCH_EVENT_SUPPORT_CPP_ +#define _DISPATCH_EVENT_SUPPORT_CPP_ + +#include +#include +#include + +#include "dispatch_event_support.h" + +namespace DispatchEventSupport { + +static std::string getExceptionString(JSContextRef context, JSValueRef exception) +{ + if (exception) + { + JSStringRef jsString = JSValueToStringCopy(context, exception, NULL); + size_t bufSize = JSStringGetMaximumUTF8CStringSize(jsString); + + char* buf = new char[bufSize]; + JSStringGetUTF8CString(jsString, buf, bufSize); + JSStringRelease(jsString); + + std::string ret = buf; + delete[] buf; + + return ret; + } + else + { + return "NULL"; + } +} + +void dispatchAppServiceEvent(JSContextRef context, const float scale, const std::string bundle) +{ + LogDebug("DispatchTizenServiceEvent(" << context << ", " << scale << ", " << bundle << ")"); + + if (context != NULL) + { + std::stringstream script; + + script << "{\n" + << " var event = document.createEvent(\"CustomEvent\");\n" + << " event.initCustomEvent(\"appservice\", true, true);\n" + << " event.scale = " << scale << ";\n" + << " event.__bundle = \"" << bundle << "\";\n" + << " document.dispatchEvent(event);\n" + << " \n" + << " for (var i=0; i < window.frames.length; i++)\n" + << " { window.frames[i].document.dispatchEvent(event); }\n" + << "}"; + + // just for debugging + // LogDebug("script :\n" << script.str()); + + JSValueRef exception = NULL, ret = NULL; + JSStringRef jsScript = JSStringCreateWithUTF8CString(script.str().c_str()); + + ret = JSEvaluateScript(context, jsScript, NULL, NULL, 1, &exception); + + JSStringRelease(jsScript); + + LogDebug("JSEvaluateScript() - ret:" << ret << ", exception:" << exception << " (" << getExceptionString(context, exception) << ")"); + } +} + +void dispatchSoftKeyboardChangeEvent(JSContextRef context, const std::string state, const int width, const int height) +{ + LogDebug("dispatchSoftKeyboardChangeEvent(" << context << ", " << state << ", " << width << ", " << height << ")"); + + if (context != NULL) + { + std::stringstream script; + + script << "{\n" + << " var event = document.createEvent(\"CustomEvent\");\n" + << " event.initCustomEvent(\"softkeyboardchange\", true, true);\n" + << " event.state = \"" << state << "\";\n" + << " event.width = " << width << ";\n" + << " event.height = " << height << ";\n" + << " document.dispatchEvent(event);\n" + << " \n" + << " for (var i=0; i < window.frames.length; i++)\n" + << " { window.frames[i].document.dispatchEvent(event); }\n" + << "}"; + + // just for debugging + // LogDebug("script :\n" << script.str()); + + JSValueRef exception = NULL, ret = NULL; + JSStringRef jsScript = JSStringCreateWithUTF8CString(script.str().c_str()); + + ret = JSEvaluateScript(context, jsScript, NULL, NULL, 1, &exception); + + JSStringRelease(jsScript); + + LogDebug("JSEvaluateScript() - ret:" << ret << ", exception:" << exception << " (" << getExceptionString(context, exception) << ")"); + } +} + +void dispatchStorageEvent(JSContextRef context, const std::string key, const std::string oldValue, const std::string newValue, const std::string url) +{ + LogDebug("dispatchStorageEvent(" << context << ", " << key << ", " << oldValue << ", " << newValue << ", " << url << ")"); + + if (context != NULL) + { + std::stringstream script; + + script << "{\n" + << " 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" + << " { window.frames[i].document.dispatchEvent(event); }\n" + << "}"; + + // just for debugging + // LogDebug("script :\n" << script.str()); + + JSValueRef exception = NULL, ret = NULL; + JSStringRef jsScript = JSStringCreateWithUTF8CString(script.str().c_str()); + + ret = JSEvaluateScript(context, jsScript, NULL, NULL, 1, &exception); + + JSStringRelease(jsScript); + + LogDebug("JSEvaluateScript() - ret:" << ret << ", exception:" << exception << " (" << getExceptionString(context, exception) << ")"); + } +} + +} +#endif //_DISPATCH_EVENT_SUPPORT_CPP_ diff --git a/src/dispatch-event/dispatch_event_support.h b/src/dispatch-event/dispatch_event_support.h new file mode 100644 index 0000000..a267e2c --- /dev/null +++ b/src/dispatch-event/dispatch_event_support.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * + * @file dispatch_event_support.h + * @author Tae-Jeong Lee (taejeong.lee@samsung.com) + * @version 0.1 + * @brief + */ + +#ifndef _DISPATCH_EVENT_SUPPORT_H_ +#define _DISPATCH_EVENT_SUPPORT_H_ + +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); + +} +#endif //_DISPATCH_EVENT_SUPPORT_H_ diff --git a/src/js-overlay/CMakeLists.txt b/src/js-overlay/CMakeLists.txt index dd68584..5cbb0d8 100644 --- a/src/js-overlay/CMakeLists.txt +++ b/src/js-overlay/CMakeLists.txt @@ -30,12 +30,7 @@ SET(TARGET_NAME ${TARGET_JS_OVERLAY}) SET(SRCS ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_support.cpp ${CMAKE_CURRENT_SOURCE_DIR}/js_function_manager.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_addEventListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/js_overlay_functions.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/js_iframe_support.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSStorageEvent.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSTizenServiceEvent.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/JSClass/JSSoftKeyboardChangeEvent.cpp ) INCLUDE_DIRECTORIES( diff --git a/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp b/src/js-overlay/deprecated/JSClass/JSSoftKeyboardChangeEvent.cpp similarity index 100% rename from src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp rename to src/js-overlay/deprecated/JSClass/JSSoftKeyboardChangeEvent.cpp diff --git a/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h b/src/js-overlay/deprecated/JSClass/JSSoftKeyboardChangeEvent.h similarity index 100% rename from src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h rename to src/js-overlay/deprecated/JSClass/JSSoftKeyboardChangeEvent.h diff --git a/src/js-overlay/JSClass/JSStorageEvent.cpp b/src/js-overlay/deprecated/JSClass/JSStorageEvent.cpp similarity index 100% rename from src/js-overlay/JSClass/JSStorageEvent.cpp rename to src/js-overlay/deprecated/JSClass/JSStorageEvent.cpp diff --git a/src/js-overlay/JSClass/JSStorageEvent.h b/src/js-overlay/deprecated/JSClass/JSStorageEvent.h similarity index 100% rename from src/js-overlay/JSClass/JSStorageEvent.h rename to src/js-overlay/deprecated/JSClass/JSStorageEvent.h diff --git a/src/js-overlay/JSClass/JSTizenServiceEvent.cpp b/src/js-overlay/deprecated/JSClass/JSTizenServiceEvent.cpp similarity index 100% rename from src/js-overlay/JSClass/JSTizenServiceEvent.cpp rename to src/js-overlay/deprecated/JSClass/JSTizenServiceEvent.cpp diff --git a/src/js-overlay/JSClass/JSTizenServiceEvent.h b/src/js-overlay/deprecated/JSClass/JSTizenServiceEvent.h similarity index 100% rename from src/js-overlay/JSClass/JSTizenServiceEvent.h rename to src/js-overlay/deprecated/JSClass/JSTizenServiceEvent.h diff --git a/src/js-overlay/js_iframe_support.cpp b/src/js-overlay/deprecated/js_iframe_support.cpp old mode 100644 new mode 100755 similarity index 100% rename from src/js-overlay/js_iframe_support.cpp rename to src/js-overlay/deprecated/js_iframe_support.cpp diff --git a/src/js-overlay/js_iframe_support.h b/src/js-overlay/deprecated/js_iframe_support.h old mode 100644 new mode 100755 similarity index 100% rename from src/js-overlay/js_iframe_support.h rename to src/js-overlay/deprecated/js_iframe_support.h diff --git a/src/js-overlay/js_overlay_addEventListener.cpp b/src/js-overlay/deprecated/js_overlay_addEventListener.cpp old mode 100644 new mode 100755 similarity index 100% rename from src/js-overlay/js_overlay_addEventListener.cpp rename to src/js-overlay/deprecated/js_overlay_addEventListener.cpp diff --git a/src/js-overlay/js_overlay_addEventListener.h b/src/js-overlay/deprecated/js_overlay_addEventListener.h old mode 100644 new mode 100755 similarity index 100% rename from src/js-overlay/js_overlay_addEventListener.h rename to src/js-overlay/deprecated/js_overlay_addEventListener.h diff --git a/src/js-overlay/js_function_manager.cpp b/src/js-overlay/js_function_manager.cpp index dfa55b2..388a3f0 100644 --- a/src/js-overlay/js_function_manager.cpp +++ b/src/js-overlay/js_function_manager.cpp @@ -23,20 +23,15 @@ #include #include -#include #include -#include #include -using namespace WrtPlugins::W3C; - IMPLEMENT_SAFE_SINGLETON(JsFunctionManager) namespace { const char* JSPRINT_NAME = "jsPrint"; const char* JSGLOBAL_OBJECT = "GLOBAL_OBJECT"; const char* JSHOOK_NAME = "jsHook"; -const char* ADD_EVENT_LISTENER_NAME = "addEventListener"; } namespace JavaScriptFunctions { @@ -61,17 +56,6 @@ class_definition_options_t jsPrintfunctionsOptions = { reinterpret_cast(JSCFunctions::JavaScriptPrintProc) }; -class_definition_options_t addEventListenerOptions = { - JS_FUNCTION, - CREATE_INSTANCE, - ALWAYS_NOTICE, - OVERLAYED_BEFORE_ORIGINAL, - IFrameSupport::RegisterAddEventListener, - NULL, - reinterpret_cast(AddEventListenerSupport:: - AddEventListener) -}; - js_entity_definition_t jsPrint = { JSGLOBAL_OBJECT, JSPRINT_NAME, @@ -90,17 +74,8 @@ js_entity_definition_t jsHook = { &jsHookfunctionsOptions }; -js_entity_definition_t addEventListener = { - JSGLOBAL_OBJECT, - ADD_EVENT_LISTENER_NAME, - "", - NULL, - NULL, - &addEventListenerOptions -}; const js_entity_definition_ptr_t jsPrintPtr = &jsPrint; const js_entity_definition_ptr_t jsHookPtr = &jsHook; -const js_entity_definition_ptr_t addEventListenerPtr = &addEventListener; } bool JsFunctionManager::initialize() @@ -112,12 +87,8 @@ bool JsFunctionManager::initialize() JSObjectDeclarationPtr jsHookObj( new JSObjectDeclaration(JavaScriptFunctions::jsHookPtr)); - JSObjectDeclarationPtr addEventListenerObj( - new JSObjectDeclaration(JavaScriptFunctions::addEventListenerPtr)); - m_functions.push_back(jsPrintObj); m_functions.push_back(jsHookObj); - m_functions.push_back(addEventListenerObj); return true; } diff --git a/src/plugin-loading/explorer.cpp b/src/plugin-loading/explorer.cpp index 3a76b3a..1ecad15 100644 --- a/src/plugin-loading/explorer.cpp +++ b/src/plugin-loading/explorer.cpp @@ -30,13 +30,6 @@ // JS overlay #include #include -#include -#include -#include -#include -#include -#include -#include namespace { //const char* SEPARATOR = "."; @@ -342,7 +335,6 @@ void Explorer::unloadFrame(JSGlobalContextRef context) JSObjectPtr frameObject = JavaScriptInterfaceSingleton::Instance().getGlobalObject(context); - AddEventListenerSupport::RemoveIFrame(frameObject); m_iframeSupport.unregisterIframe(frameObject); } @@ -379,6 +371,7 @@ void Explorer::cleanIframesData() void Explorer::callEventListeners(CustomEventType eventType, void* data) { +#if 0 // deprecated using namespace WrtPlugins::Tizen; // get iframe objects from javascript global context JavaScriptInterface::ObjectsListPtr frameLists = @@ -450,6 +443,7 @@ void Explorer::callEventListeners(CustomEventType eventType, void* data) LogInfo("Not supported custom event type"); return; } +#endif } WindowPropertySupport* Explorer::getWindowPropertySupport() diff --git a/src/standards/W3C/Widget/CMakeLists.txt b/src/standards/W3C/Widget/CMakeLists.txt old mode 100755 new mode 100644 index 70ef116..fe0174f --- a/src/standards/W3C/Widget/CMakeLists.txt +++ b/src/standards/W3C/Widget/CMakeLists.txt @@ -29,8 +29,6 @@ include_directories( ${API_WIDGET_PATH} ${webkit2_INCLUDE_DIRS} ${plugin-types_INCLUDE_DIRS} -# ${API_STORAGE_EVENT_PATH} -# ${API_LOCALSTORAGE_PATH} ) add_library(${TARGET_NAME} SHARED ${SRCS}) @@ -42,6 +40,7 @@ target_link_libraries(${TARGET_NAME} wrt-plugins-widget wrt-plugins-localstorage wrt-plugins-storageevent + wrt-dispatch-event ) INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION /usr/lib/wrt-plugins/w3c-widget-interface) 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"); diff --git a/src/standards/W3C/Widget/JSWidget.cpp b/src/standards/W3C/Widget/JSWidget.cpp index 6dd18ba..162820f 100644 --- a/src/standards/W3C/Widget/JSWidget.cpp +++ b/src/standards/W3C/Widget/JSWidget.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #define CATCH_EXCEPTION_NO_MODIFABLE \ Catch(Commons::LocalStorageValueNoModifableException) { \ @@ -302,7 +301,6 @@ void JSWidget::acquireGlobalContext(java_script_context_t global_context, js_object_instance_t iframe, js_object_instance_t object) { - IFrameSupport::RegisterWidget(global_context, iframe, object); if (!m_globalContext) { m_globalContext = static_cast(global_context); LogInfo("Global context acquired."); diff --git a/src/standards/W3C/Widget/plugin_initializer.cpp b/src/standards/W3C/Widget/plugin_initializer.cpp index 6b64770..d296869 100644 --- a/src/standards/W3C/Widget/plugin_initializer.cpp +++ b/src/standards/W3C/Widget/plugin_initializer.cpp @@ -25,8 +25,6 @@ #include #include -#include -#include #include "JSWidget.h" #include "JSPreferences.h" @@ -45,9 +43,9 @@ namespace Options { class_definition_options_t WidgetOptions = { JS_CLASS, CREATE_INSTANCE, - ALWAYS_NOTICE, + NONE_NOTICE, USE_OVERLAYED, //ignored - IFrameSupport::RegisterWidget, + NULL, NULL, NULL };