Index: extensions/renderer/resources/runtime_custom_bindings.js |
diff --git a/extensions/renderer/resources/runtime_custom_bindings.js b/extensions/renderer/resources/runtime_custom_bindings.js |
index 00a86a2239cfca7ce35bfcc08e963575b35cc79e..cafd658936762243caf8aad1667ee16ac30731ee 100644 |
--- a/extensions/renderer/resources/runtime_custom_bindings.js |
+++ b/extensions/renderer/resources/runtime_custom_bindings.js |
@@ -11,81 +11,8 @@ var runtimeNatives = requireNative('runtime'); |
var messagingNatives = requireNative('messaging_natives'); |
var process = requireNative('process'); |
var utils = require('utils'); |
- |
-var WINDOW = {}; |
-try { |
- WINDOW = window; |
-} catch (e) { |
- // Running in SW context. |
- // TODO(lazyboy): Synchronous access to background page is not possible from |
- // service worker context. Decide what we should do in this case for the class |
- // of APIs that require access to background page or window object |
-} |
- |
-var backgroundPage = WINDOW; |
-var backgroundRequire = require; |
-var contextType = process.GetContextType(); |
- |
-if (contextType == 'BLESSED_EXTENSION' || |
- contextType == 'UNBLESSED_EXTENSION') { |
- var manifest = runtimeNatives.GetManifest(); |
- if (manifest.app && manifest.app.background) { |
- // Get the background page if one exists. Otherwise, default to the current |
- // window. |
- backgroundPage = runtimeNatives.GetExtensionViews(-1, -1, 'BACKGROUND')[0]; |
- if (backgroundPage) { |
- var GetModuleSystem = requireNative('v8_context').GetModuleSystem; |
- backgroundRequire = GetModuleSystem(backgroundPage).require; |
- } else { |
- backgroundPage = WINDOW; |
- } |
- } |
-} |
- |
-// For packaged apps, all windows use the bindFileEntryCallback from the |
-// background page so their FileEntry objects have the background page's context |
-// as their own. This allows them to be used from other windows (including the |
-// background page) after the original window is closed. |
-if (WINDOW == backgroundPage) { |
- var lastError = require('lastError'); |
- var fileSystemNatives = requireNative('file_system_natives'); |
- var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; |
- var bindDirectoryEntryCallback = function(functionName, apiFunctions) { |
- apiFunctions.setCustomCallback(functionName, |
- function(name, request, callback, response) { |
- if (callback) { |
- if (!response) { |
- callback(); |
- return; |
- } |
- var fileSystemId = response.fileSystemId; |
- var baseName = response.baseName; |
- var fs = GetIsolatedFileSystem(fileSystemId); |
- |
- try { |
- fs.root.getDirectory(baseName, {}, callback, function(fileError) { |
- lastError.run('runtime.' + functionName, |
- 'Error getting Entry, code: ' + fileError.code, |
- request.stack, |
- callback); |
- }); |
- } catch (e) { |
- lastError.run('runtime.' + functionName, |
- 'Error: ' + e.stack, |
- request.stack, |
- callback); |
- } |
- } |
- }); |
- }; |
-} else { |
- // Force the runtime API to be loaded in the background page. Using |
- // backgroundPageModuleSystem.require('runtime') is insufficient as |
- // requireNative is only allowed while lazily loading an API. |
- backgroundPage.chrome.runtime; |
- var bindDirectoryEntryCallback = |
- backgroundRequire('runtime').bindDirectoryEntryCallback; |
-} |
+var getBindDirectoryEntryCallback = |
+ require('fileEntryBindingUtil').getBindDirectoryEntryCallback; |
binding.registerCustomHook(function(binding, id, contextType) { |
var apiFunctions = binding.apiFunctions; |
@@ -184,9 +111,9 @@ binding.registerCustomHook(function(binding, id, contextType) { |
} |
}); |
- bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions); |
+ apiFunctions.setCustomCallback('getPackageDirectoryEntry', |
+ getBindDirectoryEntryCallback()); |
}); |
-exports.$set('bindDirectoryEntryCallback', bindDirectoryEntryCallback); |
if (!apiBridge) |
exports.$set('binding', binding.generate()); |