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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
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 // Custom binding for the runtime API. 5 // Custom binding for the runtime API.
6 6
7 var binding = require('binding').Binding.create('runtime'); 7 var binding = require('binding').Binding.create('runtime');
8 8
9 var messaging = require('messaging'); 9 var messaging = require('messaging');
10 var runtimeNatives = requireNative('runtime'); 10 var runtimeNatives = requireNative('runtime');
11 var process = requireNative('process'); 11 var process = requireNative('process');
12 var forEach = require('utils').forEach; 12 var forEach = require('utils').forEach;
13 13
14 var backgroundPage = window; 14 var WINDOW = {};
Devlin 2016/04/13 19:46:32 Does anything else need to be done here?
lazyboy 2016/04/14 02:07:53 At this point there isn't much we can do, WINDOW i
15 try {
16 WINDOW = window;
17 } catch (e) {
18 // Running in SW context.
19 }
20
21 var backgroundPage = WINDOW;
15 var backgroundRequire = require; 22 var backgroundRequire = require;
16 var contextType = process.GetContextType(); 23 var contextType = process.GetContextType();
17 if (contextType == 'BLESSED_EXTENSION' || 24 if (contextType == 'BLESSED_EXTENSION' ||
18 contextType == 'UNBLESSED_EXTENSION') { 25 contextType == 'UNBLESSED_EXTENSION') {
19 var manifest = runtimeNatives.GetManifest(); 26 var manifest = runtimeNatives.GetManifest();
20 if (manifest.app && manifest.app.background) { 27 if (manifest.app && manifest.app.background) {
21 // Get the background page if one exists. Otherwise, default to the current 28 // Get the background page if one exists. Otherwise, default to the current
22 // window. 29 // window.
23 backgroundPage = runtimeNatives.GetExtensionViews(-1, 'BACKGROUND')[0]; 30 backgroundPage = runtimeNatives.GetExtensionViews(-1, 'BACKGROUND')[0];
24 if (backgroundPage) { 31 if (backgroundPage) {
25 var GetModuleSystem = requireNative('v8_context').GetModuleSystem; 32 var GetModuleSystem = requireNative('v8_context').GetModuleSystem;
26 backgroundRequire = GetModuleSystem(backgroundPage).require; 33 backgroundRequire = GetModuleSystem(backgroundPage).require;
27 } else { 34 } else {
28 backgroundPage = window; 35 backgroundPage = WINDOW;
29 } 36 }
30 } 37 }
31 } 38 }
32 39
33 // For packaged apps, all windows use the bindFileEntryCallback from the 40 // For packaged apps, all windows use the bindFileEntryCallback from the
34 // background page so their FileEntry objects have the background page's context 41 // background page so their FileEntry objects have the background page's context
35 // as their own. This allows them to be used from other windows (including the 42 // as their own. This allows them to be used from other windows (including the
36 // background page) after the original window is closed. 43 // background page) after the original window is closed.
37 if (window == backgroundPage) { 44 if (WINDOW == backgroundPage) {
38 var lastError = require('lastError'); 45 var lastError = require('lastError');
39 var fileSystemNatives = requireNative('file_system_natives'); 46 var fileSystemNatives = requireNative('file_system_natives');
40 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem; 47 var GetIsolatedFileSystem = fileSystemNatives.GetIsolatedFileSystem;
41 var bindDirectoryEntryCallback = function(functionName, apiFunctions) { 48 var bindDirectoryEntryCallback = function(functionName, apiFunctions) {
42 apiFunctions.setCustomCallback(functionName, 49 apiFunctions.setCustomCallback(functionName,
43 function(name, request, callback, response) { 50 function(name, request, callback, response) {
44 if (callback) { 51 if (callback) {
45 if (!response) { 52 if (!response) {
46 callback(); 53 callback();
47 return; 54 return;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 var bg = runtimeNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null; 204 var bg = runtimeNatives.GetExtensionViews(-1, 'BACKGROUND')[0] || null;
198 callback(bg); 205 callback(bg);
199 } 206 }
200 }); 207 });
201 208
202 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions); 209 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions);
203 }); 210 });
204 211
205 exports.$set('bindDirectoryEntryCallback', bindDirectoryEntryCallback); 212 exports.$set('bindDirectoryEntryCallback', bindDirectoryEntryCallback);
206 exports.$set('binding', binding.generate()); 213 exports.$set('binding', binding.generate());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698