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.
21 #include <dpl/log/log.h>
22 #include <CommonsJavaScript/Utils.h>
23 #include <CommonsJavaScript/Validator.h>
24 #include <CommonsJavaScript/Converter.h>
25 #include <CommonsJavaScript/JSCallbackManager.h>
26 #include <CommonsJavaScript/JSUtils.h>
27 #include <CommonsJavaScript/JSPendingOperation.h>
28 #include <CommonsJavaScript/PrivateObject.h>
29 #include <CommonsJavaScript/ScopedJSStringRef.h>
30 #include <JSTizenExceptionFactory.h>
31 #include <JSTizenException.h>
32 #include <SecurityExceptions.h>
33 #include <CallbackUserData.h>
34 #include <MultiCallbackUserData.h>
35 #include <GlobalContextManager.h>
36 #include <FilterConverter.h>
37 #include <JSWebAPIError.h>
38 #include <ArgumentValidator.h>
39 #include <TimeTracer.h>
42 #include "ContentFactory.h"
43 #include "ContentController.h"
44 #include "JSContentManager.h"
45 #include "JSContent.h"
49 #include "ContentConverter.h"
50 #include "plugin_config.h"
51 #include "ContentAsyncCallbackManager.h"
52 #include "ContentListener.h"
53 #include "ContentVideo.h"
54 #include "ContentImage.h"
55 #include "ContentFilterConverter.h"
56 #include "ContentUtility.h"
57 #include "JSWebAPIException.h"
60 using namespace DeviceAPI::Common;
61 using namespace DeviceAPI::Tizen;
62 using namespace WrtDeviceApis::Commons;
63 using namespace WrtDeviceApis::CommonsJavaScript;
65 #define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME "content"
70 JSStaticValue JSMediacontentManager::m_property[] =
75 JSStaticFunction JSMediacontentManager::m_function[] =
77 { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
78 { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
79 { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
80 { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
81 { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
82 { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
83 { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
88 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
90 JSClassDefinition JSMediacontentManager::m_classInfo =
93 kJSClassAttributeNone,
94 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
103 NULL, //deleteProperty,
104 NULL, //getPropertyNames,
105 NULL, //callAsFunction,
106 NULL, //callAsConstructor,
108 NULL, //convertToType
111 JSValueRef JSMediacontentManager::getFolders(
112 JSContextRef context,
114 JSObjectRef thisObject,
115 size_t argumentCount,
116 const JSValueRef arguments[],
117 JSValueRef* exception )
119 LogDebug("JSContentManagerManager::getFolders entered");
120 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
122 MediacontentManagerPrivObject *privateObject;
123 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
124 if (!privateObject) {
125 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
126 return JSWebAPIError::throwException(context, exception, err);
129 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
131 JSCallbackManagerPtr cbm(NULL);
132 cbm = JSCallbackManager::createObject(globalContext);
135 ArgumentValidator argValidator(context, argumentCount, arguments);
136 JSObjectRef successCallbackObj = argValidator.toFunction(0);
137 if(successCallbackObj){
138 cbm->setOnSuccess(successCallbackObj);
141 throw TypeMismatchException("SuccessCallback type mismatched.");
144 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
145 if(errorCallbackObj){
146 cbm->setOnError(errorCallbackObj);
148 }catch(const BasePlatformException &err){
149 return JSWebAPIException::throwException(context,exception,err);
152 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
153 return JSWebAPIException::throwException(context, exception, err);
158 IMediacontentManagerPtr contentMgr = privateObject->getObject();
160 IEventFindFolderPtr dplEvent(new IEventFindFolder());
161 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
162 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
164 contentMgr->findFolder(dplEvent);
166 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
168 Catch(WrtDeviceApis::Commons::UnsupportedException)
170 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
171 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
173 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
175 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
176 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
178 Catch(WrtDeviceApis::Commons::ConversionException)
180 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
181 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
183 Catch(WrtDeviceApis::Commons::NotFoundException)
185 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
186 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
188 Catch(WrtDeviceApis::Commons::Exception)
190 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
191 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
194 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
195 return JSValueMakeUndefined(context);
201 JSValueRef JSMediacontentManager::findItems(
202 JSContextRef context,
204 JSObjectRef thisObject,
205 size_t argumentCount,
206 const JSValueRef arguments[],
207 JSValueRef* exception )
209 LogDebug("JSContentManagerManager::find entered");
210 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
212 MediacontentManagerPrivObject *privateObject;
213 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
215 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
216 return JSWebAPIError::throwException(context, exception, err);
219 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_FIND_ITEMS);
221 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
223 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
225 JSCallbackManagerPtr cbm(NULL);
226 MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
227 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
229 cbm = JSCallbackManager::createObject(globalContext);
232 Tizen::FilterPtr filter;
233 Tizen::SortModePtr sortPtr;
234 JSObjectRef filterObj;
235 JSObjectRef sortModeObj;
236 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
238 ArgumentValidator argValidator(context, argumentCount, arguments);
239 JSObjectRef successCallbackObj = argValidator.toFunction(0);
240 if(successCallbackObj){
241 cbm->setOnSuccess(successCallbackObj);
244 throw TypeMismatchException("SuccessCallback type mismatched.");
247 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
248 if(errorCallbackObj){
249 cbm->setOnError(errorCallbackObj);
252 folderId = argValidator.toString(2, true);
253 if(!folderId.empty()){
254 if(folderId == "null" || folderId == "undefined"){
255 throw InvalidValuesException("folderId is not valid.");
257 dplEvent->setFolderID(folderId);
260 filterObj = argValidator.toObject(3,true);
263 sortModeObj= argValidator.toObject(4,true);
266 if(argumentCount >= 6){
267 long count = argValidator.toLong(5, true, -1);
269 dplEvent->setLimit(count);
272 throw InvalidValuesException( "count should be positive.");
275 if(argumentCount >= 7){
277 long offset = argValidator.toLong(6, true);
279 dplEvent->setOffset(offset);
282 throw InvalidValuesException("offset should be positive.");
285 }catch(const BasePlatformException &err){
286 return JSWebAPIException::throwException(context,exception,err);
289 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
290 return JSWebAPIException::throwException(context, exception, err);
296 dplEvent->setFilter(fConverter->toFilter(filterObj));
299 dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
301 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 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
310 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
312 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
314 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
315 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
317 Catch(WrtDeviceApis::Commons::ConversionException)
319 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
320 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
322 Catch(WrtDeviceApis::Commons::NotFoundException)
324 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
325 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
327 Catch(WrtDeviceApis::Commons::Exception)
329 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
330 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::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 LogDebug("JSContentManagerManager::updateItemsBatch entered");
347 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
348 MediacontentManagerPrivObject *privateObject;
349 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
351 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
352 return JSWebAPIError::throwException(context, exception, err);
355 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
356 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
357 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
359 JSCallbackManagerPtr cbm(NULL);
360 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
362 cbm = JSCallbackManager::createObject(globalContext);
364 MediacontentMediaListPtr contents;
366 ArgumentValidator argValidator(context, argumentCount, arguments);
368 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
369 contents = converter->toVectorOfMediaItem(arguments[0]);
372 throw TypeMismatchException( "content type mismatched.");
376 throw TypeMismatchException("content type mismatched.");
379 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
380 if(successCallbackObj){
381 cbm->setOnSuccess(successCallbackObj);
384 throw TypeMismatchException("SuccessCallback type mismatched.");
387 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
388 if(errorCallbackObj){
389 cbm->setOnError(errorCallbackObj);
391 }catch(const BasePlatformException &err){
392 return JSWebAPIException::throwException(context,exception,err);
395 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
396 return JSWebAPIException::throwException(context, exception, err);
401 IMediacontentManagerPtr contentMgr = privateObject->getObject();
403 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
404 dplEvent->setMediaItems(contents);
405 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
407 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
408 contentMgr->updateMediaItems(dplEvent);
410 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
412 Catch(WrtDeviceApis::Commons::UnsupportedException)
414 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
415 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
417 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
419 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
420 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
422 Catch(WrtDeviceApis::Commons::ConversionException)
424 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
425 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
427 Catch(WrtDeviceApis::Commons::NotFoundException)
429 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
430 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
432 Catch(WrtDeviceApis::Commons::Exception)
434 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
435 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
438 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
439 return JSValueMakeUndefined(context);
444 JSValueRef JSMediacontentManager::updateItem(
445 JSContextRef context,
447 JSObjectRef thisObject,
448 size_t argumentCount,
449 const JSValueRef arguments[],
450 JSValueRef* exception)
452 LogDebug("JSContentManagerManager::updateItem entered");
453 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
455 MediacontentManagerPrivObject *privateObject;
456 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
457 if (!privateObject) {
458 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
459 return JSWebAPIError::throwException(context, exception, err);
462 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
463 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
467 IMediacontentManagerPtr contentMgr = privateObject->getObject();
469 //parameter : MediaItem item
472 if(argumentCount >= 1)
474 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
475 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
476 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
477 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
478 ThrowMsg(ConversionException, "Content type mismatched.");
480 arg = JSValueToObject(context, arguments[0], exception);
484 ThrowMsg(ConversionException, "Content type mismatched.");
487 MediacontentMediaPtr event;
488 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
490 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
491 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
492 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
493 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
494 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
496 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
497 imgPtr->setImageLatitude(latitude);
498 imgPtr->setImageLongitude(longitude);
500 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
501 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
502 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
504 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
506 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
508 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
509 vedioPtr->setVideoLatitude(latitude);
510 vedioPtr->setVideoLongitude(longitude);
513 event = JSMedia::getMediaObject(arg);
514 dplEvent->setMediaItem(event);
516 dplEvent->setForSynchronousCall();
517 contentMgr->updateMedia(dplEvent);
519 if (!(dplEvent->getResult())) {
520 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
523 Catch(WrtDeviceApis::Commons::UnsupportedException)
525 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
526 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
528 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
530 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
531 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
533 Catch(WrtDeviceApis::Commons::ConversionException)
535 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
536 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
538 Catch(WrtDeviceApis::Commons::NotFoundException)
540 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
541 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
543 Catch(WrtDeviceApis::Commons::Exception)
545 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
546 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
549 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
550 return JSValueMakeUndefined(context);
554 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
555 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
557 if(err_msg.empty() ){
558 Converter converter(cb->getContext());
559 JSValueRef jsPath = converter.toJSValueRef(path);
560 cb->callSuccessCallback(jsPath);
563 DeviceAPI::Common::UnknownException err(err_msg.c_str());
564 JSObjectRef errorObject = JSWebAPIError::makeJSWebAPIError(cb->getContext(),err);
565 cb->callErrorCallback(errorObject);
571 JSValueRef JSMediacontentManager::scanFile(
572 JSContextRef context,
574 JSObjectRef thisObject,
575 size_t argumentCount,
576 const JSValueRef arguments[],
577 JSValueRef* exception)
579 LogDebug("JSContentManagerManager::scanFile entered");
580 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
582 MediacontentManagerPrivObject *privateObject;
583 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
585 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
586 return JSWebAPIException::throwException(context, exception, err);
589 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
590 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
593 CallbackUserData *callback = NULL;
595 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
596 ArgumentValidator argValidator(context, argumentCount, arguments);
597 path = argValidator.toString(0);
599 throw TypeMismatchException("File path type mismatched.");
601 else if(path == "null" || path == "undefined"){
602 throw InvalidValuesException("File path is not valid.");
604 path = ContentUtility::convertUriToPath(path);
606 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
607 if(successCallbackObj){
608 callback->setSuccessCallback(successCallbackObj);
611 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
612 if(errorCallbackObj){
613 callback->setErrorCallback(errorCallbackObj);
615 }catch(const BasePlatformException &err){
616 return JSWebAPIException::throwException(context,exception,err);
619 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
620 return JSWebAPIException::throwException(context, exception, err);
625 IMediacontentManagerPtr contentMgr = privateObject->getObject();
626 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
628 Catch(WrtDeviceApis::Commons::UnsupportedException)
630 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
631 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
633 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
635 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
636 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
638 Catch(WrtDeviceApis::Commons::ConversionException)
640 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
641 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
643 Catch(WrtDeviceApis::Commons::NotFoundException)
645 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
646 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
648 Catch(WrtDeviceApis::Commons::Exception)
650 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
651 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
654 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
655 return JSValueMakeUndefined(context);
659 JSValueRef JSMediacontentManager::setChangeListener(
660 JSContextRef context,
662 JSObjectRef thisObject,
663 size_t argumentCount,
664 const JSValueRef arguments[],
665 JSValueRef* exception)
667 LogDebug("JSContentManagerManager::setChangeListener entered");
668 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
670 MediacontentManagerPrivObject *privateObject;
671 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
673 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
674 return JSWebAPIException::throwException(context, exception, err);
677 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
678 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
681 ArgumentValidator argValidator(context, argumentCount, arguments);
682 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
683 JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
684 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
685 IMediacontentManagerPtr contentMgr = privateObject->getObject();
686 if(!(contentMgr->setListener(listener)))
688 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
690 }catch(const BasePlatformException &err){
691 return JSWebAPIException::throwException(context,exception,err);
694 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
695 return JSWebAPIException::throwException(context, exception, err);
698 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
699 return JSValueMakeUndefined(context);
702 JSValueRef JSMediacontentManager::unsetChangeListener(
703 JSContextRef context,
705 JSObjectRef thisObject,
706 size_t argumentCount,
707 const JSValueRef arguments[],
708 JSValueRef* exception)
710 LogDebug("JSContentManagerManager::unsetChangeListener entered");
711 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
712 MediacontentManagerPrivObject *privateObject;
713 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
715 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
716 return JSWebAPIException::throwException(context, exception, err);
719 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
720 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
724 IMediacontentManagerPtr contentMgr = privateObject->getObject();
725 if(!(contentMgr->unsetListener()))
727 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
729 }catch(const BasePlatformException &err){
730 return JSWebAPIException::throwException(context,exception,err);
733 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
734 return JSWebAPIException::throwException(context, exception, err);
737 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
738 return JSValueMakeUndefined(context);
741 const JSClassRef JSMediacontentManager::getClassRef() {
743 m_jsClassRef = JSClassCreate(&m_classInfo);
749 const JSClassDefinition* JSMediacontentManager::getClassInfo()
754 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
756 LogDebug("JSContentManager initialize entered");
757 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
758 if (NULL == privateObject)
760 LogDebug("Create ContenttManagerPrivObject");
761 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
762 privateObject = new MediacontentManagerPrivObject(context, contentManager);
763 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
765 delete privateObject;
771 void JSMediacontentManager::finalize(JSObjectRef object)
774 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
777 LogDebug("Deleting coordinates object");
779 JSObjectSetPrivate(object, NULL);
785 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
787 const JSObjectRef object,
788 JSValueRef* exception)
790 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
793 return priv->getObject();
795 ThrowMsg(ConversionException, "Private object is NULL.");