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: Use Location.pathname Created Oct. 18, 2017, 12:23 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
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
(...skipping 12 matching lines...) Expand all
23 window.ext = {}; 23 window.ext = {};
24 24
25 let backgroundFrame = document.createElement("iframe"); 25 let backgroundFrame = document.createElement("iframe");
26 backgroundFrame.setAttribute("src", 26 backgroundFrame.setAttribute("src",
27 "background.html" + window.location.search); 27 "background.html" + window.location.search);
28 backgroundFrame.style.display = "none"; 28 backgroundFrame.style.display = "none";
29 window.addEventListener("DOMContentLoaded", () => 29 window.addEventListener("DOMContentLoaded", () =>
30 { 30 {
31 document.body.appendChild(backgroundFrame); 31 document.body.appendChild(backgroundFrame);
32 }); 32 });
33 33
Manish Jethani 2017/10/18 01:41:31 All of this code has moved to polyfill.js
34 let messageQueue = []; 34 let messageQueue = [];
35 let maxMessageId = -1; 35 let maxMessageId = -1;
36 let loadHandler = (event) => 36 let loadHandler = (event) =>
37 { 37 {
38 if (event.data.type == "backgroundPageLoaded") 38 if (event.data.type == "backgroundPageLoaded")
39 { 39 {
40 let queue = messageQueue; 40 let queue = messageQueue;
41 messageQueue = null; 41 messageQueue = null;
42 if (queue) 42 if (queue)
43 { 43 {
44 for (let message of queue) 44 for (let message of queue)
45 backgroundFrame.contentWindow.postMessage(message, "*"); 45 backgroundFrame.contentWindow.postMessage(message, "*");
46 } 46 }
47 window.removeEventListener("message", loadHandler); 47 window.removeEventListener("message", loadHandler);
48 } 48 }
49 }; 49 };
50 window.addEventListener("message", loadHandler); 50 window.addEventListener("message", loadHandler);
51 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 */ 52 /* Polyfills */
63 53
64 if (!("runtime" in chrome)) 54 if (!("runtime" in chrome))
65 chrome.runtime = {}; 55 chrome.runtime = {};
66 56
57 function sendRawMessage(message)
58 {
59 if (messageQueue)
60 messageQueue.push(message);
61 else
62 backgroundFrame.contentWindow.postMessage(message, "*");
63 }
64
65 chrome.runtime.connect = () =>
66 {
67 sendRawMessage({type: "connect"});
68 return {onMessage: ext.onMessage};
69 };
70
67 chrome.runtime.sendMessage = (message, responseCallback) => 71 chrome.runtime.sendMessage = (message, responseCallback) =>
68 { 72 {
69 let messageId = ++maxMessageId; 73 let messageId = ++maxMessageId;
70 74
71 ext.backgroundPage._sendRawMessage({ 75 sendRawMessage({type: "message", messageId, payload: message});
72 type: "message",
73 messageId,
74 payload: message
75 });
76 76
77 if (responseCallback) 77 if (responseCallback)
78 { 78 {
79 let callbackWrapper = event => 79 let callbackWrapper = event =>
80 { 80 {
81 if (event.data.type == "response" && event.data.messageId == messageId) 81 if (event.data.type == "response" && event.data.messageId == messageId)
82 { 82 {
83 window.removeEventListener("message", callbackWrapper); 83 window.removeEventListener("message", callbackWrapper);
84 responseCallback(event.data.payload); 84 responseCallback(event.data.payload);
85 } 85 }
86 }; 86 };
87 87
88 window.addEventListener("message", callbackWrapper); 88 window.addEventListener("message", callbackWrapper);
89 } 89 }
90 }; 90 };
91 }()); 91 }());
OLDNEW
« ext/common.js ('K') | « ext/common.js ('k') | ext/devtools.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld