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

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

Issue 2909673003: [Extensions Bindings] Request JS execution from messaging bindings (Closed)
Patch Set: . Created 3 years, 7 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 // chrome.runtime.messaging API implementation. 5 // chrome.runtime.messaging API implementation.
6 // TODO(robwu): Fix this indentation. 6 // TODO(robwu): Fix this indentation.
7 7
8 // TODO(kalman): factor requiring chrome out of here. 8 // TODO(kalman): factor requiring chrome out of here.
9 var chrome = requireNative('chrome').GetChrome(); 9 var chrome = requireNative('chrome').GetChrome();
10 var lastError = require('lastError'); 10 var lastError = require('lastError');
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 function dispatchOnConnect(portId, 240 function dispatchOnConnect(portId,
241 channelName, 241 channelName,
242 sourceTab, 242 sourceTab,
243 sourceFrameId, 243 sourceFrameId,
244 guestProcessId, 244 guestProcessId,
245 guestRenderFrameRoutingId, 245 guestRenderFrameRoutingId,
246 sourceExtensionId, 246 sourceExtensionId,
247 targetExtensionId, 247 targetExtensionId,
248 sourceUrl, 248 sourceUrl,
249 tlsChannelId) { 249 tlsChannelId) {
250 var usedPort = dispatchOnConnectImpl(portId, channelName, sourceTab,
251 sourceFrameId, guestProcessId,
252 guestRenderFrameRoutingId,
253 sourceExtensionId, targetExtensionId,
254 sourceUrl, tlsChannelId);
255 if (!usedPort) {
lazyboy 2017/06/05 18:18:33 nit: isPortUsed (usedPort var might be misleading
Devlin 2017/06/09 20:18:02 Good point; changed to wasPortUsed.
256 // Since the JS to dispatch the connect event can (in rare cases) be
257 // executed asynchronously from when we check if there are associated
258 // listeners in the native code, it's possible that the listeners have
259 // since been removed. If that's the case (though unlikely), remove the
260 // port.
261 messagingNatives.CloseChannel(portId, false);
lazyboy 2017/06/05 18:18:33 nit: false /* force_close */
Devlin 2017/06/09 20:18:02 Done.
262 }
263 }
264
265 // Helper function to dispatchOnConnect that returns true if the new port
266 // was used.
267 function dispatchOnConnectImpl(portId,
268 channelName,
269 sourceTab,
270 sourceFrameId,
271 guestProcessId,
272 guestRenderFrameRoutingId,
273 sourceExtensionId,
274 targetExtensionId,
275 sourceUrl,
276 tlsChannelId) {
250 // Only create a new Port if someone is actually listening for a connection. 277 // Only create a new Port if someone is actually listening for a connection.
251 // In addition to being an optimization, this also fixes a bug where if 2 278 // In addition to being an optimization, this also fixes a bug where if 2
252 // channels were opened to and from the same process, closing one would 279 // channels were opened to and from the same process, closing one would
253 // close both. 280 // close both.
254 var extensionId = processNatives.GetExtensionId(); 281 var extensionId = processNatives.GetExtensionId();
255 282
256 // messaging_bindings.cc should ensure that this method only gets called for 283 // messaging_bindings.cc should ensure that this method only gets called for
257 // the right extension. 284 // the right extension.
258 logging.CHECK(targetExtensionId == extensionId); 285 logging.CHECK(targetExtensionId == extensionId);
259 286
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 exports.$set('kNativeMessageChannel', kNativeMessageChannel); 462 exports.$set('kNativeMessageChannel', kNativeMessageChannel);
436 exports.$set('Port', Port); 463 exports.$set('Port', Port);
437 exports.$set('createPort', createPort); 464 exports.$set('createPort', createPort);
438 exports.$set('sendMessageImpl', sendMessageImpl); 465 exports.$set('sendMessageImpl', sendMessageImpl);
439 exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments); 466 exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments);
440 467
441 // For C++ code to call. 468 // For C++ code to call.
442 exports.$set('dispatchOnConnect', dispatchOnConnect); 469 exports.$set('dispatchOnConnect', dispatchOnConnect);
443 exports.$set('dispatchOnDisconnect', dispatchOnDisconnect); 470 exports.$set('dispatchOnDisconnect', dispatchOnDisconnect);
444 exports.$set('dispatchOnMessage', dispatchOnMessage); 471 exports.$set('dispatchOnMessage', dispatchOnMessage);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698