| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 var fileSystem = null; | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 var testDirName = "tmp/test_dir_" + Math.floor(Math.random()*10000); | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 var testFileName = "test_file_" + Math.floor(Math.random()*10000); | 4 * LICENSE file. |
| 5 | 5 --> |
| 6 // Get local FS, create dir with a file in it. | 6 <script src="background.js"></script> |
| 7 console.log("Requesting local file system..."); | |
| 8 chrome.fileBrowserPrivate.requestLocalFileSystem(getFileSystem); | |
| 9 | |
| 10 function getFileSystem(fs, error) { | |
| 11 if (!fs) { | |
| 12 errorCallback(error); | |
| 13 return; | |
| 14 } | |
| 15 fileSystem = fs; | |
| 16 console.log("DONE requesting local filesystem: " + fileSystem.name); | |
| 17 console.log("Creating directory : " + testDirName); | |
| 18 fileSystem.root.getDirectory(testDirName, {create:true}, | |
| 19 directoryCallback, errorCallback); | |
| 20 } | |
| 21 | |
| 22 function directoryCallback(directory) { | |
| 23 console.log("DONE creating directory: " + directory.fullPath); | |
| 24 directory.getFile(testFileName, {create:true}, fileCallback, errorCallback); | |
| 25 } | |
| 26 | |
| 27 function fileCallback(file) { | |
| 28 console.log("DONE creating file: " + file.fullPath); | |
| 29 | |
| 30 // See if we can access this filesystem and its elements in the tab. | |
| 31 console.log("Opening tab..."); | |
| 32 chrome.tabs.create({ | |
| 33 url: "tab.html#" + escape(testDirName + "/" + testFileName) | |
| 34 }); | |
| 35 } | |
| 36 | |
| 37 function errorCallback(e) { | |
| 38 var msg = ''; | |
| 39 switch (e.code) { | |
| 40 case FileError.QUOTA_EXCEEDED_ERR: | |
| 41 msg = 'QUOTA_EXCEEDED_ERR'; | |
| 42 break; | |
| 43 case FileError.NOT_FOUND_ERR: | |
| 44 msg = 'NOT_FOUND_ERR'; | |
| 45 break; | |
| 46 case FileError.SECURITY_ERR: | |
| 47 msg = 'SECURITY_ERR'; | |
| 48 break; | |
| 49 case FileError.INVALID_MODIFICATION_ERR: | |
| 50 msg = 'INVALID_MODIFICATION_ERR'; | |
| 51 break; | |
| 52 case FileError.INVALID_STATE_ERR: | |
| 53 msg = 'INVALID_STATE_ERR'; | |
| 54 break; | |
| 55 default: | |
| 56 msg = 'Unknown Error'; | |
| 57 break; | |
| 58 }; | |
| 59 chrome.test.fail("Got unexpected error: " + msg); | |
| 60 console.log('Error: ' + msg); | |
| 61 alert('Error: ' + msg); | |
| 62 } | |
| 63 </script> | |
| OLD | NEW |