Left: | ||
Right: |
OLD | NEW |
---|---|
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 "use strict"; |
19 | |
19 { | 20 { |
Wladimir Palant
2017/03/09 15:05:07
Here we have no functions declared so strictly spe
kzar
2017/03/10 07:28:59
Done.
| |
20 if (!global.ext) | 21 if (typeof ext == "undefined") |
21 global.ext = {}; | 22 window.ext = {}; |
22 | 23 |
23 var backgroundFrame = document.createElement("iframe"); | 24 let backgroundFrame = document.createElement("iframe"); |
24 backgroundFrame.setAttribute("src", "background.html" + window.location.search ); | 25 backgroundFrame.setAttribute("src", |
26 "background.html" + window.location.search); | |
25 backgroundFrame.style.display = "none"; | 27 backgroundFrame.style.display = "none"; |
26 window.addEventListener("DOMContentLoaded", function() | 28 window.addEventListener("DOMContentLoaded", () => |
27 { | 29 { |
28 document.body.appendChild(backgroundFrame); | 30 document.body.appendChild(backgroundFrame); |
29 }, false); | 31 }, false); |
30 | 32 |
31 var messageQueue = []; | 33 let messageQueue = []; |
32 var maxMessageId = -1; | 34 let maxMessageId = -1; |
33 var loadHandler = function(event) | 35 let loadHandler = (event) => |
34 { | 36 { |
35 if (event.data.type == "backgroundPageLoaded") | 37 if (event.data.type == "backgroundPageLoaded") |
36 { | 38 { |
37 var queue = messageQueue; | 39 let queue = messageQueue; |
38 messageQueue = null; | 40 messageQueue = null; |
39 if (queue) | 41 if (queue) |
40 for (var i = 0; i < queue.length; i++) | 42 { |
41 backgroundFrame.contentWindow.postMessage(queue[i], "*"); | 43 for (let message of queue) |
44 backgroundFrame.contentWindow.postMessage(message, "*"); | |
45 } | |
42 window.removeEventListener("message", loadHandler, false); | 46 window.removeEventListener("message", loadHandler, false); |
43 } | 47 } |
44 } | 48 }; |
45 window.addEventListener("message", loadHandler, false); | 49 window.addEventListener("message", loadHandler, false); |
46 | 50 |
47 global.ext.backgroundPage = { | 51 ext.backgroundPage = { |
48 _sendRawMessage: function(message) | 52 _sendRawMessage(message) |
49 { | 53 { |
50 if (messageQueue) | 54 if (messageQueue) |
51 messageQueue.push(message); | 55 messageQueue.push(message); |
52 else | 56 else |
53 backgroundFrame.contentWindow.postMessage(message, "*"); | 57 backgroundFrame.contentWindow.postMessage(message, "*"); |
54 }, | 58 }, |
55 sendMessage: function(message, responseCallback) | 59 sendMessage(message, responseCallback) |
56 { | 60 { |
57 var messageId = ++maxMessageId; | 61 let messageId = ++maxMessageId; |
58 | 62 |
59 this._sendRawMessage({ | 63 this._sendRawMessage({ |
60 type: "message", | 64 type: "message", |
61 messageId: messageId, | 65 messageId, |
62 payload: message | 66 payload: message |
63 }); | 67 }); |
64 | 68 |
65 if (responseCallback) | 69 if (responseCallback) |
66 { | 70 { |
67 var callbackWrapper = function(event) | 71 let callbackWrapper = function(event) |
68 { | 72 { |
69 if (event.data.type == "response" && event.data.messageId == messageId ) | 73 if (event.data.type == "response" && |
74 event.data.messageId == messageId) | |
70 { | 75 { |
71 window.removeEventListener("message", callbackWrapper, false); | 76 window.removeEventListener("message", callbackWrapper, false); |
72 responseCallback(event.data.payload); | 77 responseCallback(event.data.payload); |
73 } | 78 } |
74 }; | 79 }; |
75 window.addEventListener("message", callbackWrapper, false); | 80 window.addEventListener("message", callbackWrapper, false); |
76 } | 81 } |
77 } | 82 } |
78 }; | 83 }; |
79 })(this); | 84 } |
OLD | NEW |