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 event = JSMedia::getMediaObject(arg);
530 dplEvent->setMediaItem(event);
532 dplEvent->setForSynchronousCall();
533 contentMgr->updateMedia(dplEvent);
535 if (!(dplEvent->getResult())) {
536 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
539 Catch(WrtDeviceApis::Commons::UnsupportedException)
541 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
542 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
544 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
546 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
547 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
549 Catch(WrtDeviceApis::Commons::ConversionException)
551 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
552 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
554 Catch(WrtDeviceApis::Commons::NotFoundException)
556 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
557 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
559 Catch(WrtDeviceApis::Commons::Exception)
561 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
562 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
565 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
566 return JSValueMakeUndefined(context);
570 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
571 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
573 if(err_msg.empty() ){
574 Converter converter(cb->getContext());
575 JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
576 cb->callSuccessCallback(jsPath);
579 DeviceAPI::Common::UnknownException err(err_msg.c_str());
580 JSObjectRef errorObject = JSWebAPIErrorFactory::makeErrorObject(cb->getContext(),err);
581 cb->callErrorCallback(errorObject);
587 JSValueRef JSMediacontentManager::scanFile(
588 JSContextRef context,
590 JSObjectRef thisObject,
591 size_t argumentCount,
592 const JSValueRef arguments[],
593 JSValueRef* exception)
595 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
597 MediacontentManagerPrivObject *privateObject;
598 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
600 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
601 return JSWebAPIErrorFactory::postException(context, exception, err);
604 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
605 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
608 CallbackUserData *callback = NULL;
610 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
611 ArgumentValidator argValidator(context, argumentCount, arguments);
612 path = argValidator.toString(0);
614 throw TypeMismatchException("File path type mismatched.");
616 else if(path == "null" || path == "undefined"){
617 throw InvalidValuesException("File path is not valid.");
619 path = ContentUtility::convertUriToPath(path);
621 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
622 if(successCallbackObj){
623 callback->setSuccessCallback(successCallbackObj);
626 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
627 if(errorCallbackObj){
628 callback->setErrorCallback(errorCallbackObj);
630 }catch(const BasePlatformException &err){
631 return JSWebAPIErrorFactory::postException(context,exception,err);
634 DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
635 return JSWebAPIErrorFactory::postException(context, exception, err);
640 IMediacontentManagerPtr contentMgr = privateObject->getObject();
641 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
643 Catch(WrtDeviceApis::Commons::UnsupportedException)
645 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
646 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
648 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
650 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
651 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
653 Catch(WrtDeviceApis::Commons::ConversionException)
655 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
656 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
658 Catch(WrtDeviceApis::Commons::NotFoundException)
660 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
661 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
663 Catch(WrtDeviceApis::Commons::Exception)
665 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
666 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
669 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
670 return JSValueMakeUndefined(context);
674 JSValueRef JSMediacontentManager::setChangeListener(
675 JSContextRef context,
677 JSObjectRef thisObject,
678 size_t argumentCount,
679 const JSValueRef arguments[],
680 JSValueRef* exception)
682 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
684 MediacontentManagerPrivObject *privateObject;
685 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
687 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
688 return JSWebAPIErrorFactory::postException(context, exception, err);
691 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
692 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
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 MediacontentManagerPrivObject *privateObject;
726 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
728 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
729 return JSWebAPIErrorFactory::postException(context, exception, err);
732 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
733 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
737 IMediacontentManagerPtr contentMgr = privateObject->getObject();
738 if(!(contentMgr->unsetListener()))
740 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
742 }catch(const BasePlatformException &err){
743 return JSWebAPIErrorFactory::postException(context,exception,err);
746 DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
747 return JSWebAPIErrorFactory::postException(context, exception, err);
750 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
751 return JSValueMakeUndefined(context);
754 const JSClassRef JSMediacontentManager::getClassRef() {
756 m_jsClassRef = JSClassCreate(&m_classInfo);
762 const JSClassDefinition* JSMediacontentManager::getClassInfo()
767 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
769 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
770 if (NULL == privateObject)
772 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
773 privateObject = new MediacontentManagerPrivObject(context, contentManager);
774 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
776 delete privateObject;
782 void JSMediacontentManager::finalize(JSObjectRef object)
784 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
788 JSObjectSetPrivate(object, NULL);
794 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
796 const JSObjectRef object,
797 JSValueRef* exception)
799 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
802 return priv->getObject();
804 ThrowMsg(ConversionException, "Private object is NULL.");