Chromium Code Reviews| 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', 'isWritableFileEntry'] | 22 ['getDisplayPath', 'getWritableEntry', 'isWritableEntry'] |
| 23 .forEach(bindFileEntryFunction); | 23 .forEach(bindFileEntryFunction); |
| 24 | 24 |
| 25 function bindFileEntryCallback(functionName) { | 25 function bindFileEntryCallback(functionName) { |
| 26 apiFunctions.setCustomCallback(functionName, | 26 apiFunctions.setCustomCallback(functionName, |
| 27 function(name, request, response) { | 27 function(name, request, response) { |
| 28 if (request.callback && response) { | 28 if (request.callback && response) { |
| 29 var callback = request.callback; | 29 var callback = request.callback; |
| 30 request.callback = null; | 30 request.callback = null; |
| 31 | 31 |
| 32 var fileSystemId = response.fileSystemId; | 32 var fileSystemId = response.fileSystemId; |
| 33 var baseName = response.baseName; | 33 var baseName = response.baseName; |
| 34 var fs = GetIsolatedFileSystem(fileSystemId); | 34 var fs = GetIsolatedFileSystem(fileSystemId); |
| 35 | 35 |
| 36 try { | 36 try { |
| 37 fs.root.getFile(baseName, {}, function(fileEntry) { | 37 fs.root.getFile(baseName, {}, function(fileEntry) { |
| 38 callback(fileEntry); | 38 callback(fileEntry); |
| 39 }, function(fileError) { | 39 }, function(fileError) { |
| 40 lastError.set('Error getting fileEntry, code: ' + fileError.code); | 40 lastError.set('Error getting fileEntry, code: ' + fileError.code); |
| 41 callback(); | 41 callback(); |
| 42 }); | 42 }); |
| 43 } catch (e) { | 43 } catch (e) { |
| 44 lastError.set('Error in event handler for onLaunched: ' + e.stack); | 44 lastError.set('Error in event handler for onLaunched: ' + e.stack); |
| 45 callback(); | 45 callback(); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 }); | 48 }); |
| 49 } | 49 } |
| 50 ['getWritableFileEntry', 'chooseFile'].forEach(bindFileEntryCallback); | 50 ['getWritableEntry', 'chooseEntry'].forEach(bindFileEntryCallback); |
| 51 | |
| 52 // Remove these deprecated versions of the functions. | |
| 53 chrome.fileSystem.getWritableFileEntry = chrome.fileSystem.getWritableEntry; | |
|
Mihai Parparita -not on Chrome
2012/09/14 06:01:59
It would be neat to have a wrapper that logs a war
| |
| 54 chrome.fileSystem.isWritableFileEntry = chrome.fileSystem.isWritableEntry; | |
| 55 chrome.fileSystem.chooseFile = chrome.fileSystem.chooseEntry; | |
| 51 }); | 56 }); |
| OLD | NEW |