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

Side by Side Diff: ext/content.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Patch Set: Avoid violating operator-linebreak rule Created March 15, 2017, 4:43 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ext/common.js ('k') | ext/devtools.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
20 (function()
19 { 21 {
20 if (!global.ext) 22 if (typeof ext == "undefined")
21 global.ext = {}; 23 window.ext = {};
22 24
23 var backgroundFrame = document.createElement("iframe"); 25 let backgroundFrame = document.createElement("iframe");
24 backgroundFrame.setAttribute("src", "background.html" + window.location.search ); 26 backgroundFrame.setAttribute("src",
27 "background.html" + window.location.search);
25 backgroundFrame.style.display = "none"; 28 backgroundFrame.style.display = "none";
26 window.addEventListener("DOMContentLoaded", function() 29 window.addEventListener("DOMContentLoaded", () =>
27 { 30 {
28 document.body.appendChild(backgroundFrame); 31 document.body.appendChild(backgroundFrame);
29 }, false); 32 }, false);
30 33
31 var messageQueue = []; 34 let messageQueue = [];
32 var maxMessageId = -1; 35 let maxMessageId = -1;
33 var loadHandler = function(event) 36 let loadHandler = (event) =>
34 { 37 {
35 if (event.data.type == "backgroundPageLoaded") 38 if (event.data.type == "backgroundPageLoaded")
36 { 39 {
37 var queue = messageQueue; 40 let queue = messageQueue;
38 messageQueue = null; 41 messageQueue = null;
39 if (queue) 42 if (queue)
40 for (var i = 0; i < queue.length; i++) 43 {
41 backgroundFrame.contentWindow.postMessage(queue[i], "*"); 44 for (let message of queue)
45 backgroundFrame.contentWindow.postMessage(message, "*");
46 }
42 window.removeEventListener("message", loadHandler, false); 47 window.removeEventListener("message", loadHandler, false);
43 } 48 }
44 } 49 };
45 window.addEventListener("message", loadHandler, false); 50 window.addEventListener("message", loadHandler, false);
46 51
47 global.ext.backgroundPage = { 52 ext.backgroundPage = {
48 _sendRawMessage: function(message) 53 _sendRawMessage(message)
49 { 54 {
50 if (messageQueue) 55 if (messageQueue)
51 messageQueue.push(message); 56 messageQueue.push(message);
52 else 57 else
53 backgroundFrame.contentWindow.postMessage(message, "*"); 58 backgroundFrame.contentWindow.postMessage(message, "*");
54 }, 59 },
55 sendMessage: function(message, responseCallback) 60 sendMessage(message, responseCallback)
56 { 61 {
57 var messageId = ++maxMessageId; 62 let messageId = ++maxMessageId;
58 63
59 this._sendRawMessage({ 64 this._sendRawMessage({
60 type: "message", 65 type: "message",
61 messageId: messageId, 66 messageId,
62 payload: message 67 payload: message
63 }); 68 });
64 69
65 if (responseCallback) 70 if (responseCallback)
66 { 71 {
67 var callbackWrapper = function(event) 72 let callbackWrapper = function(event)
68 { 73 {
69 if (event.data.type == "response" && event.data.messageId == messageId ) 74 if (event.data.type == "response" &&
75 event.data.messageId == messageId)
70 { 76 {
71 window.removeEventListener("message", callbackWrapper, false); 77 window.removeEventListener("message", callbackWrapper, false);
72 responseCallback(event.data.payload); 78 responseCallback(event.data.payload);
73 } 79 }
74 }; 80 };
75 window.addEventListener("message", callbackWrapper, false); 81 window.addEventListener("message", callbackWrapper, false);
76 } 82 }
77 } 83 }
78 }; 84 };
79 })(this); 85 }());
OLDNEW
« no previous file with comments | « ext/common.js ('k') | ext/devtools.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld