| 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 | 8 |
| 9 var entryIdManager = require('entryIdManager'); |
| 9 var fileSystemNatives = requireNative('file_system_natives'); | 10 var fileSystemNatives = requireNative('file_system_natives'); |
| 11 var forEach = require('utils').forEach; |
| 10 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; | 12 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; |
| 11 var lastError = require('lastError'); | 13 var lastError = require('lastError'); |
| 12 var entryIdManager = require('entryIdManager'); | |
| 13 | 14 |
| 14 binding.registerCustomHook(function(bindingsAPI) { | 15 binding.registerCustomHook(function(bindingsAPI) { |
| 15 var apiFunctions = bindingsAPI.apiFunctions; | 16 var apiFunctions = bindingsAPI.apiFunctions; |
| 16 var fileSystem = bindingsAPI.compiledApi; | 17 var fileSystem = bindingsAPI.compiledApi; |
| 17 | 18 |
| 18 function bindFileEntryFunction(functionName) { | 19 function bindFileEntryFunction(i, functionName) { |
| 19 apiFunctions.setUpdateArgumentsPostValidate( | 20 apiFunctions.setUpdateArgumentsPostValidate( |
| 20 functionName, function(fileEntry, callback) { | 21 functionName, function(fileEntry, callback) { |
| 21 var fileSystemName = fileEntry.filesystem.name; | 22 var fileSystemName = fileEntry.filesystem.name; |
| 22 var relativePath = fileEntry.fullPath.slice(1); | 23 var relativePath = fileEntry.fullPath.slice(1); |
| 23 return [fileSystemName, relativePath, callback]; | 24 return [fileSystemName, relativePath, callback]; |
| 24 }); | 25 }); |
| 25 } | 26 } |
| 26 ['getDisplayPath', 'getWritableEntry', 'isWritableEntry'] | 27 forEach(['getDisplayPath', 'getWritableEntry', 'isWritableEntry'], |
| 27 .forEach(bindFileEntryFunction); | 28 bindFileEntryFunction); |
| 28 | 29 |
| 29 function bindFileEntryCallback(functionName) { | 30 function bindFileEntryCallback(i, functionName) { |
| 30 apiFunctions.setCustomCallback(functionName, | 31 apiFunctions.setCustomCallback(functionName, |
| 31 function(name, request, response) { | 32 function(name, request, response) { |
| 32 if (request.callback && response) { | 33 if (request.callback && response) { |
| 33 var callback = request.callback; | 34 var callback = request.callback; |
| 34 request.callback = null; | 35 request.callback = null; |
| 35 | 36 |
| 36 var fileSystemId = response.fileSystemId; | 37 var fileSystemId = response.fileSystemId; |
| 37 var baseName = response.baseName; | 38 var baseName = response.baseName; |
| 38 // TODO(koz): Generate a persistent id in the browser and use it here. | 39 // TODO(koz): Generate a persistent id in the browser and use it here. |
| 39 var id = fileSystemId + ":" + baseName; | 40 var id = fileSystemId + ":" + baseName; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 lastError.run('Error getting fileEntry, code: ' + fileError.code, | 51 lastError.run('Error getting fileEntry, code: ' + fileError.code, |
| 51 callback); | 52 callback); |
| 52 }); | 53 }); |
| 53 } catch (e) { | 54 } catch (e) { |
| 54 lastError.run('Error in event handler for onLaunched: ' + e.stack, | 55 lastError.run('Error in event handler for onLaunched: ' + e.stack, |
| 55 callback); | 56 callback); |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 }); | 59 }); |
| 59 } | 60 } |
| 60 ['getWritableEntry', 'chooseEntry'].forEach(bindFileEntryCallback); | 61 forEach(['getWritableEntry', 'chooseEntry'], bindFileEntryCallback); |
| 61 | 62 |
| 62 apiFunctions.setHandleRequest('getEntryId', function(fileEntry) { | 63 apiFunctions.setHandleRequest('getEntryId', function(fileEntry) { |
| 63 return entryIdManager.getEntryId(fileEntry); | 64 return entryIdManager.getEntryId(fileEntry); |
| 64 }); | 65 }); |
| 65 | 66 |
| 66 apiFunctions.setHandleRequest('getEntryById', function(id) { | 67 apiFunctions.setHandleRequest('getEntryById', function(id) { |
| 67 return entryIdManager.getEntryById(id); | 68 return entryIdManager.getEntryById(id); |
| 68 }); | 69 }); |
| 69 | 70 |
| 70 // TODO(benwells): Remove these deprecated versions of the functions. | 71 // TODO(benwells): Remove these deprecated versions of the functions. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 fileSystem.chooseFile = function() { | 84 fileSystem.chooseFile = function() { |
| 84 console.log("chrome.fileSystem.chooseFile is deprecated"); | 85 console.log("chrome.fileSystem.chooseFile is deprecated"); |
| 85 console.log("Please use chrome.fileSystem.chooseEntry instead"); | 86 console.log("Please use chrome.fileSystem.chooseEntry instead"); |
| 86 fileSystem.chooseEntry.apply(this, arguments); | 87 fileSystem.chooseEntry.apply(this, arguments); |
| 87 }; | 88 }; |
| 88 }); | 89 }); |
| 89 | 90 |
| 90 exports.binding = binding.generate(); | 91 exports.binding = binding.generate(); |
| OLD | NEW |