Update change log and spec for wrt-plugins-tizen_0.4.29
[framework/web/wrt-plugins-tizen.git] / src / Filesystem / JSFilesystemManager.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18  
19 #include "JSFilesystemManager.h"
20 #include <Commons/Exception.h>
21 #include "EventResolve.h"
22 #include "IManager.h"
23 #include "IPath.h"
24 #include "EventGetStorage.h"
25 #include "EventListStorages.h"
26 #include "EventStorageStateChanged.h"
27 #include <CommonsJavaScript/JSCallbackManager.h>
28 #include <CommonsJavaScript/Utils.h>
29 #include <CommonsJavaScript/JSUtils.h>
30 #include <CommonsJavaScript/Validator.h>
31 #include <JSWebAPIErrorFactory.h>
32 #include <SecurityExceptions.h>
33 #include <Commons/WrtAccess/WrtAccess.h>
34 #include <WidgetDB/WidgetDBMgr.h>
35 #include <WidgetDB/IWidgetDB.h>
36 #include <TimeTracer.h>
37 #include <ArgumentValidator.h>
38 #include <JSWebAPIException.h>
39 #include <JSUtil.h>
40 #include <Export.h>
41 #include "JSFile.h"
42 #include "FilesystemUtils.h"
43 #include "Converter.h"
44 #include "EventGetNodeData.h"
45 #include "plugin_config.h"
46 #include "StorageStaticController.h"
47 #include "ResponseDispatcher.h"
48 #include "FilesystemAsyncCallbackManager.h"
49 #include "FilesystemListenerManager.h"
50 #include <Logger.h>
51
52 using namespace WrtDeviceApis::Commons;
53 using namespace WrtDeviceApis::CommonsJavaScript;
54 using namespace DeviceAPI::Common;
55 using namespace WrtDeviceApis;
56
57
58
59 namespace {
60 const char* PLUGIN_NAME = "FileSystemManager";
61 const char* PROPERTY_MAXPATHLENGTH = "maxPathLength";
62
63 JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg)
64 {
65         if (Validator(ctx).isCallback(arg)) {
66                 return arg;
67         } else if (!JSValueIsNull(ctx, arg) &&  !JSValueIsUndefined(ctx, arg)) {
68                 ThrowMsg(ConversionException, "Not a function nor JS null.");
69         }
70         return NULL;
71 }
72
73
74 JSValueRef getFunction(JSContextRef ctx, JSValueRef arg)
75 {
76         if (Validator(ctx).isCallback(arg)) {
77                 return arg;
78         }else{
79                 ThrowMsg(ConversionException, "JS null passed as function.");
80         }
81 }
82
83 }
84
85
86
87 namespace DeviceAPI {
88 namespace Filesystem {
89
90 JSClassRef JSFilesystemManager::m_classRef = 0;
91
92 JSClassDefinition JSFilesystemManager::m_classInfo = {
93         0,
94         kJSClassAttributeNone,
95         PLUGIN_NAME,
96         0,
97         m_properties,
98         m_functions,
99         initialize,
100         finalize,
101         NULL,
102         NULL,
103         NULL,
104         NULL,
105         NULL,
106         NULL,
107         NULL,
108         NULL,
109         NULL
110 };
111
112 JSStaticValue JSFilesystemManager::m_properties[] = {
113         { PROPERTY_MAXPATHLENGTH, getMaxPathLength, NULL, kJSPropertyAttributeReadOnly },
114         { 0, 0, 0, 0 }
115 };
116
117 JSStaticFunction JSFilesystemManager::m_functions[] = {
118         { "resolve", JSFilesystemManager::resolve, kJSPropertyAttributeNone },
119         { "getStorage", JSFilesystemManager::getStorage, kJSPropertyAttributeNone },
120         { "listStorages", JSFilesystemManager::getStorageList, kJSPropertyAttributeNone },
121         { "addStorageStateChangeListener", JSFilesystemManager::addStorageStateListener, kJSPropertyAttributeNone },
122         { "removeStorageStateChangeListener", JSFilesystemManager::removeStorageStateListener, kJSPropertyAttributeNone },
123         { 0, 0, 0 }
124 };
125
126 const JSClassRef DLL_EXPORT JSFilesystemManager::getClassRef()
127 {
128         if (!m_classRef) {
129                 m_classRef = JSClassCreate(&m_classInfo);
130         }
131         return m_classRef;
132 }
133
134 const JSClassDefinition* JSFilesystemManager::getClassInfo()
135 {
136         return &m_classInfo;
137 }
138
139 void JSFilesystemManager::initialize(JSContextRef context,
140         JSObjectRef object)
141 {
142         PrivateObject* privateObject = new PrivateObject(context);
143         if (!JSObjectSetPrivate(object, privateObject)) {
144                 delete privateObject;
145         }
146         else {
147         int widgetId = WrtAccessSingleton::Instance().getWidgetId();
148                 WidgetDB::Api::IWidgetDBPtr widgetDB = WidgetDB::Api::getWidgetDB(widgetId);
149
150                 LoggerD(widgetDB->getWidgetInstallationPath());
151                 std::string wgtpackage = "wgt-package";
152                 std::string wgtprivate = "wgt-private";
153                 std::string wgtprivatetemp = "wgt-private-tmp";
154                 
155                 IManager::getInstance().addWidgetStorage(wgtpackage, widgetDB->getWidgetInstallationPath());
156                 IManager::getInstance().addWidgetStorage(wgtprivate, widgetDB->getWidgetPersistentStoragePath());
157                 IManager::getInstance().addWidgetStorage(wgtprivatetemp, widgetDB->getWidgetTemporaryStoragePath());
158         
159         }
160 }
161
162 void JSFilesystemManager::finalize(JSObjectRef object)
163 {
164         PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
165         if (privateObject) {
166                 JSObjectSetPrivate(object, NULL);
167                 delete privateObject;
168         }
169 }
170
171 JSValueRef JSFilesystemManager::getMaxPathLength(JSContextRef context,
172                 JSObjectRef object,
173                 JSStringRef propertyName,
174                 JSValueRef* exception)
175 {
176         ConverterPtr converter = ConverterFactory::getConverter(context);
177         try {
178                 return converter->toJSValueRef(IManager::getInstance().getMaxPathLength());
179         } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
180                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::IO_ERROR, "IO error");
181         }
182 }
183
184 JSValueRef JSFilesystemManager::getStorage(JSContextRef context,
185                 JSObjectRef object,
186                 JSObjectRef thisObject,
187                 size_t argc,
188                 const JSValueRef argv[],
189                 JSValueRef* exception)
190 {
191         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
192         PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
193         if (!privateObject) {
194                 return JSValueMakeUndefined(context);
195         }
196
197         AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_GET_STORAGE);
198         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
199
200         // argument validation with new validator
201         try {
202                 ArgumentValidator validator(context, argc, argv);
203                 validator.toString(0, false);
204                 validator.toFunction(1, false);
205                 validator.toFunction(2, true);  
206         }
207         catch (const BasePlatformException &err) {
208                 return JSWebAPIErrorFactory::postException(context, exception, err);
209         } catch (...) {
210                 DeviceAPI::Common::UnknownException err("");
211                 return JSWebAPIErrorFactory::postException(context, exception, err);
212         }
213
214         if (argc < 2) {
215                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error");
216         }
217
218
219
220
221         JSContextRef globalContext = privateObject->getContext();
222         ConverterPtr converter = ConverterFactory::getConverter(globalContext);
223         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
224         
225         try {
226
227                 JSValueRef onSuccess = getFunction(globalContext, argv[1]);
228                 JSValueRef onError = NULL;
229                         
230                 if (argc>2) {
231                         onError = getFunctionOrNull(globalContext, argv[2]);
232                 }
233
234                 cbm->setOnSuccess(onSuccess);
235                 cbm->setOnError(onError);
236
237                 EventGetStoragePtr event(new EventGetStorage());
238                 event->setLabel(converter->toString(argv[0]));
239                 event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
240                 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
241                 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
242
243                 IManager::getInstance().getStorage(event);
244
245         } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
246                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
247         } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
248                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
249         } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
250                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
251         } catch(const WrtDeviceApis::Commons::Exception& ex) {
252                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
253         }
254         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
255         return JSValueMakeUndefined(context);
256 }
257
258 JSValueRef JSFilesystemManager::getStorageList(JSContextRef context,
259                 JSObjectRef object,
260                 JSObjectRef thisObject,
261                 size_t argc,
262                 const JSValueRef argv[],
263                 JSValueRef* exception)
264 {
265         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
266         PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
267         if (!privateObject) {
268                 return JSValueMakeUndefined(context);
269         }
270
271         AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_LIST_STORAGE);
272         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
273         
274         // argument validation with new validator
275         try {
276                 ArgumentValidator validator(context, argc, argv);
277                 validator.toFunction(0, false);
278                 validator.toFunction(1, true);  
279         }
280         catch (const BasePlatformException &err) {
281                 return JSWebAPIErrorFactory::postException(context, exception, err);
282         } catch (...) {
283                 DeviceAPI::Common::UnknownException err("");
284                 return JSWebAPIErrorFactory::postException(context, exception, err);
285         }
286
287         if (argc < 1) {
288                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error");
289         }
290
291         
292         JSContextRef globalContext = privateObject->getContext();
293         ConverterPtr converter = ConverterFactory::getConverter(globalContext);
294         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
295         
296         try {
297
298                 JSValueRef onSuccess = getFunction(globalContext, argv[0]);
299                 JSValueRef onError = NULL;
300                         
301                 if (argc > 1) {
302                         onError = getFunctionOrNull(globalContext, argv[1]);
303                 }
304
305                 cbm->setOnSuccess(onSuccess);
306                 cbm->setOnError(onError);
307                 cbm->setObject(thisObject);
308
309                 EventListStoragesPtr event(new EventListStorages());
310                 event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
311                 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
312                 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
313
314
315                 IManager::getInstance().listStorages(event);
316
317         } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
318                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
319         } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
320                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
321         } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
322                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
323         } catch(const WrtDeviceApis::Commons::Exception& ex) {
324                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
325         }
326         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
327         return JSValueMakeUndefined(context);
328 }
329
330 JSValueRef JSFilesystemManager::addStorageStateListener(JSContextRef context, 
331                 JSObjectRef object,
332                 JSObjectRef thisObject,
333                 size_t argc,
334                 const JSValueRef argv[],
335                 JSValueRef* exception)
336 {
337         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
338         PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
339         if (!privateObject) {
340                 return JSValueMakeUndefined(context);
341         }
342
343         AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_ADD_STORAGE_LISTENER);
344         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
345
346
347         // argument validation with new validator
348         try {
349                 ArgumentValidator validator(context, argc, argv);
350                 validator.toFunction(0, false);
351                 validator.toFunction(1, true);  
352         }
353         catch (const BasePlatformException &err) {
354                 LogDebug("Exception");
355                 return JSWebAPIErrorFactory::postException(context, exception, err);
356         } catch (...) {
357                 DeviceAPI::Common::UnknownException err("");
358                 return JSWebAPIErrorFactory::postException(context, exception, err);
359         }
360         
361
362         if (argc < 1) {
363                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "TYPE_MISMATCH_ERROR");
364         }
365
366
367         JSContextRef globalContext = privateObject->getContext();
368         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
369         ConverterPtr converter = ConverterFactory::getConverter(globalContext);
370
371         try {
372                 JSValueRef onSuccess = getFunction(globalContext, argv[0]);
373                 JSValueRef onError = NULL;
374                 if (argc > 1) {
375                         onError = getFunctionOrNull(globalContext, argv[1]);
376                 }
377
378                 cbm->setOnSuccess(onSuccess);
379                 cbm->setOnError(onError);
380
381                 EventStorageStateChangedEmitterPtr emitter(new EventStorageStateChangedEmitter);
382                 emitter->setListener(&StorageStaticController::getInstance());
383                 emitter->setEventPrivateData(DPL::StaticPointerCast<EventStorageStateChanged::PrivateDataType>(cbm));
384                 long id = IManager::getInstance().addStorageStateChangeListener(emitter);
385                 
386                 FilesystemListenerCancellerPtr canceller = FilesystemListenerCancellerPtr(new FilesystemListenerCanceller(globalContext, thisObject, id));
387                 IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
388                 FilesystemListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
389
390                 return converter->toJSValueRefLong(id);
391         } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
392                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
393         } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
394                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
395         } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
396                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
397         } catch(const WrtDeviceApis::Commons::Exception& ex) {
398                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
399         }
400         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
401         return JSValueMakeUndefined(context);
402 }
403
404 JSValueRef JSFilesystemManager::removeStorageStateListener(JSContextRef context,
405                 JSObjectRef object,
406                 JSObjectRef thisObject,
407                 size_t argc,
408                 const JSValueRef argv[],
409                 JSValueRef* exception)
410 {
411         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
412         PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
413         if (!privateObject) {
414                 return JSValueMakeUndefined(context);
415         }
416
417         AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_REMOVE_STORAGE_LISTENER);
418         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
419
420         LogDebug("a");
421
422         // argument validation with new validator
423         try {
424                 ArgumentValidator validator(context, argc, argv);
425                 validator.toLong(0, false);
426         }
427         catch (const BasePlatformException &err) {
428                 return JSWebAPIErrorFactory::postException(context, exception, err);
429         } catch (...) {
430                 DeviceAPI::Common::UnknownException err("");
431                 return JSWebAPIErrorFactory::postException(context, exception, err);
432         }
433
434         if (argc < 1) {
435                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error");
436         }
437
438
439         
440
441         JSContextRef globalContext = privateObject->getContext();
442         ConverterPtr converter = ConverterFactory::getConverter(globalContext);
443         
444         try {
445                 long id = static_cast<long>(converter->toLong(argv[0]));
446                 LoggerD("id:" << id);
447
448                 if (id >= 0) {
449                         
450                         FilesystemListenerCancellerPtr canceller = FilesystemListenerCancellerPtr(new FilesystemListenerCanceller(globalContext, thisObject, id));
451                         IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
452                         FilesystemListenerManagerSingleton::Instance().unregisterListener(listenerItem);
453
454                         IManager::getInstance().removeStorageStateChangeListener(id);
455
456                 }
457         } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
458                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
459         } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
460                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
461         } catch (const WrtDeviceApis::Commons::NotFoundException& ex) {
462                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage());
463         } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
464                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
465         } catch(const WrtDeviceApis::Commons::Exception& ex) {
466                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
467         }
468         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
469         return JSValueMakeUndefined(context);
470 }
471
472 JSValueRef JSFilesystemManager::resolve(JSContextRef context,
473                 JSObjectRef object,
474                 JSObjectRef thisObject,
475                 size_t argc,
476                 const JSValueRef argv[],
477                 JSValueRef* exception)
478 {
479
480         LoggerD("<<<");
481         TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
482
483         PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
484         if (!privateObject) {
485                 return JSValueMakeUndefined(context);
486
487         }
488
489         AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID);
490         TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
491
492         // argument validation with new validator
493         try {
494                 ArgumentValidator validator(context, argc, argv);
495                 validator.toString(0, false);
496                 validator.toFunction(1, false);
497                 validator.toFunction(2, true);
498                 validator.toString(3, true);
499         }
500         catch (const BasePlatformException &err) {
501                 return JSWebAPIErrorFactory::postException(context, exception, err);
502         } catch (...) {
503                 DeviceAPI::Common::UnknownException err("");
504                 return JSWebAPIErrorFactory::postException(context, exception, err);
505         }
506         
507         if (argc < 2) {
508                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error");
509         }
510
511         LogDebug("resolve");
512
513
514         
515
516         JSContextRef globalContext = privateObject->getContext();
517         ConverterPtr converter = ConverterFactory::getConverter(globalContext);
518
519         size_t index = 0;
520         JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);      
521         JSValueRef reserveArguments[4];
522
523         try {
524                 for (index = 0; index < 4; index++) {
525                         if (index < argc)
526                                 reserveArguments[index] = argv[index];
527                         else 
528                                 reserveArguments[index] = JSValueMakeUndefined(context);                                                        
529                 }
530                                 
531                 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
532                 JSValueRef onError = NULL;
533
534                 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
535
536                 cbm->setOnSuccess(onSuccess);
537                 cbm->setOnError(onError);
538                 cbm->setObject(thisObject);
539
540                 IPathPtr path;
541                 std::string virtualPath;
542                 path = Utils::fromVirtualPath(globalContext, converter->toString(reserveArguments[0]));
543                 virtualPath = converter->toString(reserveArguments[0]);
544                 LoggerD("virtualPath:[" << virtualPath << "]");
545                 int permissions = PERM_READ | PERM_WRITE;
546
547
548                 
549                 if (argc > 3) {
550                         std::string perms = converter->toString(reserveArguments[3]);
551                         LoggerD("perms:[" << perms << "]");
552                         if (("r" != perms) && ("rw" != perms) && ("w" != perms) && ("a" != perms)) {
553                                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Invalid permission");
554                         } else if ("r" == perms) {
555                                 permissions = PERM_READ;
556                         }
557                 }
558
559                 if (permissions & PERM_WRITE && virtualPath == "wgt-package") {
560                         return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::PERMISSION_DENIED_ERROR, "permission denied");
561                 }
562
563                 PermissionsAccessInfo perms(permissions, virtualPath);
564                 AceSecurityStatus status = FILESYSTEM_PERMISSION_CHECK_ACCESS(
565                                 FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID,
566                                 perms);
567
568                 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
569
570                 EventGetNodeDataPtr data(new EventGetNodeData(permissions, cbm));
571                 EventResolvePtr event(new EventResolve(path));
572                 event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
573                 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (data));
574                 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
575
576                 IManager::getInstance().getNode(event);
577                 
578         } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
579                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
580         } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
581                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage()));
582         } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
583                 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
584         } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
585                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
586         } catch(const WrtDeviceApis::Commons::Exception& ex) {
587                 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
588         }
589
590         TIME_TRACER_ITEM_END(__FUNCTION__, 0);
591         return JSValueMakeUndefined(context);
592 }
593 }
594 }