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