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

Delta Between Two Patch Sets: ext/content.js

Issue 29573905: Issue 4580 - Replace ext.devtools with devtools Base URL: https://hg.adblockplus.org/adblockplusui/
Left Patch Set: Fix ESLint errors Created Oct. 11, 2017, 11:47 p.m.
Right Patch Set: Rebase Created Oct. 18, 2017, 1:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « ext/background.js ('k') | ext/devtools.js » ('j') | polyfill.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 "use strict"; 18 "use strict";
19 19
20 (function() 20 (function()
21 { 21 {
22 if (typeof ext == "undefined")
23 window.ext = {};
24
25 let backgroundFrame = document.createElement("iframe"); 22 let backgroundFrame = document.createElement("iframe");
26 backgroundFrame.setAttribute("src", 23 backgroundFrame.setAttribute("src",
27 "background.html" + window.location.search); 24 "background.html" + window.location.search);
28 backgroundFrame.style.display = "none"; 25 backgroundFrame.style.display = "none";
29 window.addEventListener("DOMContentLoaded", () => 26 window.addEventListener("DOMContentLoaded", () =>
30 { 27 {
31 document.body.appendChild(backgroundFrame); 28 document.body.appendChild(backgroundFrame);
32 }); 29 });
33
34 let messageQueue = [];
35 let maxMessageId = -1;
36 let loadHandler = (event) =>
37 {
38 if (event.data.type == "backgroundPageLoaded")
39 {
40 let queue = messageQueue;
41 messageQueue = null;
42 if (queue)
43 {
44 for (let message of queue)
45 backgroundFrame.contentWindow.postMessage(message, "*");
46 }
47 window.removeEventListener("message", loadHandler);
48 }
49 };
50 window.addEventListener("message", loadHandler);
51
52 /* Polyfills */
53
54 if (!("runtime" in chrome))
55 chrome.runtime = {};
56
57 chrome.runtime.sendMessage = (message, responseCallback) =>
58 {
59 let messageId = ++maxMessageId;
60
61 let rawMessage = {type: "message", messageId, payload: message};
62
63 if (messageQueue)
64 messageQueue.push(rawMessage);
65 else
66 backgroundFrame.contentWindow.postMessage(rawMessage, "*");
67
68 if (responseCallback)
69 {
70 let callbackWrapper = event =>
71 {
72 if (event.data.type == "response" && event.data.messageId == messageId)
73 {
74 window.removeEventListener("message", callbackWrapper);
75 responseCallback(event.data.payload);
76 }
77 };
78
79 window.addEventListener("message", callbackWrapper);
80 }
81 };
82 }()); 30 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld