2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 #include <CommonsJavaScript/Utils.h>
21 #include <CommonsJavaScript/Validator.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/JSCallbackManager.h>
24 #include <CommonsJavaScript/JSUtils.h>
25 #include <CommonsJavaScript/JSPendingOperation.h>
26 #include <CommonsJavaScript/PrivateObject.h>
27 #include <CommonsJavaScript/ScopedJSStringRef.h>
28 #include <SecurityExceptions.h>
29 #include <CallbackUserData.h>
30 #include <MultiCallbackUserData.h>
31 #include <GlobalContextManager.h>
32 #include <FilterConverter.h>
33 #include <JSWebAPIErrorFactory.h>
34 #include <ArgumentValidator.h>
35 #include <TimeTracer.h>
39 #include "ContentFactory.h"
40 #include "ContentController.h"
41 #include "JSContentManager.h"
42 #include "JSContent.h"
46 #include "ContentConverter.h"
47 #include "plugin_config_impl.h"
48 #include "ContentAsyncCallbackManager.h"
49 #include "ContentListener.h"
50 #include "ContentVideo.h"
51 #include "ContentImage.h"
52 #include "ContentFilterConverter.h"
53 #include "ContentUtility.h"
56 using namespace DeviceAPI::Common;
57 using namespace DeviceAPI::Tizen;
58 using namespace WrtDeviceApis::Commons;
59 using namespace WrtDeviceApis::CommonsJavaScript;
61 #define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME "content"
66 JSStaticValue JSMediacontentManager::m_property[] =
71 JSStaticFunction JSMediacontentManager::m_function[] =
73 { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
74 { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
75 { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
76 { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
77 { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
78 { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
79 { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
84 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
86 JSClassDefinition JSMediacontentManager::m_classInfo =
89 kJSClassAttributeNone,
90 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
99 NULL, //deleteProperty,
100 NULL, //getPropertyNames,
101 NULL, //callAsFunction,
102 NULL, //callAsConstructor,
104 NULL, //convertToType
107 JSValueRef JSMediacontentManager::getFolders(
108 JSContextRef context,
110 JSObjectRef thisObject,
111 size_t argumentCount,
112 const JSValueRef arguments[],
113 JSValueRef* exception )
115 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
117 MediacontentManagerPriv *privateObject;
118 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
119 if (!privateObject) {
120 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
121 return JSWebAPIErrorFactory::postException(context, exception, err);
124 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
126 JSCallbackManagerPtr cbm(NULL);
127 cbm = JSCallbackManager::createObject(globalContext);
130 ArgumentValidator argValidator(context, argumentCount, arguments);
131 JSObjectRef successCallbackObj = argValidator.toFunction(0);
132 if(successCallbackObj){
133 cbm->setOnSuccess(successCallbackObj);
136 throw TypeMismatchException("SuccessCallback type mismatched.");
139 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
140 if(errorCallbackObj){
141 cbm->setOnError(errorCallbackObj);
143 }catch(const BasePlatformException &err){
144 return JSWebAPIErrorFactory::postException(context,exception,err);
147 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
148 return JSWebAPIErrorFactory::postException(context, exception, err);
153 IMediacontentManagerPtr contentMgr = privateObject->getObject();
155 IEventFindFolderPtr dplEvent(new IEventFindFolder());
156 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
157 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
159 contentMgr->findFolder(dplEvent);
161 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
163 Catch(WrtDeviceApis::Commons::UnsupportedException)
165 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
166 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
168 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
170 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
171 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
173 Catch(WrtDeviceApis::Commons::ConversionException)
175 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
176 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
178 Catch(WrtDeviceApis::Commons::NotFoundException)
180 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
181 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
183 Catch(WrtDeviceApis::Commons::Exception)
185 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
186 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
189 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
190 return JSValueMakeUndefined(context);
196 JSValueRef JSMediacontentManager::findItems(
197 JSContextRef context,
199 JSObjectRef thisObject,
200 size_t argumentCount,
201 const JSValueRef arguments[],
202 JSValueRef* exception )
205 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
207 MediacontentManagerPriv *privateObject;
208 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
210 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
211 return JSWebAPIErrorFactory::postException(context, exception, err);
214 TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_FIND_ITEMS);
216 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
218 JSCallbackManagerPtr cbm(NULL);
219 MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
220 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
222 cbm = JSCallbackManager::createObject(globalContext);
225 Tizen::FilterPtr filter;
226 Tizen::SortModePtr sortPtr;
227 JSObjectRef filterObj;
228 JSObjectRef sortModeObj;
229 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
231 ArgumentValidator argValidator(context, argumentCount, arguments);
232 JSObjectRef successCallbackObj = argValidator.toFunction(0);
233 if(successCallbackObj){
234 cbm->setOnSuccess(successCallbackObj);
237 throw TypeMismatchException("SuccessCallback type mismatched.");
240 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
241 if(errorCallbackObj){
242 cbm->setOnError(errorCallbackObj);
245 folderId = argValidator.toString(2, true);
246 if(!folderId.empty()){
247 if(folderId != "null" ){
248 dplEvent->setFolderID(folderId);
250 else if(folderId == "undefined"){
251 throw InvalidValuesException("folderId is not valid.");
256 filterObj = argValidator.toObject(3,true);
259 sortModeObj= argValidator.toObject(4,true);
262 if(argumentCount >= 6){
263 if(!JSValueIsNull(context, arguments[5])){
264 long count = argValidator.toLong(5, true, 0);
266 dplEvent->setLimit(count);
269 throw InvalidValuesException( "count should be positive.");
273 if(argumentCount >= 7){
275 long offset = argValidator.toLong(6, true);
277 dplEvent->setOffset(offset);
280 throw InvalidValuesException("offset should be positive.");
283 }catch(const BasePlatformException &err){
284 return JSWebAPIErrorFactory::postException(context,exception,err);
287 DeviceAPI::Common::UnknownException err("Unknown Error in find().");
288 return JSWebAPIErrorFactory::postException(context, exception, err);
294 dplEvent->setFilter(fConverter->toFilter(filterObj));
297 dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
299 IMediacontentManagerPtr contentMgr = privateObject->getObject();
301 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
302 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
303 contentMgr->browseFolder(dplEvent);
304 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
306 Catch(WrtDeviceApis::Commons::UnsupportedException)
308 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
309 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
311 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
313 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
314 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
316 Catch(WrtDeviceApis::Commons::ConversionException)
318 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
319 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
321 Catch(WrtDeviceApis::Commons::NotFoundException)
323 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
324 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
326 Catch(WrtDeviceApis::Commons::Exception)
328 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
329 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
332 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
333 return JSValueMakeUndefined(context);
338 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
340 JSObjectRef thisObject,
341 size_t argumentCount,
342 const JSValueRef arguments[],
343 JSValueRef* exception)
345 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
346 MediacontentManagerPriv *privateObject;
347 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
349 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
350 return JSWebAPIErrorFactory::postException(context, exception, err);
353 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
354 TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
356 JSCallbackManagerPtr cbm(NULL);
357 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
359 cbm = JSCallbackManager::createObject(globalContext);
361 MediacontentMediaListPtr contents;
363 ArgumentValidator argValidator(context, argumentCount, arguments);
365 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
366 contents = converter->toVectorOfMediaItem(arguments[0]);
369 throw TypeMismatchException( "content type mismatched.");
373 throw TypeMismatchException("content type mismatched.");
376 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
377 if(successCallbackObj){
378 cbm->setOnSuccess(successCallbackObj);
381 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
382 if(errorCallbackObj){
383 cbm->setOnError(errorCallbackObj);
385 }catch(const BasePlatformException &err){
386 return JSWebAPIErrorFactory::postException(context,exception,err);
389 DeviceAPI::Common::UnknownException err("Unknown Error in updateBatch().");
390 return JSWebAPIErrorFactory::postException(context, exception, err);
395 IMediacontentManagerPtr contentMgr = privateObject->getObject();
397 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
398 dplEvent->setMediaItems(contents);
399 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
401 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
402 contentMgr->updateMediaItems(dplEvent);
404 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
406 Catch(WrtDeviceApis::Commons::UnsupportedException)
408 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
409 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
411 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
413 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
414 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
416 Catch(WrtDeviceApis::Commons::ConversionException)
418 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
419 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
421 Catch(WrtDeviceApis::Commons::NotFoundException)
423 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
424 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
426 Catch(WrtDeviceApis::Commons::Exception)
428 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
429 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
432 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
433 return JSValueMakeUndefined(context);
438 JSValueRef JSMediacontentManager::updateItem(
439 JSContextRef context,
441 JSObjectRef thisObject,
442 size_t argumentCount,
443 const JSValueRef arguments[],
444 JSValueRef* exception)
447 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
449 MediacontentManagerPriv *privateObject;
450 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
451 if (!privateObject) {
452 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
453 return JSWebAPIErrorFactory::postException(context, exception, err);
456 TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_UPDATE_ITEM);
460 IMediacontentManagerPtr contentMgr = privateObject->getObject();
462 //parameter : MediaItem item
465 if(argumentCount >= 1)
467 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
468 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
469 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
470 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
471 ThrowMsg(ConversionException, "Content type mismatched.");
473 arg = JSValueToObject(context, arguments[0], exception);
477 ThrowMsg(ConversionException, "Content type mismatched.");
480 MediacontentMediaPtr event;
481 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
483 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
484 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
485 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
486 if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
487 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
488 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
489 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
490 if(ContentUtility::checkLocation(latitude, latitude)){
491 imgPtr->setImageLatitude(latitude);
492 imgPtr->setImageLongitude(longitude);
495 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
500 imgPtr->setImageLatitude(DEFAULT_GEOLOCATION);
501 imgPtr->setImageLongitude(DEFAULT_GEOLOCATION);
504 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
505 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
506 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
507 if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
508 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
509 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
510 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
511 if(ContentUtility::checkLocation(latitude, latitude)){
512 vedioPtr->setVideoLatitude(latitude);
513 vedioPtr->setVideoLongitude(longitude);
516 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
521 vedioPtr->setVideoLatitude(DEFAULT_GEOLOCATION);
522 vedioPtr->setVideoLongitude(DEFAULT_GEOLOCATION);
526 JSValueRef nameValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "name");
527 if((JSValueIsNull(context, nameValRef) || JSValueIsUndefined(context, nameValRef)) ||
528 JSUtil::JSValueToString(context, nameValRef) == ""){
529 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "name is not valid.");
531 event = JSMedia::getMediaObject(arg);
532 dplEvent->setMediaItem(event);
534 dplEvent->setForSynchronousCall();
535 contentMgr->updateMedia(dplEvent);
537 if (!(dplEvent->getResult())) {
538 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
541 Catch(WrtDeviceApis::Commons::UnsupportedException)
543 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
544 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
546 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
548 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
549 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
551 Catch(WrtDeviceApis::Commons::ConversionException)
553 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
554 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
556 Catch(WrtDeviceApis::Commons::NotFoundException)
558 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
559 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
561 Catch(WrtDeviceApis::Commons::Exception)
563 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
564 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
567 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
568 return JSValueMakeUndefined(context);
572 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
573 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
575 if(err_msg.empty() ){
576 Converter converter(cb->getContext());
577 JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
578 cb->callSuccessCallback(jsPath);
581 DeviceAPI::Common::UnknownException err(err_msg.c_str());
582 JSObjectRef errorObject = JSWebAPIErrorFactory::makeErrorObject(cb->getContext(),err);
583 cb->callErrorCallback(errorObject);
589 JSValueRef JSMediacontentManager::scanFile(
590 JSContextRef context,
592 JSObjectRef thisObject,
593 size_t argumentCount,
594 const JSValueRef arguments[],
595 JSValueRef* exception)
597 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
599 MediacontentManagerPriv *privateObject;
600 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
602 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
603 return JSWebAPIErrorFactory::postException(context, exception, err);
606 TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SCAN_FILE);
609 CallbackUserData *callback = NULL;
611 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
612 ArgumentValidator argValidator(context, argumentCount, arguments);
613 path = argValidator.toString(0);
615 throw TypeMismatchException("File path type mismatched.");
617 else if(path == "null" || path == "undefined"){
618 throw InvalidValuesException("File path is not valid.");
620 path = ContentUtility::convertUriToPath(path);
622 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
623 if(successCallbackObj){
624 callback->setSuccessCallback(successCallbackObj);
627 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
628 if(errorCallbackObj){
629 callback->setErrorCallback(errorCallbackObj);
631 }catch(const BasePlatformException &err){
632 return JSWebAPIErrorFactory::postException(context,exception,err);
635 DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
636 return JSWebAPIErrorFactory::postException(context, exception, err);
641 IMediacontentManagerPtr contentMgr = privateObject->getObject();
642 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
644 Catch(WrtDeviceApis::Commons::UnsupportedException)
646 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
647 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
649 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
651 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
652 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
654 Catch(WrtDeviceApis::Commons::ConversionException)
656 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
657 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
659 Catch(WrtDeviceApis::Commons::NotFoundException)
661 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
662 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
664 Catch(WrtDeviceApis::Commons::Exception)
666 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
667 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
670 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
671 return JSValueMakeUndefined(context);
675 JSValueRef JSMediacontentManager::setChangeListener(
676 JSContextRef context,
678 JSObjectRef thisObject,
679 size_t argumentCount,
680 const JSValueRef arguments[],
681 JSValueRef* exception)
683 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
685 MediacontentManagerPriv *privateObject;
686 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
688 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
689 return JSWebAPIErrorFactory::postException(context, exception, err);
692 TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
695 ArgumentValidator argValidator(context, argumentCount, arguments);
696 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
697 JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
698 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
699 IMediacontentManagerPtr contentMgr = privateObject->getObject();
700 if(!(contentMgr->setListener(listener)))
702 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
704 }catch(const BasePlatformException &err){
705 return JSWebAPIErrorFactory::postException(context,exception,err);
708 DeviceAPI::Common::UnknownException err("Unknown Error in setChangeListener().");
709 return JSWebAPIErrorFactory::postException(context, exception, err);
712 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
713 return JSValueMakeUndefined(context);
716 JSValueRef JSMediacontentManager::unsetChangeListener(
717 JSContextRef context,
719 JSObjectRef thisObject,
720 size_t argumentCount,
721 const JSValueRef arguments[],
722 JSValueRef* exception)
724 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
725 MediacontentManagerPriv *privateObject;
726 privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(thisObject));
728 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
729 return JSWebAPIErrorFactory::postException(context, exception, err);
732 TIZEN_CHECK_ACCESS(context, exception, privateObject, CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
736 IMediacontentManagerPtr contentMgr = privateObject->getObject();
737 if(!(contentMgr->unsetListener()))
739 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
741 }catch(const BasePlatformException &err){
742 return JSWebAPIErrorFactory::postException(context,exception,err);
745 DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
746 return JSWebAPIErrorFactory::postException(context, exception, err);
749 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
750 return JSValueMakeUndefined(context);
753 const JSClassRef JSMediacontentManager::getClassRef() {
755 m_jsClassRef = JSClassCreate(&m_classInfo);
761 const JSClassDefinition* JSMediacontentManager::getClassInfo()
766 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
768 MediacontentManagerPriv *privateObject = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(object));
769 if (NULL == privateObject)
771 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
772 privateObject = new MediacontentManagerPriv(context, contentManager);
773 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
775 delete privateObject;
781 void JSMediacontentManager::finalize(JSObjectRef object)
783 MediacontentManagerPriv* priv = static_cast<MediacontentManagerPriv*> (JSObjectGetPrivate(object));
787 JSObjectSetPrivate(object, NULL);
793 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
795 const JSObjectRef object,
796 JSValueRef* exception)
798 MediacontentManagerPriv *priv = static_cast<MediacontentManagerPriv*>(JSObjectGetPrivate(object));
801 return priv->getObject();
803 ThrowMsg(ConversionException, "Private object is NULL.");