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.
19 #ifndef TIZENAPIS_TIZEN_JSFILE_H_
20 #define TIZENAPIS_TIZEN_JSFILE_H_
22 #include <JavaScriptCore/JavaScript.h>
23 #include <Commons/IEvent.h>
24 #include <CommonsJavaScript/PrivateObject.h>
25 #include <CommonsJavaScript/JSCallbackManager.h>
29 namespace Filesystem {
34 class PrivateObjectDef
38 typedef std::vector<int> PermissionList;
40 PrivateObjectDef(const INodePtr &node,
41 const PermissionList &parentPermissions) :
43 m_parentPerms(parentPermissions)
47 virtual ~PrivateObjectDef()
51 INodePtr getNode() const
56 PermissionList getParentPermissions() const
61 void setParentPermissions(const PermissionList &permissions)
63 m_parentPerms = permissions;
66 void pushParentPermissions(int permissions)
68 m_parentPerms.push_back(permissions);
73 PermissionList m_parentPerms;
76 class ListFilesPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
80 const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr &callbackManager,
81 const PrivateObjectDef::PermissionList parentPermissions) :
82 m_callbackManager(callbackManager),
83 m_parentPermissions(parentPermissions)
87 virtual ~ListFilesPrivateData()
91 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager() const
93 return m_callbackManager;
96 PrivateObjectDef::PermissionList getParentPermissions() const
98 return m_parentPermissions;
102 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager;
103 PrivateObjectDef::PermissionList m_parentPermissions;
106 typedef DPL::SharedPtr<ListFilesPrivateData> ListFilesPrivateDataPtr;
107 typedef DPL::SharedPtr<PrivateObjectDef> PrivateObjectDefPtr;
108 typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<PrivateObjectDefPtr>::Type PrivateObject;
111 static const JSClassDefinition* getClassInfo();
113 static const JSClassRef getClassRef();
118 * The callback invoked when an object is first created.
120 static void initialize(JSContextRef context,
124 * The callback invoked when an object is finalized.
126 static void finalize(JSObjectRef object);
129 * The callback invoked when getting a property's value.
131 static JSValueRef getProperty(JSContextRef context,
133 JSStringRef propertyName,
134 JSValueRef* exception);
137 * The callback invoked when collecting the names of an object's properties.
139 static void getPropertyNames(JSContextRef context,
141 JSPropertyNameAccumulatorRef propertyNames);
144 * The callback invoked when an object is used as the target of an 'instanceof' expression.
146 static bool hasInstance(JSContextRef context,
147 JSObjectRef constructor,
148 JSValueRef possibleInstance,
149 JSValueRef* exception);
152 * Returns a URI for the file.
154 static JSValueRef toUri(JSContextRef context,
156 JSObjectRef thisObject,
157 size_t argumentCount,
158 const JSValueRef arguments[],
159 JSValueRef* exception);
162 * Returns list of all files of this directory.
164 static JSValueRef listFiles(JSContextRef context,
166 JSObjectRef thisObject,
167 size_t argumentCount,
168 const JSValueRef arguments[],
169 JSValueRef* exception);
172 * WRT_GeneralError exception
174 static JSValueRef openStream(JSContextRef context,
176 JSObjectRef thisObject,
177 size_t argumentCount,
178 const JSValueRef arguments[],
179 JSValueRef* exception);
182 * WRT_GeneralError exception
184 static JSValueRef readAsText(JSContextRef context,
186 JSObjectRef thisObject,
187 size_t argumentCount,
188 const JSValueRef arguments[],
189 JSValueRef* exception);
192 * The operation is only for file except for directory.
193 * Make sure the dest directory already exists.
195 static JSValueRef copyTo(JSContextRef context,
197 JSObjectRef thisObject,
198 size_t argumentCount,
199 const JSValueRef arguments[],
200 JSValueRef* exception);
203 * This operation is only for file not directory
204 * The dest directory should exists in local file system, or the operation fails.
206 static JSValueRef moveTo(JSContextRef context,
208 JSObjectRef thisObject,
209 size_t argumentCount,
210 const JSValueRef arguments[],
211 JSValueRef* exception);
214 * create directory even through the parent directories do not exist in local file system.
216 static JSValueRef createDirectory(JSContextRef context,
218 JSObjectRef thisObject,
219 size_t argumentCount,
220 const JSValueRef arguments[],
221 JSValueRef* exception);
224 * Creates a new empty file in a specified location.
226 static JSValueRef createFile(JSContextRef context,
228 JSObjectRef thisObject,
229 size_t argumentCount,
230 const JSValueRef arguments[],
231 JSValueRef* exception);
234 * Resolves an existing file or directory relative to
235 * the current directory this operation is performed on; and
236 * returns a file handle for it.
238 static JSValueRef resolve(JSContextRef context,
240 JSObjectRef thisObject,
241 size_t argumentCount,
242 const JSValueRef arguments[],
243 JSValueRef* exception);
246 * Removes all files from specified directory if recursive is true,
247 * or just remove the directory itself when there is no files or directories underneath it
249 static JSValueRef deleteDirectory(JSContextRef context,
251 JSObjectRef thisObject,
252 size_t argumentCount,
253 const JSValueRef arguments[],
254 JSValueRef* exception);
257 * Deletes a specified file.
259 static JSValueRef deleteFile(JSContextRef context,
261 JSObjectRef thisObject,
262 size_t argumentCount,
263 const JSValueRef arguments[],
264 JSValueRef* exception);
267 * This structure describes a statically declared function property.
269 static JSStaticFunction m_functions[];
272 * This structure describes a statically declared value property.
274 static JSStaticValue m_properties[];
277 * This structure contains properties and callbacks that define a type of object.
279 static JSClassDefinition m_classInfo;
281 static JSClassRef m_classRef;