summaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorhackademix2018-08-22 16:34:16 +0200
committerhackademix2018-08-22 16:34:16 +0200
commit075a5ad0e0f9b4f9af614194d9c8d21d0ed45184 (patch)
treecc341040d0515e54ec8466dec8d3e32c381f1457 /src/content
parent48c04726b8d2da0023abd0ccef3e2d09511bea47 (diff)
downloadnoscript-075a5ad0e0f9b4f9af614194d9c8d21d0ed45184.tar.gz
noscript-075a5ad0e0f9b4f9af614194d9c8d21d0ed45184.tar.xz
noscript-075a5ad0e0f9b4f9af614194d9c8d21d0ed45184.zip
More coherent wrapper around the webex messaging API.
Diffstat (limited to 'src/content')
-rw-r--r--src/content/PlaceHolder.js3
-rw-r--r--src/content/content.js15
2 files changed, 4 insertions, 14 deletions
diff --git a/src/content/PlaceHolder.js b/src/content/PlaceHolder.js
index 764b7bc..ec2ab5b 100644
--- a/src/content/PlaceHolder.js
+++ b/src/content/PlaceHolder.js
@@ -116,8 +116,7 @@ var PlaceHolder = (() => {
async enable(replacement) {
debug("Enabling %o", this.request, this.policyType);
- let ok = await browser.runtime.sendMessage({
- action: "enable",
+ let ok = await Messages.send("enable", {
url: this.request.url,
policyType: this.policyType,
documentUrl: document.URL
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) {