OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var fileSystemNatives = requireNative('file_system_natives'); | 5 var fileSystemNatives = requireNative('file_system_natives'); |
6 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; | 6 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; |
7 var sendRequest = require('sendRequest'); | |
8 var lastError = require('lastError'); | 7 var lastError = require('lastError'); |
9 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; | 8 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; |
10 // TODO(sammc): Don't require extension. See http://crbug.com/235689. | 9 // TODO(sammc): Don't require extension. See http://crbug.com/235689. |
11 var GetExtensionViews = requireNative('runtime').GetExtensionViews; | 10 var GetExtensionViews = requireNative('runtime').GetExtensionViews; |
| 11 var safeCallbackApply = require('uncaught_exception_handler').safeCallbackApply; |
12 | 12 |
13 // For a given |apiName|, generates object with two elements that are used | 13 // For a given |apiName|, generates object with two elements that are used |
14 // in file system relayed APIs: | 14 // in file system relayed APIs: |
15 // * 'bindFileEntryCallback' function that provides mapping between JS objects | 15 // * 'bindFileEntryCallback' function that provides mapping between JS objects |
16 // into actual FileEntry|DirectoryEntry objects. | 16 // into actual FileEntry|DirectoryEntry objects. |
17 // * 'entryIdManager' object that implements methods for keeping the tracks of | 17 // * 'entryIdManager' object that implements methods for keeping the tracks of |
18 // previously saved file entries. | 18 // previously saved file entries. |
19 function getFileBindingsForApi(apiName) { | 19 function getFileBindingsForApi(apiName) { |
20 // Fallback to using the current window if no background page is running. | 20 // Fallback to using the current window if no background page is running. |
21 var backgroundPage = GetExtensionViews(-1, -1, 'BACKGROUND')[0] || window; | 21 var backgroundPage = GetExtensionViews(-1, -1, 'BACKGROUND')[0] || window; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 var getEntryCallback = function(fileEntry) { | 65 var getEntryCallback = function(fileEntry) { |
66 if (hasError) | 66 if (hasError) |
67 return; | 67 return; |
68 entryIdManager.registerEntry(id, fileEntry); | 68 entryIdManager.registerEntry(id, fileEntry); |
69 entries.push(fileEntry); | 69 entries.push(fileEntry); |
70 // Once all entries are ready, pass them to the callback. In the | 70 // Once all entries are ready, pass them to the callback. In the |
71 // event of an error, this condition will never be satisfied so | 71 // event of an error, this condition will never be satisfied so |
72 // the callback will not be called with any entries. | 72 // the callback will not be called with any entries. |
73 if (entries.length == response.entries.length) { | 73 if (entries.length == response.entries.length) { |
74 if (response.multiple) { | 74 if (response.multiple) { |
75 sendRequest.safeCallbackApply( | 75 safeCallbackApply(apiName + '.' + functionName, request, |
76 apiName + '.' + functionName, request, callback, | 76 callback, [entries]); |
77 [entries]); | |
78 } else { | 77 } else { |
79 sendRequest.safeCallbackApply( | 78 safeCallbackApply( |
80 apiName + '.' + functionName, request, callback, | 79 apiName + '.' + functionName, request, callback, |
81 [entries[0]]); | 80 [entries[0]]); |
82 } | 81 } |
83 } | 82 } |
84 } | 83 } |
85 // TODO(koz): fs.root.getFile() makes a trip to the browser | 84 // TODO(koz): fs.root.getFile() makes a trip to the browser |
86 // process, but it might be possible avoid that by calling | 85 // process, but it might be possible avoid that by calling |
87 // WebDOMFileSystem::createV8Entry(). | 86 // WebDOMFileSystem::createV8Entry(). |
88 if (entry.isDirectory) { | 87 if (entry.isDirectory) { |
89 fs.root.getDirectory(baseName, {}, getEntryCallback, | 88 fs.root.getDirectory(baseName, {}, getEntryCallback, |
(...skipping 22 matching lines...) Expand all Loading... |
112 backgroundPage.chrome.fileSystem; | 111 backgroundPage.chrome.fileSystem; |
113 var bindFileEntryCallback = backgroundPageModuleSystem.require( | 112 var bindFileEntryCallback = backgroundPageModuleSystem.require( |
114 apiName).bindFileEntryCallback; | 113 apiName).bindFileEntryCallback; |
115 var entryIdManager = backgroundPageModuleSystem.require('entryIdManager'); | 114 var entryIdManager = backgroundPageModuleSystem.require('entryIdManager'); |
116 } | 115 } |
117 return {bindFileEntryCallback: bindFileEntryCallback, | 116 return {bindFileEntryCallback: bindFileEntryCallback, |
118 entryIdManager: entryIdManager}; | 117 entryIdManager: entryIdManager}; |
119 } | 118 } |
120 | 119 |
121 exports.$set('getFileBindingsForApi', getFileBindingsForApi); | 120 exports.$set('getFileBindingsForApi', getFileBindingsForApi); |
OLD | NEW |