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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ext/background.js ('k') | ext/devtools.js » ('j') | polyfill.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
- }
- };
}());
« no previous file with comments | « ext/background.js ('k') | ext/devtools.js » ('j') | polyfill.js » ('J')

Powered by Google App Engine
This is Rietveld