Index: lib/options.js |
=================================================================== |
--- a/lib/options.js |
+++ b/lib/options.js |
@@ -16,17 +16,16 @@ |
*/ |
/** @module options */ |
"use strict"; |
const {getDecodedHostname} = require("url"); |
const {checkWhitelisted} = require("whitelisting"); |
-const {port} = require("messaging"); |
const info = require("info"); |
const optionsUrl = "options.html"; |
function findOptionsTab(callback) |
{ |
browser.tabs.query({}, tabs => |
{ |
@@ -102,27 +101,36 @@ |
// If we don't already have an options page, it means we've just opened |
// one, in which case we must find the tab, wait for it to be ready, and |
// then return the call. |
findOptionsTab(tab => |
{ |
if (!tab) |
return; |
- function onMessage(message, sender) |
+ function onMessage(message, port) |
{ |
- if (message.type == "app.listen" && |
- sender.page && sender.page.id == tab.id) |
- { |
- port.off("app.listen", onMessage); |
- callback(new ext.Page(tab)); |
- } |
+ if (message.type != "app.listen") |
+ return; |
+ |
+ port.onMessage.removeListener(onMessage); |
+ callback(new ext.Page(tab), port); |
} |
- port.on("app.listen", onMessage); |
+ function onConnect(port) |
+ { |
+ let {name, sender} = port; |
Sebastian Noack
2018/03/23 00:01:48
Nit: I wouldn't care to destructure the port here,
saroyanm
2018/03/23 12:03:18
Done.
|
+ if (name != "ui" || !sender || sender.tab.id != tab.id) |
Sebastian Noack
2018/03/23 00:01:48
Under which circumstances do we need to check for
saroyanm
2018/03/23 11:26:47
I assume because this is optional, but according t
saroyanm
2018/03/23 12:03:17
Done.
|
+ return; |
+ |
+ browser.runtime.onConnect.removeListener(onConnect); |
+ port.onMessage.addListener(onMessage); |
+ } |
+ |
+ browser.runtime.onConnect.addListener(onConnect); |
}); |
} |
} |
let showOptions = |
/** |
* Opens the options page. |
* |
@@ -192,22 +200,22 @@ |
// On Firefox for Android, open the options page directly when the browser |
// action is clicked. |
browser.browserAction.onClicked.addListener(() => |
{ |
browser.tabs.query({active: true, lastFocusedWindow: true}, ([tab]) => |
{ |
let currentPage = new ext.Page(tab); |
- showOptions(optionsPage => |
+ showOptions((optionsPage, port) => |
{ |
if (!/^https?:$/.test(currentPage.url.protocol)) |
return; |
- optionsPage.sendMessage({ |
+ port.postMessage({ |
Sebastian Noack
2018/03/23 00:01:48
Nit: The indentation is off here.
saroyanm
2018/03/23 12:03:18
Done.
|
type: "app.respond", |
action: "showPageOptions", |
args: [ |
{ |
host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), |
whitelisted: !!checkWhitelisted(currentPage) |
} |
] |