Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: extensions/renderer/resources/runtime_custom_bindings.js

Issue 1880933002: Begin to enable extension APIs in Extension Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments -> round 1 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 1f829d4deb11abfe83933bb9fc0ec94881e267f1..0ab65d54b0448c7ee9cbef1d1b941b0f3bb2c8c2 100644
--- a/extensions/renderer/resources/runtime_custom_bindings.js
+++ b/extensions/renderer/resources/runtime_custom_bindings.js
@@ -11,7 +11,17 @@ var runtimeNatives = requireNative('runtime');
var process = requireNative('process');
var forEach = require('utils').forEach;
-var backgroundPage = window;
+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' ||
@@ -25,7 +35,7 @@ if (contextType == 'BLESSED_EXTENSION' ||
var GetModuleSystem = requireNative('v8_context').GetModuleSystem;
backgroundRequire = GetModuleSystem(backgroundPage).require;
} else {
- backgroundPage = window;
+ backgroundPage = WINDOW;
}
}
}
@@ -34,7 +44,7 @@ if (contextType == 'BLESSED_EXTENSION' ||
// 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) {
+if (WINDOW == backgroundPage) {
var lastError = require('lastError');
var fileSystemNatives = requireNative('file_system_natives');
var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;

Powered by Google App Engine
This is Rietveld 408576698