Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 */ | 98 */ |
99 off: function(name, callback) | 99 off: function(name, callback) |
100 { | 100 { |
101 let callbacks = this._callbacks[name]; | 101 let callbacks = this._callbacks[name]; |
102 if (callbacks) | 102 if (callbacks) |
103 { | 103 { |
104 let idx = callbacks.indexOf(callback); | 104 let idx = callbacks.indexOf(callback); |
105 if (idx != -1) | 105 if (idx != -1) |
106 callbacks.splice(idx, 1); | 106 callbacks.splice(idx, 1); |
107 } | 107 } |
108 }, | |
109 | |
110 /** | |
111 * Disables the port and makes it stop listening to incoming messages. | |
112 */ | |
113 disconnect: function() | |
114 { | |
115 ext.onMessage.removeListener(this._onMessage); | |
108 } | 116 } |
109 }; | 117 }; |
110 | 118 |
111 /** | 119 /** |
112 * The default port to receive messages. | 120 * The default port to receive messages. |
113 * | 121 * |
114 * @type {Port} | 122 * @type {Port} |
115 */ | 123 */ |
116 exports.port = new Port(); | 124 exports.port = new Port(); |
117 | 125 |
118 /** | 126 /** |
119 * Creates a new port that is shutdown when the given window is unloaded. | 127 * Creates a new port that is disconnected when the given window is unloaded. |
120 * | 128 * |
121 * @param {Window} window | 129 * @param {Window} window |
122 * @return {Port} | 130 * @return {Port} |
123 */ | 131 */ |
124 exports.getPort = function(window) | 132 exports.getPort = function(window) |
125 { | 133 { |
126 let port = new Port(); | 134 let port = new Port(); |
127 window.addEventListener("unload", () => | 135 window.addEventListener("unload", () => |
128 { | 136 { |
129 ext.onMessage.removeListener(port._onMessage); | 137 port.disconnect(); |
130 }); | 138 }); |
Wladimir Palant
2016/03/21 15:50:13
Please consider caching the port per window so tha
Sebastian Noack
2016/03/21 17:15:42
Done.
| |
131 return port; | 139 return port; |
132 }; | 140 }; |
133 | 141 |
LEFT | RIGHT |