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'); | 7 var sendRequest = require('sendRequest'); |
8 var lastError = require('lastError'); | 8 var lastError = require('lastError'); |
9 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; | 9 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; |
10 // TODO(sammc): Don't require extension. See http://crbug.com/235689. | 10 // TODO(sammc): Don't require extension. See http://crbug.com/235689. |
11 var GetExtensionViews = requireNative('runtime').GetExtensionViews; | 11 var GetExtensionViews = requireNative('runtime').GetExtensionViews; |
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, 'BACKGROUND')[0] || window; | 21 var backgroundPage = GetExtensionViews(-1, -1, 'BACKGROUND')[0] || window; |
22 var backgroundPageModuleSystem = GetModuleSystem(backgroundPage); | 22 var backgroundPageModuleSystem = GetModuleSystem(backgroundPage); |
23 | 23 |
24 // All windows use the bindFileEntryCallback from the background page so their | 24 // All windows use the bindFileEntryCallback from the background page so their |
25 // FileEntry objects have the background page's context as their own. This | 25 // FileEntry objects have the background page's context as their own. This |
26 // allows them to be used from other windows (including the background page) | 26 // allows them to be used from other windows (including the background page) |
27 // after the original window is closed. | 27 // after the original window is closed. |
28 if (window == backgroundPage) { | 28 if (window == backgroundPage) { |
29 var bindFileEntryCallback = function(functionName, apiFunctions) { | 29 var bindFileEntryCallback = function(functionName, apiFunctions) { |
30 apiFunctions.setCustomCallback(functionName, | 30 apiFunctions.setCustomCallback(functionName, |
31 function(name, request, callback, response) { | 31 function(name, request, callback, response) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 backgroundPage.chrome.fileSystem; | 112 backgroundPage.chrome.fileSystem; |
113 var bindFileEntryCallback = backgroundPageModuleSystem.require( | 113 var bindFileEntryCallback = backgroundPageModuleSystem.require( |
114 apiName).bindFileEntryCallback; | 114 apiName).bindFileEntryCallback; |
115 var entryIdManager = backgroundPageModuleSystem.require('entryIdManager'); | 115 var entryIdManager = backgroundPageModuleSystem.require('entryIdManager'); |
116 } | 116 } |
117 return {bindFileEntryCallback: bindFileEntryCallback, | 117 return {bindFileEntryCallback: bindFileEntryCallback, |
118 entryIdManager: entryIdManager}; | 118 entryIdManager: entryIdManager}; |
119 } | 119 } |
120 | 120 |
121 exports.$set('getFileBindingsForApi', getFileBindingsForApi); | 121 exports.$set('getFileBindingsForApi', getFileBindingsForApi); |
OLD | NEW |