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

Unified Diff: lib/options.js

Issue 29730656: Issue 6476 - Update adblockplusui dependencies to ead38c2013b5 (Closed)
Patch Set: Updated dependency to ead38c2013b5 Created March 23, 2018, 12:14 p.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 | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
}
]
« no previous file with comments | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld