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>
38 #include "ContentFactory.h"
39 #include "ContentController.h"
40 #include "JSContentManager.h"
41 #include "JSContent.h"
45 #include "ContentConverter.h"
46 #include "plugin_config.h"
47 #include "ContentAsyncCallbackManager.h"
48 #include "ContentListener.h"
49 #include "ContentVideo.h"
50 #include "ContentImage.h"
51 #include "ContentFilterConverter.h"
52 #include "ContentUtility.h"
55 using namespace DeviceAPI::Common;
56 using namespace DeviceAPI::Tizen;
57 using namespace WrtDeviceApis::Commons;
58 using namespace WrtDeviceApis::CommonsJavaScript;
60 #define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME "content"
65 JSStaticValue JSMediacontentManager::m_property[] =
70 JSStaticFunction JSMediacontentManager::m_function[] =
72 { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
73 { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
74 { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
75 { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
76 { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
77 { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
78 { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
83 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
85 JSClassDefinition JSMediacontentManager::m_classInfo =
88 kJSClassAttributeNone,
89 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
98 NULL, //deleteProperty,
99 NULL, //getPropertyNames,
100 NULL, //callAsFunction,
101 NULL, //callAsConstructor,
103 NULL, //convertToType
106 JSValueRef JSMediacontentManager::getFolders(
107 JSContextRef context,
109 JSObjectRef thisObject,
110 size_t argumentCount,
111 const JSValueRef arguments[],
112 JSValueRef* exception )
114 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
116 MediacontentManagerPrivObject *privateObject;
117 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
118 if (!privateObject) {
119 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
120 return JSWebAPIErrorFactory::postException(context, exception, err);
123 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
125 JSCallbackManagerPtr cbm(NULL);
126 cbm = JSCallbackManager::createObject(globalContext);
129 ArgumentValidator argValidator(context, argumentCount, arguments);
130 JSObjectRef successCallbackObj = argValidator.toFunction(0);
131 if(successCallbackObj){
132 cbm->setOnSuccess(successCallbackObj);
135 throw TypeMismatchException("SuccessCallback type mismatched.");
138 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
139 if(errorCallbackObj){
140 cbm->setOnError(errorCallbackObj);
142 }catch(const BasePlatformException &err){
143 return JSWebAPIErrorFactory::postException(context,exception,err);
146 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
147 return JSWebAPIErrorFactory::postException(context, exception, err);
152 IMediacontentManagerPtr contentMgr = privateObject->getObject();
154 IEventFindFolderPtr dplEvent(new IEventFindFolder());
155 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
156 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
158 contentMgr->findFolder(dplEvent);
160 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
162 Catch(WrtDeviceApis::Commons::UnsupportedException)
164 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
165 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
167 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
169 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
170 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
172 Catch(WrtDeviceApis::Commons::ConversionException)
174 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
175 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
177 Catch(WrtDeviceApis::Commons::NotFoundException)
179 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
180 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
182 Catch(WrtDeviceApis::Commons::Exception)
184 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
185 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
188 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
189 return JSValueMakeUndefined(context);
195 JSValueRef JSMediacontentManager::findItems(
196 JSContextRef context,
198 JSObjectRef thisObject,
199 size_t argumentCount,
200 const JSValueRef arguments[],
201 JSValueRef* exception )
204 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
206 MediacontentManagerPrivObject *privateObject;
207 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
209 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
210 return JSWebAPIErrorFactory::postException(context, exception, err);
213 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_FIND_ITEMS);
215 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
217 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
219 JSCallbackManagerPtr cbm(NULL);
220 MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
221 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
223 cbm = JSCallbackManager::createObject(globalContext);
226 Tizen::FilterPtr filter;
227 Tizen::SortModePtr sortPtr;
228 JSObjectRef filterObj;
229 JSObjectRef sortModeObj;
230 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
232 ArgumentValidator argValidator(context, argumentCount, arguments);
233 JSObjectRef successCallbackObj = argValidator.toFunction(0);
234 if(successCallbackObj){
235 cbm->setOnSuccess(successCallbackObj);
238 throw TypeMismatchException("SuccessCallback type mismatched.");
241 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
242 if(errorCallbackObj){
243 cbm->setOnError(errorCallbackObj);
246 folderId = argValidator.toString(2, true);
247 if(!folderId.empty()){
248 if(folderId != "null" ){
249 dplEvent->setFolderID(folderId);
251 else if(folderId == "undefined"){
252 throw InvalidValuesException("folderId is not valid.");
257 filterObj = argValidator.toObject(3,true);
260 sortModeObj= argValidator.toObject(4,true);
263 if(argumentCount >= 6){
264 if(!JSValueIsNull(context, arguments[5])){
265 long count = argValidator.toLong(5, true, 0);
267 dplEvent->setLimit(count);
270 throw InvalidValuesException( "count should be positive.");
274 if(argumentCount >= 7){
276 long offset = argValidator.toLong(6, true);
278 dplEvent->setOffset(offset);
281 throw InvalidValuesException("offset should be positive.");
284 }catch(const BasePlatformException &err){
285 return JSWebAPIErrorFactory::postException(context,exception,err);
288 DeviceAPI::Common::UnknownException err("Unknown Error in find().");
289 return JSWebAPIErrorFactory::postException(context, exception, err);
295 dplEvent->setFilter(fConverter->toFilter(filterObj));
298 dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
300 IMediacontentManagerPtr contentMgr = privateObject->getObject();
302 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
303 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
304 contentMgr->browseFolder(dplEvent);
305 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
307 Catch(WrtDeviceApis::Commons::UnsupportedException)
309 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
310 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
312 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
314 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
315 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
317 Catch(WrtDeviceApis::Commons::ConversionException)
319 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
320 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
322 Catch(WrtDeviceApis::Commons::NotFoundException)
324 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
325 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
327 Catch(WrtDeviceApis::Commons::Exception)
329 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
330 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
333 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
334 return JSValueMakeUndefined(context);
339 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
341 JSObjectRef thisObject,
342 size_t argumentCount,
343 const JSValueRef arguments[],
344 JSValueRef* exception)
346 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
347 MediacontentManagerPrivObject *privateObject;
348 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
350 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
351 return JSWebAPIErrorFactory::postException(context, exception, err);
354 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
355 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
356 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
358 JSCallbackManagerPtr cbm(NULL);
359 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
361 cbm = JSCallbackManager::createObject(globalContext);
363 MediacontentMediaListPtr contents;
365 ArgumentValidator argValidator(context, argumentCount, arguments);
367 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
368 contents = converter->toVectorOfMediaItem(arguments[0]);
371 throw TypeMismatchException( "content type mismatched.");
375 throw TypeMismatchException("content type mismatched.");
378 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
379 if(successCallbackObj){
380 cbm->setOnSuccess(successCallbackObj);
383 throw TypeMismatchException("SuccessCallback type mismatched.");
386 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
387 if(errorCallbackObj){
388 cbm->setOnError(errorCallbackObj);
390 }catch(const BasePlatformException &err){
391 return JSWebAPIErrorFactory::postException(context,exception,err);
394 DeviceAPI::Common::UnknownException err("Unknown Error in updateBatch().");
395 return JSWebAPIErrorFactory::postException(context, exception, err);
400 IMediacontentManagerPtr contentMgr = privateObject->getObject();
402 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
403 dplEvent->setMediaItems(contents);
404 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
406 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
407 contentMgr->updateMediaItems(dplEvent);
409 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
411 Catch(WrtDeviceApis::Commons::UnsupportedException)
413 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
414 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
416 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
418 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
419 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
421 Catch(WrtDeviceApis::Commons::ConversionException)
423 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
424 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
426 Catch(WrtDeviceApis::Commons::NotFoundException)
428 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
429 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
431 Catch(WrtDeviceApis::Commons::Exception)
433 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
434 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
437 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
438 return JSValueMakeUndefined(context);
443 JSValueRef JSMediacontentManager::updateItem(
444 JSContextRef context,
446 JSObjectRef thisObject,
447 size_t argumentCount,
448 const JSValueRef arguments[],
449 JSValueRef* exception)
452 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
454 MediacontentManagerPrivObject *privateObject;
455 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
456 if (!privateObject) {
457 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
458 return JSWebAPIErrorFactory::postException(context, exception, err);
461 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
462 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
466 IMediacontentManagerPtr contentMgr = privateObject->getObject();
468 //parameter : MediaItem item
471 if(argumentCount >= 1)
473 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
474 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
475 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
476 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
477 ThrowMsg(ConversionException, "Content type mismatched.");
479 arg = JSValueToObject(context, arguments[0], exception);
483 ThrowMsg(ConversionException, "Content type mismatched.");
486 MediacontentMediaPtr event;
487 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
489 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
490 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
491 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
492 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
493 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
495 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
496 imgPtr->setImageLatitude(latitude);
497 imgPtr->setImageLongitude(longitude);
499 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
500 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
501 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
503 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
505 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
507 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
508 vedioPtr->setVideoLatitude(latitude);
509 vedioPtr->setVideoLongitude(longitude);
512 event = JSMedia::getMediaObject(arg);
513 dplEvent->setMediaItem(event);
515 dplEvent->setForSynchronousCall();
516 contentMgr->updateMedia(dplEvent);
518 if (!(dplEvent->getResult())) {
519 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
522 Catch(WrtDeviceApis::Commons::UnsupportedException)
524 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
525 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
527 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
529 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
530 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
532 Catch(WrtDeviceApis::Commons::ConversionException)
534 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
535 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
537 Catch(WrtDeviceApis::Commons::NotFoundException)
539 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
540 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
542 Catch(WrtDeviceApis::Commons::Exception)
544 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
545 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
548 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
549 return JSValueMakeUndefined(context);
553 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
554 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
556 if(err_msg.empty() ){
557 Converter converter(cb->getContext());
558 JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
559 cb->callSuccessCallback(jsPath);
562 DeviceAPI::Common::UnknownException err(err_msg.c_str());
563 JSObjectRef errorObject = JSWebAPIErrorFactory::makeErrorObject(cb->getContext(),err);
564 cb->callErrorCallback(errorObject);
570 JSValueRef JSMediacontentManager::scanFile(
571 JSContextRef context,
573 JSObjectRef thisObject,
574 size_t argumentCount,
575 const JSValueRef arguments[],
576 JSValueRef* exception)
578 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
580 MediacontentManagerPrivObject *privateObject;
581 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
583 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
584 return JSWebAPIErrorFactory::postException(context, exception, err);
587 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
588 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
591 CallbackUserData *callback = NULL;
593 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
594 ArgumentValidator argValidator(context, argumentCount, arguments);
595 path = argValidator.toString(0);
597 throw TypeMismatchException("File path type mismatched.");
599 else if(path == "null" || path == "undefined"){
600 throw InvalidValuesException("File path is not valid.");
602 path = ContentUtility::convertUriToPath(path);
604 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
605 if(successCallbackObj){
606 callback->setSuccessCallback(successCallbackObj);
609 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
610 if(errorCallbackObj){
611 callback->setErrorCallback(errorCallbackObj);
613 }catch(const BasePlatformException &err){
614 return JSWebAPIErrorFactory::postException(context,exception,err);
617 DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
618 return JSWebAPIErrorFactory::postException(context, exception, err);
623 IMediacontentManagerPtr contentMgr = privateObject->getObject();
624 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
626 Catch(WrtDeviceApis::Commons::UnsupportedException)
628 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
629 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
631 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
633 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
634 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
636 Catch(WrtDeviceApis::Commons::ConversionException)
638 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
639 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
641 Catch(WrtDeviceApis::Commons::NotFoundException)
643 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
644 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
646 Catch(WrtDeviceApis::Commons::Exception)
648 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
649 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
652 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
653 return JSValueMakeUndefined(context);
657 JSValueRef JSMediacontentManager::setChangeListener(
658 JSContextRef context,
660 JSObjectRef thisObject,
661 size_t argumentCount,
662 const JSValueRef arguments[],
663 JSValueRef* exception)
665 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
667 MediacontentManagerPrivObject *privateObject;
668 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
670 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
671 return JSWebAPIErrorFactory::postException(context, exception, err);
674 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
675 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
678 ArgumentValidator argValidator(context, argumentCount, arguments);
679 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
680 JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
681 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
682 IMediacontentManagerPtr contentMgr = privateObject->getObject();
683 if(!(contentMgr->setListener(listener)))
685 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
687 }catch(const BasePlatformException &err){
688 return JSWebAPIErrorFactory::postException(context,exception,err);
691 DeviceAPI::Common::UnknownException err("Unknown Error in setChangeListener().");
692 return JSWebAPIErrorFactory::postException(context, exception, err);
695 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
696 return JSValueMakeUndefined(context);
699 JSValueRef JSMediacontentManager::unsetChangeListener(
700 JSContextRef context,
702 JSObjectRef thisObject,
703 size_t argumentCount,
704 const JSValueRef arguments[],
705 JSValueRef* exception)
707 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
708 MediacontentManagerPrivObject *privateObject;
709 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
711 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
712 return JSWebAPIErrorFactory::postException(context, exception, err);
715 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
716 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
720 IMediacontentManagerPtr contentMgr = privateObject->getObject();
721 if(!(contentMgr->unsetListener()))
723 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
725 }catch(const BasePlatformException &err){
726 return JSWebAPIErrorFactory::postException(context,exception,err);
729 DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
730 return JSWebAPIErrorFactory::postException(context, exception, err);
733 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
734 return JSValueMakeUndefined(context);
737 const JSClassRef JSMediacontentManager::getClassRef() {
739 m_jsClassRef = JSClassCreate(&m_classInfo);
745 const JSClassDefinition* JSMediacontentManager::getClassInfo()
750 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
752 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
753 if (NULL == privateObject)
755 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
756 privateObject = new MediacontentManagerPrivObject(context, contentManager);
757 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
759 delete privateObject;
765 void JSMediacontentManager::finalize(JSObjectRef object)
767 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
771 JSObjectSetPrivate(object, NULL);
777 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
779 const JSObjectRef object,
780 JSValueRef* exception)
782 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
785 return priv->getObject();
787 ThrowMsg(ConversionException, "Private object is NULL.");