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: Created March 22, 2018, 8:45 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
« dependencies ('K') | « 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,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)
}
]
« dependencies ('K') | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld