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>
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");
121 MediacontentManagerPrivObject *privateObject;
122 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
123 if (!privateObject) {
124 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
125 return JSWebAPIError::throwException(context, exception, err);
128 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
130 JSCallbackManagerPtr cbm(NULL);
131 cbm = JSCallbackManager::createObject(globalContext);
134 ArgumentValidator argValidator(context, argumentCount, arguments);
135 JSObjectRef successCallbackObj = argValidator.toFunction(0);
136 if(successCallbackObj){
137 cbm->setOnSuccess(successCallbackObj);
140 throw TypeMismatchException("SuccessCallback type mismatched.");
143 JSObjectRef errorCallbackObj = argValidator.toFunction(1,true);
144 if(errorCallbackObj){
145 cbm->setOnError(errorCallbackObj);
147 }catch(const BasePlatformException &err){
148 return JSWebAPIException::throwException(context,exception,err);
151 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
152 return JSWebAPIException::throwException(context, exception, err);
157 IMediacontentManagerPtr contentMgr = privateObject->getObject();
159 IEventFindFolderPtr dplEvent(new IEventFindFolder());
160 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
161 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
163 contentMgr->findFolder(dplEvent);
165 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
167 Catch(WrtDeviceApis::Commons::UnsupportedException)
169 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
170 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
172 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
174 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
175 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
177 Catch(WrtDeviceApis::Commons::ConversionException)
179 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
180 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
182 Catch(WrtDeviceApis::Commons::NotFoundException)
184 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
185 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
187 Catch(WrtDeviceApis::Commons::Exception)
189 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
190 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
193 return JSValueMakeUndefined(context);
199 JSValueRef JSMediacontentManager::findItems(
200 JSContextRef context,
202 JSObjectRef thisObject,
203 size_t argumentCount,
204 const JSValueRef arguments[],
205 JSValueRef* exception )
207 LogDebug("JSContentManagerManager::find entered");
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" || folderId == "undefined"){
252 throw InvalidValuesException("folderId is not valid.");
254 dplEvent->setFolderID(folderId);
257 filterObj = argValidator.toObject(3,true);
260 sortModeObj= argValidator.toObject(4,true);
263 if(argumentCount >= 6){
264 unsigned long count = argValidator.toLong(5, true, -1);
266 dplEvent->setLimit(count);
269 throw InvalidValuesException( "count should be positive.");
272 if(argumentCount >= 7){
274 unsigned long offset = argValidator.toLong(6, true);
276 dplEvent->setOffset(offset);
279 throw InvalidValuesException("offset should be positive.");
282 }catch(const BasePlatformException &err){
283 return JSWebAPIException::throwException(context,exception,err);
286 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
287 return JSWebAPIException::throwException(context, exception, err);
293 dplEvent->setFilter(fConverter->toFilter(filterObj));
296 dplEvent->setSortMode(fConverter->toSortMode(sortModeObj));
298 IMediacontentManagerPtr contentMgr = privateObject->getObject();
299 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
300 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
301 contentMgr->browseFolder(dplEvent);
302 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
304 Catch(WrtDeviceApis::Commons::UnsupportedException)
306 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
307 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
309 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
311 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
312 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
314 Catch(WrtDeviceApis::Commons::ConversionException)
316 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
317 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
319 Catch(WrtDeviceApis::Commons::NotFoundException)
321 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
322 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
324 Catch(WrtDeviceApis::Commons::Exception)
326 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
327 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
330 return JSValueMakeUndefined(context);
335 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
337 JSObjectRef thisObject,
338 size_t argumentCount,
339 const JSValueRef arguments[],
340 JSValueRef* exception)
342 LogDebug("JSContentManagerManager::updateItemsBatch entered");
343 MediacontentManagerPrivObject *privateObject;
344 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
346 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
347 return JSWebAPIError::throwException(context, exception, err);
350 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
351 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
352 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
354 JSCallbackManagerPtr cbm(NULL);
355 MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
357 cbm = JSCallbackManager::createObject(globalContext);
359 MediacontentMediaListPtr contents;
361 ArgumentValidator argValidator(context, argumentCount, arguments);
363 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0]))){
364 contents = converter->toVectorOfMediaItem(arguments[0]);
367 throw TypeMismatchException( "content type mismatched.");
371 throw TypeMismatchException("content type mismatched.");
374 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
375 if(successCallbackObj){
376 cbm->setOnSuccess(successCallbackObj);
379 throw TypeMismatchException("SuccessCallback type mismatched.");
382 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
383 if(errorCallbackObj){
384 cbm->setOnError(errorCallbackObj);
386 }catch(const BasePlatformException &err){
387 return JSWebAPIException::throwException(context,exception,err);
390 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
391 return JSWebAPIException::throwException(context, exception, err);
396 IMediacontentManagerPtr contentMgr = privateObject->getObject();
398 IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
399 dplEvent->setMediaItems(contents);
400 dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
402 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
403 contentMgr->updateMediaItems(dplEvent);
405 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
407 Catch(WrtDeviceApis::Commons::UnsupportedException)
409 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
410 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
412 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
414 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
415 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
417 Catch(WrtDeviceApis::Commons::ConversionException)
419 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
420 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
422 Catch(WrtDeviceApis::Commons::NotFoundException)
424 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
425 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
427 Catch(WrtDeviceApis::Commons::Exception)
429 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
430 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
433 return JSValueMakeUndefined(context);
438 JSValueRef JSMediacontentManager::updateItem(
439 JSContextRef context,
441 JSObjectRef thisObject,
442 size_t argumentCount,
443 const JSValueRef arguments[],
444 JSValueRef* exception)
446 LogDebug("JSContentManagerManager::updateItem entered");
448 MediacontentManagerPrivObject *privateObject;
449 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
450 if (!privateObject) {
451 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
452 return JSWebAPIError::throwException(context, exception, err);
455 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
456 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
460 IMediacontentManagerPtr contentMgr = privateObject->getObject();
462 //parameter : MediaItem item
465 if(argumentCount >= 1)
467 if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
468 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
469 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&
470 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
471 ThrowMsg(ConversionException, "Content type mismatched.");
473 arg = JSValueToObject(context, arguments[0], exception);
477 ThrowMsg(ConversionException, "Content type mismatched.");
480 MediacontentMediaPtr event;
481 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
483 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
484 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
485 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
486 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
487 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
489 MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
490 imgPtr->setImageLatitude(latitude);
491 imgPtr->setImageLongitude(longitude);
493 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
494 JSValueRef geoValRef = JSUtil::getProperty(context , JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
495 JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
497 double latitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "latitude"));
499 double longitude = JSUtil::JSValueToDouble(context, JSUtil::getProperty(context, geoObjRef, "longitude"));
501 MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
502 vedioPtr->setVideoLatitude(latitude);
503 vedioPtr->setVideoLongitude(longitude);
506 event = JSMedia::getMediaObject(arg);
507 dplEvent->setMediaItem(event);
509 dplEvent->setForSynchronousCall();
510 contentMgr->updateMedia(dplEvent);
512 if (!(dplEvent->getResult())) {
513 ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
516 Catch(WrtDeviceApis::Commons::UnsupportedException)
518 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
519 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
521 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
523 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
524 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
526 Catch(WrtDeviceApis::Commons::ConversionException)
528 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
529 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
531 Catch(WrtDeviceApis::Commons::NotFoundException)
533 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
534 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
536 Catch(WrtDeviceApis::Commons::Exception)
538 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
539 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
542 return JSValueMakeUndefined(context);
546 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
547 CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
549 if(err_msg.empty() ){
550 Converter converter(cb->getContext());
551 JSValueRef jsPath = converter.toJSValueRef(path);
552 cb->callSuccessCallback(jsPath);
555 DeviceAPI::Common::UnknownException err(err_msg.c_str());
556 JSObjectRef errorObject = JSWebAPIError::makeJSWebAPIError(cb->getContext(),err);
557 cb->callErrorCallback(errorObject);
563 JSValueRef JSMediacontentManager::scanFile(
564 JSContextRef context,
566 JSObjectRef thisObject,
567 size_t argumentCount,
568 const JSValueRef arguments[],
569 JSValueRef* exception)
571 LogDebug("JSContentManagerManager::scanFile entered");
573 MediacontentManagerPrivObject *privateObject;
574 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
576 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
577 return JSWebAPIException::throwException(context, exception, err);
580 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
581 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
584 CallbackUserData *callback = NULL;
586 callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
587 ArgumentValidator argValidator(context, argumentCount, arguments);
588 path = argValidator.toString(0);
590 throw TypeMismatchException("File path type mismatched.");
592 else if(path == "null" || path == "undefined"){
593 throw InvalidValuesException("File path is not valid.");
595 path = ContentUtility::convertUriToPath(path);
597 JSObjectRef successCallbackObj = argValidator.toFunction(1,true);
598 if(successCallbackObj){
599 callback->setSuccessCallback(successCallbackObj);
602 JSObjectRef errorCallbackObj = argValidator.toFunction(2,true);
603 if(errorCallbackObj){
604 callback->setErrorCallback(errorCallbackObj);
606 }catch(const BasePlatformException &err){
607 return JSWebAPIException::throwException(context,exception,err);
610 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
611 return JSWebAPIException::throwException(context, exception, err);
616 IMediacontentManagerPtr contentMgr = privateObject->getObject();
617 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
619 Catch(WrtDeviceApis::Commons::UnsupportedException)
621 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
622 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
624 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
626 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
627 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
629 Catch(WrtDeviceApis::Commons::ConversionException)
631 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
632 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
634 Catch(WrtDeviceApis::Commons::NotFoundException)
636 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
637 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
639 Catch(WrtDeviceApis::Commons::Exception)
641 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
642 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
645 return JSValueMakeUndefined(context);
650 JSValueRef JSMediacontentManager::setChangeListener(
651 JSContextRef context,
653 JSObjectRef thisObject,
654 size_t argumentCount,
655 const JSValueRef arguments[],
656 JSValueRef* exception)
658 LogDebug("JSContentManagerManager::setChangeListener entered");
660 MediacontentManagerPrivObject *privateObject;
661 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
663 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
664 return JSWebAPIException::throwException(context, exception, err);
667 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
668 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
671 ArgumentValidator argValidator(context, argumentCount, arguments);
672 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
673 JSObjectRef callbackObj = argValidator.toCallbackObject(0,false,"oncontentadded","oncontentupdated","oncontentremoved",NULL);
674 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
675 IMediacontentManagerPtr contentMgr = privateObject->getObject();
676 if(!(contentMgr->setListener(listener)))
678 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
680 }catch(const BasePlatformException &err){
681 return JSWebAPIException::throwException(context,exception,err);
684 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
685 return JSWebAPIException::throwException(context, exception, err);
687 return JSValueMakeUndefined(context);
692 JSValueRef JSMediacontentManager::unsetChangeListener(
693 JSContextRef context,
695 JSObjectRef thisObject,
696 size_t argumentCount,
697 const JSValueRef arguments[],
698 JSValueRef* exception)
700 LogDebug("JSContentManagerManager::unsetChangeListener entered");
701 MediacontentManagerPrivObject *privateObject;
702 privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
704 DeviceAPI::Common::UnknownException err("Content's private object is NULL.");
705 return JSWebAPIException::throwException(context, exception, err);
708 AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
709 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
713 IMediacontentManagerPtr contentMgr = privateObject->getObject();
714 if(!(contentMgr->unsetListener()))
716 throw DeviceAPI::Common::UnknownException( "Unknown exception is occured by platfrom");
718 }catch(const BasePlatformException &err){
719 return JSWebAPIException::throwException(context,exception,err);
722 DeviceAPI::Common::UnknownException err("Unknown Error in ContentManager.getDirectories().");
723 return JSWebAPIException::throwException(context, exception, err);
726 return JSValueMakeUndefined(context);
730 const JSClassRef JSMediacontentManager::getClassRef() {
732 m_jsClassRef = JSClassCreate(&m_classInfo);
738 const JSClassDefinition* JSMediacontentManager::getClassInfo()
743 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
745 LogDebug("JSContentManager initialize entered");
746 MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
747 if (NULL == privateObject)
749 LogDebug("Create ContenttManagerPrivObject");
750 IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
751 privateObject = new MediacontentManagerPrivObject(context, contentManager);
752 if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
754 delete privateObject;
760 void JSMediacontentManager::finalize(JSObjectRef object)
763 MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
766 LogDebug("Deleting coordinates object");
768 JSObjectSetPrivate(object, NULL);
774 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
776 const JSObjectRef object,
777 JSValueRef* exception)
779 MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
782 return priv->getObject();
784 ThrowMsg(ConversionException, "Private object is NULL.");