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

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

Issue 147033: Refactor extension bindings to share code, avoid exposing hidden variables (Closed)
Patch Set: at head 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/greasemonkey_api.js ('k') | no next file » | 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 31b97ed76563b188c807265b3ebf339671ef77a4..bf59671a1eddb1660777c2c1801b4e30c94c48af 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -11,44 +11,53 @@ var chrome = chrome || {};
(function () {
native function OpenChannelToExtension(id);
native function PostMessage(portId, msg);
+ native function GetChromeHidden();
+
+ var chromeHidden = GetChromeHidden();
+
+ // Map of port IDs to port object.
+ var ports = {};
// Port object. Represents a connection to another script context through
// which messages can be passed.
chrome.Port = function(portId) {
- if (chrome.Port.ports_[portId]) {
+ if (ports[portId]) {
throw new Error("Port '" + portId + "' already exists.");
}
this.portId_ = portId; // TODO(mpcomplete): readonly
this.onDisconnect = new chrome.Event();
this.onMessage = new chrome.Event();
- chrome.Port.ports_[portId] = this;
+ ports[portId] = this;
+
+ chromeHidden.onUnload.addListener(function() {
+ this.disconnect();
+ });
};
- // Map of port IDs to port object.
- chrome.Port.ports_ = {};
+ chromeHidden.Port = {};
// Called by native code when a channel has been opened to this context.
- chrome.Port.dispatchOnConnect_ = function(portId, tab) {
+ chromeHidden.Port.dispatchOnConnect = function(portId, tab) {
var port = new chrome.Port(portId);
if (tab) {
tab = JSON.parse(tab);
}
port.tab = tab;
- chrome.Event.dispatch_("channel-connect", [port]);
+ chromeHidden.Event.dispatch("channel-connect", [port]);
};
// Called by native code when a channel has been closed.
- chrome.Port.dispatchOnDisconnect_ = function(portId) {
- var port = chrome.Port.ports_[portId];
+ chromeHidden.Port.dispatchOnDisconnect = function(portId) {
+ var port = ports[portId];
if (port) {
port.onDisconnect.dispatch(port);
- delete chrome.Port.ports_[portId];
+ delete ports[portId];
}
};
// Called by native code when a message has been sent to the given port.
- chrome.Port.dispatchOnMessage_ = function(msg, portId) {
- var port = chrome.Port.ports_[portId];
+ chromeHidden.Port.dispatchOnMessage = function(msg, portId) {
+ var port = ports[portId];
if (port) {
if (msg) {
msg = JSON.parse(msg);
@@ -66,6 +75,12 @@ var chrome = chrome || {};
PostMessage(this.portId_, JSON.stringify(msg));
};
+ // Disconnects the port from the other end.
+ chrome.Port.prototype.disconnect = function() {
+ delete ports[this.portId_];
+ //CloseChannel(this.portId_); // TODO(mpcomplete)
+ }
+
// Extension object.
chrome.Extension = function(id) {
this.id_ = id;
« no previous file with comments | « chrome/renderer/resources/greasemonkey_api.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698