Remove js_overlay_addEventListener
[platform/framework/web/wrt-plugins-common.git] / src / standards / W3C / Widget / JSWidget.cpp
index 3f3f8c3..162820f 100644 (file)
 #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);\
+    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);\
+    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);\
+    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);\
+    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);\
+    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);\
+    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);\
+    Catch(Commons::InvalidArgumentException) { \
+        LogError("Pair for given key doesnt exist"); \
+        return JSValueMakeNull(context); \
     }
 
 #define WIDGET_PLUGIN_NAME "Widget"
 
 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;
+    //int widgetId     // TODO: check is it necessary (g.rynkowski)
     JSObjectRef widgetObject;
 };
 typedef std::shared_ptr<WidgetPrivateObject> WidgetPrivateObjectPtr;
 
 typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT
-    <WidgetPrivateObjectPtr>::Type JSWidgetPrivateObject;
+<WidgetPrivateObjectPtr>::Type JSWidgetPrivateObject;
 
 WrtDeviceApis::Widget::Api::IWidgetPtr getIWidget(JSObjectRef arg)
 {
@@ -131,13 +127,9 @@ WrtDeviceApis::Widget::Api::IWidgetPtr getIWidget(JSObjectRef arg)
     return priv->getObject()->iwidget;
 }
 
-
 LocalStorage::Api::ILocalStoragePtr getLocalStorage(int widgetId)
 {
-    static int id = widgetId;
-    Assert(id == widgetId && "SPA is not longer supported");
-
-    static LocalStorage::Api::ILocalStoragePtr storage(
+    LocalStorage::Api::ILocalStoragePtr storage(
         LocalStorage::Api::getLocalStorage(widgetId));
 
     return storage;
@@ -171,7 +163,7 @@ JSObjectRef createPreferencesObject(JSContextRef context,
                                            JSPreferences::getClassRef(),
                                            priv);
 
-    if(!preferences){
+    if (!preferences) {
         LogError("Preferences object is null");
         delete priv;
     }
@@ -179,8 +171,7 @@ JSObjectRef createPreferencesObject(JSContextRef context,
     JSValueProtect(context, preferences);
 
     return preferences;
-};
-
+}
 
 JSClassDefinition JSWidget::m_classInfo = {
     0,
@@ -226,7 +217,7 @@ JSStaticValue JSWidget::m_property[] = {
     { 0, 0, 0, 0 }
 };
 
-const JSClassRef JSWidget::getClassRef()
+JSClassRef JSWidget::getClassRef()
 {
     if (!m_jsClassRef) {
         m_jsClassRef = JSClassCreate(&m_classInfo);
@@ -244,7 +235,7 @@ JSClassRef JSWidget::m_jsClassRef = JSClassCreate(JSWidget::getClassInfo());
 JSContextRef JSWidget::m_globalContext = NULL;
 
 void JSWidget::initialize(JSContextRef context,
-        JSObjectRef object)
+                          JSObjectRef object)
 {
     LogDebug("entered. Context : " << context);
     LogDebug("Object: " << object);
@@ -265,7 +256,7 @@ void JSWidget::initialize(JSContextRef context,
                 createPreferencesObject(context,
                                         object,
                                         widgetId);
-            if(!preferences){
+            if (!preferences) {
                 LogError("Failed to create preferences object");
             }
 
@@ -276,34 +267,40 @@ void JSWidget::initialize(JSContextRef context,
             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));
 
-    JSValueUnprotect(priv->getContext(),
-                     priv->getObject()->preferencesObject);
+    if (priv) {
+        JSValueUnprotect(priv->getContext(),
+                         priv->getObject()->preferencesObject);
 
-    delete priv;
-    LogDebug("private object is released");
+        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)
+                                    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.");
@@ -313,9 +310,9 @@ void JSWidget::acquireGlobalContext(java_script_context_t global_context,
 }
 
 JSValueRef JSWidget::getAuthor(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                               JSObjectRef object,
+                               JSStringRef /*propertyName*/,
+                               JSValueRef* exception)
 {
     LogDebug("entered");
 
@@ -325,13 +322,13 @@ JSValueRef JSWidget::getAuthor(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getAuthorEmail(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                                    JSObjectRef object,
+                                    JSStringRef /*propertyName*/,
+                                    JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -339,13 +336,13 @@ JSValueRef JSWidget::getAuthorEmail(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getAuthorHref(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                                   JSObjectRef object,
+                                   JSStringRef /*propertyName*/,
+                                   JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -353,13 +350,13 @@ JSValueRef JSWidget::getAuthorHref(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getDescription(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                                    JSObjectRef object,
+                                    JSStringRef /*propertyName*/,
+                                    JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -367,13 +364,13 @@ JSValueRef JSWidget::getDescription(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getId(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                           JSObjectRef object,
+                           JSStringRef /*propertyName*/,
+                           JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -381,13 +378,13 @@ JSValueRef JSWidget::getId(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getName(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                             JSObjectRef object,
+                             JSStringRef /*propertyName*/,
+                             JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -395,13 +392,13 @@ JSValueRef JSWidget::getName(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getShortName(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                                  JSObjectRef object,
+                                  JSStringRef /*propertyName*/,
+                                  JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -409,13 +406,13 @@ JSValueRef JSWidget::getShortName(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getVersion(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                                JSObjectRef object,
+                                JSStringRef /*propertyName*/,
+                                JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -423,13 +420,13 @@ JSValueRef JSWidget::getVersion(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getHeight(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                               JSObjectRef object,
+                               JSStringRef /*propertyName*/,
+                               JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -441,13 +438,13 @@ JSValueRef JSWidget::getHeight(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 JSValueRef JSWidget::getWidth(JSContextRef context,
-        JSObjectRef object,
-        JSStringRef propertyName,
-        JSValueRef* exception)
+                              JSObjectRef object,
+                              JSStringRef /*propertyName*/,
+                              JSValueRef* exception)
 {
     Try {
         Converter converter(context);
@@ -459,16 +456,16 @@ JSValueRef JSWidget::getWidth(JSContextRef context,
     }
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_PLATFORM_ERROR
+        CATCH_EXCEPTION_PLATFORM_ERROR
 }
 
 bool JSWidget::hasProperty(JSContextRef context,
-                           JSObjectRef object,
+                           JSObjectRef /*object*/,
                            JSStringRef propertyName)
 {
     LogDebug("enter");
 
-    Try{
+    Try {
         Converter converter(context);
 
         std::string key = converter.toString(propertyName);
@@ -506,11 +503,10 @@ JSValueRef JSWidget::getProperty(JSContextRef context,
 
         std::string key = converter.toString(propertyName);
 
-        if (key=="preferences") {
+        if (key == "preferences") {
             Converter converter(context);
             JSObjectRef pref = getPreferences(object);
-            if (!pref)
-            {
+            if (!pref) {
                 LogError("Preferences object is NULL");
                 return JSValueMakeUndefined(context);
             }
@@ -522,43 +518,43 @@ JSValueRef JSWidget::getProperty(JSContextRef context,
 
     CATCH_EXCEPTION_CONVERSION
     CATCH_EXCEPTION_NULL_PTR
-    CATCH_EXCEPTION_INVALID_ARG
+        CATCH_EXCEPTION_INVALID_ARG
 }
 
 bool JSWidget::setProperty(JSContextRef context,
-                           JSObjectRef object,
+                           JSObjectRef /*object*/,
                            JSStringRef propertyName,
-                           JSValueRef jvalue,
+                           JSValueRef /*jvalue*/,
                            JSValueRef* exception)
 {
     LogDebug("enter");
 
-    Try{
+    Try {
         Converter converter(context);
 
         std::string key = converter.toString(propertyName);
-        if (key == "preferences"){
+        if (key == "preferences") {
             LogError("Object is read only");
             return true;
         }
     }
     CATCH_EXCEPTION_INVALID_ARG
     CATCH_EXCEPTION_CONVERSION
-    CATCH_EXCEPTION_NULL_PTR
+        CATCH_EXCEPTION_NULL_PTR
 
     return false;
 }
 
 JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
-                                        JSObjectRef constructor,
-                                        size_t argumentCount,
-                                        const JSValueRef arguments[],
-                                        JSValueRef* exception)
+                                        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!");
+                 "local context!");
         return JSObjectMake(context, JSWidget::getClassRef(), NULL);
     }
     return JSObjectMake(m_globalContext, JSWidget::getClassRef(), NULL);
@@ -571,6 +567,5 @@ JSObjectRef JSWidget::callAsConstructor(JSContextRef context,
 #undef CATCH_EXCEPTION_SECURITY
 #undef CATCH_EXCEPTION_OUT_OF_RANGE
 #undef CATCH_EXCEPTION_INVALID_ARG
-
 }
 }