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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/resources/messaging.js
diff --git a/extensions/renderer/resources/messaging.js b/extensions/renderer/resources/messaging.js
index 86c110b1de860cc661478dd05a7b64bea4081088..90aa66b6949fcad39198cf07908eb4264e2f7721 100644
--- a/extensions/renderer/resources/messaging.js
+++ b/extensions/renderer/resources/messaging.js
@@ -247,6 +247,33 @@
targetExtensionId,
sourceUrl,
tlsChannelId) {
+ var usedPort = dispatchOnConnectImpl(portId, channelName, sourceTab,
+ sourceFrameId, guestProcessId,
+ guestRenderFrameRoutingId,
+ sourceExtensionId, targetExtensionId,
+ sourceUrl, tlsChannelId);
+ 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.
+ // 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);
lazyboy 2017/06/05 18:18:33 nit: false /* force_close */
Devlin 2017/06/09 20:18:02 Done.
+ }
+ }
+
+ // 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

Powered by Google App Engine
This is Rietveld 408576698