| Index: extensions/renderer/resources/messaging.js
|
| diff --git a/extensions/renderer/resources/messaging.js b/extensions/renderer/resources/messaging.js
|
| index 86c110b1de860cc661478dd05a7b64bea4081088..cdce1cf614d3e80f98e9bbc8cac54cd2511c1e0d 100644
|
| --- a/extensions/renderer/resources/messaging.js
|
| +++ b/extensions/renderer/resources/messaging.js
|
| @@ -247,6 +247,34 @@
|
| targetExtensionId,
|
| sourceUrl,
|
| tlsChannelId) {
|
| + var wasPortUsed = dispatchOnConnectImpl(portId, channelName, sourceTab,
|
| + sourceFrameId, guestProcessId,
|
| + guestRenderFrameRoutingId,
|
| + sourceExtensionId,
|
| + targetExtensionId, sourceUrl,
|
| + tlsChannelId);
|
| + if (!wasPortUsed) {
|
| + // Since the JS to dispatch the connect event can (in rare cases) be
|
| + // executed asynchronously from when we check if there are associated
|
| + // listeners in the native code, it's possible that the listeners have
|
| + // since been removed. If that's the case (though unlikely), remove the
|
| + // port.
|
| + messagingNatives.CloseChannel(portId, false /* force_close */);
|
| + }
|
| + }
|
| +
|
| + // Helper function to dispatchOnConnect that returns true if the new port
|
| + // was used.
|
| + function dispatchOnConnectImpl(portId,
|
| + channelName,
|
| + sourceTab,
|
| + sourceFrameId,
|
| + guestProcessId,
|
| + guestRenderFrameRoutingId,
|
| + sourceExtensionId,
|
| + targetExtensionId,
|
| + sourceUrl,
|
| + tlsChannelId) {
|
| // Only create a new Port if someone is actually listening for a connection.
|
| // In addition to being an optimization, this also fixes a bug where if 2
|
| // channels were opened to and from the same process, closing one would
|
|
|