Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ext/content.js

Issue 29715759: Issue 6440 - Use long-lived connections to listen to extension events (Closed)
Patch Set: Added message passing mock for ports Created March 7, 2018, 7:10 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ext/common.js ('K') | « ext/common.js ('k') | firstRun.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/content.js
===================================================================
--- a/ext/content.js
+++ b/ext/content.js
@@ -59,7 +59,7 @@
}
};
- /* Polyfills */
+ /* Message passing */
if (!("runtime" in browser))
browser.runtime = {};
@@ -96,4 +96,21 @@
});
}
};
+
+ function postMessage(msg)
+ {
+ ext.backgroundPage._sendRawMessage({
+ type: "port",
+ name: this._name,
+ payload: msg
+ });
+ }
+ ext._Port.prototype.postMessage = postMessage;
+
+ function connect({name})
+ {
+ ext.backgroundPage._sendRawMessage({type: "connect", name});
+ return new ext._Port(name);
+ }
+ browser.runtime.connect = connect;
}());
« ext/common.js ('K') | « ext/common.js ('k') | firstRun.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld