Update change log and spec for wrt-plugins-tizen_0.4.57
[platform/framework/web/wrt-plugins-tizen.git] / src / Content / JSContent.cpp
old mode 100644 (file)
new mode 100755 (executable)
index b01bbb0..35cf614
@@ -18,8 +18,7 @@
 #include <CommonsJavaScript/PrivateObject.h>
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/JSUtils.h>
-#include <JSTizenException.h>
-#include <JSTizenExceptionFactory.h>
+#include <JSWebAPIErrorFactory.h>
 #include "JSContent.h"
 #include <Logger.h>
 
@@ -88,40 +87,35 @@ JSClassRef JSMedia::m_jsClassRef = JSClassCreate(JSMedia::getClassInfo());
 
 void JSMedia::initialize(JSContextRef context, JSObjectRef object)
 {
-    LoggerD( "entered" );
     MediaPrivObject *priv = static_cast<MediaPrivObject*>( JSObjectGetPrivate( object ) );
     if (!priv) 
        {
         MediacontentMediaPtr privateData(new MediacontentMedia());
         priv = new MediaPrivObject(context, privateData);
         JSObjectSetPrivate(object, static_cast<void*>(priv));
-        LoggerD("new event is created" );
     }
     else 
-       {
+    {
         LoggerD("private object already exists");
     }
 }
 
 void JSMedia::finalize(JSObjectRef object)
 {
-    LoggerD( "entered" );
     MediaPrivObject *priv = static_cast<MediaPrivObject*>( JSObjectGetPrivate( object ) ) ;
-       if (priv != NULL)
-       {
-               delete (priv);
-               priv = NULL;
-               JSObjectSetPrivate(object, NULL);
-       }
-    
+    if (priv != NULL)
+    {
+        delete (priv);
+        priv = NULL;
+        JSObjectSetPrivate(object, NULL);
+    }
 }
 
 const JSClassRef JSMedia::getClassRef()
 {
-       LoggerD("JSMedia::getClassRef()");
     if (!m_jsClassRef) 
-       {
-            m_jsClassRef = JSClassCreate(&m_classInfo);
+    {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
     }
     return m_jsClassRef;
 }
@@ -133,15 +127,14 @@ const JSClassDefinition* JSMedia::getClassInfo()
 
 MediacontentMediaPtr JSMedia::getMediaObject(JSObjectRef object)
 {
-    LoggerD("entered");
     MediaPrivObject *priv = static_cast<MediaPrivObject*>(JSObjectGetPrivate(object));
     if(!priv) 
-       {
+    {
         ThrowMsg(NullPointerException, "Private object is null");
     }
     MediacontentMediaPtr result = priv->getObject();
     if (!result) 
-       {
+    {
         ThrowMsg(NullPointerException, "Private object is null");
     }
     return result;
@@ -153,12 +146,10 @@ JSValueRef JSMedia::getPropertyId(
                                        JSStringRef propertyName, 
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
-
         return converter.toJSValueRef(media->getMediaUUID());
     }
     Catch(Exception)
@@ -175,7 +166,6 @@ JSValueRef  JSMedia::getPropertyMimeType(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
@@ -197,12 +187,10 @@ JSValueRef JSMedia::getPropertyDisplayName(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("getPropertyDisplayName::entered");
     Try
     {
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
-       LoggerD("getDisplayName:"<<media->getDisplayName());    
         return converter.toJSValueRef(media->getDisplayName());
     }
     Catch(Exception)
@@ -218,12 +206,10 @@ JSValueRef JSMedia::getPropertyTitle(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("getPropertyDisplayName::entered");
     Try
     {
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
-               LoggerD("getTitle:"<<media->getTitle());
         return converter.toJSValueRef(media->getTitle());
     }
     Catch(Exception)
@@ -240,7 +226,6 @@ JSValueRef JSMedia::getPropertyFilePath(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
@@ -261,7 +246,6 @@ JSValueRef JSMedia::getPropertyThumbnailPath(
                                        JSStringRef propertyName, 
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
@@ -292,12 +276,11 @@ JSValueRef JSMedia::getPropertyDescription(
                                        JSStringRef propertyName, 
                                        JSValueRef* exception)
 {
-    LoggerD("getPropertyDescription::entered");
     Try
     {
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
-        if(!(media->getDescription().empty()))
+//        if(!(media->getDescription().empty()))
         {
             return converter.toJSValueRef(media->getDescription());
         }
@@ -316,7 +299,6 @@ JSValueRef JSMedia::getPropertyModifiedDate(
                                        JSStringRef propertyName, 
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
@@ -339,7 +321,6 @@ JSValueRef JSMedia::getPropertyReleasedDate(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
@@ -364,7 +345,6 @@ JSValueRef JSMedia::getPropertyRating(
                                        JSStringRef propertyName, 
                                        JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
         Converter converter(context);
@@ -384,7 +364,6 @@ JSValueRef JSMedia::getPropertyType(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("getPropertyType::entered");
     Try
     {
         Converter converter(context);
@@ -405,14 +384,12 @@ JSValueRef JSMedia::getPropertySize(
                                        JSStringRef propertyName,
                                        JSValueRef* exception)
 {
-    LoggerD("getPropertyType::entered");
     Try
     {
         Converter converter(context);
         MediacontentMediaPtr media = getMediaObject(object);
-        LoggerD("size:" << media->getSize());
-       double var = (double)media->getSize(); //casting.
-       return converter.toJSValueRef(var);
+        double var = (double)media->getSize();
+        return converter.toJSValueRef(var);
     }
     Catch(Exception)
     {
@@ -431,30 +408,30 @@ JSValueRef JSMedia::getPropertyEditableAttr(
 {
     Try
     {
-               Converter converter(context);
-               MediacontentMediaPtr media = getMediaObject(object);
-               vector<std::string> editableAttrList = media->getEditableAttr();
-               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
-
-                       if (NULL == jsResult) 
-                       {
-                           ThrowMsg(NullPointerException, "Could not create js array object");
-                       }
-               for(unsigned int i=0; i<editableAttrList.size(); i++) 
-                       {
-                       JSValueRef val = converter.toJSValueRef(editableAttrList.at(i));
-                           if(!JSSetArrayElement(context, jsResult, i, val)) 
-                           {
-                              ThrowMsg(UnknownException, "Could not insert value into js array");
-                           }
-                       }
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        vector<std::string> editableAttrList = media->getEditableAttr();
+        JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+
+        if (NULL == jsResult)
+        {
+            ThrowMsg(NullPointerException, "Could not create js array object");
+        }
+        for(unsigned int i=0; i<editableAttrList.size(); i++)
+        {
+            JSValueRef val = converter.toJSValueRef(editableAttrList.at(i));
+            if(!JSSetArrayElement(context, jsResult, i, val))
+            {
+                ThrowMsg(UnknownException, "Could not insert value into js array");
+            }
+        }
                return jsResult;
-       }
-       Catch(Exception)
-       {
-               LoggerW("trying to get incorrect value");
-       }
-       return JSValueMakeUndefined(context);
+    }
+    Catch(Exception)
+    {
+        LoggerW("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
 
 }
 
@@ -466,86 +443,72 @@ bool      JSMedia::setPropertyRating(
                                JSValueRef value,
                                JSValueRef* exception)
 {
-    LoggerD("entered");
     Try
     {
        Converter converter(context);
        MediacontentMediaPtr objMedia = getMediaObject(object);
        int rating = converter.toInt(value);
 
-       LoggerD("Inserted value : " << rating);
-
-       if(rating < 0)
+       if(rating < 0 || rating > 10)
        {
-               rating = 0;
-               LoggerD("Rating value set 0 as inserted value is too small");
+            Throw(WrtDeviceApis::Commons::InvalidArgumentException);
        }
-       
        if ( objMedia->getRating() != rating)
        {
-               objMedia->setRating(rating, true);
+            objMedia->setRating(rating, true);
        }
-               
-        return true;
+       return true;
     }
     Catch(Exception)
     {
         LoggerW("trying to set incorrect value");
-        DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
     }
 
     return false;
 
 }
 
-bool           JSMedia::setPropertyDisplayName(
+bool JSMedia::setPropertyDisplayName(
                                        JSContextRef context,
                                        JSObjectRef object,
                                        JSStringRef propertyName,
                                        JSValueRef value,
                                        JSValueRef* exception)
 {
-       LoggerD("entered");
        Try
        {
                Converter converter(context);
                MediacontentMediaPtr objMedia = getMediaObject(object);
                string displayName = converter.toString(value);
 
-               LoggerD("Inserted value : " << displayName);
-               
-               if ((objMedia->getDescription()).compare(displayName) != 0)
+               if ((objMedia->getDisplayName()).compare(displayName) != 0)
                {
                        objMedia->setDisplayName(displayName, true);
                }
-               
+
                return true;
        }
        Catch(Exception)
        {
                LoggerW("trying to set incorrect value");
-               DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
        }
 
        return false;
 }
 
-bool           JSMedia::setPropertyDescription(
+bool JSMedia::setPropertyDescription(
                                        JSContextRef context,
                                        JSObjectRef object,
                                        JSStringRef propertyName,
                                        JSValueRef value,
                                        JSValueRef* exception)
 {
-       LoggerD("entered");
        Try
        {
                Converter converter(context);
                MediacontentMediaPtr objMedia = getMediaObject(object);
                string description = converter.toString(value);
-
-               LoggerD("Inserted value : " << description);
-               
+       
                if ( (objMedia->getDescription()).compare(description) != 0 )
                {
                        objMedia->setDescription(description, true);
@@ -556,9 +519,7 @@ bool                JSMedia::setPropertyDescription(
        Catch(Exception)
        {
                LoggerW("trying to set incorrect value");
-               DeviceAPI::Common::JSTizenExceptionFactory::postException(context, exception, DeviceAPI::Common::JSTizenException::TYPE_MISMATCH_ERROR);
        }
-
        return false;
 }