| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 const {require} = chrome.extension.getBackgroundPage(); | |
| 21 | |
| 22 let messageQueue = []; | |
| 23 | |
| 24 let iframe = document.getElementById("content"); | 20 let iframe = document.getElementById("content"); |
| 25 | 21 |
| 26 function queueMessage(message, sender, sendResponse) | 22 iframe.onload = () => |
| 27 { | 23 { |
| 28 // Ignore messages from anywhere but the background page. | 24 document.title = iframe.contentDocument.title; |
|
Manish Jethani
2017/09/26 20:37:15
Now there's no need to queue messages, all of this
| |
| 29 if (sender.tab || | 25 }; |
| 30 sender.url && sender.url != chrome.extension.getBackgroundPage().location) | |
| 31 { | |
| 32 return; | |
| 33 } | |
| 34 | 26 |
| 35 messageQueue.push({message, sendResponse}); | 27 chrome.runtime.sendMessage({ |
|
Oleksandr
2017/10/09 11:49:59
Edge does not support the 'chrome' namespace for e
Manish Jethani
2017/10/09 12:00:55
Thanks.
Sebastian Noack
2017/10/09 15:09:55
Note that we already do so in ext/common.js:
https
| |
| 36 } | 28 type: "app.get", |
| 37 | 29 what: "application" |
| 38 function handleContentLoad(event) | 30 }, |
| 31 application => | |
| 39 { | 32 { |
| 40 iframe.onload = null; | 33 // Load the mobile version of the options page on Firefox for Android. |
| 41 | 34 iframe.src = iframe.getAttribute("data-src-" + application) || |
| 42 chrome.runtime.onMessage.removeListener(queueMessage); | 35 iframe.getAttribute("data-src"); |
| 43 | 36 }); |
| 44 document.title = iframe.contentDocument.title; | |
|
Manish Jethani
2017/09/19 19:42:05
Update title.
| |
| 45 | |
| 46 // Make a local reference to the message queue and release the global | |
| 47 // reference to avoid any memory leaks. | |
| 48 let messageQueueLocalReference = messageQueue; | |
| 49 messageQueue = null; | |
| 50 | |
| 51 // Process message queue. | |
| 52 for (let {message, sendResponse} of messageQueueLocalReference) | |
| 53 iframe.contentWindow.ext.onMessage._dispatch(message, {}, sendResponse); | |
| 54 } | |
| 55 | |
| 56 // Queue up messages from the background page until the content has finished | |
| 57 // loading. | |
| 58 chrome.runtime.onMessage.addListener(queueMessage); | |
| 59 | |
| 60 // When the content has finished loading, stop listening for messages from the | |
| 61 // background page and forward all the queued up messages to the content | |
| 62 // document. | |
| 63 iframe.onload = handleContentLoad; | |
| 64 | |
| 65 // Load the mobile version of the options page on Firefox for Android. | |
| 66 iframe.src = iframe.getAttribute("data-src-" + require("info").application) || | |
| 67 iframe.getAttribute("data-src"); | |
| LEFT | RIGHT |