Index: ext/content.js |
=================================================================== |
--- a/ext/content.js |
+++ b/ext/content.js |
@@ -14,78 +14,17 @@ |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
"use strict"; |
(function() |
{ |
- if (typeof ext == "undefined") |
- window.ext = {}; |
- |
let backgroundFrame = document.createElement("iframe"); |
backgroundFrame.setAttribute("src", |
"background.html" + window.location.search); |
backgroundFrame.style.display = "none"; |
window.addEventListener("DOMContentLoaded", () => |
{ |
document.body.appendChild(backgroundFrame); |
}); |
- |
- let messageQueue = []; |
- let maxMessageId = -1; |
- let loadHandler = (event) => |
- { |
- if (event.data.type == "backgroundPageLoaded") |
- { |
- let queue = messageQueue; |
- messageQueue = null; |
- if (queue) |
- { |
- for (let message of queue) |
- backgroundFrame.contentWindow.postMessage(message, "*"); |
- } |
- window.removeEventListener("message", loadHandler); |
- } |
- }; |
- window.addEventListener("message", loadHandler); |
- |
- ext.backgroundPage = { |
- _sendRawMessage(message) |
- { |
- if (messageQueue) |
- messageQueue.push(message); |
- else |
- backgroundFrame.contentWindow.postMessage(message, "*"); |
- } |
- }; |
- |
- /* Polyfills */ |
- |
- if (!("runtime" in browser)) |
- browser.runtime = {}; |
- |
- browser.runtime.sendMessage = (message, responseCallback) => |
- { |
- let messageId = ++maxMessageId; |
- |
- ext.backgroundPage._sendRawMessage({ |
- type: "message", |
- messageId, |
- payload: message |
- }); |
- |
- if (responseCallback) |
- { |
- let callbackWrapper = event => |
- { |
- if (event.data.type == "response" && event.data.messageId == messageId) |
- { |
- window.removeEventListener("message", callbackWrapper); |
- responseCallback(event.data.payload); |
- } |
- }; |
- |
- window.addEventListener("message", callbackWrapper); |
- } |
- }; |
}()); |