| 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 bindings for the fileSystem API. | 5 // Custom bindings for the fileSystem API. |
| 6 | 6 |
| 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 8 var fileSystemNatives = requireNative('file_system_natives'); | 8 var fileSystemNatives = requireNative('file_system_natives'); |
| 9 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; | 9 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; |
| 10 var lastError = require('lastError'); | 10 var lastError = require('lastError'); |
| 11 | 11 |
| 12 chromeHidden.registerCustomHook('fileSystem', function(bindingsAPI) { | 12 chromeHidden.registerCustomHook('fileSystem', function(bindingsAPI) { |
| 13 var apiFunctions = bindingsAPI.apiFunctions; | 13 var apiFunctions = bindingsAPI.apiFunctions; |
| 14 function bindFileEntryFunction(functionName) { | 14 function bindFileEntryFunction(functionName) { |
| 15 apiFunctions.setUpdateArgumentsPostValidate( | 15 apiFunctions.setUpdateArgumentsPostValidate( |
| 16 functionName, function(fileEntry, callback) { | 16 functionName, function(fileEntry, callback) { |
| 17 var fileSystemName = fileEntry.filesystem.name; | 17 var fileSystemName = fileEntry.filesystem.name; |
| 18 var relativePath = fileEntry.fullPath.slice(1); | 18 var relativePath = fileEntry.fullPath.slice(1); |
| 19 return [fileSystemName, relativePath, callback]; | 19 return [fileSystemName, relativePath, callback]; |
| 20 }); | 20 }); |
| 21 } | 21 } |
| 22 ['getDisplayPath', 'getWritableFileEntry'].forEach(bindFileEntryFunction); | 22 ['getDisplayPath', 'getWritableFileEntry', 'isWritableFileEntry'] |
| 23 .forEach(bindFileEntryFunction); |
| 23 | 24 |
| 24 function bindFileEntryCallback(functionName) { | 25 function bindFileEntryCallback(functionName) { |
| 25 apiFunctions.setCustomCallback(functionName, | 26 apiFunctions.setCustomCallback(functionName, |
| 26 function(name, request, response) { | 27 function(name, request, response) { |
| 27 if (request.callback && response) { | 28 if (request.callback && response) { |
| 28 var callback = request.callback; | 29 var callback = request.callback; |
| 29 request.callback = null; | 30 request.callback = null; |
| 30 | 31 |
| 31 var fileSystemId = response.fileSystemId; | 32 var fileSystemId = response.fileSystemId; |
| 32 var baseName = response.baseName; | 33 var baseName = response.baseName; |
| 33 var fs = GetIsolatedFileSystem(fileSystemId); | 34 var fs = GetIsolatedFileSystem(fileSystemId); |
| 34 | 35 |
| 35 try { | 36 try { |
| 36 fs.root.getFile(baseName, {}, function(fileEntry) { | 37 fs.root.getFile(baseName, {}, function(fileEntry) { |
| 37 callback(fileEntry); | 38 callback(fileEntry); |
| 38 }, function(fileError) { | 39 }, function(fileError) { |
| 39 lastError.set('Error getting fileEntry, code: ' + fileError.code); | 40 lastError.set('Error getting fileEntry, code: ' + fileError.code); |
| 40 callback(); | 41 callback(); |
| 41 }); | 42 }); |
| 42 } catch (e) { | 43 } catch (e) { |
| 43 lastError.set('Error in event handler for onLaunched: ' + e.stack); | 44 lastError.set('Error in event handler for onLaunched: ' + e.stack); |
| 44 callback(); | 45 callback(); |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 }); | 48 }); |
| 48 } | 49 } |
| 49 ['getWritableFileEntry', 'chooseFile'].forEach(bindFileEntryCallback); | 50 ['getWritableFileEntry', 'chooseFile'].forEach(bindFileEntryCallback); |
| 50 }); | 51 }); |
| OLD | NEW |