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

Unified Diff: ext/common.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
« no previous file with comments | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/common.js
===================================================================
--- a/ext/common.js
+++ b/ext/common.js
@@ -74,4 +74,42 @@
window.removeEventListener("message", listener._extWrapper, false);
}
};
+
+ class Port
saroyanm 2018/03/12 13:08:28 I like that we have started to use javascript clas
a.giammarchi 2018/03/12 13:17:31 FWIW, when needed, I prefer classes too and I thin
Thomas Greiner 2018/03/13 18:24:45 Yes, this is just a mock. We're still supporting O
a.giammarchi 2018/03/14 07:51:03 AFAIK Opera 36 already supports Classes, but it's
+ {
+ constructor(name)
+ {
+ this._name = name;
+ }
+
+ get name()
+ {
+ return this._name;
+ }
+
+ get onDisconnect()
+ {
+ return {
+ addListener() {}
+ };
+ }
+
+ get onMessage()
+ {
+ let name = this._name;
+ return {
+ addListener(listener)
+ {
+ window.addEventListener("message", (event) =>
+ {
+ if (event.data.type != "port" || event.data.name != name)
+ return;
+
+ listener(event.data.payload);
+ });
+ }
+ };
+ }
+ }
+ window.ext._Port = Port;
}());
« no previous file with comments | « ext/background.js ('k') | ext/content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld