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