1 // Copyright (c) 2012 The Chromium Authors. 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.
5 // Custom binding for the fileSystem API.
7 var binding
= require('binding').Binding
.create('fileSystem');
8 var sendRequest
= require('sendRequest');
10 var getFileBindingsForApi
=
11 require('fileEntryBindingUtil').getFileBindingsForApi
;
12 var fileBindings
= getFileBindingsForApi('fileSystem');
13 var bindFileEntryCallback
= fileBindings
.bindFileEntryCallback
;
14 var entryIdManager
= fileBindings
.entryIdManager
;
16 binding
.registerCustomHook(function(bindingsAPI
) {
17 var apiFunctions
= bindingsAPI
.apiFunctions
;
18 var fileSystem
= bindingsAPI
.compiledApi
;
20 function bindFileEntryFunction(functionName
) {
21 apiFunctions
.setUpdateArgumentsPostValidate(
22 functionName
, function(fileEntry
, callback
) {
23 var fileSystemName
= fileEntry
.filesystem
.name
;
24 var relativePath
= $String
.slice(fileEntry
.fullPath
, 1);
25 return [fileSystemName
, relativePath
, callback
];
28 $Array
.forEach(['getDisplayPath', 'getWritableEntry', 'isWritableEntry'],
29 bindFileEntryFunction
);
31 $Array
.forEach(['getWritableEntry', 'chooseEntry', 'restoreEntry'],
32 function(functionName
) {
33 bindFileEntryCallback(functionName
, apiFunctions
);
36 apiFunctions
.setHandleRequest('retainEntry', function(fileEntry
) {
37 var id
= entryIdManager
.getEntryId(fileEntry
);
40 var fileSystemName
= fileEntry
.filesystem
.name
;
41 var relativePath
= $String
.slice(fileEntry
.fullPath
, 1);
43 sendRequest
.sendRequest(this.name
, [id
, fileSystemName
, relativePath
],
44 this.definition
.parameters
, {});
48 apiFunctions
.setHandleRequest('isRestorable',
49 function(id
, callback
) {
50 var savedEntry
= entryIdManager
.getEntryById(id
);
52 sendRequest
.safeCallbackApply(
53 'fileSystem.isRestorable',
58 sendRequest
.sendRequest(
59 this.name
, [id
, callback
], this.definition
.parameters
, {});
63 apiFunctions
.setUpdateArgumentsPostValidate('restoreEntry',
64 function(id
, callback
) {
65 var savedEntry
= entryIdManager
.getEntryById(id
);
67 // We already have a file entry for this id so pass it to the callback and
68 // send a request to the browser to move it to the back of the LRU.
69 sendRequest
.safeCallbackApply(
70 'fileSystem.restoreEntry',
74 return [id
, false, null];
76 // Ask the browser process for a new file entry for this id, to be passed
78 return [id
, true, callback
];
82 // TODO(benwells): Remove these deprecated versions of the functions.
83 fileSystem
.getWritableFileEntry = function() {
84 console
.log("chrome.fileSystem.getWritableFileEntry is deprecated");
85 console
.log("Please use chrome.fileSystem.getWritableEntry instead");
86 $Function
.apply(fileSystem
.getWritableEntry
, this, arguments
);
89 fileSystem
.isWritableFileEntry = function() {
90 console
.log("chrome.fileSystem.isWritableFileEntry is deprecated");
91 console
.log("Please use chrome.fileSystem.isWritableEntry instead");
92 $Function
.apply(fileSystem
.isWritableEntry
, this, arguments
);
95 fileSystem
.chooseFile = function() {
96 console
.log("chrome.fileSystem.chooseFile is deprecated");
97 console
.log("Please use chrome.fileSystem.chooseEntry instead");
98 $Function
.apply(fileSystem
.chooseEntry
, this, arguments
);
102 exports
.bindFileEntryCallback
= bindFileEntryCallback
;
103 exports
.binding
= binding
.generate();