OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // The ID of the extension we want to talk to. | |
6 var fileBrowserExtensionId = "ddammdhioacbehjngdmkjcjbnfginlla"; | |
7 | |
8 function errorCallback(error) { | |
9 var msg = ''; | |
10 if (!error.code) { | |
11 msg = error.message; | |
12 } else { | |
13 switch (error.code) { | |
14 case FileError.QUOTA_EXCEEDED_ERR: | |
15 msg = 'QUOTA_EXCEEDED_ERR'; | |
16 break; | |
17 case FileError.NOT_FOUND_ERR: | |
18 msg = 'NOT_FOUND_ERR'; | |
19 break; | |
20 case FileError.SECURITY_ERR: | |
21 msg = 'SECURITY_ERR'; | |
22 break; | |
23 case FileError.INVALID_MODIFICATION_ERR: | |
24 msg = 'INVALID_MODIFICATION_ERR'; | |
25 break; | |
26 case FileError.INVALID_STATE_ERR: | |
27 msg = 'INVALID_STATE_ERR'; | |
28 break; | |
29 default: | |
30 msg = 'Unknown Error'; | |
31 break; | |
32 }; | |
33 } | |
34 | |
35 chrome.extension.sendRequest(fileBrowserExtensionId, | |
36 {fileContent: null, | |
37 error: {message: "File handler error: " + msg}}, | |
38 function(response) {}); | |
39 }; | |
40 | |
41 function onGotEntryByUrl(entry) { | |
42 var reader = new FileReader(); | |
43 reader.onloadend = function(e) { | |
44 | |
45 console.log(reader.result); | |
tbarzic
2012/04/13 02:58:30
remove this log
| |
46 // Send data back to the file browser extension | |
47 chrome.extension.sendRequest( | |
48 fileBrowserExtensionId, | |
49 {fileContent: reader.result, error: null}, | |
50 function(response) {}); | |
51 }; | |
52 reader.onerror = function(e) { | |
53 errorCallback(reader.error); | |
54 }; | |
55 entry.file(function(file) { | |
56 reader.readAsText(file); | |
57 }, | |
58 errorCallback); | |
59 }; | |
60 | |
61 function readEntryByUrl(entryUrl) { | |
62 window.webkitResolveLocalFileSystemURL(entryUrl, onGotEntryByUrl, | |
63 errorCallback); | |
64 }; | |
65 | |
66 readEntryByUrl(localStorage.entryURL); | |
OLD | NEW |