Update change log and spec for wrt-plugins-tizen_0.4.70
[platform/framework/web/wrt-plugins-tizen.git] / src / Content / JSContentManager.cpp
index 26ec105..a52042e 100755 (executable)
 // limitations under the License.
 //
 
-
 #include <cassert>
 #include <memory>
-#include <dpl/log/log.h>
 #include <CommonsJavaScript/Utils.h>
 #include <CommonsJavaScript/Validator.h>
 #include <CommonsJavaScript/Converter.h>
 #include <CommonsJavaScript/JSPendingOperation.h>
 #include <CommonsJavaScript/PrivateObject.h>
 #include <CommonsJavaScript/ScopedJSStringRef.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
 #include <SecurityExceptions.h>
 #include <CallbackUserData.h>
 #include <MultiCallbackUserData.h>
 #include <GlobalContextManager.h>
 #include <FilterConverter.h>
-#include "JSUtil.h"
+#include <JSWebAPIErrorFactory.h>
+#include <ArgumentValidator.h>
+#include <TimeTracer.h>
+#include <Security.h>
 
+#include "JSUtil.h"
 #include "ContentFactory.h"
 #include "ContentController.h"
 #include "JSContentManager.h"
 #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"
 #include "ContentImage.h"
 #include "ContentFilterConverter.h"
-
+#include "ContentUtility.h"
+#include <Logger.h>
 
 using namespace DeviceAPI::Common;
 using namespace DeviceAPI::Tizen;
 using namespace WrtDeviceApis::Commons;
 using namespace WrtDeviceApis::CommonsJavaScript;
 
-#define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME                            "content"
+#define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME                 "content"
 
 namespace DeviceAPI {
 namespace Content {
@@ -69,13 +70,13 @@ JSStaticValue JSMediacontentManager::m_property[] =
 
 JSStaticFunction JSMediacontentManager::m_function[] = 
 {
-       { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
-       { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
+    { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
+    { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
     { 0, 0, 0 }
 };
 
@@ -84,123 +85,108 @@ JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
 
 JSClassDefinition JSMediacontentManager::m_classInfo =
 {
-               0,
-               kJSClassAttributeNone,
-               TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
-               0,
-               m_property,
-               m_function,
-               initialize,
-               finalize,
-               NULL, //hasProperty,
-               NULL, //getProperty,
-               NULL, //setProperty,
-               NULL, //deleteProperty,
-               NULL, //getPropertyNames,
-               NULL, //callAsFunction,
-               NULL, //callAsConstructor,
-               NULL,
-               NULL, //convertToType
+        0,
+        kJSClassAttributeNone,
+        TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
+        0,
+        m_property,
+        m_function,
+        initialize,
+        finalize,
+        NULL, //hasProperty,
+        NULL, //getProperty,
+        NULL, //setProperty,
+        NULL, //deleteProperty,
+        NULL, //getPropertyNames,
+        NULL, //callAsFunction,
+        NULL, //callAsConstructor,
+        NULL,
+        NULL, //convertToType
 };
 
 JSValueRef JSMediacontentManager::getFolders(
-                                                       JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSObjectRef thisObject,
-                                                       size_t argumentCount,
-                                                       const JSValueRef arguments[],
-                                                       JSValueRef* exception )
+                            JSContextRef context,
+                            JSObjectRef object,
+                            JSObjectRef thisObject,
+                            size_t argumentCount,
+                            const JSValueRef arguments[],
+                            JSValueRef* exception )
 {
-       LogDebug("JSContentManagerManager::getFolders entered");
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
+    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);
+    }
 
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
+    JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-       JSContextRef globalContext = privateObject->getContext();
-       Validator validator(context);
     JSCallbackManagerPtr cbm(NULL);
-    FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+    cbm = JSCallbackManager::createObject(globalContext);
+    
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+        JSObjectRef successCallbackObj = argValidator.toFunction(0);
+        if(successCallbackObj){
+            cbm->setOnSuccess(successCallbackObj);
+        }
+        else{
+            throw TypeMismatchException("SuccessCallback type mismatched.");
+        }
 
-       cbm = JSCallbackManager::createObject(globalContext);
-       cbm->setObject(thisObject);
+        JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
+        if(errorCallbackObj){
+            cbm->setOnError(errorCallbackObj);
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIErrorFactory::postException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
+        return JSWebAPIErrorFactory::postException(context, exception, err);
+    }
 
     Try
     {
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-
-               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-               if(argumentCount >= 1)  //MediaFolderArraySuccessCB successCallback
-               {
-                       if(validator.isCallback(arguments[0]))
-                       {
-                               onSuccessForCbm = arguments[0];
-                       }
-                       else
-                       {
-                               ThrowMsg(ConversionException, "SuccessCallback type mismatched.");
-                       }
-               }
-               else
-               {
-                       ThrowMsg(ConversionException,"There is no successCallback.");
-               }
-               if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
-               {
-                       if(validator.isCallback(arguments[1]))
-                       {
-                               onErrorForCbm = arguments[1];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
-                       }
-               }
-               if(cbm)
-               {
-                       cbm->setOnSuccess(onSuccessForCbm);
-                       cbm->setOnError(onErrorForCbm);
-               }
-
-               IEventFindFolderPtr dplEvent(new IEventFindFolder());
-               dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
-               dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
-
-               contentMgr->findFolder(dplEvent);
-
-               MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+        IEventFindFolderPtr dplEvent(new IEventFindFolder());
+        dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
+
+        contentMgr->findFolder(dplEvent);
+
+        MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(WrtDeviceApis::Commons::UnsupportedException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::ConversionException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::NotFoundException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::Exception)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
     return JSValueMakeUndefined(context);
 
 }
@@ -208,181 +194,142 @@ JSValueRef JSMediacontentManager::getFolders(
 
 
 JSValueRef JSMediacontentManager::findItems(
-                                                       JSContextRef context,
-                                                       JSObjectRef object,
-                                                       JSObjectRef thisObject,
-                                                       size_t argumentCount,
-                                                       const JSValueRef arguments[],
-                                                       JSValueRef* exception )
+                            JSContextRef context,
+                            JSObjectRef object,
+                            JSObjectRef thisObject,
+                            size_t argumentCount,
+                            const JSValueRef arguments[],
+                            JSValueRef* exception )
 {
 
-       LogDebug("JSContentManagerManager::findItems entered");
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(
-            CONTENT_FUNCTION_API_FIND_ITEMS);
+    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);
+    }
 
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_FIND_ITEMS);
 
+    JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
 
-       JSContextRef globalContext = privateObject->getContext();
-       Validator validator(context);
     JSCallbackManagerPtr cbm(NULL);
-    MediaContentFilterConverterFactory::ConverterType filterConverter = MediaContentFilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
-       MediaConverter mediaConverter(globalContext);
+    MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
+    MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+    cbm = JSCallbackManager::createObject(globalContext);
+
+    string folderId;
+    Tizen::FilterPtr filter;
+    Tizen::SortModePtr sortPtr;
+    JSObjectRef filterObj;
+    JSObjectRef sortModeObj;
+    IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+        JSObjectRef successCallbackObj = argValidator.toFunction(0);
+        if(successCallbackObj){
+            cbm->setOnSuccess(successCallbackObj);
+        }
+        else{
+            throw TypeMismatchException("SuccessCallback type mismatched.");
+        }
 
-       cbm = JSCallbackManager::createObject(globalContext);
-       cbm->setObject(thisObject);
+        JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
+        if(errorCallbackObj){
+            cbm->setOnError(errorCallbackObj);
+        }
 
+        folderId = argValidator.toString(2, true);
+        if(!folderId.empty()){
+            if(folderId != "null" ){
+                dplEvent->setFolderID(folderId);
+            }
+            else if(folderId == "undefined"){
+                throw InvalidValuesException("folderId is not valid.");
+            }
+        }
+
+        //filter
+        filterObj = argValidator.toObject(3,true);
+
+        //sortMode
+        sortModeObj= argValidator.toObject(4,true);
+
+        // count
+        if(argumentCount >= 6){
+            if(!JSValueIsNull(context, arguments[5])){
+                long count = argValidator.toLong(5, true, 0);
+                if( count >= 0L ){
+                    dplEvent->setLimit(count);
+                }
+                else{
+                    throw InvalidValuesException( "count should be positive.");
+                }
+            }
+        }
+        if(argumentCount >= 7){
+            // offset
+            long offset = argValidator.toLong(6, true);
+            if( offset >= 0L ){
+                dplEvent->setOffset(offset);
+            }
+            else{
+                throw InvalidValuesException("offset should be positive.");
+            }
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIErrorFactory::postException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in find().");
+        return JSWebAPIErrorFactory::postException(context, exception, err);
+    }
 
     Try
     {
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-               IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
-               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-
-               if(argumentCount >= 1)  //MediaItemArraySuccessCB successCallback
-               {
-                       if(validator.isCallback(arguments[0]))
-                       {
-                               onSuccessForCbm = arguments[0];
-                       }
-                       else
-                       {
-                               ThrowMsg(ConversionException,"SuccessCallback type mismatched.");
-                       }
-               }
-               else
-               {
-                       ThrowMsg(ConversionException,"There is no SuccessCallback.");
-               }
-               if(argumentCount >= 2)  //ErrorCallback? errorCallback
-               {
-                       if(validator.isCallback(arguments[1]))
-                       {
-                               onErrorForCbm = arguments[1];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
-                       }
-               }
-               if(cbm)
-               {
-                       cbm->setOnSuccess(onSuccessForCbm);
-                       cbm->setOnError(onErrorForCbm);
-               }
-
-               if(argumentCount >= 3)  //MediaFolderId id,
-               {
-                       string folderId = mediaConverter.toString(arguments[2]);
-                       if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
-                       {
-                               LogDebug("folderId:"+ folderId);
-
-                               int nFolderId = 0;
-                               istringstream(folderId) >> nFolderId; //string -> int
-
-                               if (nFolderId<0)
-                               {
-                                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
-                                               JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
-                                       return JSValueMakeUndefined(context);
-                               }
-
-                               dplEvent->setFolderID(folderId);
-                       }
-               }
-
-               if(argumentCount >= 4)  //optional AbstractFilter? filter
-               {
-                       if(JSValueIsObject(context, arguments[3]))
-                       {
-                               dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[3]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"Filter type mismatched.");
-                       }
-               }
-               if(argumentCount >= 5)  //optional SortMode? sortMode
-               {
-
-                       if ( JSValueIsObject(context, arguments[4]) &&
-                               !JSValueIsNull(context, arguments[4]) &&
-                               !JSValueIsUndefined(context, arguments[4]) &&
-                               !JSIsArrayValue(context, arguments[4]))
-                       {
-                               LogDebug("sortmode is object");
-                               dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[4]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"SortMode type mismatched.");
-                       }
-               }
-               if(argumentCount >= 6)  //optional unsigned long? count
-               {
-                       if(!JSValueIsNull(context, arguments[5]) && !JSValueIsUndefined(context, arguments[5])){
-                               long count = filterConverter->toLong(arguments[5]);
-                               if( count >= 0 ){
-                                       dplEvent->setLimit(count);
-                               }
-                               else{
-                                       ThrowMsg(InvalidArgumentException, "count should be positive.");
-                               }
-                       }
-               }
-               if(argumentCount >= 7)  //optional unsigned long? offset
-               {
-                       long offset = filterConverter->toLong(arguments[6]);
-                       if( offset >= 0 ){
-                               dplEvent->setOffset(offset);
-                       }
-                       else{
-                               ThrowMsg(InvalidArgumentException, "offset should be positive.");
-                       }
-               }
+        if(filterObj){
+            dplEvent->setFilter(fConverter->toFilter(filterObj));
+        }
+        if(sortModeObj){
+            dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
+        }
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
         contentMgr->browseFolder(dplEvent);
-
-               MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+        MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(WrtDeviceApis::Commons::UnsupportedException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::ConversionException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::NotFoundException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::Exception)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
     return JSValueMakeUndefined(context);
 }
 
@@ -395,511 +342,436 @@ JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
         const JSValueRef arguments[],
         JSValueRef* exception)
 {
-    LogDebug("JSContentManagerManager::updateItemsBatch entered");
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+    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 = privateObject->getContext();
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(
-            CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
 
-       Validator validator(context);
     JSCallbackManagerPtr cbm(NULL);
-    FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
-       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
-
-       cbm = JSCallbackManager::createObject(globalContext);
-       cbm->setObject(thisObject);
-
-       Try
-    {
-
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-
-               JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
-               MediacontentMediaListPtr events;
-               if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0])))     //MediaItem[] items
-               {
-                       events = converter->toVectorOfMediaItem(arguments[0]);
-                       if(!events)
-                       {
-                               ThrowMsg(ConversionException, "Items type mismatched.");
-                       }
-               }
-               else
-               {
-                       ThrowMsg(ConversionException, "Items type mismatched.");
-               }
-
-               if(argumentCount >= 2)  //Function? successCallback,
-               {
-                       if(validator.isCallback(arguments[1]))
-                       {
-                               onSuccessForCbm = arguments[1];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"successCallback type mismatched.");
-                       }
-               }
-
-               if(argumentCount >= 3)  //ErrorCallback? errorCallback,
-               {
-                       if(validator.isCallback(arguments[2]))
-                       {
-                               onErrorForCbm = arguments[2];
-                       }
-                       else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
-                       {
-                               ThrowMsg(ConversionException,"ErrorCallback type is mismatched.");
-                       }
-               }
-
-               if(cbm)
-               {
-                       cbm->setOnSuccess(onSuccessForCbm);
-                       cbm->setOnError(onErrorForCbm);
-               }
+    MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+    cbm = JSCallbackManager::createObject(globalContext);
+
+    MediacontentMediaListPtr contents;
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+
+        if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
+            contents = converter->toVectorOfMediaItem(arguments[0]);
+            if(!contents)
+            {
+                throw TypeMismatchException( "content type mismatched.");
+            }
+        }
+        else{
+            throw TypeMismatchException("content type mismatched.");
+        }
+        
+        JSObjectRef successCallbackObj = argValidator.toFunction(1,true);        
+        if(successCallbackObj){
+            cbm->setOnSuccess(successCallbackObj);
+        }
+
+        JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
+        if(errorCallbackObj){
+            cbm->setOnError(errorCallbackObj);
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIErrorFactory::postException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in updateBatch().");
+        return JSWebAPIErrorFactory::postException(context, exception, err);
+    }
+
+    Try
+    {
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
 
         IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
-        dplEvent->setMediaItems(events);
+        dplEvent->setMediaItems(contents);
         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
 
         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
         contentMgr->updateMediaItems(dplEvent);
 
-               MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+        MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
     }
     Catch(WrtDeviceApis::Commons::UnsupportedException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::ConversionException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::NotFoundException)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
     }
     Catch(WrtDeviceApis::Commons::Exception)
     {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
     }
 
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
     return JSValueMakeUndefined(context);
 }
 
 
 
 JSValueRef JSMediacontentManager::updateItem(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
 {
-LogDebug("JSContentManagerManager::updateItem entered");
-
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-       if (!privateObject) {
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
-       }
-
-
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
 
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-       Validator validator(context);
-
-       Try
-       {
-               IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
-
-               //parameter : MediaItem item
-
-               JSObjectRef arg;
-               if(argumentCount >= 1)
-               {
-                       if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
-                               !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
-                               !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&                       
-                               !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
-                                   ThrowMsg(ConversionException, "Item type mismatched.");
-                       }
-                       arg = JSValueToObject(context, arguments[0], exception);
-               }
-               else
-               {
-                        ThrowMsg(ConversionException, "Item type mismatched.");
-               }
-
-               MediacontentMediaPtr event;
-               IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
-
-               if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
-
-                       JSValueRef geoValRef = JSUtil::getProperty(context ,
-                               JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
-                       JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
-                       double latitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "latitude"));
-
-                       double longitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "longitude"));
-
-                       MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
-                       imgPtr->setImageLatitude(latitude);
-                       imgPtr->setImageLongitude(longitude);
-
-               }
-               else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
-                       JSValueRef geoValRef = JSUtil::getProperty(context ,
-                               JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
-                       JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+    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);
+    }
 
-                       double latitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "latitude"));
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_UPDATE_ITEM);
 
-                       double longitude = JSUtil::JSValueToDouble(context,
-                               JSUtil::getProperty(context, geoObjRef, "longitude"));
+    Try
+    {
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+
+        //parameter : MediaItem item
+
+        JSObjectRef arg;
+        if(argumentCount >= 1)
+        {
+            if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
+                !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
+                !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&           
+                !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
+                    ThrowMsg(ConversionException, "Content type mismatched.");
+            }
+            arg = JSValueToObject(context, arguments[0], exception);
+        }
+        else
+        {
+             ThrowMsg(ConversionException, "Content type mismatched.");
+        }
 
-                       MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
-                       vedioPtr->setVideoLatitude(latitude);
-                       vedioPtr->setVideoLongitude(longitude);
-               }
+        MediacontentMediaPtr event;
+        IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
+
+        if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
+            MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
+            JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
+            if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
+                JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+                double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
+                double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
+                if(ContentUtility::checkLocation(latitude, latitude)){
+                    imgPtr->setImageLatitude(latitude);
+                    imgPtr->setImageLongitude(longitude);
+                }
+                else{
+                    ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
+                }
+            }
+            else
+            {
+                imgPtr->setImageLatitude(DEFAULT_GEOLOCATION);
+                imgPtr->setImageLongitude(DEFAULT_GEOLOCATION);
+            }
+        }
+        else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
+            MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
+            JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
+            if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
+                JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
+                double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
+                double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
+                if(ContentUtility::checkLocation(latitude, latitude)){
+                    vedioPtr->setVideoLatitude(latitude);
+                    vedioPtr->setVideoLongitude(longitude);
+                }
+                else{
+                    ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
+                }
+            }
+            else
+            {
+                vedioPtr->setVideoLatitude(DEFAULT_GEOLOCATION);
+                vedioPtr->setVideoLongitude(DEFAULT_GEOLOCATION);
+            }
+        }
 
-               event = JSMedia::getMediaObject(arg);
-               dplEvent->setMediaItem(event);
+        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);
 
-               dplEvent->setForSynchronousCall();
-               contentMgr->updateMedia(dplEvent);
+        dplEvent->setForSynchronousCall();
+        contentMgr->updateMedia(dplEvent);
 
         if (!(dplEvent->getResult())) {
             ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
         }
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+    }
+    Catch(WrtDeviceApis::Commons::UnsupportedException)
+    {
+    LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+    return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+    {
+    LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+    return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException)
+    {
+    LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+    return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::NotFoundException)
+    {
+    LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+    return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+    LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+    return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+    return JSValueMakeUndefined(context);
 
 }
 
 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
     CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
-       if(cb != NULL){
-                       if(err_msg.empty() ){
-                               Converter converter(cb->getContext());
-                               JSValueRef jsPath = converter.toJSValueRef(path);
-                               cb->callSuccessCallback(jsPath);
-                       }
-                       else{
-                               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cb->getContext(), JSTizenException::UNKNOWN_ERROR, err_msg);
-                               cb->callErrorCallback(errorObject);
-                       }
-                       delete cb;
-       }
+    if(cb != NULL){
+            if(err_msg.empty() ){
+                        Converter converter(cb->getContext());
+                        JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
+                        cb->callSuccessCallback(jsPath);
+            }
+            else{
+                        DeviceAPI::Common::UnknownException err(err_msg.c_str());
+                        JSObjectRef errorObject = JSWebAPIErrorFactory::makeErrorObject(cb->getContext(),err);
+                        cb->callErrorCallback(errorObject);
+            }
+            delete cb;
+    }
 }
 
 JSValueRef JSMediacontentManager::scanFile(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
 {
-       LogDebug("JSContentManagerManager::scanFile entered");
-
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       Try
-       {
-
-               if(!privateObject){
-                       ThrowMsg(ConversionException, "private object is null");
-               }
-
-               CallbackUserData *callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
-
-               Converter convert(context);
-               Validator validator(context);
-               IMediacontentManagerPtr contentMgr = privateObject->getObject();
-               string path;
-
-               if(argumentCount >= 1){                                 //directoryURI
-                       path = convert.toString(arguments[0]);
-                       if(validator.isNullOrUndefined(arguments[0])){
-                               ThrowMsg(InvalidArgumentException, path+" is not available");
-                       }
-               }
-               else{
-                       ThrowMsg(InvalidArgumentException, "file path is not available");
-               }
-
-               if(argumentCount >= 2){                                 //successCallback[optional|nullable]
-                       if(validator.isCallback(arguments[1])){
-                               callback->setSuccessCallback(arguments[1]);
-                       }
-                       else if(!(JSValueIsNull(context,arguments[1]))){
-                               ThrowMsg(ConversionException, path + ":successCallback is not available");
-                       }
-               }
-
-               if(argumentCount >= 3){                                 //errorCallback
-                       if(validator.isCallback(arguments[2])){
-                               callback->setErrorCallback(arguments[2]);
-                       }
-                       else if(!(JSValueIsNull(context,arguments[2]))){
-                               ThrowMsg(ConversionException, path + ":errorCallback is not available");
-                       }
-               }
-
-               contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
-
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
 
-}
+    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);
+    }
 
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SCAN_FILE);
 
-JSValueRef JSMediacontentManager::setChangeListener(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
-{
-       LogDebug("JSContentManagerManager::setChangeListener entered");
+    string path;
+    CallbackUserData *callback = NULL;
+    try{
+        callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));    
+        ArgumentValidator argValidator(context, argumentCount, arguments);    
+        path = argValidator.toString(0);
+        if(path.empty()){
+            throw TypeMismatchException("File path type mismatched.");
+        }
+        else if(path == "null" || path == "undefined"){
+            throw InvalidValuesException("File path is not valid.");
+        }
+        path = ContentUtility::convertUriToPath(path);
 
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+        JSObjectRef successCallbackObj = argValidator.toFunction(1,true);        
+        if(successCallbackObj){
+            callback->setSuccessCallback(successCallbackObj);
+        }
 
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+        JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
+        if(errorCallbackObj){
+            callback->setErrorCallback(errorCallbackObj);
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIErrorFactory::postException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
+        return JSWebAPIErrorFactory::postException(context, exception, err);
+    }
 
-       Try
-       {
+    Try
+    {
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+        contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
+    }
+    Catch(WrtDeviceApis::Commons::UnsupportedException)
+    {
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+    {
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException)
+    {
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::NotFoundException)
+    {
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LoggerW("Exception: "<<_rethrown_exception.GetMessage());
+        return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
 
-               if(!privateObject){
-                       ThrowMsg(ConversionException, "private object is null");
-               }
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+    return JSValueMakeUndefined(context);
+}
 
-        if(argumentCount>=1) {
-            if (!JSValueIsObject(context, arguments[0])) {
-                ThrowMsg(ConversionException, "Wrong first parameter type.");
-            }
-        }
-               else{
-            ThrowMsg(ConversionException, "Wrong first parameter type.");
-        }
 
-               Converter convert(context);
-               Validator validator(context);
-
-               JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
-
-               // changeCallback Object
-               JSObjectRef callbackObj = convert.toJSObjectRef(arguments[0]);
-
-               ContentListener *listener = new ContentListener(globalCtx, callbackObj);
-
-               // perform
-               IMediacontentManagerPtr contentMgr = privateObject->getObject();
-               if(!(contentMgr->setListener(listener)))
-               {
-                       ThrowMsg(Exception, "Unknown exception is occured by platfrom");
-               }
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+JSValueRef JSMediacontentManager::setChangeListener(
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
+{
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+
+    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);
+    }
 
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
+
+    try{
+        ArgumentValidator argValidator(context, argumentCount, arguments);
+        JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);        
+        JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
+        ContentListener *listener = new ContentListener(globalCtx, callbackObj);
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+        if(!(contentMgr->setListener(listener)))
+        {
+            throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIErrorFactory::postException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in setChangeListener().");
+        return JSWebAPIErrorFactory::postException(context, exception, err);
+    }
 
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+    return JSValueMakeUndefined(context);
 }
 
 JSValueRef JSMediacontentManager::unsetChangeListener(
-                                               JSContextRef context,
-                                               JSObjectRef object,
-                                               JSObjectRef thisObject,
-                                               size_t argumentCount,
-                                               const JSValueRef arguments[],
-                                               JSValueRef* exception)
+                        JSContextRef context,
+                        JSObjectRef object,
+                        JSObjectRef thisObject,
+                        size_t argumentCount,
+                        const JSValueRef arguments[],
+                        JSValueRef* exception)
 {
-       LogDebug("JSContentManagerManager::unsetChangeListener entered");
-
-       MediacontentManagerPrivObject *privateObject;
-       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
-
-       AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
-       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-       Try
-       {
-               if(!privateObject){
-                       ThrowMsg(ConversionException, "private object is null");
-               }
-
-               // perform
-               IMediacontentManagerPtr contentMgr = privateObject->getObject();
-               if(!(contentMgr->unsetListener()))
-               {
-                       ThrowMsg(Exception, "Unknown exception is occured by platfrom");
-               }
-       }
-       Catch(WrtDeviceApis::Commons::UnsupportedException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::ConversionException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::NotFoundException)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
-       }
-       Catch(WrtDeviceApis::Commons::Exception)
-       {
-               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
-               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
-       }
-
-       return JSValueMakeUndefined(context);
+    TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
+    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);
+    }
 
+    TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
+
+    try{
+        // perform
+        IMediacontentManagerPtr contentMgr = privateObject->getObject();
+        if(!(contentMgr->unsetListener()))
+        {
+            throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
+        }
+    }catch(const BasePlatformException &err){
+        return JSWebAPIErrorFactory::postException(context,exception,err);
+    }
+    catch(...){
+        DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
+        return JSWebAPIErrorFactory::postException(context, exception, err);
+    }
+
+       TIME_TRACER_ITEM_END(__FUNCTION__, 0);
+    return JSValueMakeUndefined(context);
 }
 
 const JSClassRef JSMediacontentManager::getClassRef() {
-       if (!m_jsClassRef) {
-               m_jsClassRef = JSClassCreate(&m_classInfo);
-       }
-       return m_jsClassRef;
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
 }
 
 
 const JSClassDefinition* JSMediacontentManager::getClassInfo()
 {
-       return &m_classInfo;
+    return &m_classInfo;
 }
 
 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
 {
-    LogDebug("JSContentManager  initialize entered");
-    MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
+    MediacontentManagerPriv *privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(object));
     if (NULL == privateObject)
-       {
-        LogDebug("Create ContenttManagerPrivObject");
+    {
         IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
-        privateObject = new MediacontentManagerPrivObject(context, contentManager);
+        privateObject = new MediacontentManagerPriv(context, contentManager);
         if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
-               {
+        {
             delete privateObject;
         }
     }
@@ -908,26 +780,24 @@ void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
 
 void JSMediacontentManager::finalize(JSObjectRef object)
 {
-       LogDebug("Entered");
-       MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
-       if(priv != NULL)
-       {
-               LogDebug("Deleting coordinates object");
-               delete priv;
-               JSObjectSetPrivate(object, NULL);
-               priv = NULL;
-       }
+    MediacontentManagerPriv* priv = static_cast<MediacontentManagerPriv*> (JSObjectGetPrivate(object));
+    if(priv != NULL)
+    {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+        priv = NULL;
+    }
 
 }
 
 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
-                                               JSContextRef ctx,
-                                       const JSObjectRef object,
-                                       JSValueRef* exception)
+                        JSContextRef ctx,
+                        const JSObjectRef object,
+                        JSValueRef* exception)
 {
-    MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
+    MediacontentManagerPriv *priv = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(object));
     if (priv)
-       {
+    {
         return priv->getObject();
     }
     ThrowMsg(ConversionException, "Private object is NULL.");