Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / file_system_custom_bindings.js
blob30a8aca48e2726a733d39f4ab179a3771ade8e95
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];
26 });
28 $Array.forEach(['getDisplayPath', 'getWritableEntry', 'isWritableEntry'],
29 bindFileEntryFunction);
31 $Array.forEach(['getWritableEntry', 'chooseEntry', 'restoreEntry'],
32 function(functionName) {
33 bindFileEntryCallback(functionName, apiFunctions);
34 });
36 apiFunctions.setHandleRequest('retainEntry', function(fileEntry) {
37 var id = entryIdManager.getEntryId(fileEntry);
38 if (!id)
39 return '';
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, {});
45 return id;
46 });
48 apiFunctions.setHandleRequest('isRestorable',
49 function(id, callback) {
50 var savedEntry = entryIdManager.getEntryById(id);
51 if (savedEntry) {
52 sendRequest.safeCallbackApply(
53 'fileSystem.isRestorable',
54 {},
55 callback,
56 [true]);
57 } else {
58 sendRequest.sendRequest(
59 this.name, [id, callback], this.definition.parameters, {});
61 });
63 apiFunctions.setUpdateArgumentsPostValidate('restoreEntry',
64 function(id, callback) {
65 var savedEntry = entryIdManager.getEntryById(id);
66 if (savedEntry) {
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',
71 {},
72 callback,
73 [savedEntry]);
74 return [id, false, null];
75 } else {
76 // Ask the browser process for a new file entry for this id, to be passed
77 // to |callback|.
78 return [id, true, callback];
80 });
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();