Tizen 2.1 base
authorJinkun Jang <jinkun.jang@samsung.com>
Tue, 12 Mar 2013 17:05:51 +0000 (02:05 +0900)
committerJinkun Jang <jinkun.jang@samsung.com>
Tue, 12 Mar 2013 17:05:51 +0000 (02:05 +0900)
229 files changed:
CMakeLists.txt
clean.sh
config.dtd [new file with mode: 0644]
debian/changelog [changed mode: 0755->0644]
debian/control
debian/rules
debian/wrt-plugins-common-dev.install.in
debian/wrt-plugins-common.install.in
debian/wrt-plugins-common.postinst.in [changed mode: 0755->0644]
packaging/wrt-plugins-common.spec [new file with mode: 0644]
pkgconfigs/wrt-plugin-js-overlay.pc.in [new file with mode: 0644]
pkgconfigs/wrt-plugin-loading.pc.in [new file with mode: 0644]
pkgconfigs/wrt-plugins-api-support.pc.in [new file with mode: 0644]
pkgconfigs/wrt-plugins-commons-javascript.pc.in
pkgconfigs/wrt-plugins-commons.pc.in
pkgconfigs/wrt-plugins-filesystem.pc.in
pkgconfigs/wrt-plugins-plugin-manager.pc.in
pkgconfigs/wrt-plugins-widget-interface-dao.pc.in [new file with mode: 0644]
pkgconfigs/wrt-plugins-widgetdb.pc.in
pkgconfigs/wrt-popup-ace-runner.pc.in [new file with mode: 0644]
pkgconfigs/wrt-popup-runner.pc.in [new file with mode: 0644]
pkgconfigs/wrt-popup-wrt-runner.pc.in [new file with mode: 0644]
src/CMakeLists.txt
src/Commons/CMakeLists.txt [changed mode: 0755->0644]
src/Commons/EventReceiver.h
src/Commons/FunctionDeclaration.h
src/Commons/IEvent.h
src/Commons/JSObject.cpp [new file with mode: 0644]
src/Commons/JSObject.h [new file with mode: 0644]
src/Commons/JSObjectDeclaration.cpp [new file with mode: 0644]
src/Commons/JSObjectDeclaration.h [new file with mode: 0644]
src/Commons/StringUtils.cpp
src/Commons/StringUtils.h
src/Commons/ThreadPool.cpp
src/Commons/ThreadPool.h
src/Commons/TimeUtils.cpp [new file with mode: 0644]
src/Commons/TimeUtils.h [new file with mode: 0644]
src/Commons/WrtAccess/WrtAccess.cpp [new file with mode: 0644]
src/Commons/WrtAccess/WrtAccess.h [new file with mode: 0644]
src/Commons/WrtAccess/config.cmake [new file with mode: 0644]
src/Commons/plugin_initializer_def.h
src/CommonsJavaScript/CMakeLists.txt
src/CommonsJavaScript/Converter.cpp [changed mode: 0755->0644]
src/CommonsJavaScript/Converter.h [changed mode: 0755->0644]
src/CommonsJavaScript/JSCallbackManager.cpp
src/CommonsJavaScript/JSCallbackManager.h
src/CommonsJavaScript/Security/SecurityFunctionDeclaration.cpp
src/CommonsJavaScript/Security/SecurityFunctionDeclaration.h
src/CommonsJavaScript/Security/StaticDeclaration.h
src/js-overlay/CMakeLists.txt [new file with mode: 0644]
src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp [new file with mode: 0644]
src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h [new file with mode: 0644]
src/js-overlay/JSClass/JSStorageEvent.cpp [new file with mode: 0644]
src/js-overlay/JSClass/JSStorageEvent.h [new file with mode: 0644]
src/js-overlay/JSClass/JSTizenServiceEvent.cpp [new file with mode: 0644]
src/js-overlay/JSClass/JSTizenServiceEvent.h [new file with mode: 0644]
src/js-overlay/js_function_manager.cpp [new file with mode: 0644]
src/js-overlay/js_function_manager.h [new file with mode: 0644]
src/js-overlay/js_iframe_support.cpp [new file with mode: 0644]
src/js-overlay/js_iframe_support.h [new file with mode: 0644]
src/js-overlay/js_overlay_addEventListener.cpp [new file with mode: 0644]
src/js-overlay/js_overlay_addEventListener.h [new file with mode: 0644]
src/js-overlay/js_overlay_functions.cpp [new file with mode: 0644]
src/js-overlay/js_overlay_functions.h [new file with mode: 0644]
src/js-overlay/js_overlay_support.cpp [new file with mode: 0644]
src/js-overlay/js_overlay_support.h [new file with mode: 0644]
src/js-overlay/js_overlay_types.h [new file with mode: 0644]
src/modules/API/CMakeLists.txt
src/modules/API/Filesystem/IManager.cpp
src/modules/API/Filesystem/IManager.h
src/modules/API/LocalStorage/ILocalStorage.h
src/modules/API/PluginManager/PluginManagerFactory.cpp
src/modules/API/PluginManager/PluginManagerFactory.h
src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h [new file with mode: 0644]
src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp [new file with mode: 0644]
src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h [new file with mode: 0644]
src/modules/API/SoftKeyboardChangeEvent/config.cmake [new file with mode: 0644]
src/modules/API/TizenServiceEvent/ITizenServiceEvent.h [new file with mode: 0644]
src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp [new file with mode: 0644]
src/modules/API/TizenServiceEvent/TizenServiceEvent.h [new file with mode: 0644]
src/modules/API/TizenServiceEvent/config.cmake [new file with mode: 0644]
src/modules/API/Widget/WidgetFactory.cpp
src/modules/API/Widget/WidgetFactory.h
src/modules/API/WidgetDB/IWidgetFeature.h
src/modules/API/config.cmake [new file with mode: 0644]
src/modules/packages/CMakeLists.txt
src/modules/packages/Filesystem/CMakeLists.txt
src/modules/packages/LocalStorage/CMakeLists.txt
src/modules/packages/Networking/CMakeLists.txt
src/modules/packages/PluginManager/CMakeLists.txt
src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt [new file with mode: 0644]
src/modules/packages/StorageEvent/CMakeLists.txt
src/modules/packages/TizenServiceEvent/CMakeLists.txt [new file with mode: 0644]
src/modules/packages/Widget/CMakeLists.txt
src/modules/packages/WidgetDB/CMakeLists.txt
src/modules/packages/WidgetInterfaceDAO/CMakeLists.txt
src/modules/tizen/CMakeLists.txt
src/modules/tizen/DEPRACATED/Camera-Webkit/Camera.cpp [new file with mode: 0644]
src/modules/tizen/DEPRACATED/Camera-Webkit/Camera.h [new file with mode: 0644]
src/modules/tizen/DEPRACATED/Camera-Webkit/CameraManager.cpp [new file with mode: 0644]
src/modules/tizen/DEPRACATED/Camera-Webkit/CameraManager.h [new file with mode: 0644]
src/modules/tizen/DEPRACATED/Camera-Webkit/config.cmake [new file with mode: 0644]
src/modules/tizen/Filesystem/Manager.cpp
src/modules/tizen/Filesystem/Manager.h
src/modules/tizen/Filesystem/Node.cpp
src/modules/tizen/Filesystem/config.cmake
src/modules/tizen/PluginManager/PluginManager.cpp
src/modules/tizen/PluginManager/PluginManager.h
src/modules/tizen/PluginManager/config.cmake
src/modules/tizen/Widget/Widget.cpp
src/modules/tizen/Widget/Widget.h
src/modules/tizen/WidgetDB/WidgetDB.cpp [changed mode: 0755->0644]
src/modules/tizen/WidgetDB/WidgetFeature.cpp
src/modules/tizen/WidgetDB/config.cmake
src/modules/tizen/WidgetInterfaceDAO/CMakeLists.txt
src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp
src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.h
src/modules/tizen/config.cmake [new file with mode: 0644]
src/plugin-loading/CMakeLists.txt [new file with mode: 0644]
src/plugin-loading/explorer.cpp [new file with mode: 0644]
src/plugin-loading/explorer.h [new file with mode: 0644]
src/plugin-loading/javascript_interface.cpp [new file with mode: 0644]
src/plugin-loading/javascript_interface.h [new file with mode: 0644]
src/plugin-loading/js_page_session.cpp [new file with mode: 0644]
src/plugin-loading/js_page_session.h [new file with mode: 0644]
src/plugin-loading/js_types.h [new file with mode: 0644]
src/plugin-loading/plugin.cpp [new file with mode: 0644]
src/plugin-loading/plugin.h [new file with mode: 0644]
src/plugin-loading/plugin_container_support.cpp [new file with mode: 0644]
src/plugin-loading/plugin_container_support.h [new file with mode: 0644]
src/plugin-loading/plugin_iframe_support.cpp [new file with mode: 0644]
src/plugin-loading/plugin_iframe_support.h [new file with mode: 0644]
src/plugin-loading/plugin_logic.cpp [new file with mode: 0644]
src/plugin-loading/plugin_logic.h [new file with mode: 0644]
src/plugin-loading/plugin_model.cpp [new file with mode: 0644]
src/plugin-loading/plugin_model.h [new file with mode: 0644]
src/plugin-loading/plugin_property_support.cpp [new file with mode: 0644]
src/plugin-loading/plugin_property_support.h [new file with mode: 0644]
src/plugins-api-support/CMakeLists.txt [new file with mode: 0644]
src/plugins-api-support/CallbackSupport.h [new file with mode: 0644]
src/plugins-api-support/ExportedApi.h [new file with mode: 0644]
src/plugins-api-support/IObject.h [new file with mode: 0644]
src/plugins-api-support/IObject_cast.h [new file with mode: 0644]
src/plugins-api-support/Object.cpp [new file with mode: 0644]
src/plugins-api-support/Object.h [new file with mode: 0644]
src/plugins-api-support/ObjectFactory.cpp [new file with mode: 0644]
src/plugins-api-support/ObjectFactory.h [new file with mode: 0644]
src/plugins-api-support/Plugin.cpp [new file with mode: 0644]
src/plugins-api-support/Plugin.h [new file with mode: 0644]
src/plugins-api-support/PluginRegistration.cpp [new file with mode: 0644]
src/plugins-api-support/PluginRegistration.h [new file with mode: 0644]
src/plugins-api-support/PluginRegistrationImpl.h [new file with mode: 0644]
src/plugins-api-support/PluginRegistry.cpp [new file with mode: 0644]
src/plugins-api-support/PluginRegistry.h [new file with mode: 0644]
src/plugins-api-support/PluginSignals.h [new file with mode: 0644]
src/plugins-api-support/SignalSignature.h [new file with mode: 0644]
src/plugins-api-support/SignalsSupport.h [new file with mode: 0644]
src/plugins-api-support/SoFeatures.h [new file with mode: 0644]
src/plugins-api-support/detail/traits.h [new file with mode: 0644]
src/plugins-api-support/js_types.h [new file with mode: 0644]
src/plugins-api-support/traits.h [new file with mode: 0644]
src/plugins-api-support/tuple.h [new file with mode: 0644]
src/plugins-installer/CMakeLists.txt [new file with mode: 0644]
src/plugins-installer/DESCRIPTION [new file with mode: 0644]
src/plugins-installer/plugin_installer.cpp [new file with mode: 0644]
src/plugins-installer/plugin_installer.h [new file with mode: 0644]
src/plugins-installer/plugin_installer_errors.h [new file with mode: 0644]
src/plugins-installer/plugin_installer_types.h [new file with mode: 0644]
src/plugins-installer/plugin_metafile_reader.cpp [new file with mode: 0644]
src/plugins-installer/plugin_metafile_reader.h [new file with mode: 0644]
src/plugins-installer/plugin_objects.cpp [new file with mode: 0644]
src/plugins-installer/plugin_objects.h [new file with mode: 0644]
src/plugins-installer/plugin_utils.cpp [new file with mode: 0644]
src/plugins-installer/plugin_utils.h [new file with mode: 0755]
src/plugins-installer/wrt_plugins_installer.cpp [new file with mode: 0644]
src/standards/CMakeLists.txt [new file with mode: 0644]
src/standards/W3C/CMakeLists.txt [new file with mode: 0644]
src/standards/W3C/DESCRIPTION [new file with mode: 0644]
src/standards/W3C/Widget/CMakeLists.txt [new file with mode: 0755]
src/standards/W3C/Widget/JSPreferences.cpp [new file with mode: 0644]
src/standards/W3C/Widget/JSPreferences.h [new file with mode: 0644]
src/standards/W3C/Widget/JSWidget.cpp [new file with mode: 0644]
src/standards/W3C/Widget/JSWidget.h [new file with mode: 0644]
src/standards/W3C/Widget/plugin_config.cpp [new file with mode: 0644]
src/standards/W3C/Widget/plugin_config.h [new file with mode: 0644]
src/standards/W3C/Widget/plugin_initializer.cpp [new file with mode: 0644]
src/standards/standard-features-list [new file with mode: 0644]
src/wrt-popup/CMakeLists.txt [new file with mode: 0755]
src/wrt-popup/ace/CMakeLists.txt [new file with mode: 0755]
src/wrt-popup/ace/popup-bin/CMakeLists.txt [new file with mode: 0644]
src/wrt-popup/ace/popup-bin/Popup.cpp [new file with mode: 0644]
src/wrt-popup/ace/popup-bin/Popup.h [new file with mode: 0644]
src/wrt-popup/ace/popup-runner/CMakeLists.txt [new file with mode: 0644]
src/wrt-popup/ace/popup-runner/popup-runner.cpp [new file with mode: 0644]
src/wrt-popup/ace/popup-runner/popup-runner.h [new file with mode: 0644]
src/wrt-popup/wrt/CMakeLists.txt [new file with mode: 0755]
src/wrt-popup/wrt/PopupEnum.h [new file with mode: 0644]
src/wrt-popup/wrt/PopupSerializer.cpp [new file with mode: 0644]
src/wrt-popup/wrt/PopupSerializer.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/CMakeLists.txt [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/InfoPopup.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/InfoPopup.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/YesNoPopup.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/evas_object.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/evas_object.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_controller.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_controller.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_manager.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_manager.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_object.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/wrt-popup.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-bin/wrt-popup.h [new file with mode: 0644]
src/wrt-popup/wrt/popup-runner/CMakeLists.txt [new file with mode: 0644]
src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp [new file with mode: 0644]
src/wrt-popup/wrt/popup-runner/PopupInvoker.h [new file with mode: 0644]
tests/CMakeLists.txt
tests/CMakeUtils.txt [new file with mode: 0644]
tests/dao/CMakeLists.txt [new file with mode: 0644]
tests/dao/README [new file with mode: 0644]
tests/dao/TestInit.cpp [new file with mode: 0644]
tests/dao/WidgetDBTest.cpp [new file with mode: 0644]
tests/dao/widgetdb_tests_prepare_db.sh [new file with mode: 0755]
wrt-plugins-common.manifest [new file with mode: 0644]

index ffa4731..e9241f4 100644 (file)
 #
 cmake_minimum_required(VERSION 2.6)
 
-IF("${CMAKE_PROJECT_NAME}" STREQUAL "")
-    SET(CMAKE_PROJECT_NAME wrt-plugins-common)
-ENDIF("${CMAKE_PROJECT_NAME}" STREQUAL "")
-
+SET(CMAKE_PROJECT_NAME wrt-plugins-common)
 set(PACKAGE_NAME ${CMAKE_PROJECT_NAME})
-
 project(${CMAKE_PROJECT_NAME})
+STRING(REGEX MATCH "([^.]*)" CMAKE_PROJECT_API_VERSION "${CMAKE_PROJECT_VERSION}")
 
 ################################################################################
 # Required platform modules
 
 include(FindPkgConfig)
 
-pkg_search_module(dpl REQUIRED dpl-efl>=1.0.0)
+pkg_search_module(dpl REQUIRED dpl-efl>=0.2.21)
 
 include_directories(
   ${dpl_INCLUDE_DIRS}
-)
-
-
-#
-# Logs
-#
-OPTION(DPL_LOG "DPL logs status" ON)
-
-IF(DPL_LOG)
-    MESSAGE(STATUS "Logging enabled for DPL")
-    ADD_DEFINITIONS("-DDPL_LOGS_ENABLED")
-ELSE(DPL_LOG)
-    MESSAGE(STATUS "Logging disabled for DPL")
-ENDIF(DPL_LOG)
-
-
-###############################################################################
-# Set build type (Release by default)
-IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-     SET(CMAKE_BUILD_TYPE Release)
-ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-
-MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/API
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/Commons
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/CommonsJavaScript
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/plugin-loading
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/js-overlay
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/wrt-popup/ace/popup-runner)
 
 ##############################################################################
+# Build type
+IF(NOT CMAKE_BUILD_TYPE)
+    SET(CMAKE_BUILD_TYPE "Release")
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
 # Compiler flags
-SET(CMAKE_C_FLAGS_PROFILING    "-O0 -g -pg")
-SET(CMAKE_CXX_FLAGS_PROFILING  "-O0 -std=c++0x -g -pg")
+SET(CMAKE_C_FLAGS_PROFILING    "-O2")
+SET(CMAKE_CXX_FLAGS_PROFILING  "-O2 -std=c++0x")
 SET(CMAKE_C_FLAGS_DEBUG        "-O0 -g")
 SET(CMAKE_CXX_FLAGS_DEBUG      "-O0 -std=c++0x -g")
 SET(CMAKE_C_FLAGS_RELEASE      "-O2 -g")
 SET(CMAKE_CXX_FLAGS_RELEASE    "-O2 -std=c++0x -g")
+SET(CMAKE_CXX_FLAGS_CCOV       "-O0 -std=c++0x -g --coverage")
 ####
 
+OPTION(DPL_LOG "DPL logs status" ON)
+OPTION(WITH_TESTS "Build tests" OFF)
+
+IF(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling")
+    MESSAGE(STATUS "Logging enabled for DPL")
+    ADD_DEFINITIONS("-DDPL_LOGS_ENABLED")
+ELSE(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling")
+    MESSAGE(STATUS "Logging disabled for DPL")
+ENDIF(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling")
+
+MESSAGE(STATUS "WITH_TESTS: " ${WITH_TESTS})
+
+ADD_DEFINITIONS("-fPIC")
 ADD_DEFINITIONS("-fvisibility=default")         # mark all exported symbols as visible
+ADD_DEFINITIONS("-fPIC")                        # If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding
 ADD_DEFINITIONS("-DEXPORT_API=")
 ADD_DEFINITIONS("-Wall")
-ADD_DEFINITIONS("-Werror")
+#ADD_DEFINITIONS("-Werror")
 ADD_DEFINITIONS("-Wextra")
 ADD_DEFINITIONS("-Wno-deprecated")
+#ADD_DEFINITIONS("-DDEVPKG")
 
-#disable default singleton implementation
-ADD_DEFINITIONS("-DSEPARATED_SINGLETON_IMPLEMENTATION")
+##############################################################################
+# CMake flags
+IF (DEVPKG)
+    SET(DEVPKG "ON")
+ENDIF(DEVPKG)
 
 ################################################################################
 # Miscellaneous variables
@@ -86,6 +91,8 @@ set(DESTINATION_HEADER_PREFIX include/${PROJECT_NAME})
 
 set(DESTINATION_HEADERS_NON_JS ${DESTINATION_HEADER_PREFIX}/Commons)
 set(DESTINATION_HEADERS_JS ${DESTINATION_HEADER_PREFIX}/CommonsJavaScript)
+set(DESTINATION_HEADERS_JS_OVERLAY ${DESTINATION_HEADER_PREFIX}/js-overlay)
+set(DESTINATION_HEADERS_WRT_POPUP_RUNNER ${DESTINATION_HEADER_PREFIX}/popup-runner)
 
 ################################################################################
 # Target platform
@@ -95,6 +102,13 @@ if (NOT DEFINED PLATFORM)
 endif ()
 
 ################################################################################
+# Schema of plugin's configuration file
+
+set(COMMON_CONFIG_DTD ${CMAKE_CURRENT_SOURCE_DIR}/config.dtd)
+set(COMMON_CONFIG_DTD_DST /usr/etc/wrt-plugins)
+INSTALL(FILES ${COMMON_CONFIG_DTD} DESTINATION ${COMMON_CONFIG_DTD_DST})
+
+################################################################################
 # Macros used for including plugins from AL.
 
 
@@ -107,7 +121,10 @@ endfunction()
 # Subdirectories
 
 add_subdirectory(src)
-add_subdirectory(tests)
+
+IF(WITH_TESTS)
+  add_subdirectory(tests)
+ENDIF(WITH_TESTS)
 
 ################################################################################
 # PKGCONFIG
@@ -123,26 +140,15 @@ endmacro(configure_and_install_pkg)
 configure_and_install_pkg(wrt-plugins-commons-javascript.pc)
 configure_and_install_pkg(wrt-plugins-commons.pc)
 configure_and_install_pkg(wrt-plugins-filesystem.pc)
-configure_and_install_pkg(wrt-plugins-camera.pc)
-configure_and_install_pkg(wrt-plugins-messaging.pc)
-configure_and_install_pkg(wrt-plugins-calendar.pc)
-configure_and_install_pkg(wrt-plugins-haptics.pc)
-configure_and_install_pkg(wrt-plugins-contact.pc)
-configure_and_install_pkg(wrt-plugins-mmplayer.pc)
-configure_and_install_pkg(wrt-plugins-widget.pc)
-configure_and_install_pkg(wrt-plugins-cpu.pc)
-configure_and_install_pkg(wrt-plugins-accelerometer.pc)
-configure_and_install_pkg(wrt-plugins-task.pc)
-configure_and_install_pkg(wrt-plugins-orientation.pc)
-configure_and_install_pkg(wrt-plugins-radio.pc)
-configure_and_install_pkg(wrt-plugins-power.pc)
-configure_and_install_pkg(wrt-plugins-profile.pc)
-configure_and_install_pkg(wrt-plugins-localstorage.pc)
-configure_and_install_pkg(wrt-plugins-systeminfo.pc)
-configure_and_install_pkg(wrt-plugins-widget_interface_dao.pc)
-configure_and_install_pkg(wrt-plugins-storageevent.pc)
+configure_and_install_pkg(wrt-plugins-widget-interface-dao.pc)
 configure_and_install_pkg(wrt-plugins-widgetdb.pc)
 configure_and_install_pkg(wrt-plugins-plugin-manager.pc)
+configure_and_install_pkg(wrt-plugin-loading.pc)
+configure_and_install_pkg(wrt-plugin-js-overlay.pc)
+configure_and_install_pkg(wrt-popup-runner.pc)
+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)
 
 ################################################################################
 # Cache
index 86f7298..d5d143a 100755 (executable)
--- a/clean.sh
+++ b/clean.sh
@@ -1,4 +1,18 @@
 #!/bin/bash
+# Copyright (c) 2012 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.
+#
 
 echo Performing clean
 
diff --git a/config.dtd b/config.dtd
new file mode 100644 (file)
index 0000000..f1a1de4
--- /dev/null
@@ -0,0 +1,32 @@
+<!ELEMENT plugin-properties (library-name, feature-install-uri?,
+  feature-key-cn?, feature-root-cn?,
+  feature-root-fingerprint?, feature-set*, api-feature+) >
+
+<!ELEMENT library-name (#PCDATA)>
+
+<!ELEMENT feature-set (api-feature-ref+)>
+<!ATTLIST feature-set name CDATA #REQUIRED >
+
+<!ELEMENT api-feature-ref EMPTY>
+<!ATTLIST api-feature-ref name CDATA #REQUIRED >
+
+<!ELEMENT api-feature (name, device-capability*, Object*, Function*, Property* )>
+
+<!ELEMENT name (#PCDATA) >
+<!ELEMENT device-capability (#PCDATA )>
+
+<!ELEMENT Object (Function*, Property*)>
+<!ATTLIST Object name CDATA #REQUIRED >
+
+<!ELEMENT Function (#PCDATA )>
+<!ATTLIST Function name CDATA #REQUIRED >
+<!ATTLIST Function restricted CDATA #IMPLIED >
+
+<!ELEMENT Property (#PCDATA )>
+
+
+<!ELEMENT feature-install-uri (#PCDATA)>
+<!ELEMENT feature-key-cn (#PCDATA)>
+<!ELEMENT feature-root-cn (#PCDATA)>
+<!ELEMENT feature-root-fingerprint (#PCDATA)>
+
old mode 100755 (executable)
new mode 100644 (file)
index 21b026d..8845919
+wrt-plugins-common (0.3.70) unstable; urgency=low
+
+  * Add tests - widgetdb
+  * PluginManager change to support tizen privilege policy.
+  * Merge "PluginManager change to support tizen privilege policy.
+
+ -- Leerang Song <leerang.song@samsung.com>  Wed, 23 Jan 2013 22:36:46 +0900
+
+wrt-plugins-common (0.3.69) unstable; urgency=low
+
+  * Add initSession step in PluginLogic.
+  * [Prevent] Fixes issues with exceptions thrown out of main scope.
+  * Changed PkgName type from DPL::Optional<DPL::String> to DPL::String. PART 2
+  * [Prevent] Handle unhandled exceptions in wrt-popup.
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 10 Jan 2013 11:29:27 +0900
+
+wrt-plugins-common (0.3.68) unstable; urgency=low
+
+  * Remove popup dependency from wrt-commons
+  * Add new popup: Ask YesNo with checkbox
+  * Missing boilerplate added
+  * Support plugin without feature define
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.68
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Tue, 18 Dec 2012 14:34:58 +0900
+
+wrt-plugins-common (0.3.67) unstable; urgency=low
+
+  * Information popup
+  * [Prevent] Ensure pointer is not NULL before it's referenced.
+  * [Prevent] Delete unreachable code.
+  * Popup cleaning
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.67
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 13 Dec 2012 13:41:23 +0900
+
+wrt-plugins-common (0.3.66) unstable; urgency=low
+
+  * Unused code - removed modules CPU, MMPlayer
+  * Remove duplicated code in filesystem manager
+  * Duplicated code in plugins installer
+  * wrt-plugins-installer clean up
+  * Duplicated code in plugin loader
+  * Adjustment for usage of STL pointers - build break fix
+  * Fixed problem with running tests
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.66
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Mon, 10 Dec 2012 11:28:19 +0900
+
+wrt-plugins-common (0.3.63) unstable; urgency=low
+
+  * Fix for use after free
+  * Removal of factory_widget attribute and related functions
+  * Add Sanity Check for Plugin Logic
+  * Removed error generated by Tizen Robot on gerrit
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.63
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Fri, 23 Nov 2012 10:14:53 +0900
+
+wrt-plugins-common (0.3.62) unstable; urgency=low
+
+  * Add -ldl to link library libdl.so
+  * Add specific interface for support of custom js event
+  * Removal of factory_widget attribute and related functions 
+  * Fix for use after free 
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.61
+
+ -- Yunchan Cho <yunchan.cho@samsung.com>  Thu, 15 Nov 2012 15:30:11 +0900
+
+wrt-plugins-common (0.3.61) unstable; urgency=low
+
+  * Memory leaks in popup runner
+  * Fixing a near buildbreak
+  * Fixes for recursive opendir
+  * Change profiling build
+  * Add thread enums for new plugin modules.
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.61
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Fri, 02 Nov 2012 11:28:36 +0900
+
+wrt-plugins-common (0.3.60) unstable; urgency=low
+
+  * New Plugin API #2 : Plugins-Installer
+  * Add license installing
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.60
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Fri, 12 Oct 2012 08:11:28 +0900
+
+wrt-plugins-common (0.3.59) unstable; urgency=low
+
+  * Manifest file fix
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.59
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Tue, 09 Oct 2012 21:00:45 +0900
+
+wrt-plugins-common (0.3.58) unstable; urgency=low
+
+  * [Plugins] Add wrt-popup
+  * [Plugins] New plugin API #1 : API
+  * [Plugins] Change path for "plugin-installation-required"
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.58
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Fri, 05 Oct 2012 07:45:07 +0900
+
+wrt-plugins-common (0.3.57) unstable; urgency=low
+
+  * Add smack manifest
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.57
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 20 Sep 2012 20:12:59 +0900
+
+wrt-plugins-common (0.3.56) unstable; urgency=low
+
+  * Read allowed plugins when session start
+  * Converer toLongLong conversion
+
+  * Git : framework/web/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.56
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Wed, 19 Sep 2012 12:14:22 +0900
+
+wrt-plugins-common (0.3.55) unstable; urgency=low
+
+  * [Plugins] Allow to initialize localStorage for many widgets
+  * [Plugins] Upgrade Security dependencies
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.55
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Tue, 11 Sep 2012 15:35:20 +0900
+
+wrt-plugins-common (0.3.54) unstable; urgency=low
+
+  * [Plugins] Code clean up
+  * [Plugins] Multiple INVALID_WIDGET_HANDLE definition
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.54
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Wed, 29 Aug 2012 13:40:06 +0900
+
+wrt-plugins-common (0.3.53) unstable; urgency=low
+
+  * Removed a unnecessary dependency.
+  * Add thread pool enum for new tizen download module.
+  * Added new build type for code coverage
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.53
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Wed, 08 Aug 2012 15:42:43 +0900
+
+wrt-plugins-common (0.3.52) unstable; urgency=low
+
+  * Update tag for adding "SEL Verification"
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.52
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Wed, 01 Aug 2012 17:46:57 +0900
+
+wrt-plugins-common (0.3.51) unstable; urgency=low
+
+  * Support for multiple contexts in plugin logic
+  * Cleaned up loading plugin into iframes
+  * Added support for dispatch event and set properties in JS
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.51
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Wed, 01 Aug 2012 13:28:24 +0900
+
+wrt-plugins-common (0.3.50) unstable; urgency=low
+
+  * Re-upload package
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.50
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Tue, 31 Jul 2012 11:35:52 +0900
+
+wrt-plugins-common (0.3.49) unstable; urgency=low
+
+  * Revert "Update dependency".
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.49
+
+ -- Bartlomiej Grzelewski <b.grzelewski@samsung.com>  Mon, 30 Jul 2012 15:30:00 +0200
+
+wrt-plugins-common (0.3.48) unstable; urgency=low
+
+  * Re-upload package
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.48
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Mon, 30 Jul 2012 10:09:01 +0900
+
+wrt-plugins-common (0.3.47) unstable; urgency=low
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.47
+
+ -- Leerang Song <leerang.song@samsung.com>  Fri, 27 Jul 2012 12:16:45 +0900
+
+wrt-plugins-common (0.3.46-1) unstable; urgency=low
+
+  * Fix tag for auto SR
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.46-1
+
+ -- Zbigniew Kostrzewa <z.kostrzewa@samsung.com>  Wed, 25 Jul 2012 15:44:54 +0200
+
+wrt-plugins-common (0.3.46) unstable; urgency=low
+
+  * Upgrade dependencies to wrt-security and security-server
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.46
+
+ -- Zbigniew Kostrzewa <z.kostrzewa@samsung.com>  Wed, 25 Jul 2012 15:34:13 +0200
+
+wrt-plugins-common (0.3.45) unstable; urgency=low
+
+  * readFeatures - performance improvement
+  * Upgrade dependencies
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.45
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Wed, 25 Jul 2012 10:02:39 +0900
+
+wrt-plugins-common (0.3.44) natty; urgency=low
+
+  * fix build error in Plugin_property_support
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.44
+
+ -- Taejeong.lee <taejeong.lee@samsung.com>  Wed, 18 Jul 2012 19:35:41 +0900
+
+wrt-plugins-common (0.3.43) unstable; urgency=low
+
+  * "window.navigator.theme" property support.
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.43
+
+ -- Taejeong.lee <taejeong.lee@samsung.com>  Wed, 18 Jul 2012 17:45:56 +0900
+
+wrt-plugins-common (0.3.42) unstable; urgency=low
+
+  * Fixed CCR(#65374), jira(#WEB-1201)
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.42
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Mon, 16 Jul 2012 11:06:24 +0900
+
+wrt-plugins-common (0.3.41-1) unstable; urgency=low
+
+  * Add tag for auto SR
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.41-1
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 12 Jul 2012 15:59:21 +0900
+
+wrt-plugins-common (0.3.41) unstable; urgency=low
+
+  * Filesystem copy and move permission check fix
+  * Fix format of debian changelog entry
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.41
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 12 Jul 2012 14:20:57 +0900
+
+wrt-plugins-common (0.3.40) unstable; urgency=low
+
+  * Revision to prevent a crash when Web process is terminated by OOM
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.40
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 05 Jul 2012 09:40:36 +0900
+
+wrt-plugins-common (0.3.39) unstable; urgency=low
+
+  * Add TimeUtils API
+  * Change dependency to webkit2
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.39
+
+ -- Tae Jeong Lee <taejeong.lee@samsung.com>  Mon, 02 Jul 2012 15:01:03 +0900
+
+wrt-plugins-common (0.3.38) unstable; urgency=low
+
+  * Implementation of InjectedJavascript
+  * Changed ACE client usage to new C-API
+  * Klocwork fixes
+  * Add load and unload event for frame
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.38
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 28 Jun 2012 16:34:35 +0900
+
+wrt-plugins-common (0.3.37) unstable; urgency=low
+
+  * Seperate js overlay module from widget interface and support new requirment of tizen appservice
+  * clear event listeners for custom event and its JSObject in case of page switch
+  * Fix for w3c-packaging-v9 test
+  * Move classes regarding management of js object to src/Commons
+  * add checking code on event dispatch handler of plugin logic
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.37
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Mon, 11 Jun 2012 15:10:39 +0900
+
+wrt-plugins-common (0.3.36) unstable; urgency=low
+
+  * Removing DSEPARATED_SINGLETON_IMPLEMENTATION flag
+  * Fix generating database for WidgetInterfaceDAO
+  * signalEventByDispatcher() crash fix
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.36
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 31 May 2012 14:19:20 +0900
+
+wrt-plugins-common (0.3.35) unstable; urgency=low
+
+  * Debianize for wrt-plugins-common_0.3.35
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.35
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 24 May 2012 18:16:08 +0900
+
+wrt-plugins-common (0.3.34) unstable; urgency=low
+
+  * Debianize for wrt-plugins-common_0.3.34
+  * Include below changes.
+    - [Security] WrtAccess class implementation changed to safe one.
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.34
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 17 May 2012 18:41:37 +0900
+
+wrt-plugins-common (0.3.33) unstable; urgency=low
+
+  * Fix toLong, toInt, toChar, toSizeT converters
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.33
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 03 May 2012 10:18:10 +0900
+
+wrt-plugins-common (0.3.32) unstable; urgency=low
+
+  * Debianized for wrt-plugins-common_0.3.32
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.32
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 19 Apr 2012 15:48:10 +0900
+
+wrt-plugins-common (0.3.31) unstable; urgency=low
+
+  * Debianized for wrt-plugins-common_0.3.31
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.31
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Mon, 09 Apr 2012 11:41:21 +0900
+
+wrt-plugins-common (0.3.30) unstable; urgency=low
+
+  * Debianized for wrt-plugins-common_0.3.30
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.30
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Mon, 09 Apr 2012 10:25:40 +0900
+
+wrt-plugins-common (0.3.29) unstable; urgency=low
+
+  * Debianized for wrt-plugins-common_0.3.29
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.29
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Fri, 23 Mar 2012 10:15:50 +0900
+
+wrt-plugins-common (0.3.28) unstable; urgency=low
+
+  * Debianized for wrt-plugins-common_0.3.28
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.28
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Tue, 20 Mar 2012 20:32:02 +0900
+
+wrt-plugins-common (0.3.27) unstable; urgency=low
+
+  * Filesystem export API is changed.
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.27
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Fri, 16 Mar 2012 15:19:57 +0900
+
+wrt-plugins-common (0.3.26) unstable; urgency=low
+
+  * Invalid attributes fixed for file
+  * Localization data used for widget interface instead of database
+  * Fix closing DBus connection
+  * wrt-plugins-commons test removing
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.26
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Wed, 14 Mar 2012 19:43:54 +0900
+
+wrt-plugins-common (0.3.25) unstable; urgency=low
+
+  * Support OBS, SMACK
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.25
+
+ -- Yunchan Cho <yunchan.cho@samsung.com>  Tue, 13 Mar 2012 20:04:24 +0900
+
+wrt-plugins-common (0.3.24) unstable; urgency=low
+
+  * Revert 'Loading w3c plugin by default turned off'
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.24
+
+ -- Hoseon LEE <hoseon46.lee@samsung.com>  Sat, 10 Mar 2012 17:23:16 +0100
+
+wrt-plugins-common (0.3.23) unstable; urgency=low
+
+  * Loading w3c plugin by default turned off
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.23
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Fri, 09 Feb 2012 17:23:16 +0100
+
+wrt-plugins-common (0.3.22) unstable; urgency=low
+
+  * Fixed problem with package installation
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.22
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Mon, 05 Feb 2012 16:03:16 +0100
+
+wrt-plugins-common (0.3.21) unstable; urgency=low
+
+  * Debianized for 0.3.21
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.21
+
+ -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Mon, 05 Mar 2012 10:56:10 +0900
+
+wrt-plugins-common (0.3.20) unstable; urgency=low
+
+  * Adjust to changes in wrt-security
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.20
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Tue, 28 Feb 2012 17:43:16 +0100
+
+wrt-plugins-common (0.3.19) unstable; urgency=low
+
+  * Adjust to changes in email-service API.
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.19
+
+ -- Zbigniew Kostrzewa <z.kostrzewa@samsung.com>  Mon, 27 Feb 2012 09:23:46 +0100
+
+wrt-plugins-common (0.3.18-1) unstable; urgency=low
+
+  * Redebinized
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.18-1
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Sat, 25 Feb 2012 11:06:51 +0100
+
+wrt-plugins-common (0.3.18) unstable; urgency=low
+
+  * Camera module turned on (try)
+  * Fixed package dependency
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.18
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Sat, 25 Feb 2012 10:16:51 +0100
+
+wrt-plugins-common (0.3.17) unstable; urgency=low
+
+  * Camera module turned off
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.17
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Fri, 24 Feb 2012 19:36:54 +0100
+
+wrt-plugins-common (0.3.16) unstable; urgency=low
+
+  * Messaging bugfix
+  * Camera: old implementation has been restored
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.16
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Fri, 24 Feb 2012 18:56:54 +0100
+
 wrt-plugins-common (0.3.15) unstable; urgency=low
 
-  * Boilerplate update
+  * Messaging module adjusted to API change in msg-service
 
-  * Git : tizen2/pkgs/w/wrt-plugins-common
+  * Git : slp/pkgs/w/wrt-plugins-common
   * Tag : wrt-plugins-common_0.3.15
 
- -- Tae-Jeong Lee <taejeong.lee@samsung.com>  Thu, 23 Feb 2012 16:16:14 +0900
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Tue, 21 Feb 2012 18:26:14 +0100
 
 wrt-plugins-common (0.3.14) unstable; urgency=low
 
-  * debianize
+  * WAC 2.0 Compliance - Messaging.
 
-  * Git : tizen2/pkgs/w/wrt-plugins-common
+  * Git : slp/pkgs/w/wrt-plugins-common
   * Tag : wrt-plugins-common_0.3.14
 
- -- Yunchan Cho <yunchan.cho@samsung.com>  Wed, 22 Feb 2012 17:06:07 +0900
+ -- Zbigniew Kostrzewa <z.kostrzewa@samsung.com>  Mon, 20 Feb 2012 14:24:09 +0100
 
 wrt-plugins-common (0.3.13) unstable; urgency=low
 
-  * Updated wrt-plugins-common version
+  * Download agent API Change
 
-  * Git : tizen2/pkgs/w/wrt-plugins-common
+  * Git : slp/pkgs/w/wrt-plugins-common
   * Tag : wrt-plugins-common_0.3.13
 
- -- Hoseon LEE <hoseon46.lee@samsung.com>  Wed, 22 Feb 2012 15:13:13 +0900
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Fri, 17 Feb 2012 16:26:14 +0100
 
 wrt-plugins-common (0.3.12) unstable; urgency=low
 
-  * Init changelog
+  * Download agent API Change
 
-  * Git : tizen2/pkgs/w/wrt-plugins-common
+  * Git : slp/pkgs/w/wrt-plugins-common
   * Tag : wrt-plugins-common_0.3.12
 
  -- Hoseon LEE <hoseon46.lee@samsung.com>  Wed, 15 Feb 2012 17:56:14 +0900
+
+wrt-plugins-common (0.3.11) unstable; urgency=low
+
+  * change location of database file for widget interface
+  * Removing SLP, Bada ... strings for Source Open
+  * readAsText() API bug fix
+  * Update Threadpool
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.11
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Tue, 14 Feb 2012 10:23:18 +0900
+
+wrt-plugins-common (0.3.10-1) unstable; urgency=low
+
+  * Debianize for Refactoring Phase2
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.10-1
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Thu, 02 Feb 2012 16:24:20 +0900
+
+wrt-plugins-common (0.3.10) unstable; urgency=low
+
+  * Debianize for Refactoring Phase2
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.10
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Tue, 31 Jan 2012 13:40:17 +0900
+
+wrt-plugins-common (0.3.9-1) unstable; urgency=low
+
+  * Redebianized due to problem with repository
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.9-1
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Wed, 25 Jan 2012 17:05:05 +0100
+
+wrt-plugins-common (0.3.9) unstable; urgency=low
+
+  * Fix bug with plugin unloading
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.9
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Wed, 25 Jan 2012 15:38:19 +0100
+
+wrt-plugins-common (0.3.8) unstable; urgency=low
+
+  * Debianize latest source
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.8
+
+ -- Yunchan Cho <yunchan.cho@samsung.com>  Wed, 25 Jan 2012 10:39:09 +0900
+
+wrt-plugins-common (0.3.7) unstable; urgency=low
+
+  * Repository adopted to new wrt-commons
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.7
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Fri, 20 Jan 2012 16:34:19 +0100
+
+wrt-plugins-common (0.3.6-1) unstable; urgency=low
+
+  * (Redebianized) Modified usage of Ace Thin Client
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.6-1
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Thu, 19 Jan 2012 14:44:39 +0100
+
+wrt-plugins-common (0.3.6) unstable; urgency=low
+
+  * Modified usage of Ace Thin Client
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.6
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Thu, 19 Jan 2012 14:34:29 +0100
+
+wrt-plugins-common (0.3.5) unstable; urgency=low
+
+  * Webkit2(Refactoring) branch merged
+
+  * Git : slp/pkgs/w/wrt-plugins-common
+  * Tag : wrt-plugins-common_0.3.5
+
+ -- Jihoon Chung <jihoon.chung@samsung.com>  Mon, 16 Jan 2012 16:21:49 +0900
+
+wrt-plugins-common (0.3.4) unstable; urgency=low
+
+  * Plugin Manager class implemented.
+
+  * Git : slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.3.4
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Wed, 03 Jan 2011 15:27:19 +0100
+
+wrt-plugins-common (0.3.3) unstable; urgency=low
+
+  * Module names cleaned up. Removed old 'deviceapis' and 'commons' names.
+
+  * Git : slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.3.3
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Fri, 23 Dec 2011 13:17:19 +0100
+
+wrt-plugins-common (0.3.2) unstable; urgency=low
+
+  * Access to WidgetDB modified
+
+  * Git : slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.3.2
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Thu, 22 Dec 2011 15:04:17 +0100
+
+wrt-plugins-common (0.3.1) unstable; urgency=low
+
+  * Installation path for commons modules modified to /usr/lib
+
+  * Git : slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.3.1
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Mon, 19 Dec 2011 14:04:17 +0100
+
+wrt-plugins-common (0.3.0) unstable; urgency=low
+
+  * Debianize 0.3.0 for Webkit2 branch
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.3.0
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Thu, 15 Dec 2011 16:28:32 +0100
+
+wrt-plugins-common (0.2.2) unstable; urgency=low
+
+  * Calendar module fixes
+
+  * Git : slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.2.2
+
+ -- Yunchan Cho <yunchan.cho@samsung.com>  Tue, 20 Dec 2011 10:54:23 +0900
+
+wrt-plugins-common (0.2.1) unstable; urgency=low
+
+  * Apply changed notification macros of email-service
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.2.1
+
+ -- Yunchan Cho <yunchan.cho@samsung.com>  Thu, 15 Dec 2011 15:21:51 +0900
+
+wrt-plugins-common (0.2.0) unstable; urgency=low
+
+  * Debianize 0.2.0
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-plugins-common_0.2.0
+
+ -- Taejeong Lee <taejeong.lee@samsung.com>  Thu, 08 Dec 2011 12:54:32 +0900
+
+wrt-plugins-common (0.1.10) unstable; urgency=low
+
+  * Debianize 0.1.10
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.10
+
+ -- Taejeong Lee <taejeong.lee@samsung.com>  Fri, 02 Dec 2011 16:06:35 +0900
+
+wrt-deviceapis-commons (0.1.9) unstable; urgency=low
+
+  * Debianize for connection manager.
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.9
+
+ -- Taejeong Lee <taejeong.lee@samsung.com>  Tue, 29 Nov 2011 14:05:32 +0900
+
+wrt-deviceapis-commons (0.1.8) unstable; urgency=low
+
+  * Fixed problem with assignment operator
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.8
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Wed, 23 Nov 2011 17:38:22 +0100
+
+wrt-deviceapis-commons (0.1.7) unstable; urgency=low
+
+  * Debianized for SDK release.
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.7
+
+ -- taejeong.lee <taejeong.lee@samsung.com>  Wed, 23 Nov 2011 21:27:15 +0900
+
+wrt-deviceapis-commons (0.1.6) unstable; urgency=low
+
+  * change slp.h to tizen.h
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.6
+
+ -- Jaehyun Park <jaehyun77.park@samsung.com>  Wed, 23 Nov 2011 19:17:27 +0900
+
+wrt-deviceapis-commons (0.1.5) unstable; urgency=low
+
+  * Fixed emmiters behaviour
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.5
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Mon, 21 Nov 2011 14:31:32 +0100
+
+wrt-deviceapis-commons (0.1.4) unstable; urgency=low
+
+  * Fix segmentation fault when msg-service returns NULL body
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.4
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Thu, 10 Nov 2011 11:11:17 +0100
+
+wrt-deviceapis-commons (0.1.3) unstable; urgency=low
+
+  * Upload to package repository
+
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-commons
+  * Tag : wrt-deviceapis-commons_0.1.3
+
+ -- Grzegorz Krawczyk <g.krawczyk@samsung.com>  Tue, 08 Nov 2011 10:21:19 +0100
index 903278c..1b7e1af 100644 (file)
@@ -2,19 +2,19 @@ Source: wrt-plugins-common
 Section: devel
 Priority: extra
 Maintainer: Piotr Fatyga <p.fatyga@samsung.com>, Grzegorz Krawczyk <g.krawczyk@samsung.com>, Zbigniew Kostrzewa <z.kostrzewa@samsung.com>, Taehee Lee <th219.lee@samsung.com>
-Build-Depends: debhelper (>= 5), wrt-dev (>=0.8.6), libwebkit-engine-dev, wrt-commons-dev (>=0.2.6), libmm-player-dev, libmm-sound-dev, libpcre-dev, libdbus-1-dev, libslp-sensor-dev, email-service-dev, libslp-msg-service-dev (>=0.5.0), libslp-calendar-dev, libglib2.0-dev, capi-telephony-network-info-dev, libdevman-dev, libcontacts-service-dev, libdownload-agent-dev, libvconf-dev, libslp-pm-dev, iniparser-dev, libslp-tapi-dev
+Build-Depends: debhelper (>= 5), libwebkit2-efl-dev, wrt-commons-dev (>=0.2.7), libmm-player-dev, libmm-sound-dev, libpcre-dev, libglib2.0-dev, iniparser-dev, wrt-security-dev(>= 0.0.28)
 Uploaders: Hoseon LEE <hoseon46.lee@samsung.com>, Taejeong Lee <taejeong.lee@samsung.com>, Jaehyun Park <jaehyun77.park@samsung.com>
 
 Package: wrt-plugins-common
 Architecture: any
 Section: libs
-Depends: ${shlibs:Depends}, ${misc:Depends}, wrt (>=0.8.6)
+Depends: ${shlibs:Depends}, ${misc:Depends}, wrt-security(>= 0.0.28)
 Description: Common modules for creation JavaScript's plugins
 
 Package: wrt-plugins-common-dev
 Architecture: any
 Section: libs
-Depends: wrt-plugins-common (= ${Source-Version}), libwebkit-engine-dev, wrt-commons-dev (>=0.2.6), wrt-dev
+Depends: wrt-plugins-common (= ${Source-Version}), libwebkit2-efl-dev, wrt-commons-dev (>=0.2.7)
 Description: Common modules for creation JavaScript's plugins -dev
 
 Package: wrt-plugins-common-dbg
index 4f334dc..70b9d33 100755 (executable)
@@ -6,83 +6,40 @@
 # dh-make output file, you may use that output file without restriction.
 # This special exception was added by Craig Small in version 0.37 of dh-make.
 
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
-
-
-# These are used for cross-compiling and for saving the configure script
-# from having to guess our platform (since we know it already)
-DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
-DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-PACKAGE_VERSION ?= $(shell sed -n "1 p" debian/changelog | sed 's/.*(\(.*\)).*/\1/')
-PACKAGE_API_VERSION ?= $(shell sed -n "1 p" debian/changelog | sed 's/.*([0-9]*.\([0-9]*\).*).*/\1/')
-PROJECT_NAME ?= wrt-plugins-common
-
-CFLAGS ?= -Wall -g -fvisibility=default -fPIC
-CXXFLAGS ?=  -Wall -g -fPIC
+PACKAGE_VERSION ?= $(shell dpkg-parsechangelog | sed -n 's/^Version: // p')
 PREFIX ?= /usr
+CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -Wl,--hash-style=both -Wl,--version-script=$(CURDIR)/wrt-plugins-common.map
 
-ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
-       CFLAGS += -O0
-       CXXFLAGS += -O0
-else
-       CFLAGS += -O2
-       CXXFLAGS += -O2
-endif
-
-ifeq (,$(findstring no,$(DPL_LOG)))
+ifeq (,$(findstring no,$(DPL_LOGS)))
        DPL_LOGS_STATUS = "ON"
 else
        DPL_LOGS_STATUS = "OFF"
 endif
 
-LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -Wl,--hash-style=both -Wl,--version-script=$(CURDIR)/wrt-plugins-common.map
-
-ifdef DEVPKG
-       CMAKEFLAGS += -DDEVPKG="$(DEVPKG)"
-endif
-
-
-CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build
-
-#configure: configure-stamp
 configure-stamp:
                dh_testdir
                # Add here commands to configure the package.
                        mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && \
-               CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
-                       cmake ${SRCDIR}  \
-                                 ${CMAKEFLAGS}\
-                                                       -DBUILD_TYPE="${TARGET}" \
-                                                       -DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-                                                       -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)" \
-                                                       -DCMAKE_PACKAGE_VERSION="$(PACKAGE_API_VERSION)" \
-                                                       -DCMAKE_PROJECT_NAME="$(PROJECT_NAME)" \
-                                                       -DDPL_LOG=$(DPL_LOGS_STATUS) ..
-
+               CFLAGS= cmake ${SRCDIR}  \
+                       LDFLAGS="$(LDFLAGS)" \
+                       -DCMAKE_INSTALL_PREFIX="${PREFIX}"      \
+                       -DDPL_LOG=$(DPL_LOGS_STATUS)            \
+                       -DCMAKE_PROJECT_VERSION="$(PACKAGE_VERSION)" ..
 build: build-stamp
 
 build-stamp:  configure-stamp
        dh_testdir
 
        # Add here commands to compile the package.
-       cd $(CMAKE_BUILD_DIR) && $(MAKE) -j5
-
+       cd $(CMAKE_BUILD_DIR) && $(MAKE) -j4
        #docbook-to-man debian/ncurses.sgml > ncurses.1
 
        for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
                cat $$f > $${f%.in}; \
-               sed -i -e "s#@PREFIX@#$(PREFIX)/lib#g" $${f%.in}; \
-               sed -i -e "s#@PREFIX_INCLUDE@#$(PREFIX)/include#g" $${f%.in}; \
+               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
        done
 
-       for f in `find $(CURDIR)/pkgconfigs/ -name "*.in"`; do \
-               cat $$f > $${f%.in}; \
-               sed -i -e "s#@VERSION@#$(PACKAGE_VERSION)#g" $${f%.in}; \
-               sed -i -e "s#@PROJECT_NAME@#$(PROJECT_NAME)#g" $${f%.in}; \
-       done
-
-
        touch $@
 
 clean:
index 09f10db..7fea3e5 100644 (file)
@@ -1,2 +1,4 @@
 
-@PREFIX_INCLUDE@/*
+@PREFIX@/include/*
+@PREFIX@/lib/pkgconfig/*
+@PREFIX@/lib/*.so
index dc18d6c..147bd73 100644 (file)
@@ -1,4 +1,5 @@
-
-@PREFIX@/*
+@PREFIX@/lib/*.so.*
+@PREFIX@/lib/wrt-plugins/*
+@PREFIX@/etc/wrt-plugins/config.dtd
 
 /usr/share/wrt-plugins-common/widget_interface_db.sql
old mode 100755 (executable)
new mode 100644 (file)
index 1a24852..d808af0
@@ -1 +1,6 @@
 #!/bin/sh
+
+mkdir -p /usr/lib/wrt-plugins
+mkdir -p /usr/etc/wrt/injected-javascript
+
+touch /opt/apps/widget/plugin-installation-required
\ No newline at end of file
diff --git a/packaging/wrt-plugins-common.spec b/packaging/wrt-plugins-common.spec
new file mode 100644 (file)
index 0000000..338961f
--- /dev/null
@@ -0,0 +1,87 @@
+#git:framework/web/wrt-plugins-common wrt-plugins-common_0.3.70
+Name:       wrt-plugins-common
+Summary:    wrt-plugins common library
+Version:    0.3.70
+Release:    1
+Group:      Development/Libraries
+License:    Apache License, Version 2.0
+Source0:    %{name}-%{version}.tar.gz
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(dpl-efl)
+BuildRequires: pkgconfig(wrt-plugins-types)
+BuildRequires: pkgconfig(security-client)
+BuildRequires: pkgconfig(dpl-event-efl)
+BuildRequires: pkgconfig(ewebkit2)
+BuildRequires: pkgconfig(dpl-wrt-dao-ro)
+BuildRequires: pkgconfig(dpl-wrt-dao-rw)
+BuildRequires: pkgconfig(dpl-db-efl)
+BuildRequires: pkgconfig(libpcrecpp)
+BuildRequires: pkgconfig(icu-i18n)
+BuildRequires: pkgconfig(libxml-2.0)
+BuildRequires: pkgconfig(cert-svc-vcore)
+Requires:  ldconfig
+
+%description
+JavaScript plugins for WebRuntime
+
+%package devel
+Summary:    wrt-plugins-common library development headers
+Group:      Development/Libraries
+Requires:   %{name} = %{version}
+
+%description devel
+wrt-plugins common library development headers
+
+%prep
+%setup -q
+
+%define with_tests 0
+%if "%{WITH_TESTS}" == "ON" || "%{WITH_TESTS}" == "Y" || "%{WITH_TESTS}" == "YES" || "%{WITH_TESTS}" == "TRUE" || "%{WITH_TESTS}" == "1"
+    %define with_tests 1
+%endif
+
+%build
+export LDFLAGS+="-Wl,--rpath=/usr/lib -Wl,--as-needed -Wl,--hash-style=both"
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}  \
+        -DDPL_LOG="ON"                     \
+        -DCMAKE_PROJECT_VERSION=%{version} \
+        -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} \
+        %{?WITH_TESTS:-DWITH_TESTS=%WITH_TESTS}
+make %{?jobs:-j%jobs}
+
+%install
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+%make_install
+
+%clean
+rm -rf %{buildroot}
+
+%post
+mkdir -p %{_libdir}/wrt-plugins
+mkdir -p /usr/etc/wrt/injected-javascript
+touch /opt/share/widget/plugin-installation-required
+
+%files
+%manifest wrt-plugins-common.manifest
+/usr/etc/wrt-plugins/config.dtd
+%{_libdir}/*.so
+%{_libdir}/*.so.*
+%{_libdir}/wrt-plugins/w3c-widget-interface/libwrt-plugins-w3c-widget-interface.so
+%attr(644,root,root) %{_libdir}/wrt-plugins/standard-features-list
+%attr(644,root,root) /usr/share/wrt-plugins-common/widget_interface_db.sql
+%attr(755,root,root) %{_bindir}/wrt-popup-ace-runtime
+%attr(755,root,root) %{_bindir}/wrt-popup-wrt-runtime
+%attr(755,root,root) %{_bindir}/wrt-plugins-installer
+%{_datadir}/license/%{name}
+
+%if %{with_tests}
+    %attr(755,root,root) %{_bindir}/widgetdb_tests_prepare_db.sh
+    %attr(755,root,root) %{_bindir}/plugins-tests-widgetdb
+%endif
+
+%files devel
+%{_includedir}/*
+%{_libdir}/pkgconfig/*
diff --git a/pkgconfigs/wrt-plugin-js-overlay.pc.in b/pkgconfigs/wrt-plugin-js-overlay.pc.in
new file mode 100644 (file)
index 0000000..7b28b87
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+includedir=${prefix}/include/${project_name}
+
+Name: wrt-plugin-js-overlay
+Description: header for enum value of supported custom js event types
+Version: @CMAKE_PROJECT_VERSION@
+Requires: 
+Libs:
+Cflags: -I${includedir}/js-overlay
diff --git a/pkgconfigs/wrt-plugin-loading.pc.in b/pkgconfigs/wrt-plugin-loading.pc.in
new file mode 100644 (file)
index 0000000..69b9f8f
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: wrt-plugin-loading
+Description: wrt-plugin-loading
+Version: @PROJECT_VERSION@
+Requires: dpl-efl dpl-wrt-dao-ro ewebkit2
+Libs: -lwrt-plugin-loading -L${libdir}
+Cflags: -I${includedir}/wrt-plugin-loading -I${includedir}/wrt-plugins-common
diff --git a/pkgconfigs/wrt-plugins-api-support.pc.in b/pkgconfigs/wrt-plugins-api-support.pc.in
new file mode 100644 (file)
index 0000000..579a085
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=/usr
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: wrt-plugins-api-support
+Description: wrt-plugins-api-support
+Version: @PROJECT_VERSION@
+Requires:
+Libs: -lwrt-plugins-api-support -L${libdir}
+Cflags: -I${includedir}/wrt-plugins-api-support
index f758eb0..b522b22 100644 (file)
@@ -1,12 +1,12 @@
 prefix=/usr
-project_name=@PROJECT_NAME@
+project_name=@CMAKE_PROJECT_NAME@
 exec_prefix=${prefix}
 libdir=${prefix}/lib
 includedir=${prefix}/include/${project_name}
 
 Name: WrtDeviceApis commons with JavaScrpt dependencies
 Description: Commons for DeviceApis with JavaScrpt dependencies
-Version: @VERSION@
-Requires: dpl-efl ewebkit wrt-plugins-commons
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl ewebkit2 wrt-plugins-commons
 Libs: -L${libdir} -lwrt-plugins-commons-javascript
 Cflags: -I${includedir}
index 4b37700..e3c8c7a 100644 (file)
@@ -1,12 +1,12 @@
 prefix=/usr
-project_name=@PROJECT_NAME@
+project_name=@CMAKE_PROJECT_NAME@
 exec_prefix=${prefix}
 libdir=${prefix}/lib
 includedir=${prefix}/include/${project_name}
 
 Name: WrtDeviceApis commons
 Description: Commons for DeviceApis
-Version: @VERSION@
+Version: @CMAKE_PROJECT_VERSION@
 Requires: dpl-efl
 Libs: -L${libdir} -lwrt-plugins-commons
 Cflags: -I${includedir}
index 28f9196..49563e1 100644 (file)
@@ -1,12 +1,12 @@
 prefix=/usr
-project_name=@PROJECT_NAME@
+project_name=@CMAKE_PROJECT_NAME@
 exec_prefix=${prefix}
 libdir=${prefix}/lib
 includedir=${prefix}/include/${project_name}
 
 Name: WebRuntime DeviceApis Filesystem module
 Description: WebRuntime Filesystem module
-Version: @VERSION@
+Version: @CMAKE_PROJECT_VERSION@
 Requires: dpl-efl wrt-plugins-commons
 Libs: -L${libdir} -lwrt-plugins-filesystem
 Cflags: -I${includedir}/Filesystem
index b7e3915..c6a3faa 100644 (file)
@@ -1,12 +1,12 @@
 prefix=/usr
-project_name=@PROJECT_NAME@
+project_name=@CMAKE_PROJECT_NAME@
 exec_prefix=${prefix}
 libdir=${prefix}/lib
 includedir=${prefix}/include/${project_name}
 
 Name: WebRuntime DeviceApis Plugin Manager module
 Description: WebRuntime Plugin Manager module
-Version: @VERSION@
-Requires: dpl-efl wrt-plugins-commons wrt-plugins-commons-javascript dpl-wrt-dao-ro ewebkit
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl wrt-plugins-commons wrt-plugins-commons-javascript dpl-wrt-dao-ro ewebkit2
 Libs: -L${libdir} -lwrt-plugins-plugin-manager
 Cflags: -I${includedir}/PluginManager
diff --git a/pkgconfigs/wrt-plugins-widget-interface-dao.pc.in b/pkgconfigs/wrt-plugins-widget-interface-dao.pc.in
new file mode 100644 (file)
index 0000000..b4ca655
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: WebRuntime DeviceApis Widget Interface module
+Description: WebRuntime Widget Interface module
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl dpl-db-efl wrt-plugins-commons dpl-wrt-dao-ro wrt-plugins-localstorage
+Libs: -L${libdir} -lwrt-plugins-widget-interface-dao
+Cflags: -I${includedir}/WidgetInterfaceDAO
index 46e6b7b..788423a 100644 (file)
@@ -1,12 +1,12 @@
 prefix=/usr
-project_name=@PROJECT_NAME@
+project_name=@CMAKE_PROJECT_NAME@
 exec_prefix=${prefix}
 libdir=${prefix}/lib/
 includedir=${prefix}/include/${project_name}
 
 Name: WebRuntime DeviceApis WidgetDB module
 Description: WebRuntime WidgetDB module
-Version: @VERSION@
+Version: @CMAKE_PROJECT_VERSION@
 Requires: dpl-efl wrt-plugins-commons
 Libs: -L${libdir} -lwrt-plugins-widgetdb
 Cflags: -I${includedir}/WidgetDB
diff --git a/pkgconfigs/wrt-popup-ace-runner.pc.in b/pkgconfigs/wrt-popup-ace-runner.pc.in
new file mode 100644 (file)
index 0000000..ad9605e
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: wrt-popup-runner
+Description:  Library with function to run wrt runtime popup
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl dpl-dbus-efl elementary security-client
+Libs: -L${libdir} -lwrt-popup-ace-runner
+Cflags: -I${includedir}
diff --git a/pkgconfigs/wrt-popup-runner.pc.in b/pkgconfigs/wrt-popup-runner.pc.in
new file mode 100644 (file)
index 0000000..ad9605e
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: wrt-popup-runner
+Description:  Library with function to run wrt runtime popup
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl dpl-dbus-efl elementary security-client
+Libs: -L${libdir} -lwrt-popup-ace-runner
+Cflags: -I${includedir}
diff --git a/pkgconfigs/wrt-popup-wrt-runner.pc.in b/pkgconfigs/wrt-popup-wrt-runner.pc.in
new file mode 100644 (file)
index 0000000..a7b830f
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+project_name=@CMAKE_PROJECT_NAME@
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/${project_name}
+
+Name: wrt-popup-runner
+Description:  Library with function to run wrt runtime popup
+Version: @CMAKE_PROJECT_VERSION@
+Requires: dpl-efl
+Libs: -L${libdir} -lwrt-popup-wrt-runner
+Cflags: -I${includedir}
index ebcff65..9c0d041 100644 (file)
@@ -35,14 +35,26 @@ if("${HOST_ARCH}" MATCHES "armel")
     set(HOST_ARCH "armel")
 endif()
 
-#include directories
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}
-                    ${CMAKE_CURRENT_SOURCE_DIR}/modules/API)
-
 #target names
+set(TARGET_PLUGIN_LOADING_LIB "wrt-plugin-loading")
 set(TARGET_COMMONS "wrt-plugins-commons")
 set(TARGET_COMMONS_JAVASCRIPT "wrt-plugins-commons-javascript")
+set(TARGET_JS_OVERLAY "wrt-plugins-js-overlay")
+SET(TARGET_POPUP_ACE "wrt-popup-ace-runtime")
+SET(TARGET_POPUP_ACE_RUNNER_LIB "wrt-popup-ace-runner")
+SET(TARGET_POPUP_WRT "wrt-popup-wrt-runtime")
+SET(TARGET_POPUP_WRT_RUNNER_LIB "wrt-popup-wrt-runner")
+set(TARGET_PLUGINS_API_SUPPORT "wrt-plugins-api-support")
+
+set(PLUGIN_LOADING_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/plugin-loading)
+set(PLUGINS_API_SUPPORT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/plugins-api-support)
 
+add_subdirectory(plugins-api-support)
+add_subdirectory(plugin-loading)
+add_subdirectory(js-overlay)
 add_subdirectory(Commons)
 add_subdirectory(CommonsJavaScript)
 add_subdirectory(modules)
+add_subdirectory(standards)
+add_subdirectory(wrt-popup)
+add_subdirectory(plugins-installer)
old mode 100755 (executable)
new mode 100644 (file)
index 437cf9f..4d6e3b1
@@ -17,14 +17,9 @@ macro(install_header_file HEADER_FILE)
         DESTINATION ${DESTINATION_HEADERS_NON_JS})
 endmacro()
 
-macro(install_wrtwrapper_header_file HEADER_FILE)
+macro(install_wrtaccess_header_file HEADER_FILE)
     INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
-        DESTINATION ${DESTINATION_HEADERS_NON_JS}/WrtWrapper)
-endmacro()
-
-macro(install_widget_configuration_header_file HEADER_FILE)
-    INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
-        DESTINATION ${DESTINATION_HEADERS_NON_JS}/WidgetConfiguration)
+        DESTINATION ${DESTINATION_HEADERS_NON_JS}/WrtAccess)
 endmacro()
 
 macro(install_widget_interface_dao_header_file HEADER_FILE)
@@ -32,17 +27,18 @@ macro(install_widget_interface_dao_header_file HEADER_FILE)
         DESTINATION ${DESTINATION_HEADERS_NON_JS}/WidgetInterfaceDAO)
 endmacro()
 
-include_config_file(WrtWrapper)
-include_config_file(WidgetConfiguration)
+include_config_file(WrtAccess)
 
-pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=0.7.0)
-pkg_search_module(wrt-ace-client REQUIRED wrt-ace-client)
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
+pkg_search_module(ace-client REQUIRED security-client)
 pkg_search_module(dpl-event REQUIRED dpl-event-efl)
+pkg_search_module(icu REQUIRED icu-i18n)
 
 set(WRT_COMMONS_DEPENDECIES_INCLUDES
-    ${INCLUDE_JS_INDEPENDENT}
     ${wrt-plugin-api_INCLUDE_DIRS}
-    ${wrt-ace-client_INCLUDE_DIRS}
+    ${ace-client_INCLUDE_DIRS}
+    ${plugin-types_INCLUDE_DIRS}
+    ${icu_INCLUDE_DIRS}
     )
 
 include_directories(${WRT_COMMONS_DEPENDECIES_INCLUDES})
@@ -50,8 +46,7 @@ include_directories(${WRT_COMMONS_DEPENDECIES_INCLUDES})
 set(TARGET_NAME ${TARGET_COMMONS})
 
 set(SRCS
-  ${SRCS_WRT_WRAPPER}
-  ${SRCS_WIDGET_CONFIGURATION}
+  ${SRCS_WRT_ACCESS}
   ${CMAKE_CURRENT_SOURCE_DIR}/Base64.cpp
   ${CMAKE_CURRENT_SOURCE_DIR}/FunctionDefinition.cpp
   ${CMAKE_CURRENT_SOURCE_DIR}/Regex.cpp
@@ -59,16 +54,25 @@ set(SRCS
   ${CMAKE_CURRENT_SOURCE_DIR}/StringBuilder.cpp
   ${CMAKE_CURRENT_SOURCE_DIR}/StringUtils.cpp
   ${CMAKE_CURRENT_SOURCE_DIR}/ThreadPool.cpp
+  ${CMAKE_CURRENT_SOURCE_DIR}/JSObjectDeclaration.cpp
+  ${CMAKE_CURRENT_SOURCE_DIR}/JSObject.cpp
+  ${CMAKE_CURRENT_SOURCE_DIR}/TimeUtils.cpp
   #PARENT_SCOPE
 )
 
 add_library(${TARGET_NAME} SHARED ${SRCS})
 target_link_libraries(${TARGET_NAME}
   ${LIBS_COMMONS}
-  ${wrt-ace-client_LIBRARIES}
+  ${ace-client_LIBRARIES}
   ${dpl-event_LIBRARIES}
+  ${icu_LIBRARIES}
+  ${TARGET_POPUP_ACE_RUNNER_LIB}
+)
+
+set_target_properties(${TARGET_NAME} PROPERTIES
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX})
 
@@ -96,9 +100,7 @@ install_header_file(ThreadPool.h)
 install_header_file(TypesDeclaration.h)
 install_header_file(TypeTraits.h)
 install_header_file(plugin_initializer_def.h)
-install_wrtwrapper_header_file(WrtWrapper/IWrtCamera.h)
-install_wrtwrapper_header_file(WrtWrapper/IWrtCameraManager.h)
-install_wrtwrapper_header_file(WrtWrapper/IWrtWrapper.h)
-install_wrtwrapper_header_file(WrtWrapper/WrtWrappersMgr.h)
-install_widget_configuration_header_file(WidgetConfiguration/WidgetConfiguration.h)
-install_widget_configuration_header_file(WidgetConfiguration/ConfigurationSupport.h)
+install_header_file(JSObjectDeclaration.h)
+install_header_file(JSObject.h)
+install_header_file(TimeUtils.h)
+install_wrtaccess_header_file(WrtAccess/WrtAccess.h)
index 5506695..0768e05 100644 (file)
@@ -71,9 +71,18 @@ class EventReceiver :
     void signalEventByDispatcher(const DPL::SharedPtr<TemplateEvent> &event)
     {
         LogDebug("in");
-        DPL::Event::AbstractEventDispatcher *dispatcher =
-            ThreadPool::getInstance().getDispatcher(m_threadDispatcher);
-        dispatcher->AddEventCall(new SignalEventCall<TemplateEvent>(event));
+        Try {
+            DPL::Event::AbstractEventDispatcher *dispatcher =
+                ThreadPool::getInstance().getDispatcher(m_threadDispatcher);
+            dispatcher->AddEventCall(new SignalEventCall<TemplateEvent>(event));
+        }
+        Catch(DPL::Thread::Exception::UnmanagedThread) {
+            // if called on unmanaged thread,
+            // call signalSynchronousEventFlag() directly
+            LogDebug("signalSynchronousEventFlag() is called"
+                     "by unmanaged thread");
+            event->signalSynchronousEventFlag();
+        }
     }
 
     virtual ~EventReceiver()
index f93db50..23d3322 100644 (file)
 #include <string>
 #include <algorithm>
 #include <dpl/log/log.h>
-#include <Commons/WrtWrapper/WrtWrappersMgr.h>
+#include <Commons/WrtAccess/WrtAccess.h>
 #include <Commons/Exception.h>
 #include <Commons/TypesDeclaration.h>
 #include <Commons/TypeTraits.h>
+#include <Commons/plugin_initializer_def.h>
 
 #define ACE_DECLARE_FUNCTION(function_definition) \
     extern WrtDeviceApis::Commons::AceFunction ace_ ## function_definition
@@ -132,23 +133,18 @@ template <typename FunctionGetter,
           typename ArgumentsVerifier,
           typename ... Args>
 AceSecurityStatus aceCheckAccess(
-        JavaScriptContext globalContext,
         const FunctionGetter& f,
         const char* functionName,
         Args && ... args)
 {
+    using namespace WrtDeviceApis::Commons;
+
     AceFunction aceFunction = f(functionName);
 
     ArgumentsVerifier argsVerify;
     argsVerify(aceFunction, args ...);
 
-    IWrtWrapperPtr wrapper =
-        WrtWrappersMgr::getInstance().getWrtWrapper(globalContext);
-    if (!wrapper) {
-        LogError("Wrapper doesn't exist.");
-        return AceSecurityStatus::InternalError;
-    }
-    if (!(wrapper->checkAccess(aceFunction))) {
+    if (!(WrtAccessSingleton::Instance().checkAccessControl(aceFunction))) {
         LogDebug("Function is not allowed to run");
         return AceSecurityStatus::AccessDenied;
     }
index 9abfb23..6ff743f 100644 (file)
@@ -77,6 +77,7 @@ class IEvent : /*private DPL::WaitableEvent, */ public IEventController
     friend class EventRequestReceiver<Super>;
     friend class EventAnswerReceiver<Super>;
     friend class SignalEventCall<Super>;
+    friend class EventReceiver<Super>;
 
     enum HandlingType
     {
diff --git a/src/Commons/JSObject.cpp b/src/Commons/JSObject.cpp
new file mode 100644 (file)
index 0000000..70488f1
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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    js_object.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "JSObject.h"
+#include <dpl/log/log.h>
+
+JSObject::JSObject(RealObject object) : m_object(object)
+{
+    if (!object) {
+        LogError("Object is NULL");
+    }
+}
+
+JSObject::RealObject JSObject::getObject() const
+{
+    return m_object;
+}
diff --git a/src/Commons/JSObject.h b/src/Commons/JSObject.h
new file mode 100644 (file)
index 0000000..a5ef354
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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    js_object.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_H_
+#define WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_H_
+
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+
+class JSObject : private DPL::Noncopyable
+{
+  public:
+    typedef void* RealObject;
+
+  public:
+    explicit JSObject(RealObject object);
+
+    /**
+     * returns javascript engine object
+     * @throw NullPtrException
+     * */
+    virtual RealObject getObject() const;
+
+    virtual ~JSObject()
+    {
+    }
+
+  private:
+    RealObject m_object;
+};
+
+typedef DPL::SharedPtr<JSObject> JSObjectPtr;
+
+#endif
diff --git a/src/Commons/JSObjectDeclaration.cpp b/src/Commons/JSObjectDeclaration.cpp
new file mode 100644 (file)
index 0000000..46a3da3
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * 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    js_object_declaration.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include "JSObjectDeclaration.h"
+
+JSObjectDeclaration::JSObjectDeclaration(js_entity_definition_ptr_t classD) :
+    m_name(classD->object_name),
+    m_parentName(classD->parent_name),
+    m_interfaceName(classD->interface_name),
+    m_classTemplate(NULL),
+    m_constructorCallback(classD->js_class_constructor_cb)
+{
+    if (NULL != classD->js_class_template_getter_fun)
+    {
+        m_classTemplate = classD->js_class_template_getter_fun();
+    }
+    if(classD->class_options){
+        LogDebug("class options is not a null");
+        m_options = OptionsPtr(new Options(classD->class_options));
+    }
+}
+
+JSObjectDeclaration::~JSObjectDeclaration()
+{
+}
+
+bool JSObjectDeclaration::checkIframesSupported() const{
+    LogDebug("Check iframe supported");
+    if(!m_options ||
+       m_options->getIframeObject() == Options::IFrameObject::None)
+    {
+        LogDebug("Iframe NOT supported for object: " << getName());
+        return false;
+    }
+
+    LogDebug("Iframe supported for object: " << getName());
+
+    return true;
+}
+
+JSObjectDeclaration::Options::ClassType
+    JSObjectDeclaration::Options::getType() const
+{
+    LogDebug("Get type field from declaration's option");
+    Assert(m_options && "Pointer to options is NULL");
+
+    switch(m_options->type){
+    case JS_CLASS: return ClassType::Class;
+    case JS_FUNCTION: return ClassType::Function;
+    case JS_INTERFACE: return ClassType::Interface;
+    default: Assert(0 && "Wrong value of type");
+    }
+}
+
+JSObjectDeclaration::Options::IFrameObject
+    JSObjectDeclaration::Options::getIframeObject() const
+{
+    LogDebug("Get Frame Option");
+    Assert(m_options && "Options object is NULL");
+
+    switch(m_options->iframe_option){
+    case NONE: return IFrameObject::None;
+    case REFERENCE: return IFrameObject::Reference;
+    case CREATE_INSTANCE: return IFrameObject::CreateInstance;
+    default:
+        Assert(0 && "Wrong value of behaviour type");
+    }
+}
+
+JSObjectDeclaration::Options::IFrameNotice
+    JSObjectDeclaration::Options::getIframeNotice() const
+{
+    LogDebug("Get Frame Option");
+    Assert(m_options && "Pointer to options is null");
+
+    switch(m_options->iframe_notice){
+    case NONE_NOTICE: return IFrameNotice::None;
+    case ALWAYS_NOTICE: return IFrameNotice::AlwaysNotice;
+    default:
+        Assert(0 && "Wrong value of notice option");
+    }
+}
+
+JSObjectDeclaration::Options::IFrameOverlay
+    JSObjectDeclaration::Options::getIframeOverlay() const
+{
+    LogDebug("Get Frame Option");
+    Assert(m_options && "Pointer to options is null");
+
+    switch(m_options->iframe_overlay){
+    case IGNORED: return IFrameOverlay::Ignored;
+    case USE_OVERLAYED: return IFrameOverlay::UseOverlayed;
+    case OVERLAYED_BEFORE_ORIGINAL:
+            return IFrameOverlay::OverlayedBeforeOriginal;
+    default:
+        Assert(0 && "Wrong value of overlay option");
+    }
+}
+
+js_function_impl JSObjectDeclaration::Options::getFunctionImpl() const
+{
+    Assert(m_options && "Pointer to options is null");
+    return m_options->function;
+}
+
+void JSObjectDeclaration::Options::invokeCallback(JsContext ctx,
+                                                  ObjectInstance iframe,
+                                                  ObjectInstance object) const
+{
+    LogDebug("JS Object create, notice.");
+    Assert(m_options && m_options->cb && "Empty callback pointer");
+    m_options->cb(ctx, iframe, object);
+}
+
+JSObjectDeclaration::Options::PrivateData
+    JSObjectDeclaration::Options::getPrivateData() const
+{
+    Assert(m_options && m_options->private_data && "empty private data");
+    return m_options->private_data;
+}
diff --git a/src/Commons/JSObjectDeclaration.h b/src/Commons/JSObjectDeclaration.h
new file mode 100644 (file)
index 0000000..fa14dce
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * 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    js_object_declaration.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
+#define WRT_SRC_PLUGIN_SERVICE_JS_OBJECT_DECLARATION_H_
+
+#include <string>
+#include <memory>
+#include <cassert>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <dpl/log/log.h>
+#include <wrt_plugin_export.h>
+
+class JSObjectDeclaration : private DPL::Noncopyable
+{
+  public:
+    typedef const void* ConstClassTemplate;
+    typedef void* ClassTemplate;
+    typedef js_class_constructor_cb_t ConstructorCallback;
+    typedef class_definition_options_t ClassOptions;
+
+
+    class Options : DPL::Noncopyable {
+      public:
+        enum class ClassType{
+            Class,
+            Function,
+            Interface
+        };
+
+        enum class IFrameObject{
+            None,
+            Reference,
+            CreateInstance
+        };
+
+        enum class IFrameNotice{
+            None,
+            AlwaysNotice
+        };
+
+        //only for function
+        enum class IFrameOverlay{
+           Ignored,
+           UseOverlayed,
+           OverlayedBeforeOriginal
+        };
+
+        typedef js_object_instance_t ObjectInstance;
+        typedef java_script_context_t JsContext;
+        typedef void* PrivateData;
+
+        public:
+          ClassType getType() const;
+
+          IFrameObject getIframeObject() const;
+          IFrameNotice getIframeNotice() const;
+          IFrameOverlay getIframeOverlay() const;
+          js_function_impl getFunctionImpl() const;
+
+          void invokeCallback(JsContext ctx,
+                              ObjectInstance iframe,
+                              ObjectInstance object) const;
+
+          PrivateData getPrivateData() const;
+
+        private:
+          const ClassOptions* m_options;
+
+        private:
+          explicit Options(const ClassOptions* options) : m_options(options)
+        {
+            assert(options && "Dont create empty options");
+        }
+
+        friend class JSObjectDeclaration;
+
+    };
+
+    typedef std::shared_ptr<Options> OptionsPtr;
+
+  public:
+
+    explicit JSObjectDeclaration(js_entity_definition_ptr_t declaration);
+
+    virtual const std::string& getName() const
+    {
+        return m_name;
+    }
+
+    virtual const std::string& getParentName() const
+    {
+        return m_parentName;
+    }
+
+    virtual ConstClassTemplate getClassTemplate() const
+    {
+        return m_classTemplate;
+    }
+
+    virtual const std::string& getInterfaceName() const
+    {
+        return m_interfaceName;
+    }
+
+    virtual ConstructorCallback getConstructorCallback() const
+    {
+        return m_constructorCallback;
+    }
+
+
+    const OptionsPtr getOptions() const{
+        return m_options;
+    }
+
+    bool checkIframesSupported() const;
+
+    virtual ~JSObjectDeclaration();
+
+  private:
+    std::string m_name;
+    std::string m_parentName;
+    std::string m_interfaceName;
+    ConstClassTemplate m_classTemplate;
+    ConstructorCallback m_constructorCallback;
+    OptionsPtr m_options;
+};
+
+typedef DPL::SharedPtr<JSObjectDeclaration> JSObjectDeclarationPtr;
+
+#endif
index 4795131..1fe0b7a 100644 (file)
@@ -17,8 +17,6 @@
 #include <algorithm>
 #include <iterator>
 #include <new>
-#include <sstream>
-#include <Commons/Exception.h>
 #include "StringUtils.h"
 
 namespace WrtDeviceApis {
@@ -106,7 +104,7 @@ char* strdup(const char* str)
 }
 
 std::string merge(const std::vector<std::string>& strs,
-        std::string::value_type delim)
+                  std::string::value_type delim)
 {
     typedef std::vector<std::string> Strings;
 
@@ -138,16 +136,11 @@ std::vector<std::string> split(const std::string& str,
     return result;
 }
 
-int toInt(const std::string &text)
+int toInt(const std::string& str)
 {
-    int result;
-    std::stringstream ss(text);
-    if (!(ss >> result)) {
-        Throw(ConversionException);
-    }
-    return result;
+    return convertTo<int>(str);
 }
 
 }
 }
-} // WrtDeviceApisCommon
+}
index be6bcc8..ee7cbe8 100644 (file)
  *    See the License for the specific language governing permissions and
  *    limitations under the License.
  */
+/**
+ * @file   StringUtils.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
 #ifndef WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
 #define WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
 
 #include <string>
 #include <vector>
+#include <sstream>
+#include <utility>
+#include <Commons/Exception.h>
+#include <Commons/Deprecated.h>
 
 namespace WrtDeviceApis {
 namespace Commons {
@@ -50,8 +59,7 @@ std::string trim(const std::string& str);
  * @param startStr String to be found at the beginning of str.
  * @return true when str starts with startStr, false otherwise.
  */
-bool startsWith(const std::string& str,
-        const std::string& startStr);
+bool startsWith(const std::string& str, const std::string& startStr);
 
 /**
  * Checks if str ends with startStr
@@ -59,8 +67,7 @@ bool startsWith(const std::string& str,
  * @param endStr String to be found at the end of str.
  * @return true when str starts with startStr, false otherwise.
  */
-bool endsWith(const std::string& str,
-        const std::string& endStr);
+bool endsWith(const std::string& str, const std::string& endStr);
 
 /**
  * Merges consecutive groups of duplicate characters into one.
@@ -75,8 +82,7 @@ bool endsWith(const std::string& str,
  * ...
  * @endcode
  */
-std::string unique(const std::string& str,
-        const char needle);
+std::string unique(const std::string& str, const char needle);
 
 /**
  * Checks if supplied string exists in specified array of c-strings.
@@ -86,8 +92,7 @@ std::string unique(const std::string& str,
  * @remarks Last element of array should be NULL, otherwise there is no
  *          way to calculate its number of elements.
  */
-bool inCStringArray(const std::string& needle,
-        const char* stack[]);
+bool inCStringArray(const std::string& needle, const char* stack[]);
 
 /**
  * Duplicates a string.
@@ -104,15 +109,61 @@ inline char* strdup(const std::string& str)
 }
 
 std::string merge(const std::vector<std::string>& strs,
-        std::string::value_type delim);
+                  std::string::value_type delim);
 
 std::vector<std::string> split(const std::string& str,
-        std::string::value_type delim);
+                               std::string::value_type delim);
 
-int toInt(const std::string &text);
+/**
+ * @deprecated Use convertTo<int>().
+ */
+int toInt(const std::string& str) WRT_PLUGINS_DEPRECATED;
 
-} // String
+/**
+ * Converts string to specified type.
+ *
+ * @tparam T Type to convert to.
+ * @param str String to convert.
+ * @return Converted value.
+ * @throw ConversionException If conversion fails.
+ *
+ * @remarks T must implement default constructor and an implementation
+ *          of input string operator for T must exist.
+ */
+template<typename T>
+T convertTo(const std::string& str)
+{
+    T result;
+    std::istringstream iss(str);
+    if (!(iss >> result)) {
+        Throw(ConversionException);
+    }
+    return std::move(result);
+}
+
+/**
+ * Converts a given value to string.
+ *
+ * @tparam T Type of the value to convert. It is deduced by the compiler.
+ * @param data Value to convert.
+ * @return Value converted to string.
+ * @throw ConversionException If operation fails.
+ *
+ * @remarks Output stream operator for type T must exist.
+ */
+template<typename T>
+std::string parse(const T& data)
+{
+    std::ostringstream oss;
+    if (!(oss << data))
+    {
+        Throw(ConversionException);
+    }
+    return oss.str();
+}
+
+}
+}
 }
-} // WrtDeviceApisCommon
 
-#endif // WRTDEVICEAPIS_COMMONS_STRINGUTILS_H_
+#endif
index d074cb3..5ec65eb 100755 (executable)
@@ -123,9 +123,6 @@ DPL::Thread *ThreadPool::getThreadRef(ThreadEnum::Enumeration type)
     case ThreadEnum::CONTACT_THREAD:
         thandle = getThreadHandleCreateIfNotExists(ThreadEnum::CONTACT_THREAD);
         break;
-    case ThreadEnum::MMPLAYER_THREAD:
-        thandle = getThreadHandleCreateIfNotExists(ThreadEnum::MMPLAYER_THREAD);
-        break;
     case ThreadEnum::BONDI_THREAD:
         thandle = getThreadHandleCreateIfNotExists(ThreadEnum::BONDI_THREAD);
         break;
@@ -187,6 +184,18 @@ DPL::Thread *ThreadPool::getThreadRef(ThreadEnum::Enumeration type)
     case ThreadEnum::MEDIACONTENT_THREAD:
         thandle = getThreadHandleCreateIfNotExists(ThreadEnum::MEDIACONTENT_THREAD);
         break;
+    case ThreadEnum::SE_THREAD:
+        thandle = getThreadHandleCreateIfNotExists(ThreadEnum::SE_THREAD);
+        break;
+    case ThreadEnum::DOWNLOAD_THREAD:
+        thandle = getThreadHandleCreateIfNotExists(ThreadEnum::DOWNLOAD_THREAD);
+        break;
+    case ThreadEnum::PUSH_THREAD:
+        thandle = getThreadHandleCreateIfNotExists(ThreadEnum::PUSH_THREAD);
+        break;
+    case ThreadEnum::SYNC_THREAD:
+        thandle = getThreadHandleCreateIfNotExists(ThreadEnum::SYNC_THREAD);
+        break;
     // .....
     default:
         LogError("no case statement for ThreadEnum");
index 6a27a7c..7ee9ed6 100755 (executable)
@@ -52,7 +52,6 @@ class ThreadEnum
         APPCONFIG_THREAD,
         GALLERY_THREAD,
         CONTACT_THREAD,
-        MMPLAYER_THREAD,
         BONDI_THREAD,
         GEOLOCATION_THREAD,
         DEVICESTATUS_THREAD,
@@ -64,14 +63,18 @@ class ThreadEnum
         POWER_THREAD,
         PLUGIN_TEMPLETE_THREAD,
         BLUETOOTH_THREAD,
-       APPLICATION_THREAD,
+        APPLICATION_THREAD,
         GYROSCOPE_THREAD,
-       CLOCK_THREAD,
+        CLOCK_THREAD,
         SYSTEMINFO_THREAD,
-       CALLHISTORY_THREAD,
-       ACCOUNT_THREAD,
+        CALLHISTORY_THREAD,
+        ACCOUNT_THREAD,
         NFC_THREAD,
-       MEDIACONTENT_THREAD,
+        MEDIACONTENT_THREAD,
+        SE_THREAD,
+        DOWNLOAD_THREAD,
+        PUSH_THREAD,
+        SYNC_THREAD,
         //....
         size
     };
diff --git a/src/Commons/TimeUtils.cpp b/src/Commons/TimeUtils.cpp
new file mode 100644 (file)
index 0000000..0467c03
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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   TimeUtils.h
+ * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
+ */
+
+#include "TimeUtils.h"
+#include <unicode/ucal.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+namespace Time {
+
+struct tm* localtime_r(long long int* timep, struct tm* result)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    UCalendar *cal;
+
+    if( !result || !timep )
+    {
+        return NULL;
+    }
+
+    cal = ucal_open(NULL, 0, NULL, UCAL_DEFAULT, &status);
+
+    if(U_FAILURE(status))
+    {
+        return NULL;
+    }
+
+    ucal_setMillis(cal, (*timep * (double)1000.0), &status);
+
+    result->tm_sec  = ucal_get(cal, UCAL_SECOND,       &status);
+    result->tm_min  = ucal_get(cal, UCAL_MINUTE,       &status);
+    result->tm_hour = ucal_get(cal, UCAL_HOUR,         &status);
+    result->tm_mday = ucal_get(cal, UCAL_DAY_OF_MONTH, &status);
+    result->tm_mon  = ucal_get(cal, UCAL_MONTH,        &status);
+    result->tm_year = ucal_get(cal, UCAL_YEAR,         &status);
+    result->tm_wday = ucal_get(cal, UCAL_DAY_OF_WEEK,  &status);
+    result->tm_yday = ucal_get(cal, UCAL_DAY_OF_YEAR,  &status);
+    result->tm_isdst= ucal_get(cal, UCAL_DST_OFFSET,   &status);
+
+    ucal_close(cal);
+
+    if(U_FAILURE(status))
+    {
+        return NULL;
+    }
+    else
+    {
+        return result;
+    }
+}
+
+}
+}
+}
diff --git a/src/Commons/TimeUtils.h b/src/Commons/TimeUtils.h
new file mode 100644 (file)
index 0000000..27e4038
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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   TimeUtils.h
+ * @author Tae-Jeong Lee (taejeong.lee@samsung.com)
+ */
+
+#ifndef WRTDEVICEAPIS_COMMONS_TIMEUTILS_H_
+#define WRTDEVICEAPIS_COMMONS_TIMEUTILS_H_
+
+#include <time.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+namespace Time {
+
+struct tm* localtime_r(long long int* timep, struct tm* result);
+
+}
+}
+}
+#endif
diff --git a/src/Commons/WrtAccess/WrtAccess.cpp b/src/Commons/WrtAccess/WrtAccess.cpp
new file mode 100644 (file)
index 0000000..b1f5850
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+ * 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.
+ */
+/*
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <memory>
+#include <sstream>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_array.h>
+#include <dpl/scoped_resource.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include "WrtAccess.h"
+#include <ace_api_client.h>
+#include <dpl/singleton_safe_impl.h>
+
+#include "popup-runner.h"
+IMPLEMENT_SAFE_SINGLETON(WrtDeviceApis::Commons::WrtAccess)
+
+namespace {
+
+/**
+ * Helper class - single parameter and its value
+ */
+struct AceParam
+{
+    const char *name;
+    const char *value;
+
+    AceParam():
+        name(NULL), value(NULL)
+    {}
+
+    AceParam(const char *name, const char *value):
+        name(name), value(value)
+    {}
+};
+
+/**
+ * Helper class - list of params for single dev cap
+ */
+struct AceParamList
+{
+    size_t    count;
+    AceParam* param;
+    AceParamList():
+        count(0),
+        param(NULL)
+    {}
+};
+
+struct DeviceCapParamPolicy
+{
+    typedef AceParamList* Type;
+    static Type NullValue()
+    {
+        return NULL;
+    }
+    static void Destroy(Type ptr)
+    {
+        if (ptr) {
+            delete[] ptr->param;
+        }
+        delete[] ptr;
+    }
+};
+
+/**
+ * Helper class - modified ScopedArray for ace_param_list_t
+ */
+class ScopedDeviceCapArray : public DPL::ScopedResource<DeviceCapParamPolicy>
+{
+  public:
+    explicit ScopedDeviceCapArray(AceParamList *ptr =
+                DeviceCapParamPolicy::NullValue()) :
+        DPL::ScopedResource<DeviceCapParamPolicy>(ptr)
+    {
+    }
+
+    AceParamList & operator [](std::ptrdiff_t k) const
+    {
+        Assert(this->m_value != DeviceCapParamPolicy::NullValue() &&
+               "Dereference of scoped NULL array!");
+        Assert(k >= 0 && "Negative array index");
+
+        return this->m_value[k];
+    }
+};
+} // namespace
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+WrtAccess::WrtAccess() :
+        m_initialized(false),
+        m_sessionId(GenerateSessionId())
+{
+}
+
+WrtAccess::~WrtAccess()
+{
+}
+
+WrtAccess::SessionId WrtAccess::GenerateSessionId()
+{
+    const size_t SESSION_ID_LENGTH = 32;
+
+    std::ostringstream pid;
+    pid << static_cast<int> (getpid());
+
+    std::string session_id = pid.str();
+
+    session_id.reserve(session_id.length() + SESSION_ID_LENGTH);
+
+    for (size_t i = 0; i < SESSION_ID_LENGTH; ++i)
+    {
+        int c = random() % 16;
+
+        session_id +=  (c < 10 ?
+                        static_cast<char>('0' + c) :
+                        static_cast<char>('A' + c - 10));
+    }
+    return session_id;
+}
+
+void WrtAccess::initialize(int widgetId)
+{
+    LogDebug("initialize");
+    if (widgetId < 0)
+    {
+        LogDebug("Invalid widget id");
+        Throw(Exception);
+    }
+    ace_return_t ret = ace_client_initialize(Wrt::Popup::run_popup);
+    Assert(ACE_OK == ret);
+    m_initialized = true;
+    m_widgetId = widgetId;
+}
+
+void WrtAccess::deinitialize(int /*widgetId*/)
+{
+    LogDebug("deinitialize");
+    m_initialized = false;
+    ace_return_t ret = ace_client_shutdown();
+    Assert(ACE_OK == ret);
+}
+
+int WrtAccess::getWidgetId() const
+{
+    return m_widgetId;
+}
+
+bool WrtAccess::checkAccessControl(const AceFunction& aceFunction) const
+{
+    Assert(m_initialized && "WrtAccessSingleton needs to be initialized with"
+            "WidgetId during on_widget_start_callback in each plugin");
+    size_t deviceCount = aceFunction.deviceCapabilities.size();
+
+    DPL::ScopedArray <const char *> deviceScopedArray;
+    ScopedDeviceCapArray paramsScopedArray;
+
+    if (deviceCount) {
+        deviceScopedArray.Reset(new const char*[deviceCount]);
+        paramsScopedArray.Reset(new AceParamList[deviceCount]);
+
+        for (size_t i = 0; i < deviceCount; ++i) {
+            deviceScopedArray[i] =
+                aceFunction.deviceCapabilities.at(i).devCapName.c_str();
+            paramsScopedArray[i].count =
+                aceFunction.deviceCapabilities.at(i).devCapParams.size();
+
+            paramsScopedArray[i].param =
+                new AceParam[paramsScopedArray[i].count];
+
+            for (size_t j = 0; j < paramsScopedArray[i].count; ++j) {
+                paramsScopedArray[i].param[j].name =
+                    aceFunction.deviceCapabilities.at(i).
+                        devCapParams[j].name.c_str();
+                paramsScopedArray[i].param[j].value =
+                    aceFunction.deviceCapabilities.at(i).
+                        devCapParams[j].value.c_str();
+            }
+        }
+    }
+
+    size_t featuresCount = aceFunction.features.size();
+
+    DPL::ScopedArray <const char*> featureScopedArray;
+    if (featuresCount) {
+        featureScopedArray.Reset(new const char*[featuresCount]);
+
+        for (size_t i = 0; i < featuresCount; ++i) {
+            featureScopedArray[i] =
+                aceFunction.features.at(i).name.c_str();
+        }
+    }
+
+    LogDebug("constructing ACE request");
+
+    ace_request_t aceRequest;
+    aceRequest.session_id = const_cast<const ace_session_id_t>(m_sessionId.c_str());
+    aceRequest.widget_handle = getWidgetId();
+    aceRequest.feature_list.count = featuresCount;
+    aceRequest.feature_list.items = const_cast<ace_string_t*>(featureScopedArray.Get());
+    aceRequest.dev_cap_list.count = deviceCount;
+    aceRequest.dev_cap_list.items = new ace_dev_cap_t[deviceCount];
+
+    const char**  devCapNames = deviceScopedArray.Get();
+    AceParamList* paramList = paramsScopedArray.Get();
+
+    unsigned int i;
+    for (i = 0; i < deviceCount; ++i) {
+        aceRequest.dev_cap_list.items[i].name =
+                const_cast<const ace_string_t>(devCapNames[i]);
+        aceRequest.dev_cap_list.items[i].param_list.count = paramList[i].count;
+        aceRequest.dev_cap_list.items[i].param_list.items =
+                new ace_param_t[paramList[i].count];
+        unsigned int j;
+        for (j = 0; j < paramList[i].count; ++j) {
+            aceRequest.dev_cap_list.items[i].param_list.items[j].name =
+                    const_cast<ace_string_t>(paramList[i].param[j].name);
+            aceRequest.dev_cap_list.items[i].param_list.items[j].value =
+                    const_cast<ace_string_t>(paramList[i].param[j].value);
+        }
+    }
+
+    ace_bool_t aceCheckResult = ACE_FALSE;
+    ace_return_t ret = ace_check_access(&aceRequest, &aceCheckResult);
+
+    for (i = 0; i < deviceCount; ++i) {
+        delete [] aceRequest.dev_cap_list.items[i].param_list.items;
+    }
+    delete [] aceRequest.dev_cap_list.items;
+
+    if (ACE_OK != ret) {
+        LogError("Error in ace check: " << static_cast<int>(ret));
+        return false;
+    }
+    return ACE_TRUE == aceCheckResult;
+}
+
+}
+} // WrtDeviceApisCommon
diff --git a/src/Commons/WrtAccess/WrtAccess.h b/src/Commons/WrtAccess/WrtAccess.h
new file mode 100644 (file)
index 0000000..574324f
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+/*
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_WRT_ACCESS_H_
+#define WRT_PLUGINS_WRT_ACCESS_H_
+
+#include <string>
+
+#include <dpl/singleton.h>
+#include <Commons/TypesDeclaration.h>
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+class WrtAccess
+{
+public:
+    void initialize(int widgetId);
+    void deinitialize(int widgetId);
+    int getWidgetId() const;
+    bool checkAccessControl(const AceFunction &aceFunction) const;
+
+private:
+
+    typedef std::string SessionId;
+    SessionId GenerateSessionId();
+
+    WrtAccess();
+    virtual ~WrtAccess();
+
+    bool m_initialized;
+    int m_widgetId;
+    SessionId m_sessionId;
+
+    friend class DPL::Singleton<WrtAccess>;
+};
+
+typedef DPL::Singleton<WrtAccess> WrtAccessSingleton;
+
+}
+} // WrtDeviceApisCommon
+
+#endif //WRT_PLUGINS_WRT_ACCESS_H_
diff --git a/src/Commons/WrtAccess/config.cmake b/src/Commons/WrtAccess/config.cmake
new file mode 100644 (file)
index 0000000..a31ce63
--- /dev/null
@@ -0,0 +1,5 @@
+get_current_path()
+
+set(SRCS_WRT_ACCESS
+    ${CURRENT_PATH}/WrtAccess.cpp
+)
index 84bd4b7..f2429f9 100755 (executable)
@@ -73,6 +73,21 @@ typedef java_script_context_t JavaScriptContext;
 #define PLUGIN_ON_WIDGET_START(CALLBACK_NAME) extern "C" const on_widget_start_proc PLUGIN_WIDGET_START_PROC EXPORT_SYMBOL = CALLBACK_NAME;
 
 /*
+ *  You have to(!) call this macro in your plugin_initializer.cpp(!) file
+ *  providing callback that will be called while loading each widget
+ * (for every loaded widget this function will be called)
+ *  Example:
+ *       plugin_initializer.cpp
+ *        void on_widget_init_callback(feature_mapping_interface_t *mapping)
+ *        {
+ *          //...
+ *        }
+ *        PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
+ */
+#define PLUGIN_ON_WIDGET_INIT(CALLBACK_NAME) extern "C" \
+const on_widget_init_proc PLUGIN_WIDGET_INIT_PROC EXPORT_SYMBOL = CALLBACK_NAME;
+
+/*
  *  You have to(!) call this macro in your plugin_initializer.cpp(!) file providing callback that will be called while unloading each widget (for every unloaded widget this function will be called)
  *  Example:
  *        void on_widget_stop_callback(int widgetId)
@@ -84,6 +99,28 @@ typedef java_script_context_t JavaScriptContext;
 #define PLUGIN_ON_WIDGET_STOP(CALLBACK_NAME) extern "C" const on_widget_stop_proc PLUGIN_WIDGET_STOP_PROC EXPORT_SYMBOL = CALLBACK_NAME;
 
 /*
+ *  You have to(!) call this macro in your plugin_initializer.cpp(!) file providing callback that will be called while unloading each page (for every loaded page, including nested page, this function will be called)
+ *  Example:
+ *        void on_frame_load_callback(java_script_context_t context)
+ *        {
+ *          //...
+ *        }
+ *        PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
+ */
+#define PLUGIN_ON_FRAME_LOAD(CALLBACK_NAME) extern "C" const on_frame_load_proc PLUGIN_FRAME_LOAD_PROC EXPORT_SYMBOL = CALLBACK_NAME;
+
+/*
+ *  You have to(!) call this macro in your plugin_initializer.cpp(!) file providing callback that will be called while ununloading each page (for every unloaded page, including nested page, this function will be called)
+ *  Example:
+ *        void on_frame_unload_callback(java_script_context_t context)
+ *        {
+ *          //...
+ *        }
+ *        PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
+ */
+#define PLUGIN_ON_FRAME_UNLOAD(CALLBACK_NAME) extern "C" const on_frame_unload_proc PLUGIN_FRAME_UNLOAD_PROC EXPORT_SYMBOL = CALLBACK_NAME;
+
+/*
  * You have to(!) define an array of structures in your plugin_initializer.cpp(!) file describing a JS class (class_definition) and it's parent class name (parent_name).
  * JS class will be bind to a parent class name (parent_name.jsclass_name).
  * Example:
@@ -94,11 +131,29 @@ typedef java_script_context_t JavaScriptContext;
  *      PLUGIN_CLASS_MAP_END
  *
  */
-#define PLUGIN_CLASS_MAP_BEGIN extern "C" const class_definition_t PLUGIN_CLASS_MAP[] EXPORT_SYMBOL = {
-#define PLUGIN_CLASS_MAP_ADD_CLASS(PARENTNAME,CLASSNAME,JSCLASSTEMPLATE,PRIVDATA) {PARENTNAME,CLASSNAME,JSCLASSTEMPLATE,PRIVDATA},
-#define PLUGIN_CLASS_MAP_END {NULL,NULL,NULL,NULL} };
+#define PLUGIN_CLASS_MAP_BEGIN extern "C" const js_entity_definition_t\
+            PLUGIN_CLASS_MAP[] EXPORT_SYMBOL = {
+
+#define PLUGIN_CLASS_MAP_ADD_INTERFACE(PARENTNAME,INTERFACENAME,\
+            JSPRODUCTCLASSTEMPLATE,PRODUCTCONSTRUCTORCB,PRIVDATA) \
+                {PARENTNAME,INTERFACENAME,"",JSPRODUCTCLASSTEMPLATE,\
+                 PRODUCTCONSTRUCTORCB,PRIVDATA},
+
+#define PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(PARENTNAME,OBJECTNAME,\
+            INTERFACENAME,PRIVDATA)\
+                {PARENTNAME,OBJECTNAME,INTERFACENAME,NULL,NULL,PRIVDATA},
+
+#define PLUGIN_CLASS_MAP_ADD_CLASS(PARENTNAME,CLASSNAME,JSCLASSTEMPLATE,\
+            PRIVDATA)\
+                {PARENTNAME,CLASSNAME,"",JSCLASSTEMPLATE,NULL,PRIVDATA},
+
+#define PLUGIN_CLASS_MAP_END {NULL,NULL,NULL,NULL,NULL,NULL} };
+
+#define PLUGIN_CLASS_MAP_BEGIN_STATIC static const js_entity_definition_t\
+                PLUGIN_CLASS_MAP[] = {
 
-#define PLUGIN_CLASS_MAP_BEGIN_STATIC static const class_definition_t PLUGIN_CLASS_MAP[] = {
-#define PLUGIN_GET_CLASS_MAP(CALLBACK_NAME) extern "C" const get_widget_class_map_proc PLUGIN_GET_CLASS_PROC_MAP EXPORT_SYMBOL = CALLBACK_NAME;
+#define PLUGIN_GET_CLASS_MAP(CALLBACK_NAME) extern "C" const\
+                get_widget_entity_map_proc\
+                PLUGIN_GET_CLASS_PROC_MAP EXPORT_SYMBOL = CALLBACK_NAME;
 
 #endif // WRTDEVICEAPIS_COMMONS_PLUGIN_INITIALIZER_DEF_H_
index 3b4a9f2..ecd0317 100755 (executable)
@@ -18,16 +18,13 @@ macro(install_header_file HEADER_FILE)
 endmacro()
 
 
-#TODO fix it
-pkg_search_module(wrt-plugin-api REQUIRED wrt-plugin-api>=1.1.1)
-pkg_search_module(webkit REQUIRED ewebkit>=0.1.0)
+pkg_search_module(webkit2 REQUIRED ewebkit2)
 
 set(TARGET_NAME ${TARGET_COMMONS_JAVASCRIPT})
 
 include_directories(${DIR_JS_COMMONS}
-                    ${INCLUDE_JS_INDEPENDENT}
                     ${wrt-plugin-api_INCLUDE_DIRS}
-                    ${webkit_INCLUDE_DIRS}}
+                    ${webkit2_INCLUDE_DIRS}}
                     )
 
 
@@ -52,10 +49,13 @@ set(SRCS
 add_library(${TARGET_NAME} SHARED ${SRCS})
 target_link_libraries(${TARGET_NAME}
         ${LIBS_COMMONS}
-        ${webkit_LIBRARIES}
+        ${webkit2_LIBRARIES}
         ${TARGET_COMMONS}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+set_target_properties(${TARGET_NAME} PROPERTIES
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX})
 
old mode 100755 (executable)
new mode 100644 (file)
index 1d97810..f550032
@@ -80,6 +80,12 @@ long Converter::toLong(const JSValueRef& arg)
     return (isNan(tmp) ? 0 : static_cast<long>(tmp));
 }
 
+long long Converter::toLongLong(const JSValueRef& arg)
+{
+    double tmp = toNumber_(arg);
+    return (isNan(tmp) ? 0 : static_cast<long long>(tmp));
+}
+
 unsigned long Converter::toULong(const JSValueRef& arg)
 {
     return static_cast<unsigned long>(toLong(arg));
@@ -244,6 +250,11 @@ JSValueRef Converter::toJSValueRefLong(const long arg) {
     return JSValueMakeNumber(m_context, arg);
 }
 
+JSValueRef Converter::toJSValueRef(long long int arg)
+{
+    return JSValueMakeNumber(m_context, arg);
+}
+
 JSValueRef Converter::toJSValueRef(double arg)
 {
     return JSValueMakeNumber(m_context, arg);
@@ -347,20 +358,14 @@ std::string Converter::toString_(const JSValueRef& arg)
 
     JSValueRef exception = NULL;
     JSStringRef str = JSValueToStringCopy(m_context, arg, &exception);
-    if ((NULL == str) || (NULL != exception)) {
+    if (NULL == str) {
         ThrowMsg(ConversionException, "Couldn't cast to a string.");
     }
 
     size_t jsSize = JSStringGetMaximumUTF8CStringSize(str);
     if (jsSize > 0) {
-        jsSize = jsSize + 1;
         DPL::ScopedArray<char> buffer(new char[jsSize]);
-        size_t written = JSStringGetUTF8CString(str, buffer.Get(), jsSize);
-        if (written > jsSize) {
-            JSStringRelease(str);
-            ThrowMsg(ConversionException,
-                     "Conversion could not be fully performed.");
-        }
+        JSStringGetUTF8CString(str, buffer.Get(), jsSize);
         result = buffer.Get();
     }
     JSStringRelease(str);
old mode 100755 (executable)
new mode 100644 (file)
index 47e308d..302141d
@@ -93,6 +93,13 @@ class Converter : private DPL::Noncopyable
     long toLong(const JSValueRef& arg);
 
     /**
+     * Converts JSvalueRef to long long integer value.
+     * @param arg JSValueRef object to convert.
+     * @return Long long integer value.
+     * @throw ConversionException Thrown when conversion fails.
+     */
+    long long toLongLong(const JSValueRef& arg);
+    /**
      * Converts JSValueRef to unsigned long value.
      * @param arg JSValueRef object to convert.
      * @return Unsigned long value.
@@ -277,6 +284,14 @@ class Converter : private DPL::Noncopyable
    */
   JSValueRef toJSValueRefLong(const long arg);
 
+    /**
+     * Converts unsigned long value to JSValueRef.
+     * @param arg long long int value to convert.
+     * @return JSValueRef object.
+     * @throw ConversionException Thrown when conversion fails.
+     */
+    JSValueRef toJSValueRef(long long int arg);
+
   /**
      * Converts STL string to JSValueRef.
      * @param arg STL string to convert.
index db5dce7..21d278a 100644 (file)
@@ -68,6 +68,7 @@ JSCallbackManager::JSCallbackManager(JSContextRef context,
         JSObjectRef onError) :
     m_onSuccess(NULL),
     m_onError(NULL),
+    m_object(NULL),
     m_context(context)
 {
     LogDebug("entered");
@@ -87,21 +88,27 @@ JSCallbackManager::~JSCallbackManager()
     if (m_onError) {
         JSValueUnprotect(m_context, m_onError);
     }
+
+    if (m_object) {
+        JSValueUnprotect(m_context, m_object);
+    }
 }
 
 void JSCallbackManager::setOnSuccess(JSValueRef onSuccess)
 {
     LogDebug("entered");
-    if (onSuccess) {
-        if (m_onSuccess != NULL) {
-            JSValueUnprotect(m_context, m_onSuccess);
-        }
+    if (m_onSuccess != NULL) {
+        JSValueUnprotect(m_context, m_onSuccess);
+    }
 
+    if (onSuccess) {
         m_onSuccess = JSValueToObject(m_context, onSuccess, NULL);
+    } else {
+        m_onSuccess = NULL;
+    }
 
-        if (m_onSuccess != NULL) {
-            JSValueProtect(m_context, m_onSuccess);
-        }
+    if (m_onSuccess != NULL) {
+        JSValueProtect(m_context, m_onSuccess);
     }
 }
 
@@ -114,16 +121,18 @@ JSValueRef JSCallbackManager::getOnSuccess() const
 void JSCallbackManager::setOnError(JSValueRef onError)
 {
     LogDebug("entered");
-    if (onError) {
-        if (m_onError != NULL) {
-            JSValueUnprotect(m_context, m_onError);
-        }
+    if (m_onError != NULL) {
+        JSValueUnprotect(m_context, m_onError);
+    }
 
+    if (onError) {
         m_onError = JSValueToObject(m_context, onError, NULL);
+    } else {
+        m_onError = NULL;
+    }
 
-        if (m_onError != NULL) {
-            JSValueProtect(m_context, m_onError);
-        }
+    if (m_onError != NULL) {
+        JSValueProtect(m_context, m_onError);
     }
 }
 
@@ -133,6 +142,26 @@ JSValueRef JSCallbackManager::getOnError() const
     return m_onError;
 }
 
+void JSCallbackManager::setObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    if (m_object != NULL) {
+        JSValueUnprotect(m_context, m_object);
+    }
+
+    m_object = object;
+
+    if (m_object != NULL) {
+        JSValueProtect(m_context, m_object);
+    }
+}
+
+JSObjectRef JSCallbackManager::getObject() const
+{
+    LogDebug("entered");
+    return m_object;
+}
+
 void JSCallbackManager::setContext(JSContextRef context)
 {
     LogDebug("entered");
index 00e4ab8..9eb7ea5 100644 (file)
@@ -81,6 +81,8 @@ class JSCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
     JSValueRef getOnSuccess() const;
     void setOnError(JSValueRef onError);
     JSValueRef getOnError() const;
+    void setObject(JSObjectRef object);
+    JSObjectRef getObject() const;
 
     void callOnSuccess();
     void callOnSuccess(JSValueRef obj);
index db53b21..fe20f9c 100644 (file)
@@ -22,13 +22,11 @@ namespace CommonsJavaScript {
 
 
 AceSecurityStatus aceCheckAccessSimple(
-        JSContextRef globalContext,
         WrtDeviceApis::Commons::AceFunction aceFunction)
 {
-    return aceCheckAccess2<DefaultArgsVerifier<>>(globalContext,
-                                                  aceFunction);
+    return aceCheckAccess2<DefaultArgsVerifier<>>(aceFunction);
 }
 
 }
 
-}
\ No newline at end of file
+}
index e3305a9..ad93dd8 100644 (file)
@@ -17,7 +17,7 @@
 #define _FUNCTION_DECLARATION_
 
 #include <string>
-#include <Commons/WrtWrapper/WrtWrappersMgr.h>
+#include <Commons/WrtAccess/WrtAccess.h>
 #include <Commons/Exception.h>
 #include <JavaScriptCore/JavaScript.h>
 #include <Commons/TypesDeclaration.h>
@@ -58,25 +58,23 @@ class DefaultArgsVerifier<>
 
 template <typename ArgumentsVerifier,
           typename ... Args>
-AceSecurityStatus aceCheckAccess2(JSContextRef globalContext,
-        WrtDeviceApis::Commons::AceFunction  aceFunction,
+AceSecurityStatus aceCheckAccess2(
+        WrtDeviceApis::Commons::AceFunction aceFunction,
         Args && ... args)
 {
+    using namespace WrtDeviceApis::Commons;
+
     ArgumentsVerifier argsVerify;
     argsVerify(aceFunction, args ...);
 
     Try {
-        WrtDeviceApis::Commons::IWrtWrapperPtr wrapper =
-        WrtDeviceApis::Commons::WrtWrappersMgr::getInstance().getWrtWrapper(
-            globalContext);
-
-        if (!(wrapper->checkAccess(aceFunction))) {
+        if (!(WrtAccessSingleton::Instance().checkAccessControl(aceFunction))) {
         LogDebug("Function is not allowed to run");
         return AceSecurityStatus::AccessDenied;
         }
     }
     Catch(WrtDeviceApis::Commons::OutOfRangeException) {
-        LogError("Wrapper doesn't exist.");
+        LogError("WrtAccess doesn't exist.");
         return AceSecurityStatus::InternalError;
     }
 
@@ -88,8 +86,8 @@ AceSecurityStatus aceCheckAccess2(JSContextRef globalContext,
 
 
 //The simplest version
-AceSecurityStatus aceCheckAccessSimple(JSContextRef globalContext,
-        WrtDeviceApis::Commons::AceFunction  aceFunction);
+AceSecurityStatus aceCheckAccessSimple(
+        WrtDeviceApis::Commons::AceFunction aceFunction);
 
 }
 }
index 53c04a9..736b14a 100644 (file)
 #include <map>
 #include <vector>
 #include <string>
+#include <string.h>
 #include <dpl/noncopyable.h>
 #include <dpl/assert.h>
 #include <dpl/foreach.h>
 #include <Commons/TypesDeclaration.h>
-
+#include <wrt-commons/wrt_plugin_export.h>
 
 namespace WrtDeviceApis {
 namespace CommonsJavaScript {
@@ -207,6 +208,108 @@ class StaticDeclarations  : public DPL::Noncopyable
         }
     }
 
+    static feature_mapping_t* getFeaturesToDevCapMapping()
+    {
+        feature_mapping_t* mapping = new feature_mapping_t;
+
+        mapping->featuresCount = m_features.size();
+        mapping->features = new feature_devcaps_t[mapping->featuresCount];
+
+        size_t i = 0;
+
+        FOREACH(featureIt, m_features)
+        {
+            mapping->features[i].feature_name =
+                strndup(featureIt->first.c_str(), featureIt->first.size() + 1);
+
+            mapping->features[i].devCaps.devCapsCount =
+                    featureIt->second.size();
+
+            mapping->features[i].devCaps.deviceCaps =
+                    new char*[mapping->features[i].devCaps.devCapsCount];
+
+            for (size_t j = 0;
+                 j < mapping->features[i].devCaps.devCapsCount;
+                 ++j)
+            {
+                std::string dc = getDevCapNameById(featureIt->second[j]);
+
+                mapping->features[i].devCaps.deviceCaps[j] =
+                    strndup(dc.c_str(), dc.size() + 1);
+            }
+
+            ++i;
+        }
+
+        return mapping;
+    }
+
+    static const devcaps_t* devcapsGetter(pfeature_mapping_t feats,
+                                          const char* featureName)
+    {
+        Assert(featureName && "Trying to extract info about NULL api feature");
+
+        std::string feature(featureName);
+
+        devcaps_t* ret = NULL;
+
+        for (size_t i = 0; i < feats->featuresCount ; ++i)
+        {
+            Assert(feats->features &&
+                   feats->features[i].feature_name &&
+                   "NULL api feature in feature mapping");
+
+            std::string feat(feats->features[i].feature_name);
+
+            if (feature == feat)
+            {
+                ret = &(feats->features[i].devCaps);
+                break;
+            }
+        }
+
+        return ret;
+    }
+
+    static void featuresDeinitializer(feature_mapping_t* mapping)
+    {
+        if (mapping)
+        {
+            if (mapping->features)
+            {
+                for (size_t i = 0; i < mapping->featuresCount; ++i)
+                {
+                    free(mapping->features[i].feature_name);
+
+                    devcaps_t& dc = mapping->features[i].devCaps;
+
+                    if (dc.deviceCaps)
+                    {
+                        for (size_t j = 0; j < dc.devCapsCount; ++j)
+                        {
+                            free(dc.deviceCaps[j]);
+                        }
+
+                        delete []dc.deviceCaps;
+                    }
+                }
+                delete []mapping->features;
+            }
+            delete mapping;
+        }
+    }
+
+    static void getMappingInterface(feature_mapping_interface_t *mapping)
+    {
+        if (mapping)
+        {
+            mapping->featGetter =
+                    StaticDeclarations::getFeaturesToDevCapMapping;
+            mapping->dcGetter = StaticDeclarations::devcapsGetter;
+            mapping->release = StaticDeclarations::featuresDeinitializer;
+        }
+    }
+
 private:
     static ParamsMap m_params;
     static DeviceCapsMaps m_deviceCaps;
diff --git a/src/js-overlay/CMakeLists.txt b/src/js-overlay/CMakeLists.txt
new file mode 100644 (file)
index 0000000..dd68584
--- /dev/null
@@ -0,0 +1,73 @@
+# 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   Yunchan Cho (yunchan.cho@samsung.com)
+# @version  1.0
+#
+MACRO(INSTALL_HEADER_FILE HEADER_FILE)
+    INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}
+        DESTINATION ${DESTINATION_HEADERS_JS_OVERLAY})
+ENDMACRO()
+
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
+
+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(
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/JSClass
+    ${webkit2_INCLUDE_DIRS}
+    ${plugin-types_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+    ${webkit2_LIBRARIES}
+    ${TARGET_COMMONS}
+    ${TARGET_COMMONS_JAVASCRIPT}
+)
+
+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_HEADER_FILE(js_overlay_types.h)
+
diff --git a/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp b/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.cpp
new file mode 100644 (file)
index 0000000..048c149
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2012 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        JSSoftKeyboardChangeEvent.cpp
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ */
+
+#include "JSSoftKeyboardChangeEvent.h"
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::SoftKeyboardChangeEvent::Api;
+
+#define WIDGET_PLUGIN_NAME              "SoftKeyboardChangeEvent"
+#define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_STATE   "state"
+#define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH   "width"
+#define SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT  "height"
+
+#define CATCH_EXCEPTION_CONVERSION \
+    Catch(Commons::ConversionException) {\
+        LogError("Error on conversion");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_NULL_PTR \
+    Catch(Commons::NullPointerException) {\
+        LogError("Error on pointer, null value");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_PLATFORM_ERROR \
+    Catch(Commons::PlatformException){\
+        LogError("PlatformException occured");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+namespace WrtPlugins {
+namespace Tizen {
+JSClassDefinition JSSoftKeyboardChangeEvent::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    WIDGET_PLUGIN_NAME,
+    0,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL, //ConvertToType,
+};
+
+JSStaticValue JSSoftKeyboardChangeEvent::m_property[] = {
+    { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_STATE, JSSoftKeyboardChangeEvent::getState,
+      0, kJSPropertyAttributeReadOnly },
+    { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_WIDTH, JSSoftKeyboardChangeEvent::getWidth,
+      0, kJSPropertyAttributeReadOnly },
+    { SOFTKEYBOARD_CHANGE_EVENT_PROPERTY_HEIGHT, JSSoftKeyboardChangeEvent::getHeight,
+      0, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSSoftKeyboardChangeEvent::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSSoftKeyboardChangeEvent::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSSoftKeyboardChangeEvent::m_jsClassRef = JSClassCreate(JSSoftKeyboardChangeEvent::getClassInfo());
+
+void JSSoftKeyboardChangeEvent::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug("entered");
+
+    JSSoftKeyboardChangeEventPrivateObject* priv =
+        static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(object));
+
+    Assert(priv && "Missing private object");
+}
+
+void JSSoftKeyboardChangeEvent::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    JSSoftKeyboardChangeEventPrivateObject* priv =
+        static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(object));
+
+    delete priv;
+    LogDebug("private object is realised");
+
+}
+
+JSValueRef JSSoftKeyboardChangeEvent::getState(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered!");
+
+    Try
+    {
+        Converter converter(context);
+        return converter.toJSValueRef(getPrivateObject(object)->getState());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSSoftKeyboardChangeEvent::getWidth(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered!");
+
+    Try
+    {
+        Converter converter(context);
+        return converter.toJSValueRef(getPrivateObject(object)->getWidth());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSSoftKeyboardChangeEvent::getHeight(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+        return converter.toJSValueRef(getPrivateObject(object)->getHeight());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+ISoftKeyboardChangeEventPtr JSSoftKeyboardChangeEvent::getPrivateObject(JSObjectRef arg)
+{
+    JSSoftKeyboardChangeEventPrivateObject* priv =
+        static_cast<JSSoftKeyboardChangeEventPrivateObject*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+
+    return priv->getObject();
+}
+
+#undef CATCH_EXCEPTION_CONVERSION
+#undef CATCH_EXCEPTION_NULL_PTR
+#undef CATCH_EXCEPTION_PLATFORM_ERROR
+
+}
+}
diff --git a/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h b/src/js-overlay/JSClass/JSSoftKeyboardChangeEvent.h
new file mode 100644 (file)
index 0000000..f9dce7f
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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       JSSoftKeyboardChangeEvent.h
+ * @author     Yunchan Cho (yunchan.cho@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGIN_JS_SOFTKEYBOARD_CHANGE_EVENT_H
+#define WRT_PLUGIN_JS_SOFTKEYBOARD_CHANGE_EVENT_H
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h>
+
+namespace WrtPlugins {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
+    WrtDeviceApis::SoftKeyboardChangeEvent::Api::ISoftKeyboardChangeEventPtr>::Type
+    JSSoftKeyboardChangeEventPrivateObject;
+
+class JSSoftKeyboardChangeEvent
+{
+  public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static const JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+  private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context, JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_property[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_jsClassRef;
+
+    // getters for properties
+    static JSValueRef getState(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getWidth(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getHeight(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static WrtDeviceApis::SoftKeyboardChangeEvent::Api::ISoftKeyboardChangeEventPtr
+        getPrivateObject(JSObjectRef arg);
+};
+} // Tizen
+} // WrtPlugins
+
+#endif // WRT_PLUGIN_JS_SOFTKEYBOARD_CHANGE_EVENT_H
diff --git a/src/js-overlay/JSClass/JSStorageEvent.cpp b/src/js-overlay/JSClass/JSStorageEvent.cpp
new file mode 100644 (file)
index 0000000..09c49ce
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * 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        JSStorageEvent.cpp
+ * @author      Andrzej Surdej (a.surdej@samsung.com)
+ * @version     0.1
+ */
+
+#include "JSStorageEvent.h"
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <StorageEvent/IStorageEvent.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::StorageEvent::Api;
+
+#define WIDGET_PLUGIN_NAME "StorageEvent"
+
+#define WRT_STORAGE_EVENT_PROPERTY_KEY          "key"
+#define WRT_STORAGE_EVENT_PROPERTY_OLD_VALUE    "oldValue"
+#define WRT_STORAGE_EVENT_PROPERTY_NEW_VALUE    "newValue"
+#define WRT_STORAGE_EVENT_PROPERTY_URL          "url"
+#define WRT_STORAGE_EVENT_PROPERTY_STORAGE_AREA "storageArea"
+
+#define CATCH_EXCEPTION_CONVERSION \
+    Catch(Commons::ConversionException) {\
+        LogError("Error on conversion");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_NULL_PTR \
+    Catch(Commons::NullPointerException) {\
+        LogError("Error on pointer, null value");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_PLATFORM_ERROR \
+    Catch(Commons::PlatformException){\
+        LogError("PlatformException occured");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_SECURITY \
+    Catch(Commons::SecurityException){\
+        LogError("Security exception occured");\
+        return JSDOMExceptionFactory::\
+            SecurityException.make(context, exception);\
+    }
+
+namespace WrtPlugins {
+namespace W3C {
+JSClassDefinition JSStorageEvent::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    WIDGET_PLUGIN_NAME,
+    0,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL, //ConvertToType,
+};
+
+JSStaticValue JSStorageEvent::m_property[] = {
+    { WRT_STORAGE_EVENT_PROPERTY_KEY, JSStorageEvent::getKey,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_STORAGE_EVENT_PROPERTY_OLD_VALUE, JSStorageEvent::getOldValue,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_STORAGE_EVENT_PROPERTY_NEW_VALUE, JSStorageEvent::getNewValue,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_STORAGE_EVENT_PROPERTY_URL, JSStorageEvent::getUrl,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_STORAGE_EVENT_PROPERTY_STORAGE_AREA, JSStorageEvent::getStorageArea,
+      0, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSStorageEvent::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSStorageEvent::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSStorageEvent::m_jsClassRef = JSClassCreate(JSStorageEvent::getClassInfo());
+
+void JSStorageEvent::initialize(JSContextRef context,
+                                JSObjectRef object)
+{
+    LogDebug("entered");
+
+    JSStorageEventPrivateObject* priv =
+        static_cast<JSStorageEventPrivateObject*>(JSObjectGetPrivate(object));
+
+    Assert(priv && "Missing private object");
+}
+
+void JSStorageEvent::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    JSStorageEventPrivateObject* priv =
+        static_cast<JSStorageEventPrivateObject*>(JSObjectGetPrivate(object));
+
+    delete priv;
+    LogDebug("private object is realised");
+
+}
+
+JSValueRef JSStorageEvent::getKey(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+
+        return converter.toJSValueRef(getPrivateObject(object)->getKey());
+
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSStorageEvent::getOldValue(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+
+        DPL::OptionalString oldValue = getPrivateObject(object)->getOldValue();
+
+        if(!oldValue) {
+            return JSValueMakeNull(context);
+        } else {
+            return converter.toJSValueRef(DPL::ToUTF8String(*oldValue));
+        }
+
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSStorageEvent::getNewValue(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+
+        DPL::OptionalString newValue = getPrivateObject(object)->getNewValue();
+
+        if(!newValue) {
+            return JSValueMakeNull(context);
+        } else {
+            return converter.toJSValueRef(DPL::ToUTF8String(*newValue));
+        }
+
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSStorageEvent::getUrl(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+
+        return converter.toJSValueRef(getPrivateObject(object)->getUrl());
+
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+}
+
+JSValueRef JSStorageEvent::getStorageArea(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        LogError("Not implemented");
+        return JSValueMakeUndefined(context);
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+IStorageEventPtr JSStorageEvent::getPrivateObject(JSObjectRef arg)
+{
+    JSStorageEventPrivateObject* priv =
+        static_cast<JSStorageEventPrivateObject*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+
+    return priv->getObject();
+}
+
+#undef CATCH_EXCEPTION_CONVERSION
+#undef CATCH_EXCEPTION_NULL_PTR
+#undef CATCH_EXCEPTION_PLATFORM_ERROR
+#undef CATCH_EXCEPTION_SECURITY
+
+}
+}
diff --git a/src/js-overlay/JSClass/JSStorageEvent.h b/src/js-overlay/JSClass/JSStorageEvent.h
new file mode 100644 (file)
index 0000000..67bde4d
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * 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       JSStorageEvent.h
+ * @author     Andrzej Surdej (a.surdej@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_STORAGE_EVENT_H_
+#define _WRT_PLUGIN_JS_STORAGE_EVENT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <StorageEvent/IStorageEvent.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
+    WrtDeviceApis::StorageEvent::Api::IStorageEventPtr>::Type
+    JSStorageEventPrivateObject;
+
+class JSStorageEvent
+{
+  public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static const JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+  private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context,
+            JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_property[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_jsClassRef;
+
+    // getters for properties
+    static JSValueRef getKey(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getOldValue(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getNewValue(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getUrl(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getStorageArea(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static WrtDeviceApis::StorageEvent::Api::IStorageEventPtr
+        getPrivateObject(JSObjectRef arg);
+};
+} // W3C
+} // WrtPlugins
+
+#endif // _WRT_PLUGIN_JS_STORAGE_EVENT_H_
diff --git a/src/js-overlay/JSClass/JSTizenServiceEvent.cpp b/src/js-overlay/JSClass/JSTizenServiceEvent.cpp
new file mode 100644 (file)
index 0000000..ac4c5ad
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * 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        JSTizenServiceEvent.cpp
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ */
+
+#include "JSTizenServiceEvent.h"
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::TizenServiceEvent::Api;
+
+#define WIDGET_PLUGIN_NAME "TizenServiceEvent"
+
+#define TIZEN_SERVICE_EVENT_PROPERTY_SCALE      "scale"
+#define TIZEN_SERVICE_EVENT_PROPERTY_BUNDLE     "__bundle"
+
+#define CATCH_EXCEPTION_CONVERSION \
+    Catch(Commons::ConversionException) {\
+        LogError("Error on conversion");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_NULL_PTR \
+    Catch(Commons::NullPointerException) {\
+        LogError("Error on pointer, null value");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_PLATFORM_ERROR \
+    Catch(Commons::PlatformException){\
+        LogError("PlatformException occured");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_SECURITY \
+    Catch(Commons::SecurityException){\
+        LogError("Security exception occured");\
+        return JSDOMExceptionFactory::\
+            SecurityException.make(context, exception);\
+    }
+
+namespace WrtPlugins {
+namespace Tizen {
+JSClassDefinition JSTizenServiceEvent::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    WIDGET_PLUGIN_NAME,
+    0,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL, //ConvertToType,
+};
+
+JSStaticValue JSTizenServiceEvent::m_property[] = {
+    { TIZEN_SERVICE_EVENT_PROPERTY_SCALE, JSTizenServiceEvent::getScale,
+      0, kJSPropertyAttributeReadOnly },
+    { TIZEN_SERVICE_EVENT_PROPERTY_BUNDLE, JSTizenServiceEvent::getBundle,
+      0, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSTizenServiceEvent::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSTizenServiceEvent::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSTizenServiceEvent::m_jsClassRef = JSClassCreate(JSTizenServiceEvent::getClassInfo());
+
+void JSTizenServiceEvent::initialize(JSContextRef context,
+                                     JSObjectRef object)
+{
+    LogDebug("entered");
+
+    JSTizenServiceEventPrivateObject* priv =
+        static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(object));
+
+    Assert(priv && "Missing private object");
+}
+
+void JSTizenServiceEvent::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    JSTizenServiceEventPrivateObject* priv =
+        static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(object));
+
+    delete priv;
+    LogDebug("private object is realised");
+
+}
+
+JSValueRef JSTizenServiceEvent::getScale(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+        return converter.toJSValueRef(getPrivateObject(object)->getScale());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSTizenServiceEvent::getBundle(
+        JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        Converter converter(context);
+        return converter.toJSValueRef(getPrivateObject(object)->getBundle());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+ITizenServiceEventPtr JSTizenServiceEvent::getPrivateObject(JSObjectRef arg)
+{
+    JSTizenServiceEventPrivateObject* priv =
+        static_cast<JSTizenServiceEventPrivateObject*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+
+    return priv->getObject();
+}
+
+#undef CATCH_EXCEPTION_CONVERSION
+#undef CATCH_EXCEPTION_NULL_PTR
+#undef CATCH_EXCEPTION_PLATFORM_ERROR
+#undef CATCH_EXCEPTION_SECURITY
+
+}
+}
diff --git a/src/js-overlay/JSClass/JSTizenServiceEvent.h b/src/js-overlay/JSClass/JSTizenServiceEvent.h
new file mode 100644 (file)
index 0000000..cb7fbb3
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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       JSTizenServiceEvent.h
+ * @author     Yunchan Cho (yunchan.cho@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_TIZEN_SERVICE_EVENT_H_
+#define _WRT_PLUGIN_JS_TIZEN_SERVICE_EVENT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+
+namespace WrtPlugins {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
+    WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr>::Type
+    JSTizenServiceEventPrivateObject;
+
+class JSTizenServiceEvent
+{
+  public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static const JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+  private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context,
+            JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_property[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_jsClassRef;
+
+    // getters for properties
+    static JSValueRef getScale(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getBundle(
+            JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr
+        getPrivateObject(JSObjectRef arg);
+};
+} // Tizen
+} // WrtPlugins
+
+#endif // _WRT_PLUGIN_JS_TIZEN_SERVICE_EVENT_H_
diff --git a/src/js-overlay/js_function_manager.cpp b/src/js-overlay/js_function_manager.cpp
new file mode 100644 (file)
index 0000000..d1be598
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * 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    js_function_manager.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @author  Yunchan Cho (yunchan.cho@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <dpl/singleton_safe_impl.h>
+#include <js_function_manager.h>
+#include <js_iframe_support.h>
+#include <js_overlay_functions.h>
+#include <js_overlay_addEventListener.h>
+#include <wrt_plugin_export.h>
+
+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
+{
+//options
+    class_definition_options_t jsHookfunctionsOptions =
+    {
+        JS_FUNCTION,
+        CREATE_INSTANCE,
+        NONE_NOTICE,
+        USE_OVERLAYED, //ignored
+        NULL,
+        NULL,
+        reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptHookProc)
+    };
+
+    class_definition_options_t jsPrintfunctionsOptions =
+    {
+        JS_FUNCTION,
+        CREATE_INSTANCE,
+        NONE_NOTICE,
+        USE_OVERLAYED, //ignored
+        NULL,
+        NULL,
+        reinterpret_cast<js_function_impl>(JSCFunctions::JavaScriptPrintProc)
+    };
+
+    class_definition_options_t addEventListenerOptions =
+    {
+        JS_FUNCTION,
+        CREATE_INSTANCE,
+        ALWAYS_NOTICE,
+        OVERLAYED_BEFORE_ORIGINAL,
+        IFrameSupport::RegisterAddEventListener,
+        NULL,
+        reinterpret_cast<js_function_impl>(AddEventListenerSupport::AddEventListener)
+    };
+
+    js_entity_definition_t jsPrint =
+    {
+        JSGLOBAL_OBJECT,
+        JSPRINT_NAME,
+        "",
+        NULL,
+        NULL,
+        &jsPrintfunctionsOptions
+    };
+
+    js_entity_definition_t jsHook =
+    {
+        JSGLOBAL_OBJECT,
+        JSHOOK_NAME,
+        "",
+        NULL,
+        NULL,
+        &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()
+{
+    LogInfo("JSObjectDeclaration for js functions are intialized");
+    JSObjectDeclarationPtr jsPrintObj(
+        new JSObjectDeclaration(JavaScriptFunctions::jsPrintPtr));
+
+    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;
+}
+
+JsFunctionManager::Functions JsFunctionManager::getFunctions()
+{
+    LogInfo("get standard js fucntions");
+    static bool initialized = initialize();
+    (void) initialized;
+    return m_functions;
+}
diff --git a/src/js-overlay/js_function_manager.h b/src/js-overlay/js_function_manager.h
new file mode 100644 (file)
index 0000000..d6bd80e
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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    js_function_manager.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_JS_FUNCTION_MANGER_H_
+#define WRT_SRC_PLUGIN_SERVICE_JS_FUNCTION_MANGER_H_
+
+#include <list>
+#include <dpl/noncopyable.h>
+#include <dpl/singleton.h>
+
+#include <Commons/JSObjectDeclaration.h>
+
+class JsFunctionManager : private DPL::Noncopyable
+{
+  public:
+    typedef std::list<JSObjectDeclarationPtr> Functions;
+
+  public:
+    Functions getFunctions();
+
+  private:
+    JsFunctionManager()
+    {}
+
+    bool initialize();
+
+  private:
+    Functions m_functions;
+
+    friend class DPL::Singleton<JsFunctionManager>;
+};
+
+typedef DPL::Singleton<JsFunctionManager> JsFunctionManagerSingleton;
+
+#endif
+
diff --git a/src/js-overlay/js_iframe_support.cpp b/src/js-overlay/js_iframe_support.cpp
new file mode 100644 (file)
index 0000000..782fc0e
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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       IFrameSupport.cpp
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include <dpl/foreach.h>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <js_iframe_support.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+IFrameSupport::IFramesContainer IFrameSupport::m_iframesObject =
+    IFrameSupport::IFramesContainer();
+
+
+void IFrameSupport::RegisterWidget(java_script_context_t global_context,
+                                   js_object_instance_t iframe,
+                                   js_object_instance_t object)
+{
+    LogDebug("New widget instance registered");
+    LogDebug("iframe: " << iframe );
+    LogDebug("object: " << object );
+    getIFrameData(static_cast<JSObjectRef>(iframe))->widget =
+        static_cast<JSObjectRef>(object);
+}
+
+void IFrameSupport::RegisterAddEventListener(java_script_context_t global_context,
+                                             js_object_instance_t iframe,
+                                             js_object_instance_t object)
+{
+    LogDebug("New addEventListener instance registered");
+    LogDebug("iframe: " << iframe );
+    LogDebug("object: " << object );
+    getIFrameData(static_cast<JSObjectRef>(iframe))->addEventListener
+        = static_cast<JSObjectRef>(object);
+}
+
+JSObjectRef IFrameSupport::getIFrameObjectForWidget(JSObjectRef widgetObject)
+{
+    FOREACH(it, m_iframesObject)
+    {
+        if(it->second->widget == widgetObject)
+        {
+            LogDebug("iframe found");
+            return it->first;
+        }
+    }
+    LogDebug("Iframe not found");
+    return NULL;
+}
+
+IFrameDataPtr IFrameSupport::getIFrameData(JSObjectRef iframe)
+{
+    auto it = m_iframesObject.find(iframe);
+    if(it != m_iframesObject.end()){
+        return it->second;
+    }
+
+    return m_iframesObject[iframe] = IFrameDataPtr(new IFrameData());
+}
+
+}
+}
diff --git a/src/js-overlay/js_iframe_support.h b/src/js-overlay/js_iframe_support.h
new file mode 100644 (file)
index 0000000..92f58f8
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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       IFrameSupport.h
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_SRC_W3C_WIDGET_IFRAME_SUPPORT_H_
+#define _WRT_PLUGINS_SRC_W3C_WIDGET_IFRAME_SUPPORT_H_
+
+#include <map>
+#include <memory>
+#include <JavaScriptCore/JavaScript.h>
+#include <wrt_plugin_export.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+struct IFrameData
+{
+    IFrameData() : widget(0), addEventListener(0){}
+
+    JSObjectRef widget;
+    JSObjectRef addEventListener;
+};
+typedef std::shared_ptr<IFrameData> IFrameDataPtr;
+
+
+class IFrameSupport
+{
+  public:
+    static void RegisterWidget(java_script_context_t global_context,
+                               js_object_instance_t iframe,
+                               js_object_instance_t object);
+
+    static void RegisterAddEventListener(java_script_context_t global_context,
+                                         js_object_instance_t iframe,
+                                         js_object_instance_t object);
+
+    static JSObjectRef getIFrameObjectForWidget(JSObjectRef widgetObject);
+
+  private:
+    //map iframe:objects
+    typedef std::map<JSObjectRef, IFrameDataPtr> IFramesContainer;
+
+    static IFramesContainer m_iframesObject;
+
+  private:
+    static IFrameDataPtr getIFrameData(JSObjectRef iframe);
+};
+
+}
+}
+
+#endif
diff --git a/src/js-overlay/js_overlay_addEventListener.cpp b/src/js-overlay/js_overlay_addEventListener.cpp
new file mode 100644 (file)
index 0000000..c14fe5f
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * 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       AddEventListenerSupport.cpp
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author     Yunchan Cho (yunchan.cho@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <CommonsJavaScript/Converter.h>
+#include <js_overlay_addEventListener.h>
+#include <js_overlay_types.h>
+#include <JSStorageEvent.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+const std::string storageEventName = "storage";
+const std::string appServiceEventName = "appservice";
+const std::string softKeyboardChangeEventName = "softkeyboardchange";
+
+AddEventListenerSupport::IFramesListeners
+    AddEventListenerSupport::m_listeners =
+        AddEventListenerSupport::IFramesListeners();
+
+JSContextRef AddEventListenerSupport::m_context = NULL;
+
+void AddEventListenerSupport::initialize(JSContextRef context)
+{
+    if(!m_context) m_context = context;
+}
+
+void AddEventListenerSupport::deinitialize()
+{
+    if(!m_context) {
+        LogDebug("Not yet initialized");
+    }
+
+    m_listeners.clear();
+    m_context = NULL;
+}
+
+bool AddEventListenerSupport::isInitialized() 
+{
+    return m_context!=NULL;
+}
+
+JSValueRef AddEventListenerSupport::
+AddEventListener(JSContextRef context,
+                 JSObjectRef object,
+                 JSObjectRef thisObject,
+                 size_t argumentCount,
+                 const JSValueRef arguments[],
+                 JSValueRef* exception)
+{
+    LogDebug("Add event listener invoked");
+    LogDebug("This(iframe?):" << thisObject);
+    LogDebug("object:" << object);
+
+    if (argumentCount < 2 || !JSValueIsString(context, arguments[0])) {
+        LogError("Wrong arguments");
+        return JSValueMakeUndefined(context);
+    }
+
+    std::string eventName = WrtDeviceApis::CommonsJavaScript::
+        Converter(context).toString(arguments[0]);
+    LogDebug("Event name: " << eventName);
+
+    if(eventName != storageEventName &&
+       eventName != appServiceEventName &&
+       eventName != softKeyboardChangeEventName) {
+        LogDebug("Event type not supported");
+        return JSValueMakeUndefined(context);
+    }
+
+    JSValueProtect(m_context, arguments[1]);
+    JSObjectRef objectCb =
+        JSValueToObject(m_context,
+                        arguments[1],
+                        NULL);
+    if(!JSObjectIsFunction(m_context, objectCb))
+    {
+        LogError("JS object is not a function");
+        return JSValueMakeUndefined(context);
+    }
+    //add object to Listeners
+    //set event information according to each event type
+    CallbackData data;
+    data.object = objectCb;
+    data.thisObject = thisObject;
+
+    if(eventName == storageEventName) {
+        data.eventType = StorageCustomEvent;
+    } else if (eventName == appServiceEventName) {
+        data.eventType = ServiceCustomEvent;
+    } else if (eventName == softKeyboardChangeEventName) {
+        data.eventType = SoftKeyboardChangeCustomEvent;
+    }
+
+    getIFrameListeners(thisObject)->push_back(data);
+
+    return JSValueMakeUndefined(context);
+}
+
+void AddEventListenerSupport::
+CallStorageListenersFromDifferentIFrames(
+    JSObjectRef iframe,
+    const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event)
+{
+    LogDebug("Invoked callbacks");
+    LogInfo("Context: " << m_context);
+
+    FOREACH(it, m_listeners)
+    {
+        if(it->first == iframe){
+            continue;
+        }
+
+        auto eventPriv = new JSStorageEventPrivateObject(m_context,
+                                                         event);
+
+        JSObjectRef eventObject =
+            JSObjectMake(m_context, JSStorageEvent::getClassRef(), eventPriv);
+        const size_t argc = 1;
+        JSValueRef argv[argc] = {eventObject};
+
+        JSValueProtect(m_context, eventObject);
+
+        FOREACH(listener, *it->second)
+        {
+            LogDebug("Call");
+
+            if (listener->eventType ==
+                    StorageCustomEvent)
+            {
+                JSObjectCallAsFunction(
+                    m_context,
+                    listener->object,
+                    NULL,
+                    argc,
+                    argv,
+                    NULL);
+            }
+        }
+
+        JSValueUnprotect(m_context, eventObject);
+    }
+
+    LogDebug("Done");
+};
+
+void AddEventListenerSupport::
+CallCustomEventListenersFromIFrame(
+        JSObjectRef iframe,
+        CustomEventType eventType,
+        JSObjectRef eventObject)
+{
+    LogDebug("Invoked callbacks");
+
+    IFramesListeners::iterator it = m_listeners.find(iframe);
+    if (it == m_listeners.end()) {
+        LogDebug("This frame object not existed");
+        return;
+    }
+
+    const size_t argc = 1;
+    JSValueRef argv[argc] = {eventObject};
+
+    JSValueProtect(m_context, eventObject);
+    FOREACH(listener, *it->second)
+    {
+        if (listener->eventType == eventType) {
+            LogDebug("Call");
+            JSObjectCallAsFunction(
+                m_context,
+                listener->object,
+                iframe,
+                argc,
+                argv,
+                NULL);
+        }
+    }
+    JSValueUnprotect(m_context, eventObject);
+    LogDebug("Done");
+};
+
+AddEventListenerSupport::ListenersPtr
+AddEventListenerSupport::getIFrameListeners(JSObjectRef iframe){
+    auto it = m_listeners.find(iframe);
+    if(it != m_listeners.end()){
+        return it->second;
+    }
+
+    return m_listeners[iframe] = ListenersPtr(new Listeners());
+}
+
+}
+}
diff --git a/src/js-overlay/js_overlay_addEventListener.h b/src/js-overlay/js_overlay_addEventListener.h
new file mode 100644 (file)
index 0000000..d8ea74a
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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       js_overlay_addEventListener.h
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author     Yunchan Cho (yunchan.cho@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_SRC_W3C_WIDGET_ADDEVENTLISTENERSUPPORT_H_
+#define _WRT_PLUGINS_SRC_W3C_WIDGET_ADDEVENTLISTENERSUPPORT_H_
+
+#include <map>
+#include <list>
+#include <memory>
+#include <JavaScriptCore/JavaScript.h>
+#include <StorageEvent/IStorageEvent.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+#include <js_overlay_types.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+class AddEventListenerSupport
+{
+  public:
+    static void initialize(JSContextRef context);
+    static void deinitialize();
+
+    static bool isInitialized();
+
+    static JSValueRef AddEventListener(JSContextRef context,
+                                       JSObjectRef object,
+                                       JSObjectRef thisObject,
+                                       size_t argumentCount,
+                                       const JSValueRef arguments[],
+                                       JSValueRef* exception);
+
+    static void CallStorageListenersFromDifferentIFrames(
+        JSObjectRef iframe,
+        const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event);
+
+    static void CallCustomEventListenersFromIFrame(
+        JSObjectRef iframe,
+        CustomEventType eventType,
+        JSObjectRef eventObject);
+
+  private:
+
+    struct CallbackData{
+        CustomEventType eventType; 
+        JSObjectRef object;
+        JSObjectRef thisObject;
+    };
+
+    typedef std::list<CallbackData> Listeners;
+    typedef std::shared_ptr<Listeners> ListenersPtr;
+
+    //first-iframe, 2nd - listeners list
+    typedef std::map<JSObjectRef, ListenersPtr> IFramesListeners;
+
+    static JSContextRef m_context;
+    static IFramesListeners m_listeners;
+
+  private:
+    static ListenersPtr getIFrameListeners(JSObjectRef iframe);
+};
+
+}
+}
+
+#endif
diff --git a/src/js-overlay/js_overlay_functions.cpp b/src/js-overlay/js_overlay_functions.cpp
new file mode 100644 (file)
index 0000000..69b1263
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * 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    javascript_functions.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_array.h>
+#include <js_overlay_functions.h>
+
+namespace JSCFunctions {
+
+std::string ConvertJSStringToStdString(JSStringRef value)
+{
+    int nSize = JSStringGetLength(value) + 1;
+    DPL::ScopedArray<char> textStr(new char[nSize]);
+    JSStringGetUTF8CString(value, textStr.Get(), nSize);
+    std::string ret = textStr.Get();
+    return ret;
+}
+
+JSValueRef JavaScriptPrintProc(JSContextRef context,
+                               JSObjectRef /*object*/,
+                               JSObjectRef /*thisObject*/,
+                               size_t argumentCount,
+                               const JSValueRef arguments[],
+                               JSValueRef* exception)
+{
+    if (argumentCount == 0 || !JSValueIsString(context, arguments[0])) {
+        LogError("Argument is not string");
+        return JSValueMakeUndefined(context);
+    }
+
+    JSStringRef textRef = JSValueToStringCopy(context, arguments[0], exception);
+    int nSize = JSStringGetLength(textRef) + 1;
+
+    DPL::ScopedArray<char> textStr(new char[nSize]);
+
+    JSStringGetUTF8CString(textRef, textStr.Get(), nSize);
+    LogDebug("\033[00;35m[jsPrint] " << textStr.Get());
+
+    JSStringRelease(textRef);
+    return JSValueMakeBoolean(context, true);
+}
+
+JSValueRef JavaScriptHookProc(
+        JSContextRef context,
+        JSObjectRef /*object*/,
+        JSObjectRef /*thisObject*/,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    bool inError = false;
+    if (argumentCount < 2 ||
+        argumentCount > 3 ||
+        !JSValueIsString(context, arguments[0]) ||
+        !JSValueIsString(context, arguments[1])) {
+
+        inError = true;
+    }
+
+    if (inError) {
+        LogError("*********************************************");
+        LogError("*********************************************");
+        LogError("Cannot print test Result");
+        LogError("*********************************************");
+        LogError("*********************************************");
+        return JSValueMakeUndefined(context);
+    }
+
+    std::string id, result, message;
+    JSStringRef idRef = JSValueToStringCopy(context, arguments[0], exception);
+    id = ConvertJSStringToStdString(idRef);
+    JSStringRelease(idRef);
+    JSStringRef idResult = JSValueToStringCopy(context,
+                                               arguments[1],
+                                               exception);
+    result = ConvertJSStringToStdString(idResult);
+    JSStringRelease(idResult);
+
+    if (argumentCount == 3 && !JSValueIsString(context, arguments[2])) {
+        JSStringRef idMessage = JSValueToStringCopy(context,
+                                                    arguments[0],
+                                                    exception);
+        message = ConvertJSStringToStdString(idMessage);
+        JSStringRelease(idMessage);
+    }
+
+    LogDebug("\033[00;35m***********************************************");
+    LogDebug("\033[00;35m***********************************************");
+    LogDebug("\033[00;35m TEST ID: " << id);
+    LogDebug("\033[00;35m RESULT: " << result);
+    LogDebug("\033[00;35m MESSAGE: " << message);
+    LogDebug("\033[00;35m***********************************************");
+    LogDebug("\033[00;35m***********************************************");
+
+    return JSValueMakeBoolean(context, true);
+}
+}
diff --git a/src/js-overlay/js_overlay_functions.h b/src/js-overlay/js_overlay_functions.h
new file mode 100644 (file)
index 0000000..7dbad59
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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    javascript_functions.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_EFL_JAVASCRIPT_FUNCTIONS_H_
+#define WRT_SRC_PLUGIN_SERVICE_EFL_JAVASCRIPT_FUNCTIONS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+
+namespace JSCFunctions {
+JSValueRef JavaScriptPrintProc(
+    JSContextRef context,
+    JSObjectRef /*object*/,
+    JSObjectRef /*thisObject*/,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef * exception);
+JSValueRef JavaScriptHookProc(
+    JSContextRef context,
+    JSObjectRef /*object*/,
+    JSObjectRef /*thisObject*/,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception);
+}
+
+#endif
+
diff --git a/src/js-overlay/js_overlay_support.cpp b/src/js-overlay/js_overlay_support.cpp
new file mode 100644 (file)
index 0000000..7e2ca84
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * 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        js_overlay_support.cpp
+ * @author
+ * @version     1.0
+ * @brief
+ */
+#include <memory>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <JavaScriptCore/JavaScript.h>
+
+#include <js_overlay_support.h>
+
+namespace JSOverlaySupport
+{
+
+class JSFunctionDispatcher
+{
+  public:
+    struct PrivateData
+    {
+        //required to unprotect object in destructor;
+        JSContextRef context;
+        JSObjectPtr originalFunction;
+        JSObjectPtr overlayFunction;
+    };
+
+    static JSClassRef getClassRef();
+
+  private:
+    static JSClassDefinition m_classInfo;
+
+  private:
+    static void initialize(JSContextRef context, JSObjectRef object);
+
+    static void finalize(JSObjectRef object);
+
+    static JSValueRef callAsFunction(JSContextRef ctx,
+                                     JSObjectRef function,
+                                     JSObjectRef thisObject,
+                                     size_t argumentCount,
+                                     const JSValueRef arguments[],
+                                     JSValueRef* exception);
+};
+
+
+
+JSObjectPtr createWrappedFunction(
+    JSGlobalContextRef ctx,
+    const JSObjectPtr& originalFunction,
+    const JSObjectPtr& overlayFunction,
+    const std::string& name)
+{
+    LogDebug("Creation overlay for function: " << name);
+    JSStringRef name_js = JSStringCreateWithUTF8CString(name.c_str());
+
+    JSFunctionDispatcher::PrivateData* priv =
+        new JSFunctionDispatcher::PrivateData;
+    priv->context = ctx;
+    priv->overlayFunction = overlayFunction;
+    priv->originalFunction = originalFunction;
+
+    auto fun = JSObjectMake(ctx, JSFunctionDispatcher::getClassRef(), priv);
+
+    JSStringRelease(name_js);
+
+    LogDebug("JSValueProtect invoked for: "
+             << overlayFunction->getObject() << " "
+             << originalFunction->getObject() << " Wrapper:"
+             << fun);
+
+    //the value is unprotected in finalize of the JSFunctionDispatcher object
+    JSValueProtect(ctx,
+                   static_cast<JSObjectRef>(
+                       overlayFunction->getObject()));
+
+    return JSObjectPtr(new JSObject(fun));
+}
+
+
+
+JSClassDefinition JSFunctionDispatcher::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "IGNORED",
+    0,
+    0,
+    0,
+    initialize,
+    finalize,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    callAsFunction,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSClassRef JSFunctionDispatcher::getClassRef()
+{
+    static auto classRef = JSClassCreate(&m_classInfo);
+    return classRef;
+}
+
+
+void JSFunctionDispatcher::initialize(JSContextRef /*context*/,
+                                      JSObjectRef /*object*/)
+{
+    LogDebug("Initialize");
+}
+
+void JSFunctionDispatcher::finalize(JSObjectRef object)
+{
+    LogDebug("finalize");
+
+    PrivateData* priv = static_cast<PrivateData*> (JSObjectGetPrivate(object));
+    if(priv)
+    {
+        JSValueUnprotect(priv->context,
+                         static_cast<JSObjectRef>(
+                             priv->overlayFunction->getObject()));
+        delete priv;
+    }
+}
+
+
+
+JSValueRef JSFunctionDispatcher::callAsFunction(
+    JSContextRef context,
+    JSObjectRef object,
+    JSObjectRef thisObject,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    LogDebug("Dispatcher invoked");
+
+    JSValueRef result = JSValueMakeUndefined(context);
+
+    JSFunctionDispatcher::PrivateData* priv =
+        static_cast<JSFunctionDispatcher::PrivateData*>
+            (JSObjectGetPrivate(object));
+
+    if(!priv)
+    {
+        LogError("Private object is NULL");
+        return result;
+    }
+
+    //call overlayed function
+    if (priv->overlayFunction->getObject())
+    {
+        LogDebug("Overlayed function will be invoked...");
+        result = JSObjectCallAsFunction(
+            context,
+            static_cast<JSObjectRef>(
+                priv->overlayFunction->getObject()),
+            thisObject,
+            argumentCount,
+            arguments,
+            exception);
+    }
+
+    //call original function
+    if (priv->originalFunction->getObject())
+    {
+        LogDebug("Original function will be invoked..");
+        result = JSObjectCallAsFunction(
+            context,
+            static_cast<JSObjectRef>(
+                priv->originalFunction->getObject()),
+            thisObject,
+            argumentCount,
+            arguments,
+            exception);
+    }
+
+    LogDebug("Done");
+    return result;
+}
+
+
+
+
+}
diff --git a/src/js-overlay/js_overlay_support.h b/src/js-overlay/js_overlay_support.h
new file mode 100644 (file)
index 0000000..3d7cd04
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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        js_function_wrapper.h
+ * @author
+ * @version     1.0
+ * @brief
+ */
+
+#ifndef _JAVASCRIPT_OVERLAY_SUPPORT_H
+#define _JAVASCRIPT_OVERLAY_SUPPORT_H
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <JavaScriptCore/JSObjectRef.h>
+#include <Commons/JSObject.h>
+
+namespace JSOverlaySupport
+{
+JSObjectPtr createWrappedFunction(
+    JSGlobalContextRef ctx,
+    const JSObjectPtr& originalFunction,
+    const JSObjectPtr& overlayFunction,
+    const std::string& name);
+}
+
+#endif
diff --git a/src/js-overlay/js_overlay_types.h b/src/js-overlay/js_overlay_types.h
new file mode 100644 (file)
index 0000000..c913f62
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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       js_overlay_types.h
+ * @author     Yunchan Cho (yunchan.cho@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_JS_OVERLAY_TYPES_H_
+#define _WRT_PLUGINS_JS_OVERLAY_TYPES_H_
+
+#include <string>
+
+namespace WrtPlugins {
+namespace W3C {
+
+// If needed, enum for new custom event should be defined here
+enum CustomEventType {
+    StorageCustomEvent,
+    ServiceCustomEvent,
+    SoftKeyboardChangeCustomEvent,
+};
+
+// Argument structure of SoftKeyboardChangeCustomEvent
+typedef struct SoftKeyboardChangeArgs {
+    std::string state; // value is 'on' or 'off'
+    int width;
+    int height;
+    SoftKeyboardChangeArgs():
+        width(0),
+        height(0)
+    {
+    }
+} SoftKeyboardChangeArgs;
+
+// If needed, argument structure of other custom events should be defined here
+
+} // W3C
+} // WrtPlugins
+#endif // _WRT_PLUGINS_JS_OVERLAY_TYPES_H_
index 1ea1a8f..1a64e70 100644 (file)
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 #
-include_config_file(Calendar)
-include_config_file(Camera)
 include_config_file(Filesystem)
-include_config_file(Messaging)
-include_config_file(Haptics)
-include_config_file(Contact)
-include_config_file(MMPlayer)
-include_config_file(Cpu)
-include_config_file(Power)
-include_config_file(Accelerometer)
-include_config_file(Profile)
 include_config_file(Widget)
-include_config_file(Radio)
-include_config_file(Orientation)
-include_config_file(Task)
-include_config_file(SystemInfo)
 include_config_file(LocalStorage)
-include_config_file(StorageEvent)
 include_config_file(WidgetDB)
 include_config_file(PluginManager)
-#DEPRACATED modules
-#include_config_file(Networking)
-#include_config_file(Geolocation)
-#include_config_file(Display)
-#include_config_file(Gallery)
-#include_config_file(Telephony)
-#include_config_file(FeatureLoader)
-#include_config_file(AppLauncher)
-#include_config_file(Device)
-#include_config_file(Memory)
-#include_config_file(System)
-#include_config_file(UI)
+include_config_file(StorageEvent)
+include_config_file(TizenServiceEvent)
+include_config_file(SoftKeyboardChangeEvent)
index c4073d7..7644767 100644 (file)
@@ -27,6 +27,11 @@ IManager& IManager::getInstance()
     return instance;
 }
 
+bool IManager::fileExists(const std::string &file)
+{
+    return WrtDeviceApis::Filesystem::Manager::fileExists(file);
+}
+
 IManager::IManager() :
     Commons::EventRequestReceiver<EventResolve>(
         Commons::ThreadEnum::FILESYSTEM_THREAD),
index dbd5396..0f13dcf 100644 (file)
@@ -46,6 +46,7 @@ class IManager :
 {
   public:
     static IManager& getInstance();
+    static bool fileExists(const std::string &file);
 
     virtual ~IManager() = 0;
 
index 80fb5f5..d1a4db7 100644 (file)
@@ -73,9 +73,9 @@ class ILocalStorage
     virtual size_t getStorageSize() const = 0;
 
     /**
-     * Get value for key
+     * Get key name for index
      */
-    virtual std::string getValueByIndex(size_t index) const = 0;
+    virtual std::string getKeyByIndex(size_t index) const = 0;
 
     /**
      * virtual destructor
index a46ee2a..9cd39b8 100644 (file)
@@ -40,11 +40,13 @@ PluginManagerFactory& PluginManagerFactory::getInstance()
 IPluginManagerPtr PluginManagerFactory::getPluginManager(
         int widgetHandle,
         const std::string &objectUri,
+        JSObjectRef object,
         JSContextRef context) const
 {
-    return IPluginManagerPtr(new PluginManager(widgetHandle, objectUri, context));
+    return IPluginManagerPtr(
+        new PluginManager(widgetHandle, objectUri, object, context));
 }
 
 }
 }
-}
\ No newline at end of file
+}
index d7093b8..ed3c578 100644 (file)
@@ -38,6 +38,7 @@ public:
     IPluginManagerPtr getPluginManager(
         int widgetHandle,
         const std::string &objectUri,
+        JSObjectRef object,
         JSContextRef context) const;
 private:
     PluginManagerFactory();
@@ -47,4 +48,4 @@ private:
 }
 }
 
-#endif // WRTDEVICEAPIS_PLUGIN_MANAGER_FACTORY_H_
\ No newline at end of file
+#endif // WRTDEVICEAPIS_PLUGIN_MANAGER_FACTORY_H_
diff --git a/src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h b/src/modules/API/SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h
new file mode 100644 (file)
index 0000000..2bc752b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2012 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        ISoftKeyboardChangeEvent.h
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief       softkeyboardchange event interfece
+ */
+
+#ifndef WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_INTERFACE_H
+#define WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_INTERFACE_H
+
+#include <memory>
+
+namespace WrtDeviceApis {
+namespace SoftKeyboardChangeEvent {
+namespace Api {
+
+class ISoftKeyboardChangeEvent
+{
+  public :
+    virtual std::string getState() const = 0;
+    virtual int getWidth() const = 0;
+    virtual int getHeight() const = 0;
+
+    virtual ~ISoftKeyboardChangeEvent() {};
+};
+
+typedef std::shared_ptr<ISoftKeyboardChangeEvent> ISoftKeyboardChangeEventPtr;
+
+} // Api
+} // SoftKeyboardChangeEvent
+} // WrtDeviceApis
+
+#endif // WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_INTERFACE_H
diff --git a/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp b/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.cpp
new file mode 100644 (file)
index 0000000..154a014
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 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        SoftKeyboardChangeEvent.cpp
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief       softkeyboardchange event class implementation
+ */
+
+#include "SoftKeyboardChangeEvent.h"
+
+namespace WrtDeviceApis {
+namespace SoftKeyboardChangeEvent {
+namespace Api {
+
+SoftKeyboardChangeEvent::SoftKeyboardChangeEvent(
+        std::string state, int width, int height):
+    m_state(state), m_width(width), m_height(height)
+{
+}
+
+SoftKeyboardChangeEvent::~SoftKeyboardChangeEvent()
+{
+}
+
+std::string SoftKeyboardChangeEvent::getState() const
+{
+    return m_state;
+}
+
+int SoftKeyboardChangeEvent::getWidth() const
+{
+    return m_width;
+}
+
+int SoftKeyboardChangeEvent::getHeight() const
+{
+    return m_height;
+}
+
+} // Api
+} // SoftKeyboardChangeEvent
+} // WrtDeviceApis
diff --git a/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h b/src/modules/API/SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h
new file mode 100644 (file)
index 0000000..ef28353
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2012 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        SoftKeyboardChangeEvent.h
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief       softkeyboardchange event class
+ */
+
+#ifndef WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_CLASS_H
+#define WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_CLASS_H
+
+#include <string>
+#include "ISoftKeyboardChangeEvent.h"
+
+namespace WrtDeviceApis {
+namespace SoftKeyboardChangeEvent {
+namespace Api {
+
+class SoftKeyboardChangeEvent : public ISoftKeyboardChangeEvent
+{
+  public :
+    explicit SoftKeyboardChangeEvent(
+            std::string state,
+            int width,
+            int height);
+    ~SoftKeyboardChangeEvent();
+
+    std::string getState() const;
+    int getWidth() const;
+    int getHeight() const;
+
+  private :
+    std::string m_state;
+    int m_width;
+    int m_height;
+};
+
+} // Api
+} // SoftKeyboardChangeEvent
+} // WrtDeviceApis
+
+#endif // WRT_PLUGIN_SOFTKEYBOARD_CHANGE_EVENT_CLASS_H
diff --git a/src/modules/API/SoftKeyboardChangeEvent/config.cmake b/src/modules/API/SoftKeyboardChangeEvent/config.cmake
new file mode 100644 (file)
index 0000000..398a39b
--- /dev/null
@@ -0,0 +1,11 @@
+get_current_path()
+
+set(API_SOFTKEYBOARD_CHANGE_EVENT_PATH
+    ${CURRENT_PATH}
+    PARENT_SCOPE
+    )
+
+set(SRCS_API_SOFTKEYBOARD_CHANGE_EVENT
+    ${CURRENT_PATH}/SoftKeyboardChangeEvent.cpp
+  PARENT_SCOPE
+)
diff --git a/src/modules/API/TizenServiceEvent/ITizenServiceEvent.h b/src/modules/API/TizenServiceEvent/ITizenServiceEvent.h
new file mode 100644 (file)
index 0000000..6a6831d
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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        ITizenServiceEvent.h
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief       Tizen Service event interfece
+ */
+
+#ifndef _WRT_PLUGIN_TIZEN_SERVICE_EVENT_INTERFACE_H_
+#define _WRT_PLUGIN_TIZEN_SERVICE_EVENT_INTERFACE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace WrtDeviceApis {
+namespace TizenServiceEvent {
+namespace Api {
+
+class ITizenServiceEvent
+{
+  public :
+    virtual float getScale() const = 0;
+    virtual std::string getBundle() const = 0;
+
+    virtual void setScale(const float scale) = 0;
+    virtual void setBundle(const std::string &bundle) = 0;
+    virtual ~ITizenServiceEvent() {};
+};
+
+typedef DPL::SharedPtr<ITizenServiceEvent> ITizenServiceEventPtr;
+
+} // Api
+} // TizenServiceEvent
+} // WrtDeviceApis
+
+#endif // _WRT_PLUGIN_TIZEN_SERVICE_EVENT_INTERFACE_H_
diff --git a/src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp b/src/modules/API/TizenServiceEvent/TizenServiceEvent.cpp
new file mode 100644 (file)
index 0000000..ba07076
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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        TizenServiceEvent.cpp
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief       Tizen appservice event class implementation
+ */
+
+#include "TizenServiceEvent.h"
+
+namespace WrtDeviceApis {
+namespace TizenServiceEvent {
+namespace Api {
+
+TizenServiceEvent::TizenServiceEvent()
+{
+}
+
+TizenServiceEvent::~TizenServiceEvent()
+{
+}
+
+float TizenServiceEvent::getScale() const
+{
+    return m_scale;
+}
+
+std::string TizenServiceEvent::getBundle() const
+{
+    return m_bundle;
+}
+
+void TizenServiceEvent::setScale(const float scale)
+{
+    m_scale = scale;
+}
+
+void TizenServiceEvent::setBundle(const std::string& bundle)
+{
+    m_bundle = bundle;
+}
+
+} // Api
+} // TizenServiceEvent
+} // WrtDeviceApis
diff --git a/src/modules/API/TizenServiceEvent/TizenServiceEvent.h b/src/modules/API/TizenServiceEvent/TizenServiceEvent.h
new file mode 100644 (file)
index 0000000..3bceb3b
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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        TizenServiceEvent.h
+ * @author      Yunchan Cho (yunchan.cho@samsung.com)
+ * @version     0.1
+ * @brief       Tizen Service event class
+ */
+
+#ifndef _WRT_PLUGIN_TIZEN_SERVICE_EVENT_CLASS_H_
+#define _WRT_PLUGIN_TIZEN_SERVICE_EVENT_CLASS_H_
+
+#include <string>
+#include "ITizenServiceEvent.h"
+
+namespace WrtDeviceApis {
+namespace TizenServiceEvent {
+namespace Api {
+
+class TizenServiceEvent : public ITizenServiceEvent
+{
+  public :
+
+    TizenServiceEvent();
+    ~TizenServiceEvent();
+
+    float getScale() const;
+    std::string getBundle() const;
+
+    void setScale(const float scale);
+    void setBundle(const std::string &bundle);
+
+  private :
+    float m_scale;
+    std::string m_bundle;
+};
+
+} // Api
+} // TizenServiceEvent
+} // WrtDeviceApis
+
+#endif // _WRT_PLUGIN_TIZEN_SERVICE_EVENT_CLASS_H_
diff --git a/src/modules/API/TizenServiceEvent/config.cmake b/src/modules/API/TizenServiceEvent/config.cmake
new file mode 100644 (file)
index 0000000..5a64dcd
--- /dev/null
@@ -0,0 +1,11 @@
+get_current_path()
+
+set(API_TIZEN_SERVICE_EVENT_PATH
+    ${CURRENT_PATH}
+    PARENT_SCOPE
+    )
+
+set(SRCS_API_TIZEN_SERVICE_EVENT
+  ${CURRENT_PATH}/TizenServiceEvent.cpp
+  PARENT_SCOPE
+)
index be6dce3..b402256 100644 (file)
@@ -29,9 +29,9 @@ namespace WrtDeviceApis {
 namespace Widget {
 namespace Api {
 
-IWidgetPtr WidgetFactory::createWidget(const Commons::IWrtWrapperPtr& wrapper)
+IWidgetPtr WidgetFactory::createWidget()
 {
-    return IWidgetPtr(new WrtDeviceApis::Widget::Widget(wrapper));
+    return IWidgetPtr(new WrtDeviceApis::Widget::Widget());
 }
 
 }
index a4abffd..9773e78 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <string>
 #include <dpl/noncopyable.h>
-#include <Commons/WrtWrapper/IWrtWrapper.h>
 #include <Widget/IWidget.h>
 
 namespace WrtDeviceApis {
@@ -41,7 +40,7 @@ class WidgetFactory : private DPL::Noncopyable
      * Create widget
      * @param[in] id of the widget
      */
-    static IWidgetPtr createWidget(const Commons::IWrtWrapperPtr& wrapper);
+    static IWidgetPtr createWidget();
 
   private:
     WidgetFactory()
index 97a90ca..7ee91eb 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_INTERFACE_H_
 #define WRT_PLUGINS_WRT_ENGINE_WIDGET_FEATURE_INTERFACE_H_
 
-#include <map>
+#include <list>
 #include <string>
 #include <dpl/shared_ptr.h>
 
@@ -33,7 +33,8 @@ namespace Api {
 class IWidgetFeature
 {
   public:
-    typedef std::map<std::string, std::string> Params;
+    typedef std::pair<std::string, std::string> Param;
+    typedef std::list<Param> Params;
     typedef Params::const_iterator ParamsIterator;
 
   public:
diff --git a/src/modules/API/config.cmake b/src/modules/API/config.cmake
new file mode 100644 (file)
index 0000000..82b25da
--- /dev/null
@@ -0,0 +1,3 @@
+include_config_file(Widget)\r
+include_config_file(StorageEvent)\r
+include_config_file(LocalStorage)
\ No newline at end of file
index 295a0e6..beadcd3 100644 (file)
 #
 
 set(TARGET_MODULE_FILESYSTEM "wrt-plugins-filesystem")
-set(TARGET_MODULE_CAMERA "wrt-plugins-camera")
-set(TARGET_MODULE_CALENDAR "wrt-plugins-calendar")
-set(TARGET_MODULE_MESSAGING "wrt-plugins-messaging")
-set(TARGET_MODULE_HAPTICS "wrt-plugins-haptics")
-set(TARGET_MODULE_CONTACT "wrt-plugins-contact")
-set(TARGET_MODULE_MMPLAYER "wrt-plugins-mmplayer")
-set(TARGET_MODULE_CPU "wrt-plugins-cpu")
-set(TARGET_MODULE_ACCELEROMETER "wrt-plugins-accelerometer")
 set(TARGET_MODULE_WIDGET "wrt-plugins-widget")
-set(TARGET_MODULE_TASK "wrt-plugins-task")
-set(TARGET_MODULE_ORIENTATION "wrt-plugins-orientation")
-set(TARGET_MODULE_RADIO "wrt-plugins-radio")
-set(TARGET_MODULE_POWER "wrt-plugins-power")
-set(TARGET_MODULE_PROFILE "wrt-plugins-profile")
-set(TARGET_MODULE_SYSTEMINFO "wrt-plugins-systeminfo")
 set(TARGET_MODULE_LOCALSTORAGE "wrt-plugins-localstorage")
 set(TARGET_MODULE_WIDGET_INTERFACE_DAO "wrt-plugins-widget-interface-dao")
 set(TARGET_MODULE_STORAGEEVENT "wrt-plugins-storageevent")
+set(TARGET_MODULE_TIZEN_SERVICE_EVENT "wrt-plugins-tizen-service-event")
+set(TARGET_MODULE_SOFTKEYBOARD_CHANGE_EVENT "wrt-plugins-softkeyboardchange-event")
 set(TARGET_MODULE_WIDGETDB "wrt-plugins-widgetdb")
 set(TARGET_MODULE_PLUGIN_MANAGER "wrt-plugins-plugin-manager")
 
 add_subdirectory(Filesystem)
-add_subdirectory(Camera)
-add_subdirectory(Calendar)
-add_subdirectory(Messaging)
-add_subdirectory(Haptics)
-add_subdirectory(Contact)
-add_subdirectory(MMPlayer)
-add_subdirectory(Cpu)
-add_subdirectory(Accelerometer)
 add_subdirectory(Widget)
-add_subdirectory(Task)
-add_subdirectory(Orientation)
-add_subdirectory(Radio)
-add_subdirectory(Power)
-add_subdirectory(Profile)
-add_subdirectory(SystemInfo)
 add_subdirectory(LocalStorage)
 add_subdirectory(WidgetInterfaceDAO)
-add_subdirectory(StorageEvent)
 add_subdirectory(WidgetDB)
 add_subdirectory(PluginManager)
+add_subdirectory(StorageEvent)
+add_subdirectory(TizenServiceEvent)
+add_subdirectory(SoftKeyboardChangeEvent)
index 1944f08..e5079dc 100644 (file)
@@ -29,7 +29,10 @@ target_link_libraries(${TARGET_NAME}
    ${LIBS_COMMONS}
    ${TARGET_COMMONS}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+set_target_properties(${TARGET_NAME} PROPERTIES 
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
     ${DESTINATION_LIB_PREFIX})
index abb3854..2b0a894 100644 (file)
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 #
-macro(install_header_file HEADER_FILE)
-    INSTALL(FILES ${API_LOCALSTORAGE_PATH}/${HEADER_FILE}
-        DESTINATION ${DESTINATION_HEADER_PREFIX}/LocalStorage)
-endmacro()
-
 set(TARGET_NAME ${TARGET_MODULE_LOCALSTORAGE})
 
 set(SRCS
   ${SRCS_API_LOCALSTORAGE}
 )
 
-add_library(${TARGET_NAME} SHARED ${SRCS})
+add_library(${TARGET_NAME} STATIC ${SRCS})
 
 target_link_libraries(${TARGET_NAME}
    ${LIBS_COMMONS}
    ${TARGET_COMMONS}
    ${TARGET_MODULE_WIDGET_INTERFACE_DAO}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
-
-INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
-    ${DESTINATION_LIB_PREFIX})
-
-install_header_file(ILocalStorage.h)
-install_header_file(LocalStorageMgr.h)
 
index 5dcb9a5..9de7e04 100644 (file)
@@ -35,7 +35,10 @@ target_link_libraries(${TARGET_NAME}
    ${TARGET_COMMONS}
    ${LIBS_PLATFORM_IMPLEMENTATION_NETWORKING}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+set_target_properties(${TARGET_NAME} PROPERTIES 
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
     ${DESTINATION_LIB_PREFIX})
index 5f319b0..a66bbfd 100644 (file)
@@ -25,8 +25,11 @@ endmacro()
 
 set(TARGET_NAME ${TARGET_MODULE_PLUGIN_MANAGER})
 
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+
 include_directories(
     ${INCLUDES_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
+    ${webkit2_INCLUDE_DIRS}}
 )
 
 set(SRCS
@@ -37,12 +40,16 @@ set(SRCS
 add_library(${TARGET_NAME} SHARED ${SRCS})
 target_link_libraries(${TARGET_NAME}
    ${LIBS_COMMONS}
+   ${TARGET_PLUGIN_LOADING_LIB}
    ${TARGET_COMMONS}
    ${TARGET_COMMONS_JAVASCRIPT}
    ${LIBS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER}
 )
 
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+set_target_properties(${TARGET_NAME} PROPERTIES
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
     ${DESTINATION_LIB_PREFIX})
diff --git a/src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt b/src/modules/packages/SoftKeyboardChangeEvent/CMakeLists.txt
new file mode 100644 (file)
index 0000000..84b9944
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright (c) 2012 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      Yunchan Cho (yunchan.cho@samsung.com)
+# @version     0.1
+
+set(TARGET_NAME ${TARGET_MODULE_SOFTKEYBOARD_CHANGE_EVENT})
+
+set(SRCS
+    ${SRCS_API_SOFTKEYBOARD_CHANGE_EVENT}
+)
+
+add_library(${TARGET_NAME} STATIC ${SRCS})
index 1cc3ac9..dc9ff0d 100644 (file)
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 #
-macro(install_header_file HEADER_FILE)
-    INSTALL(FILES ${API_STORAGE_EVENT_PATH}/${HEADER_FILE}
-        DESTINATION ${DESTINATION_HEADER_PREFIX}/StorageEvent)
-endmacro()
-
 set(TARGET_NAME ${TARGET_MODULE_STORAGEEVENT})
 
 set(SRCS
   ${SRCS_API_STORAGE_EVENT}
 )
 
-add_library(${TARGET_NAME} SHARED ${SRCS})
+add_library(${TARGET_NAME} STATIC ${SRCS})
 
 target_link_libraries(${TARGET_NAME}
    ${TARGET_MODULE_LOCALSTORAGE}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
-
-INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
-    ${DESTINATION_LIB_PREFIX})
-
-install_header_file(IStorageEvent.h)
-install_header_file(StorageEventMgr.h)
 
diff --git a/src/modules/packages/TizenServiceEvent/CMakeLists.txt b/src/modules/packages/TizenServiceEvent/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e8efc16
--- /dev/null
@@ -0,0 +1,26 @@
+# 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      Yunchan Cho (yunchan.cho@samsung.com)
+# @version     0.1
+
+set(TARGET_NAME ${TARGET_MODULE_TIZEN_SERVICE_EVENT})
+
+set(SRCS
+  ${SRCS_API_TIZEN_SERVICE_EVENT}
+)
+
+add_library(${TARGET_NAME} STATIC ${SRCS})
index f0aa421..74bf1a6 100644 (file)
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 #
-macro(install_header_file HEADER_FILE)
-    INSTALL(FILES ${API_WIDGET_PATH}/${HEADER_FILE}
-        DESTINATION ${DESTINATION_HEADER_PREFIX}/Widget)
-endmacro()
 
 set(TARGET_NAME ${TARGET_MODULE_WIDGET})
 
@@ -24,17 +20,11 @@ set(SRCS
     ${SRCS_IMPLEMENTATION_WIDGET}
 )
 
-add_library(${TARGET_NAME} SHARED ${SRCS})
+add_library(${TARGET_NAME} STATIC ${SRCS})
 
 target_link_libraries(${TARGET_NAME}
    ${LIBS_COMMONS}
    ${TARGET_COMMONS}
    ${TARGET_MODULE_WIDGETDB}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
 
-INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
-    ${DESTINATION_LIB_PREFIX})
-
-install_header_file(IWidget.h)
-install_header_file(WidgetFactory.h)
index 63d9cea..ec91fdb 100644 (file)
@@ -36,7 +36,10 @@ target_link_libraries(${TARGET_NAME}
    ${TARGET_COMMONS}
    ${LIBS_PLATFORM_IMPLEMENTATION_WIDGETDB}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+set_target_properties(${TARGET_NAME} PROPERTIES 
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
     ${DESTINATION_LIB_PREFIX})
index cb77604..2a6d20e 100644 (file)
@@ -39,7 +39,10 @@ target_link_libraries(${TARGET_NAME}
    ${dpl-db_LIBRARIES}
    ${dpl-wrt-dao-ro_LIBRARIES}
 )
-set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PACKAGE_VERSION})
+set_target_properties(${TARGET_NAME} PROPERTIES 
+ SOVERSION ${CMAKE_PROJECT_API_VERSION}
+ VERSION ${CMAKE_PROJECT_VERSION}
+)
 
 INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION
     ${DESTINATION_LIB_PREFIX})
index fbecc49..85b3a95 100644 (file)
 # in which this modules and AL modules are included is significant, i.e. VConf
 # needs to be included before Power as there are some CMake variables set that
 # are used in Power config.cmake file.
-
-include_config_file(VConf)
-include_config_file(DBus)
-
-
 ################################################################################
 
-include_config_file(Calendar)
-include_config_file(Camera-Webkit)
-include_config_file(Contact)
 include_config_file(Filesystem)
-include_config_file(Messaging)
-include_config_file(Haptics)
-include_config_file(Cpu)
-include_config_file(Power)
-include_config_file(MMPlayer)
-include_config_file(Accelerometer)
-include_config_file(Profile)
 include_config_file(Widget)
-include_config_file(Radio)
-include_config_file(Orientation)
-include_config_file(Task)
-include_config_file(SystemInfo)
 include_config_file(LocalStorage)
 include_config_file(WidgetInterfaceDAO)
 add_subdirectory(WidgetInterfaceDAO)
 include_config_file(WidgetDB)
 include_config_file(PluginManager)
-#DEPRACATED MODULES
-#include_config_file(Networking)
-#include_config_file(Geolocation)
-#include_config_file(FeatureLoader)
-##include_config_file(Camera)
-##include_config_file(Telephony)
-#include_config_file(Display)
-#include_config_file(Gallery)
-##include_config_file(AppLauncher)
-#include_config_file(Device)
-#include_config_file(Memory)
-#include_config_file(PhoneBook)
-#include_config_file(UI)
-#include_config_file(System)
diff --git a/src/modules/tizen/DEPRACATED/Camera-Webkit/Camera.cpp b/src/modules/tizen/DEPRACATED/Camera-Webkit/Camera.cpp
new file mode 100644 (file)
index 0000000..33e4ded
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+ * 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.
+ */
+/*
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "Camera.h"
+#include <pthread.h>
+#include <dpl/assert.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <Commons/Exception.h>
+#include <Commons/TypeTraits.h>
+
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+template<typename EventPtr>
+class CameraPrivateData
+{
+public:
+    Camera* camera;
+    EventPtr event;
+};
+
+enum EventTypeId
+{
+    BeginRecordingType,
+    TakePictureType,
+    CreatePreviewType
+};
+
+class OpaquePrivateData
+{
+public:
+    EventTypeId eventTypeId;
+    void* cameraPrivateData;
+};
+
+
+//GetEventTypeId
+template<typename T>
+EventTypeId getEventTypeId(const T& event){ Assert(0); }
+
+template<>
+EventTypeId getEventTypeId<Api::EventBeginRecordingSharedPtr>(
+    const Api::EventBeginRecordingSharedPtr& /*event*/)
+{
+    return BeginRecordingType;
+}
+
+template<>
+EventTypeId getEventTypeId<Api::EventTakePictureSharedPtr>(
+    const Api::EventTakePictureSharedPtr& /*event*/)
+{
+    return TakePictureType;
+}
+
+template<>
+EventTypeId getEventTypeId<Api::EventGetPreviewNodeSharedPtr>(
+    const Api::EventGetPreviewNodeSharedPtr& /*event*/)
+{
+    return CreatePreviewType;
+}
+
+template<typename EventPtr>
+OpaquePrivateData* createPrivateOpaqueData(Camera* camera,
+                                           const EventPtr& event)
+{
+    //create private opaque data
+    OpaquePrivateData* opaqueData = new OpaquePrivateData;
+
+    CameraPrivateData<EventPtr>* privateData = new CameraPrivateData<EventPtr>;
+    privateData->camera = camera;
+    privateData->event = event;
+
+    opaqueData->eventTypeId = getEventTypeId(event);
+    opaqueData->cameraPrivateData = privateData;
+
+    return opaqueData;
+}
+
+template<typename EventPtr>
+CameraPrivateData<EventPtr>* getPrivateData(void* data)
+{
+    OpaquePrivateData* opaqueData = static_cast<OpaquePrivateData*> (data);
+
+    CameraPrivateData<EventPtr>* privateData =
+        static_cast<CameraPrivateData<EventPtr> *>
+        (opaqueData->cameraPrivateData);
+
+    return privateData;
+}
+
+template<typename EventPtr>
+void deletePrivateData(void* data)
+{
+    OpaquePrivateData* opaqueData = static_cast<OpaquePrivateData*> (data);
+
+    CameraPrivateData<EventPtr>* privateData =
+        static_cast<CameraPrivateData<EventPtr> *>
+        (opaqueData->cameraPrivateData);
+
+    delete privateData;
+    delete opaqueData;
+}
+
+
+template<typename EventType, typename EventArg>
+EventType createEvent(const EventArg& arg1)
+{
+    return EventType(arg1);
+}
+
+
+template<typename EventType>
+class BaseCallbackHandler : private DPL::Noncopyable
+{
+public:
+    explicit BaseCallbackHandler(void* data) :
+        m_camera(NULL)
+    {
+        Assert(data);
+        CameraPrivateData<EventType>* privateData =
+            getPrivateData<EventType>(data);
+        m_camera = privateData->camera;
+        m_event = privateData->event;
+
+        deletePrivateData<EventType>(data);
+    }
+
+    virtual void handleErrorCallback(int error)
+    {
+        LogError("Error: " << error);
+        m_event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+        this->post();
+    }
+
+    virtual void handleSuccessCallback(void* data)
+    {
+        setPrivate(data);
+        this->post();
+    }
+
+    virtual void post() = 0;
+
+    virtual ~BaseCallbackHandler(){ }
+
+  protected:
+    virtual void setPrivate(void* /*data*/) {};
+
+protected:
+    Camera* m_camera;
+    EventType m_event;
+};
+
+template<typename EventType>
+class CallbackHandler : public BaseCallbackHandler<EventType>
+{
+    static_assert(WrtDeviceApis::Commons::AlwaysFalse<EventType>::value,
+                      "Error, no specialization found for given type");
+
+  public:
+    explicit CallbackHandler(void* data) :
+        BaseCallbackHandler<EventType>(data)
+    {
+    }
+
+    //virtual void post(){ }
+};
+
+template<>
+class CallbackHandler<Api::EventBeginRecordingSharedPtr>
+ : public BaseCallbackHandler<Api::EventBeginRecordingSharedPtr>
+{
+  public:
+    explicit CallbackHandler(void* data) :
+        BaseCallbackHandler(data)
+    {}
+
+    virtual void post(){
+        this->m_camera->setRecordingState(Camera::COMPLETED);
+        this->m_camera->
+            DPL::Event::ControllerEventHandler<JobDoneVideoRecordingEvent>::PostEvent(
+                createEvent<JobDoneVideoRecordingEvent,
+                Api::EventBeginRecordingSharedPtr>(this->m_event));
+    }
+
+    virtual void handleSuccessCallback(void* data)
+    {
+        this->m_camera->setRecordingState(Camera::COMPLETED);
+        BaseCallbackHandler<Api::EventBeginRecordingSharedPtr>::
+            handleSuccessCallback(data);
+    }
+};
+
+template<>
+class CallbackHandler<Api::EventTakePictureSharedPtr>
+ : public BaseCallbackHandler<Api::EventTakePictureSharedPtr>
+{
+  public:
+    explicit CallbackHandler(void* data) :
+        BaseCallbackHandler(data)
+    {}
+
+    virtual void post(){
+        this->m_camera->
+            DPL::Event::ControllerEventHandler<JobDoneTakePictureEvent>::PostEvent(
+                createEvent<JobDoneTakePictureEvent,
+                Api::EventTakePictureSharedPtr>(this->m_event));
+    }
+
+    virtual void setPrivate(void* data)
+    {
+        m_event->getCaptureOptionsRef()->setFileName(static_cast<char*>(data));
+    }
+};
+
+template<>
+class CallbackHandler<Api::EventGetPreviewNodeSharedPtr>
+ : public BaseCallbackHandler<Api::EventGetPreviewNodeSharedPtr>
+{
+  public:
+    explicit CallbackHandler(void* data) :
+        BaseCallbackHandler(data)
+    {}
+
+    virtual void post(){
+        this->m_camera->
+            DPL::Event::ControllerEventHandler<JobDoneCreatePreviewEvent>::PostEvent(
+                createEvent<JobDoneCreatePreviewEvent,
+                Api::EventGetPreviewNodeSharedPtr>(this->m_event));
+    }
+
+    virtual void setPrivate(void* data)
+    {
+        LogDebug("Enter");
+        m_event->setPreviewNode(data);
+    }
+};
+
+Camera::Camera(const Commons::IWrtCameraPtr& wrtCamera) :
+    m_wrtCamera(wrtCamera),
+    m_stateRecordingVideo (Camera::IDLE)
+{
+    CameraJobDoneController::Touch();
+}
+
+Camera::~Camera()
+{
+    LogDebug("enter");
+
+    CameraJobDoneController::SwitchToThread(NULL);
+}
+
+
+void Camera::OnRequestReceived(
+        const Api::EventTakePictureSharedPtr & event)
+{
+    LogDebug("enter");
+
+    event->switchToManualAnswer();
+
+    m_wrtCamera->captureImage(event->getCaptureOptionsRef()->getFileName(),
+                              checkHighResolutionRequired(event),
+                              camCaptureImageSuccessCallback,
+                              camCaptureImageErrorCallback,
+                              setPendingOperation,
+                              createPrivateOpaqueData(this,event));
+
+    LogDebug("leaving");
+}
+
+void Camera::OnRequestReceived(
+        const Api::EventBeginRecordingSharedPtr & event)
+{
+    LogDebug("enter");
+
+    if (m_stateRecordingVideo != Camera::IDLE) {
+        event->setExceptionCode(Commons::ExceptionCodes::AlreadyInUseException);
+        return;
+    }
+    m_stateRecordingVideo = Camera::PROCESSING;
+
+    //from now on we will have to call answer manually
+    event->switchToManualAnswer();
+
+    m_wrtCamera->startVideoCapture(event->getCaptureOptionsRef()->getFileName(),
+                                   checkHighResolutionRequired(event),
+                                   camCaptureVideoSuccessCallback,
+                                   camCaptureVideoErrorCallback,
+                                   setPendingOperation,
+                                   createPrivateOpaqueData(this,event));
+
+    LogDebug("leaving");
+}
+
+void Camera::OnRequestReceived(
+        const Api::EventEndRecordingSharedPtr & event)
+{
+    LogDebug("end request");
+    if (m_stateRecordingVideo == Camera::PROCESSING) {
+        m_wrtCamera->stopVideoCapture();
+    } else {
+        LogDebug("stopVideo has been called but no recording is in progress");
+        event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+    }
+}
+
+void Camera::OnRequestReceived(
+        const Api::EventGetPreviewNodeSharedPtr & event)
+{
+    LogDebug("enter");
+
+    event->switchToManualAnswer();
+
+    LogDebug("start createPreview");
+
+    m_wrtCamera->createPreviewNode(camPreviewSuccessCallback,
+                                   camPreviewErrorCallback,
+                                   setPendingOperation,
+                                   createPrivateOpaqueData(this,event));
+    LogDebug("leaving");
+}
+
+void Camera::camCaptureImageSuccessCallback(
+        const char* filename, void* data)
+{
+    LogDebug("*Picture* Captured. !!!");
+
+    CallbackHandler<Api::EventTakePictureSharedPtr> handler(data);
+    handler.handleSuccessCallback(const_cast<char*>(filename));
+}
+
+void Camera::camCaptureVideoSuccessCallback(const char* filename, void* data)
+{
+    LogDebug("*Video* Captured. !!!");
+
+    CallbackHandler<Api::EventBeginRecordingSharedPtr> handler(data);
+    handler.handleSuccessCallback(const_cast<char*>(filename));
+}
+
+void Camera::camPreviewSuccessCallback(
+        Commons::IWrtCamera::CameraPreviewNode node, void* data)
+{
+    LogDebug("enter");
+
+    CallbackHandler<Api::EventGetPreviewNodeSharedPtr> handler(data);
+    handler.handleSuccessCallback(node);
+}
+
+void Camera::camPreviewErrorCallback(int errorCode, void* data)
+{
+    LogDebug("enter");
+
+    CallbackHandler<Api::EventGetPreviewNodeSharedPtr> handler(data);
+    handler.handleErrorCallback(errorCode);
+}
+
+void Camera::camCaptureImageErrorCallback(int errorCode, void* data)
+{
+    LogDebug("enter");
+
+    CallbackHandler<Api::EventTakePictureSharedPtr> handler(data);
+    handler.handleErrorCallback(errorCode);
+}
+
+void Camera::camCaptureVideoErrorCallback(int errorCode, void* data)
+{
+    LogDebug("enter");
+
+    CallbackHandler<Api::EventBeginRecordingSharedPtr> handler(data);
+    handler.handleErrorCallback(errorCode);
+}
+
+void Camera::OnEventReceived(const JobDoneVideoRecordingEvent &event)
+{
+    LogDebug("enter");
+    if (m_stateRecordingVideo == COMPLETED && event.GetArg0()) {
+        EventRequestReceiver<Api::EventBeginRecording>::
+            ManualAnswer(event.GetArg0());
+        //event.Reset();
+    }
+    m_stateRecordingVideo = Camera::IDLE;
+}
+
+void Camera::OnEventReceived(const JobDoneCreatePreviewEvent &event)
+{
+    OnJobDoneReceived(event.GetArg0());
+}
+
+void Camera::OnEventReceived(const JobDoneTakePictureEvent &event)
+{
+    OnJobDoneReceived(event.GetArg0());
+}
+
+void Camera::OnCancelEvent(
+        const Api::EventBeginRecordingSharedPtr& event)
+{
+    LogDebug(__FUNCTION__);
+
+    if (Camera::PROCESSING == m_stateRecordingVideo) {
+        if (event->checkPendingOperation()) {
+            m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
+        }
+        setRecordingState(Camera::IDLE);
+    } else {
+        LogError("Cancel invoked, but the state is wrong");
+    }
+}
+
+void Camera::OnCancelEvent(const Api::EventTakePictureSharedPtr& event)
+{
+    cancelEvent(event);
+}
+
+void Camera::OnCancelEvent(
+    const Api::EventGetPreviewNodeSharedPtr& event)
+{
+    cancelEvent(event);
+}
+
+void Camera::setRecordingState(CameraState state)
+{
+    m_stateRecordingVideo = state;
+}
+
+void Camera::setPendingOperation(
+    Commons::IWrtCamera::CameraPendingOperation pendingOperation, void* data)
+{
+    LogDebug("Set pending operation callback invoked");
+
+    Assert(data);
+    OpaquePrivateData* opaqueData = static_cast<OpaquePrivateData*> (data);
+    Assert(opaqueData->cameraPrivateData);
+
+    switch (opaqueData->eventTypeId) {
+    case BeginRecordingType:
+        {
+            static_cast<CameraPrivateData<Api::EventBeginRecordingSharedPtr>* > (
+                    opaqueData->cameraPrivateData)
+                ->event->setPendingOperation(pendingOperation);
+            break;
+        }
+    case CreatePreviewType:
+        {
+            static_cast<CameraPrivateData<Api::EventGetPreviewNodeSharedPtr>* > (
+                    opaqueData->cameraPrivateData)
+                ->event->setPendingOperation(pendingOperation);
+            break;
+        }
+    case TakePictureType:
+        {
+            static_cast<CameraPrivateData<Api::EventGetPreviewNodeSharedPtr>* > (
+                    opaqueData->cameraPrivateData)
+                ->event->setPendingOperation(pendingOperation);
+            break;
+        }
+        default:
+            Assert(0);
+    }
+}
+
+
+}
+}
diff --git a/src/modules/tizen/DEPRACATED/Camera-Webkit/Camera.h b/src/modules/tizen/DEPRACATED/Camera-Webkit/Camera.h
new file mode 100644 (file)
index 0000000..27201fe
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+/*
+ * @author      Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_CAMERA_H_
+#define WRT_PLUGINS_CAMERA_H_
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.h>
+#include <dpl/shared_ptr.h>
+#include <API/Camera/ICamera.h>
+#include <API/Camera/ICaptureOptions.h>
+#include <API/Camera/EventTakePicture.h>
+#include <API/Camera/EventBeginRecording.h>
+#include <API/Camera/EventEndRecording.h>
+#include <API/Camera/EventGetPreviewNode.h>
+#include <Commons/Dimension.h>
+#include <Commons/WrtWrapper/IWrtCamera.h>
+
+namespace WrtDeviceApis{
+namespace Camera{
+
+DECLARE_GENERIC_EVENT_1(JobDoneTakePictureEvent,
+                        Camera::Api::EventTakePictureSharedPtr)
+DECLARE_GENERIC_EVENT_1(JobDoneVideoRecordingEvent,
+                        Camera::Api::EventBeginRecordingSharedPtr)
+DECLARE_GENERIC_EVENT_1(JobDoneCreatePreviewEvent,
+                        Camera::Api::EventGetPreviewNodeSharedPtr)
+
+
+typedef DPL::TypeListDecl<JobDoneTakePictureEvent,
+                          JobDoneVideoRecordingEvent,
+                          JobDoneCreatePreviewEvent
+                              >::Type JobDoneEvents;
+
+typedef DPL::Event::Controller<JobDoneEvents> CameraJobDoneController;
+
+class Camera: public Api::ICamera,
+              public CameraJobDoneController
+{
+public:
+    enum CameraState{
+        IDLE,
+        PROCESSING,
+        COMPLETED
+    };
+
+public:
+    explicit Camera(const Commons::IWrtCameraPtr& wrtCamera);
+
+    virtual ~Camera();
+
+    virtual void OnRequestReceived(
+        const Api::EventTakePictureSharedPtr &event);
+    virtual void OnRequestReceived(
+        const Api::EventBeginRecordingSharedPtr &event);
+    virtual void OnRequestReceived(
+        const Api::EventEndRecordingSharedPtr &event);
+    virtual void OnRequestReceived(
+        const Api::EventGetPreviewNodeSharedPtr &event);
+
+    virtual void OnEventReceived(const JobDoneVideoRecordingEvent &event);
+    virtual void OnEventReceived(const JobDoneCreatePreviewEvent &event);
+    virtual void OnEventReceived(const JobDoneTakePictureEvent &event);
+
+    void OnCancelEvent(const Api::EventBeginRecordingSharedPtr& event);
+    void OnCancelEvent(const Api::EventTakePictureSharedPtr& event);
+    void OnCancelEvent(const Api::EventGetPreviewNodeSharedPtr& event);
+
+    void setRecordingState(CameraState state);
+
+private:
+    static void camCaptureImageSuccessCallback(const char* filename,
+                                               void* data);
+    static void camCaptureVideoSuccessCallback(const char* filename,
+                                               void* data);
+    static void camPreviewSuccessCallback(
+            Commons::IWrtCamera::CameraPreviewNode node, void* data);
+
+    static void camCaptureImageErrorCallback(int errorCode, void* data);
+    static void camCaptureVideoErrorCallback(int errorCode, void* data);
+    static void camPreviewErrorCallback(int errorCode, void* data);
+
+    template<class EventType>
+    bool checkHighResolutionRequired(const EventType& event) const
+    {
+        return event->getCaptureOptionsRef()->getImageResolution()
+            == Api::ICaptureOptions::IMAGE_RESOLUTION_HIGH;
+    }
+
+    template<typename EventData>
+    void OnJobDoneReceived(DPL::SharedPtr<EventData> event)
+    {
+        LogDebug("enter");
+        if (event) {
+            EventRequestReceiver<EventData>::ManualAnswer(event);
+        }
+        LogDebug("post");
+    }
+
+    template<typename EventType>
+    void cancelEvent(const EventType& event)
+    {
+        LogDebug(__FUNCTION__);
+
+        if (event->checkPendingOperation()) {
+            m_wrtCamera->cancelAsyncOperation(event->getPendingOperation());
+        }
+    }
+
+    static void setPendingOperation(
+        Commons::IWrtCamera::CameraPendingOperation pendingOperation, void* data);
+
+private:
+    Commons::IWrtCameraPtr m_wrtCamera;
+
+    CameraState m_stateRecordingVideo;
+};
+
+}
+}
+#endif /* WRTPLUGINSCAMERA_H_ */
diff --git a/src/modules/tizen/DEPRACATED/Camera-Webkit/CameraManager.cpp b/src/modules/tizen/DEPRACATED/Camera-Webkit/CameraManager.cpp
new file mode 100644 (file)
index 0000000..53d26dd
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+/*
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+#include <dpl/foreach.h>
+#include "CameraManager.h"
+#include <Commons/Exception.h>
+#include <API/Camera/EventGetCameras.h>
+#include <API/Camera/ICamera.h>
+#include "Camera.h"
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+void CameraManager::OnRequestReceived(
+    const Api::EventGetCamerasPtr &event)
+{
+    LogDebug(__FUNCTION__);
+    try
+    {
+        if (m_cameras.empty()) {
+            DPL::Mutex::ScopedLock lock(&m_accessMutex);
+
+            if (m_cameras.empty()) {
+                Commons::IWrtCameraManager::WrtCamerasPtr cameras;
+                cameras = event->
+                    getConfiguration()->
+                        getWrtWrapper()->
+                            getCameraManagerInterface()->
+                                getCameras();
+
+                FOREACH(it, *cameras)
+                {
+                    Api::ICameraSharedPtr icamera(new Camera(*it));
+                    m_cameras.push_back(icamera);
+                }
+            }
+        }
+        event->setCamerasRef(m_cameras,0);
+        LogDebug("Nr of cameras: " << m_cameras.size());
+    }
+    catch(const Commons::Exception &exc)
+    {
+        LogError("Exception has occurred: " << std::hex << exc.getCode());
+        event->setExceptionCode(exc.getCode());
+    }
+}
+
+}
+}
diff --git a/src/modules/tizen/DEPRACATED/Camera-Webkit/CameraManager.h b/src/modules/tizen/DEPRACATED/Camera-Webkit/CameraManager.h
new file mode 100644 (file)
index 0000000..6fce3eb
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+/*
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_CAMERA_MANAGER_H_
+#define WRT_PLUGINS_CAMERA_MANAGER_H_
+
+#include <dpl/mutex.h>
+
+#include <API/Camera/ICameraManager.h>
+#include <API/Camera/EventGetCameras.h>
+
+namespace WrtDeviceApis {
+namespace Camera {
+
+class CameraManager : public Api::ICameraManager
+{
+protected:
+    virtual void OnRequestReceived(
+        const Api::EventGetCamerasPtr &event);
+
+private:
+    DPL::Mutex m_accessMutex;
+};
+
+}
+}
+#endif /* */
diff --git a/src/modules/tizen/DEPRACATED/Camera-Webkit/config.cmake b/src/modules/tizen/DEPRACATED/Camera-Webkit/config.cmake
new file mode 100644 (file)
index 0000000..6efbb40
--- /dev/null
@@ -0,0 +1,15 @@
+get_current_path()
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CAMERA
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CAMERA
+  ${CURRENT_PATH}/Camera.cpp
+  ${CURRENT_PATH}/CameraManager.cpp
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CAMERA
+  PARENT_SCOPE
+)
index 6cdaad9..68d533f 100755 (executable)
@@ -22,7 +22,9 @@
 #include <ctime>
 #include <cstdio>
 #include <sstream>
-#include <dirent.h>
+#include <fts.h>
+#include <ecore-1/Ecore_File.h>
+#include <eina-1/eina/eina_list.h>
 #include <dpl/log/log.h>
 #include <dpl/scoped_ptr.h>
 #include <dpl/errno_string.h>
 #include <Commons/Regex.h>
 #include <Filesystem/PathUtils.h>
 #include "Node.h"
-#include "System.h"
-#include "CopyCommand.h"
-#include "MoveCommand.h"
-#include "RemoveCommand.h"
 #include "Utils.h"
 
 namespace {
@@ -94,8 +92,10 @@ void Manager::removeOpenedNode(const INodePtr& node)
 
 bool Manager::checkIfOpened(const IPathPtr& path) const
 {
+    Assert(path);
     NodeListIterator it = m_openedNodes.begin();
     for (; it != m_openedNodes.end(); ++it) {
+        Assert(*it);
         if (*path == *(*it)->getPath()) {
             return true;
         }
@@ -187,40 +187,59 @@ void Manager::find(const IPathPtr& path,
         const EventFindPtr& event)
 {
     Try {
-        DIR* dir = opendir(path->getFullPath().c_str());
-        if (!dir) {
+        Assert(path && "path is NULL");
+        FTS *fts;
+        FTSENT *ftsent;
+        std::string pth=path->getFullPath();
+        char * const paths[] = {const_cast<char * const>(pth.c_str()), NULL};
+
+        if ((fts = fts_open(paths, FTS_PHYSICAL|FTS_NOCHDIR, NULL)) == NULL) {
+            //ERROR
+            int error = errno;
+            LogError(__PRETTY_FUNCTION__ << ": fts_open on "
+                    << pth
+                    << " failed with error: "
+                    << strerror(error));
             return;
         }
 
-        errno = 0;
-        struct dirent* entry = NULL;
-        while ((entry = readdir(dir))) {
-            if (event && event->checkCancelled()) {
-                break;
-            }
-            if (!strncmp(entry->d_name, ".",
-                         1) || !strncmp(entry->d_name, "..", 2)) {
-                continue;
-            }
-            IPathPtr childPath = *path + entry->d_name;
-            struct stat info;
-            memset(&info, 0, sizeof(struct stat));
-            if (lstat(childPath->getFullPath().c_str(), &info) == 0) {
-                if (matchFilters(entry->d_name, info, filters)) {
-                    result.push_back(Node::resolve(childPath));
-                }
-                if (S_ISDIR(info.st_mode)) {
-                    find(childPath, filters, result, event);
-                }
+        while ((ftsent = fts_read(fts)) != NULL) {
+            if(event && event->checkCancelled()) break;
+            switch (ftsent->fts_info) {
+                case FTS_DP:
+                    //directory in postorder - do nothing
+                    break;
+                case FTS_D:
+                case FTS_DC:
+                case FTS_F:
+                case FTS_SL:
+                case FTS_SLNONE:
+                case FTS_DEFAULT:
+                    //regular files, symbolic links, directories in preorder
+                    //and other file entries that can be processed further
+                    if (matchFilters(ftsent->fts_name, *ftsent->fts_statp, filters)) {
+                        IPathPtr childPath=IPath::create(ftsent->fts_path);
+                        result.push_back(Node::resolve(childPath));
+                    }
+                    break;
+                case FTS_NS:
+                case FTS_NSOK:
+                case FTS_DOT:
+                case FTS_DNR:
+                case FTS_ERR:
+                default:
+                    LogWarning(__PRETTY_FUNCTION__
+                            << ": traversal failed with error: "
+                            << strerror(ftsent->fts_errno));
+                    ThrowMsg(Commons::PlatformException,
+                            "Error reading directory");
             }
         }
 
-        if (errno != 0) {
-            ThrowMsg(Commons::PlatformException,
-                     "Error while reading directory.");
-        }
-
-        if (closedir(dir) != 0) {
+        if (fts_close(fts) == -1) {
+            int error = errno;
+            LogWarning(__PRETTY_FUNCTION__ << ": fts_close failed with error: "
+                    << strerror(error));
             ThrowMsg(Commons::PlatformException,
                      "Could not close platform node.");
         }
@@ -229,6 +248,49 @@ void Manager::find(const IPathPtr& path,
     }
 }
 
+void Manager::copyElement(
+        const std::string &src, const std::string &dest, bool recursive) const
+{
+    LogDebug("Copying src: " << src << " to: " << dest);
+
+    //element is a file:
+    if (EINA_TRUE != ecore_file_is_dir(src.c_str())) {
+        if (EINA_TRUE != ecore_file_cp(src.c_str(), dest.c_str())) {
+            ThrowMsg(Commons::PlatformException, "Failed to copy file");
+        }
+        return;
+    }
+    //element is a directory -> create it:
+    if (EINA_TRUE != ecore_file_mkdir(dest.c_str())) {
+        LogDebug("Failed to create destination directory");
+        ThrowMsg(Commons::PlatformException, "Failed to copy directory");
+    }
+    //copy all elements of directory:
+    if (recursive) {
+        Eina_List* list = ecore_file_ls(src.c_str());
+        void* data;
+        EINA_LIST_FREE(list, data)
+        {
+            Try
+            {
+                copyElement((src + '/' + static_cast<char*>(data)).c_str(),
+                            (dest + '/' + static_cast<char*>(data)).c_str());
+            }
+            Catch(Commons::PlatformException)
+            {
+                //remove rest of the list
+                EINA_LIST_FREE(list, data)
+                {
+                    free(data);
+                }
+                ReThrowMsg(Commons::PlatformException, "Failed to copy element");
+            }
+            free(data);
+        }
+    }
+
+}
+
 bool Manager::access(const IPathPtr& path,
         int accessType) const
 {
@@ -281,79 +343,116 @@ void Manager::OnRequestReceived(const EventResolvePtr& event)
     event->setCancelAllowed(true);
 }
 
+void Manager::checkPaths(
+        Api::IPathPtr &src,
+        Api::IPathPtr &dest) {
+    Assert(dest);
+    Assert(src);
+    if (!dest->isAbsolute()) {
+        dest = src->getPath() + *dest;
+    }
+
+    if (src == dest) {
+        ThrowMsg(Commons::PlatformException,
+                 "Destination is same as source: " << src->getFullPath());
+    }
+
+    INodePtr parent;
+    Try {
+        parent = Node::resolve(IPath::create(dest->getPath()));
+    }
+    Catch(Commons::PlatformException) {
+        ReThrowMsg(Commons::PlatformException,
+                   "Could not get destination's parent node.");
+    }
+
+    if (parent->getType() != NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException,
+                 "Destination's parent node is not directory.");
+    }
+
+    if (!access(parent->getPath(), AT_WRITE)) {
+        ThrowMsg(Commons::SecurityException,
+            "Not enough permissions to write to destination.");
+    }
+}
+
+bool Manager::pathExists(const std::string &path) {
+    errno = 0;
+    struct stat info;
+    memset(&info, 0, sizeof(struct stat));
+    int status = lstat(path.c_str(), &info);
+    if ((status != 0) && (errno != ENOENT)) {
+        ThrowMsg(Commons::PlatformException,
+                 "No access to platform destination node.");
+    }
+    return 0 == status;
+}
+
 void Manager::OnRequestReceived(const EventCopyPtr& event)
 {
     Try {
         INodePtr srcNode = Node::resolve(event->getSource());
-        if ((srcNode->getMode() & PERM_READ) == 0) {
+        int requiredAccess;
+        switch (srcNode->getType()) {
+            case NT_DIRECTORY:
+                requiredAccess = AT_EXEC;
+                break;
+            case NT_FILE:
+                requiredAccess = AT_READ;
+                break;
+        }
+        if (!access(srcNode->getPath(), requiredAccess)) {
             ThrowMsg(Commons::SecurityException,
-                     "Not enough permissions to read source node.");
+                "Not enough permissions to copy source node.");
         }
 
         IPathPtr src = event->getSource();
         IPathPtr dest = event->getDestination();
-        if (!dest->isAbsolute()) {
-            dest = src->getPath() + *dest;
-        }
 
-        if (src == dest) {
-            ThrowMsg(Commons::PlatformException,
-                     "Destination is same as source.");
-        }
-
-        INodePtr parent;
-        Try {
-            parent = Node::resolve(IPath::create(dest->getPath()));
-        }
-        Catch(Commons::PlatformException) {
-            ReThrowMsg(Commons::PlatformException,
-                       "Could not get destination's parent node.");
-        }
-
-        if (parent->getType() != NT_DIRECTORY) {
-            ThrowMsg(Commons::PlatformException,
-                     "Destination's parent node is not directory.");
-        }
+        checkPaths(src, dest);
 
         std::string realSrc = src->getFullPath();
         std::string realDest = dest->getFullPath();
 
-        errno = 0;
-        struct stat info;
-        memset(&info, 0, sizeof(struct stat));
-        int status = lstat(realDest.c_str(), &info);
-        if ((status != 0) && (errno != ENOENT)) {
-            ThrowMsg(Commons::PlatformException,
-                     "No access to platform destination node.");
-        }
-
-        if (((event->getOptions() & OPT_OVERWRITE) == 0) && (status == 0)) {
-            ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
-        }
+        if (pathExists(realDest)) {
+            //no owerwrite flag setted -> exception
+            if ((event->getOptions() & OPT_OVERWRITE) == 0) {
+                ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
+            }
 
-        if (event->checkCancelled()) {
-            //file is not copied yet, so we can cancel it now.
-            event->setCancelAllowed(true);
-            return;
-        }
+            if (event->checkCancelled()) {
+                //file is not copied yet, so we can cancel it now.
+                event->setCancelAllowed(true);
+                return;
+            }
 
-        if (event->getOptions() & OPT_OVERWRITE) {
-            DPL::ScopedPtr<RemoveCommand> remove(new RemoveCommand(dest));
-            remove->setRecursive(true);
-            remove->setForce(true);
-            System::run(remove.Get());
+            //destination exist. Need to be removed
+            Try {
+                INodePtr node = Node::resolve(event->getDestination());
+                node->remove(event->getOptions());
+            }
+            Catch(Commons::PlatformException) {
+                LogError("Exception: " << _rethrown_exception.GetMessage());
+                event->setExceptionCode(
+                    Commons::ExceptionCodes::PlatformException);
+            }
+            Catch(Commons::SecurityException) {
+                event->setExceptionCode(
+                    Commons::ExceptionCodes::SecurityException);
+            }
         }
-
-        DPL::ScopedPtr<CopyCommand> copy(new CopyCommand(src, dest));
-        copy->setRecursive(true);
-        System::run(copy.Get());
+        //Destination is not exist. Start copy now.
+        copyElement(realSrc, realDest);
 
         event->setResult(Node::resolve(dest));
     }
-    Catch(Commons::PlatformException) {
+    catch (const Commons::PlatformException& ex) {
+        LogError("Exception: " << ex.GetMessage());
         event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
     }
-    Catch(Commons::SecurityException) {
+    catch (const Commons::SecurityException& ex) {
+        LogError("Exception: " << ex.GetMessage());
         event->setExceptionCode(Commons::ExceptionCodes::SecurityException);
     }
     //file is copied already so we don't allow cancelling anymore.
@@ -367,45 +466,16 @@ void Manager::OnRequestReceived(const EventMovePtr& event)
         IPathPtr dest = event->getDestination();
 
         INodePtr srcNode = Node::resolve(src);
-        if ((srcNode->getMode() & PERM_WRITE) == 0)
-        {
+        if (!access(srcNode->getParent()->getPath(), AT_WRITE)) {
             ThrowMsg(Commons::SecurityException,
-                     "Not enough permissions to move source node.");
-        }
-
-        if (!dest->isAbsolute()) {
-            dest = src->getPath() + *dest;
-        }
-
-        if (src == dest) {
-            ThrowMsg(Commons::PlatformException,
-                     "Destination is same as source.");
+                "Not enough permissions to move source node.");
         }
 
-        INodePtr parent;
-        Try {
-            parent = Node::resolve(IPath::create(dest->getPath()));
-        }
-        Catch(Commons::PlatformException) {
-            ReThrowMsg(Commons::PlatformException,
-                       "Could not get destination's parent node.");
-        }
+        checkPaths(src, dest);
 
-        if (parent->getType() != NT_DIRECTORY) {
-            ThrowMsg(Commons::PlatformException,
-                     "Destination's parent node is not directory.");
-        }
+        bool destExists = pathExists(dest->getFullPath());
 
-        errno = 0;
-        struct stat info;
-        memset(&info, 0, sizeof(info));
-        int status = lstat(dest->getFullPath().c_str(), &info);
-        if ((status != 0) && (errno != ENOENT)) {
-            ThrowMsg(Commons::PlatformException,
-                     "No access to platform destination node.");
-        }
-
-        if ((0 == (event->getOptions() & OPT_OVERWRITE)) && (0 == status)) {
+        if (destExists && (0 == (event->getOptions() & OPT_OVERWRITE))) {
             ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
         }
 
@@ -424,15 +494,35 @@ void Manager::OnRequestReceived(const EventMovePtr& event)
             {
             case EXDEV:
                 {
-                    if ((srcNode->getMode() & PERM_READ) == 0)
-                    {
-                        ThrowMsg(Commons::SecurityException,
-                                 "Not enough permissions to move source node.");
+                    if (destExists) {
+                        //destination exist. Need to be removed
+                        Try {
+                            INodePtr node = Node::resolve(
+                                event->getDestination());
+                            node->remove(event->getOptions());
+                        }
+                        Catch(Commons::PlatformException) {
+                            LogError("Exception while removing dest directory");
+                            event->setExceptionCode(
+                                Commons::ExceptionCodes::PlatformException);
+                        }
+                        Catch(Commons::SecurityException) {
+                            event->setExceptionCode(
+                                Commons::ExceptionCodes::SecurityException);
+                        }
+                    }
+
+                    copyElement(src->getFullPath(),
+                                dest->getFullPath());
+                    //remove source files
+                    Try {
+                        INodePtr node = Node::resolve(event->getSource());
+                        node->remove(event->getOptions());
+                    }
+                    Catch(Commons::Exception) {
+                        LogError("Exception: "
+                                 << _rethrown_exception.GetMessage());
                     }
-                    DPL::ScopedPtr<MoveCommand>
-                            move(new MoveCommand(src, dest));
-                    move->setForce(event->getOptions() & OPT_OVERWRITE);
-                    System::run(move.Get());
                     break;
                 }
             default:
index 7edea91..e582a89 100644 (file)
@@ -115,6 +115,18 @@ class Manager : public Api::IManager
     static void setupLocation(Api::LocationType location,
                               const char* path);
 
+    void copyElement(const std::string &src,
+                     const std::string &dest,
+                     bool recursive = true) const;
+
+    /**
+     * Check two paths to copy/move. Checks if they are not the same and
+     * required permissions.
+     * @param src
+     * @param dest
+     */
+    void checkPaths(Api::IPathPtr &src, Api::IPathPtr &dest);
+    bool pathExists(const std::string &path);
   private:
     static Locations m_locations; ///< Paths to default locations.
     static const std::size_t m_maxPathLength; ///< Maximum path length.
index 527fa85..582fcba 100755 (executable)
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <cstdio>
 #include <unistd.h>
+#include <fts.h>
 #include <dirent.h>
 #include <errno.h>
 #include <pcrecpp.h>
@@ -144,6 +145,7 @@ NodeList Node::getChildNodes(const NodeFilterPtr& filter) const
             continue;
         }
         Try {
+            Assert(m_path);
             INodePtr node = Node::resolve(*m_path + entry->d_name);
             node->setPermissions(getPermissions()); // inherit access rights
             if (NodeFilterMatcher::match(node, filter)) {
@@ -184,6 +186,8 @@ INodePtr Node::createChild(
         ThrowMsg(Commons::SecurityException, "Not enough permissions.");
     }
 
+    Assert(m_path);
+    Assert(path);
     IPathPtr childPath = *m_path + *path;
     if (exists(childPath)) {
         ThrowMsg(Commons::PlatformException, "Node already exists.");
@@ -279,6 +283,8 @@ INodePtr Node::getParent() const
 {
     LocationPaths roots = IManager::getInstance().getLocationPaths();
     for (LocationPaths::iterator it = roots.begin(); it != roots.end(); ++it) {
+        Assert(*it);
+        Assert(m_path);
         if (*(*it) == *m_path) {
             return INodePtr();
         }
@@ -413,46 +419,78 @@ void Node::removeAsFile(const IPathPtr& path)
 void Node::removeAsDirectory(const IPathPtr& path,
                              bool recursive)
 {
+    Assert(path);
     if (recursive) {
-        DIR* dir = opendir(path->getFullPath().c_str());
-        if (!dir) {
-            LogError("File: " << path->getFullPath().c_str());
-            ThrowMsg(Commons::PlatformException,
-                     "Node does not exist or access denied.");
+        FTS *fts;
+        FTSENT *ftsent;
+        int error = 0;
+        std::string pth=path->getFullPath();
+        char * const paths[] = {const_cast<char * const>(pth.c_str()), NULL};
+
+        if ((fts = fts_open(paths, FTS_PHYSICAL|FTS_NOCHDIR, NULL)) == NULL) {
+            //ERROR
+            error = errno;
+            LogError(__PRETTY_FUNCTION__ << ": fts_open on "
+                    << pth
+                    << " failed with error: "
+                    << strerror(error));
+            ThrowMsg(Commons::PlatformException, "Failed to traverse Node");
         }
-        errno = 0;
-        struct dirent *entry = NULL;
-        while ((entry = readdir(dir))) {
-            if (!strncmp(entry->d_name, ".",
-                         1) || !strncmp(entry->d_name, "..", 2)) {
-                continue;
-            }
-            IPathPtr subPath = *path + entry->d_name;
-            struct stat info;
-            memset(&info, 0, sizeof(struct stat));
-            if (lstat(subPath->getFullPath().c_str(), &info) == 0) {
-                Try {
-                    if (S_ISDIR(info.st_mode)) {
-                        removeAsDirectory(subPath, true);
-                    } else if (S_ISREG(info.st_mode)) {
-                        removeAsFile(subPath);
+
+        while ((ftsent = fts_read(fts)) != NULL) {
+            switch (ftsent->fts_info) {
+                case FTS_D:
+                    //directory in preorder - do nothing
+                    break;
+                case FTS_DP:
+                    //directory in postorder - remove
+                    errno = 0;
+                    if (rmdir(ftsent->fts_accpath) != 0) {
+                        if (errno == EEXIST) {
+                            ThrowMsg(Commons::PlatformException,
+                                    "Node has child nodes.");
+                        }
+                        ThrowMsg(Commons::PlatformException,
+                                "Error while removing platform node.");
                     }
-                }
-                Catch(Commons::PlatformException) {
-                }
-                // TODO: Not sure if above exception should be swallowed.
+                    break;
+                case FTS_DC:
+                case FTS_F:
+                case FTS_NSOK:
+                case FTS_SL:
+                case FTS_SLNONE:
+                case FTS_DEFAULT:
+                    {
+                        //regular files and other objects that can safely be removed
+                        IPathPtr file_path = IPath::create(ftsent->fts_path);
+                        removeAsFile(file_path);
+                        break;
+                    }
+                case FTS_NS:
+                case FTS_DOT:
+                case FTS_DNR:
+                case FTS_ERR:
+                default:
+                    LogWarning(__PRETTY_FUNCTION__
+                            << ": traversal failed with error: "
+                            << strerror(ftsent->fts_errno));
+                    break;
             }
         }
-        closedir(dir);
-    }
 
-    errno = 0;
-    if (rmdir(path->getFullPath().c_str()) != 0) {
-        if (errno == EEXIST) {
-            ThrowMsg(Commons::PlatformException, "Node has child nodes.");
+        if (fts_close(fts) == -1) {
+            error = errno;
+            LogWarning(__PRETTY_FUNCTION__ << ": fts_close failed with error: "
+                    << strerror(error));
+        }
+    } else {
+        if (rmdir(path->getFullPath().c_str()) != 0) {
+            if (errno == EEXIST) {
+                ThrowMsg(Commons::PlatformException, "Node has child nodes.");
+            }
+            ThrowMsg(Commons::PlatformException,
+                    "Error while removing platform node.");
         }
-        ThrowMsg(Commons::PlatformException,
-                 "Error while removing platform node.");
     }
 }
 
index 85bb12b..ed22f05 100644 (file)
@@ -1,14 +1,17 @@
 get_current_path()
 
-pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+pkg_search_module(pcrecpp REQUIRED libpcrecpp
+                  ecore REQUIRED ecore-1)
 
 set(INCLUDES_PLATFORM_IMPLEMENTATION_FILESYSTEM
   ${pcrecpp_INCLUDE_DIRS}
+  ${ecore_INCLUDE_DIRS}
   PARENT_SCOPE
 )
 
 set(LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM
   ${pcrecpp_LIBRARIES}
+  ${ecore_LIBRARIES}
   PARENT_SCOPE
 )
 
@@ -17,12 +20,7 @@ set(SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM
   ${CURRENT_PATH}/Node.cpp
   ${CURRENT_PATH}/Path.cpp
   ${CURRENT_PATH}/Stream.cpp
-  ${CURRENT_PATH}/System.cpp
   ${CURRENT_PATH}/NodeFilterMatcher.cpp
-  ${CURRENT_PATH}/Command.cpp
-  ${CURRENT_PATH}/CopyCommand.cpp
-  ${CURRENT_PATH}/MoveCommand.cpp
-  ${CURRENT_PATH}/RemoveCommand.cpp
   ${CURRENT_PATH}/Utils.cpp
   PARENT_SCOPE
 )
index 53dae94..8f71524 100644 (file)
@@ -26,6 +26,7 @@
 #include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
 #include <dpl/wrt-dao-ro/WrtDatabase.h>
 #include <plugin_logic.h>
+#include <js_types.h>
 #include <dpl/wrt-dao-ro/common_dao_types.h>
 #include <Commons/Exception.h>
 #include <CommonsJavaScript/Converter.h>
@@ -33,6 +34,7 @@
 #include <dpl/log/log.h>
 #include <dpl/foreach.h>
 
+
 using namespace std;
 
 namespace {
@@ -46,13 +48,16 @@ namespace PluginManager {
 
 PluginManager::PluginManager(int widgetHandle,
                              const string &objectUri,
+                             JSObjectRef object,
                              JSContextRef context) :
     m_widgetHandle(widgetHandle),
+    m_objectInstance(object),
     m_objectUri(GLOBAL_OBJECT_NAME),
+    m_shortUri(objectUri),
     m_context(context)
 {
     m_objectUri.append(SEPARATOR).append(objectUri);
-    WrtDB::WrtDatabase::attachToThread();
+    WrtDB::WrtDatabase::attachToThreadRO();
 }
 
 PluginManager::~PluginManager()
@@ -84,12 +89,13 @@ bool PluginManager::loadChild(const string &name) const
         return false;
     }
 
-    // Create dao
     WrtDB::DbWidgetFeatureSet features;
+    WrtDB::WidgetType widgetType;
     Try
     {
         WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
         features = dao.getFeaturesList();
+        widgetType = dao.getWidgetType();
     }
     Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
     {
@@ -99,10 +105,29 @@ bool PluginManager::loadChild(const string &name) const
         return false;
     }
 
-    FOREACH (it, features) {
-        if (it->pluginId == handle) {
-            PluginLogicSingleton::Instance().addSpecialFeatureToSession(*it);
-            return true;
+    if (widgetType == WrtDB::APP_TYPE_TIZENWEBAPP) {
+        JavaScriptObject jsObject = {m_objectInstance,
+                                          m_shortUri};
+        return PluginLogicSingleton::Instance().loadPluginOnDemand(
+            handle, jsObject, const_cast<JSGlobalContextRef>(m_context));
+    }
+
+    //check does plugin with feature was requested
+    FOREACH (it, features)
+    {
+        if (it->pluginId == handle)
+        {
+            if(it->rejected)
+            {
+                LogWarning("Feature rejected by ACE");
+                continue;
+            }
+
+            JavaScriptObject jsObject = {m_objectInstance,
+                                                      m_shortUri};
+
+            return PluginLogicSingleton::Instance().loadPluginOnDemand(
+                handle, jsObject, const_cast<JSGlobalContextRef>(m_context));
         }
     }
     LogError("Plugin not loaded");
@@ -163,40 +188,75 @@ Api::IPluginManager::PropertyList PluginManager::getProperties() const
 
     m_propertyCache = PropertyList();
 
-    WrtDB::DbWidgetFeatureSet features;
-    Try
+    WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
+    string localUri = m_objectUri + SEPARATOR;
+
+    if (dao.getWidgetType() == WrtDB::APP_TYPE_TIZENWEBAPP)
     {
-        WrtDB::WidgetDAOReadOnly dao(m_widgetHandle);
-        features = dao.getFeaturesList();
+        WrtDB::PluginHandleList pluginHandleList =
+            WrtDB::PluginDAOReadOnly::getPluginHandleList();
+
+        FOREACH(it_pluginHandle, pluginHandleList)
+        {
+            WrtDB::ImplementedObjectsList implObjectList =
+                WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+                    *it_pluginHandle);
+
+            FOREACH(it_implObject, implObjectList)
+            {
+                //check if implemented object stats with localUri
+                if (it_implObject->find(localUri) == 0) {
+                    string property = *it_implObject;
+                    //remove local uri that predicts property name.
+                    property.erase(0, localUri.size());
+                    //check if property has its own properties.
+                    size_t pos = property.find(SEPARATOR);
+                    if (pos != string::npos) {
+                        //if so then remove them.
+                        property.erase(pos);
+                    }
+                    m_propertyCache->push_back(property);
+                }
+            }
+        }
     }
-    Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
+    else
     {
-        LogError("Cannot get feature list");
-        ReThrow(Commons::PlatformException);
-    }
+        WrtDB::DbWidgetFeatureSet features;
 
-    string localUri = m_objectUri + SEPARATOR;
-    WrtDB::DbWidgetFeatureSet::const_iterator feature = features.begin();
-    for (; feature != features.end(); ++feature) {
-        WrtDB::ImplementedObjectsList implObjs =
-            WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
-                feature->pluginId);
-        FOREACH(it, implObjs) {
-            //check if implemented object stats with localUri
-            if (it->find(localUri) == 0) {
-                string property = *it;
-                //remove local uri that predicts property name.
-                property.erase(0, localUri.size());
-                //check if property has its own properties.
-                size_t pos = property.find(SEPARATOR);
-                if (pos != string::npos) {
-                    //if so then remove them.
-                    property.erase(pos);
+        Try
+        {
+            features = dao.getFeaturesList();
+        }
+        Catch(WrtDB::WidgetDAOReadOnly::Exception::Base)
+        {
+            LogError("Cannot get feature list");
+            ReThrow(Commons::PlatformException);
+        }
+
+        WrtDB::DbWidgetFeatureSet::const_iterator feature = features.begin();
+        for (; feature != features.end(); ++feature) {
+            WrtDB::ImplementedObjectsList implObjs =
+                WrtDB::PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
+                    feature->pluginId);
+            FOREACH(it, implObjs) {
+                //check if implemented object stats with localUri
+                if (it->find(localUri) == 0) {
+                    string property = *it;
+                    //remove local uri that predicts property name.
+                    property.erase(0, localUri.size());
+                    //check if property has its own properties.
+                    size_t pos = property.find(SEPARATOR);
+                    if (pos != string::npos) {
+                        //if so then remove them.
+                        property.erase(pos);
+                    }
+                    m_propertyCache->push_back(property);
                 }
-                m_propertyCache->push_back(property);
             }
         }
     }
+
     return *m_propertyCache;
 }
 
index 8cabff7..b6564e1 100644 (file)
@@ -36,6 +36,7 @@ class PluginManager : public Api::IPluginManager
 public:
     PluginManager(int widgetHandle,
                   const std::string &objectUri,
+                  JSObjectRef object,
                   JSContextRef context);
     ~PluginManager();
     bool hasChild(const std::string &name) const;
@@ -53,7 +54,9 @@ private:
     typedef std::map<std::string, JSValueRef> ObjectList;
 
     int m_widgetHandle;
+    JSObjectRef m_objectInstance;
     std::string m_objectUri;
+    std::string m_shortUri;
     mutable DPL::Optional<PropertyList> m_propertyCache;
     ObjectList m_objectList;
     JSContextRef m_context;
index fd8e9c1..ccf3c80 100644 (file)
@@ -1,17 +1,19 @@
 get_current_path()
 
 pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
-pkg_search_module(wrt-plugin-loading REQUIRED wrt-plugin-loading)
+#pkg_search_module(wrt-plugin-loading REQUIRED wrt-plugin-loading)
 
 set(INCLUDES_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
   ${dpl-wrt-dao-ro_INCLUDE_DIRS}
   ${wrt-plugin-loading_INCLUDE_DIRS}
+  ${PLUGIN_LOADING_DIRS}
   PARENT_SCOPE
 )
 
 set(LIBS_PLATFORM_IMPLEMENTATION_PLUGIN_MANAGER
   ${dpl-wrt-dao-ro_LIBRARIES}
   ${wrt-plugin-loading_LIBRARIES}
+  ${TARGET_PLUGIN_LOADING_LIB}
   PARENT_SCOPE
 )
 
index 07cb18b..3bc7341 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <dpl/log/log.h>
 #include <Commons/StringUtils.h>
-
+#include <Commons/WrtAccess/WrtAccess.h>
 #include "Widget.h"
 #include <WidgetDB/IWidgetDB.h>
 #include <WidgetDB/WidgetDBMgr.h>
@@ -35,21 +35,23 @@ namespace Widget {
 using namespace std;
 using namespace WidgetDB::Api;
 
-Widget::Widget(Commons::IWrtWrapperPtr wrapper) :
-    m_wrtWrapper(wrapper)
+Widget::Widget() 
+{
+    using namespace WrtDeviceApis::Commons;
+    m_widgetId = WrtAccessSingleton::Instance().getWidgetId();
+}
+
+Widget::~Widget()
 {
-    if (!wrapper) {
-        LogError("Wrapper is NULL");
-    }
 }
 
 string Widget::getProperty(ConfigAttribute attr) const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     string value;
     Try {
-        IWidgetDBPtr widgetDB = getWidgetDB(m_wrtWrapper->getWidgetId());
+        IWidgetDBPtr widgetDB = getWidgetDB(m_widgetId);
         value = widgetDB->getConfigValue(attr);
     }
     Catch(Commons::InvalidArgumentException){
@@ -62,7 +64,7 @@ string Widget::getProperty(ConfigAttribute attr) const
 
 string Widget::getAuthor() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_author.isValid()) {
         m_author.setValue(getProperty(ConfigAttribute::AUTHOR_NAME));
@@ -72,7 +74,7 @@ string Widget::getAuthor() const
 
 string Widget::getAuthorEmail() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_authorEmail.isValid()) {
         m_authorEmail.setValue(getProperty(ConfigAttribute::AUTHOR_EMAIL));
@@ -82,7 +84,7 @@ string Widget::getAuthorEmail() const
 
 string Widget::getAuthorHref() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_authorHref.isValid()) {
         m_authorHref.setValue(getProperty(ConfigAttribute::AUTHOR_HREF));
@@ -92,7 +94,7 @@ string Widget::getAuthorHref() const
 
 string Widget::getDescription() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_description.isValid()) {
         m_description.setValue(getProperty(ConfigAttribute::DESCRIPTION));
@@ -102,7 +104,7 @@ string Widget::getDescription() const
 
 string Widget::getId() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     LogDebug("entered");
     if (!m_id.isValid()) {
@@ -113,7 +115,7 @@ string Widget::getId() const
 
 string Widget::getName() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_name.isValid()) {
         m_name.setValue(getProperty(ConfigAttribute::NAME));
@@ -123,7 +125,7 @@ string Widget::getName() const
 
 string Widget::getShortName() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_shortName.isValid()) {
         m_shortName.setValue(getProperty(ConfigAttribute::SHORT_NAME));
@@ -133,7 +135,7 @@ string Widget::getShortName() const
 
 string Widget::getVersion() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_version.isValid()) {
         m_version.setValue(getProperty(ConfigAttribute::VERSION));
@@ -143,7 +145,7 @@ string Widget::getVersion() const
 
 unsigned int Widget::getHeight() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_height.isValid()) {
         m_height.setValue(Commons::String::toInt(
@@ -154,7 +156,7 @@ unsigned int Widget::getHeight() const
 
 unsigned int Widget::getWidth() const
 {
-    checkWrapperPointer();
+    checkWidgetId();
 
     if (!m_width.isValid()) {
         m_width.setValue(Commons::String::toInt(
@@ -163,11 +165,11 @@ unsigned int Widget::getWidth() const
     return m_width.getValue();
 }
 
-void Widget::checkWrapperPointer() const
+void Widget::checkWidgetId() const
 {
-    if (!m_wrtWrapper) {
-        LogError("Null pointer");
-        Throw(Commons::NullPointerException);
+    if (m_widgetId < 0) {
+        LogError("Invalid widget id");
+        Throw(Commons::InvalidArgumentException);
     }
     return;
 }
index 2984fd0..eb2ca30 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <string>
 
-#include <Commons/WrtWrapper/IWrtWrapper.h>
+#include <Commons/WrtAccess/WrtAccess.h>
 
 #include <Widget/IWidget.h>
 #include <WidgetDB/IWidgetDB.h>
@@ -40,7 +40,8 @@ class Widget : public Api::IWidget
 {
   public:
 
-    explicit Widget(Commons::IWrtWrapperPtr wrtWrapper);
+    explicit Widget();
+    ~Widget();
 
     virtual std::string getAuthor() const;
     virtual std::string getAuthorEmail() const;
@@ -55,8 +56,6 @@ class Widget : public Api::IWidget
 
   protected:
 
-    Commons::IWrtWrapperPtr m_wrtWrapper;
-
     mutable StringProperty m_author;
     mutable StringProperty m_authorEmail;
     mutable StringProperty m_authorHref;
@@ -71,8 +70,9 @@ class Widget : public Api::IWidget
   private:
 
     std::string getProperty(WidgetDB::Api::ConfigAttribute) const;
+    void checkWidgetId() const;
 
-    void checkWrapperPointer() const;
+    int m_widgetId;
 };
 
 }
old mode 100755 (executable)
new mode 100644 (file)
index 2727beb..0618c65
 #include <dpl/wrt-dao-ro/feature_model.h>
 #include <dpl/wrt-dao-ro/common_dao_types.h>
 
+#include <dpl/localization/w3c_file_localization.h>
+
 #include "WidgetFeature.h"
 
-namespace { // anonymous
-    const int INVALID_WIDGET_HANDLE = -1;
-} // namespace
 
 namespace WrtDeviceApis {
 namespace WidgetDB {
@@ -97,9 +96,8 @@ std::string WidgetDB::getConfigValue(Api::ConfigAttribute attribute) const
     Try
     {
         WrtDB::WidgetDAOReadOnly dao(getWidgetId());
-        std::string language = getLanguage();
-        WrtDB::WidgetLocalizedInfo widgetInfo = dao.getLocalizedInfo(
-            DPL::FromUTF8String(language));
+        WrtDB::WidgetLocalizedInfo widgetInfo =
+            W3CFileLocalization::getLocalizedInfo(getWidgetId());
 
         std::ostringstream out;
 
@@ -221,23 +219,10 @@ Api::InstallationStatus WidgetDB::checkInstallationStatus(
         const WrtDB::WidgetGUID w_guid =
             WrtDB::WidgetGUID(DPL::FromUTF8String(gid));
 
-        WrtDB::DbWidgetHandle widgetHandle = INVALID_WIDGET_HANDLE;
-
-        WrtDB::DbWidgetHandleList widgetList = WrtDB::WidgetDAOReadOnly
-            ::getHandleList();
+        try {
+            WrtDB::DbWidgetHandle widgetHandle =
+                    WrtDB::WidgetDAOReadOnly::getHandle(w_guid);
 
-        FOREACH(iterator, widgetList) {
-            WrtDB::WidgetDAOReadOnly dao(*iterator);
-            WrtDB::WidgetGUID d_guid = dao.getGUID();
-            if (w_guid == d_guid) {
-                widgetHandle = *iterator;
-            }
-        }
-
-        // TODO check name
-        if (INVALID_WIDGET_HANDLE == widgetHandle) {
-            outStatus = Api::InstallationStatus::STATUS_UNINSTALLED;
-        } else {
             WrtDB::WidgetDAOReadOnly dao(widgetHandle);
             DPL::OptionalString ver = dao.getVersion();
             if (!ver || version > DPL::ToUTF8String(*ver)) {
@@ -247,6 +232,8 @@ Api::InstallationStatus WidgetDB::checkInstallationStatus(
             } else {
                 outStatus = Api::InstallationStatus::STATUS_LATEST;
             }
+        }catch (WrtDB::WidgetDAOReadOnly::Exception::WidgetNotExist) {
+            outStatus = Api::InstallationStatus::STATUS_UNINSTALLED;
         }
     }
     Catch(DPL::Exception)
@@ -381,7 +368,7 @@ std::string WidgetDB::getWidgetPersistentStoragePath() const
     Try
     {
         WrtDB::WidgetDAOReadOnly dao(getWidgetId());
-        return WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(*dao.getPkgname());
+        return WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(dao.getPkgName());
     }
     Catch(DPL::Exception)
     {
@@ -394,7 +381,7 @@ std::string WidgetDB::getWidgetTemporaryStoragePath() const
     Try
     {
         WrtDB::WidgetDAOReadOnly dao(getWidgetId());
-        return WrtDB::WidgetConfig::GetWidgetTemporaryStoragePath(*dao.getPkgname());
+        return WrtDB::WidgetConfig::GetWidgetTemporaryStoragePath(dao.getPkgName());
     }
     Catch(DPL::Exception)
     {
index 027a416..530acff 100644 (file)
@@ -57,7 +57,7 @@ void WidgetFeature::addParam(const std::string& paramName,
         const std::string& paramValue)
 {
     //LogDebug("entered");
-    m_params[paramName] = paramValue;
+    m_params.push_back(std::make_pair(paramName, paramValue));
 }
 
 WidgetFeature::~WidgetFeature()
index 43ac130..6362668 100644 (file)
@@ -1,14 +1,17 @@
 get_current_path()
 
 pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+pkg_search_module(dpl-utils-efl REQUIRED dpl-utils-efl)
 
 set(INCLUDES_PLATFORM_IMPLEMENTATION_WIDGETDB
   ${dpl-wrt-dao-ro_INCLUDE_DIRS}
+  ${dpl-utils-efl_INCLUDE_DIRS}
   PARENT_SCOPE
 )
 
 set(LIBS_PLATFORM_IMPLEMENTATION_WIDGETDB
   ${dpl-wrt-dao-ro_LDFLAGS}
+  ${dpl-utils-efl_LDFLAGS}
   PARENT_SCOPE
 )
 
index 7a011f6..60886cf 100644 (file)
@@ -5,10 +5,12 @@ pkg_search_module(dpl-db REQUIRED dpl-db-efl)
 
 include_directories(${CURRENT_PATH})
 
+STRING(REPLACE ";" ":" SQL_GENERATOR_INCLUDE_DIRS "${dpl-db_INCLUDE_DIRS}")
+
 ADD_CUSTOM_COMMAND( OUTPUT ${CURRENT_PATH}/widget_interface_db.sql
   COMMAND rm -f ${CURRENT_PATH}/.widget_interface.db
   COMMAND rm -f ${CURRENT_PATH}/widget_interface_db.sql
-  COMMAND gcc -Wall -I${dpl-db_INCLUDE_DIRS} -E ${CURRENT_PATH}/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CURRENT_PATH}/widget_interface_db.sql
+  COMMAND CPATH=${SQL_GENERATOR_INCLUDE_DIRS} gcc -Wall -E ${CURRENT_PATH}/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CURRENT_PATH}/widget_interface_db.sql
   COMMAND sqlite3 ${CURRENT_PATH}/.widget_interface.db ".read ${CURRENT_PATH}/widget_interface_db.sql" || rm -f ${CURRENT_PATH}/.widget_interface.db
   DEPENDS ${CURRENT_PATH}/widget_interface_db_sql_generator.h ${CURRENT_PATH}/widget_interface_db
 )
index a6fe123..f78ab4a 100644 (file)
@@ -38,6 +38,8 @@
 namespace {
 DPL::DB::SqlConnection::Flag::Type DATABASE_FLAGS =
     DPL::DB::SqlConnection::Flag::UseLucene;
+DPL::DB::SqlConnection::Flag::Option DATABASE_OPTIONS =
+    DPL::DB::SqlConnection::Flag::RW;
 const char *KEY_WIDGET_ARG = "widget_arg";
 }
 
@@ -50,7 +52,7 @@ WidgetInterfaceDAO::WidgetInterfaceDAO(int widgetHandle) :
     if (!checkDatabase()) {
         LogError("There is a problem with database");
     }
-    m_databaseInterface.AttachToThread();
+    m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
 }
 
 WidgetInterfaceDAO::~WidgetInterfaceDAO()
@@ -83,7 +85,8 @@ bool WidgetInterfaceDAO::checkDatabase()
 
         Try
         {
-            DPL::DB::SqlConnection con(databaseFile);
+            DPL::DB::SqlConnection con(databaseFile,
+                DATABASE_FLAGS, DATABASE_OPTIONS);
             con.ExecCommand(buffer.str().c_str());
         }
         Catch(DPL::DB::SqlConnection::Exception::Base)
@@ -102,8 +105,8 @@ bool WidgetInterfaceDAO::copyPropertiesFromWrtDatabase()
     using namespace DPL::DB::ORM::widget_interface;
 
     bool result = true;
-    WrtDB::WrtDatabase::attachToThread();
-    m_databaseInterface.AttachToThread();
+    WrtDB::WrtDatabase::attachToThreadRO();
+    m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
 
     Try
     {
@@ -163,14 +166,14 @@ void WidgetInterfaceDAO::setItem(const std::string& key,
         //check if key exists
         Properties::Select select(&m_databaseInterface);
         select.Where(
-            Equals<Properties::key>(DPL::FromASCIIString(key)));
+            Equals<Properties::key>(DPL::FromUTF8String(key)));
         std::list<Properties::Row> rows = select.GetRowList();
 
         if (rows.size() == 0) {
             Properties::Insert insert(&m_databaseInterface);
             Properties::Row row;
-            row.Set_key(DPL::FromASCIIString(key));
-            row.Set_value(DPL::FromASCIIString(value));
+            row.Set_key(DPL::FromUTF8String(key));
+            row.Set_value(DPL::FromUTF8String(value));
             row.Set_readonly(readOnly ? 1 : 0);
             row.Set_configxml(fromConfigXml ? 1 : 0);
             insert.Values(row);
@@ -182,10 +185,10 @@ void WidgetInterfaceDAO::setItem(const std::string& key,
             if (row.Get_readonly() != 0) {
                 Throw(Commons::LocalStorageValueNoModifableException);
             }
-            row.Set_value(DPL::FromASCIIString(value));
+            row.Set_value(DPL::FromUTF8String(value));
             row.Set_readonly(readOnly ? 1 : 0);
             Properties::Update update(&m_databaseInterface);
-            update.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+            update.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
             update.Values(row);
             update.Execute();
         }
@@ -207,14 +210,14 @@ void WidgetInterfaceDAO::removeItem(const std::string& key)
     Try
     {
         Properties::Select select(&m_databaseInterface);
-        select.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         bool readonly = select.GetSingleValue<Properties::readonly>();
         if (readonly) {
             ThrowMsg(Commons::LocalStorageValueNoModifableException,
                 "Cannot delete item. Item is readonly");
         }
         Properties::Delete deleteItem(&m_databaseInterface);
-        deleteItem.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+        deleteItem.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         deleteItem.Execute();
     }
     Catch(DPL::DB::SqlConnection::Exception::Base)
@@ -233,7 +236,7 @@ DPL::Optional<std::string> WidgetInterfaceDAO::getValue(
     Try
     {
         Properties::Select select(&m_databaseInterface);
-        select.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         std::list<DPL::String> value = select.GetValueList<Properties::value>();
         if (value.size() == 0) {
             return DPL::Optional<std::string>();
@@ -245,7 +248,6 @@ DPL::Optional<std::string> WidgetInterfaceDAO::getValue(
         LogError("Not found item " << key);
         ReThrow(Commons::PlatformException);
     }
-    return std::string();
 }
 
 void WidgetInterfaceDAO::clear(bool removeReadOnly)
@@ -287,7 +289,7 @@ size_t WidgetInterfaceDAO::getStorageSize() const
     return 0;
 }
 
-std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
+std::string WidgetInterfaceDAO::getKeyByIndex(size_t index) const
 {
     using namespace DPL::DB::ORM;
     using namespace DPL::DB::ORM::widget_interface;
@@ -297,7 +299,7 @@ std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
         Properties::Select select(&m_databaseInterface);
         select.OrderBy("key");
         std::list<DPL::String> list =
-            select.GetValueList<Properties::value>();
+            select.GetValueList<Properties::key>();
         if (index >= list.size()) {
             Throw(Commons::InvalidArgumentException);
         }
@@ -311,7 +313,6 @@ std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
         LogError("Cannot get item count");
         ReThrow(Commons::PlatformException);
     }
-    return std::string();
 }
 
 std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle)
@@ -320,15 +321,15 @@ std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle)
     using namespace WrtDB::WidgetConfig;
     using namespace WrtDB::GlobalConfig;
 
-    WrtDB::WrtDatabase::attachToThread();
+    WrtDB::WrtDatabase::attachToThreadRO();
 
     std::stringstream filename;
     Try
     {
         WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle);
-        DPL::Optional<DPL::String> pkgname = widgetDAO.getPkgname();
+        WrtDB::WidgetPkgName pkgname = widgetDAO.getPkgName();
 
-        filename << GetWidgetPersistentStoragePath(*pkgname)
+        filename << GetWidgetPersistentStoragePath(pkgname)
                  << "/"
                  << GetWidgetInterfaceDatabaseFile();
     }
index da5c8ff..371ae58 100644 (file)
@@ -47,7 +47,7 @@ class WidgetInterfaceDAO :
     DPL::Optional<std::string> getValue(const std::string& key) const;
     void clear(bool removeReadOnly);
     size_t getStorageSize() const;
-    std::string getValueByIndex(size_t index) const;
+    std::string getKeyByIndex(size_t index) const;
 
   protected:
     int m_widgetHandle;
diff --git a/src/modules/tizen/config.cmake b/src/modules/tizen/config.cmake
new file mode 100644 (file)
index 0000000..82b25da
--- /dev/null
@@ -0,0 +1,3 @@
+include_config_file(Widget)\r
+include_config_file(StorageEvent)\r
+include_config_file(LocalStorage)
\ No newline at end of file
diff --git a/src/plugin-loading/CMakeLists.txt b/src/plugin-loading/CMakeLists.txt
new file mode 100644 (file)
index 0000000..fbcf48a
--- /dev/null
@@ -0,0 +1,80 @@
+# 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   Lukasz Marek (l.marek@samsung.com)
+# @version  1.0
+#
+
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
+pkg_search_module(dpl REQUIRED dpl-efl)
+pkg_search_module(dpl-event REQUIRED dpl-event-efl)
+pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+
+set(PLUGIN_LOADING_SOURCES
+    ${PLUGIN_LOADING_DIRS}/plugin_logic.cpp
+    ${PLUGIN_LOADING_DIRS}/plugin.cpp
+    ${PLUGIN_LOADING_DIRS}/plugin_model.cpp
+    ${PLUGIN_LOADING_DIRS}/explorer.cpp
+    ${PLUGIN_LOADING_DIRS}/plugin_iframe_support.cpp
+    ${PLUGIN_LOADING_DIRS}/plugin_container_support.cpp
+    ${PLUGIN_LOADING_DIRS}/plugin_property_support.cpp
+    ${PLUGIN_LOADING_DIRS}/javascript_interface.cpp
+    ${PLUGIN_LOADING_DIRS}/js_page_session.cpp
+)
+
+INCLUDE_DIRECTORIES(
+    ${PLUGIN_MODULE_SRC_DIR}
+    ${PLUGIN_LOADING_DIRS}
+    ${webkit2_INCLUDE_DIRS}
+    ${plugin-types_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_PLUGIN_LOADING_LIB} SHARED
+    ${PLUGIN_LOADING_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGIN_LOADING_LIB} PROPERTIES
+    COMPILE_FLAGS -fPIC
+    LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGIN_LOADING_LIB} PROPERTIES
+    SOVERSION ${CMAKE_PROJECT_API_VERSION}
+    VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_PLUGIN_LOADING_LIB}
+    ${dpl_LIBRARIES}
+    ${dpl-event_LIBRARIES}
+    ${dpl-wrt-dao-ro_LIBRARIES}
+    ${TARGET_COMMONS}
+    ${TARGET_JS_OVERLAY}
+    wrt-plugins-tizen-service-event # static lib
+    wrt-plugins-softkeyboardchange-event       # static lib
+)
+
+INSTALL(TARGETS ${TARGET_PLUGIN_LOADING_LIB}
+    DESTINATION lib
+    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+    GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+)
+
+# For wrt-plugins
+INSTALL(FILES
+    ${PLUGIN_LOADING_DIRS}/plugin_logic.h
+    ${PLUGIN_LOADING_DIRS}/js_types.h
+    DESTINATION include/wrt-plugin-loading)
diff --git a/src/plugin-loading/explorer.cpp b/src/plugin-loading/explorer.cpp
new file mode 100644 (file)
index 0000000..bbb22d4
--- /dev/null
@@ -0,0 +1,484 @@
+/*
+ * 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    explorer.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @author  Yunchan Cho (yunchan.cho@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/foreach.h>
+#include <dpl/log/log.h>
+#include "explorer.h"
+#include "plugin_property_support.h"
+
+// JS overlay 
+#include <js_overlay_support.h>
+#include <js_overlay_types.h>
+#include <js_overlay_addEventListener.h>
+#include <TizenServiceEvent/ITizenServiceEvent.h>
+#include <TizenServiceEvent/TizenServiceEvent.h>
+#include <SoftKeyboardChangeEvent/ISoftKeyboardChangeEvent.h>
+#include <SoftKeyboardChangeEvent/SoftKeyboardChangeEvent.h>
+#include <JSClass/JSTizenServiceEvent.h>
+#include <JSClass/JSSoftKeyboardChangeEvent.h>
+
+
+namespace {
+//const char* SEPARATOR = ".";
+const std::string GLOBAL_OBJECT_NAME = "GLOBAL_OBJECT";
+}
+
+using namespace std;
+using namespace PluginModule;
+using namespace WrtPlugins::W3C;
+
+Explorer::Explorer(JSGlobalContextRef context) :
+    m_context(context)
+{
+    if (!context) {
+        LogError("Context is NULL");
+        return;
+    }
+
+    m_globalObject =
+        JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+
+    LogDebug("Register main frame");
+    //register main frame;
+    m_iframeSupport.registerIframe(m_globalObject);
+
+    m_propertySupport.reset(new WindowPropertySupport(m_context));
+
+    // initialization for use of custom event
+    if (!AddEventListenerSupport::isInitialized())
+    {
+        LogInfo("initialization for use of custom event");
+        AddEventListenerSupport::initialize(context);
+    }
+}
+
+Explorer::~Explorer()
+{
+    // deinitialization for use of custom event
+    if (AddEventListenerSupport::isInitialized()) {
+        LogInfo("deinitialization for use of custom event");
+        AddEventListenerSupport::deinitialize();
+    }
+}
+    
+JSObjectPtr Explorer::getJSObjectProperty(const std::string& propertyName,
+                                        JSObjectPtr object)
+{
+    LogDebug("Get object property " << propertyName);
+    return JavaScriptInterfaceSingleton::Instance().getJSObjectProperty(
+            m_context, object, propertyName);
+}
+
+JSObjectPtr Explorer::getProperty(
+    const string& requestedProperty,
+    JSObjectPtr   providedObject)
+{
+    LogDebug("Requested Property: " << requestedProperty);
+
+    if(!providedObject)
+    {
+        LogError("Provided object is empty");
+        return JSObjectPtr();
+    }
+
+    std::string currentObjectName;
+    std::string currentPropertyRequested = requestedProperty;
+    JSObjectPtr currentObject = providedObject;
+
+    while(true)
+    {
+        auto pos = currentPropertyRequested.find(".");
+        if (pos == string::npos)
+        {
+            return getJSObjectProperty(currentPropertyRequested, currentObject);
+        }
+
+        //check if requested object has child
+        currentObjectName = currentPropertyRequested.substr(0,pos);
+
+        if (currentPropertyRequested.size() <= pos+1)
+        {
+            LogError("Wrong name of requested property");
+            return JSObjectPtr();
+        }
+        currentPropertyRequested = currentPropertyRequested.substr(pos+1);
+
+        currentObject = getJSObjectProperty(currentObjectName, currentObject);
+        if(!currentObject)
+        {
+            LogError("Failed to get property: " << currentObjectName);
+            return JSObjectPtr();
+        }
+    }
+}
+
+bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
+                              JSGlobalContextRef context)
+{
+    LogDebug("Register to global object");
+
+    bool retValue;
+
+    if (declaration->getParentName() == GLOBAL_OBJECT_NAME)
+    {
+        LogDebug("Connect to Global object");
+        retValue = register_(declaration, m_globalObject, context);
+    }
+    else //PIM support
+    {
+        LogDebug("Connect to NOT global object");
+        //it should be master object name
+        string masterName = declaration->getParentName();
+        auto pos = masterName.find(".");
+        if (string::npos != pos)
+        {
+            LogError("ParentName not allowed");
+            return false;
+        }
+        auto masterObject = getJSObjectProperty(masterName, m_globalObject);
+        if (masterObject->getObject() == 0)
+        {
+            return false;
+        }
+        retValue = registerObject(declaration, masterName, masterObject, context);
+    }
+
+    if (declaration->checkIframesSupported()) {
+        LogDebug("Iframe supported");
+        m_iframeSupport.registerDeclaration(declaration);
+//        m_iframeSupport.invokeCallbackForMainFrame(m_context,
+//                                                   declaration,
+//                                                   newObject);
+    }
+    else {
+        LogDebug("Iframe NOT supported");
+    }
+
+    return retValue;
+}
+
+
+bool Explorer::registerObject(const JSObjectDeclarationPtr& declaration,
+                               const std::string& providedObjectName,
+                               JSObjectPtr providedObject,
+                               JSGlobalContextRef context)
+{
+    LogDebug("Register object. Provided object name: '" << providedObjectName
+             << "', registration of: '"  <<  declaration->getName() << "'");
+
+    std::string fullParentName = declaration->getParentName();
+    LogDebug("Parent name: " << declaration->getParentName());
+
+    if(fullParentName == providedObjectName)
+    {
+        LogDebug("Provided object match equaly to requested parent");
+        return register_(declaration, providedObject, context);
+    }
+
+    //check if object exists in fullParentName
+    auto pos = fullParentName.find(providedObjectName);
+    if(pos == string::npos)
+    {
+        LogError("Object: " << declaration->getName()
+                 << " should be child of: " << declaration->getParentName()
+                 << " but you provided object: " << providedObjectName);
+
+        return false;
+    }
+
+    if (fullParentName.size() <= pos+providedObjectName.size()+1)
+    {
+        LogError("Invalid object name");
+        return false;
+    }
+
+    auto currentRequesteProperty =
+        fullParentName.substr(pos+providedObjectName.size()+1);
+
+
+    JSObjectPtr jsObject = getProperty(
+        currentRequesteProperty, providedObject);
+
+    if(!jsObject->getObject())
+    {
+        LogError("Object: '" << declaration->getName()
+                 << "' should be child of: '" << declaration->getParentName()
+                 << "'. you provided object: '" << providedObjectName
+                 << "' but object is null");
+
+        return false;
+    }
+
+    return register_(declaration, jsObject, context);
+}
+
+bool Explorer::register_(const JSObjectDeclarationPtr& declaration,
+                              JSObjectPtr parent,
+                              JSGlobalContextRef context)
+{
+    LogInfo("Registration object: " << declaration->getParentName() <<
+            "<-" << declaration->getName());
+
+    Assert(parent && "parent object is NULL");
+
+    typedef JSObjectDeclaration::Options JO;
+
+    JSGlobalContextRef gContext = (context==NULL)?m_context:context;
+    JSObjectPtr newObject;
+
+    JSObjectPtr objectInstance = JavaScriptInterfaceSingleton::Instance().
+        createObject(gContext,declaration);
+
+    //function creation
+    if (declaration->getOptions() &&
+        declaration->getOptions()->getType() == JO::ClassType::Function)
+    {
+        LogDebug("Loading function object " << declaration->getName());
+
+        auto type = declaration->getOptions()->getIframeOverlay();
+        if (JO::IFrameOverlay::OverlayedBeforeOriginal == type)
+        {
+            LogDebug("Create overlayed function");
+            JSObjectPtr original =
+                JavaScriptInterfaceSingleton::Instance().
+                getJSObjectProperty(gContext,
+                                    parent,
+                                    declaration->getName());
+            newObject = JSOverlaySupport::
+                createWrappedFunction(gContext,
+                                      original,
+                                      objectInstance,
+                                      declaration->getName());
+        }
+        else
+        {
+            LogDebug("create normal function");
+            newObject = objectInstance;
+        }
+    }
+    else //object creation
+    {
+        newObject = objectInstance;
+    }
+
+    JavaScriptInterfaceSingleton::Instance().setObjectProperty(
+            gContext,
+        parent,
+        declaration->getName(),
+        newObject);
+
+    //notice
+    if (declaration->getOptions() &&
+        (declaration->getOptions()->getIframeNotice() ==
+         JO::IFrameNotice::AlwaysNotice))
+    {
+        declaration->getOptions()->invokeCallback(gContext,
+                                                  parent->getObject(),
+                                                  objectInstance->getObject());
+    }
+
+
+    return true;
+}
+
+void Explorer::registerObjectIntoIframe(const JSObjectDeclarationPtr& declaration,
+                                        JSObjectPtr frameObject,
+                                        JSGlobalContextRef context)
+{
+    if (declaration->getParentName() == GLOBAL_OBJECT_NAME)
+    {
+        LogDebug("Connect to Global object of IFRAME");
+        register_(declaration, frameObject, context);
+        return;
+    }
+
+    //PIM SUPPORT
+    {
+        LogWarning("Connect to NOT global object of IFRAME");
+        //it should be master object name
+        string masterName = declaration->getParentName();
+        auto pos = masterName.find(".");
+        if (string::npos != pos)
+        {
+            LogError("ParentName not allowed");
+            return;
+        }
+        auto masterObject = getJSObjectProperty(masterName, frameObject);
+        if (!masterObject->getObject())
+        {
+            LogError("Object not exist in frame");
+            return;
+        }
+        register_(declaration, masterObject, context);
+    }
+}
+
+
+void Explorer::loadFrame(JSGlobalContextRef context)
+{
+    LogDebug("Frame attached");
+
+    JSObjectPtr frameObject =
+        JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+
+    LogDebug("Register main frame");
+    //register main frame;
+
+    if(frameObject->getObject() == m_globalObject->getObject())
+    {
+        // Main page was already loaded from constructor
+        LogDebug("Main page loaded");
+        return;
+    }
+
+    m_iframeSupport.registerIframe(frameObject);
+
+    auto iframeObjects = m_iframeSupport.getIframeObjects();
+
+    FOREACH(object, iframeObjects)
+    {
+        LogDebug("Register object: " << (*object)->getName() );
+
+        registerObjectIntoIframe(*object, frameObject, context);
+    }
+}
+
+void Explorer::unloadFrame(JSGlobalContextRef context)
+{
+    LogDebug("Frame detached");
+
+    JSObjectPtr frameObject =
+        JavaScriptInterfaceSingleton::Instance().getGlobalObject(context);
+
+    m_iframeSupport.unregisterIframe(frameObject);
+}
+
+void Explorer::removePluginsFromIframes()
+{
+    LogDebug("Remove plugins from iframes");
+
+    if (m_iframeSupport.hasIframes())
+    {
+        LogDebug("Removing iframes");
+        JavaScriptInterfaceSingleton::Instance().removeIframes(m_context);
+    }
+}
+
+void Explorer::deregisterObject(const JSObjectDeclarationPtr& declaration)
+{
+    LogDebug("Deregister object " << declaration->getName());
+
+    if (GLOBAL_OBJECT_NAME != declaration->getParentName())
+    {
+        LogWarning("Ignored remove property " << declaration->getName());
+        return;
+    }
+
+    JavaScriptInterfaceSingleton::Instance().
+        removeObjectProperty(m_context,
+                             m_globalObject,
+                             declaration->getName());
+}
+
+void Explorer::cleanIframesData()
+{
+    LogDebug("Clean iframes data");
+    m_iframeSupport.clean();
+}
+
+void Explorer::callEventListeners(CustomEventType eventType, void* data)
+{
+    using namespace WrtPlugins::Tizen;
+    // get iframe objects from javascript global context
+    JavaScriptInterface::ObjectsListPtr frameLists =
+        JavaScriptInterfaceSingleton::Instance().getIframesList(m_context);
+
+    // get main frame object from javascript global context
+    JSObjectRef mainFrame = JSContextGetGlobalObject(m_context);
+    frameLists->push_back(JSObjectPtr(new JSObject(mainFrame)));
+
+    if (eventType == ServiceCustomEvent) {
+        using namespace WrtDeviceApis::TizenServiceEvent::Api;
+        // set user data of js callback function for 'appservice' js event
+        ITizenServiceEventPtr event = ITizenServiceEventPtr(new TizenServiceEvent());
+        event->setScale(m_propertySupport->getScale());
+        event->setBundle(m_propertySupport->getBundle());
+
+        // call js callback function for 'appservice' js event on each frame
+        FOREACH(it, *frameLists)
+        {
+            JSObjectRef frame = static_cast<JSObjectRef>((*it).Get()->getObject());
+
+            auto eventPriv =
+                new JSTizenServiceEventPrivateObject(m_context, event);
+            JSObjectRef eventObject =
+                JSObjectMake(m_context, JSTizenServiceEvent::getClassRef(), eventPriv);
+
+            AddEventListenerSupport::CallCustomEventListenersFromIFrame(
+                    frame, eventType, eventObject);
+        }
+    } else if (eventType == SoftKeyboardChangeCustomEvent) {
+        using namespace WrtDeviceApis::SoftKeyboardChangeEvent::Api;
+        if (!data) {
+            LogDebug("no ime size");
+            return;
+        }
+
+        // set user data of js callback function for 'softkeyboardchange' js event
+        SoftKeyboardChangeArgs* args = static_cast<SoftKeyboardChangeArgs *>(data);
+        ISoftKeyboardChangeEventPtr event =
+            ISoftKeyboardChangeEventPtr(
+                    new SoftKeyboardChangeEvent(
+                        args->state,
+                        args->width,
+                        args->height));
+        LogInfo("softkeyboard event's state: " << args->state);
+
+        // call js callback function for 'softkeyboardchange' js event on each frame
+        FOREACH(it, *frameLists)
+        {
+            JSObjectRef frame = static_cast<JSObjectRef>((*it).Get()->getObject());
+
+            auto eventPriv =
+                new JSSoftKeyboardChangeEventPrivateObject(m_context, event);
+            JSObjectRef eventObject =
+                JSObjectMake(
+                        m_context,
+                        JSSoftKeyboardChangeEvent::getClassRef(),
+                        eventPriv);
+
+            AddEventListenerSupport::CallCustomEventListenersFromIFrame(
+                    frame, eventType, eventObject);
+        }
+    } else {
+        LogInfo("Not supported custom event type");
+        return;
+    }
+
+}
+
+WindowPropertySupport* Explorer::getWindowPropertySupport()
+{
+    return m_propertySupport.get();
+}
diff --git a/src/plugin-loading/explorer.h b/src/plugin-loading/explorer.h
new file mode 100644 (file)
index 0000000..0c81dcf
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * 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    explorer.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_EXPLORER_H_
+#define WRT_SRC_PLUGIN_SERVICE_EXPLORER_H_
+
+#include <string>
+
+#include <dpl/noncopyable.h>
+#include <dpl/exception.h>
+#include <dpl/shared_ptr.h>
+
+#include <Commons/JSObject.h>
+#include <Commons/JSObjectDeclaration.h>
+//JSGlobalContextRef
+#include "javascript_interface.h"
+#include "plugin_iframe_support.h"
+#include "plugin_property_support.h"
+
+//JS overlay
+#include <js_overlay_types.h>
+
+using namespace PluginModule;
+using namespace WrtPlugins::W3C;
+
+class Explorer : private DPL::Noncopyable
+{
+  public:
+    explicit Explorer(JSGlobalContextRef context);
+    ~Explorer();
+
+    //register to global frame
+    bool registerObject(const JSObjectDeclarationPtr& declaration,
+                        JSGlobalContextRef context);
+
+    bool registerObject (const JSObjectDeclarationPtr& declaration,
+                         const std::string& parentObjectName,
+                         JSObjectPtr parentObject,
+                         JSGlobalContextRef context);
+
+    void deregisterObject(const JSObjectDeclarationPtr& declaration);
+
+    // new load/unload frame API
+    void loadFrame(JSGlobalContextRef context);
+    void unloadFrame(JSGlobalContextRef context);
+
+    void removePluginsFromIframes();
+    void cleanIframesData();
+    void callEventListeners(CustomEventType eventType, void* data);
+
+    WindowPropertySupport* getWindowPropertySupport();
+
+  private:
+
+    IframesSupport m_iframeSupport;
+
+    //globalContext
+    JSGlobalContextRef m_context;
+
+    //global object of main frame
+    JSObjectPtr m_globalObject;
+
+    std::unique_ptr<WindowPropertySupport> m_propertySupport;
+
+  private:
+    void registerObjectIntoIframe(const JSObjectDeclarationPtr& declaration,
+                                  JSObjectPtr parentObject,
+                                  JSGlobalContextRef context);
+
+    bool register_(const JSObjectDeclarationPtr& declaration,
+                              JSObjectPtr parent,
+                              JSGlobalContextRef context);
+
+
+    JSObjectPtr getJSObjectProperty(const std::string& propertyName,
+                                  JSObjectPtr object);
+
+    JSObjectPtr getProperty(
+        const std::string& requestedProperty,
+        JSObjectPtr   providedObject);
+};
+
+typedef DPL::SharedPtr<Explorer> ExplorerPtr;
+#endif
diff --git a/src/plugin-loading/javascript_interface.cpp b/src/plugin-loading/javascript_interface.cpp
new file mode 100644 (file)
index 0000000..0534397
--- /dev/null
@@ -0,0 +1,426 @@
+/*
+ * 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        plugin_webkit.h
+ * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation file of webkit js plugin
+ *              accessing routines in EFL
+ */
+#include <javascript_interface.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_array.h>
+#include <vector>
+#include <dpl/singleton_impl.h>
+#include <string>
+#include <dpl/foreach.h>
+#include <dpl/noncopyable.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <JavaScriptCore/JSObjectRef.h>
+
+IMPLEMENT_SINGLETON(JavaScriptInterface)
+
+#define CHECK_JSVALUE_IS_UNDEFINED_RETURN(context, object, ret) \
+    if (JSValueIsUndefined(context, object)) {\
+        LogError("Object " << #object << " is undefined");\
+        return ret;\
+    }
+
+#define CHECK_JSOBJECT_IS_NULL_RETURN(object, ret) \
+    if (!object) {\
+        LogError("Object " << #object << " is NULL");\
+        return ret;\
+    }
+
+namespace {
+/**
+ * Converts JSStringRef to std::string
+ * */
+std::string toString(const JSStringRef& arg)
+{
+    Assert(arg);
+    std::string result;
+    size_t jsSize = JSStringGetMaximumUTF8CStringSize(arg);
+    if (jsSize > 0) {
+        ++jsSize;
+        DPL::ScopedArray<char> buffer(new char[jsSize]);
+        size_t written = JSStringGetUTF8CString(arg, buffer.Get(), jsSize);
+        if (written > jsSize) {
+            LogError("Conversion could not be fully performed.");
+            return std::string();
+        }
+        result = buffer.Get();
+    }
+
+    return result;
+}
+
+/**
+ * Converts JSValueRef to std::string
+ * */
+std::string toString(JSContextRef ctx, JSValueRef value) {
+  Assert(ctx && value);
+  std::string result;
+  JSStringRef str = JSValueToStringCopy(ctx, value, NULL);
+  result = toString(str);
+  JSStringRelease(str);
+  return result;
+}
+
+JSValueRef getProperty(JSContextRef ctx, JSValueRef value, const char* name) {
+  Assert(ctx && value && name);
+  JSValueRef result = NULL;
+  JSObjectRef obj = JSValueToObject(ctx, value, NULL);
+  if (obj) {
+    JSStringRef str = JSStringCreateWithUTF8CString(name);
+    result = JSObjectGetProperty(ctx, obj, str, NULL);
+    JSStringRelease(str);
+  }
+  return result;
+}
+
+JSValueRef getPropertyObj(JSContextRef ctx, JSObjectRef obj, const char* name) {
+  Assert(ctx && obj && name);
+  JSStringRef str = JSStringCreateWithUTF8CString(name);
+  JSValueRef result = JSObjectGetProperty(ctx, obj, str, NULL);
+  JSStringRelease(str);
+  return result;
+}
+
+JSObjectRef getJSGlobalObject(JSGlobalContextRef context){
+    return JSContextGetGlobalObject(context);
+}
+
+}
+
+typedef JSValueRef (*JSCFunction)(
+    JSContextRef context,
+    JSObjectRef object,
+    JSObjectRef thisObject,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception);
+
+
+void JavaScriptInterface::setObjectProperty(JSGlobalContextRef context,
+                                        const JSObjectPtr& parentObject,
+                                        const std::string &propertyName,
+                                        const JSObjectPtr& propertyObject)
+{
+    LogInfo("Webkit:setting property --" << propertyName << "--");
+
+    //create name
+    JSStringRef name = JSStringCreateWithUTF8CString(propertyName.c_str());
+    //set property
+    JSObjectSetProperty(
+        static_cast<JSGlobalContextRef>(context),
+        static_cast<JSObjectRef>(parentObject->getObject()), name,
+        static_cast<JSObjectRef>(propertyObject->getObject()),
+        kJSPropertyAttributeReadOnly, 0);
+
+    JSStringRelease(name);
+}
+
+void JavaScriptInterface::removeObjectProperty(JSGlobalContextRef context,
+        const JSObjectPtr& parentObject,
+        const std::string &propertyName)
+{
+    if (!context) {
+        //nothing to do -> no context
+        return;
+    }
+    LogDebug("Deleting property --" << propertyName << "--");
+
+    JSStringRef name = JSStringCreateWithUTF8CString(propertyName.c_str());
+    JSObjectDeleteProperty(
+        static_cast<JSGlobalContextRef>(context),
+        static_cast<JSObjectRef>(parentObject->getObject()), name, 0);
+
+    JSStringRelease(name);
+}
+
+JavaScriptInterface::PropertiesList JavaScriptInterface::getObjectPropertiesList(
+        JSGlobalContextRef context,
+        const JSObjectPtr& object) const
+{
+    PropertiesList result;
+    JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(
+            static_cast<JSGlobalContextRef>(context),
+            static_cast<JSObjectRef>(object->getObject()));
+    std::size_t count = JSPropertyNameArrayGetCount(properties);
+    result.reserve(count);
+    LogDebug("propesties count " << count);
+    for (std::size_t i = 0; i < count; ++i) {
+        JSStringRef property = JSPropertyNameArrayGetNameAtIndex(properties, i);
+        result.push_back(toString(property));
+    }
+    JSPropertyNameArrayRelease(properties);
+    return result;
+}
+
+JSObjectPtr JavaScriptInterface::makeJSFunctionObject(
+        JSGlobalContextRef context,
+        const std::string &name,
+        js_function_impl functionImplementation) const
+{
+    LogDebug("Create JS function");
+    JSStringRef jsFunName = JSStringCreateWithUTF8CString(name.c_str());
+
+    JSObjectRef object = JSObjectMakeFunctionWithCallback(
+        context,
+        jsFunName,
+        reinterpret_cast<JSObjectCallAsFunctionCallback>(
+                functionImplementation));
+
+    JSStringRelease(jsFunName);
+    return JSObjectPtr(new JSObject(static_cast<void*>(object)));
+}
+
+JSObjectPtr JavaScriptInterface::makeJSClassObject(
+        JSGlobalContextRef context,
+        JSObjectDeclaration::ConstClassTemplate classTemplate) const
+{
+    LogDebug("Create JS object");
+    JSObjectRef object = JSObjectMake(
+            context,
+            static_cast<JSClassRef>(
+                const_cast<JSObjectDeclaration::ClassTemplate>(classTemplate)),
+            NULL);
+    return JSObjectPtr(new JSObject(object));
+}
+
+JSObjectPtr JavaScriptInterface::makeJSObjectBasedOnInterface(
+        JSGlobalContextRef context,
+        const std::string &interfaceName) const
+{
+    LogDebug("Create JS object base on interface: " << interfaceName);
+    LogDebug("Context: " << context);
+
+
+    JSObjectPtr jsInterfaceObj = getJSObjectProperty(context,
+            getGlobalObject(context), interfaceName);
+    JSObjectRef object = JSObjectCallAsConstructor(context,
+            static_cast<JSObjectRef>(jsInterfaceObj->getObject()), 0, NULL,
+            NULL);
+    return JSObjectPtr(new JSObject(static_cast<void*>(object)));
+}
+
+JSObjectPtr JavaScriptInterface::makeJSInterface(
+        JSGlobalContextRef context,
+        JSObjectDeclaration::ConstClassTemplate classTemplate,
+        JSObjectDeclaration::ConstructorCallback constructorCallback) const
+{
+    LogDebug("Create JS interface. Context: " << context);
+    JSObjectRef object = JSObjectMakeConstructor(context,
+            static_cast<JSClassRef>(
+                    const_cast<JSObjectDeclaration::ClassTemplate>(
+                            classTemplate)),
+            reinterpret_cast<JSObjectCallAsConstructorCallback>(
+                    constructorCallback)
+            );
+    return JSObjectPtr(new JSObject(static_cast<void*>(object)));
+}
+
+JSObjectPtr JavaScriptInterface::createObject(JSGlobalContextRef context,
+        const JSObjectDeclarationPtr& declaration)
+{
+    typedef JSObjectDeclaration::Options JO;
+
+    if( declaration->getOptions())
+    {
+        switch (declaration->getOptions()->getType())
+        {
+        case JO::ClassType::Function:
+            return makeJSFunctionObject(
+                    context,
+                    declaration->getName(),
+                    declaration->getOptions()->getFunctionImpl());
+
+        case JO::ClassType::Class:
+            if (declaration->getInterfaceName().empty()) {
+                return makeJSClassObject(
+                        context,
+                        declaration->getClassTemplate());
+            } else {
+                return makeJSObjectBasedOnInterface(
+                        context,
+                        declaration->getInterfaceName());
+            }
+
+        case JO::ClassType::Interface:
+            return makeJSInterface(
+                    context,
+                    /* product class template */
+                    declaration->getClassTemplate(),
+                    declaration->getConstructorCallback());
+
+        default:
+            LogError("Invalid class type. Making empty JS object.");
+            return JSObjectPtr(new JSObject(
+                    JSObjectMake(context, NULL, NULL)));
+        }
+    } else {
+        LogDebug("No declaration options");
+        return JSObjectPtr(new JSObject(
+                JSObjectMake(
+                    context,
+                    static_cast<JSClassRef>(
+                            const_cast<JSObjectDeclaration::ClassTemplate>(
+                                    declaration->getClassTemplate())),
+                    NULL)));
+    }
+}
+
+JSObjectPtr JavaScriptInterface::getGlobalObject(JSGlobalContextRef context)
+    const
+{
+    return JSObjectPtr(new JSObject(static_cast<JSObject::RealObject>(
+        JSContextGetGlobalObject(static_cast<JSGlobalContextRef>(context)))));
+}
+
+JSObjectPtr JavaScriptInterface::copyObjectToIframe(
+    JSGlobalContextRef context,
+    const JSObjectPtr& iframe,
+    const std::string& name)
+{
+    LogError("Copy object to iframe: " << name);
+
+    JSGlobalContextRef jsGlobalContext =
+        static_cast<JSGlobalContextRef>(context);
+
+    JSObjectRef globalObject = JSContextGetGlobalObject(jsGlobalContext);
+
+    JSValueRef requestedObject = getPropertyObj(jsGlobalContext,
+                                                globalObject,
+                                                name.c_str());
+    CHECK_JSVALUE_IS_UNDEFINED_RETURN(jsGlobalContext,
+                                      requestedObject,
+                                      JSObjectPtr());
+
+    JSStringRef requestedObjectStr =
+        JSStringCreateWithUTF8CString(name.c_str());
+
+    JSObjectSetProperty(jsGlobalContext,
+                        static_cast<JSObjectRef>(iframe->getObject()),
+                        requestedObjectStr,
+                        requestedObject,
+                        kJSPropertyAttributeReadOnly,
+                        NULL);
+
+    JSStringRelease(requestedObjectStr);
+
+    return JSObjectPtr(
+        new JSObject(const_cast<OpaqueJSValue*>(requestedObject)));
+}
+
+JavaScriptInterface::ObjectsListPtr
+JavaScriptInterface::getIframesList(JSGlobalContextRef ctx) const
+{
+    JSGlobalContextRef context = static_cast<JSGlobalContextRef>(ctx);
+
+    LogDebug("get global object");
+    JSObjectRef globalObject = JSContextGetGlobalObject(context);
+
+    ObjectsListPtr retList = getIframesList(context, globalObject);
+
+    return retList;
+}
+
+JavaScriptInterface::ObjectsListPtr
+JavaScriptInterface::getIframesList(JSContextRef context,
+                                    JSObjectRef globalObject) const
+{
+    JSValueRef frames = getPropertyObj(context, globalObject, "frames");
+    CHECK_JSVALUE_IS_UNDEFINED_RETURN(context, frames, ObjectsListPtr());
+
+    JSObjectRef frames_o = JSValueToObject(context, frames, NULL);
+    CHECK_JSOBJECT_IS_NULL_RETURN(frames_o, ObjectsListPtr());
+
+    JSValueRef len = getPropertyObj(context, frames_o, "length");
+    CHECK_JSVALUE_IS_UNDEFINED_RETURN(context, len, ObjectsListPtr());
+
+    size_t count = JSValueToNumber(context, len, NULL);
+    LogDebug("frames_o.length = " << count);
+
+    ObjectsListPtr retList = ObjectsListPtr(new ObjectsList());
+
+    for (size_t i = 0; i < count; ++i) {
+        std::stringstream ss;
+        ss << i;
+        JSValueRef frame = getPropertyObj(context,
+                                          frames_o,
+                                          ss.str().c_str());
+        if (JSValueIsUndefined(context, frame)) {
+            LogError("Selected frame is null: frame[" << i << "]");
+            continue;
+        }
+        JSObjectRef frame_obj = JSValueToObject(context, frame, NULL);
+        if (!frame_obj) {
+            LogError("frame_obj is NULL.");
+            continue;
+        }
+        retList->push_back(JSObjectPtr(new JSObject(frame_obj)));
+        ObjectsListPtr childList = getIframesList(context, frame_obj);
+
+        retList->merge(*childList);
+        LogDebug("Frame Value Pointer: " << frame);
+        LogDebug("Frame Object Pointer: " << frame_obj);
+    }
+
+    return retList;
+}
+
+JSObjectPtr JavaScriptInterface::getJSObjectProperty(JSGlobalContextRef ctx,
+                                         const JSObjectPtr& frame,
+                                         const std::string& name) const
+{
+    JSObjectRef frame_js = static_cast<JSObjectRef>(frame->getObject());
+
+    JSValueRef property = getPropertyObj(ctx, frame_js, name.c_str());
+
+    JSObjectRef objProp = JSValueToObject(ctx, property, NULL);
+
+    return JSObjectPtr(new JSObject(objProp));
+}
+
+void JavaScriptInterface::removeIframes(JSGlobalContextRef context)
+{
+    const char* deleteIframesScript =
+        "frame_set = document.getElementsByTagName('iframe');"
+        "len = frame_set.length;"
+        "for(i=0; i< len; i++)"
+        "   frame_set[0].parentNode.removeChild(frame_set[0]); ";
+
+    JSGlobalContextRef ctx = static_cast<JSGlobalContextRef>(context);
+
+    JSStringRef script_src = JSStringCreateWithUTF8CString(deleteIframesScript);
+
+    JSEvaluateScript(ctx, script_src, 0, 0, 0, 0);
+
+    JSStringRelease(script_src);
+}
+
+void JavaScriptInterface::invokeGarbageCollector(JSGlobalContextRef context)
+{
+    LogDebug("Garbage collection #1");
+    JSGarbageCollect(context);
+    LogDebug("Garbage collection #2");
+    JSGarbageCollect(context);
+    LogDebug("Garbage collection #3");
+    JSGarbageCollect(context);
+    LogDebug("Garbage collection #4");
+    JSGarbageCollect(context);
+}
diff --git a/src/plugin-loading/javascript_interface.h b/src/plugin-loading/javascript_interface.h
new file mode 100644 (file)
index 0000000..7b77cc6
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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       JavaScriptInterface.h
+ * @author     Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @author     Piotr Fatyga (p.fatyga@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+#ifndef WRT_SRC_PLUGIN_SERVICE_WEBKIT_INTERFACE_H_
+#define WRT_SRC_PLUGIN_SERVICE_WEBKIT_INTERFACE_H_
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <list>
+#include <dpl/noncopyable.h>
+#include <dpl/singleton.h>
+#include <Commons/JSObjectDeclaration.h>
+#include <Commons/JSObject.h>
+
+//forward declaration of JSConectexRef
+extern "C" {
+    typedef const struct OpaqueJSContext* JSContextRef;
+    typedef struct OpaqueJSContext* JSGlobalContextRef;
+    typedef struct OpaqueJSValue* JSObjectRef;
+}
+
+class JavaScriptInterface : DPL::Noncopyable
+{
+  public:
+
+    typedef std::vector<std::string> PropertiesList;
+
+    typedef std::list<JSObjectPtr> ObjectsList;
+    typedef std::shared_ptr<ObjectsList> ObjectsListPtr;
+
+  public:
+    JSObjectPtr getGlobalObject(JSGlobalContextRef context) const;
+
+    // object creation
+    JSObjectPtr createObject(JSGlobalContextRef context,
+                             const JSObjectDeclarationPtr& declaration);
+
+    //properties
+    void setObjectProperty(JSGlobalContextRef context,
+                           const JSObjectPtr& parentObject,
+                           const std::string &propertyName,
+                           const JSObjectPtr& propertyObject);
+
+    void removeObjectProperty(JSGlobalContextRef context,
+                              const JSObjectPtr& parentObject,
+                              const std::string &propertyName);
+
+    PropertiesList getObjectPropertiesList(JSGlobalContextRef context,
+                                           const JSObjectPtr& object) const;
+
+    JSObjectPtr copyObjectToIframe(JSGlobalContextRef context,
+                                   const JSObjectPtr& iframe,
+                                   const std::string& name);
+
+    ObjectsListPtr getIframesList(JSGlobalContextRef context) const;
+
+    void removeIframes(JSGlobalContextRef context);
+
+    void invokeGarbageCollector(JSGlobalContextRef context);
+
+    JSObjectPtr getJSObjectProperty(JSGlobalContextRef ctx,
+                            const JSObjectPtr& frame,
+                            const std::string& name) const;
+
+  private:
+    JavaScriptInterface()
+    {
+    }
+
+    JSObjectPtr makeJSFunctionObject(
+            JSGlobalContextRef context,
+            const std::string &name,
+            js_function_impl functionImplementation) const;
+    JSObjectPtr makeJSClassObject(
+            JSGlobalContextRef context,
+            JSObjectDeclaration::ConstClassTemplate classTemplate) const;
+    JSObjectPtr makeJSObjectBasedOnInterface(
+            JSGlobalContextRef context,
+            const std::string &interfaceName) const;
+    JSObjectPtr makeJSInterface(
+            JSGlobalContextRef context,
+            JSObjectDeclaration::ConstClassTemplate classTemplate,
+            JSObjectDeclaration::ConstructorCallback constructorCallback) const;
+
+    ObjectsListPtr getIframesList(JSContextRef context,
+            JSObjectRef object) const;
+
+    friend class DPL::Singleton<JavaScriptInterface>;
+};
+
+typedef DPL::Singleton<JavaScriptInterface> JavaScriptInterfaceSingleton;
+
+#endif
diff --git a/src/plugin-loading/js_page_session.cpp b/src/plugin-loading/js_page_session.cpp
new file mode 100644 (file)
index 0000000..1534d24
--- /dev/null
@@ -0,0 +1,758 @@
+/*
+ * 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        plugin_logic.cpp
+ * @author      Piotr Fatyga (p.fatyga@samsung.com)
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation file of plugin and
+ *              feature loading routines
+ * @brief       This code is intended to work behind view controller
+ */
+
+#include "plugin_logic.h"
+
+#include <dpl/assert.h>
+#include <dpl/scoped_array.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/singleton_impl.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+#include <JavaScriptCore/JavaScript.h>
+
+#include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fstream>
+#include <map>
+#include <list>
+#include <vector>
+#include <algorithm>
+#include <cstring>
+
+#include <wrt_plugin_export.h>
+#include <js_overlay_types.h>
+
+#include "explorer.h"
+#include "plugin.h"
+#include "plugin_model.h"
+#include "javascript_interface.h"
+#include "js_function_manager.h"
+#include "plugin_container_support.h"
+
+#include "js_page_session.h"
+
+using namespace std;
+using namespace WrtDB;
+using namespace WrtPlugins::W3C;
+
+namespace {
+const char *LIBRARY_PATH_SEPARATOR = "/";
+const char *TIZEN_ROOT_FEATURES = "http://tizen.org/privilege/tizen";
+}
+
+class JSPageSession::Impl
+{
+  private:
+    typedef std::set<PluginPtr> LoadedPlugins;
+    typedef std::set<JSGlobalContextRef> LoadedContexts;
+
+  private:
+    ///< Widget handle using this session
+    int m_widgetHandle;
+
+    //view for this session
+    JSGlobalContextRef m_context;
+
+    bool m_sessionStarted;
+
+    ///< JS object explorer for this session
+    Explorer* m_objectExplorer;
+
+    PluginContainerSupportPtr m_pluginsSupport;
+
+    ///< All loaded plugins. Each one must be unloaded. Plugins means
+    //set of features connected with such plugin (library)
+    LoadedPlugins m_loadedPlugins;
+
+    // Set of currently loaded web pages' contexts. These contexts are
+    // exactly matching with each frames' global context.
+    LoadedContexts m_loadedContexts;
+
+  private:
+    PluginPtr loadLibrary(PluginModelPtr& pluginModel);
+
+    void loadInjectedJavaScript();
+    void installStandardFeatures();
+    void installRootFeatures();
+    void installRequestedFeatures();
+
+    //returns true if success or false if failed
+    bool installPlugin(PluginModelPtr plugin);
+    bool installPluginOnDemand(PluginModelPtr plugin,
+                               JavaScriptObject& parentObject,
+                               JSGlobalContextRef context);
+
+    void unloadPluginsFromSession();
+
+  public:
+    Impl(const PluginContainerSupportPtr& containerSupport);
+    ~Impl();
+
+    // Widget session
+    void startSession(int widgetHandle,
+                      JSGlobalContextRef view,
+                      double scaleFactor,
+                      const char* encodedBundle,
+                      const char* theme);
+
+    void stopSession();
+
+    void performLibrariesUnload();
+
+    bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+                            JavaScriptObject& parentObject,
+                            JSGlobalContextRef context);
+
+    void loadFrame(JSGlobalContextRef context);
+    void unloadFrame(JSGlobalContextRef context);
+
+    void setCustomProperties(double scaleFactor,
+                             const char* encodedBundle,
+                             const char* theme);
+
+    void dispatchJavaScriptEvent(CustomEventType eventType, void* data);
+
+};
+
+
+JSPageSession::Impl::Impl(const PluginContainerSupportPtr& support) :
+    m_sessionStarted(false)
+{
+//    DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
+    LogDebug("Initializing Page Session");
+    m_pluginsSupport = support;
+
+    // explicit call to keep singleton's lifetime until calling destructor.
+//    JsFunctionManagerSingleton::Instance();
+//    JavaScriptInterfaceSingleton::Instance();
+}
+
+JSPageSession::Impl::~Impl()
+{
+    if(m_sessionStarted)
+    {
+        LogError("Must stop widget session before exit!");
+        stopSession();
+    }
+
+    LogDebug("Deinitializing plugin Logic...");
+}
+
+void JSPageSession::Impl::installStandardFeatures()
+{
+    LogInfo("Installing standard widget features...");
+
+    //add standard functions
+    FOREACH(it, JsFunctionManagerSingleton::Instance().getFunctions())
+    {
+        m_objectExplorer->registerObject(*it, NULL);
+    }
+
+    //add standard objects
+    LogDebug("Installing standard extensions...");
+
+    auto standardPlugins = m_pluginsSupport->getStandardPlugins();
+    FOREACH(it, standardPlugins)
+    {
+        //loadFeatureToSession(*it);
+        installPlugin(*it);
+    }
+
+    LogInfo("Standard widget features installed.");
+}
+
+void JSPageSession::Impl::installRootFeatures()
+{
+    LogInfo("Installing requested widget features...");
+    WrtDB::FeatureDAOReadOnly dao(TIZEN_ROOT_FEATURES);
+    auto plugin = m_pluginsSupport->getPluginModelById(dao.GetPluginHandle());
+    installPlugin(plugin);
+    LogInfo("requested root feature installed.");
+}
+
+bool JSPageSession::Impl::installPlugin(PluginModelPtr plugin)
+{
+    Assert(plugin && "Plugin Model is NULL");
+    auto library = loadLibrary(plugin);
+
+    LogInfo("Install Plugin '" << library->GetFileName());
+
+
+    if(!library)
+    {
+        LogError("Loading library failed");
+        return false;
+    }
+
+    // Register new class
+    FOREACH(it, *(library->GetClassList()))
+    {
+        if (!m_objectExplorer->registerObject(*it, NULL)) {
+            LogError("Object Registration failed : " << (*it)->getName());
+        }
+    }
+
+    LogDebug("Registered feature.");
+    return true;
+}
+
+void JSPageSession::Impl::installRequestedFeatures()
+{
+    LogInfo("Installing requested widget features...");
+
+    std::list<std::string> allowedFeatures =
+            m_pluginsSupport->getAllowedFeatures(m_widgetHandle);
+
+    PluginContainerSupport::PluginsList allowedPlugins;
+
+    FOREACH(feature, allowedFeatures)
+    {
+        LogDebug("Processing feature: " << *feature);
+
+        auto plugin = m_pluginsSupport->getPluginForFeature(*feature);
+        ImplementedObjectsList implObjs =
+            PluginDAOReadOnly::
+            getImplementedObjectsForPluginHandle(plugin->Handle.Get());
+
+        FOREACH(obj, implObjs)
+        {
+            LogDebug("Processing object: " << *obj);
+            /* This can be optimalized, but would need extra data in database.
+               There should be a list of features that are allowed to be
+               installed at widget start */
+            if (obj->find(".") == obj->rfind(".")) {
+                allowedPlugins.push_back(plugin);
+                LogWarning("Plugin will be added: "
+                           << plugin->LibraryName.Get());
+                break;
+            }
+        }
+    }
+
+    FOREACH(plugin, allowedPlugins)
+    {
+        LogDebug("Installation plugin: " << (*plugin)->LibraryName.Get());
+        installPlugin(*plugin);
+    }
+
+    LogInfo("requested features installed.");
+}
+
+bool JSPageSession::Impl::loadPluginOnDemand(
+    const WrtDB::DbPluginHandle &pluginHandle,
+    JavaScriptObject& parentObject,
+    JSGlobalContextRef context)
+{
+    LogDebug("load plugin with feature");
+
+    Assert(parentObject.instance &&
+           !parentObject.name.empty()
+           && "Wrong arguments");
+
+    if (!m_sessionStarted) {
+        LogError("Session not started");
+        return false;
+    }
+//    //TODO here may be a bug. if plugin contains feature rejected and accepted
+//    LogInfo("Installing feature : " << widgetFeature.name);
+//    if (widgetFeature.rejected) {
+//        LogWarning("This api-feature was rejected");
+//        return;
+//    }
+//
+//    auto plugin = m_pluginsSupport->getPluginModelById(pluginHandle);
+//    if (!plugin) {
+//        LogError("Failed to load plugin. plugin handle: " << pluginHandle);
+//        return false;
+//    }
+    m_pluginsSupport->registerPluginModel(pluginHandle);
+    return installPluginOnDemand(
+        m_pluginsSupport->getPluginModelById(pluginHandle),
+        parentObject,
+        context);
+}
+
+bool JSPageSession::Impl::installPluginOnDemand(PluginModelPtr plugin,
+                                              JavaScriptObject& parentObject,
+                                              JSGlobalContextRef context)
+{
+    Assert(plugin && "Plugin Model is NULL");
+    auto library = loadLibrary(plugin);
+
+    LogInfo("Install Plugin '" << library->GetFileName());
+
+    if(!library)
+    {
+        LogError("Loading library failed");
+        return false;
+    }
+
+    if(!(parentObject.instance))
+    {
+        LogError("NULL pointer value");
+        return false;
+    }
+
+    JSObjectPtr parent(new JSObject(parentObject.instance));
+
+    if (!parent->getObject())
+    {
+        LogError("NULL pointer value");
+        assert(false);
+        return false;
+    }
+
+    FOREACH(it, *(library->GetClassList()))
+    {
+        bool installationStatus =
+            m_objectExplorer->registerObject(*it,
+                                             parentObject.name,
+                                             parent,
+                                             context);
+
+        if(!installationStatus)
+        {
+            LogError("Object Registration failed : " << (*it)->getName()
+                     << "; Parent object name: " << parentObject.name);
+            return false;
+        }
+    }
+
+    LogDebug("Plugin on demand registration completed");
+    return true;
+}
+
+void JSPageSession::Impl::setCustomProperties(double scaleFactor,
+                                            const char* encodedBundle,
+                                            const char* theme)
+{
+    LogInfo("set properties of window object " << scaleFactor << ", "
+            << encodedBundle << ", " << theme);
+
+    m_objectExplorer->getWindowPropertySupport()
+        ->setScaleToNavigatorProperty(scaleFactor);
+    m_objectExplorer->getWindowPropertySupport()
+        ->setBundleToWindowProperty(encodedBundle);
+    m_objectExplorer->getWindowPropertySupport()
+        ->setThemeToNavigatorProperty(theme);
+}
+
+void JSPageSession::Impl::dispatchJavaScriptEvent(CustomEventType eventType, void* data)
+{
+    // Check if session is already started
+    if (!m_sessionStarted) {
+        LogWarning("Session not started!");
+        return;
+    }
+
+    LogInfo("Request dispatching javascript event");
+    m_objectExplorer->callEventListeners(eventType, data);
+}
+
+void JSPageSession::Impl::loadInjectedJavaScript()
+{
+    LogInfo("Entered");
+
+    std::string DIR_PATH     = "/usr/etc/wrt/injected-javascript";
+    std::string JS_EXTENSION = ".js";
+
+    DIR *dir = opendir(DIR_PATH.c_str());
+
+    if (!dir) {
+        LogError("opendir(\"" << DIR_PATH << "\") error!" );
+        return;
+    }
+
+    struct dirent* libdir;
+    std::list<std::string> jsFiles;
+
+    // make file list from DIR_PATH
+    while ((libdir = readdir(dir)) != 0)
+    {
+        if (strncmp(libdir->d_name, ".", 2) == 0 ||
+            strncmp(libdir->d_name, "..", 3) == 0)
+        {
+            continue;
+        }
+
+        std::string filepath = DIR_PATH;
+        filepath += "/";
+        filepath += libdir->d_name;
+
+        std::string lowercase = filepath;
+        std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(),
+                       towlower);
+
+        if( lowercase.rfind(JS_EXTENSION) == std::string::npos ||
+            lowercase.length() !=
+            lowercase.rfind(JS_EXTENSION) + JS_EXTENSION.length() )
+        {
+            LogError("This is not js file" << filepath);
+            continue;
+        }
+
+        struct stat tmp;
+
+        if (stat(filepath.c_str(), &tmp) == -1) {
+            LogError("Failed to open file " << filepath);
+            continue;
+        }
+
+        if (!S_ISREG(tmp.st_mode)) {
+            LogError("This is not a regular file " << filepath);
+            continue;
+        }
+
+        LogInfo("Added : " << filepath);
+        jsFiles.push_back(filepath);
+    }
+
+    closedir(dir);
+
+
+    FOREACH(it, jsFiles)
+    {
+        LogDebug("load file : " << (*it));
+        // load file
+        std::string content;
+        std::ifstream fin(it->c_str());
+
+        while(fin.good())
+        {
+            string line;
+            std::getline(fin, line);
+            content += line + "\n";
+        }
+
+        fin.close();
+        // execute
+        if(!content.empty())
+        {
+            JSValueRef exception = NULL;
+            JSStringRef script =
+                JSStringCreateWithUTF8CString(content.c_str());
+
+            JSEvaluateScript(m_context, script, NULL, NULL, 1, &exception);
+
+            JSStringRelease(script);
+
+            if(exception)
+            {
+                LogDebug("Exception Occured while injecting javascript "
+                    "file. : " << *it);
+
+                JSStringRef exceptionJSString =
+                    JSValueToStringCopy(m_context, exception, NULL);
+                size_t size =
+                    JSStringGetMaximumUTF8CStringSize(exceptionJSString);
+                char* exceptionString = new char[size];
+                JSStringGetUTF8CString(exceptionJSString,
+                                       exceptionString, size);
+                LogDebug("Exception : " << exceptionString);
+
+                delete [] exceptionString;
+                JSStringRelease(exceptionJSString);
+             }
+        }
+    }
+}
+
+void JSPageSession::Impl::startSession(int widgetHandle,
+                                     JSGlobalContextRef context,
+                                     double scaleFactor,
+                                     const char* encodedBundle,
+                                     const char* theme)
+{
+    LogInfo("Starting widget session...");
+
+    // Check if corresponding session if not already created
+    if (m_sessionStarted) {
+        LogWarning("Session already started!");
+        return;
+    }
+
+    // Create js object explorer object
+    m_objectExplorer = new Explorer(context);
+
+    m_sessionStarted = true;
+    m_widgetHandle = widgetHandle;
+    m_loadedPlugins.clear();
+    m_context = context;
+
+    // Register standard features
+    installStandardFeatures();
+
+    WidgetDAOReadOnly dao(m_widgetHandle);
+    WidgetType appType = dao.getWidgetType();
+    if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
+        installRootFeatures();
+    }
+    // Register special features
+    installRequestedFeatures();
+
+    // set scale, bundle as window's property
+    setCustomProperties(scaleFactor, encodedBundle, theme);
+
+    // Load injected javascript files
+    loadInjectedJavaScript();
+    LogInfo("Widget session started.");
+}
+
+void JSPageSession::Impl::stopSession()
+{
+    LogInfo("Stopping widget session...");
+
+    if (!m_sessionStarted) {
+        LogWarning("Session not started!");
+        return;
+    }
+
+    unloadPluginsFromSession();
+    m_sessionStarted = false;
+
+    LogInfo("Widget session stopped.");
+}
+
+
+void JSPageSession::Impl::unloadPluginsFromSession()
+{
+    LogDebug("Unload plugins from session");
+
+    m_objectExplorer->removePluginsFromIframes();
+    m_objectExplorer->cleanIframesData();
+
+    // delete js object for overlayed js functions
+    FOREACH(it, JsFunctionManagerSingleton::Instance().getFunctions())
+    {
+        m_objectExplorer->deregisterObject(*it);
+    }
+
+    // delete js object for plugins
+    FOREACH(pluginIt, m_loadedPlugins)
+    {
+        LogDebug("Unregistering plugin " << (*pluginIt)->GetFileName());
+
+        (*pluginIt)->OnWidgetStop(m_widgetHandle);
+        LogDebug("Emitted WidgetStop for plugin: " <<
+                 (*pluginIt)->GetFileName());
+
+        FOREACH(it, *((*pluginIt)->GetClassList()))
+        {
+            m_objectExplorer->deregisterObject(*it);
+        }
+    }
+
+    JavaScriptInterfaceSingleton::Instance().invokeGarbageCollector(m_context);
+
+    m_loadedPlugins.clear();
+
+    delete m_objectExplorer;
+    m_objectExplorer = NULL;
+}
+
+
+
+
+void JSPageSession::Impl::performLibrariesUnload()
+{
+#if 0
+    LogDebug("Perform library unload");
+
+    size_t unloadedLibraries = 0;
+
+    FOREACH(pluginIt, m_loadedPlugins)
+    {
+        LogDebug("Preparing library: " << (*pluginIt)->LibraryName.Get());
+
+        PluginPtr plugin = (*pluginIt)->LibraryInstance.Get();
+        if (!plugin) {
+            LogWarning("Library not loaded " << (*pluginIt)->LibraryName.Get());
+            continue;
+        }
+        unloadedLibraries++;
+        (*pluginIt)->LibraryInstance.Set(PluginPtr());
+    }
+
+    LogInfo("unloaded " << unloadedLibraries << " unreferenced libraries!");
+#endif
+}
+
+PluginPtr JSPageSession::Impl::loadLibrary(PluginModelPtr& pluginModel)
+{
+    PluginPtr pluginLib = pluginModel->LibraryInstance.Get();
+    if (!pluginLib)
+    {
+        std::string path = pluginModel->LibraryPath.Get() +
+                           std::string(LIBRARY_PATH_SEPARATOR) +
+                           pluginModel->LibraryName.Get();
+
+        pluginLib = Plugin::LoadFromFile(path);
+
+        if (!pluginLib)
+        {
+            LogError("Loading library failed");
+        } else
+        {
+            pluginModel->LibraryInstance.Set(pluginLib);
+
+            LogDebug("On widget start");
+            // This is first time for this plugin, start widget Session
+            pluginLib->OnWidgetStart(
+                m_widgetHandle);
+            m_loadedPlugins.insert(pluginLib);
+
+            FOREACH(context, m_loadedContexts)
+            {
+                pluginLib->OnFrameLoad(*context);
+            }
+        }
+    }
+    else
+    {
+        LogDebug("Get from LibraryInstance");
+        LogDebug("On widget start");
+        // This is first time for this plugin, start widget Session
+        pluginLib->OnWidgetStart(
+            m_widgetHandle);
+        m_loadedPlugins.insert(pluginLib);
+
+        FOREACH(context, m_loadedContexts)
+        {
+            pluginLib->OnFrameLoad(*context);
+        }
+    }
+
+    return pluginLib;
+}
+
+
+void JSPageSession::Impl::loadFrame(JSGlobalContextRef context)
+{
+    LogDebug("Load a frame");
+
+    if (!m_sessionStarted) {
+        LogWarning("Session NOT started!");
+        return;
+    }
+
+    m_loadedContexts.insert(context);
+
+    FOREACH(pluginIt, m_loadedPlugins)
+    {
+        LogDebug("load plugin to frame" << (*pluginIt)->GetFileName());
+
+        (*pluginIt)->OnFrameLoad(context);
+    }
+
+    m_objectExplorer->loadFrame(context);
+}
+
+void JSPageSession::Impl::unloadFrame(JSGlobalContextRef context)
+{
+    LogDebug("Unload a frame");
+
+    if (!m_sessionStarted) {
+        LogWarning("Session NOT started!");
+        return;
+    }
+
+    m_loadedContexts.erase(context);
+
+    FOREACH(pluginIt, m_loadedPlugins)
+    {
+        LogDebug("unload plugin to frame" << (*pluginIt)->GetFileName());
+
+        (*pluginIt)->OnFrameUnload(context);
+    }
+
+    m_objectExplorer->unloadFrame(context);
+}
+
+
+void JSPageSession::startSession(int widgetHandle,
+                               JSGlobalContextRef ctx,
+                               double scaleFactor,
+                               const char* encodedBundle,
+                               const char* theme)
+{
+    m_impl->startSession(widgetHandle, ctx, scaleFactor, encodedBundle, theme);
+}
+
+void JSPageSession::stopSession()
+{
+    m_impl->stopSession();
+}
+
+void JSPageSession::performLibrariesUnload()
+{
+    m_impl->performLibrariesUnload();
+}
+
+bool JSPageSession::loadPluginOnDemand(
+    const WrtDB::DbPluginHandle &pluginHandle,
+    JavaScriptObject& parentObject,
+    JSGlobalContextRef context)
+{
+    return m_impl->loadPluginOnDemand(pluginHandle, parentObject, context);
+}
+
+void JSPageSession::setCustomProperties(double scaleFactor,
+                                      const char* encodedBundle,
+                                      const char* theme)
+{
+    m_impl->setCustomProperties(scaleFactor, encodedBundle, theme);
+}
+
+void JSPageSession::dispatchJavaScriptEvent(CustomEventType eventType, void* data)
+{
+    m_impl->dispatchJavaScriptEvent(eventType, data);
+}
+
+void JSPageSession::loadFrame(JSGlobalContextRef context)
+{
+    m_impl->loadFrame(context);
+}
+
+void JSPageSession::unloadFrame(JSGlobalContextRef context)
+{
+    m_impl->unloadFrame(context);
+}
+
+JSPageSession::JSPageSession(const PluginContainerSupportPtr& containerSupport)
+    : m_impl(new JSPageSession::Impl(containerSupport))
+{
+}
+
+JSPageSession::~JSPageSession()
+{
+}
diff --git a/src/plugin-loading/js_page_session.h b/src/plugin-loading/js_page_session.h
new file mode 100644 (file)
index 0000000..3580287
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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        js_page_session.h
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     1.0
+ */
+#ifndef WRT_PLUGIN_JS_PAGE_SESSION_H_
+#define WRT_PLUGIN_JS_PAGE_SESSION_H_
+
+#include <memory>
+#include <vector>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <js_overlay_types.h>
+#include "js_types.h"
+
+using namespace WrtPlugins::W3C;
+
+class JSPageSession
+{
+  public:
+    // Widget session
+    void startSession(int widgetHandle,
+                      JSGlobalContextRef view,
+                      double scaleFactor,
+                      const char* encodedBundle,
+                      const char* theme);
+
+    void stopSession();
+
+    //TODO im not sure if it is needed. I think it should be hidden
+    void performLibrariesUnload();
+    bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+                            JavaScriptObject& parentObject,
+                            JSGlobalContextRef context);
+
+    void loadFrame(JSGlobalContextRef context);
+    void unloadFrame(JSGlobalContextRef context);
+
+    // reset custom window properties. (Tizen requirements)
+    void setCustomProperties(double scaleFactor,
+                             const char* encodedBundle,
+                             const char* theme);
+
+    void dispatchJavaScriptEvent(CustomEventType eventType, void* data);
+
+    JSPageSession(const PluginContainerSupportPtr& containerSupport);
+
+    virtual ~JSPageSession();
+
+  private:
+    class Impl;
+    std::unique_ptr<Impl> m_impl;
+};
+
+typedef std::shared_ptr<JSPageSession> JSPageSessionPtr;
+
+#endif // PLUGIN_LOGIC_H
diff --git a/src/plugin-loading/js_types.h b/src/plugin-loading/js_types.h
new file mode 100644 (file)
index 0000000..bb85699
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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        js_types.h
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     1.0
+ */
+
+#ifndef WRT_PLUGIN_JS_TYPES_H_
+#define WRT_PLUGIN_JS_TYPES_H_
+
+//forward declaration of JSConectexRef
+extern "C" {
+    typedef struct OpaqueJSContext* JSGlobalContextRef;
+    typedef struct OpaqueJSValue* JSObjectRef;
+}
+
+struct JavaScriptObject
+{
+    JSObjectRef instance;
+    std::string name;
+};
+
+#endif
diff --git a/src/plugin-loading/plugin.cpp b/src/plugin-loading/plugin.cpp
new file mode 100644 (file)
index 0000000..9ab4518
--- /dev/null
@@ -0,0 +1,258 @@
+/*
+ * 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        plugin.cpp
+ * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation file of plugin
+ */
+#include "plugin.h"
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dlfcn.h>
+
+Plugin::Plugin(const std::string &fileName,
+        void *libHandle,
+        on_widget_start_proc *apiOnWidgetStart,
+        on_widget_init_proc *apiOnWidgetInit,
+        on_widget_stop_proc *apiOnWidgetStop,
+        on_frame_load_proc* apiOnFrameLoad,
+        on_frame_unload_proc* apiOnFrameUnload,
+        const ClassPtrList &apiClassList) :
+    m_fileName(fileName),
+    m_libHandle(libHandle),
+    m_apiOnWidgetStart(apiOnWidgetStart),
+    m_apiOnWidgetInit(apiOnWidgetInit),
+    m_apiOnWidgetStop(apiOnWidgetStop),
+    m_apiOnFrameLoad(apiOnFrameLoad),
+    m_apiOnFrameUnload(apiOnFrameUnload),
+    m_apiClassList(apiClassList)
+{
+}
+
+Plugin::~Plugin()
+{
+    LogInfo("Unloading plugin library: " << m_fileName << "...");
+
+    // Unload library
+    if (dlclose(m_libHandle) != 0) {
+        LogError("Cannot close plugin handle");
+    } else {
+        LogDebug("Library is unloaded");
+    }
+}
+
+PluginPtr Plugin::LoadFromFile(const std::string& fileName)
+{
+    LogDebug("LoadFromFile" << fileName);
+
+    LogDebug("Loading plugin: " << fileName);
+
+    void *dllHandle;
+    dllHandle = dlopen(fileName.c_str(), RTLD_NOW);
+
+    if (dllHandle == NULL) {
+        LogError(
+            "Failed to load plugin: " << fileName << ". Reason: " << dlerror());
+        PluginPtr empty;
+        return empty;
+    }
+
+    // Load new plugin API
+    on_widget_start_proc *onWidgetStartProcPtr = NULL;
+    on_widget_stop_proc *onWidgetStopProcPtr = NULL;
+    on_widget_init_proc *onWidgetInitProcPtr = NULL;
+    on_frame_load_proc *onFrameLoadProcPtr = NULL;
+    on_frame_unload_proc *onFrameUnloadProcPtr = NULL;
+
+    const js_entity_definition_t *rawClassList = NULL;
+    get_widget_entity_map_proc *getWidgetEntityMapProcPtr = NULL;
+
+    onWidgetStartProcPtr =
+        reinterpret_cast<on_widget_start_proc *>(
+            dlsym(dllHandle, PLUGIN_WIDGET_START_PROC_NAME));
+    onWidgetInitProcPtr =
+        reinterpret_cast<on_widget_init_proc *>(
+            dlsym(dllHandle, PLUGIN_WIDGET_INIT_PROC_NAME));
+    onWidgetStopProcPtr =
+        reinterpret_cast<on_widget_stop_proc *>(
+            dlsym(dllHandle, PLUGIN_WIDGET_STOP_PROC_NAME));
+    onFrameLoadProcPtr =
+        reinterpret_cast<on_frame_load_proc *>(
+            dlsym(dllHandle, PLUGIN_FRAME_LOAD_PROC_NAME));
+    onFrameUnloadProcPtr =
+        reinterpret_cast<on_frame_unload_proc *>(
+            dlsym(dllHandle, PLUGIN_FRAME_UNLOAD_PROC_NAME));
+    getWidgetEntityMapProcPtr =
+        reinterpret_cast<get_widget_entity_map_proc *>(
+            dlsym(dllHandle, PLUGIN_GET_CLASS_MAP_PROC_NAME));
+
+    if( getWidgetEntityMapProcPtr )
+    {
+        rawClassList = (*getWidgetEntityMapProcPtr)();
+        LogDebug("rawClassList : " << rawClassList  << "by getWidgetClassMapProcPtr()");
+    }
+    else
+    {
+        rawClassList =
+            static_cast<const js_entity_definition_t *>(dlsym(dllHandle,
+                                                        PLUGIN_CLASS_MAP_NAME));
+        LogDebug("rawClassList : " << rawClassList );
+    }
+
+
+    if (NULL == onWidgetStartProcPtr || NULL == onWidgetStopProcPtr ||
+        /*NULL == onWidgetInitProcPtr ||*/ NULL == rawClassList) {
+        LogWarning("#####");
+        LogWarning(
+            "##### Warning: The following plugin does not support new plugin API.");
+        LogWarning(
+            "##### Old plugin API is deprecated. Please update it to new API");
+        LogWarning("#####");
+        LogWarning(
+            "##### Plugin: " << fileName <<
+            " has got deprecated or invalid API");
+        LogWarning("#####");
+
+        // Will not load plugin
+        dlclose(dllHandle);
+
+        PluginPtr empty;
+        return empty;
+    }
+
+    LogInfo("#####");
+    LogInfo("##### Plugin: " << fileName << " supports new plugin API");
+    LogInfo("#####");
+    LogInfo("##### $onWidgetStartProc: " << onWidgetStartProcPtr);
+    LogInfo("##### $onWidgetInitProc: " << onWidgetInitProcPtr);
+    LogInfo("##### $onWidgetStopProc " << onWidgetStopProcPtr);
+    LogInfo("##### $onFrameLoadProc " << onFrameLoadProcPtr);
+    LogInfo("##### $onFrameUnloadProc " << onFrameUnloadProcPtr);
+    LogInfo("##### $classMap: " << reinterpret_cast<const void *>(rawClassList));
+    LogInfo("##### ");
+    LogInfo("##### Class map:");
+
+    const js_entity_definition_t *rawEntityListIterator = rawClassList;
+    ClassPtrList classList(new Plugin::ClassList());
+
+    // Parse all class definitions
+    while (rawEntityListIterator->parent_name != NULL &&
+            rawEntityListIterator->object_name != NULL)
+    {
+        // Logging
+        LogInfo("#####");
+        LogInfo("#####     [" << rawEntityListIterator->object_name << "]: ");
+        LogInfo("#####     Interface: " <<
+                rawEntityListIterator->interface_name);
+        LogInfo("#####     Parent: " << rawEntityListIterator->parent_name);
+
+        // Register class
+        classList->push_back(ClassPtr(new Class(rawEntityListIterator)));
+
+        // Go to next class
+        ++rawEntityListIterator;
+    }
+
+    LogInfo("#####");
+
+    // Load export table
+    LogDebug("Plugin successfuly loaded");
+
+    // Insert to loaded modules list
+
+    PluginPtr instance(new Plugin(fileName,
+                                  dllHandle,
+                                  onWidgetStartProcPtr,
+                                  onWidgetInitProcPtr,
+                                  onWidgetStopProcPtr,
+                                  onFrameLoadProcPtr,
+                                  onFrameUnloadProcPtr,
+                                  classList));
+
+    return instance;
+}
+
+std::string Plugin::GetFileName() const
+{
+    return m_fileName;
+}
+
+void Plugin::OnWidgetStart(int widgetId)
+{
+    if (NULL != m_apiOnWidgetStart)
+    {
+        (*m_apiOnWidgetStart)(widgetId);
+    }
+    else
+    {
+        LogWarning("OnWidgetStart not set!");
+    }
+}
+
+void Plugin::OnWidgetInit(feature_mapping_interface_t* mapping)
+{
+    Assert(NULL != mapping && "NULL mapping interface provided");
+    if (NULL != m_apiOnWidgetInit)
+    {
+        (*m_apiOnWidgetInit)(mapping);
+    }
+    else
+    {
+        LogWarning("OnWidgetInit not set!");
+    }
+}
+
+void Plugin::OnWidgetStop(int widgetId)
+{
+    if (NULL != m_apiOnWidgetStop)
+    {
+        (*m_apiOnWidgetStop)(widgetId);
+    }
+    else
+    {
+        LogWarning("OnWidgetStop not set!");
+    }
+}
+
+void Plugin::OnFrameLoad(java_script_context_t context)
+{
+    if (NULL != m_apiOnFrameLoad)
+    {
+        (*m_apiOnFrameLoad)(context);
+    }
+    else
+    {
+        LogWarning("OnFrameLoad not set!");
+    }
+}
+
+void Plugin::OnFrameUnload(java_script_context_t context)
+{
+    if (NULL != m_apiOnFrameUnload)
+    {
+        (*m_apiOnFrameUnload)(context);
+    }
+    else
+    {
+        LogWarning("OnFrameUnload not set!");
+    }
+}
+
+const Plugin::ClassPtrList Plugin::GetClassList() const
+{
+    return m_apiClassList;
+}
diff --git a/src/plugin-loading/plugin.h b/src/plugin-loading/plugin.h
new file mode 100644 (file)
index 0000000..d3eec30
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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        plugin.h
+ * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation file of plugin
+ */
+#ifndef WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
+#define WRT_SRC_PLUGIN_SERVICE_PLUGIN_H_
+
+#include <list>
+#include <map>
+#include <string>
+#include <dpl/atomic.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <wrt_plugin_export.h>
+#include <Commons/JSObjectDeclaration.h>
+
+class Plugin;
+typedef DPL::SharedPtr<Plugin> PluginPtr;
+
+class Plugin : private DPL::Noncopyable
+{
+  public:
+    typedef JSObjectDeclaration Class;
+    typedef JSObjectDeclarationPtr ClassPtr;
+    typedef std::list<ClassPtr> ClassList;
+    typedef DPL::SharedPtr<ClassList> ClassPtrList;
+
+  private:
+    ///< Plug-in identifier. Currently plug-in file name is used as the ID
+    std::string m_fileName;
+
+    ///< Handle for the plug-in library. A plug-in is a dynamic loadable library
+    void* m_libHandle;
+
+    // Plugin API
+    on_widget_start_proc* m_apiOnWidgetStart;
+    on_widget_init_proc* m_apiOnWidgetInit;
+    on_widget_stop_proc* m_apiOnWidgetStop;
+    on_frame_load_proc* m_apiOnFrameLoad;
+    on_frame_unload_proc* m_apiOnFrameUnload;
+    const ClassPtrList m_apiClassList;
+
+    Plugin(const std::string &fileName,
+            void *libHandle,
+            on_widget_start_proc* apiOnWidgetStart,
+            on_widget_init_proc* apiOnWidgetInit,
+            on_widget_stop_proc* apiOnWidgetStop,
+            on_frame_load_proc* apiOnFrameLoad,
+            on_frame_unload_proc* apiOnFrameUnload,
+            const ClassPtrList &apiClassList);
+
+  public:
+    virtual ~Plugin();
+
+    // Loading
+    static PluginPtr LoadFromFile(const std::string &fileName);
+
+    // Filename
+    std::string GetFileName() const;
+
+    // API
+    void OnWidgetStart(int widgetId);
+
+    void OnWidgetInit(feature_mapping_interface_t *interface);
+
+    void OnWidgetStop(int widgetId);
+
+    void OnFrameLoad(java_script_context_t context);
+
+    void OnFrameUnload(java_script_context_t context);
+
+    const ClassPtrList GetClassList() const;
+};
+
+#endif // PLUGIN_H
diff --git a/src/plugin-loading/plugin_container_support.cpp b/src/plugin-loading/plugin_container_support.cpp
new file mode 100644 (file)
index 0000000..4518b0f
--- /dev/null
@@ -0,0 +1,311 @@
+/*
+ * 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        plugin_container_support.h
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     1.0
+ */
+
+#include "plugin_container_support.h"
+
+#include <fstream>
+
+#include <dpl/foreach.h>
+#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+namespace {
+const char *STANDARD_FEATURES_LIST_FILE = "standard-features-list";
+const char *TIZEN_ROOT_FEATURES = "http://tizen.org/privilege/tizen";
+}
+
+using namespace WrtDB;
+
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+
+PluginContainerSupport::PluginContainerSupport(): m_initialized(false)
+{
+    // Reading standard features list from file
+    readStandardFeaturesList();
+}
+
+PluginContainerSupport::~PluginContainerSupport()
+{
+    // Remove all plugin models
+    m_pluginModels.clear();
+
+    // Remove all feature models
+    m_featureModels.clear();
+
+    // Clear standard features list
+    m_standardFeatureList.clear();
+}
+
+void PluginContainerSupport::Initialize(int widgetHandle)
+{
+    if (isInitialized() == false)
+    {
+        readAllowedPlugins(widgetHandle);
+        readRootPlugins(widgetHandle);
+    }
+}
+
+std::list<std::string> PluginContainerSupport::getAllowedFeatures(int widgetHandle) const
+{
+    //TODO it has to return LIST NOT SET!!!
+    WidgetDAOReadOnly widgetDao(widgetHandle);
+    DbWidgetFeatureSet features = widgetDao.getFeaturesList();
+
+    std::list<std::string> allowedFeatures;
+    FOREACH(it, features) {
+        LogInfo("Loading api-feature: " << it->name);
+        if (it->rejected) {
+            LogWarning("Api-feature was rejected by ace. (Api-feature name: "
+                       << it->name << ")" );
+            continue;
+        }
+
+        allowedFeatures.push_back(DPL::ToUTF8String(it->name));
+    }
+    return allowedFeatures;
+}
+
+void PluginContainerSupport::readAllowedPlugins(int widgetHandle)
+{
+    std::list<std::string> allowedFeatures(m_standardFeatureList);
+    auto requested = getAllowedFeatures(widgetHandle);
+    FOREACH(f, requested)
+    {
+        allowedFeatures.push_back(*f);
+    }
+
+    FeatureData* dt = NULL;
+    std::map<FeatureHandle, FeatureData> featureDataList = FeatureDAOReadOnly::GetFeatures(allowedFeatures);
+    DeviceCapList deviceCapabilities = FeatureDAOReadOnly::GetDevCapWithFeatureHandle();
+    FOREACH(data, featureDataList) {
+        dt = &(data->second);
+        registerPluginModel(dt->pluginHandle);
+        registerFeatureModel(data->first, dt, deviceCapabilities);
+    }
+
+    m_initialized = true;
+}
+
+void PluginContainerSupport::readRootPlugins(int widgetHandle)
+{
+    WidgetDAOReadOnly dao(widgetHandle);
+    WidgetType appType = dao.getWidgetType();
+    if (appType == WrtDB::APP_TYPE_TIZENWEBAPP) {
+        WrtDB::FeatureDAOReadOnly dao(TIZEN_ROOT_FEATURES);
+        registerPluginModel(dao.GetPluginHandle());
+    } else {
+        LogDebug("Not defined app type");
+    }
+    m_initialized = true;
+}
+
+void PluginContainerSupport::registerFeatureModel(FeatureHandle handle, FeatureData* data, DeviceCapList deviceCapabilities)
+{
+    LogDebug("Analyzing feature: " << handle);
+    FeatureModelPtr model = getFeatureModel(handle);
+    if (model) {
+        LogDebug("Model for feature:" << handle << " already created");
+        return;
+    }
+
+    LogDebug("Creating Model for feature:" << handle);
+
+    model.reset(new FeatureModel(handle));
+
+    std::set<std::string> devCapList;
+    auto ret = deviceCapabilities.equal_range(handle);
+    for (auto devCapIt = ret.first; devCapIt != ret.second; devCapIt++) {
+        devCapList.insert((*devCapIt).second);
+    }
+    model->SetData(data->featureName, devCapList, data->pluginHandle);
+    m_featureModels.insert(model);
+}
+
+void PluginContainerSupport::registerPluginModel(DbPluginHandle handle)
+{
+    PluginModelPtr model = getPluginModelById(handle);
+
+    if (model) {
+        LogDebug("Model for plugin:" << handle << " already registered");
+        return;
+    }
+
+    LogDebug("Creating Model for plugin: " << handle);
+
+    if (PluginDAOReadOnly::INSTALLATION_COMPLETED !=
+        PluginDAOReadOnly::getInstallationStateForHandle(handle))
+    {
+        LogWarning("Failed To CreateModel for handle " << handle);
+        return;
+    }
+
+    model.Reset(new PluginModel(handle));
+
+    LogInfo("Model Created. Handle: " <<
+            handle << ", name: " << model->LibraryName.Get());
+
+    m_pluginModels.insert(model);
+}
+
+void PluginContainerSupport::readStandardFeaturesList()
+{
+    LogDebug("Reading standard features list from file...");
+
+    std::string path = GlobalConfig::GetDevicePluginPath();
+    path += "/";
+    path += STANDARD_FEATURES_LIST_FILE;
+
+    std::ifstream standardFeatureFile;
+    standardFeatureFile.open(path.c_str(), std::ifstream::in);
+
+    if (!standardFeatureFile.is_open()) {
+        LogError("Reading standard features list from file FAILED.");
+        return;
+    }
+
+    char buffer[1024];
+
+    while (!standardFeatureFile.eof()) {
+        standardFeatureFile.getline(buffer, sizeof(buffer));
+
+        if (buffer[0] == '\0') {
+            break;
+        }
+
+        LogDebug("Standard Feature: <" << buffer << ">");
+        m_standardFeatureList.push_back(std::string(buffer));
+    }
+
+    standardFeatureFile.close();
+}
+
+FeatureModelPtr
+PluginContainerSupport::getFeatureModel(const std::string &name) const
+{
+    FOREACH(iter, m_featureModels)
+    {
+        if ((*iter)->Name.Get() == name) {
+            return *iter;
+        }
+    }
+
+    return FeatureModelPtr();
+}
+
+FeatureModelPtr
+PluginContainerSupport::getFeatureModel(const FeatureHandle handle) const
+{
+    FOREACH(iter, m_featureModels)
+    {
+        if ((*iter)->FHandle.Get() == handle) {
+            return *iter;
+        }
+    }
+
+    return FeatureModelPtr();
+}
+
+PluginModelPtr
+PluginContainerSupport::getPluginModelById(DbPluginHandle handle) const
+{
+    FOREACH(pluginModel, m_pluginModels)
+    {
+        if ((*pluginModel)->Handle.Get() == handle) {
+            return *pluginModel;
+        }
+    }
+
+    return PluginModelPtr();
+}
+
+PluginModelPtr
+PluginContainerSupport::getPluginModel(const FeatureModelPtr &feature) const
+{
+    LogDebug("");
+    Assert(feature && "Null Ptr for feature model");
+    LogDebug("Feature located in plugin: " << feature->PHandle.Get());
+
+    return getPluginModelById(feature->PHandle.Get());
+}
+
+PluginContainerSupport::FeaturesList
+PluginContainerSupport::getStandardFeatures() const
+{
+    //TODO use move
+    FeaturesList standardFeatures;
+
+    FOREACH(it, m_standardFeatureList)
+    {
+        FeatureModelPtr feature = getFeatureModel(*it);
+        if (!feature) {
+            LogWarning("Feature does not exist in DB " << *it);
+            continue;
+        }
+
+        //TODO maybe it should be sorted
+        standardFeatures.push_back(feature);
+    }
+
+    return standardFeatures;
+}
+
+PluginContainerSupport::PluginsList
+PluginContainerSupport::getStandardPlugins() const
+{
+    PluginsList plugins;
+
+    auto features = getStandardFeatures();
+
+    FOREACH(it, features)
+    {
+        auto plugin = getPluginModel(*it);
+        if(!plugin)
+        {
+            LogError("PluginModel not found");
+            continue;
+        }
+
+        plugins.push_back(plugin);
+    }
+
+    return plugins;
+}
+
+PluginContainerSupport::PluginsList
+PluginContainerSupport::getPluginsList() const
+{
+    LogDebug("");
+
+    PluginsList plugins;
+
+    FOREACH(it, m_pluginModels)
+    {
+        plugins.push_back(*it);
+    }
+
+    return plugins;
+}
+
+PluginModelPtr
+PluginContainerSupport::getPluginForFeature(const std::string& featureName)
+{
+   return getPluginModel(getFeatureModel(featureName));
+}
diff --git a/src/plugin-loading/plugin_container_support.h b/src/plugin-loading/plugin_container_support.h
new file mode 100644 (file)
index 0000000..8bd361e
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * 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        plugin_container_support.h
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     1.0
+ */
+#ifndef PLUGIN_CONTAINER_SUPPORT_H
+#define PLUGIN_CONTAINER_SUPPORT_H
+
+#include <memory>
+#include <set>
+#include <string>
+
+#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+#include <dpl/wrt-dao-ro/feature_model.h>
+
+#include "plugin_model.h"
+
+class PluginContainerSupport
+{
+public:
+    typedef std::list<WrtDB::FeatureModelPtr> FeaturesList;
+    typedef std::list<PluginModelPtr> PluginsList;
+
+private:
+    // Standard features
+    typedef std::list<std::string> StandardFeatureList;
+
+    // Main feature list. Always equal to DB feature list
+    typedef std::set<WrtDB::FeatureModelPtr> FeatureModelContainer;
+
+    // Main plugin list. Always equal to DB plugin list
+    typedef std::set<PluginModelPtr> PluginModelsContainer;
+
+    StandardFeatureList m_standardFeatureList;
+
+    PluginModelsContainer m_pluginModels;
+
+    FeatureModelContainer m_featureModels;
+
+    bool m_initialized;
+
+private:
+    // Reading
+    void readStandardFeaturesList();
+
+    // Plugin models
+    typedef std::multimap<WrtDB::FeatureHandle, std::string> DeviceCapList;
+    void registerFeatureModel(WrtDB::FeatureHandle handle, WrtDB::FeatureData* data, DeviceCapList deviceCapabilities);
+
+    WrtDB::FeatureModelPtr getFeatureModel(const std::string &name) const ;
+    WrtDB::FeatureModelPtr getFeatureModel(WrtDB::FeatureHandle handle) const ;
+
+    PluginModelPtr getPluginModel(const WrtDB::FeatureModelPtr &feature) const;
+
+public:
+    PluginContainerSupport();
+
+    bool isInitialized() { return m_initialized; }
+    void Initialize(int widgetHandle);
+    void registerPluginModel(WrtDB::DbPluginHandle handle);
+    std::list<std::string> getAllowedFeatures(int widgetHandle) const;
+    void readAllowedPlugins(int widgetHandle);
+    void readRootPlugins(int widgetHandle);
+    FeaturesList getStandardFeatures() const;
+    PluginsList  getStandardPlugins() const;
+    PluginsList  getPluginsList() const;
+
+    PluginModelPtr getPluginForFeature(const std::string& featureName);
+
+    PluginModelPtr getPluginModelById(WrtDB::DbPluginHandle handle) const;
+
+    ~PluginContainerSupport();
+};
+
+
+typedef std::shared_ptr<PluginContainerSupport> PluginContainerSupportPtr;
+
+#endif // PLUGIN_CONTAINER_SUPPORT_H
diff --git a/src/plugin-loading/plugin_iframe_support.cpp b/src/plugin-loading/plugin_iframe_support.cpp
new file mode 100644 (file)
index 0000000..311d847
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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    plugin_iframe_support.cpp
+ * @version 1.0
+ * @brief
+ */
+
+#include "plugin_iframe_support.h"
+
+#include <algorithm>
+#include <dpl/foreach.h>
+
+void IframesSupport::registerDeclaration(
+    const JSObjectDeclarationPtr& declaration)
+{
+    LogDebug("Registration iframes-supported plugins " <<
+             declaration->getName());
+
+    if(declaration->getParentName().find('.') != std::string::npos)
+    {
+        LogWarning("The object will not be loaded to iframes");
+        return;
+    }
+    m_iframesObjects.push_back(declaration);
+}
+
+void IframesSupport::registerIframe(const JSObjectPtr& iframe){
+    LogDebug("LoadedIframes size: " << m_loadedIframes.size() );
+
+    m_loadedIframes.insert(iframe);
+}
+
+void IframesSupport::unregisterIframe(const JSObjectPtr& iframe){
+    LogDebug("LoadedIframes size: " << m_loadedIframes.size() );
+
+    auto it_loaded = std::find_if(m_loadedIframes.begin(),
+            m_loadedIframes.end(),
+            std::bind2nd(EqualToJSObjectPtr(), iframe));
+    //object not found, so thats the new iframe
+    if(it_loaded == m_loadedIframes.end()){
+        LogDebug("Nothing to unregister");
+        return;
+    }
+
+    m_loadedIframes.erase(it_loaded);
+}
+
+bool IframesSupport::hasIframes() const
+{
+    return !m_loadedIframes.empty();
+}
+
+IframesSupport::DeclarationsList IframesSupport::getIframeObjects() const
+{
+    return m_iframesObjects;
+}
+
+void IframesSupport::clean()
+{
+    m_iframesObjects.clear();
+    m_loadedIframes.clear();
+}
diff --git a/src/plugin-loading/plugin_iframe_support.h b/src/plugin-loading/plugin_iframe_support.h
new file mode 100644 (file)
index 0000000..ce5cd14
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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    plugin_iframe_support.h
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef _WRTENGINE_SRC_PLUGINSERVICE_IFRAME_SUPPORT_H_
+#define _WRTENGINE_SRC_PLUGINSERVICE_IFRAME_SUPPORT_H_
+
+#include<list>
+#include<set>
+#include <Commons/JSObjectDeclaration.h>
+#include <Commons/JSObject.h>
+#include "javascript_interface.h"
+
+class IframesSupport
+{
+  public:
+    typedef std::list<JSObjectDeclarationPtr> DeclarationsList;
+
+  public:
+    void registerDeclaration(const JSObjectDeclarationPtr& declaration);
+
+    void registerIframe(const JSObjectPtr& iframe);
+
+    void unregisterIframe(const JSObjectPtr& iframe);
+
+    DeclarationsList getIframeObjects() const;
+
+    bool hasIframes() const;
+
+    void clean();
+
+  private:
+    std::list<JSObjectDeclarationPtr> m_iframesObjects;
+    std::set<JSObjectPtr> m_loadedIframes;
+
+    // used to find matching object from m_loadedIframes
+    struct EqualToJSObjectPtr
+    {
+        typedef JSObjectPtr     first_argument_type;
+        typedef JSObjectPtr     second_argument_type;
+        typedef bool            result_type;
+
+        result_type operator()(const first_argument_type &s1,
+                const second_argument_type &s2) const
+        {
+            return (s1->getObject() == s2->getObject());
+        }
+    };
+};
+
+#endif
diff --git a/src/plugin-loading/plugin_logic.cpp b/src/plugin-loading/plugin_logic.cpp
new file mode 100644 (file)
index 0000000..5fb5d70
--- /dev/null
@@ -0,0 +1,424 @@
+/*
+ * 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        plugin_logic.cpp
+ * @author      Piotr Fatyga (p.fatyga@samsung.com)
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation file of plugin and
+ *              feature loading routines
+ * @brief       This code is intended to work behind view controller
+ */
+
+#include "plugin_logic.h"
+
+#include <dpl/assert.h>
+#include <dpl/scoped_array.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/singleton_impl.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+#include <JavaScriptCore/JavaScript.h>
+
+#include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fstream>
+#include <map>
+#include <list>
+#include <vector>
+#include <algorithm>
+#include <cstring>
+
+#include <wrt_plugin_export.h>
+#include <js_overlay_types.h>
+
+#include "explorer.h"
+#include "plugin.h"
+#include "plugin_model.h"
+#include "javascript_interface.h"
+#include "js_function_manager.h"
+#include "plugin_container_support.h"
+
+#include "js_page_session.h"
+
+using namespace std;
+using namespace WrtDB;
+using namespace WrtPlugins::W3C;
+
+namespace {
+const char *LIBRARY_PATH_SEPARATOR = "/";
+const char* FEATURE_WAC20_DEVICAPIS_NAME = "http://wacapps.net/api/deviceapis";
+}
+
+class PluginLogic::Impl
+{
+    PluginContainerSupportPtr m_pluginsSupport;
+
+    typedef std::map<JSContextRef, JSPageSessionPtr> PagesSessionsSet;
+    PagesSessionsSet m_sessions;
+
+
+  public:
+    Impl();
+    ~Impl();
+
+    // Widget session
+    void initSession(int widgetHandle);
+    void startSession(int widgetHandle,
+                      JSGlobalContextRef context,
+                      double scaleFactor,
+                      const char* encodedBundle,
+                      const char* theme);
+
+    void stopSession(JSGlobalContextRef context);
+
+    void performLibrariesUnload();
+
+    bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+                            JavaScriptObject& parentObject,
+                            JSGlobalContextRef context);
+
+    void loadFrame(JSGlobalContextRef context);
+    void unloadFrame(JSGlobalContextRef context);
+
+    void setCustomProperties(JSGlobalContextRef ctx,
+                             double scaleFactor,
+                             const char* encodedBundle,
+                             const char* theme);
+
+    void dispatchJavaScriptEvent(JSGlobalContextRef ctx,
+                                 CustomEventType eventType,
+                                 void* data);
+
+    static bool s_sanityCheck;
+};
+
+IMPLEMENT_SINGLETON(PluginLogic);
+
+bool PluginLogic::Impl::s_sanityCheck = false;
+
+#define PLUGIN_LOGIC_SANITY_CHECK \
+    if(!s_sanityCheck)\
+    {\
+        LogError("Object is not available. Wrong flow occured");\
+        return;\
+    }
+
+PluginLogic::Impl::Impl()
+{
+    s_sanityCheck = true;
+
+    DPL::Log::LogSystemSingleton::Instance().SetTag("WRT_PLUGINS");
+    LogDebug("Initializing Plugin Logic...");
+    m_pluginsSupport = PluginContainerSupportPtr(new PluginContainerSupport());
+
+    // explicit call to keep singleton's lifetime until calling destructor.
+    JsFunctionManagerSingleton::Instance();
+    JavaScriptInterfaceSingleton::Instance();
+}
+
+PluginLogic::Impl::~Impl()
+{
+    LogDebug("");
+
+    s_sanityCheck = false;
+
+    FOREACH(it, m_sessions)
+    {
+        LogError("Must stop widget session before exit!");
+        it->second->stopSession();
+    }
+
+    LogDebug("Deinitializing plugin Logic...");
+}
+
+void PluginLogic::initSession(int widgetHandle)
+{
+    m_impl->initSession(widgetHandle);
+}
+
+void PluginLogic::startSession(int widgetHandle,
+                               JSGlobalContextRef ctx,
+                               double scaleFactor,
+                               const char* encodedBundle,
+                               const char* theme)
+{
+    m_impl->startSession(widgetHandle, ctx, scaleFactor, encodedBundle, theme);
+}
+
+void PluginLogic::stopSession(JSGlobalContextRef context)
+{
+    m_impl->stopSession(context);
+}
+
+void PluginLogic::performLibrariesUnload()
+{
+    LogError("Libraries unload TURNED OFF");
+//    m_impl->performLibrariesUnload();
+}
+
+bool PluginLogic::loadPluginOnDemand(
+    const WrtDB::DbPluginHandle &pluginHandle,
+    JavaScriptObject& parentObject,
+    JSGlobalContextRef context)
+{
+    return m_impl->loadPluginOnDemand(pluginHandle, parentObject, context);
+}
+
+void PluginLogic::loadPluginsIntoIframes(JSGlobalContextRef context)
+{
+    LogError("This function is Deprecated");
+}
+
+void PluginLogic::setCustomProperties(double scaleFactor,
+                                      const char* encodedBundle,
+                                      const char* theme)
+{
+    LogError("This function is DEPRECATED");
+}
+
+void PluginLogic::setCustomProperties(JSGlobalContextRef context,
+                                      double scaleFactor,
+                                      const char* encodedBundle,
+                                      const char* theme)
+{
+    m_impl->setCustomProperties(context, scaleFactor, encodedBundle, theme);
+}
+
+void PluginLogic::dispatchJavaScriptEvent(CustomEventType eventType)
+{
+    LogError("This function is DEPRECATED");
+}
+
+void PluginLogic::dispatchJavaScriptEvent(JSGlobalContextRef context,
+                                          CustomEventType eventType,
+                                          void *data)
+{
+    m_impl->dispatchJavaScriptEvent(context, eventType, data);
+}
+
+void PluginLogic::loadFrame(JSGlobalContextRef context)
+{
+    m_impl->loadFrame(context);
+}
+
+void PluginLogic::unloadFrame(JSGlobalContextRef context)
+{
+    m_impl->unloadFrame(context);
+}
+
+PluginLogic::PluginLogic() : m_impl(new PluginLogic::Impl())
+{
+}
+
+PluginLogic::~PluginLogic()
+{
+}
+
+void PluginLogic::Impl::initSession(int widgetHandle)
+{
+    LogInfo("init pluginLogic...");
+
+    m_pluginsSupport->Initialize(widgetHandle);
+
+    //add standard objects
+    LogDebug("Preload plugins so file");
+
+    PluginContainerSupport::PluginsList pluginList =
+                                          m_pluginsSupport->getPluginsList();
+
+    FOREACH(it, pluginList)
+    {
+        PluginModelPtr& pluginModel = *it;
+        PluginPtr pluginLib = pluginModel->LibraryInstance.Get();
+
+        if (!pluginLib)
+        {
+            std::string path = pluginModel->LibraryPath.Get() +
+                               std::string(LIBRARY_PATH_SEPARATOR) +
+                               pluginModel->LibraryName.Get();
+
+            pluginLib = Plugin::LoadFromFile(path);
+
+            if (!pluginLib)
+            {
+                LogError("Loading library failed");
+            } else
+            {
+                pluginModel->LibraryInstance.Set(pluginLib);
+
+                LogDebug("pluginModel->LibraryInstance.Set() : " << pluginLib->GetFileName());
+            }
+        }
+        else
+        {
+            LogDebug("Already loaded");
+        }
+    }
+
+    LogDebug("Preload plugins so file_done");
+}
+
+void PluginLogic::Impl::startSession(int widgetHandle,
+                                     JSGlobalContextRef context,
+                                     double scaleFactor,
+                                     const char* encodedBundle,
+                                     const char* theme)
+{
+    LogInfo("Starting widget session...");
+
+    if (!m_pluginsSupport->isInitialized())
+    {
+        m_pluginsSupport->Initialize(widgetHandle);
+    }
+    auto sessionIt = m_sessions.find(context);
+
+    // Check if corresponding session if not already created
+    if (sessionIt != m_sessions.end())
+    {
+        LogWarning("Session already started!");
+        return;
+    }
+
+    auto newSession = JSPageSessionPtr(new JSPageSession(m_pluginsSupport));
+    newSession->startSession(widgetHandle,
+                             context,
+                             scaleFactor,
+                             encodedBundle,
+                             theme);
+
+    m_sessions[context] = newSession;
+}
+
+void PluginLogic::Impl::stopSession(JSGlobalContextRef context)
+{
+    LogInfo("Stopping widget session...");
+
+    auto sessionIt = m_sessions.find(context);
+    if (sessionIt == m_sessions.end())
+    {
+        LogError("Session not exist!");
+        return;
+    }
+
+    sessionIt->second->stopSession();
+    m_sessions.erase(sessionIt);
+
+    LogInfo("Widget session stopped.");
+}
+
+bool PluginLogic::Impl::loadPluginOnDemand(
+    const WrtDB::DbPluginHandle &pluginHandle,
+    JavaScriptObject& parentObject,
+    JSGlobalContextRef context
+    )
+{
+    LogInfo("Load plugin on demand");
+
+    auto sessionIt = m_sessions.find(context);
+    if (sessionIt == m_sessions.end())
+    {
+        LogWarning("Session not exist!");
+        return false;
+    }
+
+    return sessionIt->second->loadPluginOnDemand(pluginHandle,
+                                                 parentObject,
+                                                 context);
+}
+
+void PluginLogic::Impl::loadFrame(JSGlobalContextRef context)
+{
+    LogDebug("Load a frame");
+
+    PLUGIN_LOGIC_SANITY_CHECK
+
+    auto sessionIt = m_sessions.find(context);
+    if (sessionIt == m_sessions.end())
+    {
+        LogWarning("Session not exist!");
+        return;
+    }
+
+    sessionIt->second->loadFrame(context);
+}
+
+void PluginLogic::Impl::unloadFrame(JSGlobalContextRef context)
+{
+    LogDebug("Unload a frame");
+
+    PLUGIN_LOGIC_SANITY_CHECK
+
+    auto sessionIt = m_sessions.find(context);
+    if (sessionIt == m_sessions.end())
+    {
+        LogWarning("Session not exist!");
+        return;
+    }
+
+    sessionIt->second->unloadFrame(context);
+    m_sessions.erase(sessionIt);
+}
+
+void PluginLogic::Impl::setCustomProperties(JSGlobalContextRef context,
+                                            double scaleFactor,
+                                            const char* encodedBundle,
+                                            const char* theme)
+{
+    LogInfo("set properties of window object " << scaleFactor << ", "
+            << encodedBundle << ", " << theme);
+
+    PLUGIN_LOGIC_SANITY_CHECK
+
+    auto sessionIt = m_sessions.find(context);
+    if (sessionIt == m_sessions.end())
+    {
+        LogWarning("Session not exist!");
+        return;
+    }
+
+    sessionIt->second->setCustomProperties(scaleFactor,
+                                           encodedBundle,
+                                           theme);
+
+}
+
+void PluginLogic::Impl::dispatchJavaScriptEvent(JSGlobalContextRef context,
+                                                CustomEventType eventType,
+                                                void* data)
+{
+    LogDebug("Dispatch event");
+
+    PLUGIN_LOGIC_SANITY_CHECK
+
+    auto sessionIt = m_sessions.find(context);
+    if (sessionIt == m_sessions.end())
+    {
+        LogWarning("Session not exist!");
+        return;
+    }
+
+    sessionIt->second->dispatchJavaScriptEvent(eventType, data);
+
+
+}
diff --git a/src/plugin-loading/plugin_logic.h b/src/plugin-loading/plugin_logic.h
new file mode 100644 (file)
index 0000000..e524ec0
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * 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        plugin_logic.h
+ * @author      Piotr Fatyga (p.fatyga@samsung.com)
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation file of plugin and feature
+ *              loading routines
+ * @brief       This code is intended to work behind view controller
+ */
+#ifndef PLUGIN_LOGIC_H
+#define PLUGIN_LOGIC_H
+
+#include <memory>
+#include <vector>
+#include <set>
+#include <dpl/singleton.h>
+#include <dpl/noncopyable.h>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <js_overlay_types.h>
+#include <js_types.h>
+#include <Commons/Deprecated.h>
+
+using namespace WrtPlugins::W3C;
+
+
+class PluginLogic : DPL::Noncopyable
+{
+  public:
+    // Widget session
+    void initSession(int widgetHandle);
+    void startSession(int widgetHandle,
+                      JSGlobalContextRef view,
+                      double scaleFactor,
+                      const char* encodedBundle,
+                      const char* theme);
+
+    void stopSession(JSGlobalContextRef context);
+
+    //TODO im not sure if it is needed. I think it should be hidden
+    void performLibrariesUnload();
+    bool loadPluginOnDemand(const WrtDB::DbPluginHandle &pluginHandle,
+                            JavaScriptObject& parentObject,
+                            JSGlobalContextRef context);
+
+    WRT_PLUGINS_DEPRECATED void loadPluginsIntoIframes(
+        JSGlobalContextRef context);
+
+    void loadFrame(JSGlobalContextRef context);
+    void unloadFrame(JSGlobalContextRef context);
+
+    // reset custom window properties. (Tizen requirements)
+    WRT_PLUGINS_DEPRECATED void setCustomProperties(double scaleFactor,
+                                                    const char* encodedBundle,
+                                                    const char* theme);
+
+    void setCustomProperties(JSGlobalContextRef ctx,
+                             double scaleFactor,
+                             const char* encodedBundle,
+                             const char* theme);
+
+    WRT_PLUGINS_DEPRECATED void dispatchJavaScriptEvent(CustomEventType eventType);
+
+    void dispatchJavaScriptEvent(JSGlobalContextRef ctx,
+                                CustomEventType eventType,
+                                void* data);
+
+  private:
+    PluginLogic();
+    ~PluginLogic();
+
+    class Impl;
+    std::unique_ptr<Impl> m_impl;
+
+    friend class DPL::Singleton<PluginLogic>;
+};
+
+typedef DPL::Singleton<PluginLogic> PluginLogicSingleton;
+
+#endif // PLUGIN_LOGIC_H
diff --git a/src/plugin-loading/plugin_model.cpp b/src/plugin-loading/plugin_model.cpp
new file mode 100644 (file)
index 0000000..58b56d8
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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    plugin_model.cpp
+ * @author  Pawel Sikorski (p.sikorski@samgsung.com)
+ * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samgsung.com)
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief   This file contains PluginModel, PluginHandle definitions.
+ */
+
+#include "plugin_model.h"
+#include <dpl/event/model_bind_to_dao.h>
+#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
+
+using namespace WrtDB;
+
+template <typename RetType, RetType(PluginDAOReadOnly::*extFun) () const >
+struct BindToPluginDAO :
+    DPL::Event::BindToDAO<PluginModel,
+                          RetType,
+                          WrtDB::DbPluginHandle,
+                          PluginDAOReadOnly,
+                          &PluginModel::getHandle,
+                          extFun>
+{
+};
+
+template <typename RetType, RetType(*extFun) (WrtDB::DbPluginHandle)>
+struct BindToFeatureDAOStatic :
+    DPL::Event::BindToDAO_Static<PluginModel,
+                                 RetType,
+                                 WrtDB::DbPluginHandle,
+                                 &PluginModel::getHandle,
+                                 extFun>
+{
+};
+
+PluginModel::PluginModel(const WrtDB::DbPluginHandle& handle) :
+    Handle(this, handle),
+    LibraryName(this,
+                BindToPluginDAO<std::string,
+                &PluginDAOReadOnly::getLibraryName>::Get),
+    LibraryPath(this,
+                BindToPluginDAO<std::string,
+                &PluginDAOReadOnly::getLibraryPath>::Get),
+    FeatureHandles(this,
+                   BindToFeatureDAOStatic<FeatureHandleListPtr,
+                   FeatureDAOReadOnly::GetFeatureHandleListForPlugin>::Get),
+    LibraryDependencies(this,
+                        BindToPluginDAO<PluginHandleSetPtr,
+                        &PluginDAOReadOnly::getLibraryDependencies>::Get),
+    LibraryInstance(this, PluginPtr())
+{
+}
+
+WrtDB::DbPluginHandle PluginModel::getHandle() const
+{
+    return Handle.Get();
+}
diff --git a/src/plugin-loading/plugin_model.h b/src/plugin-loading/plugin_model.h
new file mode 100644 (file)
index 0000000..624f86e
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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    plugin_model.h
+ * @author  Pawel Sikorski (p.sikorski@samgsung.com)
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief   This file contains PluginModel, PluginHandle definitions.
+ */
+
+#ifndef WRT_SRC_PLUGIN_SERVICE_PLUGIN_MODEL_H_
+#define WRT_SRC_PLUGIN_SERVICE_PLUGIN_MODEL_H_
+
+#include <string>
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <dpl/event/model.h>
+#include <dpl/event/property.h>
+
+#include <dpl/wrt-dao-ro/feature_model.h>
+#include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
+#include <plugin.h>
+
+class PluginModel;
+
+class PluginModel : public DPL::Event::Model
+{
+  public:
+
+    /**
+       *@brief Plugin handle
+     */
+    DPL::Event::Property<WrtDB::DbPluginHandle, DPL::Event::PropertyReadOnly> Handle;
+
+    /**
+       *@brief LibraryName
+     */
+    DPL::Event::Property<std::string,
+                  DPL::Event::PropertyReadOnly,
+                  DPL::Event::PropertyStorageDynamicCached> LibraryName;
+
+    /**
+       *@brief Library Path
+     */
+    DPL::Event::Property<std::string,
+                  DPL::Event::PropertyReadOnly,
+                  DPL::Event::PropertyStorageDynamicCached> LibraryPath;
+
+    /**
+       *@brief Feature set
+     */
+    DPL::Event::Property<WrtDB::FeatureHandleListPtr,
+                  DPL::Event::PropertyReadOnly,
+                  DPL::Event::PropertyStorageDynamicCached> FeatureHandles;
+
+    /**
+       *@brief Librarydepencies
+     */
+    DPL::Event::Property<WrtDB::PluginHandleSetPtr,
+                  DPL::Event::PropertyReadOnly,
+                  DPL::Event::PropertyStorageDynamicCached> LibraryDependencies;
+
+    /**
+       *@brief Library instance Low Level
+     * */
+    DPL::Event::Property<PluginPtr,
+                  DPL::Event::PropertyReadWrite,
+                  DPL::Event::PropertyStorageCached> LibraryInstance;
+
+  public:
+    PluginModel(const WrtDB::DbPluginHandle& handle);
+
+  private:
+    WrtDB::DbPluginHandle getHandle() const;
+};
+
+typedef DPL::SharedPtr<PluginModel> PluginModelPtr;
+
+#endif
diff --git a/src/plugin-loading/plugin_property_support.cpp b/src/plugin-loading/plugin_property_support.cpp
new file mode 100644 (file)
index 0000000..bf54b6f
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * 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    plugin_property_support.cpp
+ * @author  Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#include "plugin_property_support.h"
+#include <dpl/log/log.h>
+
+using namespace PluginModule;
+
+
+const char *NAVIGATOR_PROPERTY_NAME  =  "navigator";
+const char *SCALE_PROPERTY_NAME = "scale";
+const char *BUNDLE_PROPERTY_NAME  =  "__bundle";
+const char *THEME_PROPERTY_NAME  =  "theme";
+
+WindowPropertySupport::WindowPropertySupport(
+        JSGlobalContextRef context):
+    m_scale(0),
+    m_bundle(""),
+    m_theme(""),
+    m_context(context)
+{
+}
+
+WindowPropertySupport::~WindowPropertySupport()
+{
+}
+
+float WindowPropertySupport::getScale() const
+{
+    return m_scale;
+}
+
+std::string WindowPropertySupport::getBundle() const
+{
+    return m_bundle;
+}
+
+std::string WindowPropertySupport::getTheme() const
+{
+    return m_theme;
+}
+
+JSGlobalContextRef WindowPropertySupport::getJSContext() const
+{
+    return m_context;
+}
+
+void WindowPropertySupport::setScaleToNavigatorProperty(const double scale)
+{
+    LogInfo("set window.navigator.scale: " << scale);
+
+    m_scale = scale;
+    
+    setPropertyToNavigator(SCALE_PROPERTY_NAME,  JSValueMakeNumber(m_context, scale));
+}
+
+void WindowPropertySupport::setBundleToWindowProperty(const char* bundle)
+{
+    LogInfo("set window.__bundle: " << bundle);
+
+    if(bundle)
+    {
+        m_bundle = bundle;
+
+        JSStringRef bundleString = JSStringCreateWithUTF8CString(bundle);
+
+        setPropertyToWindow(BUNDLE_PROPERTY_NAME,
+                            JSValueMakeString(m_context, bundleString));
+
+        JSStringRelease(bundleString);
+    }
+}
+
+void WindowPropertySupport::setThemeToNavigatorProperty(const char* theme)
+{
+    LogInfo("set window.navigator.__theme: " << theme);
+
+    if(theme)
+    {
+        m_theme = theme;
+
+        JSStringRef themeString = JSStringCreateWithUTF8CString(theme);
+
+        setPropertyToNavigator(THEME_PROPERTY_NAME,
+                               JSValueMakeString(m_context, themeString));
+
+        JSStringRelease(themeString);
+    }
+}
+
+void WindowPropertySupport::setPropertyToWindow(const char* propertyName,
+                                                             JSValueRef jsValue)
+{
+    if(propertyName)
+    {
+        JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
+
+        JSStringRef propertyNameString =
+            JSStringCreateWithUTF8CString(propertyName);
+        JSObjectSetProperty(m_context,
+                            globalObject,
+                            propertyNameString,
+                            jsValue,
+                            kJSPropertyAttributeReadOnly,
+                            NULL);
+
+        JSStringRelease(propertyNameString);
+    }
+}
+
+void WindowPropertySupport::setPropertyToNavigator(const char* propertyName,
+                                                             JSValueRef jsValue)
+{
+    if(propertyName)
+    {
+        JSObjectRef globalObject = JSContextGetGlobalObject(m_context);
+
+        JSStringRef navigatorString =
+            JSStringCreateWithUTF8CString(NAVIGATOR_PROPERTY_NAME);
+        JSValueRef navigatorValue = JSObjectGetProperty(m_context,
+                                                        globalObject,
+                                                        navigatorString,
+                                                        NULL);
+
+        JSStringRef propertyNameString =
+            JSStringCreateWithUTF8CString(propertyName);
+        JSObjectSetProperty(m_context,
+                            JSValueToObject(m_context, navigatorValue, NULL),
+                            propertyNameString,
+                            jsValue,
+                            kJSPropertyAttributeReadOnly,
+                            NULL);
+
+        JSStringRelease(propertyNameString);
+        JSStringRelease(navigatorString);
+    }
+}
+
diff --git a/src/plugin-loading/plugin_property_support.h b/src/plugin-loading/plugin_property_support.h
new file mode 100644 (file)
index 0000000..a1914da
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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    plugin_property_support.h
+ * @author  Yunchan Cho (yunchan.cho@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef _PLUGIN_LOGIC_PROPERTY_SUPPORT_H_
+#define _PLUGIN_LOGIC_PROPERTY_SUPPORT_H_
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace PluginModule {
+
+class WindowPropertySupport
+{
+  public:
+      float getScale() const;
+      std::string getBundle() const;
+      std::string getTheme() const;
+      JSGlobalContextRef getJSContext() const;
+
+      void setScaleToNavigatorProperty(const double scale);
+      void setBundleToWindowProperty(const char* bundle);
+      void setThemeToNavigatorProperty(const char* theme);
+
+      explicit WindowPropertySupport(JSGlobalContextRef m_context);
+      ~WindowPropertySupport();
+      
+  private: 
+      float m_scale;
+      std::string m_bundle; // string of base64 encoded bundle
+      std::string m_theme;
+      JSGlobalContextRef m_context;
+
+      void setPropertyToWindow(const char* propertyName, JSValueRef jsValue);
+      void setPropertyToNavigator(const char* propertyName, JSValueRef jsValue);
+};
+
+} // namespace PluginModule
+
+#endif // _PLUGIN_LOGIC_PROPERTY_SUPPORT_H_
diff --git a/src/plugins-api-support/CMakeLists.txt b/src/plugins-api-support/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7a67b5e
--- /dev/null
@@ -0,0 +1,70 @@
+# 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   Grzegorz Krawczyk (g.krawczyk@samsung.com)
+# @version  1.0
+#
+
+pkg_search_module(dpl REQUIRED dpl-efl)
+
+set(PLUGINS_API_SUPPORT_SOURCES
+    ${CMAKE_CURRENT_SOURCE_DIR}/Plugin.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/Object.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/ObjectFactory.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/PluginRegistration.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/PluginRegistry.cpp
+)
+
+INCLUDE_DIRECTORIES(
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${dpl_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_PLUGINS_API_SUPPORT} SHARED
+    ${PLUGINS_API_SUPPORT_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGIN_API_SUPPORT} PROPERTIES
+    COMPILE_FLAGS -fPIC
+    LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_API_SUPPORT} PROPERTIES
+    SOVERSION ${CMAKE_PROJECT_API_VERSION}
+    VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_PLUGINS_API_SUPPORT}
+    ${dpl_LIBRARIES}
+)
+
+INSTALL(TARGETS ${TARGET_PLUGINS_API_SUPPORT}
+    DESTINATION lib
+    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+    GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
+)
+
+INSTALL(FILES
+    ${CMAKE_CURRENT_SOURCE_DIR}/ExportedApi.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/Plugin.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/IObject.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/ObjectFactory.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/CallbackSupport.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/tuple.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/PluginSignals.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/SignalSignature.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/PluginRegistration.h
+    DESTINATION include/wrt-plugins-api-support)
diff --git a/src/plugins-api-support/CallbackSupport.h b/src/plugins-api-support/CallbackSupport.h
new file mode 100644 (file)
index 0000000..f460fd1
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2012 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   CallbackSupport.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_CALLBACK_SUPPORT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_CALLBACK_SUPPORT_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <dpl/foreach.h>
+
+namespace WrtPluginsApi
+{
+
+template<typename Sig>
+class CallbackSupport
+{
+public:
+    typedef typename Sig::Signature SlotSignature;
+    typedef typename Sig::Type SlotType;
+    typedef std::string GroupType;
+    typedef std::vector<SlotType> SlotList;
+
+    void Connect(const GroupType& group, const SlotType& slot)
+    {
+        auto groupIt = m_slots.find(group);
+        if (m_slots.end() == groupIt)
+        {
+            groupIt = m_slots.insert(std::make_pair(group, SlotList())).first;
+        }
+        groupIt->second.push_back(slot);
+    }
+
+    void Disconnect(const GroupType& group)
+    {
+        m_slots.erase(group);
+    }
+
+    template<typename...Args>
+    void Invoke(const Args&... args)
+    {
+
+        FOREACH(groupIt, m_slots)
+        {
+            FOREACH(slotIt, groupIt->second)
+            {
+                (*slotIt)(args...);
+            }
+        }
+    }
+
+    template<typename...Args>
+    void InvokeGroup(const GroupType& group, const Args&... args)
+    {
+        auto groupIt = m_slots.find(group);
+
+        if (m_slots.end() != groupIt)
+        {
+            FOREACH (slotIt, groupIt->second)
+            {
+                (*slotIt)(args...);
+            }
+        }
+    }
+
+private:
+    std::map<GroupType, SlotList> m_slots;
+};
+
+}
+#endif
diff --git a/src/plugins-api-support/ExportedApi.h b/src/plugins-api-support/ExportedApi.h
new file mode 100644 (file)
index 0000000..f11395c
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2012 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       ExportedApi.h
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_EXPORTED_API_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_EXPORTED_API_H_
+
+#include <PluginRegistration.h>
+
+/**
+ * This file provides definition of entry point to the plugin's shared library
+ * used by wrt.
+ *
+ * Each plugin have to provide 1 symbol which is get by dlsym.
+ * The name of required symbol is specified by 'GetExportedSymbolName' function
+ * The type of this symbol is pointer to ExportedApi struct
+ *
+ * To allow access to your plugin, you have to:
+ *
+ * 1)define 3 functions:
+ *  - Register,
+ *  - Unregister,
+ *  - GetProvidedFeatures
+ *  (names are not important)
+ *
+ * 2)define global struct named "dll_api" and initialize it with above functions
+ *   *Example:
+ *    ExportedApi dll_api = {Register, Unregister, GetProvidedFeatures};
+ *
+ *
+ * Detailed Example how the file with api may looks like file:
+ *
+    #include <Commons/Exception.h>
+    #include <Commons/WrtAccess/WrtAccess.h>
+
+    #include <Plugin.h>
+    #include <ObjectFactory.h>
+    #include <PluginRegistration.h>
+    #include <ExportedApi.h>
+
+    #include "JSTest.h"
+    #include "plugin_config.h"
+
+    #define OBJECT_WIDGET "widget"
+    #define OBJECT_TEST "__test"
+
+    using namespace WrtPlugins::W3C;
+    using namespace WrtDeviceApis;
+    using namespace WrtDeviceApis::Commons;
+    using namespace WrtPluginsApi;
+
+    namespace W3CTest
+    {
+
+    void on_widget_start_callback(int widgetId)
+    {
+
+    }
+
+    void on_widget_stop_callback(int widgetId)
+    {
+    }
+
+    }
+
+    void Register(PluginRegistration& r)
+    {
+        Plugin* plugin = new Plugin();
+
+        auto test = ObjectFactory::createMainObject(
+                            OBJECT_TEST,
+                            WrtPlugins::W3C::JSTest::getClassRef,
+                            OBJECT_WIDGET);
+
+        plugin->AddObject(test);
+
+        r.Connect<OnWidgetStart>(W3CTest::on_widget_start_callback);
+
+        r.Connect<OnWidgetStop>(W3CTest::on_widget_stop_callback);
+
+        r.AddPlugin(*plugin);
+    }
+
+    void Unregister(PluginRegistration& r, Plugin* plugin)
+    {
+        r.DisconnectAll();
+        delete plugin;
+    }
+
+    void GetProvidedFeatures(feature_mapping_interface_t *mapping)
+    {
+        WrtPlugins::W3C::WidgetTestDeclarations::getMappingInterface(mapping);
+    }
+
+    ExportedApi dll_api={Register, Unregister, GetProvidedFeatures};
+
+    #undef OBJECT_WIDGET
+    #undef OBJECT_TEST
+ *
+ *
+ * */
+
+//forward declaration
+struct feature_mapping_interface_s;
+typedef struct feature_mapping_interface_s feature_mapping_interface_t;
+
+class WrtPluginsApi::Plugin;
+
+extern "C" struct ExportedApi
+{
+    /*
+     * This function is invoked when library is loaded
+     * */
+    void (*Register)(WrtPluginsApi::PluginRegistration&);
+
+    /*
+     * This function is invoked when library is unloaded
+     * */
+    void (*Unregister)(WrtPluginsApi::PluginRegistration&,
+                       WrtPluginsApi::Plugin* plugin);
+
+    /*
+     * This function is invoked by wrt-plugins-installer to obtain
+     * info about features,functions,objects provided by plugin
+     * */
+    void (*GetProvidedFeatures)(feature_mapping_interface_t*);
+};
+
+
+constexpr const char* GetExportedSymbolName()
+{
+    return "dll_api";
+}
+
+#endif
diff --git a/src/plugins-api-support/IObject.h b/src/plugins-api-support/IObject.h
new file mode 100644 (file)
index 0000000..a3acf24
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012 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    IObject.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_IOBJECT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_IOBJECT_H_
+
+#include <memory>
+#include <list>
+
+extern "C" {
+    typedef struct OpaqueJSClass* const (*ClassRef)();
+}
+
+namespace WrtPluginsApi
+{
+
+enum class IObjectType
+{
+    Object,
+    Function,
+    Interface,
+    InterfaceInstance
+};
+
+enum class IObjectOption
+{
+    Overlayed
+};
+
+class IObject;
+typedef std::shared_ptr<IObject> IObjectPtr;
+
+class IObject
+{
+  public:
+    constexpr static const char* WINDOW_OBJECT()
+    {
+        return "window";
+    }
+
+    virtual void AddChild(const IObjectPtr& ) = 0;
+
+    /*
+     * Optional
+     * */
+    virtual void setBoolOption(IObjectOption option, bool value) = 0;
+
+    virtual ~IObject(){};
+};
+
+typedef std::list<IObjectPtr> IObjectsList;
+typedef std::shared_ptr<IObjectsList> IObjectsListPtr;
+
+}
+#endif
diff --git a/src/plugins-api-support/IObject_cast.h b/src/plugins-api-support/IObject_cast.h
new file mode 100644 (file)
index 0000000..8dcf234
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2012 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    IObject_cast.h
+ * @author
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGINS_API_SUPPORT_CAST_H_
+#define _WRT_PLUGINS_COMMON_PLUGINS_API_SUPPORT_CAST_H_
+
+#include <memory>
+#include <IObject.h>
+#include <Object.h>
+
+namespace WrtPluginsApi
+{
+
+inline ObjectPtr CAST(const IObjectPtr& object)
+{
+    return std::dynamic_pointer_cast<Object>(object);
+}
+
+}
+#endif
diff --git a/src/plugins-api-support/Object.cpp b/src/plugins-api-support/Object.cpp
new file mode 100644 (file)
index 0000000..1aa039e
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2012 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    Object.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "Object.h"
+
+namespace WrtPluginsApi
+{
+
+void Object::AddChild(const IObjectPtr& child)
+{
+    if(!m_children)
+    {
+        m_children = IObjectsListPtr(new IObjectsList);
+    }
+    m_children->push_back(child);
+}
+
+void Object::setBoolOption(IObjectOption option, bool value)
+{
+   if(!m_options)
+   {
+        m_options = ObjectOptionPtr(new ObjectOption);
+   }
+
+   switch(option)
+   {
+   case IObjectOption::Overlayed:
+       m_options->overlayedMode = value;
+       break;
+   default:
+       break;
+   }
+}
+
+IObjectsListPtr Object::GetChildren() const
+{
+    return m_children;
+}
+
+ClassRef Object::GetClass() const
+{
+    return m_classRef;
+}
+
+ClassRef Object::GetClassConstructor() const
+{
+    return m_constructorRef;
+}
+
+const char* Object::GetInterfaceName() const
+{
+    return m_interfaceName;
+}
+
+const char* Object::GetName() const
+{
+    return m_name;
+}
+
+IObjectType Object::GetType() const
+{
+    return m_type;
+}
+
+const char* Object::GetParentName() const
+{
+    return m_parentName;
+}
+
+ObjectOptionPtr Object::GetOptions() const
+{
+   return m_options;
+}
+
+Object::Object(const char* name,
+               ClassRef ref,
+               IObjectType type)
+    :   m_name(name),
+        m_classRef(ref),
+        m_parentName(0),
+        m_type(type),
+        m_interfaceRef(0),
+        m_interfaceName(0),
+        m_constructorRef(0)
+{
+}
+
+Object::Object(const char* name,
+               ClassRef ref,
+               const char* parentName,
+               IObjectType type)
+    :   m_name(name),
+        m_classRef(ref),
+        m_parentName(parentName),
+        m_type(type),
+        m_interfaceRef(0),
+        m_interfaceName(0),
+        m_constructorRef(0)
+{
+}
+
+Object::Object(const char* name,
+               ClassRef interfaceRef,
+               const char* interfaceName,
+               ClassRef constructorRef,
+               const char* parentName,
+               IObjectType type)
+    :   m_name(name),
+        m_parentName(parentName),
+        m_type(type),
+        m_interfaceRef(interfaceRef),
+        m_interfaceName(interfaceName),
+        m_constructorRef(constructorRef)
+{
+}
+
+Object::~Object()
+{
+}
+
+}
diff --git a/src/plugins-api-support/Object.h b/src/plugins-api-support/Object.h
new file mode 100644 (file)
index 0000000..285f3fe
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2012 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    IObject.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_H_
+
+#include <memory>
+#include <list>
+
+#include <IObject.h>
+#include <dpl/optional.h>
+
+namespace WrtPluginsApi
+{
+
+class Object;
+typedef std::shared_ptr<Object> ObjectPtr;
+
+struct ObjectOption
+{
+    DPL::Optional<bool> overlayedMode;
+};
+typedef std::shared_ptr<ObjectOption> ObjectOptionPtr;
+
+
+class Object : public IObject
+{
+  public:
+    Object(const char* name,
+           ClassRef ref,
+           IObjectType type = IObjectType::Object);
+
+    Object(const char* name,
+           ClassRef ref,
+           const char* parentName = IObject::WINDOW_OBJECT(),
+           IObjectType type = IObjectType::Object);
+
+    Object(const char* name,
+           ClassRef interfaceRef,
+           const char* interfaceName,
+           ClassRef constructorRef,
+           const char* parentName = IObject::WINDOW_OBJECT(),
+           IObjectType type = IObjectType::Object);
+
+    ~Object();
+
+    void AddChild(const IObjectPtr& );
+
+    void setBoolOption(IObjectOption option, bool value);
+
+    IObjectsListPtr GetChildren() const ;
+
+    ClassRef GetClass() const;
+
+    /*
+     * Available only for object with type InterfaceInstance
+     * */
+    ClassRef GetClassConstructor() const;
+
+    const char* GetInterfaceName() const;
+
+    const char* GetName() const;
+
+    IObjectType GetType() const;
+
+    const char* GetParentName() const;
+
+    ObjectOptionPtr GetOptions() const;
+
+  private:
+    const char* m_name;
+    ClassRef m_classRef;
+
+    const char* m_parentName;
+
+    IObjectType m_type;
+
+    ClassRef m_interfaceRef;
+    const char* m_interfaceName;
+    ClassRef m_constructorRef;
+
+    ObjectOptionPtr m_options;
+
+    IObjectsListPtr m_children;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/ObjectFactory.cpp b/src/plugins-api-support/ObjectFactory.cpp
new file mode 100644 (file)
index 0000000..c854344
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 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    ObjectFactory.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "ObjectFactory.h"
+#include "Object.h"
+
+namespace WrtPluginsApi {
+namespace ObjectFactory {
+
+IObjectPtr createObject(
+    const char* name,
+    ClassRef ref,
+    IObjectType type)
+{
+    return IObjectPtr(new Object(name, ref, type));
+}
+
+IObjectPtr createMainObject(
+    const char* name,
+    ClassRef ref,
+    const char* parentName,
+    IObjectType type)
+{
+    return IObjectPtr(new Object(name, ref, parentName, type));
+}
+
+IObjectPtr createObjectWithInterface(
+    const char* name,
+    ClassRef interfaceRef,
+    const char* interfaceName,
+    ClassRef constructorRef,
+    const char* parentName,
+    IObjectType type)
+{
+    return IObjectPtr(new Object(name,
+                                 interfaceRef,
+                                 interfaceName,
+                                 constructorRef,
+                                 parentName,
+                                 type));
+}
+
+}
+}
diff --git a/src/plugins-api-support/ObjectFactory.h b/src/plugins-api-support/ObjectFactory.h
new file mode 100644 (file)
index 0000000..bd43878
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012 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    ObjectFactory.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_FACTORY_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_OBJECT_FACTORY_H_
+
+#include <memory>
+#include <IObject.h>
+
+namespace WrtPluginsApi {
+namespace ObjectFactory {
+
+    IObjectPtr createObject(
+        const char* name,
+        ClassRef ref,
+        IObjectType type = IObjectType::Object);
+
+    IObjectPtr createMainObject(
+        const char* name,
+        ClassRef ref,
+        const char* parentName = IObject::WINDOW_OBJECT(),
+        IObjectType type = IObjectType::Object);
+
+    IObjectPtr createObjectWithInterface(
+        const char* name,
+        ClassRef interfaceRef,
+        const char* interfaceName,
+        ClassRef constructorRef,
+        const char* parentName = IObject::WINDOW_OBJECT(),
+        IObjectType type = IObjectType::Object);
+}
+}
+#endif
diff --git a/src/plugins-api-support/Plugin.cpp b/src/plugins-api-support/Plugin.cpp
new file mode 100644 (file)
index 0000000..a3c1d04
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012 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    Plugin.cpp
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#include "Plugin.h"
+
+namespace WrtPluginsApi
+{
+
+void Plugin::AddObject(const IObjectPtr& object)
+{
+   m_objects->push_back(object);
+}
+
+IObjectsListPtr Plugin::GetObjects() const
+{
+    return m_objects;
+}
+
+Plugin::~Plugin()
+{
+}
+
+Plugin::Plugin() : m_objects(new IObjectsList())
+{
+}
+
+}
diff --git a/src/plugins-api-support/Plugin.h b/src/plugins-api-support/Plugin.h
new file mode 100644 (file)
index 0000000..3cee0a2
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012 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    Plugin.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_H_
+
+#include <list>
+#include <IObject.h>
+
+namespace WrtPluginsApi
+{
+
+class Plugin
+{
+public:
+    void AddObject(const IObjectPtr& object);
+
+    IObjectsListPtr GetObjects() const;
+
+    Plugin();
+
+    virtual ~Plugin();
+
+private:
+    IObjectsListPtr m_objects;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginRegistration.cpp b/src/plugins-api-support/PluginRegistration.cpp
new file mode 100644 (file)
index 0000000..dadd367
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012 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   PluginRegistration.cpp
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#include "PluginRegistration.h"
+
+#include "PluginRegistrationImpl.h"
+#include "Plugin.h"
+#include <dpl/assert.h>
+
+namespace WrtPluginsApi
+{
+
+PluginRegistration::PluginRegistration(Impl* impl) : m_impl(impl)
+{
+    Assert(impl != 0 && "impl is NULL");
+}
+
+template<typename SignalSignature>
+void PluginRegistration::Connect(const typename SignalSignature::Type& slot)
+{
+    m_impl->Connect<SignalSignature>(slot);
+}
+
+void PluginRegistration::DisconnectAll()
+{
+    m_impl->DisconnectAll();
+}
+
+void PluginRegistration::AddPlugin(Plugin& plugin)
+{
+    m_impl->AddPlugin(plugin);
+}
+
+#define EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(SignalSignature)               \
+        template void PluginRegistration::Connect<SignalSignature>(            \
+                const typename SignalSignature::Type&)
+
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnWidgetStart);
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnWidgetStop);
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnFrameLoad);
+EXPLICIT_INSTATIATE_PLUGIN_REGISTRATION(OnFrameUnload);
+
+}
diff --git a/src/plugins-api-support/PluginRegistration.h b/src/plugins-api-support/PluginRegistration.h
new file mode 100644 (file)
index 0000000..ea7972f
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012 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   PluginRegistration.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_H_
+
+#include <memory>
+#include "Plugin.h"
+#include "PluginSignals.h"
+
+namespace WrtPluginsApi
+{
+
+class PluginRegistration
+{
+public:
+    class Impl;
+
+    explicit PluginRegistration(PluginRegistration::Impl* impl);
+
+    template<typename SignalSignature>
+    void Connect(const typename SignalSignature::Type& slot);
+
+    void DisconnectAll();
+
+    void AddPlugin(Plugin& plugin);
+
+private:
+    std::unique_ptr<Impl> m_impl;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginRegistrationImpl.h b/src/plugins-api-support/PluginRegistrationImpl.h
new file mode 100644 (file)
index 0000000..3e1c752
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 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   PluginRegistrationImpl.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_IMPL_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_REGISTRATION_IMPL_H_
+
+#include <string>
+#include "SignalsSupport.h"
+#include "Plugin.h"
+#include <dpl/log/log.h>
+
+namespace WrtPluginsApi
+{
+
+class PluginRegistration::Impl
+{
+public:
+    Impl(SignalsSupport& registry, const std::string& libraryName)
+        : m_registry(registry),
+          m_libraryName(libraryName)
+    {}
+
+    void AddPlugin(Plugin& plugin)
+    {
+        m_registry.AddPlugin(m_libraryName, plugin);
+    }
+
+    template<typename T>
+    void Connect(const typename T::Type& slot)
+    {
+        m_registry.Connect<T>(m_libraryName, slot);
+    }
+
+    void DisconnectAll()
+    {
+        m_registry.Disconnect(m_libraryName);
+    }
+
+private:
+    SignalsSupport& m_registry;
+    std::string m_libraryName;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginRegistry.cpp b/src/plugins-api-support/PluginRegistry.cpp
new file mode 100644 (file)
index 0000000..761ba9d
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2012 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    PluginRegistry.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#include "PluginRegistry.h"
+#include "PluginRegistration.h"
+#include "PluginRegistrationImpl.h"
+#include "ExportedApi.h"
+
+#include <dlfcn.h>
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+#include <algorithm>
+
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+
+
+namespace {
+const char* DLL_ENTRY_POINT_NAME = "dll_api";
+}
+
+namespace WrtPluginsApi
+{
+
+void PluginRegistry::AddPlugin(const std::string& libraryName,
+                               Plugin& plugin)
+{
+    LogDebug("Adding plugin for library: " << libraryName);
+
+    auto libraryIt = m_plugins.find(libraryName);
+    if (m_plugins.end() == libraryIt)
+    {
+        m_plugins[libraryName] = &plugin;
+    }
+}
+
+Plugin* PluginRegistry::GetPlugin(const std::string& libraryName)
+{
+    auto it = m_plugins.find(libraryName);
+    if (it == m_plugins.end())
+    {
+        if (!LoadFromFile(libraryName))
+        {
+           LogError("Failed to load lib" << libraryName);
+           ThrowMsg(PluginNotFound, "Failed to load plugin");
+        }
+
+        return m_plugins[libraryName];
+    }
+
+    return it->second;
+}
+
+void PluginRegistry::RemovePlugin(const std::string& libraryName,
+                                  Plugin& plugin)
+{
+    auto it = m_plugins.find(libraryName);
+    if (it != m_plugins.end())
+    {
+        if (&plugin == it->second)
+        {
+            m_plugins.erase(it);
+        }
+    }
+}
+
+void PluginRegistry::UnloadAll()
+{
+    LogDebug("Unload all plugins");
+
+    typedef void (*UnregisterFunction) (PluginRegistration&, Plugin&);
+
+    FOREACH(libraryIt, m_libraries)
+    {
+        auto pluginIt = m_plugins.find(libraryIt->first);
+        if (m_plugins.end() != pluginIt)
+        {
+            void* handle = dlopen(libraryIt->first.c_str(), RTLD_NOW);
+            if (!handle) {
+                LogError("Error: " << dlerror());
+                continue;
+            }
+
+            ExportedApi* entryPoint =
+                static_cast<ExportedApi*>
+                    (dlsym(handle, GetExportedSymbolName()));
+            if (NULL == entryPoint)
+            {
+                LogError("Error: " << dlerror());
+                continue;
+            }
+            if (entryPoint->Unregister == NULL)
+            {
+                LogError("Error Unregister function not set");
+                continue;
+            }
+
+            PluginRegistration registration(
+                new PluginRegistration::Impl(*this, libraryIt->first));
+
+            entryPoint->Unregister(registration, (pluginIt->second));
+
+            m_plugins.erase(pluginIt);
+        }
+        dlclose(libraryIt->second);
+    }
+}
+
+bool PluginRegistry::LoadFromFile(const std::string& libraryName)
+{
+    void* handle = dlopen(libraryName.c_str(), RTLD_NOW);
+    if (!handle) {
+        LogError("Error: " << dlerror());
+        return false;
+    }
+    m_libraries[libraryName] = handle;
+
+    ExportedApi* entryPoint =
+        static_cast<ExportedApi*>(dlsym(handle, GetExportedSymbolName()));
+    if (NULL == entryPoint)
+    {
+        LogError("Error: " << dlerror());
+        return false;
+    }
+
+    if (entryPoint->Register == NULL)
+    {
+        LogError("Error Register function not set");
+        return false;
+    }
+    if (entryPoint->Unregister== NULL)
+    {
+        LogError("Error Unregister function not set");
+        return false;
+    }
+
+    PluginRegistration registration(
+            new PluginRegistration::Impl(*this, libraryName));
+    entryPoint->Register(registration);
+
+    return true;
+}
+
+
+PluginRegistry::~PluginRegistry()
+{
+    //TODO discuss ... when the unload should be called
+//    UnloadAll();
+}
+
+}
diff --git a/src/plugins-api-support/PluginRegistry.h b/src/plugins-api-support/PluginRegistry.h
new file mode 100644 (file)
index 0000000..d3e66b4
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012 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    PluginRegistry.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_LOADING_PLUGIN_REGISTRY_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_LOADING_PLUGIN_REGISTRY_H_
+
+#include <map>
+#include <string>
+#include "SignalsSupport.h"
+#include "Plugin.h"
+#include <dpl/exception.h>
+
+namespace WrtPluginsApi
+{
+
+typedef std::list<Plugin*> PluginsList;
+typedef std::shared_ptr<PluginsList> PluginsListPtr;
+typedef std::map< std::string, PluginsListPtr> PluginsSet;
+
+class PluginRegistry : public SignalsSupport
+{
+public:
+    DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+    DECLARE_EXCEPTION_TYPE(Base, PluginNotFound)
+
+    template <typename T, typename ...Args>
+    void Call(Args... args)
+    {
+        Invoke<T>(args...);
+    }
+
+    template <typename T, typename ...Args>
+    void CallGroup(const typename CallbackSupport<T>::GroupType& type,
+                   Args... args)
+    {
+        InvokeGroup<T>(type, args...);
+    }
+
+    void AddPlugin(const std::string& libraryName, Plugin& plugin);
+
+    /*
+     * @throw PluginNotFound
+     * */
+    Plugin* GetPlugin(const std::string& libraryName);
+
+    void RemovePlugin(const std::string& libraryName, Plugin& plugin);
+
+    void UnloadAll();
+
+    ~PluginRegistry();
+private:
+    bool LoadFromFile(const std::string& libraryName);
+
+    typedef void* Symbol;
+
+    std::map<std::string, Plugin*> m_plugins;
+    std::map<std::string, void*> m_libraries;
+};
+
+typedef std::shared_ptr<PluginRegistry> PluginRegistryPtr;
+
+}
+
+#endif
diff --git a/src/plugins-api-support/PluginSignals.h b/src/plugins-api-support/PluginSignals.h
new file mode 100644 (file)
index 0000000..ab22da1
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012 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   PluginSignals.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_SIGNALS_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_PLUGIN_SIGNALS_H_
+
+#include "SignalSignature.h"
+
+namespace WrtPluginsApi
+{
+
+struct OnWidgetStart : SignalSignature<void (int)> {};
+
+struct OnWidgetStop : SignalSignature<void (int)> {};
+
+struct OnFrameLoad: SignalSignature<void (void*)> {};
+
+struct OnFrameUnload : SignalSignature<void (void*)> {};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/SignalSignature.h b/src/plugins-api-support/SignalSignature.h
new file mode 100644 (file)
index 0000000..19fce6c
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012 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   SignalSignature.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNAL_SIGNATURE_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNAL_SIGNATURE_H_
+
+#include <functional>
+
+namespace WrtPluginsApi
+{
+
+template<typename> struct SignalSignature;
+
+template<typename R, typename ...Args>
+struct SignalSignature<R (Args...)>
+{
+    typedef R (*Signature) (Args...);
+    typedef std::function<R (Args...)> Type;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/SignalsSupport.h b/src/plugins-api-support/SignalsSupport.h
new file mode 100644 (file)
index 0000000..56e7e67
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2012 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    IPluginRegistry.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNALS_SUPPORT_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_SIGNALS_SUPPORT_H_
+
+#include <tuple>
+#include <string>
+#include "CallbackSupport.h"
+#include "tuple.h"
+#include "PluginSignals.h"
+#include "Plugin.h"
+
+namespace WrtPluginsApi
+{
+
+class SignalsSupport
+{
+public:
+    virtual ~SignalsSupport() {}
+
+    template<typename T>
+    void Connect(const std::string& libraryName, const typename T::Type& slot)
+    {
+        Tuple::get_by_type<CallbackSupport<T>>(m_slots).Connect(libraryName,
+                                                                slot);
+    }
+
+    void Disconnect(const std::string& libraryName)
+    {
+        DisconnectGroup(m_slots, libraryName);
+    }
+
+    virtual void AddPlugin(const std::string& libraryName, Plugin& plugin) = 0;
+
+protected:
+    template<typename T, typename ...Args>
+    void Invoke(const Args&... args)
+    {
+        Tuple::get_by_type<CallbackSupport<T>>(m_slots).Invoke(args...);
+    }
+
+    template<typename T, typename ...Args>
+    void InvokeGroup(const std::string& libraryName, const Args&... args)
+    {
+        Tuple::get_by_type<CallbackSupport<T>>(m_slots).InvokeGroup(libraryName,
+                                                                    args...);
+    }
+
+private:
+    template<int N, typename ...Args>
+    void DisconnectSlot(std::tuple<Args...>& slots,
+                        const std::string& libraryName,
+                        typename std::enable_if<(N >= 0)>::type* = NULL)
+    {
+        std::get<N>(slots).Disconnect(libraryName);
+        DisconnectSlot<N-1>(slots, libraryName);
+    }
+
+    template<int N, typename ...Args>
+    void DisconnectSlot(std::tuple<Args...>& slots,
+                        const std::string& libraryName,
+                        typename std::enable_if<(N == -1)>::type* = NULL)
+    {
+    }
+
+    template<typename ...Args>
+    void DisconnectGroup(std::tuple<Args...>& slots,
+                         const std::string& libraryName)
+    {
+        DisconnectSlot<sizeof...(Args)-1>(slots, libraryName);
+    }
+
+    std::tuple<CallbackSupport<OnWidgetStart>,
+               CallbackSupport<OnWidgetStop>,
+               CallbackSupport<OnFrameLoad>,
+               CallbackSupport<OnFrameUnload>> m_slots;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/SoFeatures.h b/src/plugins-api-support/SoFeatures.h
new file mode 100644 (file)
index 0000000..54b1bd7
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2012 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
+ * @author
+ * @version
+ * @brief    TODO This header must be removed because it does not fit to current
+ * solution, its just a temporary approach.
+ */
+#ifndef _WRT_PLUGINS_COMMON_FEATURE_API_SO_FEATURES_H_
+#define _WRT_PLUGINS_COMMON_FEATURE_API_SO_FEATURES_H_
+
+#define PLUGIN_WIDGET_INIT_PROC_NAME         "on_widget_init"
+//#define PLUGIN_WIDGET_INIT_PROC_NAME \
+//    "_Z23on_widget_init_callbackP27feature_mapping_interface_s"
+
+//TODO remove
+/*
+ * list of device caps
+ */
+typedef struct devcaps_s
+{
+    char** deviceCaps;
+    size_t devCapsCount;
+} devcaps_t;
+
+/*
+ * mapping from a feature to corresponding list of device capabilities
+ */
+typedef struct feature_devcaps_s
+{
+    char* feature_name;
+    devcaps_t devCaps;
+} feature_devcaps_t;
+
+/*
+ * list of feature_devcaps_t structs
+ */
+typedef struct feature_mapping_s
+{
+    feature_devcaps_t* features;
+    size_t featuresCount;
+} feature_mapping_t;
+
+
+typedef feature_mapping_t* pfeature_mapping_t;
+
+typedef pfeature_mapping_t (*features_getter)(void);
+
+typedef const devcaps_t* (*devcaps_getter)(pfeature_mapping_t /*features*/,
+                                           const char* /*featureName*/);
+typedef void (*deinitializer)(pfeature_mapping_t /*features*/);
+
+typedef struct feature_mapping_interface_s
+{
+    features_getter featGetter;  /* returns a list of api features */
+    devcaps_getter dcGetter;     /*
+                                  * for a given api feature returns a list of
+                                  * corresponding device capabilities
+                                  */
+
+    deinitializer release;       /* as memory ownership of features is
+                                  * transfered to callee you have to call
+                                  * the release function ptr on features
+                                  */
+} feature_mapping_interface_t;
+
+typedef void (*on_widget_init_proc)(feature_mapping_interface_t *interface);
+
+#endif
diff --git a/src/plugins-api-support/detail/traits.h b/src/plugins-api-support/detail/traits.h
new file mode 100644 (file)
index 0000000..912e286
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2012 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   traits.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_DETAIL_TRAITS_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_DETAIL_TRAITS_H_
+
+namespace WrtPluginsApi {
+namespace Traits {
+namespace Detail {
+
+template<size_t, typename RequiredType, typename ...TupleArgTypes>
+struct index_of_;
+
+/*
+ * CurrentArgType is not equal to RequiredType, check next tuple's argument
+ */
+template<size_t n,
+        typename RequiredType,
+        typename CurrentArgType,
+        typename ...TupleArgTypes>
+struct index_of_<n, RequiredType, CurrentArgType, TupleArgTypes...>
+{
+    static const size_t value = index_of_<n + 1,
+                                          RequiredType,
+                                          TupleArgTypes...>::value;
+};
+
+/*
+ * RequiredType found on tuple's args list
+ * return position on tuple's list
+ */
+template<size_t n, typename RequiredType, typename ...TupleArgTypes>
+struct index_of_<n, RequiredType, RequiredType, TupleArgTypes...>
+{
+    static const size_t value = n;
+};
+
+/*
+ * RequiredType found on last position of tuple's args list
+ * return position on tuple's list
+ */
+template<size_t n, typename RequiredType>
+struct index_of_<n, RequiredType, RequiredType>
+{
+  static const size_t value = n;
+};
+
+/*
+ * RequiredType was not found on tuple args list
+ */
+template<size_t n, typename RequiredType, typename LastArgType>
+struct index_of_<n, RequiredType, LastArgType>
+{
+    static const size_t value = -1;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/plugins-api-support/js_types.h b/src/plugins-api-support/js_types.h
new file mode 100644 (file)
index 0000000..69181ee
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012 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        js_types.h
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     1.0
+ */
+
+#ifndef WRT_PLUGIN_COMMON_API_SUPPORT_JS_TYPES_H_
+#define WRT_PLUGIN_COMMON_API_SUPPORT_JS_TYPES_H_
+
+#include <string>
+
+//forward declaration
+extern "C" {
+    typedef struct OpaqueJSContext* JSGlobalContextRef;
+    typedef struct OpaqueJSValue* JSObjectRef;
+}
+
+namespace WrtPluginsApi
+{
+
+struct JavaScriptObject
+{
+    JSObjectRef instance;
+    std::string name;
+};
+
+}
+
+#endif
diff --git a/src/plugins-api-support/traits.h b/src/plugins-api-support/traits.h
new file mode 100644 (file)
index 0000000..7635a0a
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012 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   traits.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TRAITS_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TRAITS_H_
+
+#include "detail/traits.h"
+
+namespace WrtPluginsApi
+{
+
+namespace Traits {
+
+/**
+ * Gets index of specified type in the type list.
+ */
+template<typename RequiredType, typename ...TupleArgTypes>
+struct index_of
+{
+    static const size_t value = Detail::index_of_<0,
+                                               RequiredType,
+                                               TupleArgTypes...>::value;
+};
+
+}
+
+}
+
+#endif
diff --git a/src/plugins-api-support/tuple.h b/src/plugins-api-support/tuple.h
new file mode 100644 (file)
index 0000000..ef3b62c
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012 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   tuple.h
+ * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+ */
+
+#ifndef _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TUPLE_H_
+#define _WRT_PLUGINS_COMMON_PLUGIN_API_SUPPORT_TUPLE_H_
+
+#include <tuple>
+#include "traits.h"
+
+namespace WrtPluginsApi {
+namespace Tuple {
+
+template<typename T, typename ...Args>
+T& get_by_type(std::tuple<Args...>& tuple)
+{
+    return std::get<Traits::index_of<T, Args...>::value>(tuple);
+}
+
+}
+}
+
+#endif
diff --git a/src/plugins-installer/CMakeLists.txt b/src/plugins-installer/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4fcb46d
--- /dev/null
@@ -0,0 +1,69 @@
+# 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   Andrzej Surdej (a.surdej@samsung.com)
+# @version  1.0
+#
+
+SET(TARGET_PLUGINS_INSTALLER "wrt-plugins-installer")
+
+SET(WRT_PLUGINS_INSTALLER_SRC_DIR
+    ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+PKG_CHECK_MODULES(PLUGINS_INSTALLER_DEPS
+    libxml-2.0
+    cert-svc-vcore
+    dpl-efl
+    dpl-wrt-dao-rw
+    libpcrecpp
+    REQUIRED
+)
+
+INCLUDE_DIRECTORIES(
+    ${WRT_PLUGINS_INSTALLER_SRC_DIR}
+    ${PLUGINS_INSTALLER_INCLUDES}
+    ${PLUGINS_INSTALLER_DEPS_INCLUDE_DIRS}
+    ${PLUGINS_API_SUPPORT_DIRS}
+)
+
+SET(WRT_PLUGINS_INSTALLER_SOURCES
+    ${WRT_PLUGINS_INSTALLER_SRC_DIR}/wrt_plugins_installer.cpp
+    ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_installer.cpp
+    ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_utils.cpp
+    ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_objects.cpp
+    ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_metafile_reader.cpp
+)
+
+ADD_DEFINITIONS(${PLUGINS_INSTALLER_DEPS_CFLAGS})
+ADD_DEFINITIONS(${PLUGINS_INSTALLER_DEPS_CFLAGS_OTHERS})
+
+ADD_EXECUTABLE(${TARGET_PLUGINS_INSTALLER}
+    ${WRT_PLUGINS_INSTALLER_SOURCES}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_PLUGINS_INSTALLER}
+    ${PLUGINS_INSTALLER_DEPS_LIBRARIES}
+    ${TARGET_PLUGINS_API_SUPPORT} "-ldl"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_INSTALLER} PROPERTIES
+    LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both -Wl"
+    BUILD_WITH_INSTALL_RPATH ON
+    INSTALL_RPATH_USE_LINK_PATH ON
+)
+
+INSTALL(TARGETS ${TARGET_PLUGINS_INSTALLER} DESTINATION bin)
diff --git a/src/plugins-installer/DESCRIPTION b/src/plugins-installer/DESCRIPTION
new file mode 100644 (file)
index 0000000..0e8c571
--- /dev/null
@@ -0,0 +1,2 @@
+!!!options!!! stop
+Widget (un)installer, plugin (un)installer
diff --git a/src/plugins-installer/plugin_installer.cpp b/src/plugins-installer/plugin_installer.cpp
new file mode 100644 (file)
index 0000000..a2c668d
--- /dev/null
@@ -0,0 +1,691 @@
+/*
+ * Copyright (c) 2012 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    plugin_installer.cpp
+ * @author  Andrzej Surdej(a.surdej@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "plugin_installer.h"
+
+#include <sys/stat.h>
+#include <cstdio>
+#include <dlfcn.h>
+#include <string>
+
+#include <vcore/VCore.h>
+#include <libxml/parser.h>
+
+#include "plugin_objects.h"
+#include "plugin_metafile_reader.h"
+#include "plugin_installer_errors.h"
+
+#include <Plugin.h>
+#include <IObject_cast.h>
+//#include <SoFeatures.h>
+#include <plugin_utils.h>
+#include <ExportedApi.h>
+
+#include <wrt-commons/wrt_plugin_export.h>
+
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-rw/plugin_dao.h>
+#include <dpl/wrt-dao-rw/feature_dao.h>
+#include <dpl/foreach.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+
+#include <dpl/singleton_impl.h>
+
+using namespace WrtDB;
+using namespace WrtPluginsApi;
+
+IMPLEMENT_SINGLETON(PluginsInstaller)
+
+namespace {
+const std::string DIRECTORY_SEPARATOR = std::string("/");
+}
+
+const int PluginsInstaller::INSTALLATION_ERROR = -1;
+
+PluginsInstaller::PluginsInstaller()
+    : m_initialized(false)
+{
+    LogInfo("PluginsInstaller created.");
+}
+PluginsInstaller::~PluginsInstaller()
+{
+    LogInfo("PluginsInstaller destroyed.");
+}
+
+void PluginsInstaller::checkDatabaseTablesExistance()
+{
+    if (!WrtDB::WrtDatabase::CheckTableExist("FeaturesList") ||
+        !WrtDB::WrtDatabase::CheckTableExist("PluginProperties") ||
+        !WrtDB::WrtDatabase::CheckTableExist("PluginDependencies") ||
+        !WrtDB::WrtDatabase::CheckTableExist("PluginImplementedObjects") ||
+        !WrtDB::WrtDatabase::CheckTableExist("PluginRequiredObjects") ||
+        !WrtDB::WrtDatabase::CheckTableExist("DeviceCapabilities") ||
+        !WrtDB::WrtDatabase::CheckTableExist("FeatureDeviceCapProxy"))
+    {
+        LogError("Wrong database. Required tables not exist.");
+        deinitialize();
+        Assert(false && "Wrong database. Required tables not exist.");
+    }
+}
+
+bool PluginsInstaller::initialize()
+{
+    LogDebug("Initializing required systems.");
+
+    // Check paths
+    if (!PluginUtils::checkPaths()) {
+        return false;
+    }
+    // Initialize ValidationCore - this must be done before AttachDatabases
+    ValidationCore::VCoreInit(
+        std::string(GlobalConfig::GetFingerprintListFile()),
+        std::string(GlobalConfig::GetFingerprintListSchema()),
+        std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
+
+    xmlInitParser();
+    WrtDB::WrtDatabase::attachToThreadRW();
+    ValidationCore::AttachToThreadRW();
+    checkDatabaseTablesExistance();
+    LogDebug("Initialized.");
+    m_initialized = true;
+    return true;
+}
+
+void PluginsInstaller::deinitialize()
+{
+    LogDebug("Shuting systems down.");
+    m_initialized = false;
+    ValidationCore::DetachFromThread();
+    WrtDB::WrtDatabase::detachFromThread();
+    ValidationCore::VCoreDeinit();
+    xmlCleanupParser();
+    LogDebug("Done");
+}
+
+PluginsInstaller::ReturnStatus PluginsInstaller::installPlugin(
+        const std::string& libPath)
+{
+    if (!m_initialized) {
+        LogError("Plugins installer not initialized.");
+        return ReturnStatus::NotInitialized;
+    }
+    LogInfo("Plugin installation started. Checking path: " << libPath);
+
+    if (!PluginUtils::checkPath(libPath))
+        return ReturnStatus::WrongPluginPath;
+
+    LogInfo("Plugin path ok. Searching for config file...");
+
+    std::string metaFileName = libPath + DIRECTORY_SEPARATOR +
+        std::string(WrtDB::GlobalConfig::GetPluginMetafileName());
+    if (PluginUtils::checkFileExistance(metaFileName))
+    {
+        return installPluginFromMetafile(libPath, metaFileName);
+    }
+
+    PluginMetafileData pluginInfo;
+    pluginInfo.m_libraryName = getLibraryName(libPath);
+
+    LogInfo("Config file done. Lib name: " << pluginInfo.m_libraryName
+            << ". Searching for installed plugin...");
+
+    if (WrtDB::PluginDAO::isPluginInstalled(pluginInfo.m_libraryName)) {
+        LogInfo("Plugin already installed.");
+        return ReturnStatus::AlreadyInstalled;
+    }
+    LogInfo("Plugin not installed. Loading library file...");
+
+    PluginObjectsPtr libraryObjects;
+    PluginHandle pluginHandle;
+
+    std::string filename = libPath + DIRECTORY_SEPARATOR +
+        pluginInfo.m_libraryName;
+
+    LogDebug("Loading plugin: " << filename);
+
+    Plugin* plugin;
+    Try
+    {
+        plugin = m_registry.GetPlugin(filename);
+    }
+    Catch(DPL::Exception) {
+        LogError("Loading library failed " << filename);
+        return ReturnStatus::LoadingLibraryError;
+    }
+    libraryObjects = PluginObjectsPtr(new PluginObjects());
+
+    LogInfo("#####");
+    LogInfo("##### Plugin: " << filename << " supports new plugin API");
+    LogInfo("#####");
+
+    FOREACH(o, *plugin->GetObjects()) {
+        libraryObjects->addObjects(CAST(*o)->GetParentName(),
+            CAST(*o)->GetName());
+
+        LogDebug("[Parent << Object] " << CAST(*o)->GetParentName()
+            << " << "
+            << CAST(*o)->GetName());
+
+        registerObjects(libraryObjects, plugin->GetObjects());
+    }
+
+    if (!fillMappingInterfaces(pluginInfo, filename)) {
+        m_registry.RemovePlugin(filename, *plugin);
+        return ReturnStatus::LoadingLibraryError;
+    }
+
+    LogInfo("Library loaded. Registering plugin...");
+
+    Try
+    {
+        pluginHandle =
+            PluginDAO::registerPlugin(pluginInfo, libPath);
+
+        LogInfo("Plugin registered. Registering features...");
+
+        FOREACH(it, pluginInfo.m_featureContainer)
+        {
+            LogError("PluginHandle: " << pluginHandle);
+            FeatureDAO::RegisterFeature(*it, pluginHandle);
+        }
+
+        LogInfo("Features registered. Registering objects...");
+
+        registerPluginObjects(pluginHandle, libraryObjects);
+
+        LogInfo("Registration done. Resolving dependencies...");
+
+        //TODO: can it be replaced with resolvePluginDependencies(handle)
+        if (!registerAndUpdateInstallation(pluginHandle, libraryObjects))
+            return ReturnStatus::InstallationWaiting;
+    } Catch (DPL::Exception) {
+        LogError("Failed to make database entry.");
+        return ReturnStatus::DatabaseError;
+    }
+
+    LogInfo("Plugin installed successfully.");
+    return ReturnStatus::Success;
+}
+
+PluginObjectsPtr PluginsInstaller::loadLibraryFromMetafile(
+        const std::string& libName) const
+{
+    LogInfo("Loading library: " << libName);
+
+    void *dlHandle = dlopen(libName.c_str(), RTLD_NOW);
+    if (dlHandle == NULL ) {
+        LogError(
+                "Failed to load plugin: " << libName <<
+                ". Reason: " << dlerror());
+        ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+    }
+
+    const js_entity_definition_t *rawEntityList = NULL;
+    get_widget_entity_map_proc *getWidgetEntityMapProcPtr = NULL;
+
+    getWidgetEntityMapProcPtr =
+        reinterpret_cast<get_widget_entity_map_proc *>(dlsym(dlHandle,
+                    PLUGIN_GET_CLASS_MAP_PROC_NAME));
+
+    if (getWidgetEntityMapProcPtr) {
+        rawEntityList = (*getWidgetEntityMapProcPtr)();
+    } else {
+        rawEntityList =
+            static_cast<const js_entity_definition_t *>(dlsym(dlHandle,
+                        PLUGIN_CLASS_MAP_NAME));
+    }
+
+    if (rawEntityList == NULL) {
+        dlclose(dlHandle);
+        LogError("Failed to read class name" << libName);
+        ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+    }
+
+    PluginObjectsPtr libraryObjects = PluginObjectsPtr(new PluginObjects());
+    const js_entity_definition_t *rawEntityListIterator = rawEntityList;
+
+    LogInfo("#####");
+    LogInfo("##### Plugin: " << libName << " is using deprecated API");
+    LogInfo("#####");
+
+    while (rawEntityListIterator->parent_name != NULL &&
+            rawEntityListIterator->object_name != NULL)
+    {
+        LogInfo("#####     [" << rawEntityListIterator->object_name << "]: ");
+        LogInfo("#####     Parent: " << rawEntityListIterator->parent_name);
+        LogInfo("#####");
+
+        libraryObjects->addObjects(rawEntityListIterator->parent_name,
+                rawEntityListIterator->object_name);
+
+        ++rawEntityListIterator;
+    }
+
+    // Unload library
+    if (dlclose(dlHandle) != 0) {
+        LogError("Cannot close plugin handle");
+    } else {
+        LogDebug("Library is unloaded");
+    }
+
+    // Load export table
+    LogDebug("Library successfuly loaded and parsed");
+
+    return libraryObjects;
+}
+
+
+PluginsInstaller::ReturnStatus PluginsInstaller::installPluginFromMetafile(
+        const std::string& path, const std::string& metaFilePath)
+{
+    if (!m_initialized) {
+        LogError("Plugins installer not initialized.");
+        return ReturnStatus::NotInitialized;
+    }
+    OptionalPluginMetafileData pluginData;
+    Try
+    {
+        pluginData = parseMetafile(metaFilePath);
+    }
+    Catch (PluginInstall::Exceptions::XMLFileParsingException)
+    {
+        LogError("Parsing metafile failed.");
+        return ReturnStatus::MetafileError;
+    }
+    if (pluginData.IsNull()) {
+        return ReturnStatus::MetafileError;
+    }
+
+    if (WrtDB::PluginDAO::isPluginInstalled(pluginData->m_libraryName)) {
+        LogInfo("Plugin already installed.");
+        return ReturnStatus::AlreadyInstalled;
+    }
+    Try {
+
+        LogError("path is: " << path << ", libraryName: " << pluginData->m_libraryName);
+        PluginObjectsPtr objects = loadLibraryFromMetafile(
+            path + DIRECTORY_SEPARATOR + pluginData->m_libraryName);
+
+        PluginHandle pluginHandle =
+            PluginDAO::registerPlugin(*pluginData, path);
+
+        LogInfo("Plugin registered. Registering features...");
+
+        FOREACH(it, pluginData->m_featureContainer)
+        {
+            LogError("PluginHandle: " << pluginHandle);
+            FeatureDAO::RegisterFeature(*it, pluginHandle);
+        }
+
+        LogInfo("Features registered. Registering objects...");
+
+        registerPluginObjects(pluginHandle, objects);
+
+        LogInfo("Objects registered. Finishing...");
+
+        if (!registerAndUpdateInstallation(pluginHandle, objects))
+            return ReturnStatus::InstallationWaiting;
+    } Catch (DPL::Exception) {
+        LogError("Failed to make database entry.");
+        return ReturnStatus::DatabaseError;
+    }
+
+    LogInfo("Plugin installed successfully.");
+    return ReturnStatus::Success;
+}
+
+int PluginsInstaller::installAllPlugins()
+{
+    if (!m_initialized) {
+        LogError("Plugins installer not initialized.");
+        return INSTALLATION_ERROR;
+    }
+    LogDebug("Installing plugins ...");
+
+    std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
+
+    DIR *dir;
+    dir = opendir(PLUGIN_PATH.c_str());
+
+    if (!dir) {
+        return INSTALLATION_ERROR;
+    }
+
+    LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
+    struct dirent* libdir;
+
+    errno = 0;
+
+    std::list<std::string> pluginsPaths;
+
+    while ((libdir = readdir(dir)) != 0) {
+        if (strcmp(libdir->d_name, ".") == 0 ||
+            strcmp(libdir->d_name, "..") == 0) {
+            continue;
+        }
+
+        std::string path = PLUGIN_PATH;
+        path += "/";
+        path += libdir->d_name;
+
+        struct stat tmp;
+
+        if (stat(path.c_str(), &tmp) == -1) {
+            LogError("Failed to open file" << path);
+            continue;
+        }
+
+        if (!S_ISDIR(tmp.st_mode)) {
+            LogError("Not a directory" << path);
+            continue;
+        }
+
+        LogDebug("Found plugin at " << path);
+        pluginsPaths.push_back(path);
+    }
+
+    if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+        LogError("Failed to close dir: " << PLUGIN_PATH);
+    }
+
+    LogDebug("Plugins to install: " << pluginsPaths.size());
+
+    for (int k = 0; k <= pluginsPaths.size(); ++k)
+        printf(" ");
+    printf("]\r[");
+    int installedPluginsCount = 0;
+    ReturnStatus ret = ReturnStatus::Unknown;
+    FOREACH(it, pluginsPaths) {
+        LogInfo("Preparing to plugin installation: " << *it);
+        ret = installPlugin(*it);
+        if (ReturnStatus::Success == ret) {
+            ++installedPluginsCount;
+            LogInfo("Plugin " << *it << " installed.");
+        } else if (ReturnStatus::InstallationWaiting == ret) {
+            LogWarning("Plugin not installed. Waiting for dependency");
+        } else {
+            LogError("Plugin installation failed");
+        }
+        printf("#");
+        fflush(stdout);
+    }
+    printf("\n");
+    installedPluginsCount += installWaitingPlugins();
+    m_registry.UnloadAll();
+    LogInfo("Installed " << installedPluginsCount
+            << " plugins of total: " << pluginsPaths.size());
+    return installedPluginsCount;
+}
+
+int PluginsInstaller::installWaitingPlugins()
+{
+    PluginHandleSetPtr waitingPlugins;
+
+    waitingPlugins =
+        PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_WAITING);
+
+    int pluginsInstalled = 0;
+    FOREACH(it, *waitingPlugins)
+    {
+        if (resolvePluginDependencies(*it))
+            ++pluginsInstalled;
+    }
+    return pluginsInstalled;
+}
+
+bool PluginsInstaller::resolvePluginDependencies(PluginHandle handle)
+{
+    PluginHandleSetPtr dependencies(new PluginHandleSet);
+
+    PluginObjects::ObjectsPtr requiredObjects =
+        PluginDAO::getRequiredObjectsForPluginHandle(handle);
+
+    PluginHandle depHandle = INVALID_PLUGIN_HANDLE;
+
+    FOREACH(requiredObject, *requiredObjects)
+    {
+        depHandle =
+            PluginDAO::getPluginHandleForImplementedObject(*requiredObject);
+
+        if (INVALID_PLUGIN_HANDLE == depHandle) {
+            LogError("Library implementing: " <<
+                     *requiredObject << " NOT FOUND");
+            return false;
+        }
+        dependencies->insert(depHandle);
+    }
+
+    PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
+    PluginDAO::setPluginInstallationStatus(handle,
+                                           PluginDAO::INSTALLATION_COMPLETED);
+
+    return true;
+}
+
+void PluginsInstaller::registerObjects(const PluginObjectsPtr& libObj,
+                                       const IObjectsListPtr& objects) const
+{
+   LogDebug("registerObjects invoked");
+
+   FOREACH(o, *objects)
+   {
+       auto children = CAST(*o)->GetChildren();
+
+       if(children)
+       {
+           FOREACH(c, *children)
+           {
+               libObj->addObjects(CAST(*o)->GetName(), CAST(*c)->GetName());
+
+               LogDebug("[Parent << Object] " << CAST(*c)->GetName()
+                        << " << "
+                        << CAST(*o)->GetName());
+           }
+
+           registerObjects(libObj, children);
+       }
+   }
+}
+
+
+PluginsInstaller::OptionalPluginMetafileData PluginsInstaller::parseMetafile(
+        const std::string& path) const
+{
+    LogInfo("Plugin Config file::" << path);
+    Try
+    {
+        PluginMetafileData pluginInfo;
+        PluginMetafileReader reader;
+        reader.initialize(path);
+        reader.read(pluginInfo);
+
+        FOREACH(it, pluginInfo.m_featureContainer) {
+            LogDebug("Parsed feature : " << it->m_name);
+
+            FOREACH(devCap, it->m_deviceCapabilities) {
+                LogDebug("  |  DevCap : " << *devCap);
+            }
+        }
+        return OptionalPluginMetafileData(pluginInfo);
+    }
+    Catch(ValidationCore::ParserSchemaException::Base) {
+        LogError("Error during file processing " << path);
+        ThrowMsg(PluginInstall::Exceptions::XMLFileParsingException,
+            "Parsing metafile failed");
+    }
+}
+
+std::string PluginsInstaller::getLibraryName(const std::string& dirPath) const
+{
+    std::string pluginPath = dirPath;
+    size_t indexpos = pluginPath.find_last_of('/');
+
+    if (std::string::npos == indexpos)
+    {
+        indexpos = 0;
+    }
+    else
+    {
+        indexpos += 1;  // move after '/'
+    }
+
+    std::string libName = pluginPath.substr(indexpos);
+    libName = WrtDB::GlobalConfig::GetPluginPrefix() + libName
+        + WrtDB::GlobalConfig::GetPluginSuffix();
+    LogDebug("Plugin .so: " << libName);
+    return libName;
+}
+
+bool PluginsInstaller::registerAndUpdateInstallation(
+        const WrtDB::DbPluginHandle& pluginHandle,
+        const PluginObjectsPtr& libraries)
+{
+    PluginHandleSetPtr handles = PluginHandleSetPtr(new PluginHandleSet);
+
+    DbPluginHandle handle = INVALID_PLUGIN_HANDLE;
+
+    //register requiredObjects
+    FOREACH(it, *(libraries->getDependentObjects()))
+    {
+        if (libraries->hasObject(*it)) {
+            LogDebug("Dependency from the same library. ignored");
+            continue;
+        }
+
+        handle = PluginDAO::getPluginHandleForImplementedObject(*it);
+        if (handle == INVALID_PLUGIN_HANDLE) {
+            LogError("Library implementing: " << *it << " NOT FOUND");
+            PluginDAO::setPluginInstallationStatus(
+                pluginHandle,
+                PluginDAO::INSTALLATION_WAITING);
+            return false;
+        }
+
+        handles->insert(handle);
+    }
+
+    PluginDAO::registerPluginLibrariesDependencies(pluginHandle, handles);
+
+    PluginDAO::setPluginInstallationStatus(pluginHandle,
+                                           PluginDAO::INSTALLATION_COMPLETED);
+    return true;
+}
+
+bool PluginsInstaller::fillMappingInterfaces(PluginMetafileData& pluginData,
+                                             const std::string& filename)
+{
+    void *dlHandle = dlopen(filename.c_str(), RTLD_NOW);
+    if (dlHandle == NULL) {
+        LogError("Failed to load plugin: " << filename << ". Reason: " << dlerror());
+        return false;
+    }
+    Try
+    {
+        ExportedApi* entryPoint =
+            static_cast<ExportedApi*> (dlsym(dlHandle, GetExportedSymbolName()));
+        if (NULL == entryPoint) {
+            LogError("Error: " << dlerror());
+            ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+        }
+
+        // obtain feature -> dev-cap mapping
+        feature_mapping_interface_t mappingInterface = {NULL, NULL, NULL};
+        entryPoint->GetProvidedFeatures(&mappingInterface);
+
+        if (!mappingInterface.featGetter || !mappingInterface.release ||
+            !mappingInterface.dcGetter) {
+            LogError("Failed to obtain mapping interface from .so");
+            ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+        }
+
+        feature_mapping_t* devcapMapping = mappingInterface.featGetter();
+
+        LogDebug("Getting mapping from features to device capabilities");
+
+        for (size_t i = 0; i < devcapMapping->featuresCount; ++i) {
+            PluginMetafileData::Feature feature;
+            feature.m_name = devcapMapping->features[i].feature_name;
+
+            LogDebug("Feature: " << feature.m_name);
+
+            const devcaps_t* dc =
+                mappingInterface.dcGetter(devcapMapping,
+                devcapMapping->features[i].feature_name);
+
+            LogDebug("device=cap: " << dc);
+
+            if (dc) {
+                LogDebug("devcaps count: " << dc->devCapsCount);
+
+                for (size_t j = 0; j < dc->devCapsCount; ++j) {
+                    LogDebug("devcap: " << dc->deviceCaps[j]);
+                    feature.m_deviceCapabilities.insert(dc->deviceCaps[j]);
+                }
+            }
+
+            pluginData.m_featureContainer.insert(feature);
+        }
+
+        mappingInterface.release(devcapMapping);
+    } Catch (PluginInstall::Exceptions::PluginsInstallerException)
+    {
+        LogError("Exception while feature mapping");
+        dlclose(dlHandle);
+        return false;
+    }
+
+    // Unload library
+    if (dlclose(dlHandle) != 0) {
+        LogError("Cannot close plugin handle");
+    } else {
+        LogDebug("Library is unloaded");
+    }
+    return true;
+}
+
+void PluginsInstaller::registerPluginObjects(const WrtDB::DbPluginHandle& handle,
+                                             const PluginObjectsPtr libObjects) const
+{
+        //register implemented objects
+    PluginObjects::ObjectsPtr objects =
+        libObjects->getImplementedObject();
+
+    FOREACH(it, *objects)
+    {
+        WrtDB::PluginDAO::registerPluginImplementedObject(*it, handle);
+    }
+
+    //register requiredObjects
+    objects = libObjects->getDependentObjects();
+
+    FOREACH(it, *objects)
+    {
+        if (libObjects->hasObject(*it)) {
+            LogDebug("Dependency from the same library. ignored");
+            continue;
+        }
+        WrtDB::PluginDAO::registerPluginRequiredObject(*it, handle);
+    }
+}
+
diff --git a/src/plugins-installer/plugin_installer.h b/src/plugins-installer/plugin_installer.h
new file mode 100644 (file)
index 0000000..899be3c
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2012 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    plugin_installer.h
+ * @author  Andrzej Surdej(a.surdej@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H
+#define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H
+
+#include <string>
+#include <plugin_installer_types.h>
+#include <plugin_objects.h>
+#include <IObject.h>
+#include <PluginRegistry.h>
+
+#include <dpl/singleton.h>
+
+class PluginsInstaller
+{
+public:
+    static const int INSTALLATION_ERROR;
+    enum class ReturnStatus
+    {
+        Success,                    ///< Success
+
+        NotInitialized,             ///< Singleton not initialized
+        WrongPluginPath,            ///< ?
+        MetafileError,              ///< ?
+        AlreadyInstalled,           ///< ?
+        LoadingLibraryError,        ///< Loading library by dlopen failed.
+                                    /// It may be caused by missing symbols
+        InstallationWaiting,        /// Installation failed due to dependencies
+        DatabaseError,              /// Unable to update database
+        Unknown                     ///< Temporary error. Try to not use this.
+    };
+
+    bool initialize();
+    int installAllPlugins();
+    void deinitialize();
+
+    ReturnStatus installPlugin(const std::string& libPath);
+    ReturnStatus installPluginFromMetafile(const std::string& libPath,
+                                           const std::string& metaFilePath);
+
+    int installWaitingPlugins();
+    bool resolvePluginDependencies(PluginHandle handle);
+
+    bool isInitialized();
+private:
+    friend class DPL::Singleton<PluginsInstaller>;
+
+    PluginsInstaller();
+    virtual ~PluginsInstaller();
+
+    void registerObjects(const PluginObjectsPtr& libObj,
+                         const WrtPluginsApi::IObjectsListPtr& objects) const;
+
+    typedef DPL::Optional<WrtDB::PluginMetafileData> OptionalPluginMetafileData;
+    OptionalPluginMetafileData parseMetafile(const std::string& path) const;
+
+    std::string getLibraryName(const std::string& dirPath) const;
+    bool registerAndUpdateInstallation(const PluginHandle& pluginHandle,
+                                       const PluginObjectsPtr& libraries);
+    bool fillMappingInterfaces(WrtDB::PluginMetafileData& pluginData,
+                               const std::string& filename);
+    void registerPluginObjects(const PluginHandle& handle,
+                               const PluginObjectsPtr libObjects) const;
+    void checkDatabaseTablesExistance();
+    PluginObjectsPtr loadLibraryFromMetafile(const std::string& libName) const;
+
+    WrtPluginsApi::PluginRegistry m_registry;
+    bool m_initialized;
+    bool m_reinstall;
+};
+
+typedef DPL::Singleton<PluginsInstaller> PluginsInstallerSingleton;
+
+
+#endif  /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H */
+
diff --git a/src/plugins-installer/plugin_installer_errors.h b/src/plugins-installer/plugin_installer_errors.h
new file mode 100644 (file)
index 0000000..55aa39b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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    plugin_installer_errors.h
+ * @author  Pawel Sikorski (p.sikorski@samgsung.com)
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_ERRORS_H
+#define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_ERRORS_H
+
+#include <dpl/exception.h>
+
+namespace PluginInstall {
+namespace Exceptions {
+
+DECLARE_EXCEPTION_TYPE(DPL::Exception, PluginsInstallerException)
+DECLARE_EXCEPTION_TYPE(PluginsInstallerException, LibraryException)
+DECLARE_EXCEPTION_TYPE(PluginsInstallerException, XMLFileParsingException)
+
+} //namespace
+} //namespace
+
+#endif /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_ERRORS_H */
+
diff --git a/src/plugins-installer/plugin_installer_types.h b/src/plugins-installer/plugin_installer_types.h
new file mode 100644 (file)
index 0000000..ae3a5db
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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    plugin_installer_types.h
+ * @author  Andrzej Surdej (a.surdej@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_TYPES_H
+#define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_TYPES_H
+
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+
+/* Define db type */
+typedef WrtDB::DbWidgetHandle WidgetHandle;
+typedef WrtDB::DbWidgetHandleList WidgetHandleList;
+
+typedef WrtDB::DbWidgetFeature WidgetFeature;
+typedef WrtDB::DbWidgetFeatureSet WidgetFeatureSet;
+
+typedef WrtDB::DbPluginHandle PluginHandle;
+
+#endif /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_TYPES_H */
diff --git a/src/plugins-installer/plugin_metafile_reader.cpp b/src/plugins-installer/plugin_metafile_reader.cpp
new file mode 100644 (file)
index 0000000..ac500e8
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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        plugin_metafile_reader.cpp
+ * @author      Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+
+#include "plugin_metafile_reader.h"
+
+using namespace WrtDB;
+
+namespace {
+const std::string XML_NAMESPACE = "";
+
+const std::string TOKEN_LIBRARY_NAME = "library-name";
+const std::string TOKEN_API_FEATURE = "api-feature";
+const std::string TOKEN_NAME = "name";
+const std::string TOKEN_DEVICECAPABILITY = "device-capability";
+}
+
+PluginMetafileReader::PluginMetafileReader() : m_parserSchema(this)
+{
+    m_parserSchema.addEndTagCallback(
+        TOKEN_LIBRARY_NAME,
+        XML_NAMESPACE,
+        &PluginMetafileReader::tokenEndLibraryName);
+
+    m_parserSchema.addEndTagCallback(
+        TOKEN_API_FEATURE,
+        XML_NAMESPACE,
+        &PluginMetafileReader::tokenEndApiFeature);
+
+    m_parserSchema.addEndTagCallback(
+        TOKEN_NAME,
+        XML_NAMESPACE,
+        &PluginMetafileReader::tokenEndName);
+
+    m_parserSchema.addEndTagCallback(
+        TOKEN_DEVICECAPABILITY,
+        XML_NAMESPACE,
+        &PluginMetafileReader::tokenEndDeviceCapability);
+}
+
+void PluginMetafileReader::blankFunction(PluginMetafileData & /* data */)
+{
+}
+
+void PluginMetafileReader::tokenEndLibraryName(PluginMetafileData &data)
+{
+    data.m_libraryName = m_parserSchema.getText();
+}
+
+void PluginMetafileReader::tokenEndApiFeature(PluginMetafileData &data)
+{
+    data.m_featureContainer.insert(m_feature);
+    m_feature.m_deviceCapabilities.clear();
+}
+
+void PluginMetafileReader::tokenEndName(PluginMetafileData & /* data */)
+{
+    m_feature.m_name = m_parserSchema.getText();
+}
+
+void PluginMetafileReader::tokenEndDeviceCapability(PluginMetafileData& /*data*/)
+{
+    m_feature.m_deviceCapabilities.insert(m_parserSchema.getText());
+}
+
diff --git a/src/plugins-installer/plugin_metafile_reader.h b/src/plugins-installer/plugin_metafile_reader.h
new file mode 100644 (file)
index 0000000..b0c88f0
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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        plugin_metafile_reader.h
+ * @author      Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+
+#ifndef WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_METAFILE_READER_H_
+#define WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_METAFILE_READER_H_
+
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <vcore/ParserSchema.h>
+
+class PluginMetafileReader
+{
+  public:
+    PluginMetafileReader();
+
+    void initialize(const std::string &filename)
+    {
+        m_parserSchema.initialize(filename,
+                                  true,
+                                  ValidationCore::SaxReader::VALIDATION_DTD,
+                                  std::string());
+    }
+
+    void read(WrtDB::PluginMetafileData &data)
+    {
+        m_parserSchema.read(data);
+    }
+
+  private:
+    void blankFunction(WrtDB::PluginMetafileData &data);
+
+    void tokenEndLibraryName(WrtDB::PluginMetafileData &data);
+    void tokenEndApiFeature(WrtDB::PluginMetafileData &data);
+    void tokenEndName(WrtDB::PluginMetafileData &data);
+    void tokenEndDeviceCapability(WrtDB::PluginMetafileData &data);
+
+    WrtDB::PluginMetafileData::Feature m_feature;
+
+    ValidationCore::ParserSchema<PluginMetafileReader,
+                                 WrtDB::PluginMetafileData> m_parserSchema;
+};
+
+#endif
diff --git a/src/plugins-installer/plugin_objects.cpp b/src/plugins-installer/plugin_objects.cpp
new file mode 100644 (file)
index 0000000..2ded4f5
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * 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    plugin_objects.h
+ * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#include <string>
+#include <dpl/log/log.h>
+#include "plugin_objects.h"
+#include <IObject.h>
+
+namespace {
+const char* SEPARATOR = ".";
+const std::string GLOBAL_OBJECT_NAME = WrtPluginsApi::IObject::WINDOW_OBJECT();
+const std::string OLD_GLOBAL_OBJECT_NAME = "GLOBAL_OBJECT";
+
+std::string normalizeName(const std::string& objectName)
+{
+    if (objectName.empty()) {
+        LogError("Normalize name, name size is 0");
+        return objectName;
+    }
+
+    if (!objectName.compare(0, GLOBAL_OBJECT_NAME.size(),
+                            GLOBAL_OBJECT_NAME)) {
+        return objectName;
+    }
+    if (!objectName.compare(0, OLD_GLOBAL_OBJECT_NAME.size(),
+        OLD_GLOBAL_OBJECT_NAME))
+    {
+        return GLOBAL_OBJECT_NAME;
+    }
+
+    //each object in storage has name started from $GLOBAL_OBJECT_NAME$
+    return GLOBAL_OBJECT_NAME + std::string(SEPARATOR) + objectName;
+}
+
+std::string normalizeName(const std::string& objectName,
+        const std::string& parentName)
+{
+    if (objectName.empty() || parentName.empty()) {
+        LogError("Normalize name, name size or parent name size is 0");
+        return std::string();
+    }
+
+    std::string normalizedName;
+    normalizedName = normalizeName(parentName) +
+        std::string(SEPARATOR) + objectName;
+
+    return normalizedName;
+}
+}
+
+PluginObjects::PluginObjects()
+{
+    m_implemented = ObjectsPtr(new Objects());
+    m_dependent = ObjectsPtr(new Objects());
+}
+
+PluginObjects::ObjectsPtr PluginObjects::getImplementedObject() const
+{
+    return m_implemented;
+}
+
+PluginObjects::ObjectsPtr PluginObjects::getDependentObjects() const
+{
+    return m_dependent;
+}
+
+void PluginObjects::addObjects(const std::string& parentName,
+        const std::string& name)
+{
+    LogDebug("\n Parent: "  << parentName
+             << "\n Name: " << name
+            << "\n After: Implemented: "  << normalizeName(name, parentName)
+             << "\n After Dependent: " << normalizeName(parentName)
+             );
+
+    addImplementedObject(normalizeName(name, parentName));
+    addDependentObject(normalizeName(parentName));
+}
+
+void PluginObjects::addDependentObject(const std::string& value)
+{
+    if (!value.compare(GLOBAL_OBJECT_NAME)) {
+        //dont add dependency to GLOBAL_OBJECT
+        return;
+    }
+    m_dependent->insert(value);
+}
+
+bool PluginObjects::hasObject(const std::string& name) const
+{
+    return m_implemented->find(name) != m_implemented->end();
+}
+
+void PluginObjects::addImplementedObject(const std::string& value)
+{
+    m_implemented->insert(value);
+}
diff --git a/src/plugins-installer/plugin_objects.h b/src/plugins-installer/plugin_objects.h
new file mode 100644 (file)
index 0000000..c4cda28
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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        plugin_objects.h
+ * @author      Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version     1.0
+ * @brief
+ */
+
+#ifndef WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_OBJECTS_H_
+#define WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_OBJECTS_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <set>
+#include <list>
+
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+//TODO TO BE MOVED SOMEWHERE ELSE
+// AS OTHER MODULES (LIKE DAO) USE IT
+
+class PluginObjects : public WrtDB::PluginObjectsDAO
+{
+  public:
+    explicit PluginObjects();
+
+    //getters for objects from library
+    ObjectsPtr getImplementedObject() const;
+    ObjectsPtr getDependentObjects() const;
+
+    //add object declaration
+    void addObjects(const std::string& parentName,
+            const std::string& name);
+
+    //check if library implemements object given as name
+    bool hasObject(const std::string& name) const;
+
+  private:
+    void addImplementedObject(const std::string& value);
+    void addDependentObject(const std::string& value);
+};
+
+typedef DPL::SharedPtr<PluginObjects> PluginObjectsPtr;
+
+#endif
diff --git a/src/plugins-installer/plugin_utils.cpp b/src/plugins-installer/plugin_utils.cpp
new file mode 100644 (file)
index 0000000..dbf50ae
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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    plugin-utils.cpp
+ * @author
+ * @version 1.0
+ * @brief   Header file for plugin util
+ */
+
+#include "plugin_utils.h"
+#include <dpl/semaphore.h>
+#include <dpl/exception.h>
+#include <dpl/log/log.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+using namespace WrtDB;
+
+namespace PluginUtils {
+
+//checks if file exists and is regular file
+bool checkFileExistance(const std::string& filename)
+{
+    struct stat tmp;
+
+    if (0 == stat(filename.c_str(), &tmp) && S_ISREG(tmp.st_mode)) {
+        return true;
+    }
+    return false;
+}
+
+std::string cutOffFileName(const std::string& path) {
+    size_t found = path.find_last_of("/");
+    if (found == std::string::npos) {
+        return path;
+    } else {
+        return path.substr(0, found);
+    }
+}
+
+bool checkPath(const std::string& path) {
+    struct stat st;
+    if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
+        return true;
+    }
+    LogError("Cannot access directory [ " << path << " ]");
+    return false;
+}
+
+bool checkPaths()
+{
+    bool if_ok = true;
+    if_ok &= (checkPath(cutOffFileName(
+            GlobalConfig::GetWrtDatabaseFilePath())));
+    if (!if_ok) {
+        LogError(
+                "Path <" << GlobalConfig::GetWrtDatabaseFilePath() <<
+                "> does not exist.");
+    }
+
+    if_ok &= (checkPath(GlobalConfig::GetDevicePluginPath()));
+    if (!if_ok) {
+        LogError(
+                "Path <" << GlobalConfig::GetDevicePluginPath() <<
+                "> does not exist.");
+    }
+
+    if_ok &= (checkPath(GlobalConfig::GetUserInstalledWidgetPath()));
+    if (!if_ok) {
+        LogError(
+                "Path <" << GlobalConfig::GetUserInstalledWidgetPath() <<
+                "> does not exist.");
+    }
+    return if_ok;
+}
+
+} //namespace PluginUtils
diff --git a/src/plugins-installer/plugin_utils.h b/src/plugins-installer/plugin_utils.h
new file mode 100755 (executable)
index 0000000..3109ab3
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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    plugin-utils.h
+ * @author
+ * @version 1.0
+ * @brief   Header file for plugin util
+ */
+#ifndef PLUGIN_UTILS_H
+#define PLUGIN_UTILS_H
+
+#include <string>
+#include <sys/stat.h>
+
+namespace PluginUtils {
+
+bool checkFileExistance(const std::string& filename);
+
+std::string cutOffFileName(const std::string& path);
+bool checkPath(const std::string& path);
+bool checkPaths();
+
+}
+#endif // PLUGIN_UTILS_H
diff --git a/src/plugins-installer/wrt_plugins_installer.cpp b/src/plugins-installer/wrt_plugins_installer.cpp
new file mode 100644 (file)
index 0000000..5f78b72
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012 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    wrt_plugins_installer.cpp
+ * @author  Andrzej Surdej(a.surdej@gmail.com)
+ * @version 1.0
+ * @brief   Main file for plugins installer
+ */
+
+#include <plugin_installer.h>
+#include <dpl/log/log.h>
+#include <string>
+#include <cstdio>
+
+int main(int argc, char *argv[])
+{
+    DPL::Log::LogSystemSingleton::Instance().SetTag("PLUGINS_INSTALLER");
+    LogInfo("Plugins installation started.");
+
+    printf("Installing plugins...\n");
+    PluginsInstallerSingleton::Instance().initialize();
+    int installed =
+        PluginsInstallerSingleton::Instance().installAllPlugins();
+    PluginsInstallerSingleton::Instance().deinitialize();
+    printf("Completed: %d plugins installed.\n", installed);
+
+    LogInfo("All plugins installed successfuly");
+    return 0;
+}
diff --git a/src/standards/CMakeLists.txt b/src/standards/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6bab9bf
--- /dev/null
@@ -0,0 +1,19 @@
+# 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.
+#
+set(STANDARD_FILE_DESTINATION /usr/lib/wrt-plugins)
+
+add_subdirectory(W3C)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/standard-features-list DESTINATION ${STANDARD_FILE_DESTINATION})
diff --git a/src/standards/W3C/CMakeLists.txt b/src/standards/W3C/CMakeLists.txt
new file mode 100644 (file)
index 0000000..11828fb
--- /dev/null
@@ -0,0 +1,15 @@
+# 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.
+#
+add_subdir(Widget)
diff --git a/src/standards/W3C/DESCRIPTION b/src/standards/W3C/DESCRIPTION
new file mode 100644 (file)
index 0000000..8e32c7b
--- /dev/null
@@ -0,0 +1,2 @@
+!!!options!!! stop
+W3C plugin - Widget Interface
diff --git a/src/standards/W3C/Widget/CMakeLists.txt b/src/standards/W3C/Widget/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..e6ab932
--- /dev/null
@@ -0,0 +1,47 @@
+# 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.
+#
+set(TARGET_NAME "wrt-plugins-w3c-widget-interface")
+
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+pkg_search_module(plugin-types REQUIRED wrt-plugins-types)
+
+set(SRCS
+  ${SRCS_COMMONS}
+  JSWidget.cpp
+  JSPreferences.cpp
+  plugin_initializer.cpp
+  plugin_config.cpp
+)
+
+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})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${TARGET_COMMONS}
+  ${TARGET_COMMONS_JAVASCRIPT}
+  ${TARGET_JS_OVERLAY}
+  wrt-plugins-widget
+  wrt-plugins-localstorage
+  wrt-plugins-storageevent
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${STANDARD_FILE_DESTINATION}/w3c-widget-interface)
diff --git a/src/standards/W3C/Widget/JSPreferences.cpp b/src/standards/W3C/Widget/JSPreferences.cpp
new file mode 100644 (file)
index 0000000..c461fc8
--- /dev/null
@@ -0,0 +1,561 @@
+/*
+ * 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        JSPreferences.cpp
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ */
+
+#include "JSPreferences.h"
+
+#include <string>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <dpl/optional.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <StorageEvent/StorageEventMgr.h>
+#include <StorageEvent/IStorageEvent.h>
+#include <js-overlay/js_iframe_support.h>
+#include <js-overlay/js_overlay_addEventListener.h>
+
+using namespace std;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::LocalStorage::Api;
+using namespace WrtDeviceApis::StorageEvent::Api;
+
+#define PREFERENCES_PLUGIN_NAME       "preferences"
+#define LOCAL_STORAGE_PROPERTY_LENGTH "length"
+
+#define CATCH_EXCEPTION_NO_MODIFABLE \
+    Catch(Commons::LocalStorageValueNoModifableException) {\
+        LogError("The item is read only");\
+        return JSDOMExceptionFactory::\
+            NoModificationAllowedException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_CONVERSION \
+    Catch(Commons::ConversionException) {\
+        LogError("Error on conversion");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_NULL_PTR \
+    Catch(Commons::NullPointerException) {\
+        LogError("Error on pointer, null value");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_PLATFORM_ERROR \
+    Catch(Commons::PlatformException){\
+        LogError("PlatformException occured");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_SECURITY \
+    Catch(Commons::SecurityException){\
+        LogError("Security exception occured");\
+        return JSDOMExceptionFactory::\
+            SecurityException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_OUT_OF_RANGE \
+    Catch(Commons::OutOfRangeException) {\
+        LogError("OutOfRangeException");\
+        return JSDOMExceptionFactory::\
+            QuotaExceededException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_INVALID_ARG \
+    Catch(Commons::InvalidArgumentException) {\
+        LogError("Pair for given key doesnt exist");\
+        return JSValueMakeNull(context);\
+    }
+
+namespace WrtPlugins {
+namespace W3C {
+
+
+ILocalStoragePtr getIStorage(JSObjectRef arg)
+{
+    LogWarning("get localstorage object");
+
+    LocalStoragePrivateData* priv =
+        static_cast<LocalStoragePrivateData*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+
+    return priv->istorage;
+}
+
+JSObjectRef getWidgetObject(JSObjectRef arg)
+{
+    LogWarning("get widget object");
+
+    LocalStoragePrivateData* priv =
+        static_cast<LocalStoragePrivateData*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+
+    return priv->widgetObject;
+
+}
+
+enum class ModificationType{
+    RemoveItem,
+    SetItem
+};
+
+//this function may throw exceptions
+IStorageEventPtr modifyItemAndCreateEvent(ModificationType type,
+                                          JSObjectRef thisObject,
+                                          const string& key,
+                                          const string& value = std::string())
+{
+    DPL::Optional<std::string> oldValue =
+        getIStorage(thisObject)->getValue(key);
+
+    if (ModificationType::SetItem == type)
+    {
+        getIStorage(thisObject)->setItem(key, value, false);
+    }
+    else if (ModificationType::RemoveItem == type)
+    {
+        getIStorage(thisObject)->removeItem(key);
+    }
+    else
+    {
+        Assert(0 && "Wrong Modification type");
+    }
+
+    DPL::Optional<std::string> newValue =
+        getIStorage(thisObject)->getValue(key);
+
+    //create event object
+    IStorageEventPtr storageEvent = getStorageEvent();
+
+    //key
+    storageEvent->setKey(key);
+    //oldvalue
+    if (!!oldValue) { storageEvent->setOldValue(*oldValue); }
+    //newValue
+    if(!!newValue){ storageEvent->setNewValue(*newValue); }
+
+    return storageEvent;
+}
+
+
+JSClassDefinition JSPreferences::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    PREFERENCES_PLUGIN_NAME,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    hasProperty,
+    getProperty,
+    setProperty,
+    NULL,//DeleteProperty,
+    NULL,//GetPropertyNames,
+    NULL,//CallAsFunction,
+    NULL,//CallAsConstructor,
+    NULL,//HasInstance,
+    NULL,//ConvertToType,
+};
+
+JSStaticFunction JSPreferences::m_function[] = {
+    { "setItem", JSPreferences::setItem, kJSPropertyAttributeNone },
+    { "removeItem", JSPreferences::removeItem, kJSPropertyAttributeNone },
+    { "getItem", JSPreferences::getItem, kJSPropertyAttributeNone },
+    { "clear", JSPreferences::clear, kJSPropertyAttributeNone },
+    { "key", JSPreferences::key, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+JSStaticValue JSPreferences::m_property[] =
+{
+    {LOCAL_STORAGE_PROPERTY_LENGTH,
+        JSPreferences::getLength,
+        NULL,
+        kJSPropertyAttributeReadOnly},
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSPreferences::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSPreferences::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSPreferences::m_jsClassRef =
+    JSClassCreate(JSPreferences::getClassInfo());
+
+void JSPreferences::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    LogDebug("entered. Context: " << context);
+
+    LocalStoragePrivateData* priv =
+      static_cast<LocalStoragePrivateData*>(JSObjectGetPrivate(object));
+
+    Assert(priv && "private object of preferences is NULL");
+}
+
+void JSPreferences::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    LocalStoragePrivateData* priv =
+      static_cast<LocalStoragePrivateData*>(JSObjectGetPrivate(object));
+
+    delete priv;
+    LogDebug("private object is realised");
+}
+
+JSValueRef JSPreferences::removeItem(JSContextRef context,
+                                     JSObjectRef object,
+                                     JSObjectRef thisObject,
+                                     size_t argumentCount,
+                                     const JSValueRef arguments[],
+                                     JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try {
+        Converter converter(context);
+
+        std::string key = converter.toString(arguments[0]);
+
+        auto event = modifyItemAndCreateEvent(ModificationType::RemoveItem,
+                                              thisObject,
+                                              key);
+
+        auto iframe = IFrameSupport::
+            getIFrameObjectForWidget(getWidgetObject(thisObject));
+
+        Assert(iframe && "Iframe is NULL");
+
+        AddEventListenerSupport::
+            CallStorageListenersFromDifferentIFrames(iframe, event);
+
+        LogDebug("end");
+        return JSValueMakeNull(context);
+    }
+    CATCH_EXCEPTION_NO_MODIFABLE
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSPreferences::setItem(JSContextRef context,
+                                  JSObjectRef object,
+                                  JSObjectRef thisObject,
+                                  size_t argumentCount,
+                                  const JSValueRef arguments[],
+                                  JSValueRef* exception)
+{
+    LogDebug("entered");
+    LogDebug("This: " << thisObject);
+    LogDebug("Object: " << object);
+
+    Try {
+        Converter converter(context);
+
+        std::string key = converter.toString(arguments[0]);
+        std::string value = converter.tryString(arguments[1]);
+
+        auto event = modifyItemAndCreateEvent(ModificationType::SetItem,
+                                              thisObject,
+                                              key,
+                                              value);
+
+        auto iframe = IFrameSupport::
+            getIFrameObjectForWidget(getWidgetObject(thisObject));
+        Assert(iframe && "Iframe is NULL");
+
+        AddEventListenerSupport::
+            CallStorageListenersFromDifferentIFrames(iframe, event);
+
+        LogDebug("end");
+
+        return JSValueMakeUndefined(context);
+    }
+    CATCH_EXCEPTION_NO_MODIFABLE
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+    CATCH_EXCEPTION_OUT_OF_RANGE
+}
+
+
+JSValueRef JSPreferences::clear(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try {
+        getIStorage(thisObject)->clear(false);
+
+
+        auto iframe = IFrameSupport::
+            getIFrameObjectForWidget(getWidgetObject(thisObject));
+
+        Assert(iframe && "Iframe is NULL");
+
+        //create event object
+        IStorageEventPtr storageEvent = getStorageEvent();
+
+        AddEventListenerSupport::
+            CallStorageListenersFromDifferentIFrames(iframe, storageEvent);
+
+        LogDebug("end");
+
+        return JSValueMakeNull(context);
+    }
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSPreferences::getItem(JSContextRef context,
+                                  JSObjectRef object,
+                                  JSObjectRef thisObject,
+                                  size_t argumentCount,
+                                  const JSValueRef arguments[],
+                                  JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try {
+        Converter converter(context);
+
+        std::string key = converter.tryString(arguments[0]);
+
+        LogDebug("Getting item for key " << key);
+
+        DPL::Optional<std::string> value =
+            getIStorage(thisObject)->getValue(key);
+
+        if (!value)
+            return JSValueMakeNull(context);
+        else
+            return converter.toJSValueRef(*value);
+    }
+    CATCH_EXCEPTION_INVALID_ARG
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+}
+
+JSValueRef JSPreferences::key(JSContextRef context,
+                              JSObjectRef object,
+                              JSObjectRef thisObject,
+                              size_t argumentCount,
+                              const JSValueRef arguments[],
+                              JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try{
+        if (argumentCount<1) {
+            LogError("No argument found");
+            Throw(Commons::InvalidArgumentException);
+        }
+
+        Converter converter(context);
+
+        size_t n = converter.toSizeT(arguments[0]);
+
+        std::string value = getIStorage(thisObject)->getKeyByIndex(n);
+
+        LogDebug("end");
+
+        return converter.toJSValueRef(value);
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+    CATCH_EXCEPTION_INVALID_ARG
+}
+
+JSValueRef JSPreferences::getLength(JSContextRef context,
+                                    JSObjectRef object,
+                                    JSStringRef propertyName,
+                                    JSValueRef* exception)
+{
+    LogDebug("enter");
+
+    Try
+    {
+        Converter converter(context);
+
+        size_t value = getIStorage(object)->getStorageSize();
+        return converter.toJSValueRef(value);
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+    CATCH_EXCEPTION_INVALID_ARG
+}
+
+bool JSPreferences::hasProperty(JSContextRef context,
+                           JSObjectRef object,
+                           JSStringRef propertyName)
+{
+    LogDebug("enter");
+
+    Try{
+        Converter converter(context);
+
+        std::string key = converter.toString(propertyName);
+
+        if(!getIStorage(object)->getValue(key)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    Catch(Commons::InvalidArgumentException) {
+        LogDebug("Pair for given key doesnt exist");
+    }
+
+    Catch(Commons::ConversionException) {
+        LogError("Error on conversion");
+    }
+
+    Catch(Commons::NullPointerException) {
+        LogError("Error on pointer, null value");
+    }
+
+    Catch(Commons::PlatformException){
+        LogError("PlatformException occured");
+    }
+    return false;
+}
+
+JSValueRef JSPreferences::getProperty(JSContextRef context,
+                                      JSObjectRef object,
+                                      JSStringRef propertyName,
+                                      JSValueRef* exception)
+{
+    LogDebug("enter");
+
+    Try{
+        Converter converter(context);
+
+        std::string key = converter.toString(propertyName);
+
+        DPL::Optional<std::string> value =
+            getIStorage(object)->getValue(key);
+
+        LogDebug("end");
+
+        if (!value)
+            return JSValueMakeNull(context);
+        else
+            return converter.toJSValueRef(*value);
+    }
+
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_INVALID_ARG
+}
+
+bool JSPreferences::setProperty(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef jvalue,
+                                JSValueRef* exception)
+{
+    LogDebug("enter");
+
+    Try{
+        Converter converter(context);
+
+        std::string key = converter.toString(propertyName);
+        std::string value = converter.toString(jvalue);
+
+        auto event = modifyItemAndCreateEvent(ModificationType::SetItem,
+                                              object,
+                                              key,
+                                              value);
+
+        auto iframe = IFrameSupport::
+            getIFrameObjectForWidget(getWidgetObject(object));
+        Assert(iframe && "Iframe is NULL");
+
+        AddEventListenerSupport::
+            CallStorageListenersFromDifferentIFrames(iframe, event);
+
+        LogDebug("end");
+
+        return true;
+    }
+    CATCH_EXCEPTION_NO_MODIFABLE
+    CATCH_EXCEPTION_OUT_OF_RANGE
+    CATCH_EXCEPTION_INVALID_ARG
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+    CATCH_EXCEPTION_SECURITY
+
+    return false;
+}
+
+#undef CATCH_EXCEPTION_NO_MODIFABLE
+#undef CATCH_EXCEPTION_CONVERSION
+#undef CATCH_EXCEPTION_NULL_PTR
+#undef CATCH_EXCEPTION_PLATFORM_ERROR
+#undef CATCH_EXCEPTION_SECURITY
+#undef CATCH_EXCEPTION_OUT_OF_RANGE
+#undef CATCH_EXCEPTION_INVALID_ARG
+
+}
+}
diff --git a/src/standards/W3C/Widget/JSPreferences.h b/src/standards/W3C/Widget/JSPreferences.h
new file mode 100644 (file)
index 0000000..c91d4c5
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * 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       JSPreferences.h
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_WIDGET_PREFERENCES_H_
+#define _WRT_PLUGIN_JS_WIDGET_PREFERENCES_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <LocalStorage/ILocalStorage.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+struct LocalStoragePrivateData{
+    WrtDeviceApis::LocalStorage::Api::ILocalStoragePtr istorage;
+    //parent
+    JSObjectRef widgetObject;
+};
+
+class JSPreferences
+{
+public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static const JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context, JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * This structure contains properties and callbacks
+     * that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function.
+     */
+    static JSStaticFunction m_function[];
+
+    static JSStaticValue m_property[];
+
+    static JSClassRef m_jsClassRef;
+
+    //Modified functions for Preference object
+    static JSValueRef removeItem(JSContextRef context, JSObjectRef object,
+                                 JSObjectRef thisObject, size_t argumentCount,
+                                 const JSValueRef arguments[],
+                                 JSValueRef* exception);
+
+    static JSValueRef setItem(JSContextRef context, JSObjectRef object,
+                              JSObjectRef thisObject, size_t argumentCount,
+                              const JSValueRef arguments[],
+                              JSValueRef* exception);
+
+    static JSValueRef getItem(JSContextRef context, JSObjectRef object,
+                              JSObjectRef thisObject, size_t argumentCount,
+                              const JSValueRef arguments[],
+                              JSValueRef* exception);
+
+    static JSValueRef clear(JSContextRef context, JSObjectRef object,
+                            JSObjectRef thisObject, size_t argumentCount,
+                            const JSValueRef arguments[],
+                            JSValueRef* exception);
+
+    static JSValueRef key(JSContextRef context, JSObjectRef object,
+                          JSObjectRef thisObject, size_t argumentCount,
+                          const JSValueRef arguments[],
+                          JSValueRef* exception);
+
+    static JSValueRef getLength(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef* exception);
+
+    static bool hasProperty(JSContextRef context,
+                            JSObjectRef object,
+                            JSStringRef propertyName);
+
+    static JSValueRef getProperty(JSContextRef context,
+                                  JSObjectRef object,
+                                  JSStringRef propertyName,
+                                  JSValueRef* exception);
+
+    static bool setProperty(JSContextRef context,
+                            JSObjectRef object,
+                            JSStringRef propertyName,
+                            JSValueRef value,
+                            JSValueRef* exception);
+
+};
+}
+}
+
+#endif
diff --git a/src/standards/W3C/Widget/JSWidget.cpp b/src/standards/W3C/Widget/JSWidget.cpp
new file mode 100644 (file)
index 0000000..9daec95
--- /dev/null
@@ -0,0 +1,582 @@
+/*
+ * 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        JSWidget.cpp
+ * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version     0.1
+ */
+
+#include "JSWidget.h"
+#include <memory>
+#include <CommonsJavaScript/Converter.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Widget/WidgetFactory.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include "JSPreferences.h"
+#include <Widget/IWidget.h>
+#include <LocalStorage/LocalStorageMgr.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <js-overlay/js_iframe_support.h>
+
+
+#define CATCH_EXCEPTION_NO_MODIFABLE \
+    Catch(Commons::LocalStorageValueNoModifableException) {\
+        LogError("The item is read only");\
+        return JSDOMExceptionFactory::\
+            NoModificationAllowedException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_CONVERSION \
+    Catch(Commons::ConversionException) {\
+        LogError("Error on conversion");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_NULL_PTR \
+    Catch(Commons::NullPointerException) {\
+        LogError("Error on pointer, null value");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_PLATFORM_ERROR \
+    Catch(Commons::PlatformException){\
+        LogError("PlatformException occured");\
+        return JSDOMExceptionFactory::\
+            UnknownException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_SECURITY \
+    Catch(Commons::SecurityException){\
+        LogError("Security exception occured");\
+        return JSDOMExceptionFactory::\
+            SecurityException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_OUT_OF_RANGE \
+    Catch(Commons::OutOfRangeException) {\
+        LogError("OutOfRangeException");\
+        return JSDOMExceptionFactory::\
+            QuotaExceededException.make(context, exception);\
+    }
+
+#define CATCH_EXCEPTION_INVALID_ARG \
+    Catch(Commons::InvalidArgumentException) {\
+        LogError("Pair for given key doesnt exist");\
+        return JSValueMakeNull(context);\
+    }
+
+#define WIDGET_PLUGIN_NAME "Widget"
+
+#define WRT_WIDGET_PROPERTY_AUTHOR       "author"
+#define WRT_WIDGET_PROPERTY_AUTHOR_EMAIL "authorEmail"
+#define WRT_WIDGET_PROPERTY_AUTHOR_HREF  "authorHref"
+#define WRT_WIDGET_PROPERTY_DESCRIPTION  "description"
+#define WRT_WIDGET_PROPERTY_ID           "id"
+#define WRT_WIDGET_PROPERTY_NAME         "name"
+#define WRT_WIDGET_PROPERTY_SHORT_NAME   "shortName"
+#define WRT_WIDGET_PROPERTY_VERSION      "version"
+#define WRT_WIDGET_PROPERTY_HEIGHT       "height"
+#define WRT_WIDGET_PROPERTY_WIDTH        "width"
+
+namespace WrtPlugins {
+namespace W3C {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Widget;
+
+
+struct WidgetPrivateObject
+{
+    Widget::Api::IWidgetPtr iwidget;
+    JSObjectRef preferencesObject;
+    //TEMP
+    int widgetId;
+    JSObjectRef widgetObject;
+};
+typedef std::shared_ptr<WidgetPrivateObject> WidgetPrivateObjectPtr;
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT
+    <WidgetPrivateObjectPtr>::Type JSWidgetPrivateObject;
+
+WrtDeviceApis::Widget::Api::IWidgetPtr getIWidget(JSObjectRef arg)
+{
+    JSWidgetPrivateObject* priv =
+        static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+
+    return priv->getObject()->iwidget;
+}
+
+
+LocalStorage::Api::ILocalStoragePtr getLocalStorage(int widgetId)
+{
+    LocalStorage::Api::ILocalStoragePtr storage(
+        LocalStorage::Api::getLocalStorage(widgetId));
+
+    return storage;
+}
+
+JSObjectRef getPreferences(JSObjectRef arg)
+{
+    JSWidgetPrivateObject* priv =
+        static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(arg));
+
+    if (!priv) {
+        LogError("Private object not initialized");
+        return NULL;
+    }
+
+    return priv->getObject()->preferencesObject;
+}
+
+JSObjectRef createPreferencesObject(JSContextRef context,
+                                    JSObjectRef widgetObject,
+                                    int widgetId)
+{
+    Assert(widgetObject && "Widget Object can'n be null");
+    //delete is invoked in JSPreferences::finalize
+    LocalStoragePrivateData* priv = new LocalStoragePrivateData;
+    Assert(priv && "Private data is null");
+    priv->istorage = getLocalStorage(widgetId);
+    priv->widgetObject = widgetObject;
+
+    JSObjectRef preferences = JSObjectMake(context,
+                                           JSPreferences::getClassRef(),
+                                           priv);
+
+    if(!preferences){
+        LogError("Preferences object is null");
+        delete priv;
+    }
+    //Unprotect is called in JSWidget::finalize
+    JSValueProtect(context, preferences);
+
+    return preferences;
+};
+
+
+JSClassDefinition JSWidget::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    WIDGET_PLUGIN_NAME,
+    0,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    hasProperty,
+    getProperty,
+    setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    callAsConstructor,
+    NULL, //HasInstance,
+    NULL, //ConvertToType,
+};
+
+JSStaticValue JSWidget::m_property[] = {
+    { WRT_WIDGET_PROPERTY_AUTHOR, JSWidget::getAuthor,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_AUTHOR_EMAIL, JSWidget::getAuthorEmail,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_AUTHOR_HREF, JSWidget::getAuthorHref,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_DESCRIPTION, JSWidget::getDescription,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_ID, JSWidget::getId,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_NAME, JSWidget::getName,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_SHORT_NAME, JSWidget::getShortName,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_VERSION, JSWidget::getVersion,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_HEIGHT, JSWidget::getHeight,
+      0, kJSPropertyAttributeReadOnly },
+    { WRT_WIDGET_PROPERTY_WIDTH, JSWidget::getWidth,
+      0, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSWidget::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSWidget::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSWidget::m_jsClassRef = JSClassCreate(JSWidget::getClassInfo());
+
+JSContextRef JSWidget::m_globalContext = NULL;
+
+void JSWidget::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    LogDebug("entered. Context : " << context);
+    LogDebug("Object: " << object);
+
+    JSWidgetPrivateObject* priv =
+        static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
+
+    if (!priv) {
+        LogDebug("creation private object");
+
+        Try {
+            using namespace WrtDeviceApis::Commons;
+
+            Widget::Api::IWidgetPtr widget =
+                Api::WidgetFactory::createWidget();
+            int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+            JSObjectRef preferences =
+                createPreferencesObject(context,
+                                        object,
+                                        widgetId);
+            if(!preferences){
+                LogError("Failed to create preferences object");
+            }
+
+            WidgetPrivateObjectPtr widgetPriv(new WidgetPrivateObject);
+            widgetPriv->iwidget = widget;
+            widgetPriv->preferencesObject = preferences;
+
+            priv = new JSWidgetPrivateObject(context, widgetPriv);
+            JSObjectSetPrivate(object, priv);
+            LogDebug("private object created");
+
+        }
+        Catch(Commons::InvalidArgumentException){
+            LogError("You should register widget id in ON_WIDGET_START");
+            return;
+        }
+        Catch(DPL::Exception) {
+            LogError("Failed to create private object for JSWidget");
+            return;
+        }
+
+    }
+}
+
+void JSWidget::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    LogDebug("Object: " << object);
+    JSWidgetPrivateObject* priv =
+        static_cast<JSWidgetPrivateObject*>(JSObjectGetPrivate(object));
+
+    if (priv) {
+        JSValueUnprotect(priv->getContext(),
+                         priv->getObject()->preferencesObject);
+
+        delete priv;
+        LogDebug("private object is released");
+    } else {
+        LogDebug("private object wasn't created");
+    }
+}
+
+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<JSContextRef>(global_context);
+        LogInfo("Global context acquired.");
+    } else {
+        LogInfo("Global context already set.");
+    }
+}
+
+JSValueRef JSWidget::getAuthor(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getAuthor());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getAuthorEmail(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getAuthorEmail());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getAuthorHref(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getAuthorHref());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getDescription(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getDescription());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getId());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getName(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getName());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getShortName(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getShortName());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getVersion(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        return converter.toJSValueRef(getIWidget(object)->getVersion());
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getHeight(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        unsigned int height = getIWidget(object)->getHeight();
+        if (0 == height) {
+            height = 1;
+        }
+        return converter.toJSValueRef(height);
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+JSValueRef JSWidget::getWidth(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try {
+        Converter converter(context);
+        unsigned int width = getIWidget(object)->getWidth();
+        if (0 == width) {
+            width = 1;
+        }
+        return converter.toJSValueRef(width);
+    }
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_PLATFORM_ERROR
+}
+
+bool JSWidget::hasProperty(JSContextRef context,
+                           JSObjectRef object,
+                           JSStringRef propertyName)
+{
+    LogDebug("enter");
+
+    Try{
+        Converter converter(context);
+
+        std::string key = converter.toString(propertyName);
+        if (key == "preferences") {
+            return true;
+        }
+    }
+    Catch(Commons::InvalidArgumentException) {
+        LogDebug("Pair for given key doesnt exist");
+    }
+
+    Catch(Commons::ConversionException) {
+        LogError("Error on conversion");
+    }
+
+    Catch(Commons::NullPointerException) {
+        LogError("Error on pointer, null value");
+    }
+
+    Catch(Commons::PlatformException){
+        LogError("PlatformException occured");
+    }
+    return false;
+}
+
+JSValueRef JSWidget::getProperty(JSContextRef context,
+                                 JSObjectRef object,
+                                 JSStringRef propertyName,
+                                 JSValueRef* exception)
+{
+    LogDebug("Object: " << object);
+
+    Try {
+        Converter converter(context);
+
+        std::string key = converter.toString(propertyName);
+
+        if (key=="preferences") {
+            Converter converter(context);
+            JSObjectRef pref = getPreferences(object);
+            if (!pref)
+            {
+                LogError("Preferences object is NULL");
+                return JSValueMakeUndefined(context);
+            }
+            return pref;
+        }
+        LogError("Property NOT supported: " << propertyName);
+        return JSValueMakeUndefined(context);
+    }
+
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+    CATCH_EXCEPTION_INVALID_ARG
+}
+
+bool JSWidget::setProperty(JSContextRef context,
+                           JSObjectRef object,
+                           JSStringRef propertyName,
+                           JSValueRef jvalue,
+                           JSValueRef* exception)
+{
+    LogDebug("enter");
+
+    Try{
+        Converter converter(context);
+
+        std::string key = converter.toString(propertyName);
+        if (key == "preferences"){
+            LogError("Object is read only");
+            return true;
+        }
+    }
+    CATCH_EXCEPTION_INVALID_ARG
+    CATCH_EXCEPTION_CONVERSION
+    CATCH_EXCEPTION_NULL_PTR
+
+    return false;
+}
+
+JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
+                                        JSObjectRef constructor,
+                                        size_t argumentCount,
+                                        const JSValueRef arguments[],
+                                        JSValueRef* exception)
+{
+    LogDebug("widget constructor");
+    if (!m_globalContext) {
+        LogError("Global context not set. Creating 'widget' object with "
+                "local context!");
+        return JSObjectMake(context, JSWidget::getClassRef(), NULL);
+    }
+    return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
+}
+
+#undef CATCH_EXCEPTION_NO_MODIFABLE
+#undef CATCH_EXCEPTION_CONVERSION
+#undef CATCH_EXCEPTION_NULL_PTR
+#undef CATCH_EXCEPTION_PLATFORM_ERROR
+#undef CATCH_EXCEPTION_SECURITY
+#undef CATCH_EXCEPTION_OUT_OF_RANGE
+#undef CATCH_EXCEPTION_INVALID_ARG
+
+}
+}
diff --git a/src/standards/W3C/Widget/JSWidget.h b/src/standards/W3C/Widget/JSWidget.h
new file mode 100644 (file)
index 0000000..3be203a
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * 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       JSWidget.h
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_WIDGET_H_
+#define _WRT_PLUGIN_JS_WIDGET_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <wrt_plugin_export.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+
+class JSWidget
+{
+  public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static const JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+    static JSObjectRef callAsConstructor(JSContextRef context,
+                                         JSObjectRef constructor,
+                                         size_t argumentCount,
+                                         const JSValueRef arguments[],
+                                         JSValueRef* exception);
+
+    /**
+     * This function will acquire global context which is used later to
+     * keep JSValueProtect/Unprotect functionality working.
+     * This is workaround for JSCore semantic: when an object is created with
+     * JSObjectMakeConstructor a context passed to createCallback function
+     * is different (shorter lifecycle) than global context, so JSValueUnprotect
+     * called in finalize may fail because of invalid context.
+     */
+    static void acquireGlobalContext(java_script_context_t global_context,
+            js_object_instance_t iframe,
+            js_object_instance_t object);
+
+  private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context,
+            JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_property[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_jsClassRef;
+
+    /**
+     * Global context acquired by acquireGlobalContext() function.
+     */
+    static JSContextRef m_globalContext;
+
+    // getters for properties
+    static JSValueRef getAuthor(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef* exception);
+    static JSValueRef getAuthorEmail(JSContextRef context,
+                                     JSObjectRef object,
+                                     JSStringRef propertyName,
+                                     JSValueRef* exception);
+    static JSValueRef getAuthorHref(JSContextRef context,
+                                    JSObjectRef object,
+                                    JSStringRef propertyName,
+                                    JSValueRef* exception);
+    static JSValueRef getDescription(JSContextRef context,
+                                     JSObjectRef object,
+                                     JSStringRef propertyName,
+                                     JSValueRef* exception);
+    static JSValueRef getId(JSContextRef context,
+                            JSObjectRef object,
+                            JSStringRef propertyName,
+                            JSValueRef* exception);
+    static JSValueRef getName(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception);
+    static JSValueRef getShortName(JSContextRef context,
+                                   JSObjectRef object,
+                                   JSStringRef propertyName,
+                                   JSValueRef* exception);
+    static JSValueRef getVersion(JSContextRef context,
+                                 JSObjectRef object,
+                                 JSStringRef propertyName,
+                                 JSValueRef* exception);
+    static JSValueRef getHeight(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef* exception);
+    static JSValueRef getWidth(JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef* exception);
+
+    static bool hasProperty(JSContextRef context,
+                            JSObjectRef object,
+                            JSStringRef propertyName);
+
+    static JSValueRef getProperty(JSContextRef context,
+                                  JSObjectRef object,
+                                  JSStringRef propertyName,
+                                  JSValueRef* exception);
+
+    static bool setProperty(JSContextRef context,
+                            JSObjectRef object,
+                            JSStringRef propertyName,
+                            JSValueRef value,
+                            JSValueRef* exception);
+
+};
+}
+}
+
+#endif /* _WRT_PLUGIN_JS_WIDGET_INTERFACE_H_ */
diff --git a/src/standards/W3C/Widget/plugin_config.cpp b/src/standards/W3C/Widget/plugin_config.cpp
new file mode 100644 (file)
index 0000000..581bec5
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+#include "plugin_config.h"
+
+namespace WrtPlugins {
+namespace W3C {
+
+template <>
+WidgetDeclarations::ParamsMap WidgetDeclarations::m_params =
+        WrtPlugins::W3C::WidgetDeclarations::ParamsMap();
+
+template <>
+WidgetDeclarations::DeviceCapsMaps WidgetDeclarations::m_deviceCaps =
+        WrtPlugins::W3C::WidgetDeclarations::DeviceCapsMaps();
+
+
+template <>
+WidgetDeclarations::FeaturesMap WidgetDeclarations::m_features =
+{
+    {
+        "http://w3cWidgetInterface.com/w3c-widget-interface",
+        {
+        }
+    }
+};
+
+template <>
+WidgetDeclarations::FunctionsMap WidgetDeclarations::m_functions =
+        WrtPlugins::W3C::WidgetDeclarations::FunctionsMap();
+
+} // namespace Wac2_0
+} // namespace WrtPlugins
diff --git a/src/standards/W3C/Widget/plugin_config.h b/src/standards/W3C/Widget/plugin_config.h
new file mode 100644 (file)
index 0000000..f0f8326
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+#ifndef _WIDGET_PLUGIN_CONFIG_H_
+#define _WIDGET_PLUGIN_CONFIG_H_
+
+#include <Security/StaticDeclaration.h>
+
+namespace WrtPlugins {
+namespace W3C {
+
+enum class WidgetParamId {
+};
+
+enum class WidgetDeviceCapId {
+};
+
+enum class WidgetFunctionId {
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::StaticDeclarations <
+        WidgetParamId,
+        WidgetDeviceCapId,
+        WidgetFunctionId> WidgetDeclarations;
+
+}
+}
+
+#endif //  _WIDGET_PLUGIN_CONFIG_H_
diff --git a/src/standards/W3C/Widget/plugin_initializer.cpp b/src/standards/W3C/Widget/plugin_initializer.cpp
new file mode 100644 (file)
index 0000000..6042af9
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * 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       plugin_initializer.cpp
+ * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <js-overlay/js_overlay_addEventListener.h>
+#include <js-overlay/js_iframe_support.h>
+
+#include "JSWidget.h"
+#include "JSPreferences.h"
+
+#include "plugin_config.h"
+
+#define OBJECT_WIDGET "widget"
+#define INTERFACE_WIDGET_NAME "Widget"
+#define OBJECT_PREFERENCES "preferences"
+
+using namespace WrtPlugins::W3C;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace Options{
+
+class_definition_options_t WidgetOptions =
+{
+    JS_CLASS,
+    CREATE_INSTANCE,
+    ALWAYS_NOTICE,
+    USE_OVERLAYED, //ignored
+    IFrameSupport::RegisterWidget,
+    NULL,
+    NULL
+};
+
+class_definition_options_t WidgetInterfaceOptions =
+{
+    JS_INTERFACE,
+    CREATE_INSTANCE,
+    ALWAYS_NOTICE,
+    USE_OVERLAYED, //ignored
+    JSWidget::acquireGlobalContext,
+    NULL,
+    NULL
+};
+
+};
+
+void on_widget_init_callback(feature_mapping_interface_t *mapping)
+{
+    LogDebug("[W3C\\widget] on_widget_init_callback");
+
+    WrtPlugins::W3C::WidgetDeclarations::getMappingInterface(mapping);
+}
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[W3C\\widget] on_widget_start_callback (" << widgetId << ")");
+
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch (Commons::Exception)
+    {
+        LogError("Wrt wrapper registration failed");
+        return;
+    }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[W3C\\widget] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch (Commons::Exception)
+    {
+        LogError("Wrt wrapper registration failed");
+        return;
+    }
+
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+PLUGIN_ON_WIDGET_INIT(on_widget_init_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_INTERFACE(
+        WRT_JS_EXTENSION_OBJECT_GLOBAL,
+        INTERFACE_WIDGET_NAME,
+        (js_class_template_getter)WrtPlugins::W3C::JSWidget::getClassRef,
+        reinterpret_cast<js_class_constructor_cb_t>(WrtPlugins::W3C::JSWidget::callAsConstructor),
+        &Options::WidgetInterfaceOptions)
+PLUGIN_CLASS_MAP_ADD_INTERFACE_PRODUCT(
+        WRT_JS_EXTENSION_OBJECT_GLOBAL,
+        OBJECT_WIDGET,
+        INTERFACE_WIDGET_NAME,
+        &Options::WidgetOptions)
+
+PLUGIN_CLASS_MAP_END
+
+#undef OBJECT_WIDGET
+#undef OBJECT_PREFERENCES
diff --git a/src/standards/standard-features-list b/src/standards/standard-features-list
new file mode 100644 (file)
index 0000000..4ef06c8
--- /dev/null
@@ -0,0 +1 @@
+http://w3cWidgetInterface.com/w3c-widget-interface
diff --git a/src/wrt-popup/CMakeLists.txt b/src/wrt-popup/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..13a79cc
--- /dev/null
@@ -0,0 +1,2 @@
+ADD_SUBDIRECTORY(ace)
+ADD_SUBDIRECTORY(wrt)
diff --git a/src/wrt-popup/ace/CMakeLists.txt b/src/wrt-popup/ace/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..2ecd23d
--- /dev/null
@@ -0,0 +1,2 @@
+ADD_SUBDIRECTORY(popup-bin)
+ADD_SUBDIRECTORY(popup-runner)
diff --git a/src/wrt-popup/ace/popup-bin/CMakeLists.txt b/src/wrt-popup/ace/popup-bin/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f87483d
--- /dev/null
@@ -0,0 +1,64 @@
+# 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   Janusz Kozerski (j.kozerski@samsung.com)
+#
+# @version  1.0
+#
+
+PKG_CHECK_MODULES(WRT_POPUP_DEP
+    dpl-efl
+    elementary
+    security-client
+    security-popup-validation
+   REQUIRED)
+
+set(WRT_POPUP_SRC_DIR ${PROJECT_SOURCE_DIR}/src/wrt-popup/ace/popup-bin)
+
+set(WRT_POPUP_SOURCES
+    ${WRT_POPUP_SRC_DIR}/Popup.cpp
+)
+
+ADD_DEFINITIONS(${WRT_POPUP_DEP_CFLAGS})
+
+INCLUDE_DIRECTORIES(
+    ${WRT_POPUP_SRC_DIR}
+    ${WRT_POPUP_DEP_INCLUDE_DIRS}
+)
+
+ADD_EXECUTABLE(${TARGET_POPUP_ACE}
+    ${WRT_POPUP_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_ACE} PROPERTIES
+    COMPILE_FLAGS -fPIC
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_ACE} PROPERTIES
+    #LINK_FLAGS "-Wl,--as-needed -Wl"
+    SOVERSION ${PROJECT_API_VERSION}
+    VERSION ${PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_POPUP_ACE}
+    ${WRT_POPUP_DEP_LIBRARIES}
+    ${TARGET_POPUP_ACE_RUNNER_LIB}
+    ${WRT_POPUP_DEP_LDFLAGS}
+)
+
+INSTALL(TARGETS ${TARGET_POPUP_ACE}
+    DESTINATION bin
+)
diff --git a/src/wrt-popup/ace/popup-bin/Popup.cpp b/src/wrt-popup/ace/popup-bin/Popup.cpp
new file mode 100644 (file)
index 0000000..16b0640
--- /dev/null
@@ -0,0 +1,434 @@
+/*
+ * 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        Popup.c
+ * @author      Janusz Kozerski (j.kozerski@samsung.com)
+ * @version     1.0
+ */
+
+/*
+ * This is just a example pop-up that shows how to use a new C-API in wrt-security.
+ * This pop-up should be re-implemented by members of NGWAP.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <vector>
+#include <ctime>
+
+#include <Elementary.h>
+
+#include <dpl/log/log.h>
+#include <dpl/serialization.h>
+#include <ace_api_common.h>
+#include <ace_api_popup_validation.h>
+
+#include "popup-runner.h"
+#include "Popup.h"
+
+namespace { // anonymous
+
+static void set_validity_from_checkbox(struct ace_popup_data *pdp) {
+
+    if(NULL == pdp){
+        LogError("pdp is NULL; return");
+        return;
+    }
+
+    if (pdp->always) {
+        LogDebug("Remember ALWAYS");
+        pdp->remember_choice = ACE_ALWAYS;
+        return;
+    }
+    if (pdp->per_session) {
+        LogDebug("Remember PER_SESSION");
+        pdp->remember_choice = ACE_PER_SESSION;
+        return;
+    }
+    LogDebug("Remember ONCE");
+    pdp->remember_choice = ACE_ONCE;
+    return;
+}
+
+static void on_done(void) {
+    // Quit the efl-mainloop
+    LogDebug("elm_exit()");
+    elm_exit();
+}
+
+static void grant_answer(void *data, Evas_Object * /* obj */, void * /* event_info */) {
+
+    LogDebug("grant_answer");
+    if(NULL == data){
+        LogError("data is NULL; return");
+        return;
+    }
+    struct ace_popup_data *pdp = static_cast <struct ace_popup_data *> (data);
+
+    set_validity_from_checkbox(pdp);
+
+    ace_popup_validation_initialize();
+    pdp->validation_return = ace_validate_answer(
+            ACE_TRUE,
+            pdp->remember_choice,
+            pdp->resource_name,
+            pdp->session_id,
+            &(pdp->param_list),
+            pdp->handle,
+            &(pdp->validation_result));
+    ace_popup_validation_shutdown();
+
+    on_done();
+}
+
+static void deny_answer(void *data, Evas_Object * /* obj */, void * /* event_info */) {
+
+    LogDebug("deny_answer");
+    if(NULL == data){
+        LogError("data is NULL; return");
+        return;
+    }
+    struct ace_popup_data *pdp = static_cast <struct ace_popup_data *> (data);
+
+    set_validity_from_checkbox(pdp);
+
+    ace_popup_validation_initialize();
+    pdp->validation_return = ace_validate_answer(
+            ACE_FALSE,
+            pdp->remember_choice,
+            pdp->resource_name,
+            pdp->session_id,
+            &(pdp->param_list),
+            pdp->handle,
+            &(pdp->validation_result));
+    ace_popup_validation_shutdown();
+
+    on_done();
+}
+
+static int _ace_params_deserializer(ace_param_list_t* ace_param_list, Wrt::Popup::BinaryStream *stream){
+
+    LogDebug("_ace_params_deserializer");
+
+    if(NULL == ace_param_list || NULL == stream){
+        LogError("ace_param_list or stream is NULL; return -1");
+        return -1;
+    }
+
+    // deserialize ace_param_list->count;
+    size_t count = 0;
+    DPL::Deserialization::Deserialize(*stream, count);
+    ace_param_list->count = count;
+    LogDebug("count : " << count);
+
+    std::string name;
+    std::string value;
+    if(count == 0){
+        ace_param_list->items = NULL;
+        return 0;
+    }
+    ace_param_list->items = static_cast <ace_param_t *> (malloc(count * sizeof(ace_param_t)));
+    memset(ace_param_list->items, 0, count * sizeof(ace_param_t));
+
+    for(size_t i=0; i < count; ++i){
+        DPL::Deserialization::Deserialize(*stream, name);
+        ace_param_list->items[i].name =
+                strdup(const_cast <char *> (name.c_str()));
+
+        DPL::Deserialization::Deserialize(*stream, value);
+        ace_param_list->items[i].value =
+                strdup(const_cast <char *> (value.c_str()));
+    }
+    return 0;
+}
+
+static void _ace_params_finalize(ace_param_list_t* ace_param_list) {
+    if (!ace_param_list || !ace_param_list->items) {
+        LogDebug("List is null, nothing to do");
+        return;
+    }
+    for (size_t i = 0; i < ace_param_list->count; ++i) {
+        free(ace_param_list->items[i].name);
+        free(ace_param_list->items[i].value);
+    }
+    free(ace_param_list->items);
+    ace_param_list->items = NULL;
+    ace_param_list->count = 0;
+}
+
+static void show_popup(struct ace_popup_data *pdp) {
+    LogDebug("show_popup()");
+
+    if(NULL == pdp){
+        LogError("pdp is NULL; return");
+        return;
+    }
+
+    const char *resource_type = static_cast <char *> (pdp->resource_name);
+
+    Evas_Object *win          = NULL;
+    Evas_Object *cb_session   = NULL;
+    Evas_Object *cb_always    = NULL;
+    Evas_Object *box          = NULL;
+    Evas_Object *label        = NULL;
+    Evas_Object *grant_button = NULL;
+    Evas_Object *deny_button  = NULL;
+    pdp->per_session          = EINA_FALSE;
+    pdp->always               = EINA_FALSE;
+
+    win = elm_win_add(NULL, "The wrt-client popup", ELM_WIN_NOTIFICATION);
+    elm_win_autodel_set(win, EINA_TRUE);
+    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+    evas_object_show(win);
+    elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_TRANSLUCENT);
+
+    pdp->popup = elm_popup_add(win);
+
+    box = elm_box_add(pdp->popup);
+    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0);
+    evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0);
+
+    label = elm_label_add(pdp->popup);
+    elm_object_style_set(label, "popup_description/default");
+    elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
+    char *buff = NULL;
+    if(-1 == asprintf(&buff, "Application need an access to %s.<br>Grant or deny?", resource_type)){
+        LogError("asprintf failed - returned -1");
+        evas_object_del(label);
+        evas_object_del(pdp->popup);
+        evas_object_del(win);
+        return;
+    }
+    elm_object_text_set(label, buff);
+    free(buff);
+    evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
+    evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
+    evas_object_show(label);
+    elm_box_pack_end(box, label);
+
+    LogDebug("popup_type == " << pdp->popup_type);
+    if (pdp->popup_type == ACE_SESSION || pdp->popup_type == ACE_BLANKET) {
+        LogDebug("popup_type == ACE_SESSION || ACE_BLANKET");
+        cb_session = elm_check_add(pdp->popup);
+        elm_object_text_set(cb_session, "Remember choice for this session");
+        elm_check_state_pointer_set(cb_session, &(pdp->per_session));
+        evas_object_smart_callback_add(cb_session, "changed", NULL, NULL);
+        evas_object_size_hint_align_set(cb_session, EVAS_HINT_FILL, EVAS_HINT_FILL);
+        evas_object_size_hint_weight_set(cb_session, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+        evas_object_show(cb_session);
+        elm_box_pack_end(box, cb_session);
+
+        if (pdp->popup_type == ACE_BLANKET) {
+            LogDebug("popup_type == ACE_BLANKET");
+            cb_always = elm_check_add(pdp->popup);
+            elm_object_text_set(cb_always, "Remember choice forever");
+            elm_check_state_pointer_set(cb_always, &(pdp->always));
+            evas_object_smart_callback_add(cb_always, "changed", NULL, NULL);
+            evas_object_size_hint_align_set(cb_always, EVAS_HINT_FILL, EVAS_HINT_FILL);
+            evas_object_size_hint_weight_set(cb_always, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+            evas_object_show(cb_always);
+            elm_box_pack_end(box, cb_always);
+        }
+    }
+
+    elm_object_part_content_set(pdp->popup, "default", box);
+
+    grant_button = elm_button_add(pdp->popup);
+    elm_object_text_set(grant_button, "Grant");
+    elm_object_part_content_set(pdp->popup, "button1", grant_button);
+    evas_object_smart_callback_add(grant_button, "clicked", grant_answer, pdp);
+
+    deny_button = elm_button_add(pdp->popup);
+    elm_object_text_set(deny_button, "Deny");
+    elm_object_part_content_set(pdp->popup, "button2", deny_button);
+    evas_object_smart_callback_add(deny_button, "clicked", deny_answer, pdp);
+
+    evas_object_show(pdp->popup);
+
+    // Showing the popup window
+    evas_object_show(win);
+
+    // Run the efl mainloop
+    elm_run();
+}
+
+} // anonymous
+
+
+EAPI_MAIN int
+elm_main(int argc , char ** argv)
+{
+    UNHANDLED_EXCEPTION_HANDLER_BEGIN
+    {
+// int pipe_in and int pipe_out should be passed to Popup via args.
+
+//  These parameters should be passed to Popup via pipe:
+//  ace_popup_t             popup_type
+//  const ace_resource_t    resource_name
+//  const ace_session_id_t  session_id
+//  ace_widget_handle_t     handle
+//  const ace_param_list_t  param_list
+
+        try {
+            DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-POPUP-BIN");
+        } Catch(DPL::Exception) {
+            //cannot run logger
+            return ACE_INTERNAL_ERROR;
+        }
+        LogDebug("############################ popup binary ################################");
+
+        if(argc < 3){
+            LogError("To few args passed in exec to popup-bin - should be at least 3:");
+            LogError("(binary-name, pipe_in, pipe_out)");
+            LogError("return ACE_INTERNAL_ERROR");
+            return ACE_INTERNAL_ERROR;
+        }
+        LogDebug("Passed args: " << argv[0] <<", " << argv[1] << ", " << argv[2]);
+
+        int pipe_in;
+        int pipe_out;
+
+        // Parsing args (pipe_in, pipe_out)
+        if ( 0 == sscanf(argv[1], "%d", &pipe_in) ){
+            LogError("Error while parsing pipe_in; return ACE_INTERNAL_ERROR");
+            return ACE_INTERNAL_ERROR;
+        }
+        if ( 0 == sscanf(argv[2], "%d", &pipe_out) ){
+            LogError("Error while parsing pipe_out; return ACE_INTERNAL_ERROR");
+            return ACE_INTERNAL_ERROR;
+        }
+        LogDebug("Parsed pipes: IN: " << pipe_in <<", OUT: " <<  pipe_out);
+
+        int  buff_size = 1024;
+        char line[buff_size];
+
+        struct ace_popup_data pd;
+        struct ace_popup_data *pdp = &pd;
+
+        pdp->popup = NULL;
+
+        ssize_t count = 0;
+        time_t time_start;
+        time(&time_start); // now
+        double timeout = 10.0;
+        // try to read parameters from pipe_in
+        // timeout is set for 10 seconds
+        do {
+            count = TEMP_FAILURE_RETRY(read(pipe_in, line, buff_size));
+            if ( timeout < difftime(time(NULL), time_start) ) {
+                LogError("Timeout reached! Exit popup - ACE_INTERNAL_ERROR");
+                close(pipe_in);
+                close(pipe_out);
+                return ACE_INTERNAL_ERROR;
+            }
+        } while (0 == count);
+        if(count < 0){
+            close(pipe_in);
+            close(pipe_out);
+            LogError("read returned a negative value (" << count <<")");
+            LogError("errno: " << strerror( errno ) );
+            LogError("Exit popup - ACE_INTERNAL_ERROR");
+            return ACE_INTERNAL_ERROR;
+        }
+        LogDebug("Read bytes : " << count << " (in " << difftime(time_start, time(NULL)) << " seconds)");
+        close(pipe_in); // cleanup
+
+        Wrt::Popup::BinaryStream stream;
+        stream.Write(count, static_cast <void *> (line));
+        int popup_type = ACE_ONESHOT;
+        std::string resource_name_str;
+        std::string session_id_str;
+        int handle = 0;
+
+        LogDebug("------- Deserialization -------");
+        // Deserialization order:
+        // popup_type, resource_name, session_id, handle, param_list
+
+        DPL::Deserialization::Deserialize(stream, popup_type);
+        LogDebug("popup_type_int : " << popup_type);
+        pdp->popup_type = static_cast <ace_popup_t> (popup_type);
+
+        DPL::Deserialization::Deserialize(stream, resource_name_str);
+        LogDebug("resource_name_char : " << resource_name_str.c_str());
+        pdp->resource_name =
+                strdup(const_cast <ace_resource_t> (resource_name_str.c_str()));
+
+        DPL::Deserialization::Deserialize(stream, session_id_str);
+        LogDebug("session_id_char : " << session_id_str.c_str());
+        pdp->session_id =
+                strdup(const_cast <ace_session_id_t> (session_id_str.c_str()));
+
+        DPL::Deserialization::Deserialize(stream, handle);
+        LogDebug("handle_int : " << handle);
+        pdp->handle = static_cast <ace_widget_handle_t> (handle);
+
+        if(_ace_params_deserializer(&(pdp->param_list), &stream)){
+            return ACE_INTERNAL_ERROR;
+        }
+
+        pdp->per_session = EINA_FALSE;
+        pdp->always = EINA_FALSE;
+        pdp->validation_return = ACE_ACE_UNKNOWN_ERROR;
+
+        show_popup(pdp); // Showing popup
+
+        // sending validation_result to popup-runner
+        Wrt::Popup::BinaryStream stream_out;
+
+        LogDebug("pdp->validation_result : " << pdp->validation_result);
+        int validation_result_int = (int) pdp->validation_result;
+        LogDebug("validation_result_int : " << validation_result_int);
+        DPL::Serialization::Serialize(stream_out, validation_result_int);
+        if(-1 == TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(), stream_out.size()))){
+            LogError("Write to pipe failed!");
+            close(pipe_out);
+            return ACE_INTERNAL_ERROR;
+        }
+        close(pipe_out);
+
+        if (pdp->validation_return == ACE_OK) {
+            LogDebug("ACE_OK");
+        }
+        else if (pdp->validation_return == ACE_INVALID_ARGUMENTS) {
+            LogError("ACE_INVALID_ARGUMENTS");
+        }
+        else if (pdp->validation_return == ACE_INTERNAL_ERROR) {
+            LogError("ACE_INTERNAL_ERROR");
+        }
+        else if (pdp->validation_return == ACE_ACE_UNKNOWN_ERROR) {
+            LogError("ACE_ACE_UNKNOWN_ERROR");
+        }
+        else {
+            LogError("Really unknown error!!!");
+        }
+
+        LogDebug("############################ /popup binary ################################");
+
+        // Shutdown elementary
+        //LogDebug("elm_shutdown()");
+        //elm_shutdown();
+        // This is commented because, it causes that popup exits with 139 code (Segmentatation violation).
+        // Not calling elm_shutdown() should not have any negative consequences because this binary ends
+        // in next line, and system should clear the memory.
+
+        _ace_params_finalize(&(pdp->param_list));
+        return pdp->validation_return;
+    }
+    UNHANDLED_EXCEPTION_HANDLER_END
+}
+ELM_MAIN()
diff --git a/src/wrt-popup/ace/popup-bin/Popup.h b/src/wrt-popup/ace/popup-bin/Popup.h
new file mode 100644 (file)
index 0000000..8c841d6
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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        Popup.h
+ * @author      Janusz Kozerski (j.kozerski@samsung.com)
+ * @version     1.0
+ */
+
+#include <Elementary.h>
+#include <ace_api_common.h>
+
+struct ace_popup_data {
+    ace_popup_t          popup_type;
+    ace_resource_t       resource_name;
+    ace_session_id_t     session_id;
+    ace_param_list_t     param_list;
+    ace_widget_handle_t  handle;
+    ace_bool_t           validation_result;
+    ace_return_t         validation_return;
+
+    Evas_Object          *popup;
+    Eina_Bool            per_session;
+    Eina_Bool            always;
+
+    ace_validity_t       remember_choice;
+};
diff --git a/src/wrt-popup/ace/popup-runner/CMakeLists.txt b/src/wrt-popup/ace/popup-runner/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4e5053c
--- /dev/null
@@ -0,0 +1,65 @@
+# 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   Janusz Kozerski (j.kozerski@samsung.com)
+#
+# @version  1.0
+#
+
+PKG_CHECK_MODULES(WRT_POPUP_RUNNER_LIB_DEP
+    dpl-efl
+    elementary
+    security-client
+   REQUIRED)
+
+set(WRT_POPUP_RUNNER_LIB_SRC_DIR ${PROJECT_SOURCE_DIR}/src/wrt-popup/ace/popup-runner)
+
+set(WRT_POPUP_RUNNER_LIB_SOURCES
+    ${WRT_POPUP_RUNNER_LIB_SRC_DIR}/popup-runner.cpp
+)
+
+ADD_DEFINITIONS(${WRT_POPUP_RUNNER_LIB_DEP_CFLAGS})
+
+INCLUDE_DIRECTORIES(
+    ${WRT_POPUP_RUNNER_LIB_SRC_DIR}
+    ${WRT_POPUP_RUNNER_LIB_DEP_INCLUDE_DIRS}
+)
+
+ADD_LIBRARY(${TARGET_POPUP_ACE_RUNNER_LIB} SHARED
+    ${WRT_POPUP_RUNNER_LIB_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_ACE_RUNNER_LIB} PROPERTIES
+    COMPILE_FLAGS -fPIC
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_ACE_RUNNER_LIB} PROPERTIES
+    SOVERSION ${CMAKE_PROJECT_API_VERSION}
+    VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_POPUP_ACE_RUNNER_LIB}
+    ${WRT_POPUP_RUNNER_LIB_DEP_LIBRARIES}
+    ${WRT_POPUP_RUNNER_LIB_DEP_LDFLAGS}
+)
+
+INSTALL(TARGETS ${TARGET_POPUP_ACE_RUNNER_LIB}
+    DESTINATION lib
+)
+
+INSTALL(FILES ${WRT_POPUP_RUNNER_LIB_SRC_DIR}/popup-runner.h
+    DESTINATION ${DESTINATION_HEADERS_WRT_POPUP_RUNNER}
+)
diff --git a/src/wrt-popup/ace/popup-runner/popup-runner.cpp b/src/wrt-popup/ace/popup-runner/popup-runner.cpp
new file mode 100644 (file)
index 0000000..0068bcc
--- /dev/null
@@ -0,0 +1,283 @@
+/*
+ * 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        popup-runner.cpp
+ * @author      Janusz Kozerski (j.kozerski@samsung.com)
+ * @version     1.0
+ */
+
+/*
+ * This is just a example pop-up that shows how to use a new C-API in wrt-security.
+ * This pop-up should be re-implemented by members of NGWAP.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <iostream>
+#include <sstream>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <dpl/log/log.h>
+
+#include "popup-runner.h"
+
+namespace { // anonymous
+
+const char *POPUP_EXEC = "/usr/bin/wrt-popup-ace-runtime";
+
+void _ace_params_serializer (const ace_param_list_t* ace_param_list, Wrt::Popup::BinaryStream *stream){
+
+    LogDebug("_ace_params_serializer");
+
+    if(NULL == ace_param_list || NULL == stream){
+        LogError("*ace_param_list or *stream is NULL; return");
+        return;
+    }
+    LogDebug("Param count : " << ace_param_list->count);
+
+    // serialize ace_param_list->count;
+    size_t count = static_cast <size_t> (ace_param_list->count);
+    DPL::Serialization::Serialize(*stream, count);
+
+    for(size_t i=0; i < count; ++i){
+        std::string name(ace_param_list->items[i].name);
+        DPL::Serialization::Serialize(*stream, name);
+
+        std::string value(ace_param_list->items[i].value);
+        DPL::Serialization::Serialize(*stream, value);
+    }
+}
+
+} // anonymous namespace
+
+namespace Wrt {
+namespace Popup {
+
+// BinaryStream class implementation
+void BinaryStream::Read(size_t num, void * bytes) {
+    size_t max_size = m_data.size();
+    for (size_t i = 0; i < num; ++i) {
+        if( i + m_readPosition >= max_size){
+            return;
+        }
+        static_cast <unsigned char*> (bytes)[i] = m_data[i + m_readPosition];
+    }
+    m_readPosition += num;
+}
+
+void BinaryStream::Write(size_t num, const void * bytes) {
+    for (size_t i = 0; i < num; ++i) {
+        m_data.push_back(static_cast <const unsigned char*> (bytes)[i]);
+    }
+}
+
+BinaryStream::BinaryStream() {
+    m_readPosition = 0;
+}
+
+BinaryStream::~BinaryStream() {
+}
+
+const unsigned char* BinaryStream::char_pointer() const {
+    return &m_data[0];
+}
+
+size_t BinaryStream::size() const {
+    return m_data.size();
+}
+// BinaryStream
+
+ace_return_t run_popup(
+        ace_popup_t popup_type,
+        const ace_resource_t resource_name,
+        const ace_session_id_t session_id,
+        const ace_param_list_t* ace_param_list,
+        ace_widget_handle_t handle,
+        ace_bool_t* validation_result)
+{
+    if (    NULL == resource_name  ||
+            NULL == session_id     ||
+            NULL == ace_param_list ||
+            NULL == validation_result )
+    {
+        LogError("run_popup : ACE_INVALID_ARGUMENTS");
+        return ACE_INVALID_ARGUMENTS;
+    }
+    LogDebug("popup_type    : " << popup_type);
+    LogDebug("resource_name : " << resource_name);
+    LogDebug("session_id    : " << session_id);
+    LogDebug("widget handle : " << handle);
+
+    int  popup_type_int      = static_cast <int>    (popup_type);
+    char *resource_name_char = static_cast <char *> (resource_name);
+    char *session_id_char    = static_cast <char *> (session_id);
+    int  handle_int          = static_cast <int>    (handle);
+
+    // serialization
+    Wrt::Popup::BinaryStream stream;
+    DPL::Serialization::Serialize(stream, popup_type_int);
+
+    std::string resource_name_str(resource_name_char);
+    DPL::Serialization::Serialize(stream, resource_name_str);
+
+    std::string session_id_str(session_id_char);
+    DPL::Serialization::Serialize(stream, session_id_str);
+
+    DPL::Serialization::Serialize(stream, handle_int);
+
+    _ace_params_serializer (ace_param_list, &stream);
+
+    int   fd_send_to_child[2];
+    int   fd_send_to_parent[2];
+    pid_t childpid;
+
+    if(0 != pipe(fd_send_to_child)){
+        LogError("Cannot create pipes!");
+        return ACE_INTERNAL_ERROR;
+    }
+    if(0 != pipe(fd_send_to_parent)){
+        LogError("Cannot create pipes!");
+        return ACE_INTERNAL_ERROR;
+    }
+
+    if ((childpid = fork()) == -1) {
+        LogError("Fork() ERROR");
+        return ACE_ACE_UNKNOWN_ERROR;
+    }
+
+    if(childpid == 0) { // Child process
+        LogDebug("Child");
+
+        // read data from parent
+        close(fd_send_to_child[1]);
+
+        // send data to parent
+        close(fd_send_to_parent[0]);
+
+        std::stringstream pipe_in_buff;
+        std::stringstream pipe_out_buff;
+        pipe_in_buff  << fd_send_to_parent[1];
+        pipe_out_buff << fd_send_to_child[0];
+        std::string pipe_in  = pipe_in_buff.str();
+        std::string pipe_out = pipe_out_buff.str();
+
+        LogDebug("Passed file descriptors: " << fd_send_to_child[0] << ", "<< fd_send_to_parent[1]);
+
+        if (execl(POPUP_EXEC, POPUP_EXEC, pipe_out.c_str(), pipe_in.c_str(), NULL) < 0){
+            LogError("execlp FAILED");
+        }
+
+        LogError("This should not happened!!!");
+
+    } // end of child process - from now you can use DEBUG LOGS
+    else { // Parent process
+        LogDebug("Parent");
+
+        int  buff_size = 1024;
+        char result[buff_size];
+        // send data to child
+        close(fd_send_to_child[0]);
+
+        //writing to child
+        LogDebug("Sending message to popup-bin process");
+        if(-1 == TEMP_FAILURE_RETRY(write(fd_send_to_child[1], stream.char_pointer(), stream.size()))){
+            LogError("Write to pipe failed!");
+            return ACE_INTERNAL_ERROR;
+        }
+        close(fd_send_to_child[1]); // cleanup
+        LogDebug("Message has been sent");
+
+        // read data from child
+        close(fd_send_to_parent[1]);
+
+        int status;
+        wait(&status);
+        LogDebug("STATUS EXIT ON POPUP (CHILD): " << status);
+        switch (status){
+
+        case ACE_OK:
+            LogDebug("ACE_OK");
+            break;
+
+        case ACE_INVALID_ARGUMENTS:
+            LogDebug("ACE_INVALID_ARGUMENTS");
+            close(fd_send_to_parent[0]);
+            return static_cast <ace_return_t> (status);
+            break;
+
+        case ACE_INTERNAL_ERROR:
+            LogDebug("ACE_INTERNAL_ERROR");
+            close(fd_send_to_parent[0]);
+            return static_cast <ace_return_t> (status);
+            break;
+
+        case ACE_ACE_UNKNOWN_ERROR:
+            LogDebug("ACE_ACE_UNKNOWN_ERROR");
+            close(fd_send_to_parent[0]);
+            return static_cast <ace_return_t> (status);
+            break;
+
+        default:
+            LogDebug("UNKNOWN_ERROR");
+            close(fd_send_to_parent[0]);
+            status = (int) ACE_ACE_UNKNOWN_ERROR;
+            return static_cast <ace_return_t> (status);
+            break;
+        }
+
+        int count;
+        count = TEMP_FAILURE_RETRY(read(fd_send_to_parent[0], result, buff_size));
+        close(fd_send_to_parent[0]); // cleanup
+        int validation_result_int;
+
+        if(0 < count){
+            BinaryStream stream_in;
+            stream_in.Write(count, result);
+            LogDebug("RESULT FROM POPUP (CHILD) : [ " << count << " ]");
+            DPL::Deserialization::Deserialize(stream_in, validation_result_int);
+            *validation_result = static_cast <ace_bool_t> (validation_result_int);
+
+            LogDebug("validation_result :");
+            switch (*validation_result){
+            case ACE_FALSE:
+                LogDebug("ACE_FALSE");
+                break;
+            case ACE_TRUE:
+                LogDebug("ACE_TRUE");
+                break;
+            default:
+                LogDebug("UNKNOWN - DEFAULT");
+                break;
+            }
+        }
+        else {
+            LogDebug("count = " << count);
+            LogDebug("UNKNOWN_ERROR");
+            return ACE_ACE_UNKNOWN_ERROR;
+        }
+
+        LogDebug("popup-runner: EXIT");
+        return (ace_return_t) status;
+    }
+
+    LogError("This should not happend!!!");
+    return ACE_ACE_UNKNOWN_ERROR;
+}
+
+} // Popup
+} // Wrt
diff --git a/src/wrt-popup/ace/popup-runner/popup-runner.h b/src/wrt-popup/ace/popup-runner/popup-runner.h
new file mode 100644 (file)
index 0000000..e3cf0ad
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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        popup-runner.h
+ * @author      Janusz Kozerski (j.kozerski@samsung.com)
+ * @version     1.0
+ */
+
+#include <ace_api_client.h>
+#include <vector>
+
+#include <dpl/serialization.h>
+
+namespace Wrt {
+namespace Popup {
+
+class BinaryStream : public DPL::IStream {
+  public:
+    void Read (size_t num,       void * bytes);
+    void Write(size_t num, const void * bytes);
+
+    BinaryStream();
+    ~BinaryStream();
+
+    const unsigned char* char_pointer() const;
+    size_t size() const;
+
+  private:
+    std::vector<unsigned char> m_data;
+    size_t m_readPosition;
+};
+
+ace_return_t run_popup(
+        ace_popup_t popup_type,
+        const ace_resource_t resource_name,
+        const ace_session_id_t session_id,
+        const ace_param_list_t* ace_param_list,
+        ace_widget_handle_t handle,
+        ace_bool_t* validation_result
+        );
+
+} // Popup
+} // Wrt
diff --git a/src/wrt-popup/wrt/CMakeLists.txt b/src/wrt-popup/wrt/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..ed0e24b
--- /dev/null
@@ -0,0 +1,9 @@
+
+set(WRT_POPUP_COMMON_DIR ${PROJECT_SOURCE_DIR}/src/wrt-popup/wrt)
+
+SET(WRT_POPUP_COMMON_SRCS
+    ${WRT_POPUP_COMMON_DIR}/PopupSerializer.cpp
+)
+
+ADD_SUBDIRECTORY(popup-bin)
+ADD_SUBDIRECTORY(popup-runner)
diff --git a/src/wrt-popup/wrt/PopupEnum.h b/src/wrt-popup/wrt/PopupEnum.h
new file mode 100644 (file)
index 0000000..3200ef4
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+#ifndef WRT_POPUP_ENUM_H
+#define WRT_POPUP_ENUM_H
+
+namespace Wrt {
+enum PopupType {
+    INFO_PROMPT = 1,
+    YES_NO_PROMPT,
+    YES_NO_CHECK_PROMPT
+};
+}
+
+#endif
+
diff --git a/src/wrt-popup/wrt/PopupSerializer.cpp b/src/wrt-popup/wrt/PopupSerializer.cpp
new file mode 100644 (file)
index 0000000..481519a
--- /dev/null
@@ -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.
+ */
+
+#include "PopupSerializer.h"
+
+#include <memory>
+
+namespace Wrt {
+namespace PopupSerializer {
+
+void appendArg(int arg, DPL::BinaryQueue &buffer)
+{
+    size_t argSize = sizeof(arg);
+    buffer.AppendCopy(&argSize, sizeof(argSize));
+    buffer.AppendCopy(&arg, sizeof(arg));
+}
+
+void appendArg(const std::string &arg, DPL::BinaryQueue &buffer)
+{
+    size_t argSize = arg.size();
+    buffer.AppendCopy(&argSize, sizeof(argSize));
+    buffer.AppendCopy(arg.c_str(), argSize);
+}
+
+int getIntArg(DPL::BinaryQueue &buffer)
+{
+    int result;
+    size_t argSize;
+    buffer.FlattenConsume(&argSize, sizeof(argSize));
+    buffer.FlattenConsume(&result, argSize);
+    //TODO: what if argSize != sizeof(int)
+    //This should not be problem if this is run on the same machine.
+    return result;
+}
+
+std::string getStringArg(DPL::BinaryQueue &buffer)
+{
+    std::string::size_type size;
+    buffer.FlattenConsume(&size, sizeof(size));
+    std::unique_ptr<char[]> str(new char[size]);
+    buffer.FlattenConsume(str.get(), size);
+    return std::string(str.get(), str.get() + size);
+}
+
+}
+} // Wrt
diff --git a/src/wrt-popup/wrt/PopupSerializer.h b/src/wrt-popup/wrt/PopupSerializer.h
new file mode 100644 (file)
index 0000000..27094fd
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#ifndef WRT_POPUP_SERIALIZER_H
+#define WRT_POPUP_SERIALIZER_H
+
+#include <string>
+#include <dpl/binary_queue.h>
+
+namespace Wrt {
+namespace PopupSerializer {
+
+void appendArg(int arg, DPL::BinaryQueue &buffer);
+void appendArg(const std::string &arg, DPL::BinaryQueue &buffer);
+
+int getIntArg(DPL::BinaryQueue &buffer);
+std::string getStringArg(DPL::BinaryQueue &buffer);
+
+}
+} // Wrt
+
+#endif
\ No newline at end of file
diff --git a/src/wrt-popup/wrt/popup-bin/CMakeLists.txt b/src/wrt-popup/wrt/popup-bin/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d76b34e
--- /dev/null
@@ -0,0 +1,56 @@
+# 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.
+#
+
+PKG_CHECK_MODULES(WRT_POPUP_DEPS
+    ecore-x
+    dpl-efl
+    dpl-event-efl
+    REQUIRED
+)
+
+INCLUDE_DIRECTORIES(
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/renderer
+    ${WRT_POPUP_DEPS_INCLUDE_DIRS}
+    ${WRT_POPUP_COMMON_DIR}
+)
+
+SET(WRT_POPUP_SRCS
+    ${WRT_POPUP_COMMON_SRCS}
+    wrt-popup.cpp
+    YesNoPopup.cpp
+    YesNoCheckPopup.cpp
+    InfoPopup.cpp
+    renderer/evas_object.cpp
+    renderer/popup_controller.cpp
+    renderer/popup_manager.cpp
+    renderer/popup_renderer.cpp
+)
+
+ADD_EXECUTABLE(${TARGET_POPUP_WRT}
+    ${WRT_POPUP_SRCS}
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_POPUP_WRT}
+    ${WRT_POPUP_DEPS_LIBRARIES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_WRT} PROPERTIES
+    LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both -Wl"
+    BUILD_WITH_INSTALL_RPATH ON
+    INSTALL_RPATH_USE_LINK_PATH ON
+)
+
+INSTALL(TARGETS ${TARGET_POPUP_WRT} DESTINATION bin)
diff --git a/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp b/src/wrt-popup/wrt/popup-bin/InfoPopup.cpp
new file mode 100644 (file)
index 0000000..2b9cc37
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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        InfoPopup.cpp
+ * @author      Lukasz Marek(l.marek@samsung.com)
+ * @version     1.0
+ * @brief       Popup that displays information. Inplementation
+ */
+
+#include "InfoPopup.h"
+#include <memory>
+#include <string.h>
+#include "popup_manager.h"
+#include "popup.h"
+#include "PopupSerializer.h"
+
+namespace Wrt {
+namespace Popup {
+
+void InfoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent)
+{
+    LogDebug("Entered");
+    std::string title = PopupSerializer::getStringArg(*data);
+    std::string message = PopupSerializer::getStringArg(*data);
+    std::string button = PopupSerializer::getStringArg(*data);
+    Assert(data->Empty());
+    LogDebug("title: " << title << " message: " << message);
+
+    m_parent = parent;
+
+    Renderer::CtrlPopupPtr popup =
+        Renderer::PopupControllerSingleton::Instance().CreatePopup();
+
+    popup->SetTitle(title);
+    popup->Append(new Renderer::PopupObject::Label(message));
+
+    popup->Append(new Renderer::PopupObject::Button(button, 0));
+
+    ListenForAnswer(popup);
+
+    Renderer::ShowPopupEventShort event(popup,
+                                        MakeAnswerCallback(
+                                            this,
+                                            &InfoPopup::responseCallback));
+
+    CONTROLLER_POST_EVENT(Renderer::PopupController,
+                          event);
+
+    LogDebug("Exited");
+    return;
+}
+
+void InfoPopup::responseCallback(const Renderer::AnswerCallbackData &answer)
+{
+    DPL::BinaryQueue retValue;
+    PopupSerializer::appendArg(answer.buttonAnswer, retValue);
+    m_parent->response(retValue);
+}
+
+} // Popup
+} // Wrt
diff --git a/src/wrt-popup/wrt/popup-bin/InfoPopup.h b/src/wrt-popup/wrt/popup-bin/InfoPopup.h
new file mode 100644 (file)
index 0000000..7c83b59
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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        InfoPopup.h
+ * @author      Andrzej Surdej (a.surdej@samsung.com)
+ * @version     1.0
+ * @brief       Popup that contains 'Yes' and 'No' buttons
+ */
+
+#ifndef WRT_INFO_POPUP_H
+#define WRT_INFO_POPUP_H
+
+#include "wrt-popup.h"
+
+namespace Wrt {
+namespace Popup {
+
+class InfoPopup : public IPopup
+{
+public:
+    virtual void show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent);
+
+private:
+
+    void responseCallback(const Renderer::AnswerCallbackData &answer);
+    WrtPopup* m_parent;
+};
+
+} // Popup
+} // Wrt
+
+#endif /* WRT_INFO_POPUP_H */
+
diff --git a/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp b/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.cpp
new file mode 100644 (file)
index 0000000..4a7e597
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * File:   YesNoCheckPopup.cpp
+ * Author: pciezkowski
+ *
+ * Created on December 12, 2012, 9:23 AM
+ */
+
+#include "YesNoCheckPopup.h"
+#include <memory>
+#include <string.h>
+#include "popup_manager.h"
+#include "PopupSerializer.h"
+
+namespace Wrt {
+namespace Popup {
+
+YesNoCheckPopup::~YesNoCheckPopup()
+{
+}
+
+Renderer::CtrlPopupPtr YesNoCheckPopup::createPopup(DPL::BinaryQueueAutoPtr data)
+{
+    std::string title = PopupSerializer::getStringArg(*data);
+    std::string message = PopupSerializer::getStringArg(*data);
+    std::string checkboxLabel = PopupSerializer::getStringArg(*data);
+    Assert(data->Empty());
+    LogDebug("title: " << title << " message: " << message << " checkbox: " <<
+            checkboxLabel);
+    Renderer::CtrlPopupPtr popup =
+        Renderer::PopupControllerSingleton::Instance().CreatePopup();
+
+    popup->SetTitle(title);
+    popup->Append(new Renderer::PopupObject::Label(message));
+    popup->Append(new Renderer::PopupObject::Check(checkboxLabel));
+    popup->Append(new Renderer::PopupObject::Button(YES_LABEL, POPUP_YES_VALUE));
+    popup->Append(new Renderer::PopupObject::Button(NO_LABEL, POPUP_NO_VALUE));
+    return popup;
+}
+
+void YesNoCheckPopup::responseCallback(
+        const Renderer::AnswerCallbackData &answer)
+{
+    bool result = (POPUP_YES_VALUE == answer.buttonAnswer);
+    DPL::BinaryQueue retValue;
+    PopupSerializer::appendArg(result, retValue);
+    LogDebug("Check state: " << answer.chackState);
+    PopupSerializer::appendArg(answer.chackState, retValue);
+    m_parent->response(retValue);
+}
+
+
+} // Popup
+} // Wrt
diff --git a/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.h b/src/wrt-popup/wrt/popup-bin/YesNoCheckPopup.h
new file mode 100644 (file)
index 0000000..710fc6c
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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        YesNoCheckPopup.cpp
+ * @author      Przmeyslaw Ciezkowsko (p.ciezkowski@samsung.com)
+ * @version     1.0
+ * @brief       Popup that contains 'Yes' and 'No' buttons and checkbox. Inplementation
+ */
+
+#include "YesNoPopup.h"
+#include "wrt-popup.h"
+
+#ifndef WRT_YES_NO_CHECK_POPUP_H
+#define WRT_YES_NO_CHECK_POPUP_H
+
+namespace Wrt {
+namespace Popup {
+
+class YesNoCheckPopup: public YesNoPopup {
+public:
+    virtual ~YesNoCheckPopup();
+protected:
+    virtual Renderer::CtrlPopupPtr createPopup(DPL::BinaryQueueAutoPtr data);
+    virtual void responseCallback(const Renderer::AnswerCallbackData &answer);
+
+};
+
+} // Popup
+} // Wrt
+
+#endif /* WRT_YES_NO_CHECK_POPUP_H */
+
diff --git a/src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp b/src/wrt-popup/wrt/popup-bin/YesNoPopup.cpp
new file mode 100644 (file)
index 0000000..9951954
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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        YesNoPopup.cpp
+ * @author      Andrzej Surdej (a.surdej@samsung.com)
+ * @version     1.0
+ * @brief       Popup that contains 'Yes' and 'No' buttons. Inplementation
+ */
+
+#include "YesNoPopup.h"
+#include <memory>
+#include <string.h>
+#include "popup_manager.h"
+#include "PopupSerializer.h"
+
+namespace Wrt {
+namespace Popup {
+
+void YesNoPopup::show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent)
+{
+    LogDebug("Entered");
+    m_parent = parent;
+    Renderer::CtrlPopupPtr popup = createPopup(data);
+    ListenForAnswer(popup);
+
+    Renderer::ShowPopupEventShort event(popup,
+                                        MakeAnswerCallback(
+                                            this,
+                                            &YesNoPopup::responseCallback));
+
+    CONTROLLER_POST_EVENT(Renderer::PopupController,
+                          event);
+
+    LogDebug("Exited");
+    return;
+}
+
+void YesNoPopup::responseCallback(const Renderer::AnswerCallbackData &answer)
+{
+    bool result = (POPUP_YES_VALUE == answer.buttonAnswer);
+    DPL::BinaryQueue retValue;
+    PopupSerializer::appendArg(result, retValue);
+    m_parent->response(retValue);
+}
+
+YesNoPopup::~YesNoPopup()
+{
+}
+
+Renderer::CtrlPopupPtr YesNoPopup::createPopup(DPL::BinaryQueueAutoPtr data)
+{
+    std::string title = PopupSerializer::getStringArg(*data);
+    std::string message = PopupSerializer::getStringArg(*data);
+    Assert(data->Empty());
+    LogDebug("title: " << title << " message: " << message);
+    Renderer::CtrlPopupPtr popup =
+        Renderer::PopupControllerSingleton::Instance().CreatePopup();
+
+    popup->SetTitle(title);
+    popup->Append(new Renderer::PopupObject::Label(message));
+
+    popup->Append(new Renderer::PopupObject::Button(YES_LABEL, POPUP_YES_VALUE));
+    popup->Append(new Renderer::PopupObject::Button(NO_LABEL, POPUP_NO_VALUE));
+    return popup;
+}
+
+} // Popup
+} // Wrt
diff --git a/src/wrt-popup/wrt/popup-bin/YesNoPopup.h b/src/wrt-popup/wrt/popup-bin/YesNoPopup.h
new file mode 100644 (file)
index 0000000..8b07ba7
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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        YesNoPopup.h
+ * @author      Andrzej Surdej (a.surdej@samsung.com)
+ * @version     1.0
+ * @brief       Popup that contains 'Yes' and 'No' buttons
+ */
+
+#ifndef WRT_YES_NO_POPUP_H
+#define WRT_YES_NO_POPUP_H
+
+#include "wrt-popup.h"
+
+namespace Wrt {
+namespace Popup {
+
+const char YES_LABEL[] = "Yes";
+const char NO_LABEL[] = "No";
+const int POPUP_YES_VALUE = 1;
+const int POPUP_NO_VALUE = 2;
+
+class YesNoPopup : public IPopup
+{
+public:
+    virtual void show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent);
+    virtual ~YesNoPopup();
+protected:
+    virtual Renderer::CtrlPopupPtr createPopup(DPL::BinaryQueueAutoPtr data);
+    virtual void responseCallback(const Renderer::AnswerCallbackData &answer);
+    WrtPopup* m_parent;
+};
+
+} // Popup
+} // Wrt
+
+#endif /* WRT_YES_NO_POPUP_H */
+
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/evas_object.cpp b/src/wrt-popup/wrt/popup-bin/renderer/evas_object.cpp
new file mode 100644 (file)
index 0000000..9510c83
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+ * 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        evas_object.cpp
+ * @author      Lukasz Wrzosek (l.wrzosel@samsung.com)
+ * @version     1.0
+ * @brief       This file is the implementation for Evas_Object wrapper from Efl.
+ */
+
+#include "evas_object.h"
+#include <stddef.h>
+#include <dpl/foreach.h>
+
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+Evas_Object* EvasObject::IConnection::GetEvasObject()
+{
+    return m_object->GetObject();
+}
+
+void EvasObject::IConnection::Disconnect()
+{
+    m_object->DisconnectCallback(this);
+}
+
+EvasObject::IConnection::IConnection(EvasObject::EvasObjectShared* object) :
+    m_object(object)
+{
+}
+
+void EvasObject::IConnection::SmartCallbackWrapper(void* data,
+        Evas_Object* /*object*/,
+        void* event_info)
+{
+    Assert(data);
+    IConnection* Calle = static_cast<IConnection*>(data);
+    Calle->Call(event_info);
+}
+
+void EvasObject::IConnection::EvasCallbackWrapper(void* data,
+        Evas* /*evas*/,
+        Evas_Object* /*object*/,
+        void* event_info)
+{
+    Assert(data);
+    IConnection* Calle = static_cast<IConnection*>(data);
+    Calle->Call(event_info);
+}
+
+Evas_Object* EvasObject::EvasObjectShared::GetObject()
+{
+    return m_object;
+}
+
+EvasObject::EvasObjectShared::SmartConnectionBase::SmartConnectionBase(
+        const std::string& name,
+        EvasObject::EvasObjectShared* object) :
+    IConnection(object),
+    m_callbackName(name)
+{
+}
+
+void EvasObject::EvasObjectShared::SmartConnectionBase::ConnectPrv()
+{
+    evas_object_smart_callback_add(GetEvasObject(),
+                                   m_callbackName.c_str(),
+                                   &IConnection::SmartCallbackWrapper, this);
+}
+
+void EvasObject::EvasObjectShared::SmartConnectionBase::DisconnectPrv()
+{
+    evas_object_smart_callback_del(GetEvasObject(),
+                                   m_callbackName.c_str(),
+                                   &IConnection::SmartCallbackWrapper);
+}
+
+EvasObject::EvasObjectShared::EvasConnectionBase::EvasConnectionBase(
+        Evas_Callback_Type type,
+        EvasObject::EvasObjectShared* object) :
+    IConnection(object),
+    m_callbackType(type)
+{
+}
+
+void EvasObject::EvasObjectShared::EvasConnectionBase::ConnectPrv()
+{
+    evas_object_event_callback_add(
+        GetEvasObject(), m_callbackType, &IConnection::EvasCallbackWrapper,
+        this);
+}
+
+void EvasObject::EvasObjectShared::EvasConnectionBase::DisconnectPrv()
+{
+    evas_object_event_callback_del_full(
+        GetEvasObject(), m_callbackType, &IConnection::EvasCallbackWrapper,
+        this);
+}
+
+EvasObject::EvasObjectShared::EvasObjectShared() :
+    m_object(NULL)
+{
+}
+
+EvasObject::EvasObjectShared::EvasObjectShared(Evas_Object* object) :
+    m_object(object)
+{
+    Assert(m_object);
+    evas_object_event_callback_add(m_object,
+                                   EVAS_CALLBACK_DEL,
+                                   &StaticOnDelEvent,
+                                   this);
+}
+
+void EvasObject::EvasObjectShared::SetObject(Evas_Object* object)
+{
+    Assert(m_object == NULL);
+    Assert(object != NULL);
+    m_object = object;
+    evas_object_event_callback_add(m_object,
+                                   EVAS_CALLBACK_DEL,
+                                   &StaticOnDelEvent,
+                                   this);
+}
+
+EvasObject::EvasObjectShared::~EvasObjectShared()
+{
+    if (m_object) {
+        DisconnectAll();
+        evas_object_event_callback_del(m_object,
+                                       EVAS_CALLBACK_DEL,
+                                       &StaticOnDelEvent);
+        m_object = NULL;
+    }
+}
+
+bool EvasObject::EvasObjectShared::DisconnectCallback(IConnection* connection)
+{
+    IConnectionsSet::iterator it = m_connections.find(connection);
+    if (it != m_connections.end()) {
+        (*it)->DisconnectPrv();
+        delete connection;
+        m_connections.erase(it);
+        return true;
+    }
+    return false;
+}
+
+void EvasObject::EvasObjectShared::DisconnectAll()
+{
+    FOREACH(it, m_connections)
+    {
+        (*it)->DisconnectPrv();
+        delete *it;
+    }
+    m_connections.clear();
+}
+
+void EvasObject::EvasObjectShared::StaticOnDelEvent(void* data,
+        Evas* /*e*/,
+        Evas_Object* /*o*/,
+        void* /*ev*/)
+{
+    Assert(data);
+    EvasObjectShared* This = static_cast<EvasObjectShared*>(data);
+    if (This->m_object) {
+        evas_object_event_callback_del(This->m_object,
+                                       EVAS_CALLBACK_DEL,
+                                       &StaticOnDelEvent);
+        This->DisconnectAll();
+        This->m_object = NULL;
+    }
+}
+
+EvasObject::EvasObject() :
+    m_object(new EvasObjectShared())
+{
+}
+
+EvasObject::EvasObject(Evas_Object* object) :
+    m_object(new EvasObjectShared(object))
+{
+}
+
+EvasObject::EvasObject(const EvasObject& other) :
+    m_object(other.m_object)
+{
+}
+
+//this destructor must be here to let pimpl with shared_ptr work without warning
+EvasObject::~EvasObject()
+{
+}
+
+EvasObject& EvasObject::operator=(const EvasObject& other)
+{
+    Assert(m_object);
+    m_object = other.m_object;
+    return *this;
+}
+
+EvasObject* EvasObject::operator=(Evas_Object* object)
+{
+    Assert(m_object);
+    m_object->SetObject(object);
+    return this;
+}
+
+bool EvasObject::DisconnectCallback(IConnection* connection)
+{
+    Assert(m_object);
+    return m_object->DisconnectCallback(connection);
+}
+
+void EvasObject::DisconnectAll()
+{
+    Assert(m_object);
+    m_object->DisconnectAll();
+}
+
+EvasObject::operator Evas_Object *()
+{
+    Assert(m_object);
+    return m_object->GetObject();
+}
+
+}
+} // namespace DPL
+} // namespace Popup
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/evas_object.h b/src/wrt-popup/wrt/popup-bin/renderer/evas_object.h
new file mode 100644 (file)
index 0000000..b7ccda1
--- /dev/null
@@ -0,0 +1,666 @@
+/*
+ * 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        evas_object.h
+ * @author      Lukasz Wrzosek (l.wrzosel@samsung.com)
+ * @version     1.0
+ * @brief       This file is the header for Evas_Object wrapper from Efl.
+ */
+
+#ifndef WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
+#define WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
+
+#include <Evas.h>
+#include <dpl/noncopyable.h>
+#include <dpl/framework_efl.h>
+#include <dpl/assert.h>
+#include <dpl/foreach.h>
+#include <dpl/apply.h>
+#include <set>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <memory>
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+class EvasObject
+{
+    class EvasObjectShared;
+    typedef std::shared_ptr<EvasObjectShared> EvasObjectSharedPtr;
+
+  public:
+    class IConnection
+    {
+      public:
+        Evas_Object* GetEvasObject();
+        void Disconnect();
+
+      private:
+        IConnection(EvasObjectShared* object);
+        virtual ~IConnection()
+        {
+        }
+        virtual void Call(void* /*event_info*/) = 0;
+
+        static void SmartCallbackWrapper(void* data,
+                Evas_Object* /*object*/,
+                void* event_info);
+        static void EvasCallbackWrapper(void* data,
+                Evas* /*evas*/,
+                Evas_Object* /*object*/,
+                void* event_info);
+
+        virtual void ConnectPrv() = 0;
+        virtual void DisconnectPrv() = 0;
+
+        friend class EvasObjectShared;
+
+        EvasObjectShared* m_object;
+    };
+
+  private:
+    class EvasObjectShared : DPL::Noncopyable
+    {
+      public:
+        friend class IConnection;
+        Evas_Object* GetObject();
+
+        typedef std::set<IConnection*> IConnectionsSet;
+
+        class SmartConnectionBase : public IConnection
+        {
+          public:
+            SmartConnectionBase(const std::string& name,
+                    EvasObjectShared* object);
+
+            virtual void ConnectPrv();
+            virtual void DisconnectPrv();
+            std::string m_callbackName;
+        };
+
+        template<typename ... Args>
+        class SmartConnection : public SmartConnectionBase
+        {
+          public:
+            typedef void (*CbType)(IConnection* connection,
+                                   void* event_info,
+                                   Args ... args);
+
+            SmartConnection(const std::string& name,
+                    CbType callback,
+                    EvasObjectShared* object,
+                    Args ... args) :
+                SmartConnectionBase(name, object),
+                m_callback(callback),
+                m_args(args ...)
+            {
+            }
+
+            virtual ~SmartConnection()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                DPL::Apply<void,
+                           DPL::ExtraArgsInsertPolicy::Prepend>(m_callback,
+                                                                m_args,
+                                                                this,
+                                                                event_info);
+            }
+
+          private:
+            CbType m_callback;
+            std::tuple<Args ...> m_args;
+        };
+
+        template <class ThisType, class ArgType1>
+        class SmartMemberConnection1 : public SmartConnectionBase
+        {
+          public:
+            typedef void (ThisType::*CbType)(IConnection* connection,
+                                             void* event_info, ArgType1 *arg1);
+
+            SmartMemberConnection1(const std::string& name,
+                    CbType callback,
+                    ThisType* callee,
+                    ArgType1* arg1,
+                    EvasObjectShared* object) :
+                SmartConnectionBase(name, object),
+                m_callback(callback),
+                m_callee(callee),
+                m_arg1(arg1)
+            {
+            }
+
+            virtual ~SmartMemberConnection1()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                (m_callee->*m_callback)(this, event_info, m_arg1);
+            }
+
+          private:
+            CbType m_callback;
+            ThisType* m_callee;
+            ArgType1* m_arg1;
+        };
+
+        template <class ThisType, class ArgType1, class ArgType2>
+        class SmartMemberConnection2 : public SmartConnectionBase
+        {
+          public:
+            typedef void (ThisType::*CbType)(IConnection* connection,
+                                             void* event_info, ArgType1 *arg1,
+                                             ArgType2* arg2);
+
+            SmartMemberConnection2(const std::string& name,
+                    CbType callback,
+                    ThisType* callee,
+                    ArgType1* arg1,
+                    ArgType2* arg2,
+                    EvasObjectShared* object) :
+                SmartConnectionBase(name, object),
+                m_callback(callback),
+                m_callee(callee),
+                m_arg1(arg1),
+                m_arg2(arg2)
+            {
+            }
+
+            virtual ~SmartMemberConnection2()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
+            }
+
+          private:
+            CbType m_callback;
+            ThisType* m_callee;
+            ArgType1* m_arg1;
+            ArgType2* m_arg2;
+        };
+
+        class EvasConnectionBase : public IConnection
+        {
+          public:
+            EvasConnectionBase(Evas_Callback_Type type,
+                    EvasObjectShared* object);
+
+            virtual void ConnectPrv();
+            virtual void DisconnectPrv();
+
+            Evas_Callback_Type m_callbackType;
+        };
+
+        template <class ArgType1>
+        class EvasConnection1 : public EvasConnectionBase
+        {
+          public:
+            typedef void (*CbType)(IConnection* connection, void* event_info,
+                                   ArgType1 *arg1);
+
+            EvasConnection1(Evas_Callback_Type type,
+                    CbType callback,
+                    ArgType1* arg1,
+                    EvasObjectShared* object) :
+                EvasConnectionBase(type, object),
+                m_callback(callback),
+                m_arg1(arg1)
+            {
+            }
+
+            virtual ~EvasConnection1()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                m_callback(this, event_info, m_arg1);
+            }
+
+          private:
+            CbType m_callback;
+            ArgType1* m_arg1;
+        };
+
+        template <class ArgType1, class ArgType2>
+        class EvasConnection2 : public EvasConnectionBase
+        {
+          public:
+            typedef void (*CbType)(IConnection* connection, void* event_info,
+                                   ArgType1 *arg1, ArgType2 *arg2);
+
+            EvasConnection2(Evas_Callback_Type type,
+                    CbType callback,
+                    ArgType1* arg1,
+                    ArgType2* arg2,
+                    EvasObjectShared* object) :
+                EvasConnectionBase(type, object),
+                m_callback(callback),
+                m_arg1(arg1),
+                m_arg2(arg2)
+            {
+            }
+
+            virtual ~EvasConnection2()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                m_callback(this, event_info, m_arg1, m_arg2);
+            }
+
+          private:
+            CbType m_callback;
+            ArgType1* m_arg1;
+            ArgType2* m_arg2;
+        };
+
+        template <class ThisType, class ArgType1>
+        class EvasMemberConnection1 : public EvasConnectionBase
+        {
+          public:
+            typedef void (ThisType::*CbType)(IConnection* connection,
+                                             void* event_info, ArgType1 *arg1);
+
+            EvasMemberConnection1(Evas_Callback_Type type,
+                    CbType callback,
+                    ThisType* callee,
+                    ArgType1* arg1,
+                    EvasObjectShared* object) :
+                EvasConnectionBase(type, object),
+                m_callback(callback),
+                m_callee(callee),
+                m_arg1(arg1)
+            {
+            }
+
+            virtual ~EvasMemberConnection1()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                (m_callee->*m_callback)(this, event_info, m_arg1);
+            }
+
+          private:
+            CbType m_callback;
+            ThisType* m_callee;
+            ArgType1* m_arg1;
+        };
+
+        template <class ThisType, class ArgType1, class ArgType2>
+        class EvasMemberConnection2 : public EvasConnectionBase
+        {
+          public:
+            typedef void (ThisType::*CbType)(IConnection* connection,
+                                             void* event_info, ArgType1* arg1,
+                                             ArgType2* arg2);
+
+            EvasMemberConnection2(Evas_Callback_Type type,
+                    CbType callback,
+                    ThisType* callee,
+                    ArgType1* arg1,
+                    ArgType2* arg2,
+                    EvasObjectShared* object) :
+                EvasConnectionBase(type, object),
+                m_callback(callback),
+                m_callee(callee),
+                m_arg1(arg1),
+                m_arg2(arg2)
+            {
+            }
+
+            virtual ~EvasMemberConnection2()
+            {
+            }
+
+            virtual void Call(void* event_info)
+            {
+                (m_callee->*m_callback)(this, event_info, m_arg1, m_arg2);
+            }
+
+          private:
+            CbType m_callback;
+            ThisType* m_callee;
+            ArgType1* m_arg1;
+            ArgType2* m_arg2;
+        };
+
+        EvasObjectShared();
+        explicit EvasObjectShared(Evas_Object* object);
+        void SetObject(Evas_Object* object);
+        ~EvasObjectShared();
+
+        template<typename ... Args>
+        IConnection* ConnectSmartCallback(const char* callbackName,
+                typename SmartConnection<Args ...>::CbType callback,
+                Args ... args)
+        {
+            Assert(m_object);
+            Assert(callbackName);
+            Assert(callback);
+            IConnection* connection = new SmartConnection<Args ...>(
+                    callbackName,
+                    callback,
+                    this,
+                    args ...);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        template <class ThisType, class ArgType1, class ArgType2>
+        IConnection* ConnectMemberSmartCallback(
+                const char* callbackName,
+                typename SmartMemberConnection2<ThisType, ArgType1,
+                                                ArgType2>::CbType callback,
+                ThisType* callee,
+                ArgType1* arg1,
+                ArgType2* arg2)
+        {
+            Assert(m_object);
+            Assert(callee);
+            Assert(callbackName);
+            Assert(callback);
+            IConnection* connection =
+                new SmartMemberConnection2<ThisType, ArgType1, ArgType2>(
+                    callbackName,
+                    callback,
+                    callee,
+                    arg1,
+                    arg2,
+                    this);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        template <class ThisType, class ArgType1>
+        IConnection* ConnectMemberSmartCallback(
+                const char* callbackName,
+                typename SmartMemberConnection1<ThisType,
+                                                ArgType1>::CbType callback,
+                ThisType* callee,
+                ArgType1* arg1)
+        {
+            Assert(m_object);
+            Assert(callee);
+            Assert(callbackName);
+            Assert(callback);
+            IConnection* connection =
+                new SmartMemberConnection1<ThisType, ArgType1>(callbackName,
+                                                               callback,
+                                                               callee,
+                                                               arg1,
+                                                               this);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        template <class ArgType1, class ArgType2>
+        IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
+                typename EvasConnection2<ArgType1, ArgType2>::CbType callback,
+                ArgType1* arg1,
+                ArgType2* arg2)
+        {
+            Assert(m_object);
+            Assert(callbackType);
+            Assert(callback);
+            IConnection* connection = new EvasConnection2<ArgType1, ArgType2>(
+                    callbackType,
+                    callback,
+                    arg1,
+                    arg2,
+                    this);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        template <class ArgType1>
+        IConnection* ConnectEvasCallback(Evas_Callback_Type callbackType,
+                typename EvasConnection1<ArgType1>::CbType callback,
+                ArgType1* arg1)
+        {
+            Assert(m_object);
+            Assert(callbackType);
+            Assert(callback);
+            IConnection* connection = new EvasConnection1<ArgType1>(
+                    callbackType,
+                    callback,
+                    arg1,
+                    this);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        template <class ThisType, class ArgType1, class ArgType2>
+        IConnection* ConnectMemberEvasCallback(
+                Evas_Callback_Type callbackType,
+                typename EvasMemberConnection2<ThisType, ArgType1,
+                                               ArgType2>::CbType callback,
+                ThisType* callee,
+                ArgType1* arg1,
+                ArgType2* arg2)
+        {
+            Assert(m_object);
+            Assert(callee);
+            Assert(callbackType);
+            Assert(callback);
+            IConnection* connection =
+                new EvasMemberConnection2<ThisType, ArgType1, ArgType2>(
+                    callbackType,
+                    callback,
+                    callee,
+                    arg1,
+                    arg2,
+                    this);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        template <class ThisType, class ArgType1>
+        IConnection* ConnectMemberEvasCallback(
+                Evas_Callback_Type callbackType,
+                typename EvasMemberConnection1<ThisType,
+                                               ArgType1>::CbType callback,
+                ThisType* callee,
+                ArgType1* arg1)
+        {
+            Assert(m_object);
+            Assert(callee);
+            Assert(callbackType);
+            Assert(callback);
+            IConnection* connection =
+                new EvasMemberConnection1<ThisType, ArgType1>(callbackType,
+                                                              callback,
+                                                              callee,
+                                                              arg1,
+                                                              this);
+            m_connections.insert(connection);
+            connection->ConnectPrv();
+            return connection;
+        }
+
+        bool DisconnectCallback(IConnection* connection);
+        void DisconnectAll();
+
+        static void StaticOnDelEvent(void* data,
+                Evas* /*e*/,
+                Evas_Object* /*o*/,
+                void* /*ev*/);
+
+        IConnectionsSet m_connections;
+        Evas_Object* m_object;
+    };
+
+  public:
+    EvasObject();
+    explicit EvasObject(Evas_Object* object);
+    EvasObject(const EvasObject& other);
+    ~EvasObject();
+
+    EvasObject& operator=(const EvasObject& other);
+    EvasObject* operator=(Evas_Object* object);
+
+    operator Evas_Object *();
+
+    bool IsValid() const
+    {
+        Assert(m_object);
+        return m_object->GetObject() != NULL;
+    }
+
+    bool DisconnectCallback(IConnection* connection);
+    void DisconnectAll();
+
+    template <class ... Args>
+    IConnection* ConnectSmartCallback(
+            const char* callbackName,
+            typename EvasObjectShared::SmartConnection<Args ...>::CbType
+            callback,
+            Args ... args)
+    {
+        Assert(m_object);
+        return m_object->ConnectSmartCallback(callbackName, callback, args ...);
+    }
+
+    template <class ThisType, class ArgType1, class ArgType2>
+    IConnection* ConnectMemberSmartCallback(
+            const char* callbackName,
+            typename EvasObjectShared::SmartMemberConnection2<ThisType,
+                                                              ArgType1,
+                                                              ArgType2>::CbType
+            callback,
+            ThisType* callee,
+            ArgType1* arg1,
+            ArgType2* arg2)
+    {
+        Assert(m_object);
+        Assert(callee);
+        Assert(callback);
+        return m_object->ConnectMemberSmartCallback(callbackName,
+                                                    callback,
+                                                    callee,
+                                                    arg1,
+                                                    arg2);
+    }
+
+    template <class ThisType, class ArgType1>
+    IConnection* ConnectMemberSmartCallback(
+            const char* callbackName,
+            typename EvasObjectShared::SmartMemberConnection1<ThisType,
+                                                              ArgType1>::CbType
+            callback,
+            ThisType* callee,
+            ArgType1* arg1)
+    {
+        Assert(m_object);
+        Assert(callee);
+        Assert(callback);
+        return m_object->ConnectMemberSmartCallback(callbackName,
+                                                    callback,
+                                                    callee,
+                                                    arg1);
+    }
+
+    template <class ArgType1, class ArgType2>
+    IConnection* ConnectEvasCallback(
+            Evas_Callback_Type callbackType,
+            typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
+            callback,
+            ArgType1* arg1,
+            ArgType2* arg2)
+    {
+        Assert(m_object);
+        return m_object->ConnectEvasCallback(callbackType, callback, arg1, arg2);
+    }
+
+    template <class ArgType1>
+    IConnection* ConnectEvasCallback(
+            Evas_Callback_Type callbackType,
+            typename EvasObjectShared::EvasConnection1<ArgType1>::CbType
+            callback,
+            ArgType1* arg1)
+    {
+        Assert(m_object);
+        return m_object->ConnectEvasCallback(callbackType, callback, arg1);
+    }
+
+    template <class ThisType, class ArgType1>
+    IConnection* ConnectMemberEvasCallback(
+            Evas_Callback_Type callbackType,
+            typename EvasObjectShared::EvasMemberConnection1<ThisType,
+                                                             ArgType1>::CbType
+            callback,
+            ThisType* callee,
+            ArgType1* arg1)
+    {
+        Assert(m_object);
+        Assert(callee);
+        Assert(callback);
+        return m_object->ConnectMemberEvasCallback(callbackType,
+                                                   callback,
+                                                   callee,
+                                                   arg1);
+    }
+
+    template <class ThisType, class ArgType1, class ArgType2>
+    IConnection* ConnectMemberEvasCallback(
+            Evas_Callback_Type callbackType,
+            typename EvasObjectShared::EvasMemberConnection2<ThisType, ArgType1,
+                                                             ArgType2>::CbType
+            callback,
+            ThisType* callee,
+            ArgType1* arg1,
+            ArgType2* arg2)
+    {
+        Assert(m_object);
+        Assert(callee);
+        Assert(callback);
+        return m_object->ConnectMemberEvasCallback(callbackType,
+                                                   callback,
+                                                   callee,
+                                                   arg1,
+                                                   arg2);
+    }
+
+  private:
+    EvasObjectSharedPtr m_object;
+};
+
+}
+}//namespace
+}//namespace
+
+
+#endif //WRT_SRC_DOMAIN_EFL_EVAS_OBJECT_H
+
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup.h b/src/wrt-popup/wrt/popup-bin/renderer/popup.h
new file mode 100644 (file)
index 0000000..3b2e867
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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        popup.h
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version     1.0
+ * @brief       This is popup inteface declaration
+ */
+
+#ifndef WRT_SRC_POPUP_POPUP_H_
+#define WRT_SRC_POPUP_POPUP_H_
+
+#include <memory>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <string>
+#include <dpl/optional.h>
+#include "popup_object.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+struct AnswerCallbackData
+{
+    int buttonAnswer;
+    DPL::Optional<std::string> password;
+    bool chackState;
+};
+
+class PopupManager;
+class IPopup;
+typedef std::shared_ptr<IPopup> IPopupPtr;
+
+class IPopup : public std::enable_shared_from_this<IPopup>
+{
+  public:
+    virtual void SetTitle(const std::string &title) = 0;
+    /*The object is deleted automatically after rendered */
+    virtual void Append(PopupObject::IPopupObject *object) = 0;
+
+  protected:
+    typedef void (*PopupCallbackType)(const AnswerCallbackData& answer,
+                                      void *data);
+    virtual void Show(PopupCallbackType callback,
+            void* data) = 0;
+    virtual ~IPopup()
+    {
+    }
+
+  private:
+    friend class PopupManager;
+    friend class std::shared_ptr<IPopup>;
+};
+
+}
+} // namespace Popup
+} // namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUP_H_
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_controller.cpp b/src/wrt-popup/wrt/popup-bin/renderer/popup_controller.cpp
new file mode 100644 (file)
index 0000000..eaafaff
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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    popup_controller.cpp
+ * @author  Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @bref    Implementation file for popup controller
+ */
+
+#include "popup_controller.h"
+#include <stddef.h>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(Wrt::Popup::Renderer::PopupController)
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+void CtrlPopup::SetTitle(const std::string &title)
+{
+    Assert(m_popup);
+    m_popup->SetTitle(title);
+}
+
+void CtrlPopup::Append(PopupObject::IPopupObject *object)
+{
+    Assert(m_popup);
+    m_popup->Append(object);
+}
+
+CtrlPopup::CtrlPopup(IPopupPtr popup) :
+    m_popup(popup),
+    m_callback()
+{
+    Assert(m_popup);
+}
+
+CtrlPopup::~CtrlPopup()
+{
+}
+
+void CtrlPopup::EmitAnswer(const AnswerCallbackData & answer)
+{
+    AnswerCallbackData l_answer = answer;
+    PopupAnswerEvent event(shared_from_this(), m_callback, l_answer);
+    DPL::Event::EventSupport<PopupAnswerEvent>::EmitEvent(event);
+}
+
+PopupController::PopupController() : m_canvas(NULL)
+{
+}
+
+CtrlPopupPtr PopupController::CreatePopup() const
+{
+    return CtrlPopupPtr(
+               new CtrlPopup(PopupManagerSingleton::Instance().CreatePopup()));
+}
+
+void PopupController::OnEventReceived(const ShowPopupEventShort& event)
+{
+    CtrlPopupPtr popup = event.GetArg0();
+    popup->m_callback = event.GetArg1();
+
+    //pass canvas from controller to manager
+    //canvas is not passed earlier because value wasn't set properly
+    PopupManagerSingleton::Instance().setExternalCanvas(getExternalCanvas());
+
+    PopupManagerSingleton::Instance().RunAsyncWithArgType(
+        popup->m_popup,
+        &PopupController::StaticOnAnswerReceived,
+        new CtrlPopupPtr(popup));
+}
+
+void PopupController::StaticOnAnswerReceived(const AnswerCallbackData & answer,
+        CtrlPopupPtr* popup)
+{
+    Assert(popup != NULL);
+    (*popup)->EmitAnswer(answer);
+    delete popup; // Just SharedPtr is destroyed, not the popup itself
+}
+
+void PopupControllerUser::OnEventReceived(const PopupAnswerEvent& event)
+{
+    //Here we are in a proper context to call the callback
+    PopupAnswerCallback answerCall = event.GetArg1();
+    AnswerCallbackData answer = event.GetArg2();
+    answerCall.Call(answer);
+    event.GetArg0()->DPL::Event::EventSupport<PopupAnswerEvent>::RemoveListener(this);
+}
+
+void PopupControllerUser::ListenForAnswer(CtrlPopupPtr popup)
+{
+    popup->DPL::Event::EventSupport<PopupAnswerEvent>::AddListener(this);
+}
+
+}
+} //namespace Popup
+} //namespace Wrt
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_controller.h b/src/wrt-popup/wrt/popup-bin/renderer/popup_controller.h
new file mode 100644 (file)
index 0000000..eea2d0d
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * 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    popup_controller.h
+ * @author  Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version 1.0
+ * @bref    Header file for popup controller
+ */
+
+/**
+ * To display a popup from a given class:
+ *
+ **class ABC
+ **{
+ *    void AskUser()
+ *    {
+ *    }
+ *
+ *    void DoSomeLogicWithAnswer()
+ *    {
+ *    }
+ **};
+ *
+ * ... update the class to something simmilar:
+ *
+ **class ABC : Popup::PopupControllerUser
+ **{
+ *    void AskUser() {
+ *        using namespace Popup;
+ *        CtrlPopupPtr popup =
+ *                PopupControllerSingletion::Instance().CreatePopup();
+ *        popup->SetTitle("Title");
+ *        popup->SetContent("Content");
+ *        popup->AddButton("name1", 1);
+ *        popup->AddButton("name2", 2);
+ *        ListenForAnswer(popup);
+ *        ShowPopupEvent event(popup,
+ *                             MakeAnswerCallback(this,
+ *                                                &ABC::DoSomeLogicWithAnswer));
+ *        CONTROLLER_POST_EVENT(PopupController, event);
+ *    }
+ *
+ *    void DoSomeLogicWithAnswer(Popup::LabelId answer) {
+ *        if (answer == 1)
+ *            ;//name1 pressed
+ *        else if (answer == 2)
+ *            ;//name2 pressed
+ *    }
+ **};
+ **/
+
+#ifndef WRT_SRC_POPUP_CONTROLLER_POPUP_CONTROLLER_H_
+#define WRT_SRC_POPUP_CONTROLLER_POPUP_CONTROLLER_H_
+
+#include <memory>
+#include <dpl/singleton.h>
+#include <dpl/event/controller.h>
+#include <dpl/event/event_listener.h>
+#include <dpl/generic_event.h>
+#include <dpl/mutex.h>
+#include <dpl/exception.h>
+#include <dpl/noncopyable.h>
+#include <dpl/log/log.h>
+#include "popup_manager.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+typedef int LabelId;
+
+struct PopupAnswerCallback
+{
+    typedef void (PopupAnswerCallback::*MemberPtr)();
+
+    void* callee;
+    MemberPtr member;
+    void (*callTranslator)(PopupAnswerCallback* callData,
+            const AnswerCallbackData& answer);
+
+    void Call(const AnswerCallbackData& answer)
+    {
+        callTranslator(this, answer);
+    }
+};
+
+class PopupController;
+class CtrlPopup;
+
+typedef std::shared_ptr<CtrlPopup> CtrlPopupPtr;
+
+DECLARE_GENERIC_EVENT_3(PopupAnswerEvent,
+                        CtrlPopupPtr,
+                        PopupAnswerCallback,
+                        AnswerCallbackData)
+
+DECLARE_GENERIC_EVENT_2(ShowPopupEventShort,
+                        CtrlPopupPtr,
+                        PopupAnswerCallback)
+
+class CtrlPopup : public DPL::Event::EventSupport<PopupAnswerEvent>,
+    public std::enable_shared_from_this<CtrlPopup>
+{
+  public:
+    void SetTitle(const std::string &title);
+    void Append(PopupObject::IPopupObject *object);
+
+    ~CtrlPopup();
+  private:
+    friend class PopupController;
+    friend class std::shared_ptr<CtrlPopup>;
+
+    explicit CtrlPopup(IPopupPtr popup);
+    void EmitAnswer(const AnswerCallbackData& answer);
+
+    IPopupPtr m_popup;
+    PopupAnswerCallback m_callback;
+};
+
+class PopupController :
+    public DPL::Event::Controller<DPL::TypeListDecl<ShowPopupEventShort>::Type>
+{
+  public:
+    CtrlPopupPtr CreatePopup() const;
+
+    void setExternalCanvas(void* canvas)
+    {
+        m_canvas = canvas;
+    }
+    void* getExternalCanvas() const
+    {
+        return m_canvas;
+    }
+    void* m_canvas;
+
+  protected:
+    virtual void OnEventReceived(const ShowPopupEventShort& event);
+    PopupController();
+
+  private:
+    static void StaticOnAnswerReceived(const AnswerCallbackData& answer,
+            CtrlPopupPtr* popup);
+};
+
+class PopupControllerUser : DPL::Event::EventListener<PopupAnswerEvent>
+{
+    template <class Type>
+    struct PopupAnswerCallbackCreator
+    {
+        typedef void (Type::*MemberPtr)(const AnswerCallbackData& answer);
+        union Caster
+        {
+            MemberPtr specific;
+            PopupAnswerCallback::MemberPtr generic;
+        };
+
+        static PopupAnswerCallback Create(Type* callee,
+                MemberPtr callback)
+        {
+            PopupAnswerCallback callData;
+
+            callData.callee = callee;
+
+            Caster caster;
+            caster.specific = callback;
+            callData.member = caster.generic;
+
+            callData.callTranslator =
+                &PopupAnswerCallbackCreator::MemberCallbackTranslator;
+
+            return callData;
+        }
+
+        static void MemberCallbackTranslator(PopupAnswerCallback* callData,
+                const AnswerCallbackData& answer)
+        {
+            Type* typedThis = static_cast<Type*>(callData->callee);
+            Caster caster;
+            caster.generic = callData->member;
+            MemberPtr typedCallback = caster.specific;
+            (typedThis->*typedCallback)(answer);
+        }
+    };
+
+  protected:
+    virtual void OnEventReceived(const PopupAnswerEvent& event);
+    void ListenForAnswer(CtrlPopupPtr popup);
+
+    template <class Type>
+    PopupAnswerCallback MakeAnswerCallback(Type* This,
+            void (Type::*callback)
+            (const AnswerCallbackData &))
+    {
+        return PopupAnswerCallbackCreator<Type>::Create(This, callback);
+    }
+};
+
+typedef DPL::Singleton<PopupController> PopupControllerSingleton;
+
+}
+} //namespace Popup
+} //namespace Wrt
+
+#endif //WRT_SRC_POPUP_CONTROLLER_POPUP_CONTROLLER_H_
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_manager.cpp b/src/wrt-popup/wrt/popup-bin/renderer/popup_manager.cpp
new file mode 100644 (file)
index 0000000..e50c530
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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        popup_manager.cpp
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version     1.0
+ * @brief       This is popup_manager implementation file
+ */
+
+#include "popup_manager.h"
+#include <stddef.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dpl/singleton_impl.h>
+#include "popup.h"
+
+IMPLEMENT_SINGLETON(Wrt::Popup::Renderer::PopupManager)
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+void PopupManager::Initialize(PopupRendererPtr renderer)
+{
+    Assert(!m_initialized);
+    m_popupRenderer = renderer;
+    m_popupRenderer->Initialize();
+    m_initialized = true;
+}
+
+void PopupManager::Deinitialize()
+{
+    m_popupRenderer->Deinitialize();
+    Assert(m_initialized);
+    m_popupRenderer.reset();
+    m_initialized = false;
+}
+
+IPopupPtr PopupManager::CreatePopup()
+{
+    Assert(m_initialized);
+    return m_popupRenderer->CreatePopup();
+}
+
+}
+} // namespace Popup
+} // namespace Wrt
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_manager.h b/src/wrt-popup/wrt/popup-bin/renderer/popup_manager.h
new file mode 100644 (file)
index 0000000..4b90ace
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * 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        popup_manager.h
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version     1.0
+ * @brief       This is popup_manager declaration file
+ */
+
+#ifndef WRT_SRC_POPUP_POPUP_MANAGER_H_
+#define WRT_SRC_POPUP_POPUP_MANAGER_H_
+
+#include <memory>
+#include <dpl/assert.h>
+#include <dpl/noncopyable.h>
+#include <dpl/singleton.h>
+#include <dpl/optional.h>
+#include <dpl/log/log.h>
+#include "popup.h"
+#include "popup_renderer.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+class PopupManager : DPL::Noncopyable
+{
+    template <class ArgType>
+    struct TemplatedPopupCallback
+    {
+        typedef void (*Type)(const AnswerCallbackData& answer, ArgType* data);
+    };
+
+  public:
+    PopupManager() : m_initialized(false) {}
+    ~PopupManager()
+    {
+        if (m_initialized) {
+            LogError("Destroyed without Deinitialize");
+        }
+    }
+    void Initialize (PopupRendererPtr creator);
+    void Deinitialize();
+    void SetPopupRenderer (PopupRendererPtr creator);
+    IPopupPtr CreatePopup();
+
+    template <class ArgType>
+    void RunAsyncWithArgType(IPopupPtr popup,
+            typename TemplatedPopupCallback<ArgType>::Type callback,
+            ArgType* argument)
+    {
+        Assert(callback);
+        WrapCbAndArg<ArgType>* wrapped =
+            new WrapCbAndArg<ArgType>(callback, argument);
+        popup->Show(&CallbackArgTypeTranslator<ArgType>, wrapped);
+    }
+
+    void Show(IPopupPtr popup,
+            IPopup::PopupCallbackType callback,
+            void* userdata)
+    {
+        popup->Show(callback, userdata);
+    }
+
+    void setExternalCanvas(void* externalCanvas)
+    {
+        Assert(m_initialized && "Manger should be initialized");
+        m_popupRenderer->setExternalCanvas(externalCanvas);
+    }
+
+  private:
+    template <class ArgType>
+    struct WrapCbAndArg
+    {
+        WrapCbAndArg(typename TemplatedPopupCallback<ArgType>::Type cb,
+                ArgType* arg) :
+            callback(cb),
+            argument(arg)
+        {
+        }
+
+        typename TemplatedPopupCallback<ArgType>::Type callback;
+        ArgType* argument;
+    };
+
+    template <class ArgType>
+    static void CallbackArgTypeTranslator(const AnswerCallbackData & answer,
+            void* data)
+    {
+        WrapCbAndArg<ArgType>* wrapped =
+            static_cast< WrapCbAndArg<ArgType>* >(data);
+        wrapped->callback(answer, wrapped->argument);
+        delete wrapped;
+    }
+
+    bool m_initialized;
+    PopupRendererPtr m_popupRenderer;
+};
+
+typedef DPL::Singleton<PopupManager> PopupManagerSingleton;
+
+}
+} // namespace Popup
+} // namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUP_MANAGER_H_
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_object.h b/src/wrt-popup/wrt/popup-bin/renderer/popup_object.h
new file mode 100644 (file)
index 0000000..090b874
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * 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        popup_object.h
+ * @author      Justyna Mejzner (j.mejzner@samsung.com)
+ * @version     1.0
+ * @brief       This is declaration file of PopupObject
+ */
+
+#ifndef WRT_SRC_POPUP_POPUPOBJECT_H_
+#define WRT_SRC_POPUP_POPUPOBJECT_H_
+
+#include <dpl/foreach.h>
+
+#include <list>
+#include <string>
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+namespace PopupObject {
+class IPopupObject;
+class PopupObjectBase;
+class Button;
+class Label;
+class Check;
+
+typedef std::list<IPopupObject*> PopupObjects;
+
+enum PopupType
+{
+    BUTTON,
+    LABEL,
+    CHECK
+};
+
+class IPopupObject
+{
+  public:
+    virtual Button* asButton() = 0;
+    virtual Label* asLabel() = 0;
+    virtual Check* asCheck() = 0;
+    virtual PopupType getType() const = 0;
+    virtual ~IPopupObject()
+    {
+    }
+};
+
+class PopupObjectBase : public IPopupObject
+{
+  public:
+    virtual Button* asButton()
+    {
+        Assert("wrong type");
+        return NULL;
+    }
+    virtual Label* asLabel()
+    {
+        Assert("wrong type");
+        return NULL;
+    }
+    virtual Check* asCheck()
+    {
+        Assert("wrong type");
+        return NULL;
+    }
+
+    PopupType getType() const
+    {
+        return m_type;
+    }
+
+  protected:
+    PopupObjectBase(PopupType type) : m_type(type)
+    {
+    }
+
+    PopupType m_type;
+};
+
+class Button : public PopupObjectBase
+{
+  public:
+    Button(const std::string& label,
+            int labelId) :
+        PopupObjectBase(BUTTON),
+        m_label(label),
+        m_labelId(labelId)
+    {
+    }
+
+    Button* asButton()
+    {
+        return this;
+    }
+
+    const std::string& getLabel() const
+    {
+        return m_label;
+    }
+
+    int getLabelId() const
+    {
+        return m_labelId;
+    }
+
+  private:
+    std::string m_label;
+    int m_labelId;
+};
+
+class Label : public PopupObjectBase
+{
+  public:
+    Label(const std::string &label) :
+        PopupObjectBase(LABEL),
+        m_label(label)
+    {
+    }
+
+    Label* asLabel()
+    {
+        return this;
+    }
+
+    const std::string& getLabel() const
+    {
+        return m_label;
+    }
+
+  private:
+    std::string m_label;
+};
+
+class Check : public PopupObjectBase
+{
+  public:
+    Check(const std::string &label) :
+        PopupObjectBase(CHECK),
+        m_checkLabel(label)
+    {
+    }
+
+    Check* asCheck()
+    {
+        return this;
+    }
+
+    const std::string& getCheckLabel() const
+    {
+        return m_checkLabel;
+    }
+
+  private:
+    std::string m_checkLabel;
+};
+} /*PopupObject*/
+
+}
+}//namespace Popup
+}//namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUPOBJECT_H_
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp b/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.cpp
new file mode 100644 (file)
index 0000000..ed00236
--- /dev/null
@@ -0,0 +1,419 @@
+/*
+ * 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        popup_renderer.cpp
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version     1.0
+ * @brief       This is efl specific implementation for PopupRenderer
+ */
+
+#include "popup_renderer.h"
+#include <stddef.h>
+#include <dpl/scoped_array.h>
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/framework_efl.h>
+#include <dpl/lexical_cast.h>
+#include <queue>
+#include "popup_manager.h"
+#include "popup_manager.h"
+#include "evas_object.h"
+
+namespace Wrt {
+
+namespace {
+using namespace Popup;
+const char* EDJ_NAME = "/usr/share/edje/ace/generic_popup.edj";
+const char* POPUP_LAYOUT1 = "popup_layout1";
+const char* POPUP_LAYOUT2 = "popup_layout2";
+const char* POPUP_PART_TITLE = "title,text";
+const char* POPUP_PART_BUTTON1 = "button1";
+const char* POPUP_PART_BUTTON2 = "button2";
+const char* POPUP_PART_BUTTON3 = "button3";
+const char* BUTTON_CLICKED_CALLBACK_NAME = "clicked";
+const char* CHANGED_CALLBACK_NAME = "changed";
+const unsigned int MAX_NUMBER_OF_VERTICAL = 2;
+
+Evas_Object* create_layout_main(Evas_Object* parent, int totalV)
+{
+    Evas_Object *layout = elm_layout_add(parent);
+
+    if (totalV == 1) {
+        elm_layout_file_set(layout, EDJ_NAME, POPUP_LAYOUT1);
+    } else if (totalV == 2) {
+        elm_layout_file_set(layout, EDJ_NAME, POPUP_LAYOUT2);
+    } else {
+        Assert("popup needs define new group in the edc");
+    }
+
+    evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
+                                     EVAS_HINT_EXPAND);
+    return layout;
+}
+} //namespace
+
+namespace Popup {
+namespace Renderer {
+
+class PopupRenderer::Impl
+{
+  public:
+    Impl() :
+        m_popupsToRender(),
+        m_current(),
+        m_initialized(false)
+    {
+    }
+
+    ~Impl()
+    {
+        if (m_initialized) {
+            LogError("Destroyed without Deinitialize");
+        }
+    }
+
+    void Initialize()
+    {
+        Assert(!m_initialized);
+        m_initialized = true;
+    }
+
+    void Deinitialize()
+    {
+        Assert(m_initialized);
+        m_current.reset();
+        while (!m_popupsToRender.empty()) {
+            m_popupsToRender.pop();
+        }
+        m_initialized = false;
+    }
+
+    void ButtonCallback(EvasObject::IConnection* /*connection*/,
+            void* /*event_info*/,
+            void* data)
+    {
+        LogInfo("ButtonCallback");
+        Assert(m_initialized);
+        AnswerCallbackData answerData;
+
+        answerData.buttonAnswer = reinterpret_cast<int>(data);
+        answerData.chackState = m_checkState;
+        answerData.password = m_password;
+        m_current->ForwardAnswer(answerData);
+        m_current.reset();
+
+        FOREACH(it, m_createdObjects)
+        {
+            if (it->IsValid()) {
+                evas_object_del(*it);
+            }
+        }
+        m_createdObjects.clear();
+        m_checkState = false;
+        DoRender();
+    }
+
+    void CheckCallback(EvasObject::IConnection* connection,
+            void* /*event_info*/,
+            void* /* unused */)
+    {
+        m_checkState =
+            elm_check_state_get(connection->GetEvasObject());
+    }
+
+    void Render (PopupPtr popup)
+    {
+        Assert(m_initialized);
+        m_popupsToRender.push(popup);
+        DoRender();
+    }
+
+    void DoRender(const PopupObject::Label& object,
+            EvasObject& parent,
+            EvasObject& layout,
+            int themeIndex)
+    {
+        EvasObject label(elm_label_add(parent));
+
+        elm_object_style_set(label, "popup_description/default");
+        elm_label_line_wrap_set(label, ELM_WRAP_WORD);
+        elm_object_text_set(label, object.getLabel().c_str());
+        evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
+        evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
+        evas_object_show(label);
+
+        elm_object_part_content_set(
+            layout,
+            DPL::lexical_cast<std::string>(themeIndex).c_str(),
+            label);
+        m_createdObjects.push_back(label);
+    }
+
+    void DoRender(const PopupObject::Check& object,
+            EvasObject& parent,
+            EvasObject& layout,
+            int themeIndex)
+    {
+        EvasObject check(elm_check_add(parent));
+
+        evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
+        evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
+        elm_object_text_set(check,
+                            object.getCheckLabel().c_str());
+        elm_object_part_content_set(
+            layout,
+            DPL::lexical_cast<std::string>(themeIndex).c_str(),
+            check);
+
+        check.ConnectMemberSmartCallback(CHANGED_CALLBACK_NAME,
+                                         &Impl::CheckCallback,
+                                         this,
+                                         static_cast<void*>(NULL));
+        evas_object_show(check);
+        m_createdObjects.push_back(check);
+    }
+
+    void DoRender(const PopupObject::Button& object,
+            EvasObject &parent)
+    {
+        EvasObject btn(elm_button_add(parent));
+
+        elm_object_text_set(btn, object.getLabel().c_str());
+        elm_object_part_content_set(parent, POPUP_PART_BUTTON1, btn);
+        btn.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
+                                       &Impl::ButtonCallback,
+                                       this,
+                                       reinterpret_cast<void*>(object.getLabelId()));
+        m_createdObjects.push_back(btn);
+    }
+
+    void DoRender(const PopupObject::Button& object1,
+            const PopupObject::Button& object2,
+            EvasObject &parent)
+    {
+        DoRender(object1, parent);
+
+        EvasObject btn2(elm_button_add(parent));
+
+        elm_object_text_set(btn2, object2.getLabel().c_str());
+        elm_object_part_content_set(parent, POPUP_PART_BUTTON2, btn2);
+        btn2.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
+                                        &Impl::ButtonCallback,
+                                        this,
+                                        reinterpret_cast<void*>(object2.getLabelId()));
+        m_createdObjects.push_back(btn2);
+    }
+
+    void DoRender(const PopupObject::Button& object1,
+            const PopupObject::Button& object2,
+            const PopupObject::Button& object3,
+            EvasObject &parent)
+    {
+        DoRender(object1, object2, parent);
+
+        EvasObject btn3(elm_button_add(parent));
+
+        elm_object_text_set(btn3, object3.getLabel().c_str());
+        elm_object_part_content_set(parent, POPUP_PART_BUTTON3, btn3);
+        btn3.ConnectMemberSmartCallback(BUTTON_CLICKED_CALLBACK_NAME,
+                                        &Impl::ButtonCallback,
+                                        this,
+                                        reinterpret_cast<void*>(object3.getLabelId()));
+        m_createdObjects.push_back(btn3);
+    }
+
+    EvasObject getBaseObject()
+    {
+        if (getExternalCanvas() == NULL) {
+            LogInfo("Create old style popup");
+            EvasObject win(elm_win_add(NULL, "Popup", ELM_WIN_DIALOG_BASIC));
+            elm_win_borderless_set(win, EINA_TRUE);
+            elm_win_alpha_set(win, EINA_TRUE);
+            elm_win_raise(win);
+            {
+                int w, h, x, y;
+                ecore_x_window_geometry_get(ecore_x_window_root_first_get(),
+                                            &x,
+                                            &y,
+                                            &w,
+                                            &h);
+                evas_object_resize(win, w, h);
+                evas_object_move(win, x, y);
+            }
+            m_createdObjects.push_back(win);
+            evas_object_show(win);
+            return win;
+        } else {
+            LogInfo("Create new style popup");
+            EvasObject win(getExternalCanvas());
+            evas_object_show(win);
+            return win;
+        }
+    }
+
+    void DoRender()
+    {
+        if (!m_current && !m_popupsToRender.empty()) {
+            m_current = m_popupsToRender.front();
+            m_popupsToRender.pop();
+
+            m_themeIndexV = 0;
+
+            // preprocessing
+            std::vector<int> countPopupObjects = {0 /* PopupObject::BUTTON */,
+                                                  0 /* PopupObject::LABEL */,
+                                                  0 /* PopupObject::CHECK */};
+            FOREACH(it, m_current->GetPopupObjects()) {
+                Assert((*it)->getType() < countPopupObjects.size() &&
+                    "Wrong PopupObject assigned");
+                countPopupObjects[(*it)->getType()]++;
+            }
+            int needsIndexV = countPopupObjects[PopupObject::LABEL] +
+                countPopupObjects[PopupObject::CHECK];
+
+            EvasObject win = getBaseObject();
+            EvasObject main(elm_popup_add(win));
+
+            evas_object_size_hint_weight_set(main,
+                                             EVAS_HINT_EXPAND,
+                                             EVAS_HINT_EXPAND);
+            elm_object_part_text_set(main,
+                                     POPUP_PART_TITLE,
+                                     m_current->GetTitle().c_str());
+
+            m_createdObjects.push_back(main);
+            std::vector<PopupObject::Button> buttonObjectList;
+            EvasObject layout(create_layout_main(main, needsIndexV));
+            m_createdObjects.push_back(layout);
+
+            FOREACH(it, m_current->GetPopupObjects()) {
+                switch ((*it)->getType()) {
+                case PopupObject::BUTTON:
+                    buttonObjectList.push_back(*(*it)->asButton());
+                    break;
+                case PopupObject::LABEL:
+                    DoRender(*(*it)->asLabel(),
+                             main,
+                             layout,
+                             m_themeIndexV++);
+                    break;
+                case PopupObject::CHECK:
+                    DoRender(*(*it)->asCheck(),
+                             main,
+                             layout,
+                             m_themeIndexV++);
+                    break;
+                default:
+                    Assert("incorrect type");
+                }
+                Assert(m_themeIndexV <= MAX_NUMBER_OF_VERTICAL);
+            }
+            elm_object_content_set(main,
+                                   layout);
+
+            // show buution
+            switch(buttonObjectList.size()) {
+            case 0:
+                LogInfo("no button");
+                break;
+            case 1:
+                DoRender(buttonObjectList.at(0),
+                         main);
+                break;
+            case 2:
+                DoRender(buttonObjectList.at(0),
+                         buttonObjectList.at(1),
+                         main);
+                break;
+            case 3:
+                DoRender(buttonObjectList.at(0),
+                         buttonObjectList.at(1),
+                         buttonObjectList.at(2),
+                         main);
+                break;
+            default:
+                Assert("incorrect button number");
+                break;
+            }
+
+            evas_object_show(main);
+        }
+    }
+
+    void setExternalCanvas(void* externalCanvas)
+    {
+        m_externalCanvas = static_cast<Evas_Object*>(externalCanvas);
+    }
+
+    Evas_Object* getExternalCanvas() const
+    {
+        return m_externalCanvas;
+    }
+
+    std::queue<PopupPtr> m_popupsToRender;
+    std::list<EvasObject> m_createdObjects;
+    PopupPtr m_current;
+    bool m_initialized;
+    bool m_checkState;
+    DPL::Optional<std::string> m_password;
+    unsigned int m_themeIndexV;
+
+  private:
+    Evas_Object* m_externalCanvas;
+};
+
+PopupRenderer::PopupRenderer()
+{
+    m_impl = new PopupRenderer::Impl();
+}
+
+PopupRenderer::~PopupRenderer()
+{
+    delete m_impl;
+}
+
+void PopupRenderer::Initialize()
+{
+    Assert(m_impl);
+    m_impl->Initialize();
+}
+
+void PopupRenderer::Deinitialize()
+{
+    Assert(m_impl);
+    m_impl->Deinitialize();
+}
+
+IPopupPtr PopupRenderer::CreatePopup()
+{
+    return std::static_pointer_cast<IPopup>(IPopupPtr
+                                              (new Popup(shared_from_this())));
+}
+
+void PopupRenderer::Render(PopupPtr popup)
+{
+    m_impl->Render(popup);
+}
+
+void PopupRenderer::setExternalCanvas(void* externalCanvas)
+{
+    m_impl->setExternalCanvas(externalCanvas);
+}
+
+}
+} // namespace Popup
+} // namespace Wrt
diff --git a/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.h b/src/wrt-popup/wrt/popup-bin/renderer/popup_renderer.h
new file mode 100644 (file)
index 0000000..0a34547
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * 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        popup_renderer.h
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @version     1.0
+ * @brief       This is declaration file of PopupRenderer
+ */
+
+#ifndef WRT_SRC_POPUP_POPUP_RENDERER_H_
+#define WRT_SRC_POPUP_POPUP_RENDERER_H_
+
+#include <map>
+#include <string>
+#include <memory>
+
+#include <dpl/noncopyable.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dpl/foreach.h>
+#include "popup.h"
+
+namespace Wrt {
+namespace Popup {
+namespace Renderer {
+
+class PopupRenderer : public std::enable_shared_from_this<PopupRenderer>
+{
+  public:
+    PopupRenderer();
+    ~PopupRenderer();
+    void Initialize();
+    void Deinitialize();
+    IPopupPtr CreatePopup();
+    virtual void setExternalCanvas(void* externalCanvas);
+  protected:
+    class Popup;
+    typedef std::shared_ptr<Popup> PopupPtr;
+
+    class Popup : public IPopup
+    {
+      public:
+        typedef std::map<int, std::string> ButtonMap;
+        virtual void SetTitle(const std::string &title)
+        {
+            LogDebug(title);
+            Assert(m_title.empty());
+            m_title = title;
+        }
+
+        virtual void Append(PopupObject::IPopupObject *object)
+        {
+            m_popupObjectList.push_back(object);
+        }
+
+        virtual void Show(IPopup::PopupCallbackType callback,
+                void* data)
+        {
+            Assert(callback);
+            m_data = data;
+            m_callback = callback;
+            m_renderer->Render(std::static_pointer_cast<Popup>(shared_from_this()));
+        }
+
+        const std::string& GetTitle() const
+        {
+            return m_title;
+        }
+
+        PopupObject::PopupObjects& GetPopupObjects()
+        {
+            return m_popupObjectList;
+        }
+
+        virtual ~Popup()
+        {
+            FOREACH(it, m_popupObjectList) {
+                delete *it;
+            }
+        }
+
+      private:
+        friend class PopupRenderer;
+        friend class std::shared_ptr<Popup>;
+        friend class PopupObjectTheme;
+
+        Popup(std::shared_ptr<PopupRenderer> renderer) : m_renderer(renderer)
+        {
+        }
+
+        void ForwardAnswer(const AnswerCallbackData & answer) const
+        {
+            m_callback(answer, m_data);
+        }
+
+        std::string m_title;
+        void* m_data;
+        IPopup::PopupCallbackType m_callback;
+        PopupObject::PopupObjects m_popupObjectList;
+        std::shared_ptr<PopupRenderer> m_renderer;
+    };
+
+  private:
+    void Render (PopupPtr popup);
+
+    class Impl;
+    Impl* m_impl;
+};
+
+typedef std::shared_ptr<PopupRenderer> PopupRendererPtr;
+
+}
+} // namespace Popup
+} // namespace Wrt
+
+#endif //WRT_SRC_POPUP_POPUP_RENDERER_H_
diff --git a/src/wrt-popup/wrt/popup-bin/wrt-popup.cpp b/src/wrt-popup/wrt/popup-bin/wrt-popup.cpp
new file mode 100644 (file)
index 0000000..3023302
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * 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.
+ */
+#include "wrt-popup.h"
+#include <limits>
+#include <memory>
+
+#include <aul.h>
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+#include <dpl/assert.h>
+
+#include "PopupEnum.h"
+#include "PopupSerializer.h"
+#include "YesNoPopup.h"
+#include "InfoPopup.h"
+#include "YesNoCheckPopup.h"
+
+namespace Wrt {
+namespace Popup {
+
+bool WrtPopup::openPipes()
+{
+    Try
+    {
+        if (m_argc != 3) {
+            LogError("Wrong arguments!");
+            return false;
+        }
+        m_input.Open(m_argv[1]);
+        //open output pipe
+        m_output.Open(m_argv[2]);
+
+        DPL::WaitableHandleWatchSupport::InheritedContext()->
+            AddWaitableHandleWatch(this,
+                                   m_input.WaitableReadHandle(),
+                                   DPL::WaitMode::Read);
+        m_pipesOpened = true;
+        return true;
+    }
+    Catch(DPL::Exception)
+    {
+        LogError("cannot open pipes");
+    }
+    return false;
+}
+
+void WrtPopup::closePipes()
+{
+    Try
+    {
+        if (m_pipesOpened)
+        {
+            DPL::WaitableHandleWatchSupport::InheritedContext()->
+                RemoveWaitableHandleWatch(this,
+                                          m_input.WaitableReadHandle(),
+                                          DPL::WaitMode::Read);
+            m_input.Close();
+            m_output.Close();
+            m_pipesOpened = false;
+        }
+    }
+    Catch(DPL::Exception)
+    {
+        LogError("cannot close pipes");
+    }
+}
+
+void WrtPopup::OnEventReceived(const QuitEvent &/* event */)
+{
+    LogDebug("Quiting");
+    closePipes();
+    Quit();
+}
+
+void WrtPopup::OnWaitableHandleEvent(DPL::WaitableHandle waitableHandle,
+                                     DPL::WaitMode::Type /*mode*/)
+{
+    if (waitableHandle == m_input.WaitableReadHandle())
+    {
+        readInputData();
+    }
+}
+
+void WrtPopup::readInputData()
+{
+    DPL::BinaryQueueAutoPtr data =
+        m_input.Read(std::numeric_limits<std::size_t>::max());
+    int popupType = PopupSerializer::getIntArg(*data);
+    LogDebug("popup type " << popupType);
+    switch(popupType) {
+    case YES_NO_PROMPT:
+        m_popup.reset(new YesNoPopup());
+        m_popup->show(data, this);
+        break;
+    case INFO_PROMPT:
+        m_popup.reset(new InfoPopup());
+        m_popup->show(data, this);
+        break;
+    case YES_NO_CHECK_PROMPT:
+        m_popup.reset(new YesNoCheckPopup());
+        m_popup->show(data, this);
+        break;
+    default:
+        Assert(false);
+    }
+}
+
+void WrtPopup::response(DPL::BinaryQueue result)
+{
+    m_output.Write(result, result.Size());
+    PostEvent(QuitEvent());
+}
+
+void WrtPopup::OnStop()
+{
+    LogInfo("On Stop");
+}
+
+void WrtPopup::OnCreate()
+{
+    if (!openPipes())
+    {
+        PostEvent(QuitEvent());
+    }
+    LogInfo("On Create");
+}
+
+void WrtPopup::OnResume()
+{
+    LogDebug("OnResume");
+}
+
+void WrtPopup::OnPause()
+{
+    LogDebug("OnPause");
+}
+
+void WrtPopup::OnReset(bundle */*b*/)
+{
+    LogDebug("OnReset");
+}
+
+void WrtPopup::OnTerminate()
+{
+    LogDebug("Wrt Shutdown now");
+}
+
+WrtPopup::WrtPopup(int argc, char **argv) :
+    Application(argc, argv, "wrt-popup", false),
+    m_pipesOpened(false)
+{
+    Touch();
+    Renderer::PopupControllerSingleton::Instance().Touch();
+    Renderer::PopupManagerSingleton::Instance().Initialize(
+        Renderer::PopupRendererPtr(new Renderer::PopupRenderer));
+    LogDebug("App Created");
+}
+
+WrtPopup::~WrtPopup()
+{
+    Renderer::PopupManagerSingleton::Instance().Deinitialize();
+    LogDebug("App Finished");
+}
+
+}
+}
+
+int main(int argc, char *argv[])
+{
+    UNHANDLED_EXCEPTION_HANDLER_BEGIN
+    {
+        // Output on stdout will be flushed after every newline character,
+        // even if it is redirected to a pipe. This is useful for running
+        // from a script and parsing output.
+        // (Standard behavior of stdlib is to use full buffering when
+        // redirected to a pipe, which means even after an end of line
+        // the output may not be flushed).
+        setlinebuf(stdout);
+
+        DPL::Log::LogSystemSingleton::Instance().SetTag("WRT-POPUP");
+        Wrt::Popup::WrtPopup app(argc, argv);
+        int ret = app.Exec();
+        LogDebug("App returned: " << ret);
+        return ret;
+    }
+    UNHANDLED_EXCEPTION_HANDLER_END
+}
diff --git a/src/wrt-popup/wrt/popup-bin/wrt-popup.h b/src/wrt-popup/wrt/popup-bin/wrt-popup.h
new file mode 100644 (file)
index 0000000..47ddaa1
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+#ifndef WRT_POPUP_H
+#define WRT_POPUP_H
+
+#include <memory>
+#include <dpl/application.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.h>
+#include <dpl/named_input_pipe.h>
+#include <dpl/named_output_pipe.h>
+#include <dpl/waitable_handle_watch_support.h>
+#include <dpl/binary_queue.h>
+#include "popup_controller.h"
+
+namespace Wrt {
+namespace Popup {
+
+DECLARE_GENERIC_EVENT_0(QuitEvent)
+class WrtPopup;
+
+class IPopup : public Renderer::PopupControllerUser
+{
+public:
+    virtual void show(DPL::BinaryQueueAutoPtr data, WrtPopup* parent) = 0;
+    virtual ~IPopup() {}
+};
+
+typedef std::unique_ptr<IPopup> IPopupPtr;
+
+
+class WrtPopup :
+    public DPL::WaitableHandleWatchSupport::WaitableHandleListener,
+    public DPL::Application,
+    private DPL::Event::Controller<DPL::TypeListDecl<QuitEvent>::Type>
+{
+public:
+    WrtPopup(int argc, char **argv);
+    virtual ~WrtPopup();
+
+    void response(DPL::BinaryQueue result);
+
+protected:
+    //DPL::Application functions
+    virtual void OnStop();
+    virtual void OnCreate();
+    virtual void OnResume();
+    virtual void OnPause();
+    virtual void OnReset(bundle *b);
+    virtual void OnTerminate();
+    virtual void OnEventReceived(const QuitEvent &event);
+    virtual void OnWaitableHandleEvent(DPL::WaitableHandle waitableHandle,
+                                       DPL::WaitMode::Type mode);
+private:
+
+    void showAcePrompt(DPL::BinaryQueueAutoPtr data);
+    void communicationBoxResponse(int buttonAnswer,
+                                  bool checkState,
+                                  void* userdata);
+    bool m_pipesOpened;
+    IPopupPtr m_popup;
+
+    bool openPipes();
+    void closePipes();
+    void readInputData();
+
+    DPL::NamedInputPipe m_input;
+    DPL::NamedOutputPipe m_output;
+};
+
+}
+}
+
+#endif // WRT_POPUP_H
diff --git a/src/wrt-popup/wrt/popup-runner/CMakeLists.txt b/src/wrt-popup/wrt/popup-runner/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0a8f45e
--- /dev/null
@@ -0,0 +1,66 @@
+# 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   Lukasz Marek (l.marek@samsung.com)
+#
+# @version  1.0
+#
+
+PKG_CHECK_MODULES(WRT_POPUP_RUNNER_LIB_DEP
+    dpl-efl
+    REQUIRED
+)
+
+set(WRT_POPUP_RUNNER_LIB_SRC_DIR ${PROJECT_SOURCE_DIR}/src/wrt-popup/wrt/popup-runner)
+
+set(WRT_POPUP_RUNNER_LIB_SOURCES
+    ${WRT_POPUP_COMMON_SRCS}
+    ${WRT_POPUP_RUNNER_LIB_SRC_DIR}/PopupInvoker.cpp
+)
+
+ADD_DEFINITIONS(${WRT_POPUP_RUNNER_LIB_DEP_CFLAGS})
+
+INCLUDE_DIRECTORIES(
+    ${WRT_POPUP_RUNNER_LIB_SRC_DIR}
+    ${WRT_POPUP_RUNNER_LIB_DEP_INCLUDE_DIRS}
+    ${WRT_POPUP_COMMON_DIR}
+)
+
+ADD_LIBRARY(${TARGET_POPUP_WRT_RUNNER_LIB} SHARED
+    ${WRT_POPUP_RUNNER_LIB_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_WRT_RUNNER_LIB} PROPERTIES
+    COMPILE_FLAGS -fPIC
+)
+
+SET_TARGET_PROPERTIES(${TARGET_POPUP_WRT_RUNNER_LIB} PROPERTIES
+    SOVERSION ${CMAKE_PROJECT_API_VERSION}
+    VERSION ${CMAKE_PROJECT_VERSION}
+)
+
+target_link_libraries(${TARGET_POPUP_WRT_RUNNER_LIB}
+    ${WRT_POPUP_RUNNER_LIB_DEP_LIBRARIES}
+    ${WRT_POPUP_RUNNER_LIB_DEP_LDFLAGS}
+)
+
+INSTALL(TARGETS ${TARGET_POPUP_WRT_RUNNER_LIB}
+    DESTINATION lib
+)
+
+INSTALL(FILES ${WRT_POPUP_RUNNER_LIB_SRC_DIR}/PopupInvoker.h
+    DESTINATION ${DESTINATION_HEADERS_WRT_POPUP_RUNNER}
+)
diff --git a/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp b/src/wrt-popup/wrt/popup-runner/PopupInvoker.cpp
new file mode 100644 (file)
index 0000000..9b50a88
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * 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.
+ */
+
+#include "PopupInvoker.h"
+#include <sstream>
+#include <unistd.h>
+#include <stdio.h>
+#include <dpl/log/log.h>
+#include <dpl/waitable_handle.h>
+#include <dpl/binary_queue.h>
+#include <dpl/serialization.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "PopupEnum.h"
+#include "PopupSerializer.h"
+
+namespace {
+const char *POPUP_EXEC = "/usr/bin/wrt-popup-wrt-runtime";
+}
+
+namespace Wrt {
+namespace Popup {
+
+PopupInvoker::PopupInvoker() :
+    m_inputName(tmpnam(NULL)),
+    m_outputName(tmpnam(NULL))
+{
+    Try
+    {
+        m_input.Create(m_inputName);
+        m_output.Create(m_outputName);
+        LogDebug("Pipes created");
+    }
+    Catch (DPL::Exception)
+    {
+        LogError("Cannot create pipes");
+    }
+}
+
+PopupInvoker::~PopupInvoker()
+{
+    Try
+    {
+        m_input.Destroy(m_inputName);
+        m_output.Destroy(m_outputName);
+        LogDebug("Pipes destroyed");
+    }
+    Catch (DPL::Exception)
+    {
+        LogError("Cannot destroy pipes");
+    }
+}
+
+bool PopupInvoker::askYesNo(const std::string& title, const std::string& message)
+{
+    Try
+    {
+        DPL::BinaryQueue data;
+        PopupSerializer::appendArg(YES_NO_PROMPT, data);
+        PopupSerializer::appendArg(title, data);
+        PopupSerializer::appendArg(message, data);
+        DPL::NamedInputPipe tmp;
+        tmp.Open(m_outputName);
+        m_output.Open(m_outputName);
+        m_input.Open(m_inputName);
+        m_output.Write(data, data.Size());
+
+        executePopup();
+
+        //Result from popup application is available. Read it.
+        DPL::BinaryQueueAutoPtr resultData =
+            m_input.Read(std::numeric_limits<std::size_t>::max());
+        const int result = PopupSerializer::getIntArg(*resultData);
+
+        LogDebug("Popup result is: " << result);
+
+        Assert(resultData->Empty());
+
+        tmp.Close();
+        m_input.Close();
+        m_output.Close();
+
+        return (!!result);
+    }
+    Catch(DPL::Exception)
+    {
+        LogError("error occured");
+    }
+
+    return false;
+}
+
+void PopupInvoker::showInfo(const std::string& title,
+                            const std::string& message,
+                            const std::string& buttonLabel)
+{
+    Try
+    {
+        DPL::BinaryQueue data;
+        PopupSerializer::appendArg(INFO_PROMPT, data);
+        PopupSerializer::appendArg(title, data);
+        PopupSerializer::appendArg(message, data);
+        PopupSerializer::appendArg(buttonLabel, data);
+        DPL::NamedInputPipe tmp;
+        tmp.Open(m_outputName);
+        m_output.Open(m_outputName);
+        m_input.Open(m_inputName);
+        m_output.Write(data, data.Size());
+
+        executePopup();
+
+        //ignore result
+
+        tmp.Close();
+        m_input.Close();
+        m_output.Close();
+    }
+    Catch(DPL::Exception)
+    {
+        LogError("error occured");
+    }
+}
+
+PopupResponse PopupInvoker::askYesNoCheckbox(const std::string& title,
+    const std::string& message, const std::string& checkboxLabel)
+{
+    Try
+    {
+        DPL::BinaryQueue data;
+        PopupSerializer::appendArg(YES_NO_CHECK_PROMPT, data);
+        PopupSerializer::appendArg(title, data);
+        PopupSerializer::appendArg(message, data);
+        PopupSerializer::appendArg(checkboxLabel, data);
+        DPL::NamedInputPipe tmp;
+        tmp.Open(m_outputName);
+        m_output.Open(m_outputName);
+        m_input.Open(m_inputName);
+        m_output.Write(data, data.Size());
+
+        executePopup();
+
+        //Result from popup application is available. Read it.
+        DPL::BinaryQueueAutoPtr resultData =
+            m_input.Read(std::numeric_limits<std::size_t>::max());
+        const int result = PopupSerializer::getIntArg(*resultData);
+        const int rememberResult = PopupSerializer::getIntArg(*resultData);
+
+        LogDebug("Popup result is: " << result << " remeber: " << rememberResult);
+
+        Assert(resultData->Empty());
+        tmp.Close();
+        m_input.Close();
+        m_output.Close();
+
+        if (1 == result) {
+            if (rememberResult == 1) {
+                return YES_DO_REMEMBER;
+            } else {
+                return YES_DONT_REMEMBER;
+            }
+        } else {
+            if (rememberResult == 1) {
+                return NO_DO_REMEMBER;
+            } else {
+                return NO_DONT_REMEMBER;
+            }
+        }
+    }
+    Catch(DPL::Exception)
+    {
+        LogError("error occured");
+    }
+    return NO_DONT_REMEMBER;
+}
+
+void PopupInvoker::executePopup()
+{
+    pid_t pid = fork();
+    if (pid == -1)
+    {
+        //error occured
+        LogError("Cannot display popup!");
+        Assert(false);
+    }
+    if (pid == 0)
+    {
+        //child process
+        int ret = execl(POPUP_EXEC,
+                        POPUP_EXEC,
+                        m_outputName.c_str(),
+                        m_inputName.c_str(),
+                        NULL);
+        if (ret == -1) {
+            //execl returns -1 on error
+            LogError("Cannot display popup!");
+            Assert(false);
+        }
+    }
+
+    DPL::WaitableHandle handle = m_input.WaitableReadHandle();
+    DPL::WaitForSingleHandle(handle);
+}
+
+} // Popup
+} // Wrt
diff --git a/src/wrt-popup/wrt/popup-runner/PopupInvoker.h b/src/wrt-popup/wrt/popup-runner/PopupInvoker.h
new file mode 100644 (file)
index 0000000..112028f
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+#ifndef WRT_POPUP_INVOKER_H
+#define WRT_POPUP_INVOKER_H
+
+#include <string>
+
+#include <dpl/named_input_pipe.h>
+#include <dpl/named_output_pipe.h>
+
+/*
+
+ Example usage:
+
+ bool result = PopupInvoker().askYesNo("title", "message");
+
+ */
+
+namespace Wrt {
+namespace Popup {
+
+enum PopupResponse {
+    NO_DO_REMEMBER,
+    NO_DONT_REMEMBER,
+    YES_DONT_REMEMBER,
+    YES_DO_REMEMBER
+};
+
+class PopupInvoker
+{
+public:
+    class Exception
+    {
+      public:
+        DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+        DECLARE_EXCEPTION_TYPE(Base, PopupInvokerException)
+    };
+
+    PopupInvoker();
+    ~PopupInvoker();
+
+    bool askYesNo(const std::string &title, const std::string &message);
+    void showInfo(const std::string &title,
+                  const std::string &message,
+                  const std::string &buttonLabel = std::string("OK"));
+    PopupResponse askYesNoCheckbox(const std::string& title,
+            const std::string& message, const std::string& checkboxLabel);
+
+private:
+
+    void executePopup();
+
+    DPL::NamedInputPipe m_input;
+    DPL::NamedOutputPipe m_output;
+    const std::string m_inputName;
+    const std::string m_outputName;
+};
+
+} // Popup
+} // Wrt
+
+#endif
index 6e00c3f..406edbd 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2012 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.
 #
 # @file        CMakeLists.txt
 # @author      Lukasz Marek (l.marek@samsung.com)
-# @version     1.0
-# @brief
 #
 
-#
-# Test files
-#
-# Define all wrt-plugins-common tests sources.
-# Runner is responsible for runnint it all and
-# generating proper output files
-#
-
-SET(TARGET_NAME wrt-plugins-commons-test)
-
-pkg_search_module(dpl REQUIRED dpl-efl>=1.0.0)
-pkg_search_module(dpl-test REQUIRED dpl-test-efl)
-pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro)
-
-SET(WRT_PLUGINS_COMMONS_TESTS_SOURCES
-    ${PROJECT_SOURCE_DIR}/tests/main.cpp
-    ${PROJECT_SOURCE_DIR}/tests/test_widget_interface_dao.cpp
-)
-
-SET(WRT_PLUGINS_COMMONS_TESTS_DIR
-    ${PROJECT_SOURCE_DIR}/src/
-    ${PROJECT_SOURCE_DIR}/src/Commons/
-    ${PROJECT_SOURCE_DIR}/src/CommonsJavaScript/
-    ${PROJECT_SOURCE_DIR}/src/modules/tizen/
-    ${PROJECT_SOURCE_DIR}/src/modules/API/
-    ${PROJECT_SOURCE_DIR}/tests
-)
-
-include_directories(
-    ${WRT_PLUGINS_COMMONS_TESTS_DIR}
-    ${dpl_INCLUDE_DIRS}
-    ${dpl-wrt-dao-ro_INCLUDE_DIRS}
-    ${dpl-test_INCLUDE_DIRS}
-)
-
-ADD_EXECUTABLE(${TARGET_NAME}
-    ${WRT_PLUGINS_COMMONS_TESTS_SOURCES}
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_NAME}
-    ${dpl_LIBRARIES}
-    ${dpl-test_LIBRARIES}
-    ${dpl-wrt-dao-ro_LIBRARIES}
-    "wrt-plugins-widget-interface-dao"
-)
-
-SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
-    RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/
-    BUILD_WITH_INSTALL_RPATH ON
-    INSTALL_RPATH_USE_LINK_PATH ON
-)
+INCLUDE(CMakeUtils.txt)
 
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wrt_plugins_commons_test_prepare_db.sh
-    ${PROJECT_SOURCE_DIR}/bin/wrt_plugins_commons_test_prepare_db.sh COPYONLY)
+ADD_SUBDIRECTORY(dao)
diff --git a/tests/CMakeUtils.txt b/tests/CMakeUtils.txt
new file mode 100644 (file)
index 0000000..cb27239
--- /dev/null
@@ -0,0 +1,69 @@
+# @file        CMakeUtils.txt
+# @author      Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
+# @author      Pawel Sikorski (p.sikorski@samsung.com)
+# @author      Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+# @version     1.0
+# @brief
+#
+
+#
+# Replacement functions for standard (w/o "WRT_" prefix) CMake functions.
+# They store supplied arguments in global properties to assign them to tests.
+FUNCTION(WRT_INCLUDE_DIRECTORIES)
+  SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_INCLUDE_DIRS ${ARGV})
+ENDFUNCTION(WRT_INCLUDE_DIRECTORIES)
+
+FUNCTION(WRT_LINK_DIRECTORIES)
+  SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARY_DIRS ${ARGV})
+ENDFUNCTION(WRT_LINK_DIRECTORIES)
+
+FUNCTION(WRT_TARGET_LINK_LIBRARIES)
+  SET_PROPERTY(GLOBAL APPEND PROPERTY TESTS_LIBRARIES ${ARGV})
+ENDFUNCTION(WRT_TARGET_LINK_LIBRARIES)
+
+FUNCTION(WRT_TEST_LIBRARY)
+  SET_PROPERTY(GLOBAL APPEND PROPERTY COMMON_TESTS_LIBRARY ${ARGV})
+ENDFUNCTION(WRT_TEST_LIBRARY)
+
+# Functions used to build test targets (proper sources, includes, libs are
+# added automatically)
+FUNCTION(WRT_TEST_BUILD TARGET_NAME)
+    SET(SOURCES "${ARGN}")
+    ADD_EXECUTABLE("${TARGET_NAME}"
+        ${SOURCES}
+    )
+    # get include dirs global property
+    GET_PROPERTY(INCLUDE_DIRS GLOBAL PROPERTY TESTS_INCLUDE_DIRS)
+    INCLUDE_DIRECTORIES(
+        ${INCLUDE_DIRS}
+    )
+    # get library dirs global property
+    GET_PROPERTY(LIBRARY_DIRS GLOBAL PROPERTY TESTS_LIBRARY_DIRS)
+    LINK_DIRECTORIES(
+        ${LIBRARY_DIRS}
+    )
+    # get link libraries global property
+    GET_PROPERTY(LINK_LIBRARIES GLOBAL PROPERTY TESTS_LIBRARIES)
+    GET_PROPERTY(TEST_LIBRARY GLOBAL PROPERTY COMMON_TESTS_LIBRARY)
+    TARGET_LINK_LIBRARIES("${TARGET_NAME}"
+        ${TEST_LIBRARY}
+        ${LINK_LIBRARIES}
+    )
+ENDFUNCTION(WRT_TEST_BUILD)
+
+FUNCTION(WRT_TEST_INSTALL)
+    SET_TARGET_PROPERTIES(${ARGV} PROPERTIES
+        BUILD_WITH_INSTALL_RPATH ON
+        INSTALL_RPATH_USE_LINK_PATH ON
+    )
+    INSTALL(TARGETS ${ARGV}
+        DESTINATION bin
+        PERMISSIONS OWNER_READ
+                    OWNER_WRITE
+                    OWNER_EXECUTE
+                    GROUP_READ
+                    GROUP_EXECUTE
+                    WORLD_READ
+                    WORLD_EXECUTE
+    )
+ENDFUNCTION(WRT_TEST_INSTALL)
diff --git a/tests/dao/CMakeLists.txt b/tests/dao/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c088821
--- /dev/null
@@ -0,0 +1,47 @@
+# 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      Andrzej Surdej (a.surdej@sasmung.com)
+# @version     1.0
+# @brief
+#
+
+SET(TARGET_WIDGETDB_TEST "plugins-tests-widgetdb")
+
+pkg_search_module(dpl REQUIRED dpl-efl)
+pkg_search_module(dpl-test REQUIRED dpl-test-efl)
+
+include_directories(
+  ${dpl_INCLUDE_DIRS}
+  ${dpl-test_INCLUDE_DIRS}
+)
+
+# Set widgetdb tests sources
+SET(WIDGETDB_TESTS_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/TestInit.cpp"
+                           "${CMAKE_CURRENT_SOURCE_DIR}/WidgetDBTest.cpp")
+
+WRT_TEST_BUILD(${TARGET_WIDGETDB_TEST} ${WIDGETDB_TESTS_SOURCES})
+WRT_TEST_INSTALL(${TARGET_WIDGETDB_TEST})
+
+target_link_libraries(${TARGET_WIDGETDB_TEST}
+  "wrt-plugins-widgetdb"
+  ${dpl_LIBRARIES}
+  ${dpl-test_LIBRARIES}
+)
+
+INSTALL(PROGRAMS
+  ${CMAKE_CURRENT_SOURCE_DIR}/widgetdb_tests_prepare_db.sh
+  DESTINATION bin
+  )
diff --git a/tests/dao/README b/tests/dao/README
new file mode 100644 (file)
index 0000000..a618eb1
--- /dev/null
@@ -0,0 +1,12 @@
+Plugins DAO
+System tests. Tests widget's private database data access object.
+Binary file: plugins-tests-widgetdb. Uses our test framework. Allows to use
+different types of output. Text output shows results on console - green passed.
+To run:
+1. Install wrt-extra on target
+2. Run plugins-tests-widgetdb --output=text
+
+Automatic: YES
+Included in Daily Build: YES (http://build01.sprc.samsung.pl/browse/LINUXNGWAP-INT)
+Included in Gerrit Builds: YES (http://build01.sprc.samsung.pl/browse/LINUXNGWAP-GERRIT)
+Number of test cases: 22
\ No newline at end of file
diff --git a/tests/dao/TestInit.cpp b/tests/dao/TestInit.cpp
new file mode 100644 (file)
index 0000000..0474752
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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    TestInit.cpp
+ * @author  Pawel Sikorski (p.sikorski@samsung.com)
+ * @author  Andrzej Surdej (a.surdej@samsung.com)
+ * @version 1.0
+ * @brief   Init widgetDB module test
+ */
+
+#include <sys/wait.h>
+#include <dpl/test/test_runner.h>
+#include <dpl/log/log.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+
+int main (int argc, char *argv[])
+{
+    int ret = system("/usr/bin/widgetdb_tests_prepare_db.sh start");
+
+    if (!WIFEXITED(ret)) {      //unexpected termiate
+        LogDebug("Fail while preparing database. Restoring");
+        system("/usr/bin/widgetdb_tests_prepare_db.sh stop");
+        return -1;
+    } else if (WEXITSTATUS(ret)) { //wrong script command, nothing done
+            LogError("Preparation script has return error: " << ret
+                     << ". Quitting");
+            return -1;
+    }
+
+    LogInfo("Starting tests");
+
+    WrtDB::WrtDatabase::attachToThreadRW();
+
+    int status =
+        DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);
+
+    WrtDB::WrtDatabase::detachFromThread();
+
+    system("/usr/bin/widgetdb_tests_prepare_db.sh stop");
+    return status;
+}
diff --git a/tests/dao/WidgetDBTest.cpp b/tests/dao/WidgetDBTest.cpp
new file mode 100644 (file)
index 0000000..1e87fde
--- /dev/null
@@ -0,0 +1,568 @@
+/*
+ * 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    WidgetDBTest.cpp
+ * @author  Andrzej Surdej (a.surdej@samsung.com)
+ * @version 1.0
+ * @brief   This file contains tests for widgetDB commons module
+ */
+
+#include <dpl/test/test_runner.h>
+#include <dpl/foreach.h>
+#include <dpl/log/log.h>
+#include <WidgetDB/IWidgetDB.h>
+#include <WidgetDB/WidgetDBMgr.h>
+#include <Commons/Exception.h>
+
+using namespace WrtDeviceApis::WidgetDB::Api;
+
+#define RUNNER_ASSERT_WHAT_EQUALS(in, test)                                    \
+    do                                                                         \
+    {                                                                          \
+        std::string temp(in);                                                  \
+        RUNNER_ASSERT_MSG(temp == (test), "Equals: [" << temp << "]");         \
+    }                                                                          \
+    while(0)
+
+RUNNER_TEST_GROUP_INIT(WidgetDB)
+
+/*
+Name: widgetDB_test_get_language1
+Description: check default widget language
+Expected: default should be "en"
+*/
+RUNNER_TEST(widgetDB_test_get_language1)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string lang = widget->getLanguage();
+
+        LogDebug("language is: " << lang);
+        RUNNER_ASSERT_WHAT_EQUALS(lang, "en");
+
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_language2
+Description: check language returned by WidgetDB if widget does nto exists
+Expected: result should be ""
+*/
+RUNNER_TEST(widgetDB_test_get_language2)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(1000); //widget not exist
+        std::string lang = widget->getLanguage();
+
+        LogDebug("language is: " << lang);
+        RUNNER_ASSERT_WHAT_EQUALS(lang, "");
+
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_id
+Description: check GUID returned by WidgetDB
+Expected: GUID should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_id)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
+
+        LogDebug("id is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_id_2000");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_version
+Description: check version returned by WidgetDB
+Expected: version should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_version)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::VERSION);
+
+        LogDebug("version is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "1.0.0");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_description
+Description: check description returned by WidgetDB
+Expected: description should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_description)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::DESCRIPTION);
+
+        LogDebug("description is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_desc_2000_en");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_license
+Description: check license returned by WidgetDB
+Expected: license should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_license)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE);
+
+        LogDebug("licence is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_2000_en");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_license_href
+Description: check license href returned by WidgetDB
+Expected: license href should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_license_href)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::LICENSE_HREF);
+
+        LogDebug("license href is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_lic_href_2000_en");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_author_name
+Description: check author name href returned by WidgetDB
+Expected: author name should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_author_name)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_NAME);
+
+        LogDebug("author name is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_name_2000");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_author_href
+Description: check author href returned by WidgetDB
+Expected: author href should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_author_href)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_HREF);
+
+        LogDebug("author href is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_href_2000");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_author_email
+Description: check author email returned by WidgetDB
+Expected: author email should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_author_email)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::AUTHOR_EMAIL);
+
+        LogDebug("author email is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "a_email_2000");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_name
+Description: check localized widget name returned by WidgetDB
+Expected: localized widget name should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_name)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::NAME);
+
+        LogDebug("name is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_name_2000_en");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_short_name
+Description: check localized widget short name returned by WidgetDB
+Expected: localized widget short name should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_short_name)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::SHORT_NAME);
+
+        LogDebug("short name is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "w_shortname_2000_en");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_access_network
+Description: check network access returned by WidgetDB
+Expected: network access should be set to "yes"
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_access_network)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(
+            ConfigAttribute::ACCESS_NETWORK);
+
+        LogDebug("acces network is always true: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "yes");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_width
+Description: check widget prefered width returned by WidgetDB
+Expected: widget prefered width should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_width)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::WIDTH);
+
+        LogDebug("width is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "100");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_height
+Description: check widget prefered height returned by WidgetDB
+Expected: widget prefered height should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_height)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::HEIGHT);
+
+        LogDebug("height is: " << tmp);
+        RUNNER_ASSERT_WHAT_EQUALS(tmp, "200");
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_paths
+Description: check widget installation path returned by WidgetDB
+Expected: widget installation path should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_paths)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::INSTALL_PATH);
+
+        LogDebug("install path is: " << tmp);
+
+        tmp = widget->getConfigValue(
+            ConfigAttribute::PUBLIC_STORAGE_PATH);
+
+        LogDebug("public storage path is: " << tmp);
+
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogDebug("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_get_config_value_empty
+Description: check if requesting GUID from WidgetDB throw excpetion if widget does not exists
+Expected: accessing GUID should throw WrtDeviceApis::Commons::SecurityException
+*/
+RUNNER_TEST(widgetDB_test_get_config_value_empty)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2005);
+        std::string tmp = widget->getConfigValue(ConfigAttribute::ID);
+
+        //exception should be thrown
+        RUNNER_ASSERT(false);
+
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogDebug("OK. Exception thrown." << e.DumpToString());
+    }
+}
+
+/*
+Name: widgetDB_test_check_installation_status_installed
+Description: check if widget is installed by WidgetDB
+Expected: plugin should be notified that widget is installed
+*/
+RUNNER_TEST(widgetDB_test_check_installation_status_installed)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        InstallationStatus tmp = widget->checkInstallationStatus(
+            "w_id_2000", "w_name_2000_en", "2.0.0");
+
+        RUNNER_ASSERT(tmp == InstallationStatus::STATUS_INSTALLED);
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_check_installation_status_uninstalled
+Description: check if widget is not installed by WidgetDB
+Expected: plugin should be notified that widget is not installed
+*/
+RUNNER_TEST(widgetDB_test_check_installation_status_uninstalled)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        InstallationStatus tmp = widget->checkInstallationStatus(
+            "w_id_2011", "w_name_2000_en", "2.0.0");
+
+        RUNNER_ASSERT(tmp == InstallationStatus::STATUS_UNINSTALLED);
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_check_installation_status_latest
+Description: check if widget installation information is taken from latest version
+Expected: plugin installation status should be same is both calls of WidgetDB
+*/
+RUNNER_TEST(widgetDB_test_check_installation_status_latest)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        InstallationStatus tmp1 = widget->checkInstallationStatus(
+            "w_id_2000", "w_name_2000_en", "0.1.0");
+        InstallationStatus tmp2 = widget->checkInstallationStatus(
+            "w_id_2000", "w_name_2000_en", "1.0.0");
+
+        RUNNER_ASSERT(tmp1 == InstallationStatus::STATUS_LATEST);
+        RUNNER_ASSERT(tmp2 == InstallationStatus::STATUS_LATEST);
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_widget_feature
+Description: check accessiblity of widget features and their values by WidgetDB
+Expected: feature names and values should match this, which was inserted into widget database
+*/
+RUNNER_TEST(widgetDB_test_widget_feature)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2000);
+        Features features = widget->getWidgetFeatures();
+
+        RUNNER_ASSERT(features.size() == 5);
+
+        FOREACH(it, features)
+        {
+           std::string name = (*it)->getName();
+           if ("first_2000" == name)
+           {
+               RUNNER_ASSERT((*it)->getParams().size() == 4);
+
+               RUNNER_ASSERT((*it)->isRequired());
+           }
+           else if ("second_2000" == name)
+           {
+               RUNNER_ASSERT((*it)->getParams().size() == 1);
+           }
+           else if ("third_2000" == name)
+           {
+               IWidgetFeature::Params params = (*it)->getParams();
+
+               RUNNER_ASSERT(params.size() == 1);
+               RUNNER_ASSERT_WHAT_EQUALS("third_2000", params.begin()->first);
+               RUNNER_ASSERT_WHAT_EQUALS("thirdValue1", params.begin()->second);
+               RUNNER_ASSERT(!(*it)->isRequired());
+           }
+           else if ("fourth_2000" == name)
+           {
+               RUNNER_ASSERT((*it)->getParams().size() == 0);
+           }
+           else if ("fifth_2000" == name)
+           {
+               RUNNER_ASSERT((*it)->getParams().size() == 0);
+           }
+           else
+               RUNNER_ASSERT(false);
+        }
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogError("Exception thrown." << e.DumpToString());
+        RUNNER_ASSERT(false);
+    }
+}
+
+/*
+Name: widgetDB_test_widget_feature2
+Description: check if requesting features from WidgetDB throw excpetion if widget does not exists
+Expected: exception should be raise if widget does not exists
+*/
+RUNNER_TEST(widgetDB_test_widget_feature2)
+{
+    try
+    {
+        IWidgetDBPtr widget = getWidgetDB(2011); //no such widget
+        Features features = widget->getWidgetFeatures();
+
+        RUNNER_ASSERT(false);
+    }
+    catch(const WrtDeviceApis::Commons::SecurityException &e)
+    {
+        LogDebug("OK. Exception thrown." << e.DumpToString());
+    }
+}
+
+#undef RUNNER_ASSERT_WHAT_EQUALS
diff --git a/tests/dao/widgetdb_tests_prepare_db.sh b/tests/dao/widgetdb_tests_prepare_db.sh
new file mode 100755 (executable)
index 0000000..31f29fb
--- /dev/null
@@ -0,0 +1,133 @@
+#!/bin/sh
+#
+# 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.
+#
+#
+
+WRT_DB=/opt/dbspace/.wrt.db
+WRT_DB_BCK=/tmp/wrt.db_backup
+
+if [ "x$1" == "xstart" ]; then
+    echo start;
+    cp $WRT_DB $WRT_DB_BCK
+    wrt_commons_create_clean_db.sh;
+
+    #simple plugins
+    INS_MIN_PLUGINPROP="insert into PluginProperties(PluginPropertiesId, InstallationState, PluginLibraryName"
+    INS_ALL_PLUGINPROP="insert into PluginProperties(PluginPropertiesId, InstallationState, PluginLibraryName, PluginLibraryPath)"
+
+    sqlite3 $WRT_DB "${INS_MIN_PLUGINPROP}) VALUES(1, 1, 'plugin1')";
+    sqlite3 $WRT_DB "${INS_MIN_PLUGINPROP}, PluginLibraryPath) VALUES(2, 1, 'plugin2', 'path_to_plugin2')";
+    sqlite3 $WRT_DB "${INS_MIN_PLUGINPROP}) VALUES(3, 1, 'plugin3')";
+    sqlite3 $WRT_DB "${INS_ALL_PLUGINPROP} VALUES(4, 1, 'p4', 'path_to_p4')";
+    sqlite3 $WRT_DB "${INS_ALL_PLUGINPROP} VALUES(5, 1, 'p5', 'path_to_p5')";
+
+    #simple features
+    INS_ALL_FEATURESLIST="insert into FeaturesList(FeatureUUID, FeatureName, PluginPropertiesId)"
+    sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(1, 'feature1', 1)";
+    sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(2, 'feature2', 4)";
+    sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(3, 'feature3', 4)";
+    sqlite3 $WRT_DB "${INS_ALL_FEATURESLIST} VALUES(4, 'feature4', 4)";
+
+    #Device capab
+    #TODO
+
+    #Widgets
+    INS_ALL_WIDGETEXT="insert into WidgetExtendedInfo(app_id, share_href, signature_type)"
+    INS_ALL_WIDGET="insert into WidgetInfo(app_id, widget_id, widget_version, widget_width, widget_height, author_name, author_email, author_href, base_folder, webkit_plugins_required, recognized, wac_signed, distributor_signed, min_version, back_supported, access_network, defaultlocale, pkgname)"
+    INS_ALL_WIDGET_LOC="insert into LocalizedWidgetInfo(app_id, widget_locale, widget_name, widget_shortname, widget_description, widget_license, widget_license_file, widget_license_href)"
+    INS_ALL_WIDGET_ICONS="insert into WidgetIcon(app_id, icon_src, icon_width, icon_height)"
+    INS_ALL_WIDGET_LOC_ICONS="insert into WidgetLocalizedIcon(app_id, icon_id, widget_locale)"
+    INS_ALL_WIDGET_STARTFILE="insert into WidgetStartFile(app_id, src)"
+    INS_ALL_WIDGET_LOC_STARTFILE="insert into WidgetLocalizedStartFile(app_id, start_file_id, widget_locale, type, encoding)"
+    INS_ALL_WIDGET_DEFPREF="insert into WidgetDefaultPreference(app_id, key_name, key_value, readonly)"
+    INS_ALL_WIDGET_PREF="insert into WidgetPreference(pkgname, key_name, key_value, readonly)"
+    INS_ALL_WIDGET_FEATURE="insert into WidgetFeature(widget_feature_id, app_id, name, required, rejected)"
+    INS_ALL_WIDGET_FEATURE_PARAM="insert into FeatureParam(widget_feature_id, name, value)"
+    INS_ALL_WIDGET_WINMODES="insert into WidgetWindowModes(app_id, window_mode)"
+    INS_ALL_WIDGET_WARP="insert into WidgetWARPInfo(app_id, iri, subdomain_access)"
+    INS_ALL_WIDGET_CERT="insert into WidgetCertificateFingerprint(app_id, owner, chainid, type, md5_fingerprint, sha1_fingerprint, common_name)"
+    INS_ALL_WIDGET_POWDERLEV="insert into PowderLevels(app_id, category, level)"
+    INS_ALL_WIDGET_POWDERLEV_CONT="insert into PowderLevelContexts(levelid, context)"
+
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET} VALUES(2000, 'w_id_2000', '1.0.0', 100, 200, 'a_name_2000', 'a_email_2000', 'a_href_2000', 'basef_2000', 1, 1, 1, 1, '1.0', 0, 0, 'en', 'tid2000')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET} VALUES(2001, 'w_id_2001', '2.0.0', 100, 200, 'a_name_2001', 'a_email_2001', 'a_href_2001', 'basef_2001', 1, 1, 1, 1, '0.5', 0, 0, 'en', 'tid2001')";
+    sqlite3 $WRT_DB "insert into WidgetInfo(app_id, back_supported, pkgname) VALUES(2002, 0, 'tid2002')";
+    sqlite3 $WRT_DB "insert into WidgetInfo(app_id, back_supported, pkgname) VALUES(2003, 0, 'NOTUSEDPKGNAME3')"; # for properties tests
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGETEXT} VALUES(2000, 'share_href_2000', 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGETEXT} VALUES(2001, 'share_href_2001', 0)";
+    sqlite3 $WRT_DB "insert into WidgetExtendedInfo(app_id) VALUES(2002)";
+    sqlite3 $WRT_DB "insert into WidgetExtendedInfo(app_id) VALUES(2003)";
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC} VALUES(2000, 'en', 'w_name_2000_en', 'w_shortname_2000_en', 'w_desc_2000_en', 'w_lic_2000_en', 'w_licf_2000_en', 'w_lic_href_2000_en')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC} VALUES(2000, 'pl', 'w_name_2000_pl', 'w_shortname_2000_pl', 'w_desc_2000_pl', 'w_lic_2000_pl', 'w_licf_2000_pl', 'w_lic_href_2000_pl')";
+    sqlite3 $WRT_DB "insert into LocalizedWidgetInfo(app_id, widget_locale) VALUES(2002, 'en')";
+    sqlite3 $WRT_DB "insert into LocalizedWidgetInfo(app_id, widget_locale) VALUES(2003, 'en')";
+
+#Widget features
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(1,2000, 'first_2000', 1, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(2,2000, 'second_2000', 1, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(3,2000, 'third_2000', 0, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(8,2000, 'fourth_2000', 1, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(9,2000, 'fifth_2000', 0, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(4,2001, 'first_2001', 1, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(5,2001, 'second_2001', 1, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(6,2001, 'third_2001', 0, 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE} VALUES(7,2001, 'fourth_2001', 1, 0)";
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(1, 'first_2000_first', 'firstValue1')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(1, 'first_2000_second', 'firstValue2')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(1, 'first_2000_third', 'firstValue3')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(1, 'first_2000_fourth', 'firstValue4')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(2, 'second_2000', 'secondValue1')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(3, 'third_2000', 'thirdValue1')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(4, 'first_2001', 'firstValue_2001')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(5, 'second_2001', 'secondValue_2001')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_FEATURE_PARAM} VALUES(6, 'third_2001', 'thirdValue_2001')";
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_ICONS} VALUES(2000, 'icon_src_2000', 50, 50)";
+    sqlite3 $WRT_DB "insert into WidgetIcon(app_id, icon_src) VALUES(2002, 'icon_src_2002')";
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_ICONS} VALUES(2000, 1, 'en')";
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2000, 'start_file_2000')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2001, 'start_file_2001')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2002, 'start_file_2002')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_STARTFILE} VALUES(2003, 'start_file_2003')";
+
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2000, 1, 'en', '', '')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2001, 2, 'en', '', '')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2002, 3, 'en', '', '')";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_LOC_STARTFILE} VALUES(2003, 4, 'en', '', '')";
+
+    #widget properties
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tid2000', 'key1_for_2000', 'value_for_key1_2000', 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tid2000', 'key2_for_2000', 'value_for_key2_2000', 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tid2001', 'key1_for_2001', 'value1_for_key_2001', 1)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tid2002', 'key1_for_2002', 'value1_for_key_2002', 0)";
+    sqlite3 $WRT_DB "${INS_ALL_WIDGET_PREF} VALUES('tid2002', 'key2_for_2002', 'value2_for_key_2002', 1)";
+
+
+    exit $?
+
+elif [ "x$1" == "xstop" ]; then
+    echo stop;
+    cp $WRT_DB_BCK $WRT_DB
+    exit $?
+else
+    exit 1
+fi
diff --git a/wrt-plugins-common.manifest b/wrt-plugins-common.manifest
new file mode 100644 (file)
index 0000000..f717929
--- /dev/null
@@ -0,0 +1,11 @@
+<manifest>
+  <define>
+    <domain name="wrt-plugins-common" />
+    <provide>
+      <label name="wrt-plugins-common::wrt-plugins-installer" />
+    </provide>
+  </define>
+  <request>
+    <domain name="_" />
+  </request>
+</manifest>