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