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

Unified Diff: chrome/renderer/resources/renderer_extension_bindings.js

Issue 152003: Fix some issues with extension messaging: (Closed)
Patch Set: Created 11 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 | « chrome/renderer/resources/extension_process_bindings.js ('k') | webkit/glue/webview_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/resources/renderer_extension_bindings.js
diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js
index f9d354ecd35b2697124c0d761a07aba82dc6d283..b27a2df0ba2ff8d772f64a71d9861d171bfde85a 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -29,22 +29,30 @@ var chrome = chrome || {};
this.onDisconnect = new chrome.Event();
this.onMessage = new chrome.Event();
ports[portId] = this;
-
+
+ var port = this;
chromeHidden.onUnload.addListener(function() {
- this.disconnect();
+ port.disconnect();
});
};
chromeHidden.Port = {};
// Called by native code when a channel has been opened to this context.
- chromeHidden.Port.dispatchOnConnect = function(portId, tab) {
- var port = new chrome.Port(portId);
- if (tab) {
- tab = JSON.parse(tab);
+ chromeHidden.Port.dispatchOnConnect = function(portId, tab, extensionId) {
+ // 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
+ // close both.
+ var connectEvent = "channel-connect:" + (extensionId || "");
+ if (chromeHidden.Event.hasListener(connectEvent)) {
+ var port = new chrome.Port(portId);
+ if (tab) {
+ tab = JSON.parse(tab);
+ }
+ port.tab = tab;
+ chromeHidden.Event.dispatch(connectEvent, [port]);
}
- port.tab = tab;
- chromeHidden.Event.dispatch("channel-connect", [port]);
};
// Called by native code when a channel has been closed.
« no previous file with comments | « chrome/renderer/resources/extension_process_bindings.js ('k') | webkit/glue/webview_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698