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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/resources/event.js ('k') | extensions/renderer/test_extensions_renderer_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« 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