Update change log and spec for wrt-plugins-tizen_0.4.70
[platform/framework/web/wrt-plugins-tizen.git] / src / Content / JSContentManager.cpp
index 0a99561..a52042e 100755 (executable)
@@ -33,6 +33,7 @@
 #include <JSWebAPIErrorFactory.h>
 #include <ArgumentValidator.h>
 #include <TimeTracer.h>
+#include <Security.h>
 
 #include "JSUtil.h"
 #include "ContentFactory.h"
@@ -43,7 +44,7 @@
 #include "JSVideo.h"
 #include "JSAudio.h"
 #include "ContentConverter.h"
-#include "plugin_config.h"
+#include "plugin_config_impl.h"
 #include "ContentAsyncCallbackManager.h"
 #include "ContentListener.h"
 #include "ContentVideo.h"
@@ -113,8 +114,8 @@ JSValueRef JSMediacontentManager::getFolders(
 {
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if (!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
@@ -203,16 +204,14 @@ JSValueRef JSMediacontentManager::findItems(
 
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if(!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
-    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_FIND_ITEMS);
-
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_FIND_ITEMS);
 
     JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
 
@@ -344,16 +343,15 @@ JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
         JSValueRef* exception)
 {
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if(!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
     JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
-    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
 
     JSCallbackManagerPtr cbm(NULL);
     MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
@@ -448,15 +446,14 @@ JSValueRef JSMediacontentManager::updateItem(
 
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if (!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
-    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_UPDATE_ITEM);
 
     Try
     {
@@ -526,6 +523,11 @@ JSValueRef JSMediacontentManager::updateItem(
             }
         }
 
+        JSValueRef nameValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "name");
+        if((JSValueIsNull(context, nameValRef) || JSValueIsUndefined(context, nameValRef)) ||
+            JSUtil::JSValueToString(context, nameValRef) == ""){
+            ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "name is not valid.");
+        }
         event = JSMedia::getMediaObject(arg);
         dplEvent->setMediaItem(event);
 
@@ -594,15 +596,14 @@ JSValueRef JSMediacontentManager::scanFile(
 {
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if(!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
-    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SCAN_FILE);
 
     string path;
     CallbackUserData *callback = NULL;
@@ -681,15 +682,14 @@ JSValueRef JSMediacontentManager::setChangeListener(
 {
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if(!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
-    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
 
     try{
         ArgumentValidator argValidator(context, argumentCount, arguments);
@@ -722,15 +722,14 @@ JSValueRef JSMediacontentManager::unsetChangeListener(
                         JSValueRef* exception)
 {
     TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
-    MediacontentManagerPrivObject *privateObject;
-    privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+    MediacontentManagerPriv *privateObject;
+    privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
     if(!privateObject) {
         DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
         return JSWebAPIErrorFactory::postException(context, exception, err);
     }
 
-    AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
-    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
 
     try{
         // perform
@@ -766,11 +765,11 @@ const JSClassDefinition* JSMediacontentManager::getClassInfo()
 
 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
 {
-    MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
+    MediacontentManagerPriv *privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(object));
     if (NULL == privateObject)
     {
         IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
-        privateObject = new MediacontentManagerPrivObject(context, contentManager);
+        privateObject = new MediacontentManagerPriv(context, contentManager);
         if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
         {
             delete privateObject;
@@ -781,7 +780,7 @@ void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
 
 void JSMediacontentManager::finalize(JSObjectRef object)
 {
-    MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
+    MediacontentManagerPriv* priv = static_cast<MediacontentManagerPriv*> (JSObjectGetPrivate(object));
     if(priv != NULL)
     {
         delete priv;
@@ -796,7 +795,7 @@ IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
                         const JSObjectRef object,
                         JSValueRef* exception)
 {
-    MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
+    MediacontentManagerPriv *priv = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(object));
     if (priv)
     {
         return priv->getObject();