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 <JSTizenExceptionFactory.h>
29 #include <JSTizenException.h>
30 #include <SecurityExceptions.h>
31 #include <CallbackUserData.h>
32 #include <MultiCallbackUserData.h>
33 #include <GlobalContextManager.h>
34 #include <FilterConverter.h>
35 #include <JSWebAPIError.h>
36 #include <ArgumentValidator.h>
37 #include <TimeTracer.h>
40 #include "ContentFactory.h"
41 #include "ContentController.h"
42 #include "JSContentManager.h"
43 #include "JSContent.h"
47 #include "ContentConverter.h"
48 #include "plugin_config.h"
49 #include "ContentAsyncCallbackManager.h"
50 #include "ContentListener.h"
51 #include "ContentVideo.h"
52 #include "ContentImage.h"
53 #include "ContentFilterConverter.h"
54 #include "ContentUtility.h"
55 #include "JSWebAPIException.h"
58 using namespace DeviceAPI::Common;
59 using namespace DeviceAPI::Tizen;
60 using namespace WrtDeviceApis::Commons;
61 using namespace WrtDeviceApis::CommonsJavaScript;
63 #define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME "content"
68 JSStaticValue JSMediacontentManager::m_property[] =
73 JSStaticFunction JSMediacontentManager::m_function[] =
75 { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
76 { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
77 { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
78 { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
79 { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
80 { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
81 { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
86 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
88 JSClassDefinition JSMediacontentManager::m_classInfo =
91 kJSClassAttributeNone,
92 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
101 NULL, //deleteProperty,
102 NULL, //getPropertyNames,
103 NULL, //callAsFunction,
104 NULL, //callAsConstructor,
106 NULL, //convertToType
109 JSValueRef JSMediacontentManager::getFolders(
110 JSContextRef context,
112 JSObjectRef thisObject,
113 size_t argumentCount,
114 const JSValueRef arguments[],
115 JSValueRef* exception )
117 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
119 MediacontentManagerPrivObject *privateObject;
120 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
121 if (!privateObject) {
122 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
123 return JSWebAPIError::throwException(context, exception, err);
126 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
128 JSCallbackManagerPtr cbm(NULL);
129 cbm = JSCallbackManager::createObject(globalContext);
132 ArgumentValidator argValidator(context, argumentCount, arguments);
133 JSObjectRef successCallbackObj = argValidator.toFunction(0);
134 if(successCallbackObj){
135 cbm->setOnSuccess(successCallbackObj);
138 throw TypeMismatchException("SuccessCallback type mismatched.");
141 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
142 if(errorCallbackObj){
143 cbm->setOnError(errorCallbackObj);
145 }catch(const BasePlatformException &err){
146 return JSWebAPIException::throwException(context,exception,err);
149 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
150 return JSWebAPIException::throwException(context, exception, err);
155 IMediacontentManagerPtr contentMgr = privateObject->getObject();
157 IEventFindFolderPtr dplEvent(new IEventFindFolder());
158 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
159 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
161 contentMgr->findFolder(dplEvent);
163 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
165 Catch(WrtDeviceApis::Commons::UnsupportedException)
167 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
168 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
170 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
172 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
173 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
175 Catch(WrtDeviceApis::Commons::ConversionException)
177 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
178 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
180 Catch(WrtDeviceApis::Commons::NotFoundException)
182 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
183 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
185 Catch(WrtDeviceApis::Commons::Exception)
187 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
188 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
191 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
192 return JSValueMakeUndefined(context);
198 JSValueRef JSMediacontentManager::findItems(
199 JSContextRef context,
201 JSObjectRef thisObject,
202 size_t argumentCount,
203 const JSValueRef arguments[],
204 JSValueRef* exception )
207 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
209 MediacontentManagerPrivObject *privateObject;
210 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
212 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
213 return JSWebAPIError::throwException(context, exception, err);
216 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_FIND_ITEMS);
218 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
220 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
222 JSCallbackManagerPtr cbm(NULL);
223 MediaContentFilterConverterFactory::ConverterType fConverter = MediaContentFilterConverterFactory::getConverter(context);
224 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
226 cbm = JSCallbackManager::createObject(globalContext);
229 Tizen::FilterPtr filter;
230 Tizen::SortModePtr sortPtr;
231 JSObjectRef filterObj;
232 JSObjectRef sortModeObj;
233 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
235 ArgumentValidator argValidator(context, argumentCount, arguments);
236 JSObjectRef successCallbackObj = argValidator.toFunction(0);
237 if(successCallbackObj){
238 cbm->setOnSuccess(successCallbackObj);
241 throw TypeMismatchException("SuccessCallback type mismatched.");
244 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
245 if(errorCallbackObj){
246 cbm->setOnError(errorCallbackObj);
249 folderId = argValidator.toString(2, true);
250 if(!folderId.empty()){
251 if(folderId != "null" ){
252 dplEvent->setFolderID(folderId);
254 else if(folderId == "undefined"){
255 throw InvalidValuesException("folderId is not valid.");
260 filterObj = argValidator.toObject(3,true);
263 sortModeObj= argValidator.toObject(4,true);
266 if(argumentCount >= 6){
267 if(!JSValueIsNull(context, arguments[5])){
268 long count = argValidator.toLong(5, true, 0);
270 dplEvent->setLimit(count);
273 throw InvalidValuesException( "count should be positive.");
277 if(argumentCount >= 7){
279 long offset = argValidator.toLong(6, true);
281 dplEvent->setOffset(offset);
284 throw InvalidValuesException("offset should be positive.");
287 }catch(const BasePlatformException &err){
288 return JSWebAPIException::throwException(context,exception,err);
291 DeviceAPI::Common::UnknownException err("Unknown Error in find().");
292 return JSWebAPIException::throwException(context, exception, err);
298 dplEvent->setFilter(fConverter->toFilter(filterObj));
301 dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
303 IMediacontentManagerPtr contentMgr = privateObject->getObject();
305 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
306 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
307 contentMgr->browseFolder(dplEvent);
308 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
310 Catch(WrtDeviceApis::Commons::UnsupportedException)
312 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
313 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
315 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
317 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
318 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
320 Catch(WrtDeviceApis::Commons::ConversionException)
322 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
323 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
325 Catch(WrtDeviceApis::Commons::NotFoundException)
327 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
328 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
330 Catch(WrtDeviceApis::Commons::Exception)
332 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
333 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
336 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
337 return JSValueMakeUndefined(context);
342 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
344 JSObjectRef thisObject,
345 size_t argumentCount,
346 const JSValueRef arguments[],
347 JSValueRef* exception)
349 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
350 MediacontentManagerPrivObject *privateObject;
351 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
353 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
354 return JSWebAPIError::throwException(context, exception, err);
357 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
358 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
359 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
361 JSCallbackManagerPtr cbm(NULL);
362 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
364 cbm = JSCallbackManager::createObject(globalContext);
366 MediacontentMediaListPtr contents;
368 ArgumentValidator argValidator(context, argumentCount, arguments);
370 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
371 contents = converter->toVectorOfMediaItem(arguments[0]);
374 throw TypeMismatchException( "content type mismatched.");
378 throw TypeMismatchException("content type mismatched.");
381 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
382 if(successCallbackObj){
383 cbm->setOnSuccess(successCallbackObj);
386 throw TypeMismatchException("SuccessCallback type mismatched.");
389 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
390 if(errorCallbackObj){
391 cbm->setOnError(errorCallbackObj);
393 }catch(const BasePlatformException &err){
394 return JSWebAPIException::throwException(context,exception,err);
397 DeviceAPI::Common::UnknownException err("Unknown Error in updateBatch().");
398 return JSWebAPIException::throwException(context, exception, err);
403 IMediacontentManagerPtr contentMgr = privateObject->getObject();
405 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
406 dplEvent->setMediaItems(contents);
407 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
409 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
410 contentMgr->updateMediaItems(dplEvent);
412 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
414 Catch(WrtDeviceApis::Commons::UnsupportedException)
416 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
417 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
419 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
421 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
422 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
424 Catch(WrtDeviceApis::Commons::ConversionException)
426 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
427 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
429 Catch(WrtDeviceApis::Commons::NotFoundException)
431 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
432 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
434 Catch(WrtDeviceApis::Commons::Exception)
436 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
437 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
440 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
441 return JSValueMakeUndefined(context);
446 JSValueRef JSMediacontentManager::updateItem(
447 JSContextRef context,
449 JSObjectRef thisObject,
450 size_t argumentCount,
451 const JSValueRef arguments[],
452 JSValueRef* exception)
455 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
457 MediacontentManagerPrivObject *privateObject;
458 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
459 if (!privateObject) {
460 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
461 return JSWebAPIError::throwException(context, exception, err);
464 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
465 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
469 IMediacontentManagerPtr contentMgr = privateObject->getObject();
471 //parameter : MediaItem item
474 if(argumentCount >= 1)
476 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
477 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
478 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
479 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
480 ThrowMsg(ConversionException, "Content type mismatched.");
482 arg = JSValueToObject(context, arguments[0], exception);
486 ThrowMsg(ConversionException, "Content type mismatched.");
489 MediacontentMediaPtr event;
490 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
492 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
493 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
494 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
495 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
496 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
498 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
499 imgPtr->setImageLatitude(latitude);
500 imgPtr->setImageLongitude(longitude);
502 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
503 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
504 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
506 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
508 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
510 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
511 vedioPtr->setVideoLatitude(latitude);
512 vedioPtr->setVideoLongitude(longitude);
515 event = JSMedia::getMediaObject(arg);
516 dplEvent->setMediaItem(event);
518 dplEvent->setForSynchronousCall();
519 contentMgr->updateMedia(dplEvent);
521 if (!(dplEvent->getResult())) {
522 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
525 Catch(WrtDeviceApis::Commons::UnsupportedException)
527 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
528 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
530 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
532 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
533 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
535 Catch(WrtDeviceApis::Commons::ConversionException)
537 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
538 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
540 Catch(WrtDeviceApis::Commons::NotFoundException)
542 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
543 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
545 Catch(WrtDeviceApis::Commons::Exception)
547 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
548 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
551 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
552 return JSValueMakeUndefined(context);
556 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
557 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
559 if(err_msg.empty() ){
560 Converter converter(cb->getContext());
561 JSValueRef jsPath = converter.toJSValueRef(ContentUtility::convertPathToUri(path));
562 cb->callSuccessCallback(jsPath);
565 DeviceAPI::Common::UnknownException err(err_msg.c_str());
566 JSObjectRef errorObject = JSWebAPIError::makeJSWebAPIError(cb->getContext(),err);
567 cb->callErrorCallback(errorObject);
573 JSValueRef JSMediacontentManager::scanFile(
574 JSContextRef context,
576 JSObjectRef thisObject,
577 size_t argumentCount,
578 const JSValueRef arguments[],
579 JSValueRef* exception)
581 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
583 MediacontentManagerPrivObject *privateObject;
584 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
586 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
587 return JSWebAPIException::throwException(context, exception, err);
590 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
591 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
594 CallbackUserData *callback = NULL;
596 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
597 ArgumentValidator argValidator(context, argumentCount, arguments);
598 path = argValidator.toString(0);
600 throw TypeMismatchException("File path type mismatched.");
602 else if(path == "null" || path == "undefined"){
603 throw InvalidValuesException("File path is not valid.");
605 path = ContentUtility::convertUriToPath(path);
607 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
608 if(successCallbackObj){
609 callback->setSuccessCallback(successCallbackObj);
612 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
613 if(errorCallbackObj){
614 callback->setErrorCallback(errorCallbackObj);
616 }catch(const BasePlatformException &err){
617 return JSWebAPIException::throwException(context,exception,err);
620 DeviceAPI::Common::UnknownException err("Unknown Error in scanFile().");
621 return JSWebAPIException::throwException(context, exception, err);
626 IMediacontentManagerPtr contentMgr = privateObject->getObject();
627 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
629 Catch(WrtDeviceApis::Commons::UnsupportedException)
631 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
632 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
634 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
636 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
637 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
639 Catch(WrtDeviceApis::Commons::ConversionException)
641 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
642 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
644 Catch(WrtDeviceApis::Commons::NotFoundException)
646 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
647 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
649 Catch(WrtDeviceApis::Commons::Exception)
651 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
652 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
655 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
656 return JSValueMakeUndefined(context);
660 JSValueRef JSMediacontentManager::setChangeListener(
661 JSContextRef context,
663 JSObjectRef thisObject,
664 size_t argumentCount,
665 const JSValueRef arguments[],
666 JSValueRef* exception)
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 setChangeListener().");
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 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
711 MediacontentManagerPrivObject *privateObject;
712 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
714 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
715 return JSWebAPIException::throwException(context, exception, err);
718 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
719 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
723 IMediacontentManagerPtr contentMgr = privateObject->getObject();
724 if(!(contentMgr->unsetListener()))
726 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
728 }catch(const BasePlatformException &err){
729 return JSWebAPIException::throwException(context,exception,err);
732 DeviceAPI::Common::UnknownException err("Unknown Error in unsetChangeListener().");
733 return JSWebAPIException::throwException(context, exception, err);
736 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
737 return JSValueMakeUndefined(context);
740 const JSClassRef JSMediacontentManager::getClassRef() {
742 m_jsClassRef = JSClassCreate(&m_classInfo);
748 const JSClassDefinition* JSMediacontentManager::getClassInfo()
753 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
755 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
756 if (NULL == privateObject)
758 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
759 privateObject = new MediacontentManagerPrivObject(context, contentManager);
760 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
762 delete privateObject;
768 void JSMediacontentManager::finalize(JSObjectRef object)
770 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
774 JSObjectSetPrivate(object, NULL);
780 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
782 const JSObjectRef object,
783 JSValueRef* exception)
785 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
788 return priv->getObject();
790 ThrowMsg(ConversionException, "Private object is NULL.");