#include <Tizen/Common/JSTizenExceptionFactory.h>
#include <Tizen/Common/JSTizenException.h>
#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <WidgetDB/WidgetDBMgr.h>
+#include <WidgetDB/IWidgetDB.h>
#include "JSFile.h"
#include "FilesystemUtils.h"
using namespace WrtDeviceApis::Commons;
using namespace WrtDeviceApis::CommonsJavaScript;
using namespace TizenApis::Commons;
+using namespace WrtDeviceApis;
+using namespace TizenApis::Api::Filesystem;
namespace {
{
if (Validator(ctx).isCallback(arg)) {
return arg;
- } else if (JSValueIsNull(ctx, arg) || JSValueIsUndefined(ctx, arg)) {
- ThrowMsg(InvalidArgumentException, "JS null passed as function.");
+ }else{
+ ThrowMsg(ConversionException, "JS null passed as function.");
}
- ThrowMsg(ConversionException, "Not a function nor JS null.");
}
}
if (!JSObjectSetPrivate(object, privateObject)) {
delete privateObject;
}
+ else {
+ int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+ WidgetDB::Api::IWidgetDBPtr widgetDB = WidgetDB::Api::getWidgetDB(widgetId);
+
+ LogDebug(widgetDB->getWidgetInstallationPath());
+ std::string wgtpackage = "wgt-package";
+ std::string wgtprivate = "wgt-private";
+ std::string wgtprivatetemp = "wgt-private-tmp";
+
+ Api::Filesystem::IManager::getInstance().addWidgetStorage(wgtpackage, widgetDB->getWidgetInstallationPath());
+ Api::Filesystem::IManager::getInstance().addWidgetStorage(wgtprivate, widgetDB->getWidgetPersistentStoragePath());
+ Api::Filesystem::IManager::getInstance().addWidgetStorage(wgtprivatetemp, widgetDB->getWidgetTemporaryStoragePath());
+
+ }
}
void JSFilesystemManager::finalize(JSObjectRef object)
JSContextRef globalContext = privateObject->getContext();
ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
try {
JSValueRef onSuccess = getFunction(globalContext, argv[1]);
JSValueRef onError = NULL;
- JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
- if (argc > 2) {
+ if (argc>2) {
onError = getFunctionOrNull(globalContext, argv[2]);
}
cbm->setOnSuccess(onSuccess);
cbm->setOnError(onError);
-
- if (JSValueIsNull(context, argv[0]) || JSValueIsUndefined(context, argv[0]) || !JSValueIsString(context, argv[0])) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
- }
Api::Filesystem::EventGetStoragePtr event(new Api::Filesystem::EventGetStorage());
event->setLabel(converter->toString(argv[0]));
event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
-
+ JSValueProtect(globalContext, thisObject);
Api::Filesystem::IManager::getInstance().getStorage(event);
} catch(const WrtDeviceApis::Commons::ConversionException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
} catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
} catch(const WrtDeviceApis::Commons::Exception& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
}
- return JSValueMakeNull(context);
+ return JSValueMakeUndefined(context);
}
JSValueRef JSFilesystemManager::getStorageList(JSContextRef context,
JSContextRef globalContext = privateObject->getContext();
ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
try {
JSValueRef onSuccess = getFunction(globalContext, argv[0]);
JSValueRef onError = NULL;
- JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
if (argc > 1) {
onError = getFunctionOrNull(globalContext, argv[1]);
Api::Filesystem::EventListStoragesPtr event(new Api::Filesystem::EventListStorages());
event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+ JSValueProtect(globalContext, thisObject);
+
+
Api::Filesystem::IManager::getInstance().listStorages(event);
} catch(const WrtDeviceApis::Commons::ConversionException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
} catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
} catch(const WrtDeviceApis::Commons::Exception& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
}
- return JSValueMakeNull(context);
+ return JSValueMakeUndefined(context);
}
JSValueRef JSFilesystemManager::addStorageStateListener(JSContextRef context,
}
if (argc < 1) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "TYPE_MISMATCH_ERROR");
}
JSContextRef globalContext = privateObject->getContext();
ConverterPtr converter = ConverterFactory::getConverter(globalContext);
try {
- if (JSValueIsNull(context, argv[0]) || JSValueIsUndefined(context, argv[0])) {
- cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error"));
- return JSValueMakeNull(context);
- } else if (!JSObjectIsFunction(context, converter->toJSObjectRef(argv[0]))) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+ JSValueRef onSuccess = getFunction(globalContext, argv[0]);
+ JSValueRef onError = NULL;
+ if (argc > 1) {
+ onError = getFunctionOrNull(globalContext, argv[1]);
}
- cbm->setOnSuccess(argv[0]);
+
+ cbm->setOnSuccess(onSuccess);
+ cbm->setOnError(onError);
Api::Filesystem::EventStorageStateChangedEmitterPtr emitter(new Api::Filesystem::EventStorageStateChangedEmitter);
emitter->setListener(&StorageStaticController::getInstance());
long id = Api::Filesystem::IManager::getInstance().addStorageStateChangeListener(emitter);
return converter->toJSValueRefLong(id);
} catch(const WrtDeviceApis::Commons::ConversionException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
} catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
} catch(const WrtDeviceApis::Commons::Exception& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
}
return JSValueMakeUndefined(context);
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
}
- if (!JSValueIsNumber(context, argv[0])) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
- }
-
JSContextRef globalContext = privateObject->getContext();
ConverterPtr converter = ConverterFactory::getConverter(globalContext);
try {
long id = static_cast<long>(converter->toLong(argv[0]));
+ LogDebug("id:" << id);
if (id >= 0) {
Api::Filesystem::IManager::getInstance().removeStorageStateChangeListener(id);
}
} catch(const WrtDeviceApis::Commons::ConversionException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
} catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+ } catch (const WrtDeviceApis::Commons::NotFoundException& ex) {
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::Exception& ex) {
const JSValueRef argv[],
JSValueRef* exception)
{
+
+ LogDebug("<<<");
+
PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
if (!privateObject) {
return JSValueMakeUndefined(context);
JSContextRef globalContext = privateObject->getContext();
ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+
+ size_t index = 0;
+ JSValueRef reserveArguments[4];
+ JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
- try {
- JSValueRef onSuccess = getFunction(globalContext, argv[1]);
- JSValueRef onError = NULL;
- JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
-
- if (argc > 2) {
- onError = getFunctionOrNull(globalContext, argv[2]);
+ try {
+ for (index = 0; index < 4; index++) {
+ if (index < argc)
+ reserveArguments[index] = argv[index];
+ else
+ reserveArguments[index] = JSValueMakeUndefined(context);
}
+ JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
+ JSValueRef onError = NULL;
+
+ onError = getFunctionOrNull(globalContext, reserveArguments[2]);
cbm->setOnSuccess(onSuccess);
cbm->setOnError(onError);
-
- Api::Filesystem::IPathPtr path = Utils::fromVirtualPath(globalContext, converter->toString(argv[0]));
- std::string virtualPath = converter->toString(argv[0]);
- int permissions = Api::Filesystem::PERM_READ;
+ Api::Filesystem::IPathPtr path;
+ std::string virtualPath;
+ path = Utils::fromVirtualPath(globalContext, converter->toString(reserveArguments[0]));
+ virtualPath = converter->toString(reserveArguments[0]);
+ LogDebug("virtualPath:[" << virtualPath << "]");
+ int permissions = Api::Filesystem::PERM_READ | Api::Filesystem::PERM_WRITE;
+
+
if (argc > 3) {
- if (!JSValueIsNull(context, argv[3]) && !JSValueIsUndefined(context, argv[3])) {
- std::string perms = converter->toString(argv[3]);
- if (("r" != perms) && ("rw" != perms) && ("w" != perms) && ("a" != perms)) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
- } else if ("r" == perms) {
- permissions = Api::Filesystem::PERM_READ;
- } else {
- permissions = Api::Filesystem::PERM_READ | Api::Filesystem::PERM_WRITE;
- }
-
+ std::string perms = converter->toString(reserveArguments[3]);
+ LogDebug("perms:[" << perms << "]");
+ if (("r" != perms) && ("rw" != perms) && ("w" != perms) && ("a" != perms)) {
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid permission");
+ } else if ("r" == perms) {
+ permissions = Api::Filesystem::PERM_READ;
}
}
+ if (permissions & Api::Filesystem::PERM_WRITE && virtualPath == "wgt-package") {
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "permission denied");
+ }
+
PermissionsAccessInfo perms(permissions, virtualPath);
AceSecurityStatus status = FILESYSTEM_PERMISSION_CHECK_ACCESS(
- privateObject->getContext(),
FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID,
perms);
Api::Filesystem::EventResolvePtr event(new Api::Filesystem::EventResolve(path));
event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (data));
+ JSValueProtect(globalContext, thisObject);
+
Api::Filesystem::IManager::getInstance().getNode(event);
} catch(const WrtDeviceApis::Commons::ConversionException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
} catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
} catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
} catch(const WrtDeviceApis::Commons::Exception& ex) {
- return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+ cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
}
- return JSValueMakeNull(context);
+ return JSValueMakeUndefined(context);
}
}
}