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

Side by Side Diff: extensions/renderer/resources/runtime_custom_bindings.js

Issue 2300453002: [Extensions] Begin making Extension port initialization asynchronous (Closed)
Patch Set: Nasko's Created 4 years, 3 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 messagingNatives = requireNative('messaging_natives');
11 var process = requireNative('process'); 12 var process = requireNative('process');
12 var utils = require('utils'); 13 var utils = require('utils');
13 14
14 var WINDOW = {}; 15 var WINDOW = {};
15 try { 16 try {
16 WINDOW = window; 17 WINDOW = window;
17 } catch (e) { 18 } catch (e) {
18 // Running in SW context. 19 // Running in SW context.
19 // TODO(lazyboy): Synchronous access to background page is not possible from 20 // TODO(lazyboy): Synchronous access to background page is not possible from
20 // service worker context. Decide what we should do in this case for the class 21 // service worker context. Decide what we should do in this case for the class
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 targetId = id; 148 targetId = id;
148 } 149 }
149 150
150 var name = ''; 151 var name = '';
151 if (connectInfo && connectInfo.name) 152 if (connectInfo && connectInfo.name)
152 name = connectInfo.name; 153 name = connectInfo.name;
153 154
154 var includeTlsChannelId = 155 var includeTlsChannelId =
155 !!(connectInfo && connectInfo.includeTlsChannelId); 156 !!(connectInfo && connectInfo.includeTlsChannelId);
156 157
157 var portId = runtimeNatives.OpenChannelToExtension(targetId, name, 158 var portId = messagingNatives.OpenChannelToExtension(targetId, name,
158 includeTlsChannelId); 159 includeTlsChannelId);
159 if (portId >= 0) 160 if (portId >= 0)
160 return messaging.createPort(portId, name); 161 return messaging.createPort(portId, name);
161 }); 162 });
162 163
163 // 164 //
164 // Privileged APIs. 165 // Privileged APIs.
165 // 166 //
166 if (contextType != 'BLESSED_EXTENSION') 167 if (contextType != 'BLESSED_EXTENSION')
167 return; 168 return;
168 169
169 apiFunctions.setHandleRequest('connectNative', 170 apiFunctions.setHandleRequest('connectNative',
170 function(nativeAppName) { 171 function(nativeAppName) {
171 var portId = runtimeNatives.OpenChannelToNativeApp(nativeAppName); 172 var portId = messagingNatives.OpenChannelToNativeApp(nativeAppName);
172 if (portId >= 0) 173 if (portId >= 0)
173 return messaging.createPort(portId, ''); 174 return messaging.createPort(portId, '');
174 throw new Error('Error connecting to native app: ' + nativeAppName); 175 throw new Error('Error connecting to native app: ' + nativeAppName);
175 }); 176 });
176 177
177 apiFunctions.setCustomCallback('getBackgroundPage', 178 apiFunctions.setCustomCallback('getBackgroundPage',
178 function(name, request, callback, response) { 179 function(name, request, callback, response) {
179 if (callback) { 180 if (callback) {
180 var bg = 181 var bg =
181 runtimeNatives.GetExtensionViews(-1, -1, 'BACKGROUND')[0] || null; 182 runtimeNatives.GetExtensionViews(-1, -1, 'BACKGROUND')[0] || null;
182 callback(bg); 183 callback(bg);
183 } 184 }
184 }); 185 });
185 186
186 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions); 187 bindDirectoryEntryCallback('getPackageDirectoryEntry', apiFunctions);
187 }); 188 });
188 189
189 exports.$set('bindDirectoryEntryCallback', bindDirectoryEntryCallback); 190 exports.$set('bindDirectoryEntryCallback', bindDirectoryEntryCallback);
190 exports.$set('binding', binding.generate()); 191 exports.$set('binding', binding.generate());
OLDNEW
« no previous file with comments | « extensions/renderer/resources/messaging.js ('k') | extensions/renderer/runtime_custom_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698