From 075a5ad0e0f9b4f9af614194d9c8d21d0ed45184 Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 22 Aug 2018 16:34:16 +0200 Subject: More coherent wrapper around the webex messaging API. --- src/content/content.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/content/content.js') diff --git a/src/content/content.js b/src/content/content.js index d5adc94..22dbf1e 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -114,8 +114,7 @@ var seen = { } } -var handlers = { - +Messages.addHandler({ seen(event) { let {allowed, policyType, request, ownFrame} = event; if (window.top === window) { @@ -129,19 +128,11 @@ var handlers = { } } }, - collect(event) { let list = seen.list; debug("COLLECT", list); return list; } -}; - -browser.runtime.onMessage.addListener(async event => { - if (event.type in handlers) { - debug("Received message", event); - return handlers[event.type](event); - } }); if (document.readyState !== "complete") { @@ -157,7 +148,7 @@ let notifyPage = async () => { debug("Page %s shown, %s", document.URL, document.readyState); if (document.readyState === "complete") { try { - await browser.runtime.sendMessage({action: "pageshow", seen: seen.list, canScript}); + await Messages.send("pageshow", {seen: seen.list, canScript}); return true; } catch (e) { debug(e); @@ -184,7 +175,7 @@ async function init(oldPage = false) { document.URL, document.contentType, document.readyState, window.frameElement && frameElement.data); try { - ({canScript, shouldScript} = await browser.runtime.sendMessage({action: "docStatus", url: document.URL})); + ({canScript, shouldScript} = await Messages.send("queryDocStatus", {url: document.URL})); debug(`document %s, canScript=%s, shouldScript=%s, readyState %s`, document.URL, canScript, shouldScript, document.readyState); if (canScript) { if (oldPage) { -- cgit v1.2.3