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.
21 #include <CommonsJavaScript/JSUtils.h>
22 //#include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
25 #include "StorageProperties.h"
26 #include "JSStorage.h"
27 #include "Converter.h"
31 namespace Filesystem {
33 using namespace WrtDeviceApis;
34 using namespace WrtDeviceApis::Commons;
35 using namespace WrtDeviceApis::CommonsJavaScript;
38 const char* STR_STORAGE_LABEL = "label";
39 const char* STR_STORAGE_TYPE = "type";
40 const char* STR_STORAGE_STATE = "state";
41 /*const char* STR_TYPE_INTERNAL = "INTERNAL";
42 const char* STR_TYPE_EXTERNAL = "EXTERNAL";
43 const char* STR_STATE_MOUNTED = "MOUNTED";
44 const char* STR_STATE_REMOVED = "REMOVED";
45 const char* STR_STATE_UNMOUNTABLE = "UNMOUNTABLE";*/
48 JSClassDefinition JSStorage::m_classInfo = {
50 kJSClassAttributeNone,
60 NULL, //DeleteProperty,
61 NULL, //GetPropertyNames,
62 NULL, //CallAsFunction,
63 NULL, //CallAsConstructor,
68 JSStaticValue JSStorage::m_property[] = {
69 { STR_STORAGE_LABEL, getProperty, NULL, kJSPropertyAttributeReadOnly },
70 { STR_STORAGE_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
71 { STR_STORAGE_STATE, getProperty, NULL, kJSPropertyAttributeReadOnly },
72 /* { STR_TYPE_INTERNAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
73 { STR_TYPE_EXTERNAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
74 { STR_STATE_MOUNTED, getProperty, NULL, kJSPropertyAttributeReadOnly },
75 { STR_STATE_REMOVED, getProperty, NULL, kJSPropertyAttributeReadOnly },
76 { STR_STATE_UNMOUNTABLE, getProperty, NULL, kJSPropertyAttributeReadOnly },*/
80 const JSClassRef DLL_EXPORT JSStorage::getClassRef()
83 m_jsClassRef = JSClassCreate(&m_classInfo);
88 const JSClassDefinition* JSStorage::getClassInfo()
93 JSClassRef JSStorage::m_jsClassRef = JSClassCreate(
94 JSStorage::getClassInfo());
96 JSObjectRef JSStorage::createJSObject(JSContextRef context,
97 const StorageProperties &storages)
99 std::auto_ptr<StorageProperties> storageProps(new StorageProperties());
101 storageProps->setLabel(storages.getLabel());
102 storageProps->setType(storages.getType());
103 storageProps->setState(storages.getState());
105 JSStoragePriv *priv = new JSStoragePriv(context, storageProps.get());
106 storageProps.release();
108 ThrowMsg(Commons::NullPointerException, "Can not new an object");
110 return JSObjectMake(context, getClassRef(), priv);
113 void JSStorage::initialize(JSContextRef context,
118 void JSStorage::finalize(JSObjectRef object)
120 JSStoragePriv* priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
121 JSObjectSetPrivate(object, NULL);
125 JSValueRef JSStorage::getProperty(JSContextRef context,
127 JSStringRef propertyName,
128 JSValueRef* exception)
130 JSStoragePriv *priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
134 ThrowMsg(Commons::PlatformException, "Can not new an object");
136 StorageProperties *storages = priv->getObject();
137 Converter convert(context);
139 if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_LABEL)) {
140 return convert.toJSValueRef(storages->getLabel());
141 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_TYPE)) {
142 return convert.toStorageType(storages->getType());
143 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_STATE)) {
144 return convert.toStorageState(storages->getState());
146 /*else if (JSStringIsEqualToUTF8CString(propertyName, STR_TYPE_INTERNAL)) {
147 return convert.toJSValueRef(TYPE_INTERNAL);
148 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_TYPE_EXTERNAL)) {
149 return convert.toJSValueRef(TYPE_EXTERNAL);
150 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_MOUNTED)) {
151 return convert.toJSValueRef(STATE_MOUNTED);
152 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_REMOVED)) {
153 return convert.toJSValueRef(STATE_REMOVED);
154 } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_UNMOUNTABLE)) {
155 return convert.toJSValueRef(STATE_UNMOUNTABLE);
157 } Catch(Commons::Exception) {
158 LoggerW("trying to get incorrect value");
160 return JSValueMakeUndefined(context);
163 bool JSStorage::hasInstance(JSContextRef context,
164 JSObjectRef constructor,
165 JSValueRef possibleInstance,
166 JSValueRef* exception)
168 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());