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