| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Custom binding for the fileSystem API. | 5 // Custom binding for the fileSystem API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('fileSystem'); | 7 var binding = require('binding').Binding.create('fileSystem'); |
| 8 var sendRequest = require('sendRequest'); | 8 var sendRequest = require('sendRequest'); |
| 9 | 9 |
| 10 var getFileBindingsForApi = | 10 var getFileBindingsForApi = |
| 11 require('fileEntryBindingUtil').getFileBindingsForApi; | 11 require('fileEntryBindingUtil').getFileBindingsForApi; |
| 12 var fileBindings = getFileBindingsForApi('fileSystem'); | 12 var fileBindings = getFileBindingsForApi('fileSystem'); |
| 13 var bindFileEntryCallback = fileBindings.bindFileEntryCallback; | 13 var bindFileEntryCallback = fileBindings.bindFileEntryCallback; |
| 14 var entryIdManager = fileBindings.entryIdManager; | 14 var entryIdManager = fileBindings.entryIdManager; |
| 15 var fileSystemNatives = requireNative('file_system_natives'); | 15 var fileSystemNatives = requireNative('file_system_natives'); |
| 16 var safeCallbackApply = require('uncaught_exception_handler').safeCallbackApply; |
| 16 | 17 |
| 17 binding.registerCustomHook(function(bindingsAPI) { | 18 binding.registerCustomHook(function(bindingsAPI) { |
| 18 var apiFunctions = bindingsAPI.apiFunctions; | 19 var apiFunctions = bindingsAPI.apiFunctions; |
| 19 var fileSystem = bindingsAPI.compiledApi; | 20 var fileSystem = bindingsAPI.compiledApi; |
| 20 | 21 |
| 21 function bindFileEntryFunction(functionName) { | 22 function bindFileEntryFunction(functionName) { |
| 22 apiFunctions.setUpdateArgumentsPostValidate( | 23 apiFunctions.setUpdateArgumentsPostValidate( |
| 23 functionName, function(fileEntry, callback) { | 24 functionName, function(fileEntry, callback) { |
| 24 var fileSystemName = fileEntry.filesystem.name; | 25 var fileSystemName = fileEntry.filesystem.name; |
| 25 var relativePath = $String.slice(fileEntry.fullPath, 1); | 26 var relativePath = $String.slice(fileEntry.fullPath, 1); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 | 44 |
| 44 sendRequest.sendRequest(this.name, [id, fileSystemName, relativePath], | 45 sendRequest.sendRequest(this.name, [id, fileSystemName, relativePath], |
| 45 this.definition.parameters); | 46 this.definition.parameters); |
| 46 return id; | 47 return id; |
| 47 }); | 48 }); |
| 48 | 49 |
| 49 apiFunctions.setHandleRequest('isRestorable', | 50 apiFunctions.setHandleRequest('isRestorable', |
| 50 function(id, callback) { | 51 function(id, callback) { |
| 51 var savedEntry = entryIdManager.getEntryById(id); | 52 var savedEntry = entryIdManager.getEntryById(id); |
| 52 if (savedEntry) { | 53 if (savedEntry) { |
| 53 sendRequest.safeCallbackApply( | 54 safeCallbackApply('fileSystem.isRestorable', {}, callback, [true]); |
| 54 'fileSystem.isRestorable', | |
| 55 {}, | |
| 56 callback, | |
| 57 [true]); | |
| 58 } else { | 55 } else { |
| 59 sendRequest.sendRequest( | 56 sendRequest.sendRequest( |
| 60 this.name, [id, callback], this.definition.parameters); | 57 this.name, [id, callback], this.definition.parameters); |
| 61 } | 58 } |
| 62 }); | 59 }); |
| 63 | 60 |
| 64 apiFunctions.setUpdateArgumentsPostValidate('restoreEntry', | 61 apiFunctions.setUpdateArgumentsPostValidate('restoreEntry', |
| 65 function(id, callback) { | 62 function(id, callback) { |
| 66 var savedEntry = entryIdManager.getEntryById(id); | 63 var savedEntry = entryIdManager.getEntryById(id); |
| 67 if (savedEntry) { | 64 if (savedEntry) { |
| 68 // We already have a file entry for this id so pass it to the callback and | 65 // We already have a file entry for this id so pass it to the callback and |
| 69 // send a request to the browser to move it to the back of the LRU. | 66 // send a request to the browser to move it to the back of the LRU. |
| 70 sendRequest.safeCallbackApply( | 67 safeCallbackApply('fileSystem.restoreEntry', {}, callback, [savedEntry]); |
| 71 'fileSystem.restoreEntry', | |
| 72 {}, | |
| 73 callback, | |
| 74 [savedEntry]); | |
| 75 return [id, false, null]; | 68 return [id, false, null]; |
| 76 } else { | 69 } else { |
| 77 // Ask the browser process for a new file entry for this id, to be passed | 70 // Ask the browser process for a new file entry for this id, to be passed |
| 78 // to |callback|. | 71 // to |callback|. |
| 79 return [id, true, callback]; | 72 return [id, true, callback]; |
| 80 } | 73 } |
| 81 }); | 74 }); |
| 82 | 75 |
| 83 apiFunctions.setCustomCallback('requestFileSystem', | 76 apiFunctions.setCustomCallback('requestFileSystem', |
| 84 function(name, request, callback, response) { | 77 function(name, request, callback, response) { |
| 85 var fileSystem; | 78 var fileSystem; |
| 86 if (response && response.file_system_id) { | 79 if (response && response.file_system_id) { |
| 87 fileSystem = fileSystemNatives.GetIsolatedFileSystem( | 80 fileSystem = fileSystemNatives.GetIsolatedFileSystem( |
| 88 response.file_system_id, response.file_system_path); | 81 response.file_system_id, response.file_system_path); |
| 89 } | 82 } |
| 90 sendRequest.safeCallbackApply( | 83 safeCallbackApply('fileSystem.requestFileSystem', request, callback, |
| 91 'fileSystem.requestFileSystem', | 84 [fileSystem]); |
| 92 request, | |
| 93 callback, | |
| 94 [fileSystem]); | |
| 95 }); | 85 }); |
| 96 | 86 |
| 97 // TODO(benwells): Remove these deprecated versions of the functions. | 87 // TODO(benwells): Remove these deprecated versions of the functions. |
| 98 fileSystem.getWritableFileEntry = function() { | 88 fileSystem.getWritableFileEntry = function() { |
| 99 console.log("chrome.fileSystem.getWritableFileEntry is deprecated"); | 89 console.log("chrome.fileSystem.getWritableFileEntry is deprecated"); |
| 100 console.log("Please use chrome.fileSystem.getWritableEntry instead"); | 90 console.log("Please use chrome.fileSystem.getWritableEntry instead"); |
| 101 $Function.apply(fileSystem.getWritableEntry, this, arguments); | 91 $Function.apply(fileSystem.getWritableEntry, this, arguments); |
| 102 }; | 92 }; |
| 103 | 93 |
| 104 fileSystem.isWritableFileEntry = function() { | 94 fileSystem.isWritableFileEntry = function() { |
| 105 console.log("chrome.fileSystem.isWritableFileEntry is deprecated"); | 95 console.log("chrome.fileSystem.isWritableFileEntry is deprecated"); |
| 106 console.log("Please use chrome.fileSystem.isWritableEntry instead"); | 96 console.log("Please use chrome.fileSystem.isWritableEntry instead"); |
| 107 $Function.apply(fileSystem.isWritableEntry, this, arguments); | 97 $Function.apply(fileSystem.isWritableEntry, this, arguments); |
| 108 }; | 98 }; |
| 109 | 99 |
| 110 fileSystem.chooseFile = function() { | 100 fileSystem.chooseFile = function() { |
| 111 console.log("chrome.fileSystem.chooseFile is deprecated"); | 101 console.log("chrome.fileSystem.chooseFile is deprecated"); |
| 112 console.log("Please use chrome.fileSystem.chooseEntry instead"); | 102 console.log("Please use chrome.fileSystem.chooseEntry instead"); |
| 113 $Function.apply(fileSystem.chooseEntry, this, arguments); | 103 $Function.apply(fileSystem.chooseEntry, this, arguments); |
| 114 }; | 104 }; |
| 115 }); | 105 }); |
| 116 | 106 |
| 117 exports.$set('bindFileEntryCallback', bindFileEntryCallback); | 107 exports.$set('bindFileEntryCallback', bindFileEntryCallback); |
| 118 exports.$set('binding', binding.generate()); | 108 exports.$set('binding', binding.generate()); |
| OLD | NEW |