64743c23efd7792f21f8cac6d6f2714f18e19941
[framework/web/wrt-plugins-tizen.git] / src / Notification / JSStatusNotification.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 #include <SecurityExceptions.h>
19
20 #include <JSUtil.h>
21 #include <JSWebAPIError.h>
22 #include <ArgumentValidator.h>
23 #include <GlobalContextManager.h>
24 #include <MultiCallbackUserData.h>
25 #include <PlatformException.h>
26 #include <JSWebAPIError.h>
27 #include <FilesystemUtils.h>
28 #include "plugin_config.h"
29
30 #include "JSStatusNotification.h"
31 #include "JSNotificationDetailInfo.h"
32
33 using namespace WrtDeviceApis::Commons;
34 using namespace DeviceAPI::Common;
35
36 namespace DeviceAPI {
37 namespace Notification {
38
39 #define NOTIFICATION_TYPE_VALUE "STATUS"
40
41 JSClassDefinition JSStatusNotification::m_classInfo = {
42     0,
43     kJSClassAttributeNone,
44     "StatusNotification",
45     NULL, //ParentClass
46     m_property, //StaticValues
47     NULL, //StaticFunctions
48     initialize, //Initialize
49     finalize, //Finalize
50     NULL, //HasProperty,
51     NULL, //GetProperty,
52     NULL, //SetProperty,
53     NULL, //DeleteProperty,
54     NULL, //GetPropertyNames,
55     NULL, //CallAsFunction,
56     NULL, //CallAsConstructor,
57     NULL, //HasInstance,
58     NULL //ConvertToType
59 };
60
61 JSStaticValue JSStatusNotification::m_property[] = 
62 {
63         {STATUS_NOTIFICATION_PROGRESS_TYPE,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,      kJSPropertyAttributeNone },
64         {STATUS_NOTIFICATION_PROGRESS_VALUE,  JSStatusNotification::getProperty, JSStatusNotification::setProperty,     kJSPropertyAttributeNone },
65         {0, 0, 0, 0}
66 };
67
68 bool JSStatusNotification::setProperty(JSContextRef context,
69         JSObjectRef object,
70         JSStringRef propertyName,
71         JSValueRef value,
72         JSValueRef* exception)
73 {
74
75     StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
76     LogDebug("statusNotification :" << priv);
77     if (!priv) {
78         throw TypeMismatchException("StatusNotification's private object is NULL.");
79     }
80
81         try {
82                     std::string property;
83                     size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
84                     if (jsSize > 0) {
85                         jsSize = jsSize + 1;
86                         char* buffer = new char[jsSize];        
87                         size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
88                         if (written > jsSize) {
89                             throw InvalidValuesException("Conversion could not be fully performed.");
90                         }
91                         property = buffer;
92                         delete[] buffer;
93                     }
94
95                    LogInfo("property =" << property);
96
97                    if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
98                    {
99                         std::string strProgressType = JSUtil::JSValueToString(context, value);
100                         LogInfo("Progress Type : " << strProgressType);
101
102                         NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
103                         if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
104                             progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
105                         else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
106                             progType = NOTI_PROGRESS_TYPE_SIZE;
107                         else
108                             throw InvalidValuesException("Invalid Progress Type.");
109                         
110                         priv->setProgressType(progType);        //set progress Type
111
112                         return true;
113                    }
114                    else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
115                    {
116                             // progressValue
117                             unsigned long progressVal = JSUtil::JSValueToULong(context, value);
118                             LogInfo("Progress Value : " << progressVal);
119                                 
120                             if ( priv->getProgressType() == NOTI_PROGRESS_TYPE_PERCENTAGE)
121                             {
122                                 if ( 100 < progressVal )
123                                                 throw InvalidValuesException("The percentage progress value must be between 0 and 100");
124                                 priv->setProgressValue((double)progressVal/(double)100);
125                             }
126                             else 
127                             {
128                                 priv->setProgressValue((double)progressVal);
129                             }
130
131                             return true;
132                    }
133
134     }
135     catch ( const BasePlatformException& err) 
136     {
137         LogWarning(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
138     }
139         
140
141     return false;
142 }
143
144 JSValueRef JSStatusNotification::getProperty(JSContextRef context,
145                                                                                 JSObjectRef object,
146                                                                                 JSStringRef propertyName,
147                                                                                 JSValueRef* exception)
148 {
149
150         StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
151         LogDebug("statusNotification :" << priv);
152         if (!priv) {
153                 throw TypeMismatchException("StatusNotification's private object is NULL.");
154         }
155
156         try {
157                     std::string property;
158                     size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
159                     if (jsSize > 0) {
160                         jsSize = jsSize + 1;
161                         char* buffer = new char[jsSize];        
162                         size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
163                         if (written > jsSize) {
164                             throw InvalidValuesException("Conversion could not be fully performed.");
165                         }
166                         property = buffer;
167                         delete[] buffer;
168                     }
169
170                    LogInfo("property =" << property);
171                    if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
172                    {
173                         std::string type;
174                         if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
175                         {
176                                 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
177                         }
178                         else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
179                         {
180                                 type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
181                         }
182                    
183                         return JSUtil::toJSValueRef(context, type);
184                    
185                    }
186                    else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
187                    {                            
188                         // progressValue
189                         LogInfo("Progress Type=" << priv->getProgressType());
190                         
191                            // progressValue
192                         unsigned long progressVal = 0;  
193                         if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
194                         {
195                                 progressVal = (unsigned long)( (priv->getProgressValue()*100) );
196                         }
197                         else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
198                         {
199                                 progressVal = (unsigned long)priv->getProgressValue();
200                         }
201                         
202                         LogInfo("Progress Value=" << progressVal);
203
204                         if( priv->getNotiType() != NOTI_TYPE_PROGRESS && progressVal == 0)
205                         {
206                                 return JSValueMakeNull(context);
207                         }
208                         else
209                         {                                  
210                                 return  JSUtil::toJSValueRef(context, progressVal);
211                         }
212                    }
213
214     }
215     catch ( const BasePlatformException& err) 
216     {
217         LogWarning(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
218         return NULL;
219     }
220
221    return NULL;
222 }
223
224
225 JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
226
227 const JSClassRef JSStatusNotification::getClassRef()
228 {
229     if (!m_jsClassRef) {
230         m_jsClassRef = JSClassCreate(&m_classInfo);
231     }
232     return m_jsClassRef;
233 }
234
235 const JSClassDefinition* JSStatusNotification::getClassInfo()
236 {
237     return &m_classInfo;
238 }
239
240 void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
241 {
242         LogDebug("JSStatusNotification::initialize, nothing ");
243 }
244
245 void JSStatusNotification::finalize(JSObjectRef object)
246 {
247     StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
248     if (priv) {
249         JSObjectSetPrivate(object, NULL);
250         delete priv;
251     }
252 }
253
254 JSObjectRef JSStatusNotification::constructor(JSContextRef context,
255     JSObjectRef constructor,
256     size_t argumentCount,
257     const JSValueRef arguments[],
258     JSValueRef* exception)
259 {
260     ArgumentValidator validator(context, argumentCount, arguments);
261
262     //get StatusType
263     JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
264            
265     JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
266     JSObjectSetProperty(context, obj, ctorName, constructor,
267                 kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
268     JSStringRelease(ctorName);
269         
270     try {
271         //Status Notification Type.
272         NotificationType notiType = NOTI_TYPE_NONE;
273         std::string strStatusType = validator.toString(0, false, "");
274         LogInfo("Notification Type : " << strStatusType);
275         
276         if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
277             notiType = NOTI_TYPE_SIMPLE;
278         else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
279             notiType = NOTI_TYPE_THUMBNAIL;
280         else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
281             notiType = NOTI_TYPE_ONGOING;
282         else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
283             notiType = NOTI_TYPE_PROGRESS;
284         else
285             throw TypeMismatchException("notification status type mismatch.");
286         
287         StatusNotification *priv = new StatusNotification(notiType);
288         
289         priv->setTitle(validator.toString(1, false, ""));    //title
290         
291         JSObjectRef notiInitDict = validator.toObject(2, true);
292         
293         if (notiInitDict)
294         {
295             LogInfo("Set Notification Init Dictionary");
296             //content
297             JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
298             if (!JSValueIsUndefined(context, contentValue))
299             {           
300                 priv->setContent(JSUtil::JSValueToString(context, contentValue));
301             }
302                     
303             //icon
304             try {                  
305                 JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
306                 if (!JSValueIsUndefined(context, iconValue))
307                 {
308                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
309                     priv->setIconPath(path->getFullPath());
310                 }
311             }
312             catch (...)
313             {
314                 throw InvalidValuesException("Icon file path is invaild");
315             }
316 #if 0                   
317             catch ( const BasePlatformException& err) 
318             {
319                 LogWarning("notification's icon path convertion is failed."  << err.getMessage());
320             }
321 #endif
322             
323             //sound
324             try {                  
325                 JSValueRef soundValue   = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);      
326                 if (!JSValueIsUndefined(context, soundValue))
327                 {
328                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
329                     priv->setSoundPath(path->getFullPath());
330                 }
331             }
332             catch (...)
333             {
334                  throw InvalidValuesException("sound file path is invaild");
335             }
336        
337             //vibration
338             JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
339             priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
340             
341             //appControl
342             JSValueRef appControlValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
343             if (!JSValueIsUndefined(context, appControlValue))
344                 priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
345             
346             //appID                
347             JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
348             if (!JSValueIsUndefined(context, appIdValue))
349                 priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
350                            
351             //progressType
352             NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
353
354             JSStringRef propertyName = JSStringCreateWithUTF8CString(STATUS_NOTIFICATION_PROGRESS_TYPE);
355             bool has = JSObjectHasProperty(context, notiInitDict, propertyName);
356             JSStringRelease(propertyName);
357             if (has)
358             {
359                 JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
360                 std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
361                 LogInfo("==Progress Type : " << strProgressType);       
362                 if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
363                         progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
364                 else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
365                         progressType = NOTI_PROGRESS_TYPE_SIZE;
366                 else
367                         throw TypeMismatchException("Invalid Progress Type.");          
368             }
369             priv->setProgressType(progressType);
370
371 #if 0                   
372             JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
373             if (progressTypeValue)
374             {
375
376             }
377             if (!JSValueIsUndefined(context, progressTypeValue))
378             {      
379                     std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
380                     LogInfo("==Progress Type : " << strProgressType);   
381                     if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
382                            progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
383                     else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
384                             progressType = NOTI_PROGRESS_TYPE_SIZE;
385                     else
386                             throw TypeMismatchException("Invalid Progress Type.");
387             }
388             priv->setProgressType(progressType);
389 #endif                                          
390             //ProgressValue
391             JSValueRef progressValue    = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);          
392             if (!JSValueIsUndefined(context, progressValue))
393             {
394                 if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
395                {
396                     if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
397                         throw TypeMismatchException("The percentage progress value must be between 0 and 100");
398                     priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
399                 }
400                 else 
401                {
402                     priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
403                }
404             }
405              
406             //DetailInfo
407             JSValueRef detailInfoValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
408
409             std::vector<NotificationDetailInfo*> detailInfos;
410             if (JSIsArrayValue(context, detailInfoValue))
411             {
412                 JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
413                 for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
414                 {
415                     JSValueRef element = JSGetArrayElement(context, arrayobj, i);
416                     JSObjectRef object = JSUtil::JSValueToObject(context, element);
417                     if (object)
418                     {
419                         NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
420                         std::string main = item->getMainText();
421                         std::string sub = item->getSubText();
422                         LogInfo("Main : " << main << " Sub : " << sub);
423              
424                         NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
425                         detailInfos.push_back(detailinfo);      
426                     }
427                 }
428             }
429             priv->setDetailInfos(detailInfos);  
430     
431             //backgroundimage
432             try {                  
433                 JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
434                 if (!JSValueIsUndefined(context, backgroundImageValue))
435                 {
436                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
437                     priv->setBackground(path->getFullPath());
438                 }
439             }
440             catch(...)
441             {
442                  throw TypeMismatchException("The backgound image path is invalid : ");
443             }
444         
445             //number
446             JSValueRef numberValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
447             if (!JSValueIsUndefined(context, numberValue))
448             {
449                  priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
450             }
451            
452             //thumbnail
453             try {                  
454                 JSValueRef thumbnailsValue  = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
455                 if (!JSValueIsUndefined(context, thumbnailsValue))
456                 {
457
458                     std::vector<std::string> thumbnailPaths;
459                     if( JSIsArrayValue(context, thumbnailsValue)){
460                         JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnailsValue);        
461                         for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
462                                  JSValueRef element = JSGetArrayElement(context, arrayobj, i);
463                                          DeviceAPI::Filesystem::IPathPtr thumbnailPath = 
464                                                  DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
465                                          LogInfo("thumbnail Path = " << thumbnailPath->getFullPath());
466                                          thumbnailPaths.push_back(thumbnailPath->getFullPath());
467                         }
468                     }           
469                     priv->setThumbnails(thumbnailPaths);                
470                 }
471             }
472             catch ( ... ) 
473             {
474                 throw TypeMismatchException("thumbnail path convertion is failed.");
475             }
476
477             //subIconPath
478             try {                  
479                 JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
480                 if (!JSValueIsUndefined(context, subIconPathValue))
481                 {
482                     DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
483                     priv->setSubIconPath( path->getFullPath());
484                 }
485             }
486             catch (...) 
487             {
488                 throw TypeMismatchException("subIcon path convertion is failed.");
489             }
490                     
491         }
492                
493         setPrivateObject(context, obj, priv);
494                 
495     } 
496      catch ( const BasePlatformException& err) 
497     {
498         LogWarning(" notification convertion is failed. "   << err.getName().c_str() << ":"  << err.getMessage().c_str());
499         JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
500         *exception = error;
501         return error;
502     }
503
504     return obj;      
505
506 }
507
508 StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
509 {
510     LogDebug("get object :" << object);
511
512     StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
513     LogDebug("statusNotification :" << priv);
514     if (!priv) {
515         throw TypeMismatchException("StatusNotification's private object is NULL.");
516     }
517
518     //type
519     JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
520     if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
521     {
522         throw TypeMismatchException("StatusNotification's type is mismatched");
523     }
524      
525     //Title
526     JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
527     priv->setTitle( JSUtil::JSValueToString(context, title));
528
529     //Content
530     JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
531     priv->setContent( JSUtil::JSValueToString(context, contents));
532
533     // iconPath
534     JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
535     if (!JSUtil::JSValueToString(context, iconPath).empty())
536     {
537         DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
538         priv->setIconPath(icon->getFullPath());
539     }
540     else
541     {
542         priv->setIconPath("");
543     }
544
545     // subIconPath
546     JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
547     if (!JSUtil::JSValueToString(context, subIconPath).empty())
548     {
549         DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
550         priv->setSubIconPath(subIcon->getFullPath());
551     }
552     else
553     {
554         priv->setSubIconPath("");
555     }
556
557     // number
558     JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
559     priv->setNumber(JSUtil::JSValueToLong(context, number));
560
561     // detailInfo
562     JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
563     std::vector<NotificationDetailInfo*> detailInfos;
564     if (JSIsArrayValue(context, detailInfo))
565     {
566         JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
567         for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
568         {
569             JSValueRef element = JSGetArrayElement(context, arrayobj, i);
570             JSObjectRef object = JSUtil::JSValueToObject(context, element);
571             if (object)
572             {
573                 NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
574                 detailInfos.push_back(detailinfo);      
575             }
576         }
577     }
578     priv->setDetailInfos(detailInfos);
579     
580     // backgroundImagePath
581     JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
582     if (!JSUtil::JSValueToString(context, backgroundImagePath).empty())
583     {
584         DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
585         priv->setBackground(backgroundImage->getFullPath());
586     }
587     else
588     {
589         priv->setBackground("");
590     }
591     
592     // thumbnails
593     JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
594
595     std::vector<std::string> thumbnailPaths;
596     if( JSIsArrayValue(context, thumbnails)){
597         JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnails);     
598          for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
599                  JSValueRef element = JSGetArrayElement(context, arrayobj, i);
600                  DeviceAPI::Filesystem::IPathPtr thumbnailPath = 
601                      DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
602                  LogInfo("thumbnail Path = " << thumbnailPath->getFullPath());
603                  thumbnailPaths.push_back(thumbnailPath->getFullPath());
604          }
605     }           
606     priv->setThumbnails(thumbnailPaths);
607     
608     // soundPath
609     JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
610     if (!JSUtil::JSValueToString(context, soundPath).empty())
611     {
612         DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
613         priv->setSoundPath(sound->getFullPath());
614     }
615     else
616     {
617         priv->setSoundPath("");
618     }
619     
620     // vibration
621     JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
622     priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
623
624     // appControl
625     JSValueRef appControl = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL);
626     priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context,appControl)));
627
628     // appId
629     JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
630     priv->setApplicationId(JSUtil::JSValueToString(context, appId));
631
632 #if 0
633     // progressType
634     JSValueRef progressType = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE);
635     std::string strProgressType = JSUtil::JSValueToString(context, progressType);
636     LogInfo("Progress Type : " << strProgressType);
637     
638     NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
639     if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
640         progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
641     else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
642         progType = NOTI_PROGRESS_TYPE_SIZE;
643     else
644         throw InvalidValuesException("Invalid Progress Type.");
645     priv->setProgressType(progType);
646     
647     // progressValue
648     JSValueRef progressValue = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE);
649     LogInfo(" Progress Value in Private Object = " << JSUtil::JSValueToULong(context, progressValue));
650     if ( progType == NOTI_PROGRESS_TYPE_PERCENTAGE)
651     {
652         if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
653                         throw InvalidValuesException("The percentage progress value must be between 0 and 100");
654         priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
655     }
656     else 
657     {
658         priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
659     }
660  #endif   
661     return priv;
662 }
663
664 void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
665 {
666     if (priv) {
667         JSObjectSetPrivate(object, static_cast<void*>(priv));
668     }
669     else
670         throw TypeMismatchException("StatusNotification object is invaild.");
671
672     //type
673     std::string typeVal(NOTIFICATION_TYPE_VALUE);
674     JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
675             JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeReadOnly);
676         
677     std::string type;
678     
679     //statusType
680     if ( NOTI_TYPE_SIMPLE ==  priv->getNotiType())
681         type = TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE;
682     else if ( NOTI_TYPE_ONGOING ==  priv->getNotiType())
683         type = TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING;
684     else if ( NOTI_TYPE_PROGRESS ==  priv->getNotiType())
685         type = TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS; 
686     else if ( NOTI_TYPE_THUMBNAIL ==  priv->getNotiType())
687         type = TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL;
688     else
689         throw TypeMismatchException("status type mismatch.");
690         
691     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
692             JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
693     //id
694     if (priv->getID() >= 0)
695     {
696             std::stringstream stream;
697             stream << priv->getID();
698             
699             if(stream.fail())
700                throw TypeMismatchException("Notification's ID conversion is failed.");
701
702             JSUtil::setProperty(context, object, NOTIFICATION_ID,
703                 JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeReadOnly);        
704     }
705     else
706     {
707             JSUtil::setProperty(context, object, NOTIFICATION_ID,
708                     JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
709     }
710
711     //postedTime
712     if (priv->getPostedTime() > 0)
713     {
714             JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
715                 JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeReadOnly);  
716     }
717     else
718     {
719             JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
720                     JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
721     }    
722
723     //title
724     JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
725             JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
726
727     //content
728     if (priv->getStrContent())
729         JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
730                   JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
731     else
732         JSUtil::setProperty(context, object, NOTIFICATION_CONTENT, JSValueMakeNull(context), kJSPropertyAttributeNone);   
733
734     //iconPath
735     if (!priv->getIconPath().empty())
736         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
737                 JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
738     else
739          JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
740
741     //subIconPath
742     if ( !priv->getSubIconPath().empty())
743         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
744                JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
745     else 
746         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,  JSValueMakeNull(context), kJSPropertyAttributeNone);
747
748     //number
749     if (priv->getStrNumber()){
750         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
751             JSUtil::toJSValueRef(context, priv->getNumber()), kJSPropertyAttributeNone);        
752     }
753     else
754         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER, JSValueMakeNull(context), kJSPropertyAttributeNone);                   
755
756      // backgroundImagePath
757     if ( !priv->getBackground().empty()) 
758         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
759             JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
760     else
761         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
762         
763     // thumbnails
764     std::vector<std::string> thumbnails = priv->getThumbnails();
765     LogInfo("Thumbnail Size : " << thumbnails.size());
766      JSValueRef tumbnailvalueArray[thumbnails.size()];
767     for( unsigned int i = 0 ; i < thumbnails.size(); i++) {
768             if (!thumbnails[i].empty())
769             {
770                 LogInfo("Thumbnail :" << thumbnails[i]);
771                 tumbnailvalueArray[i] =  JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, thumbnails[i]));
772             }
773     }
774
775     JSValueRef exception = NULL;
776     JSObjectRef jsThumbnails = JSObjectMakeArray(context, thumbnails.size(), tumbnailvalueArray, &exception);
777     if (exception != NULL) {
778         throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
779     }
780
781     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
782            jsThumbnails, kJSPropertyAttributeNone);
783
784     // soundPath
785     if ( !priv->getSoundPath().empty() )
786         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
787             JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
788     else
789         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH, JSValueMakeNull(context), kJSPropertyAttributeNone);
790
791     // vibration
792     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
793             JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
794
795     // appId
796     if (!priv->getApplicationId().empty())
797         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
798             JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
799     else
800         JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID, JSValueMakeNull(context), kJSPropertyAttributeNone);
801
802 #if 0
803     // progressType   & Value
804     LogInfo("Progress Type=" << priv->getProgressType());
805
806        // progressValue
807     unsigned long progressVal = 0;      
808     if ( NOTI_PROGRESS_TYPE_PERCENTAGE ==  priv->getProgressType())
809     {
810         type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
811         progressVal = (unsigned long)( (priv->getProgressValue()*100) );
812     }
813     else if ( NOTI_PROGRESS_TYPE_SIZE==   priv->getProgressType())
814     {
815         type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
816         progressVal = (unsigned long)priv->getProgressValue();
817     }
818
819     LogInfo("Progress Type=" << type);
820     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE,
821             JSUtil::toJSValueRef(context, type), kJSPropertyAttributeNone);
822                 
823     LogInfo("Progress Value =" << progressVal); 
824     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE,                
825             JSUtil::toJSValueRef(context, progressVal), kJSPropertyAttributeNone);
826 #endif
827     // detailInfo
828     std::vector<NotificationDetailInfo*> detailInfo = priv->getDetailInfos();
829     LogInfo("detail Info Size : " << detailInfo.size());
830     JSObjectRef valueArray[detailInfo.size()];
831     for( unsigned int i = 0 ; i < detailInfo.size(); i++) {
832             if (detailInfo[i])
833             {
834                 LogInfo("Main = " << detailInfo[i]->getMainText() << " Sub = " << detailInfo[i]->getSubText());
835                 valueArray[i] = JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSNotificationDetailInfo::getClassRef(), static_cast<void*>(detailInfo[i]));
836                 JSNotificationDetailInfo::setPrivateObject(context, valueArray[i], detailInfo[i]);
837                 LogInfo("make Object : " << valueArray[i]);
838             }
839     }
840
841     exception = NULL;
842     JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), detailInfo.size(), valueArray, &exception);
843     if (exception != NULL) {
844         throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
845     }
846
847        // detailInfo
848     JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
849            jsResult, kJSPropertyAttributeNone);
850
851     // appControl
852     if (  !(priv->getApplicationControl())->getOperation().empty())
853     {   
854             DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
855             JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
856             JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL,  jsAppCtrl, kJSPropertyAttributeNone);
857     }
858     else
859            JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL,   JSValueMakeNull(context), kJSPropertyAttributeNone);
860   
861 }
862
863
864 } // Notification
865 } // DeviceAPI