2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include "plugin_config_impl.h"
25 #include <Commons/FunctionDeclaration.h>
26 #include <Commons/Exception.h>
27 #include <Commons/WrtAccess/WrtAccess.h>
30 #include "EventCopy.h"
31 #include "EventMove.h"
32 #include "EventListNodes.h"
33 #include "EventOpen.h"
34 #include "EventReadText.h"
35 #include <CommonsJavaScript/JSCallbackManager.h>
36 #include <CommonsJavaScript/Validator.h>
37 #include <CommonsJavaScript/JSUtils.h>
38 #include <CommonsJavaScript/Utils.h>
39 #include <JSWebAPIErrorFactory.h>
40 #include <SecurityExceptions.h>
41 #include <ArgumentValidator.h>
45 #include <TimeTracer.h>
46 #include "FilesystemUtils.h"
47 #include "Converter.h"
48 #include "plugin_config.h"
49 #include "Encodings.h"
50 #include "ResponseDispatcher.h"
51 #include "FilesystemAsyncCallbackManager.h"
54 using namespace WrtDeviceApis::Commons;
55 using namespace WrtDeviceApis::CommonsJavaScript;
56 using namespace DeviceAPI::Common;
59 #define PLUGIN_NAME "File"
60 #define PROPERTY_PARENT "parent"
61 #define PROPERTY_READ_ONLY "readOnly"
62 #define PROPERTY_IS_FILE "isFile"
63 #define PROPERTY_IS_DIRECTORY "isDirectory"
64 #define PROPERTY_CREATED "created"
65 #define PROPERTY_MODIFIED "modified"
66 #define PROPERTY_PATH "path"
67 #define PROPERTY_NAME "name"
68 #define PROPERTY_FULL_PATH "fullPath"
69 #define PROPERTY_FILE_SIZE "fileSize"
70 #define PROPERTY_LENGTH "length"
73 JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg)
75 if (Validator(ctx).isCallback(arg)) {
77 } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) {
78 ThrowMsg(ConversionException, "Not a function nor JS null.");
85 JSValueRef getFunction(JSContextRef ctx, JSValueRef arg)
87 if (Validator(ctx).isCallback(arg)) {
90 ThrowMsg(ConversionException, "Not a function nor JS null.");
95 namespace Filesystem {
97 JSClassRef JSFile::m_classRef = 0;
99 JSClassDefinition JSFile::m_classInfo = {
101 kJSClassAttributeNone,
119 JSStaticValue JSFile::m_properties[] = {
120 { PROPERTY_PARENT, getProperty, NULL, kJSPropertyAttributeReadOnly },
121 { PROPERTY_READ_ONLY, getProperty, NULL, kJSPropertyAttributeReadOnly },
122 { PROPERTY_IS_FILE, getProperty, NULL, kJSPropertyAttributeReadOnly },
123 { PROPERTY_IS_DIRECTORY, getProperty, NULL, kJSPropertyAttributeReadOnly },
124 { PROPERTY_CREATED, getProperty, NULL, kJSPropertyAttributeReadOnly },
125 { PROPERTY_MODIFIED, getProperty, NULL, kJSPropertyAttributeReadOnly },
126 { PROPERTY_PATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
127 { PROPERTY_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
128 { PROPERTY_FULL_PATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
129 { PROPERTY_FILE_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
130 { PROPERTY_LENGTH, getProperty, NULL, kJSPropertyAttributeReadOnly },
134 JSStaticFunction JSFile::m_functions[] = {
135 { "toURI", toUri, kJSPropertyAttributeNone },
136 { "listFiles", listFiles, kJSPropertyAttributeNone },
137 { "openStream", openStream, kJSPropertyAttributeNone },
138 { "readAsText", readAsText, kJSPropertyAttributeNone },
139 { "copyTo", copyTo, kJSPropertyAttributeNone },
140 { "moveTo", moveTo, kJSPropertyAttributeNone },
141 { "createDirectory", createDirectory, kJSPropertyAttributeNone },
142 { "createFile", createFile, kJSPropertyAttributeNone },
143 { "resolve", resolve, kJSPropertyAttributeNone },
144 { "deleteDirectory", deleteDirectory, kJSPropertyAttributeNone },
145 { "deleteFile", deleteFile, kJSPropertyAttributeNone },
149 void JSFile::initialize(JSContextRef context,
154 void JSFile::finalize(JSObjectRef object)
156 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
158 JSObjectSetPrivate(object, NULL);
159 delete privateObject;
163 const JSClassRef DLL_EXPORT JSFile::getClassRef()
166 m_classRef = JSClassCreate(&m_classInfo);
171 const JSClassDefinition* JSFile::getClassInfo()
176 JSValueRef JSFile::getProperty(JSContextRef context,
178 JSStringRef propertyName,
179 JSValueRef* exception)
181 PrivateObject* privateObject =
182 static_cast<PrivateObject*>(JSObjectGetPrivate(object));
183 if (!privateObject) {
184 LoggerE("Private object is not set.");
185 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
188 JSContextRef globalContext = privateObject->getContext();
189 Converter converter(globalContext);
192 if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PARENT))
194 INodePtr parent(privateObject->getObject()->getNode()->getParent());
195 PrivateObjectDef::PermissionList perms =
196 privateObject->getObject()->getParentPermissions();
197 if (parent && !perms.empty())
199 parent->setPermissions(perms.back());
201 PrivateObjectDefPtr privDefData(new PrivateObjectDef(parent, perms));
202 JSFile::PrivateObject* privData = new JSFile::PrivateObject(globalContext, privDefData);
203 privData->copyAceCheckAccessFunction(privateObject);
205 JSObjectRef object = JSObjectMake(globalContext, JSFile::getClassRef(), privData);
209 return JSValueMakeNull(context);
211 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_READ_ONLY))
213 bool readOnly = ((privateObject->getObject()->getNode()->getMode() & PM_USER_WRITE) == 0);
214 return converter.toJSValueRef(readOnly);
216 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_FILE))
218 bool isFile = (privateObject->getObject()->getNode()->getType() == NT_FILE);
219 return converter.toJSValueRef(isFile);
221 else if (JSStringIsEqualToUTF8CString(propertyName,
222 PROPERTY_IS_DIRECTORY))
224 bool isDirectory = (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY);
225 return converter.toJSValueRef(isDirectory);
227 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CREATED))
229 std::time_t created = privateObject->getObject()->getNode()->getCreated();
230 return converter.toJSValueRef(created);
232 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MODIFIED))
234 std::time_t modified = privateObject->getObject()->getNode()->getModified();
235 return converter.toJSValueRef(modified);
237 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PATH))
239 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
240 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
241 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
242 std::string path = (std::string::npos != pos ? vpath.substr(0, pos + 1) : vpath);
243 return converter.toJSValueRef(path);
245 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME))
247 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
248 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
250 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
252 if (std::string::npos != pos) {
253 name = vpath.substr(pos + 1);
255 return converter.toJSValueRef(name);
257 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FULL_PATH))
259 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
260 return converter.toJSValueRef(Utils::toVirtualPath(globalContext, path));
262 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FILE_SIZE))
264 if (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY)
266 return JSValueMakeUndefined(context);
268 return converter.toJSValueRef(privateObject->getObject()->getNode()->getSize());
270 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_LENGTH))
272 if (privateObject->getObject()->getNode()->getType() == NT_FILE) {
273 return JSValueMakeUndefined(context);
275 // TODO: think about more efficent solution!
276 NodeList children = privateObject->getObject()->getNode()->getChildNodes();
277 return converter.toJSValueRef(children.size());
280 catch (const WrtDeviceApis::Commons::Exception& ex) {
281 LoggerE("Exception: " << ex.GetMessage());
284 else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_READ_ONLY)) {
285 bool readOnly = ((privateObject->getObject()->getNode() & PERM_WRITE) == 0);
286 return converter.toJSValueRef(readOnly);
287 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_FILE)) {
288 bool isFile = (privateObject->getObject()->getNode()->getType() == NT_FILE);
289 return converter.toJSValueRef(isFile);
290 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_DIRECTORY)) {
291 bool isDirectory =(privateObject->getObject()->getNode()->getType() == NT_DIRECTORY);
292 return converter.toJSValueRef(isDirectory);
293 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CREATED)) {
294 std::time_t created = privateObject->getObject()->getNode()->getCreated();
295 return converter.toJSValueRef(created);
296 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MODIFIED)) {
297 std::time_t modified = privateObject->getObject()->getNode()->getModified();
298 return converter.toJSValueRef(modified);
299 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PATH)) {
300 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
301 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
302 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
303 std::string path = (std::string::npos != pos ? vpath.substr(0, pos + 1) : vpath);
304 return converter.toJSValueRef(path);
305 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME)) {
306 std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
307 std::string vpath = Utils::toVirtualPath(globalContext, fpath);
309 std::string::size_type pos = vpath.rfind(IPath::getSeparator());
310 if (std::string::npos != pos) {
311 name = vpath.substr(pos + 1);
313 return converter.toJSValueRef(name);
314 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FULL_PATH)) {
315 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
316 return converter.toJSValueRef(Utils::toVirtualPath(globalContext, path));
317 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FILE_SIZE)) {
318 if (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY) {
319 return JSValueMakeUndefined(context);
321 return converter.toJSValueRef(privateObject->getObject()->getNode()->getSize());
322 } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_LENGTH)) {
323 if (privateObject->getObject()->getNode()->getType() == NT_FILE) {
324 return JSValueMakeUndefined(context);
326 NodeList children = privateObject->getObject()->getNode()->getChildNodes();
327 return converter.toJSValueRef(children.size());
329 } catch (const WrtDeviceApis::Commons::Exception& ex) {
330 LoggerW("trying to get incorrect value");
333 return JSValueMakeUndefined(context);
336 void JSFile::getPropertyNames(JSContextRef context,
338 JSPropertyNameAccumulatorRef propertyNames)
342 bool JSFile::hasInstance(JSContextRef context,
343 JSObjectRef constructor,
344 JSValueRef possibleInstance,
345 JSValueRef* exception)
347 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
350 JSValueRef JSFile::toUri(JSContextRef context,
352 JSObjectRef thisObject,
354 const JSValueRef argv[],
355 JSValueRef* exception)
357 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
358 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
359 if (!privateObject) {
360 LoggerE("Private object is not set.");
361 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
363 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_TO_URI);
365 Converter converter(context);
368 int widgetId = WrtAccessSingleton::Instance().getWidgetId();
369 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
370 return converter.toJSValueRef(privateObject->getObject()->getNode()->toUri(widgetId));
371 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
372 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
373 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
374 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
375 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
376 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
377 } catch(const WrtDeviceApis::Commons::Exception& ex) {
378 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
382 JSValueRef JSFile::listFiles(JSContextRef context,
384 JSObjectRef thisObject,
386 const JSValueRef argv[],
387 JSValueRef* exception)
389 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
390 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
391 if (!privateObject) {
392 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
397 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_LIST_FILES);
399 // argument validation with new validator
401 ArgumentValidator validator(context, argc, argv);
402 validator.toFunction(0, false);
403 validator.toFunction(1, true);
404 validator.toObject(2, true);
406 catch (const BasePlatformException &err) {
407 return JSWebAPIErrorFactory::postException(context, exception, err);
409 DeviceAPI::Common::UnknownException err("");
410 return JSWebAPIErrorFactory::postException(context, exception, err);
413 JSContextRef globalContext = privateObject->getContext();
415 JSValueRef reserveArguments[3];
416 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
421 for (index = 0; index < 3; index++)
424 reserveArguments[index] = argv[index];
426 reserveArguments[index] = JSValueMakeUndefined(context);
429 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
430 JSValueRef onError = NULL;
434 onError = getFunctionOrNull(globalContext, reserveArguments[1]);
437 cbm->setOnSuccess(onSuccess);
438 cbm->setOnError(onError);
439 cbm->setObject(thisObject);
441 Converter converter(globalContext);
443 EventListNodesPtr event(new EventListNodes(privateObject->getObject()->getNode()));
445 if (JSValueIsNull(context, reserveArguments[2]) == false &&
446 JSValueIsUndefined(context, reserveArguments[2]) == false) {
447 event->setFilter(converter.toNodeFilter(reserveArguments[2]));
450 PrivateObjectDef::PermissionList perms =
451 privateObject->getObject()->getParentPermissions();
452 perms.push_back(privateObject->getObject()->getNode()->getPermissions());
454 ListFilesPrivateDataPtr privData(new ListFilesPrivateData(cbm, perms));
456 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
457 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
458 event->copyAceCheckAccessFunction(privateObject);
460 privateObject->getObject()->getNode()->getChildNodes(event);
461 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
464 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
465 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
466 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
467 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
468 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
469 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
470 } catch(const WrtDeviceApis::Commons::Exception& ex) {
471 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
473 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
474 return JSValueMakeUndefined(context);
477 JSValueRef JSFile::openStream(JSContextRef context,
479 JSObjectRef thisObject,
480 size_t argumentCount,
481 const JSValueRef arguments[],
482 JSValueRef* exception)
484 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
485 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
486 if (!privateObject) {
487 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
490 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_OPEN_STREAM);
492 // argument validation with new validator
494 ArgumentValidator validator(context, argumentCount, arguments);
495 validator.toFunction(1, false);
496 validator.toFunction(2, true);
498 catch (const BasePlatformException &err) {
499 return JSWebAPIErrorFactory::postException(context, exception, err);
501 DeviceAPI::Common::UnknownException err("");
502 return JSWebAPIErrorFactory::postException(context, exception, err);
505 JSContextRef globalContext = privateObject->getContext();
506 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
509 JSValueRef reserveArguments[4];
514 for (index = 0; index < 4; index++) {
515 if (index < argumentCount)
516 reserveArguments[index] = arguments[index];
518 reserveArguments[index] = JSValueMakeUndefined(context);
522 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
523 JSValueRef onError = NULL;
525 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
527 cbm->setOnSuccess(onSuccess);
528 cbm->setOnError(onError);
529 cbm->setObject(thisObject);
532 Converter converter(globalContext);
534 AccessMode mode = converter.toAccessMode(reserveArguments[0]);
535 std::string encoding = Encodings::UTF8;
536 if (argumentCount > 3) {
537 if(!JSValueIsNull(globalContext, reserveArguments[3]) && !JSValueIsUndefined(globalContext, reserveArguments[3])){
538 encoding = converter.toEncoding(reserveArguments[3]);
542 if ((AM_READ != mode) && (PERM_READ == privateObject->getObject()->getNode()->getPermissions())) {
543 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context,
544 JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "permission denied error"));
545 return JSValueMakeUndefined(context);
548 std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
549 std::string vpath = Utils::toVirtualPath(globalContext, path);
551 EventOpenPtr event(new EventOpen(mode));
552 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(cbm));
553 event->setCharSet(encoding);
554 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
555 event->copyAceCheckAccessFunction(privateObject);
557 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
559 privateObject->getObject()->getNode()->open(event);
562 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
563 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
564 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
565 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
566 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
567 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
568 } catch(const WrtDeviceApis::Commons::Exception& ex) {
569 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
571 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
572 return JSValueMakeUndefined(context);
575 JSValueRef JSFile::readAsText(JSContextRef context,
577 JSObjectRef thisObject,
579 const JSValueRef argv[],
580 JSValueRef* exception)
582 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
583 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
584 if (!privateObject) {
585 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
588 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_READ_AS_TEXT);
590 // argument validation with new validator
592 ArgumentValidator validator(context, argc, argv);
593 validator.toFunction(0, false);
594 validator.toFunction(1, true);
596 catch (const BasePlatformException &err) {
597 return JSWebAPIErrorFactory::postException(context, exception, err);
599 DeviceAPI::Common::UnknownException err("");
600 return JSWebAPIErrorFactory::postException(context, exception, err);
604 JSContextRef globalContext = privateObject->getContext();
608 JSValueRef reserveArguments[3];
609 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
613 for (index = 0; index < 3; index++) {
615 reserveArguments[index] = argv[index];
617 reserveArguments[index] = JSValueMakeUndefined(context);
622 JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
623 JSValueRef onError = NULL;
626 onError = getFunctionOrNull(globalContext, reserveArguments[1]);
629 cbm->setOnSuccess(onSuccess);
630 cbm->setOnError(onError);
631 cbm->setObject(thisObject);
633 Converter converter(context);
634 std::string src = Encodings::UTF8;
636 if (!JSValueIsNull(context, reserveArguments[2]) && !JSValueIsUndefined(context, reserveArguments[2])) {
637 src = converter.toEncoding(reserveArguments[2]);
641 if (NT_FILE != privateObject->getObject()->getNode()->getType()) {
642 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, "IO error"));
643 return JSValueMakeUndefined(context);
646 EventReadTextPtr event(new EventReadText());
647 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData,JSCallbackManager>(cbm));
648 event->setCharSet(src);
649 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
650 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
652 privateObject->getObject()->getNode()->read(event);
654 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
655 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
656 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
657 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
658 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
659 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
660 } catch(const WrtDeviceApis::Commons::Exception& ex) {
661 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
663 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
664 return JSValueMakeUndefined(context);
667 JSValueRef JSFile::copyTo(JSContextRef context,
669 JSObjectRef thisObject,
671 const JSValueRef argv[],
672 JSValueRef* exception)
674 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
675 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
676 if (!privateObject) {
677 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
680 TIZEN_CHECK_ACCESS(context, exception, privateObject,FILESYSTEM_FUNCTION_API_COPY_TO);
682 JSContextRef globalContext = privateObject->getContext();
684 JSValueRef reserveArguments[5];
685 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
688 // argument validation with new validator
690 ArgumentValidator validator(context, argc, argv);
691 validator.toFunction(3, true);
692 validator.toFunction(4, true);
694 catch (const BasePlatformException &err) {
695 return JSWebAPIErrorFactory::postException(context, exception, err);
697 DeviceAPI::Common::UnknownException err("");
698 return JSWebAPIErrorFactory::postException(context, exception, err);
704 for (index = 0; index < 5; index++)
707 reserveArguments[index] = argv[index];
709 reserveArguments[index] = JSValueMakeUndefined(context);
712 Converter converter(globalContext);
713 JSValueRef onSuccess = NULL;
714 JSValueRef onError = NULL;
716 onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
717 onError = getFunctionOrNull(globalContext, reserveArguments[4]);
719 cbm->setOnSuccess(onSuccess);
720 cbm->setOnError(onError);
721 cbm->setObject(thisObject);
724 //TODO add check validation for src, dest string.
725 IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
726 IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
727 bool overwrite = converter.toBool(reserveArguments[2]);;
729 /* if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
730 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context,
731 JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "permission denied error"));
732 return JSValueMakeUndefined(context);
735 if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
736 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, "IO error"));
737 return JSValueMakeUndefined(context);
740 std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
742 EventCopyPtr event(new EventCopy(src, dest));
745 event->setOptions(OPT_OVERWRITE);
748 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::
752 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
753 event->copyAceCheckAccessFunction(privateObject);
755 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
757 IManager::getInstance().copy(event);
758 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
759 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
760 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
761 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
762 } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
763 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage()));
764 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
765 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
766 } catch(const WrtDeviceApis::Commons::Exception& ex) {
767 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
770 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
771 return JSValueMakeUndefined(context);
774 JSValueRef JSFile::moveTo(JSContextRef context,
776 JSObjectRef thisObject,
778 const JSValueRef argv[],
779 JSValueRef* exception)
781 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
782 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
783 if (!privateObject) {
784 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
787 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_MOVE_TO);
789 JSContextRef globalContext = privateObject->getContext();
793 // argument validation with new validator
795 ArgumentValidator validator(context, argc, argv);
796 validator.toFunction(3, true);
797 validator.toFunction(4, true);
799 catch (const BasePlatformException &err) {
800 return JSWebAPIErrorFactory::postException(context, exception, err);
802 DeviceAPI::Common::UnknownException err("");
803 return JSWebAPIErrorFactory::postException(context, exception, err);
807 JSValueRef reserveArguments[5];
808 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
813 for (index = 0; index < 5; index++) {
815 reserveArguments[index] = argv[index];
817 reserveArguments[index] = JSValueMakeUndefined(context);
820 Converter converter(context);
821 JSValueRef onSuccess = NULL;
822 JSValueRef onError = NULL;
824 onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
825 onError = getFunctionOrNull(globalContext, reserveArguments[4]);
826 cbm->setOnSuccess(onSuccess);
827 cbm->setOnError(onError);
828 cbm->setObject(thisObject);
830 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
831 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context,
832 JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "permission denied error"));
833 return JSValueMakeUndefined(context);
836 if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
837 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, "io error"));
838 return JSValueMakeUndefined(context);
841 IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
842 IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
843 bool overwrite = converter.toBool(reserveArguments[2]);
845 std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
847 EventMovePtr event(new EventMove(src, dest));
849 event->setOptions(OPT_OVERWRITE);
852 event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
853 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
854 event->copyAceCheckAccessFunction(privateObject);
856 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
858 IManager::getInstance().move(event);
860 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
861 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
862 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
863 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
864 } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
865 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage()));
867 catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
868 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
869 } catch(const WrtDeviceApis::Commons::Exception& ex) {
870 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
872 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
873 return JSValueMakeUndefined(context);
876 JSValueRef JSFile::createDirectory(JSContextRef context,
878 JSObjectRef thisObject,
880 const JSValueRef argv[],
881 JSValueRef* exception)
883 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
884 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
885 if (!privateObject) {
886 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
889 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_CREATE_DIR);
891 Converter converter(context);
895 ThrowMsg(InvalidArgumentException, "Invalid path name");
897 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
898 ThrowMsg(WrtDeviceApis::Commons::SecurityException, "Permission denied error");
901 IPathPtr path = converter.toPath(argv[0]);
902 INodePtr node(privateObject->getObject()->getNode()->createChild(path, NT_DIRECTORY, OPT_RECURSIVE));
903 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
905 PrivateObjectDefPtr privDefData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
906 privDefData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
907 JSFile::PrivateObject* privData = new JSFile::PrivateObject(privateObject->getContext(), privDefData);
908 privData->copyAceCheckAccessFunction(privateObject);
910 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
913 JSObjectRef object = JSObjectMake(privateObject->getContext(), JSFile::getClassRef(), privData);
915 } catch (const WrtDeviceApis::Commons::SecurityException& ex) {
916 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
918 catch (const WrtDeviceApis::Commons::PlatformException& ex) {
919 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::IO_ERROR, ex.GetMessage());
920 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
921 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
922 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
923 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
924 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
925 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
926 } catch(const WrtDeviceApis::Commons::Exception& ex) {
927 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
931 JSValueRef JSFile::createFile(JSContextRef context,
933 JSObjectRef thisObject,
935 const JSValueRef argv[],
936 JSValueRef* exception)
938 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
939 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
940 if (!privateObject) {
941 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
944 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_CREATE_FILE);
946 Converter converter(context);
950 ThrowMsg(InvalidArgumentException, "Invalid path name");
953 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
954 ThrowMsg(WrtDeviceApis::Commons::SecurityException, "Permission denied error");
957 IPathPtr path = converter.toPath(argv[0]);
958 INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
960 PrivateObjectDefPtr privDefData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
961 privDefData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
963 JSFile::PrivateObject* privData = new JSFile::PrivateObject(privateObject->getContext(), privDefData);
964 privData->copyAceCheckAccessFunction(privateObject);
966 JSObjectRef object = JSObjectMake(privateObject->getContext(), JSFile::getClassRef(), privData);
968 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
972 } catch (const WrtDeviceApis::Commons::SecurityException& ex) {
973 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
974 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
975 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::IO_ERROR, ex.GetMessage());
976 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
977 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
978 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
979 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
980 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
981 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
982 } catch(const WrtDeviceApis::Commons::Exception& ex) {
983 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
988 JSValueRef JSFile::resolve(JSContextRef context,
990 JSObjectRef thisObject,
992 const JSValueRef argv[],
993 JSValueRef* exception)
995 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
996 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
997 if (!privateObject) {
998 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
1001 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_RESOLVE);
1003 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
1004 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::IO_ERROR, "IO error");
1007 Converter converter(context);
1011 ThrowMsg(InvalidArgumentException, "Invalid path name");
1014 IPathPtr path = converter.toPath(argv[0]);
1015 INodePtr node = privateObject->getObject()->getNode()->getChild(path);
1016 node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
1017 PrivateObjectDefPtr privDefData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
1018 privDefData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
1020 JSFile::PrivateObject* privData = new JSFile::PrivateObject(privateObject->getContext(), privDefData);
1021 privData->copyAceCheckAccessFunction(privateObject);
1022 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1024 JSObjectRef object = JSObjectMake(privateObject->getContext(), JSFile::getClassRef(), privData);
1026 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1027 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::IO_ERROR, ex.GetMessage());
1028 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1029 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
1030 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1031 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
1032 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1033 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage());
1034 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1035 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage());
1036 } catch(const WrtDeviceApis::Commons::Exception& ex) {
1037 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage());
1041 JSValueRef JSFile::deleteDirectory(JSContextRef context,
1043 JSObjectRef thisObject,
1045 const JSValueRef argv[],
1046 JSValueRef* exception)
1048 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1049 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
1050 if (!privateObject) {
1051 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
1055 TIZEN_CHECK_ACCESS(context, exception, privateObject,FILESYSTEM_FUNCTION_API_DELETE_DIR);
1058 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type missmatch error");
1061 JSContextRef globalContext = privateObject->getContext();
1065 // argument validation with new validator
1067 ArgumentValidator validator(context, argc, argv);
1068 validator.toFunction(2, true);
1069 validator.toFunction(3, true);
1071 catch (const BasePlatformException &err) {
1072 return JSWebAPIErrorFactory::postException(context, exception, err);
1074 DeviceAPI::Common::UnknownException err("");
1075 return JSWebAPIErrorFactory::postException(context, exception, err);
1079 JSValueRef reserveArguments[4];
1080 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
1083 for (index = 0; index < 4; index++) {
1085 reserveArguments[index] = argv[index];
1087 reserveArguments[index] = JSValueMakeUndefined(context);
1091 JSValueRef onSuccess = NULL;
1092 JSValueRef onError = NULL;
1094 onSuccess = getFunctionOrNull(globalContext, reserveArguments[2]);
1095 onError = getFunctionOrNull(globalContext, reserveArguments[3]);
1097 cbm->setOnSuccess(onSuccess);
1098 cbm->setOnError(onError);
1099 cbm->setObject(thisObject);
1101 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
1102 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context,
1103 JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "permission denied error"));
1104 return JSValueMakeUndefined(context);
1107 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
1108 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, "IO error"));
1109 return JSValueMakeUndefined(context);
1112 Converter converter(context);
1113 IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
1114 bool recursive = converter.toBool(reserveArguments[1]);
1117 if (privateObject->getObject()->getNode()->getPath()->getFullPath() != path->getPath()) {
1118 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "not found error in current directory"));
1119 return JSValueMakeUndefined(context);
1123 EventResolvePtr eventResolve(new EventResolve(path));
1124 if (eventResolve->setForSynchronousCall()) {
1125 IManager::getInstance().getNode(eventResolve);
1126 if (!eventResolve->getResult() || (eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
1128 if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException)
1129 ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Not found error");
1130 else if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException){
1131 ThrowMsg(WrtDeviceApis::Commons::SecurityException, "Permission denied error");
1134 ThrowMsg(PlatformException, "IO Error");
1137 if (eventResolve->getResult()->getType() != NT_DIRECTORY) {
1138 ThrowMsg(InvalidArgumentException, "Invalid directory");
1141 EventRemovePtr eventRemove(new EventRemove(path));
1144 eventRemove->setOptions(OPT_RECURSIVE);
1147 eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance());
1148 eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
1149 eventRemove->copyAceCheckAccessFunction(privateObject);
1151 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
1153 IManager::getInstance().remove(eventRemove);
1155 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1156 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, ex.GetMessage()));
1158 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1159 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
1160 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1161 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
1162 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1163 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
1164 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1165 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage()));
1166 } catch(const WrtDeviceApis::Commons::SecurityException& ex) {
1167 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
1168 }catch(const WrtDeviceApis::Commons::Exception& ex) {
1169 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
1171 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1172 return JSValueMakeUndefined(context);
1175 JSValueRef JSFile::deleteFile(JSContextRef context,
1177 JSObjectRef thisObject,
1179 const JSValueRef argv[],
1180 JSValueRef* exception)
1183 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
1185 PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
1188 if (!privateObject) {
1189 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, "Type mismatch error");
1192 TIZEN_CHECK_ACCESS(context, exception, privateObject, FILESYSTEM_FUNCTION_API_DELETE_FILE);
1194 // argument validation with new validator
1196 ArgumentValidator validator(context, argc, argv);
1197 validator.toFunction(1, true);
1198 validator.toFunction(2, true);
1200 catch (const BasePlatformException &err) {
1201 return JSWebAPIErrorFactory::postException(context, exception, err);
1203 DeviceAPI::Common::UnknownException err("");
1204 return JSWebAPIErrorFactory::postException(context, exception, err);
1207 JSContextRef globalContext = privateObject->getContext();
1210 JSValueRef reserveArguments[3];
1211 JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
1214 for (index = 0; index < 3; index++) {
1216 reserveArguments[index] = argv[index];
1218 reserveArguments[index] = JSValueMakeUndefined(context);
1221 JSValueRef onSuccess = NULL;
1222 JSValueRef onError = NULL;
1224 onSuccess = getFunctionOrNull(globalContext, reserveArguments[1]);
1225 onError = getFunctionOrNull(globalContext, reserveArguments[2]);
1227 cbm->setOnSuccess(onSuccess);
1228 cbm->setOnError(onError);
1229 cbm->setObject(thisObject);
1231 if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
1232 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context,
1233 JSWebAPIErrorFactory::INVALID_VALUES_ERROR, "permission denied error"));
1234 return JSValueMakeUndefined(context);
1237 if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
1238 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, "IO error"));
1239 return JSValueMakeUndefined(context);
1243 Converter converter(context);
1244 IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
1246 /*if (privateObject->getObject()->getNode()->getPath()->getFullPath() != path->getPath()) {
1247 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, "not found error in current directory"));
1248 return JSValueMakeUndefined(context);
1252 EventResolvePtr eventResolve(new EventResolve(path));
1253 if (eventResolve->setForSynchronousCall()) {
1254 IManager::getInstance().getNode(eventResolve);
1256 if (!eventResolve->getResult() ||(eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
1257 if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException){
1258 LoggerD("POST IO NOT_FOUND_ERROR");
1259 ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Not found error");
1261 if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException){
1262 ThrowMsg(WrtDeviceApis::Commons::SecurityException, "Permission denied error");
1265 LoggerD("POST IO ERROR");
1266 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, "IO error"));
1267 return JSValueMakeUndefined(context);
1270 if (eventResolve->getResult()->getType() != NT_FILE) {
1271 ThrowMsg(InvalidArgumentException, "Invalid directory");
1274 LoggerD("try to call async event");
1275 EventRemovePtr eventRemove(new EventRemove(path));
1276 eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance());
1277 eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
1278 eventRemove->copyAceCheckAccessFunction(privateObject);
1280 FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
1282 IManager::getInstance().remove(eventRemove);
1285 } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
1286 LoggerD("Platform Exception !!!!!!!! post io error");
1287 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::IO_ERROR, ex.GetMessage()));
1288 } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
1289 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, ex.GetMessage());
1290 } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
1291 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, ex.GetMessage());
1292 } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
1293 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
1294 } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
1295 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::NOT_FOUND_ERROR, ex.GetMessage()));
1296 } catch(const WrtDeviceApis::Commons::SecurityException& ex) {
1297 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, ex.GetMessage()));
1298 } catch(const WrtDeviceApis::Commons::Exception& ex) {
1299 cbm->callOnError(JSWebAPIErrorFactory::makeErrorObject(context, JSWebAPIErrorFactory::UNKNOWN_ERROR, ex.GetMessage()));
1303 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
1304 return JSValueMakeUndefined(context);