Update change log and spec for wrt-plugins-tizen_0.4.12
[platform/framework/web/wrt-plugins-tizen.git] / src / Content / JSContentManager.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18
19 #include <cassert>
20 #include <memory>
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 "JSUtil.h"
38
39 #include "ContentFactory.h"
40 #include "ContentController.h"
41 #include "JSContentManager.h"
42 #include "JSContent.h"
43 #include "JSImage.h"
44 #include "JSVideo.h"
45 #include "JSAudio.h"
46 #include "ContentConverter.h"
47 #include "plugin_config.h"
48 #include "ContentAsyncCallbackManager.h"
49 #include "ContentListener.h"
50 #include "ContentVideo.h"
51 #include "ContentImage.h"
52
53
54 using namespace DeviceAPI::Common;
55 using namespace DeviceAPI::Tizen;
56 using namespace WrtDeviceApis::Commons;
57 using namespace WrtDeviceApis::CommonsJavaScript;
58
59 #define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME                             "content"
60
61 namespace DeviceAPI {
62 namespace Content {
63
64 JSStaticValue JSMediacontentManager::m_property[] =
65 {
66     { 0, 0, 0, 0 }
67 };
68
69 JSStaticFunction JSMediacontentManager::m_function[] = 
70 {
71         { CONTENT_FUNCTION_API_FIND_ITEMS, findItems, kJSPropertyAttributeNone },
72         { CONTENT_FUNCTION_API_GET_FOLDERS, getFolders, kJSPropertyAttributeNone },
73         { CONTENT_FUNCTION_API_UPDATE_ITEM, updateItem, kJSPropertyAttributeNone },
74         { CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, updateItemsBatch, kJSPropertyAttributeNone },
75         { CONTENT_FUNCTION_API_SCAN_FILE, scanFile, kJSPropertyAttributeNone },
76         { CONTENT_FUNCTION_API_SET_CHANGE_LISTENER, setChangeListener, kJSPropertyAttributeNone },
77         { CONTENT_FUNCTION_API_UNSET_CHANGE_LISTENER, unsetChangeListener,kJSPropertyAttributeNone},
78     { 0, 0, 0 }
79 };
80
81
82 JSClassRef JSMediacontentManager::m_jsClassRef = NULL;
83
84 JSClassDefinition JSMediacontentManager::m_classInfo =
85 {
86                 0,
87                 kJSClassAttributeNone,
88                 TIZEN_CONTENT_MANAGER_ATTRIBUTENAME,
89                 0,
90                 m_property,
91                 m_function,
92                 initialize,
93                 finalize,
94                 NULL, //hasProperty,
95                 NULL, //getProperty,
96                 NULL, //setProperty,
97                 NULL, //deleteProperty,
98                 NULL, //getPropertyNames,
99                 NULL, //callAsFunction,
100                 NULL, //callAsConstructor,
101                 NULL,
102                 NULL, //convertToType
103 };
104
105 JSValueRef JSMediacontentManager::getFolders(
106                                                         JSContextRef context,
107                                                         JSObjectRef object,
108                                                         JSObjectRef thisObject,
109                                                         size_t argumentCount,
110                                                         const JSValueRef arguments[],
111                                                         JSValueRef* exception )
112 {
113         LogDebug("JSContentManagerManager::getFolders entered");
114
115
116         MediacontentManagerPrivObject *privateObject;
117         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
118         if (!privateObject) {
119                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
120         }
121
122         JSContextRef globalContext = privateObject->getContext();
123         Validator validator(context);
124     JSCallbackManagerPtr cbm(NULL);
125     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
126         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
127
128         cbm = JSCallbackManager::createObject(globalContext);
129         cbm->setObject(thisObject);
130
131     Try
132     {
133                 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
134
135                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
136
137                 if(argumentCount >= 1)  //MediaFolderArraySuccessCB successCallback
138                 {
139                         if(validator.isCallback(arguments[0]))
140                         {
141                                 onSuccessForCbm = arguments[0];
142                         }
143                         else
144                         {
145                                 ThrowMsg(ConversionException, "SuccessCallback type mismatched.");
146                         }
147                 }
148                 else
149                 {
150                         ThrowMsg(ConversionException,"There is no successCallback.");
151                 }
152                 if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
153                 {
154                         if(validator.isCallback(arguments[1]))
155                         {
156                                 onErrorForCbm = arguments[1];
157                         }
158                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
159                         {
160                                 ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
161                         }
162                 }
163                 if(cbm)
164                 {
165                         cbm->setOnSuccess(onSuccessForCbm);
166                         cbm->setOnError(onErrorForCbm);
167                 }
168
169                 IEventFindFolderPtr dplEvent(new IEventFindFolder());
170                 dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
171                 dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
172
173                 contentMgr->findFolder(dplEvent);
174
175                 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
176     }
177     Catch(WrtDeviceApis::Commons::UnsupportedException)
178     {
179                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
180         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
181     }
182     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
183     {
184                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
185         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
186     }
187     Catch(WrtDeviceApis::Commons::ConversionException)
188     {
189                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
190         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
191     }
192     Catch(WrtDeviceApis::Commons::NotFoundException)
193     {
194                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
195         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
196     }
197     Catch(WrtDeviceApis::Commons::Exception)
198     {
199                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
200         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
201     }
202
203     return JSValueMakeUndefined(context);
204
205 }
206
207
208
209 JSValueRef JSMediacontentManager::findItems(
210                                                         JSContextRef context,
211                                                         JSObjectRef object,
212                                                         JSObjectRef thisObject,
213                                                         size_t argumentCount,
214                                                         const JSValueRef arguments[],
215                                                         JSValueRef* exception )
216 {
217
218         LogDebug("JSContentManagerManager::findItems entered");
219
220         MediacontentManagerPrivObject *privateObject;
221         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
222         if (!privateObject) {
223                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
224         }
225
226
227
228         AceSecurityStatus status = CONTENT_CHECK_ACCESS(
229             CONTENT_FUNCTION_API_FIND_ITEMS);
230
231         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
232
233
234         JSContextRef globalContext = privateObject->getContext();
235         Validator validator(context);
236     JSCallbackManagerPtr cbm(NULL);
237     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
238         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
239         MediaConverter mediaConverter(globalContext);
240
241         cbm = JSCallbackManager::createObject(globalContext);
242         cbm->setObject(thisObject);
243
244
245     Try
246     {
247                 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
248                 IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder());
249                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
250
251                 if(argumentCount >= 1)  //MediaItemArraySuccessCB successCallback
252                 {
253                         if(validator.isCallback(arguments[0]))
254                         {
255                                 onSuccessForCbm = arguments[0];
256                         }
257                         else
258                         {
259                                 ThrowMsg(ConversionException,"SuccessCallback type mismatched.");
260                         }
261                 }
262                 else
263                 {
264                         ThrowMsg(ConversionException,"There is no SuccessCallback.");
265                 }
266                 if(argumentCount >= 2)  //ErrorCallback? errorCallback
267                 {
268                         if(validator.isCallback(arguments[1]))
269                         {
270                                 onErrorForCbm = arguments[1];
271                         }
272                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
273                         {
274                                 ThrowMsg(ConversionException,"ErrorCallback type mismatched.");
275                         }
276                 }
277                 if(cbm)
278                 {
279                         cbm->setOnSuccess(onSuccessForCbm);
280                         cbm->setOnError(onErrorForCbm);
281                 }
282
283                 if(argumentCount >= 3)  //MediaFolderId id,
284                 {
285                         string folderId = mediaConverter.toString(arguments[2]);
286                         if(!(validator.isNullOrUndefined(arguments[2])) && (folderId.length() > 0)  )
287                         {
288                                 LogDebug("folderId:"+ folderId);
289
290                                 int nFolderId = 0;
291                                 istringstream(folderId) >> nFolderId; //string -> int
292
293                                 if (nFolderId<0)
294                                 {
295                                         cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
296                                                 JSTizenException::INVALID_VALUES_ERROR, "Argument is invalid"));
297                                         return JSValueMakeUndefined(context);
298                                 }
299
300                                 dplEvent->setFolderID(folderId);
301                         }
302                 }
303
304                 if(argumentCount >= 4)  //optional AbstractFilter? filter
305                 {
306                         if(JSValueIsObject(context, arguments[3]))
307                         {
308                                 dplEvent->setFilter(filterConverter->toFilter(arguments[3]));
309                         }
310                         else if(!validator.isNullOrUndefined(arguments[3]))             //nullable
311                         {
312                                 ThrowMsg(ConversionException,"Filter type mismatched.");
313                         }
314                 }
315                 if(argumentCount >= 5)  //optional SortMode? sortMode
316                 {
317
318                         if ( JSValueIsObject(context, arguments[4]) &&
319                                 !JSValueIsNull(context, arguments[4]) &&
320                                 !JSValueIsUndefined(context, arguments[4]) &&
321                                 !JSIsArrayValue(context, arguments[4]))
322                         {
323                                 LogDebug("sortmode is object");
324                                 dplEvent->setSortMode(filterConverter->toSortMode(arguments[4]));
325                         }
326                         else if(!validator.isNullOrUndefined(arguments[4]))             //nullable
327                         {
328                                 ThrowMsg(ConversionException,"SortMode type mismatched.");
329                         }
330                 }
331                 if(argumentCount >= 6)  //optional unsigned long? count
332                 {
333                         if(!JSValueIsNull(context, arguments[5]) && !JSValueIsUndefined(context, arguments[5])){
334                                 long count = filterConverter->toLong(arguments[5]);
335                                 if( count >= 0 ){
336                                         dplEvent->setLimit(count);
337                                 }
338                                 else{
339                                         ThrowMsg(InvalidArgumentException, "count should be positive.");
340                                 }
341                         }
342                 }
343                 if(argumentCount >= 7)  //optional unsigned long? offset
344                 {
345                         long offset = filterConverter->toLong(arguments[6]);
346                         if( offset >= 0 ){
347                                 dplEvent->setOffset(offset);
348                         }
349                         else{
350                                 ThrowMsg(InvalidArgumentException, "offset should be positive.");
351                         }
352                 }
353         dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
354         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
355         contentMgr->browseFolder(dplEvent);
356
357                 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
358     }
359     Catch(WrtDeviceApis::Commons::UnsupportedException)
360     {
361                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
362         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
363     }
364     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
365     {
366                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
367         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
368     }
369     Catch(WrtDeviceApis::Commons::ConversionException)
370     {
371                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
372         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
373     }
374     Catch(WrtDeviceApis::Commons::NotFoundException)
375     {
376                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
377         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
378     }
379     Catch(WrtDeviceApis::Commons::Exception)
380     {
381                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
382         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
383     }
384
385     return JSValueMakeUndefined(context);
386 }
387
388
389
390 JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
391         JSObjectRef object,
392         JSObjectRef thisObject,
393         size_t argumentCount,
394         const JSValueRef arguments[],
395         JSValueRef* exception)
396 {
397     LogDebug("JSContentManagerManager::updateItemsBatch entered");
398         MediacontentManagerPrivObject *privateObject;
399         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
400         if (!privateObject) {
401                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
402         }
403
404
405         JSContextRef globalContext = privateObject->getContext();
406         AceSecurityStatus status = CONTENT_CHECK_ACCESS(
407             CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH);
408         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
409
410         Validator validator(context);
411     JSCallbackManagerPtr cbm(NULL);
412     FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
413         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
414
415         cbm = JSCallbackManager::createObject(globalContext);
416         cbm->setObject(thisObject);
417
418         Try
419     {
420
421                 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
422
423                 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
424                 MediacontentMediaListPtr events;
425                 if((argumentCount >= 1) && (JSIsArrayValue(context, arguments[0])))     //MediaItem[] items
426                 {
427                         events = converter->toVectorOfMediaItem(arguments[0]);
428                         if(!events)
429                         {
430                                 ThrowMsg(ConversionException, "Items type mismatched.");
431                         }
432                 }
433                 else
434                 {
435                         ThrowMsg(ConversionException, "Items type mismatched.");
436                 }
437
438                 if(argumentCount >= 2)  //Function? successCallback,
439                 {
440                         if(validator.isCallback(arguments[1]))
441                         {
442                                 onSuccessForCbm = arguments[1];
443                         }
444                         else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
445                         {
446                                 ThrowMsg(ConversionException,"successCallback type mismatched.");
447                         }
448                 }
449
450                 if(argumentCount >= 3)  //ErrorCallback? errorCallback,
451                 {
452                         if(validator.isCallback(arguments[2]))
453                         {
454                                 onErrorForCbm = arguments[2];
455                         }
456                         else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
457                         {
458                                 ThrowMsg(ConversionException,"ErrorCallback type is mismatched.");
459                         }
460                 }
461
462                 if(cbm)
463                 {
464                         cbm->setOnSuccess(onSuccessForCbm);
465                         cbm->setOnError(onErrorForCbm);
466                 }
467
468         IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
469         dplEvent->setMediaItems(events);
470         dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
471
472         dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
473         contentMgr->updateMediaItems(dplEvent);
474
475                 MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
476     }
477     Catch(WrtDeviceApis::Commons::UnsupportedException)
478     {
479                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
480         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
481     }
482     Catch(WrtDeviceApis::Commons::InvalidArgumentException)
483     {
484                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
485         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
486     }
487     Catch(WrtDeviceApis::Commons::ConversionException)
488     {
489                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
490         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
491     }
492     Catch(WrtDeviceApis::Commons::NotFoundException)
493     {
494                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
495         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
496     }
497     Catch(WrtDeviceApis::Commons::Exception)
498     {
499                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
500         return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
501     }
502
503     return JSValueMakeUndefined(context);
504 }
505
506
507
508 JSValueRef JSMediacontentManager::updateItem(
509                                                 JSContextRef context,
510                                                 JSObjectRef object,
511                                                 JSObjectRef thisObject,
512                                                 size_t argumentCount,
513                                                 const JSValueRef arguments[],
514                                                 JSValueRef* exception)
515 {
516 LogDebug("JSContentManagerManager::updateItem entered");
517
518
519         MediacontentManagerPrivObject *privateObject;
520         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
521         if (!privateObject) {
522                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
523         }
524
525
526
527         AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_UPDATE_ITEM);
528
529         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
530
531         Validator validator(context);
532
533         Try
534         {
535                 IMediacontentManagerPtr contentMgr = getContentManagerPrivObject(context, thisObject, exception);
536
537                 //parameter : MediaItem item
538
539                 JSObjectRef arg;
540                 if(argumentCount >= 1)
541                 {
542                         if (!JSValueIsObjectOfClass(context, arguments[0], JSMedia::getClassRef()) &&
543                                 !JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef()) &&
544                                 !JSValueIsObjectOfClass(context, arguments[0], JSAudio::getClassRef()) &&                       
545                                 !JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())) {
546                                     ThrowMsg(ConversionException, "Item type mismatched.");
547                         }
548                         arg = JSValueToObject(context, arguments[0], exception);
549                 }
550                 else
551                 {
552                          ThrowMsg(ConversionException, "Item type mismatched.");
553                 }
554
555                 MediacontentMediaPtr event;
556                 IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
557
558                 if(JSValueIsObjectOfClass(context, arguments[0], JSImage::getClassRef())){
559
560                         JSValueRef geoValRef = JSUtil::getProperty(context ,
561                                 JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
562                         JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
563                         double latitude = JSUtil::JSValueToDouble(context,
564                                 JSUtil::getProperty(context, geoObjRef, "latitude"));
565
566                         double longitude = JSUtil::JSValueToDouble(context,
567                                 JSUtil::getProperty(context, geoObjRef, "longitude"));
568
569                         MediacontentImagePtr imgPtr = JSImage::getImageObject(arg);
570                         imgPtr->setImageLatitude(latitude);
571                         imgPtr->setImageLongitude(longitude);
572
573                 }
574                 else if(JSValueIsObjectOfClass(context, arguments[0], JSVideo::getClassRef())){
575                         JSValueRef geoValRef = JSUtil::getProperty(context ,
576                                 JSUtil::JSValueToObject(context, arguments[0]), "geolocation");
577                         JSObjectRef geoObjRef = JSUtil::JSValueToObject(context, geoValRef);
578
579                         double latitude = JSUtil::JSValueToDouble(context,
580                                 JSUtil::getProperty(context, geoObjRef, "latitude"));
581
582                         double longitude = JSUtil::JSValueToDouble(context,
583                                 JSUtil::getProperty(context, geoObjRef, "longitude"));
584
585                         MediacontentVideoPtr vedioPtr = JSVideo::getVideoObject(arg);
586                         vedioPtr->setVideoLatitude(latitude);
587                         vedioPtr->setVideoLongitude(longitude);
588                 }
589
590                 event = JSMedia::getMediaObject(arg);
591                 dplEvent->setMediaItem(event);
592
593                 dplEvent->setForSynchronousCall();
594                 contentMgr->updateMedia(dplEvent);
595
596         if (!(dplEvent->getResult())) {
597             ThrowMsg(WrtDeviceApis::Commons::Exception, "updating failed by unknown reason.");
598         }
599         }
600         Catch(WrtDeviceApis::Commons::UnsupportedException)
601         {
602                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
603                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
604         }
605         Catch(WrtDeviceApis::Commons::InvalidArgumentException)
606         {
607                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
608                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
609         }
610         Catch(WrtDeviceApis::Commons::ConversionException)
611         {
612                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
613                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
614         }
615         Catch(WrtDeviceApis::Commons::NotFoundException)
616         {
617                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
618                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
619         }
620         Catch(WrtDeviceApis::Commons::Exception)
621         {
622                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
623                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
624         }
625
626         return JSValueMakeUndefined(context);
627
628 }
629
630 static void _scanCompletedCallback(std::string err_msg, std::string path, void *user_data){
631     CallbackUserData *cb = static_cast<CallbackUserData*>(user_data);
632         if(cb != NULL){
633                         if(err_msg.empty() ){
634                                 Converter converter(cb->getContext());
635                                 JSValueRef jsPath = converter.toJSValueRef(path);
636                                 cb->callSuccessCallback(jsPath);
637                         }
638                         else{
639                                 JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cb->getContext(), JSTizenException::UNKNOWN_ERROR, err_msg);
640                                 cb->callErrorCallback(errorObject);
641                         }
642                         delete cb;
643         }
644 }
645
646 JSValueRef JSMediacontentManager::scanFile(
647                                                 JSContextRef context,
648                                                 JSObjectRef object,
649                                                 JSObjectRef thisObject,
650                                                 size_t argumentCount,
651                                                 const JSValueRef arguments[],
652                                                 JSValueRef* exception)
653 {
654         LogDebug("JSContentManagerManager::scanFile entered");
655
656
657         MediacontentManagerPrivObject *privateObject;
658         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
659
660         AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SCAN_FILE);
661         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
662
663         Try
664         {
665
666                 if(!privateObject){
667                         ThrowMsg(ConversionException, "private object is null");
668                 }
669
670                 CallbackUserData *callback = new CallbackUserData(GlobalContextManager::getInstance()->getGlobalContext(context));
671
672                 Converter convert(context);
673                 Validator validator(context);
674                 IMediacontentManagerPtr contentMgr = privateObject->getObject();
675                 string path;
676
677                 if(argumentCount >= 1){                                 //directoryURI
678                         path = convert.toString(arguments[0]);
679                         if(validator.isNullOrUndefined(arguments[0])){
680                                 ThrowMsg(InvalidArgumentException, path+" is not available");
681                         }
682                 }
683                 else{
684                         ThrowMsg(InvalidArgumentException, "file path is not available");
685                 }
686
687                 if(argumentCount >= 2){                                 //successCallback[optional|nullable]
688                         if(validator.isCallback(arguments[1])){
689                                 callback->setSuccessCallback(arguments[1]);
690                         }
691                         else if(!(JSValueIsNull(context,arguments[1]))){
692                                 ThrowMsg(ConversionException, path + ":successCallback is not available");
693                         }
694                 }
695
696                 if(argumentCount >= 3){                                 //errorCallback
697                         if(validator.isCallback(arguments[2])){
698                                 callback->setErrorCallback(arguments[2]);
699                         }
700                         else if(!(JSValueIsNull(context,arguments[2]))){
701                                 ThrowMsg(ConversionException, path + ":errorCallback is not available");
702                         }
703                 }
704
705                 contentMgr->scanFile(_scanCompletedCallback,path,(void*)callback);
706
707         }
708         Catch(WrtDeviceApis::Commons::UnsupportedException)
709         {
710                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
711                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
712         }
713         Catch(WrtDeviceApis::Commons::InvalidArgumentException)
714         {
715                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
716                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
717         }
718         Catch(WrtDeviceApis::Commons::ConversionException)
719         {
720                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
721                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
722         }
723         Catch(WrtDeviceApis::Commons::NotFoundException)
724         {
725                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
726                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
727         }
728         Catch(WrtDeviceApis::Commons::Exception)
729         {
730                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
731                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
732         }
733
734         return JSValueMakeUndefined(context);
735
736 }
737
738
739 JSValueRef JSMediacontentManager::setChangeListener(
740                                                 JSContextRef context,
741                                                 JSObjectRef object,
742                                                 JSObjectRef thisObject,
743                                                 size_t argumentCount,
744                                                 const JSValueRef arguments[],
745                                                 JSValueRef* exception)
746 {
747         LogDebug("JSContentManagerManager::setChangeListener entered");
748
749         MediacontentManagerPrivObject *privateObject;
750         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
751
752         AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
753         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
754
755         Try
756         {
757
758                 if(!privateObject){
759                         ThrowMsg(ConversionException, "private object is null");
760                 }
761
762         if(argumentCount>=1) {
763             if (!JSValueIsObject(context, arguments[0])) {
764                 ThrowMsg(ConversionException, "Wrong first parameter type.");
765             }
766         }
767                 else{
768             ThrowMsg(ConversionException, "Wrong first parameter type.");
769         }
770
771                 Converter convert(context);
772                 Validator validator(context);
773
774                 JSContextRef globalCtx = GlobalContextManager::getInstance()->getGlobalContext(context);
775
776                 // changeCallback Object
777                 JSObjectRef callbackObj = convert.toJSObjectRef(arguments[0]);
778
779                 ContentListener *listener = new ContentListener(globalCtx, callbackObj);
780
781                 // perform
782                 IMediacontentManagerPtr contentMgr = privateObject->getObject();
783                 if(!(contentMgr->setListener(listener)))
784                 {
785                         ThrowMsg(Exception, "Unknown exception is occured by platfrom");
786                 }
787         }
788         Catch(WrtDeviceApis::Commons::UnsupportedException)
789         {
790                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
791                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
792         }
793         Catch(WrtDeviceApis::Commons::InvalidArgumentException)
794         {
795                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
796                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
797         }
798         Catch(WrtDeviceApis::Commons::ConversionException)
799         {
800                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
801                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
802         }
803         Catch(WrtDeviceApis::Commons::NotFoundException)
804         {
805                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
806                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
807         }
808         Catch(WrtDeviceApis::Commons::Exception)
809         {
810                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
811                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
812         }
813
814         return JSValueMakeUndefined(context);
815
816
817 }
818
819 JSValueRef JSMediacontentManager::unsetChangeListener(
820                                                 JSContextRef context,
821                                                 JSObjectRef object,
822                                                 JSObjectRef thisObject,
823                                                 size_t argumentCount,
824                                                 const JSValueRef arguments[],
825                                                 JSValueRef* exception)
826 {
827         LogDebug("JSContentManagerManager::unsetChangeListener entered");
828
829         MediacontentManagerPrivObject *privateObject;
830         privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
831
832         AceSecurityStatus status = CONTENT_CHECK_ACCESS(CONTENT_FUNCTION_API_SET_CHANGE_LISTENER);
833         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
834
835         Try
836         {
837                 if(!privateObject){
838                         ThrowMsg(ConversionException, "private object is null");
839                 }
840
841                 // perform
842                 IMediacontentManagerPtr contentMgr = privateObject->getObject();
843                 if(!(contentMgr->unsetListener()))
844                 {
845                         ThrowMsg(Exception, "Unknown exception is occured by platfrom");
846                 }
847         }
848         Catch(WrtDeviceApis::Commons::UnsupportedException)
849         {
850                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
851                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
852         }
853         Catch(WrtDeviceApis::Commons::InvalidArgumentException)
854         {
855                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
856                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
857         }
858         Catch(WrtDeviceApis::Commons::ConversionException)
859         {
860                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
861                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
862         }
863         Catch(WrtDeviceApis::Commons::NotFoundException)
864         {
865                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
866                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
867         }
868         Catch(WrtDeviceApis::Commons::Exception)
869         {
870                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
871                 return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
872         }
873
874         return JSValueMakeUndefined(context);
875
876 }
877
878 const JSClassRef JSMediacontentManager::getClassRef() {
879         if (!m_jsClassRef) {
880                 m_jsClassRef = JSClassCreate(&m_classInfo);
881         }
882         return m_jsClassRef;
883 }
884
885
886 const JSClassDefinition* JSMediacontentManager::getClassInfo()
887 {
888         return &m_classInfo;
889 }
890
891 void JSMediacontentManager::initialize(JSContextRef context, JSObjectRef object)
892 {
893     LogDebug("JSContentManager  initialize entered");
894     MediacontentManagerPrivObject *privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
895     if (NULL == privateObject)
896         {
897         LogDebug("Create ContenttManagerPrivObject");
898         IMediacontentManagerPtr contentManager = MediacontentFactory::getInstance().createMediacontentManagerObject();
899         privateObject = new MediacontentManagerPrivObject(context, contentManager);
900         if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject)))
901                 {
902             delete privateObject;
903         }
904     }
905
906 }
907
908 void JSMediacontentManager::finalize(JSObjectRef object)
909 {
910         LogDebug("Entered");
911         MediacontentManagerPrivObject* priv = static_cast<MediacontentManagerPrivObject*> (JSObjectGetPrivate(object));
912         if(priv != NULL)
913         {
914                 LogDebug("Deleting coordinates object");
915                 delete priv;
916                 JSObjectSetPrivate(object, NULL);
917                 priv = NULL;
918         }
919
920 }
921
922 IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
923                                                 JSContextRef ctx,
924                                         const JSObjectRef object,
925                                         JSValueRef* exception)
926 {
927     MediacontentManagerPrivObject *priv = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(object));
928     if (priv)
929         {
930         return priv->getObject();
931     }
932     ThrowMsg(ConversionException, "Private object is NULL.");
933 }
934
935
936 }
937 }
938
939