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

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

Issue 2909673003: [Extensions Bindings] Request JS execution from messaging bindings (Closed)
Patch Set: lazyboy's Created 3 years, 6 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 wasPortUsed = dispatchOnConnectImpl(portId, channelName, sourceTab,
251 sourceFrameId, guestProcessId,
252 guestRenderFrameRoutingId,
253 sourceExtensionId,
254 targetExtensionId, sourceUrl,
255 tlsChannelId);
256 if (!wasPortUsed) {
257 // Since the JS to dispatch the connect event can (in rare cases) be
258 // executed asynchronously from when we check if there are associated
259 // listeners in the native code, it's possible that the listeners have
260 // since been removed. If that's the case (though unlikely), remove the
261 // port.
262 messagingNatives.CloseChannel(portId, false /* force_close */);
263 }
264 }
265
266 // Helper function to dispatchOnConnect that returns true if the new port
267 // was used.
268 function dispatchOnConnectImpl(portId,
269 channelName,
270 sourceTab,
271 sourceFrameId,
272 guestProcessId,
273 guestRenderFrameRoutingId,
274 sourceExtensionId,
275 targetExtensionId,
276 sourceUrl,
277 tlsChannelId) {
250 // Only create a new Port if someone is actually listening for a connection. 278 // 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 279 // 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 280 // channels were opened to and from the same process, closing one would
253 // close both. 281 // close both.
254 var extensionId = processNatives.GetExtensionId(); 282 var extensionId = processNatives.GetExtensionId();
255 283
256 // messaging_bindings.cc should ensure that this method only gets called for 284 // messaging_bindings.cc should ensure that this method only gets called for
257 // the right extension. 285 // the right extension.
258 logging.CHECK(targetExtensionId == extensionId); 286 logging.CHECK(targetExtensionId == extensionId);
259 287
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 exports.$set('kNativeMessageChannel', kNativeMessageChannel); 463 exports.$set('kNativeMessageChannel', kNativeMessageChannel);
436 exports.$set('Port', Port); 464 exports.$set('Port', Port);
437 exports.$set('createPort', createPort); 465 exports.$set('createPort', createPort);
438 exports.$set('sendMessageImpl', sendMessageImpl); 466 exports.$set('sendMessageImpl', sendMessageImpl);
439 exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments); 467 exports.$set('sendMessageUpdateArguments', sendMessageUpdateArguments);
440 468
441 // For C++ code to call. 469 // For C++ code to call.
442 exports.$set('dispatchOnConnect', dispatchOnConnect); 470 exports.$set('dispatchOnConnect', dispatchOnConnect);
443 exports.$set('dispatchOnDisconnect', dispatchOnDisconnect); 471 exports.$set('dispatchOnDisconnect', dispatchOnDisconnect);
444 exports.$set('dispatchOnMessage', dispatchOnMessage); 472 exports.$set('dispatchOnMessage', dispatchOnMessage);
OLDNEW
« no previous file with comments | « extensions/renderer/resources/event.js ('k') | extensions/renderer/test_extensions_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698