| 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,35 @@ |
| // 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) |
| + { |
| + if (port.name != "ui" || port.sender.tab.id != tab.id) |
| + return; |
| + |
| + browser.runtime.onConnect.removeListener(onConnect); |
| + port.onMessage.addListener(onMessage); |
| + } |
| + |
| + browser.runtime.onConnect.addListener(onConnect); |
| }); |
| } |
| } |
| let showOptions = |
| /** |
| * Opens the options page. |
| * |
| @@ -192,22 +199,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({ |
| type: "app.respond", |
| action: "showPageOptions", |
| args: [ |
| { |
| host: getDecodedHostname(currentPage.url).replace(/^www\./, ""), |
| whitelisted: !!checkWhitelisted(currentPage) |
| } |
| ] |