[jslint] Enable js lint and fix the errors.
[platform/framework/web/tizen-extensions-crosswalk.git] / filesystem / filesystem_api.js
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var _callbacks = {};
6 var _next_reply_id = 0;
7
8 var _listeners = {};
9 var _next_listener_id = 0;
10
11 var getNextReplyId = function() {
12   return _next_reply_id++;
13 };
14
15 function defineReadOnlyProperty(object, key, value) {
16   Object.defineProperty(object, key, {
17     configurable: false,
18     writable: false,
19     value: value
20   });
21 }
22
23 var postMessage = function(msg, callback) {
24   var reply_id = getNextReplyId();
25   _callbacks[reply_id] = callback;
26   msg.reply_id = reply_id;
27   extension.postMessage(JSON.stringify(msg));
28 };
29
30 extension.setMessageListener(function(json) {
31   var msg = JSON.parse(json);
32   if (msg.cmd === 'storageChanged') {
33     handleStorageChanged(msg);
34   } else {
35     var reply_id = msg.reply_id;
36     var callback = _callbacks[reply_id];
37     if (typeof(callback) === 'function') {
38       callback(msg);
39       delete msg.reply_id;
40       delete _callbacks[reply_id];
41     } else {
42       console.log('Invalid reply_id from Tizen Filesystem: ' + reply_id);
43     }
44   }
45 });
46
47 var sendSyncMessage = function(msg, args) {
48   args = args || {};
49   args.cmd = msg;
50   return JSON.parse(extension.internal.sendSyncMessage(JSON.stringify(args)));
51 };
52
53 var FileSystemStorage = function(label, type, state) {
54   Object.defineProperties(this, {
55     'label': { writable: false, value: label, enumerable: true },
56     'type': { writable: false, value: type, enumerable: true },
57     'state': { writable: false, value: state, enumerable: true }
58   });
59 };
60
61 var getFileParent = function(childPath) {
62   if (childPath.search('/') < 0)
63     return null;
64
65   var parentPath = childPath.substr(0, childPath.lastIndexOf('/'));
66   return new File(parentPath, getFileParent(parentPath));
67 };
68
69 function is_string(value) { return typeof(value) === 'string' || value instanceof String; }
70 function is_integer(value) { return isFinite(value) && !isNaN(parseInt(value)); }
71 function get_valid_mode(mode) {
72   if (mode == null)
73     return 'rw';
74   else if (mode === 'a' || mode === 'w' || mode === 'r' || mode === 'rw')
75     return mode;
76   else
77     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
78 }
79
80 function FileSystemManager() {
81   Object.defineProperty(this, 'maxPathLength', {
82     get: function() {
83       var message = sendSyncMessage('FileSystemManagerGetMaxPathLength');
84       if (message.isError)
85         return 4096;
86       return message.value;
87     },
88     enumerable: true
89   });
90 }
91
92 FileSystemManager.prototype.resolve = function(location, onsuccess,
93     onerror, mode) {
94   if (!(onsuccess instanceof Function))
95     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
96   if (onerror !== null && !(onerror instanceof Function) &&
97       arguments.length > 2)
98     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
99
100   mode = get_valid_mode(mode);
101
102   postMessage({
103     cmd: 'FileSystemManagerResolve',
104     location: location,
105     mode: mode
106   }, function(result) {
107     if (result.isError)
108       onerror(new tizen.WebAPIException(result.errorCode));
109     else
110       onsuccess(new File(result.fullPath, getFileParent(result.fullPath)));
111   });
112 };
113
114 FileSystemManager.prototype.getStorage = function(label, onsuccess, onerror) {
115   if (!(onsuccess instanceof Function))
116     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
117   if (onerror !== null && !(onerror instanceof Function) &&
118       arguments.length > 2)
119     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
120
121   postMessage({
122     cmd: 'FileSystemManagerGetStorage',
123     label: label
124   }, function(result) {
125     if (result.isError)
126       onerror(new tizen.WebAPIError(result.errorCode));
127     else
128       onsuccess(new FileSystemStorage(result.label, result.type, result.state));
129   });
130 };
131
132 FileSystemManager.prototype.listStorages = function(onsuccess, onerror) {
133   if (!(onsuccess instanceof Function))
134     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
135   if (onerror !== null && !(onerror instanceof Function) &&
136       arguments.length > 1)
137     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
138
139   postMessage({
140     cmd: 'FileSystemManagerListStorages'
141   }, function(result) {
142     if (result.isError)
143       onerror(new tizen.WebAPIError(result.errorCode));
144     else {
145       var storages = [];
146       for (var i = 0; i < result.value.length; i++) {
147         var storage = result.value[i];
148         storages.push(new FileSystemStorage(storage.label, storage.type, storage.state));
149       }
150       onsuccess(storages);
151     }
152   });
153 };
154
155 function handleStorageChanged(msg) {
156   var storage = msg.storage;
157   _listeners.forEach(function(id) {
158     _listeners[id](new FileSystemStorage(storage.label, storage.type, storage.state));
159   });
160 }
161
162 FileSystemManager.prototype.addStorageStateChangeListener = function(onsuccess, onerror) {
163   if (!(onsuccess instanceof Function))
164     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
165   if (onerror !== null && !(onerror instanceof Function) &&
166       arguments.length > 1)
167     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
168
169   _listeners[_next_listener_id] = onsuccess;
170   return _next_listener_id++;
171 };
172
173 FileSystemManager.prototype.removeStorageStateChangeListener = function(watchId) {
174   if (!(typeof(watchId) !== 'number'))
175     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
176
177   var index = _listeners.indexOf(watchId);
178   if (~index)
179     _listeners.slice(index, 1);
180   else
181     throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
182 };
183
184 function FileFilter(name, startModified, endModified, startCreated, endCreated) {
185   var self = {
186     toString: function() {
187       return JSON.stringify(this);
188     }
189   };
190   Object.defineProperties(self, {
191     'name': { writable: false, value: name, enumerable: true },
192     'startModified': { writable: false, value: startModified, enumerable: true },
193     'endModified': { writable: false, value: endModified, enumerable: true },
194     'startCreated': { writable: false, value: startCreated, enumerable: true },
195     'endCreated': { writable: false, value: endCreated, enumerable: true }
196   });
197   return self;
198 }
199
200 function FileStream(streamID, encoding) {
201   this.streamID = streamID;
202   this.encoding = encoding || 'UTF-8';
203
204   function fs_stat(streamID) {
205     var result = sendSyncMessage('FileStreamStat', { streamID: streamID });
206     if (result.isError)
207       return result;
208     return result.value;
209   }
210
211   var getStreamID = function() {
212     return streamID;
213   };
214   var getEncoding = function() {
215     return encoding;
216   };
217   var isEof = function() {
218     var status = fs_stat(streamID);
219     if (status.isError)
220       return true;
221     return status.eof;
222   };
223   var getPosition = function() {
224     var status = fs_stat(streamID);
225     if (status.isError)
226       return -1;
227     return status.position;
228   };
229   var setPosition = function(position) {
230     if (!(is_integer(position)))
231       return;
232
233     var result = sendSyncMessage('FileStreamSetPosition',
234                                  { streamID: this.streamID,
235                                    position: position });
236     if (result.isError)
237       throw new tizen.WebAPIException(result.errorCode);
238   };
239   var getBytesAvailable = function() {
240     var status = fs_stat(streamID);
241     if (status.isError)
242       return -1;
243     return status.bytesAvailable;
244   };
245
246   defineReadOnlyProperty(this, 'eof', false);
247   defineReadOnlyProperty(this, 'bytesAvailable', 0);
248
249   Object.defineProperties(this, {
250     'streamID': { get: getStreamID, enumerable: false },
251     'encoding': { get: getEncoding, enumerable: false },
252     'position': { get: getPosition, set: setPosition, enumerable: true }
253   });
254 }
255
256 FileStream.prototype.close = function() {
257   sendSyncMessage('FileStreamClose', {
258     streamID: this.streamID
259   });
260 };
261
262 FileStream.prototype.read = function(charCount) {
263   if (arguments.length == 1 && !(is_integer(charCount)))
264     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
265
266   var result = sendSyncMessage('FileStreamRead', {
267     streamID: this.streamID,
268     encoding: this.encoding,
269     type: 'Default',
270     count: charCount
271   });
272   if (result.isError)
273     throw new tizen.WebAPIException(result.errorCode);
274   else
275     return result.value;
276 };
277
278 FileStream.prototype.readBytes = function(byteCount) {
279   if (arguments.length == 1 && !(is_integer(byteCount)))
280     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
281
282   var result = sendSyncMessage('FileStreamRead', {
283     streamID: this.streamID,
284     encoding: this.encoding,
285     type: 'Bytes',
286     count: byteCount
287   });
288   if (result.isError)
289     throw new tizen.WebAPIException(result.errorCode);
290   else
291     return result.value;
292 };
293
294 FileStream.prototype.readBase64 = function(byteCount) {
295   if (arguments.length == 1 && !(is_integer(byteCount)))
296     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
297
298   var result = sendSyncMessage('FileStreamRead', {
299     streamID: this.streamID,
300     encoding: this.encoding,
301     type: 'Base64',
302     count: byteCount
303   });
304   if (result.isError)
305     throw new tizen.WebAPIException(result.errorCode);
306   else
307     return result.value;
308 };
309
310 FileStream.prototype.write = function(stringData) {
311   if (!(is_string(stringData)))
312     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
313
314   var result = sendSyncMessage('FileStreamWrite', {
315     streamID: this.streamID,
316     encoding: this.encoding,
317     type: 'Default',
318     data: stringData
319   });
320   if (result.isError)
321     throw new tizen.WebAPIException(result.errorCode);
322 };
323
324 FileStream.prototype.writeBytes = function(byteData) {
325   if (!Array.isArray(byteData))
326     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
327
328   var result = sendSyncMessage('FileStreamWrite', {
329     streamID: this.streamID,
330     encoding: this.encoding,
331     type: 'Bytes',
332     data: byteData
333   });
334   if (result.isError)
335     throw new tizen.WebAPIException(result.errorCode);
336 };
337
338 FileStream.prototype.writeBase64 = function(base64Data) {
339   if (!(is_string(base64Data)))
340     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
341
342   var result = sendSyncMessage('FileStreamWrite', {
343     streamID: this.streamID,
344     encoding: this.encoding,
345     type: 'Base64',
346     data: base64Data
347   });
348   if (result.isError)
349     throw new tizen.WebAPIException(result.errorCode);
350 };
351
352 function File(fullPath, parent) {
353   this.fullPath = fullPath;
354   this.parent = parent;
355
356   var stat_cached = undefined;
357   var stat_last_time = undefined;
358
359   function stat() {
360     var now = Date.now();
361     if (stat_cached === undefined || (now - stat_last_time) > 5) {
362       var result = sendSyncMessage('FileStat', { fullPath: fullPath });
363       if (result.isError)
364         return result;
365
366       stat_cached = result;
367       stat_last_time = now;
368       result.value.isError = result.isError;
369       return result.value;
370     }
371     return stat_cached.value;
372   }
373
374   var getParent = function() {
375     return parent;
376   };
377   var getReadOnly = function() {
378     var status = stat();
379     if (status.isError)
380       return true;
381     return status.readOnly;
382   };
383   var getIsFile = function() {
384     var status = stat();
385     if (status.isError)
386       return false;
387     return status.isFile;
388   };
389   var getIsDirectory = function() {
390     var status = stat();
391     if (status.isError)
392       return false;
393     return status.isDirectory;
394   };
395   var getCreatedDate = function() {
396     var status = stat();
397     if (status.isError)
398       return null;
399     return new Date(status.created * 1000);
400   };
401   var getModifiedDate = function() {
402     var status = stat();
403     if (status.isError)
404       return null;
405     return new Date(status.modified * 1000);
406   };
407   var getPath = function() {
408     var lastSlashIndex = fullPath.lastIndexOf('/');
409     if (lastSlashIndex < 0)
410       return fullPath;
411     return fullPath.slice(0, lastSlashIndex + 1);
412   };
413   var getName = function() {
414     var lastSlashIndex = fullPath.lastIndexOf('/');
415     if (lastSlashIndex < 0)
416       return '';
417     return fullPath.substr(lastSlashIndex + 1);
418   };
419   var getFullPath = function() {
420     return fullPath;
421   };
422   var getFileSize = function() {
423     var status = stat();
424     if (status.isError)
425       return 0;
426     if (status.isDirectory)
427       return undefined;
428     return status.size;
429   };
430   var getLength = function() {
431     var status = stat();
432     if (status.isError)
433       return 0;
434     if (status.isDirectory)
435       return status.length;
436     return undefined;
437   };
438
439   Object.defineProperties(this, {
440     'parent': { get: getParent, enumerable: true },
441     'readOnly': { get: getReadOnly, enumerable: true },
442     'isFile': { get: getIsFile, enumerable: true },
443     'isDirectory': { get: getIsDirectory, enumerable: true },
444     'created': { get: getCreatedDate, enumerable: true },
445     'modified': { get: getModifiedDate, enumerable: true },
446     'path': { get: getPath, enumerable: true },
447     'name': { get: getName, enumerable: true },
448     'fullPath': { get: getFullPath, enumerable: true },
449     'fileSize': { get: getFileSize, enumerable: true },
450     'length': { get: getLength, enumerable: true }
451   });
452 }
453
454 File.prototype.toURI = function() {
455   var status = sendSyncMessage('FileGetURI', { fullPath: this.fullPath });
456
457   if (status.isError)
458     return '';
459   return status.value;
460 };
461
462 File.prototype.listFiles = function(onsuccess, onerror, filter) {
463   if (!(onsuccess instanceof Function))
464     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
465   if (onerror !== null && !(onerror instanceof Function) &&
466       arguments.length > 1)
467     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
468   if (filter !== null && !(filter instanceof FileFilter) &&
469       arguments.length > 2)
470     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
471
472   postMessage({
473     cmd: 'FileListFiles',
474     fullPath: this.fullPath,
475     filter: filter ? filter.toString() : ''
476   }, function(result) {
477     if (result.isError) {
478       if (onerror)
479         onerror(new tizen.WebAPIError(result.errorCode));
480     } else if (onsuccess) {
481       var file_list = [];
482
483       for (var i = 0; i < result.value.length; i++)
484         file_list.push(new File(result.value[i], getFileParent(result.value[i])));
485
486       onsuccess(file_list);
487     }
488   }.bind(this));
489 };
490
491 File.prototype.openStream = function(mode, onsuccess, onerror, encoding) {
492   if (!(onsuccess instanceof Function))
493     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
494   if (onerror !== null && !(onerror instanceof Function) &&
495       arguments.length > 2)
496     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
497
498   mode = get_valid_mode(mode);
499
500   if ((arguments.length > 3 && is_string(encoding)) &&
501       (encoding != 'UTF-8' && encoding != 'ISO-8859-1'))
502     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
503
504   postMessage({
505     cmd: 'FileOpenStream',
506     fullPath: this.fullPath,
507     mode: mode,
508     encoding: encoding
509   }, function(result) {
510     if (result.isError) {
511       if (onerror)
512         onerror(new tizen.WebAPIError(result.errorCode));
513     } else if (onsuccess) {
514       onsuccess(new FileStream(result.streamID, result.encoding));
515     }
516   });
517 };
518
519 File.prototype.readAsText = function(onsuccess, onerror, encoding) {
520   if (!(onsuccess instanceof Function))
521     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
522   if (onerror !== null && !(onerror instanceof Function) &&
523       arguments.length > 1)
524     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
525
526   if ((arguments.length > 2 && is_string(encoding)) &&
527       (encoding != 'UTF-8' && encoding != 'ISO-8859-1'))
528     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
529
530   var streamOpened = function(stream) {
531     onsuccess(stream.read());
532     stream.close();
533   };
534   var streamError = function(error) {
535     if (onerror)
536       onerror(error);
537   };
538
539   if (this.isDirectory) {
540     streamError(new tizen.WebAPIException(tizen.WebAPIException.IO_ERR));
541     return;
542   }
543
544   this.openStream('r', streamOpened, streamError, encoding);
545 };
546
547 File.prototype.copyTo = function(originFilePath, destinationFilePath,
548     overwrite, onsuccess, onerror) {
549   // originFilePath, destinationFilePath - full virtual file path
550   if (onsuccess !== null && !(onsuccess instanceof Function) &&
551       arguments.length > 3)
552     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
553   if (onerror !== null && !(onerror instanceof Function) &&
554       arguments.length > 4)
555     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
556
557   if (!is_string(originFilePath) || !is_string(destinationFilePath)) {
558     onerror(new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR));
559     return;
560   }
561
562   if (originFilePath.indexOf('./') >= 0 || destinationFilePath.indexOf('./') >= 0) {
563     onerror(new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR));
564     return;
565   }
566
567   if (originFilePath.indexOf(this.fullPath) < 0) {
568     onerror(new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR));
569     return;
570   }
571
572   postMessage({
573     cmd: 'FileCopyTo',
574     originFilePath: originFilePath,
575     destinationFilePath: destinationFilePath,
576     overwrite: overwrite
577   }, function(result) {
578     if (result.isError) {
579       if (onerror) {
580         onerror(new tizen.WebAPIException(result.errorCode));
581       }
582     } else if (onsuccess) {
583       onsuccess();
584     }
585   });
586 };
587
588 File.prototype.moveTo = function(originFilePath, destinationFilePath,
589     overwrite, onsuccess, onerror) {
590   // originFilePath, destinationFilePath - full virtual file path
591   if (onsuccess !== null && !(onsuccess instanceof Function) &&
592       arguments.length > 3)
593     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
594   if (onerror !== null && !(onerror instanceof Function) &&
595       arguments.length > 4)
596     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
597
598   if (!is_string(originFilePath) || !is_string(destinationFilePath)) {
599     onerror(new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR));
600     return;
601   }
602
603   if (originFilePath.indexOf('./') >= 0 || destinationFilePath.indexOf('./') >= 0) {
604     onerror(new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR));
605     return;
606   }
607
608   if (originFilePath.indexOf(this.fullPath) < 0) {
609     onerror(new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR));
610     return;
611   }
612
613   postMessage({
614     cmd: 'FileMoveTo',
615     originFilePath: originFilePath,
616     destinationFilePath: destinationFilePath,
617     overwrite: overwrite
618   }, function(result) {
619     if (result.isError) {
620       if (onerror) {
621         onerror(new tizen.WebAPIException(result.errorCode));
622       }
623     } else if (onsuccess) {
624       onsuccess();
625     }
626   });
627 };
628
629 File.prototype.createDirectory = function(relativeDirPath) {
630   if (relativeDirPath.indexOf('./') >= 0)
631     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
632
633   var status = sendSyncMessage('FileCreateDirectory', {
634     fullPath: this.fullPath,
635     relativeDirPath: relativeDirPath
636   });
637
638   if (status.isError)
639     throw new tizen.WebAPIException(status.errorCode);
640   else
641     return new File(status.value, getFileParent(status.value));
642 };
643
644 File.prototype.createFile = function(relativeFilePath) {
645   if (relativeFilePath.indexOf('./') >= 0)
646     throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
647
648   var status = sendSyncMessage('FileCreateFile', {
649     fullPath: this.fullPath,
650     relativeFilePath: relativeFilePath
651   });
652
653   if (status.isError)
654     throw new tizen.WebAPIException(status.errorCode);
655   else
656     return new File(status.value, getFileParent(status.value));
657 };
658
659 File.prototype.resolve = function(relativeFilePath) {
660   var status = sendSyncMessage('FileResolve', {
661     fullPath: this.fullPath,
662     relativeFilePath: relativeFilePath
663   });
664
665   if (status.isError)
666     throw new tizen.WebAPIException(status.errorCode);
667
668   return new File(status.value, getFileParent(status.value));
669 };
670
671 File.prototype.deleteDirectory = function(directoryPath, recursive, onsuccess, onerror) {
672   // directoryPath - full virtual directory path
673   if (onsuccess !== null && !(onsuccess instanceof Function) &&
674       arguments.length > 2)
675     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
676   if (onerror !== null && !(onerror instanceof Function) &&
677       arguments.length > 3)
678     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
679
680   if (directoryPath.indexOf(this.fullPath) < 0 && onerror) {
681     onerror(new tizen.WebAPIError(tizen.WebAPIException.NOT_FOUND_ERR));
682     return;
683   }
684
685   postMessage({
686     cmd: 'FileDeleteDirectory',
687     directoryPath: directoryPath,
688     recursive: !!recursive
689   }, function(result) {
690     if (result.isError) {
691       if (onerror)
692         onerror(new tizen.WebAPIError(result.errorCode));
693     } else if (onsuccess) {
694       onsuccess();
695     }
696   });
697 };
698
699 File.prototype.deleteFile = function(filePath, onsuccess, onerror) {
700   // filePath - full virtual file path
701   if (onsuccess !== null && !(onsuccess instanceof Function) &&
702       arguments.length > 1)
703     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
704   if (onerror !== null && !(onerror instanceof Function) &&
705       arguments.length > 2)
706     throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
707
708   if (filePath.indexOf(this.fullPath) < 0 && onerror) {
709     onerror(new tizen.WebAPIError(tizen.WebAPIException.NOT_FOUND_ERR));
710     return;
711   }
712
713   postMessage({
714     cmd: 'FileDeleteFile',
715     filePath: filePath
716   }, function(result) {
717     if (result.isError) {
718       if (onerror)
719         onerror(new tizen.WebAPIError(result.errorCode));
720     } else if (onsuccess) {
721       onsuccess();
722     }
723   });
724 };
725
726 (function() {
727   exports = new FileSystemManager();
728 })();