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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 (function(global) | 18 (function(global) |
19 { | 19 { |
20 if (!global.ext) | 20 if (!global.ext) |
21 global.ext = {}; | 21 global.ext = {}; |
22 | 22 |
23 let wrapperSymbol = Symbol("ext-wrapper"); | 23 var wrapperSymbol = Symbol("ext-wrapper"); |
Thomas Greiner
2016/04/18 17:47:14
Detail: I guess the `let` here is unintentional be
Wladimir Palant
2016/04/19 11:57:28
Correct, that's the problem when testing in newer
| |
24 | 24 |
25 function wrapFrames(frames) | 25 function wrapFrames(frames) |
26 { | 26 { |
27 if (!frames.length) | 27 if (!frames.length) |
28 return null; | 28 return null; |
29 | 29 |
30 // We have frames as an array, non-Firefox code expects url and parent | 30 // We have frames as an array, non-Firefox code expects url and parent |
31 // properties however. | 31 // properties however. |
32 Object.defineProperty(frames, "url", { | 32 Object.defineProperty(frames, "url", { |
33 enumerable: true, | 33 enumerable: true, |
(...skipping 19 matching lines...) Expand all Loading... | |
53 var wrapper = (message, sender) => | 53 var wrapper = (message, sender) => |
54 { | 54 { |
55 if (this._windowID && this._windowID != message.targetID) | 55 if (this._windowID && this._windowID != message.targetID) |
56 return undefined; | 56 return undefined; |
57 | 57 |
58 return new Promise((resolve, reject) => | 58 return new Promise((resolve, reject) => |
59 { | 59 { |
60 var sender = {}; | 60 var sender = {}; |
61 if (message.senderID) | 61 if (message.senderID) |
62 { | 62 { |
63 // We will only get here on the background side so we can access | |
64 // the Page object. | |
63 const Page = require("ext_background").Page; | 65 const Page = require("ext_background").Page; |
64 sender.page = new Page(message.senderID); | 66 sender.page = new Page(message.senderID); |
65 } | 67 } |
66 if (message.frames) | 68 if (message.frames) |
67 sender.frame = wrapFrames(message.frames); | 69 sender.frame = wrapFrames(message.frames); |
68 if (!listener(message.payload, sender, resolve)) | 70 if (!listener(message.payload, sender, resolve)) |
69 resolve(undefined); | 71 resolve(undefined); |
70 }); | 72 }); |
71 }; | 73 }; |
72 listener[wrapperSymbol] = wrapper; | 74 listener[wrapperSymbol] = wrapper; |
73 this._port.on("ext_message", wrapper); | 75 this._port.on("ext_message", wrapper); |
74 }, | 76 }, |
75 | 77 |
76 removeListener: function(listener) | 78 removeListener: function(listener) |
77 { | 79 { |
78 if (listener[wrapperSymbol]) | 80 if (listener[wrapperSymbol]) |
79 this._port.off("ext_message", listener[wrapperSymbol]); | 81 this._port.off("ext_message", listener[wrapperSymbol]); |
80 } | 82 } |
81 }; | 83 }; |
82 | 84 |
83 if (typeof exports == "object") | 85 if (typeof exports == "object") |
84 exports = global.ext; | 86 exports = global.ext; |
85 })(this); | 87 })(this); |
LEFT | RIGHT |