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

Side by Side Diff: ext/content.js

Issue 29573905: Issue 4580 - Replace ext.devtools with devtools Base URL: https://hg.adblockplus.org/adblockplusui/
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:
View unified diff | Download patch
« no previous file with comments | « 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')
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-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 ext.backgroundPage = {
53 _sendRawMessage(message)
54 {
55 if (messageQueue)
56 messageQueue.push(message);
57 else
58 backgroundFrame.contentWindow.postMessage(message, "*");
59 }
60 };
61
62 /* Polyfills */
63
64 if (!("runtime" in browser))
65 browser.runtime = {};
66
67 browser.runtime.sendMessage = (message, responseCallback) =>
68 {
69 let messageId = ++maxMessageId;
70
71 ext.backgroundPage._sendRawMessage({
72 type: "message",
73 messageId,
74 payload: message
75 });
76
77 if (responseCallback)
78 {
79 let callbackWrapper = event =>
80 {
81 if (event.data.type == "response" && event.data.messageId == messageId)
82 {
83 window.removeEventListener("message", callbackWrapper);
84 responseCallback(event.data.payload);
85 }
86 };
87
88 window.addEventListener("message", callbackWrapper);
89 }
90 };
91 }()); 30 }());
OLDNEW
« no previous file with comments | « ext/background.js ('k') | ext/devtools.js » ('j') | polyfill.js » ('J')

Powered by Google App Engine
This is Rietveld