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 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
384 if(errorCallbackObj){
385 cbm->setOnError(errorCallbackObj);
387 }catch(const BasePlatformException &err){
388 return JSWebAPIErrorFactory::postException(context,exception,err);
391 DeviceAPI::Common::UnknownException err("Unknown Error in updateBatch().");
392 return JSWebAPIErrorFactory::postException(context, exception, err);
397 IMediacontentManagerPtr contentMgr = privateObject->getObject();
399 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
400 dplEvent->setMediaItems(contents);
401 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
403 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
404 contentMgr->updateMediaItems(dplEvent);
406 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
408 Catch(WrtDeviceApis::Commons::UnsupportedException)
410 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
411 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
413 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
415 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
416 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
418 Catch(WrtDeviceApis::Commons::ConversionException)
420 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
421 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
423 Catch(WrtDeviceApis::Commons::NotFoundException)
425 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
426 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
428 Catch(WrtDeviceApis::Commons::Exception)
430 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
431 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
434 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
435 return JSValueMakeUndefined(context);
440 JSValueRef JSMediacontentManager::updateItem(
441 JSContextRef context,
443 JSObjectRef thisObject,
444 size_t argumentCount,
445 const JSValueRef arguments[],
446 JSValueRef* exception)
449 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
451 MediacontentManagerPrivObject *privateObject;
452 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
453 if (!privateObject) {
454 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
455 return JSWebAPIErrorFactory::postException(context, exception, err);
458 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
459 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
463 IMediacontentManagerPtr contentMgr = privateObject->getObject();
465 //parameter : MediaItem item
468 if(argumentCount >= 1)
470 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
471 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
472 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
473 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
474 ThrowMsg(ConversionException, "Content type mismatched.");
476 arg = JSValueToObject(context, arguments[0], exception);
480 ThrowMsg(ConversionException, "Content type mismatched.");
483 MediacontentMediaPtr event;
484 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
486 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
487 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
488 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
489 if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
490 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
491 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
492 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
493 if(ContentUtility::checkLocation(latitude, latitude)){
494 imgPtr->setImageLatitude(latitude);
495 imgPtr->setImageLongitude(longitude);
498 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
503 imgPtr->setImageLatitude(DEFAULT_GEOLOCATION);
504 imgPtr->setImageLongitude(DEFAULT_GEOLOCATION);
507 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
508 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
509 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
510 if(!(JSValueIsNull(context, geoValRef) || JSValueIsUndefined(context, geoValRef))){
511 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
512 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
513 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
514 if(ContentUtility::checkLocation(latitude, latitude)){
515 vedioPtr->setVideoLatitude(latitude);
516 vedioPtr->setVideoLongitude(longitude);
519 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "geolocation value is not valid.");
524 vedioPtr->setVideoLatitude(DEFAULT_GEOLOCATION);
525 vedioPtr->setVideoLongitude(DEFAULT_GEOLOCATION);
529 JSValueRef nameValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "name");
530 if((JSValueIsNull(context, nameValRef) || JSValueIsUndefined(context, nameValRef)) ||
531 JSUtil::JSValueToString(context, nameValRef) == ""){
532 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "name is not valid.");
534 event = JSMedia::getMediaObject(arg);
535 dplEvent->setMediaItem(event);
537 dplEvent->setForSynchronousCall();
538 contentMgr->updateMedia(dplEvent);
540 if (!(dplEvent->getResult())) {
541 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
544 Catch(WrtDeviceApis::Commons::UnsupportedException)
546 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
547 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
549 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
551 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
552 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
554 Catch(WrtDeviceApis::Commons::ConversionException)
556 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
557 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
559 Catch(WrtDeviceApis::Commons::NotFoundException)
561 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
562 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
564 Catch(WrtDeviceApis::Commons::Exception)
566 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
567 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
570 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
571 return JSValueMakeUndefined(context);
575 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
576 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
578 if(err_msg.empty() ){
579 Converter converter(cb->getContext());
580 JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
581 cb->callSuccessCallback(jsPath);
584 DeviceAPI::Common::UnknownException err(err_msg.c_str());
585 JSObjectRef errorObject = JSWebAPIErrorFactory::makeErrorObject(cb->getContext(),err);
586 cb->callErrorCallback(errorObject);
592 JSValueRef JSMediacontentManager::scanFile(
593 JSContextRef context,
595 JSObjectRef thisObject,
596 size_t argumentCount,
597 const JSValueRef arguments[],
598 JSValueRef* exception)
600 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
602 MediacontentManagerPrivObject *privateObject;
603 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
605 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
606 return JSWebAPIErrorFactory::postException(context, exception, err);
609 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
610 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
613 CallbackUserData *callback = NULL;
615 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
616 ArgumentValidator argValidator(context, argumentCount, arguments);
617 path = argValidator.toString(0);
619 throw TypeMismatchException("File path type mismatched.");
621 else if(path == "null" || path == "undefined"){
622 throw InvalidValuesException("File path is not valid.");
624 path = ContentUtility::convertUriToPath(path);
626 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
627 if(successCallbackObj){
628 callback->setSuccessCallback(successCallbackObj);
631 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
632 if(errorCallbackObj){
633 callback->setErrorCallback(errorCallbackObj);
635 }catch(const BasePlatformException &err){
636 return JSWebAPIErrorFactory::postException(context,exception,err);
639 DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
640 return JSWebAPIErrorFactory::postException(context, exception, err);
645 IMediacontentManagerPtr contentMgr = privateObject->getObject();
646 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
648 Catch(WrtDeviceApis::Commons::UnsupportedException)
650 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
651 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
653 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
655 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
656 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
658 Catch(WrtDeviceApis::Commons::ConversionException)
660 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
661 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
663 Catch(WrtDeviceApis::Commons::NotFoundException)
665 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
666 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
668 Catch(WrtDeviceApis::Commons::Exception)
670 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
671 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
674 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
675 return JSValueMakeUndefined(context);
679 JSValueRef JSMediacontentManager::setChangeListener(
680 JSContextRef context,
682 JSObjectRef thisObject,
683 size_t argumentCount,
684 const JSValueRef arguments[],
685 JSValueRef* exception)
687 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
689 MediacontentManagerPrivObject *privateObject;
690 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
692 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
693 return JSWebAPIErrorFactory::postException(context, exception, err);
696 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
697 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
700 ArgumentValidator argValidator(context, argumentCount, arguments);
701 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
702 JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
703 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
704 IMediacontentManagerPtr contentMgr = privateObject->getObject();
705 if(!(contentMgr->setListener(listener)))
707 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
709 }catch(const BasePlatformException &err){
710 return JSWebAPIErrorFactory::postException(context,exception,err);
713 DeviceAPI::Common::UnknownException err("Unknown Error in setChangeListener().");
714 return JSWebAPIErrorFactory::postException(context, exception, err);
717 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
718 return JSValueMakeUndefined(context);
721 JSValueRef JSMediacontentManager::unsetChangeListener(
722 JSContextRef context,
724 JSObjectRef thisObject,
725 size_t argumentCount,
726 const JSValueRef arguments[],
727 JSValueRef* exception)
729 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
730 MediacontentManagerPrivObject *privateObject;
731 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
733 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
734 return JSWebAPIErrorFactory::postException(context, exception, err);
737 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
738 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
742 IMediacontentManagerPtr contentMgr = privateObject->getObject();
743 if(!(contentMgr->unsetListener()))
745 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
747 }catch(const BasePlatformException &err){
748 return JSWebAPIErrorFactory::postException(context,exception,err);
751 DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
752 return JSWebAPIErrorFactory::postException(context, exception, err);
755 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
756 return JSValueMakeUndefined(context);
759 const JSClassRef JSMediacontentManager::getClassRef() {
761 m_jsClassRef = JSClassCreate(&m_classInfo);
767 const JSClassDefinition* JSMediacontentManager::getClassInfo()
772 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
774 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
775 if (NULL == privateObject)
777 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
778 privateObject = new MediacontentManagerPrivObject(context, contentManager);
779 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
781 delete privateObject;
787 void JSMediacontentManager::finalize(JSObjectRef object)
789 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
793 JSObjectSetPrivate(object, NULL);
799 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
801 const JSObjectRef object,
802 JSValueRef* exception)
804 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
807 return priv->getObject();
809 ThrowMsg(ConversionException, "Private object is NULL.");