Commit 64651b9f authored by Thomas Greiner's avatar Thomas Greiner Committed by Winsley

Issue 7110 - Only show icon popup notification for pages that match URL filters

parent 98dc4f34
......@@ -234,6 +234,7 @@ See [`filterNotifier`][filternotifier].
- **string** [displayMethod] - (see [`displayMethods`](https://hg.adblockplus.org/adblockpluschrome/file/master/lib/notificationHelper.js))
- (deprecated) **string** locale
- **string** [url]
**Response**
......
......@@ -22,6 +22,7 @@ require("./popup.notifications.js");
const setupToggle = require("./popup.toggle.js");
const setupBlock = require("./popup.blockelement.js");
const {activeTab} = require("./popup.utils.js");
const {$, $$} = require("./dom");
const {
......
......@@ -17,26 +17,26 @@
"use strict";
const {getDocLinks, setPref} = require("./popup.utils.js");
const {activeTab, getDocLinks, setPref} = require("./popup.utils.js");
const {wire} = require("./io-element");
const {$} = require("./dom");
window.addEventListener(
"load", () =>
activeTab
.then((tab) =>
{
browser.runtime.sendMessage({
return browser.runtime.sendMessage({
type: "notifications.get",
displayMethod: "popup"
}, notification =>
{
if (notification)
window.dispatchEvent(
new CustomEvent("extension:notification", {detail: notification})
);
displayMethod: "popup",
url: tab.url
});
},
{once: true}
);
})
.then((notification) =>
{
if (notification)
window.dispatchEvent(
new CustomEvent("extension:notification", {detail: notification})
);
});
// Using an event to make testing as easy as possible.
/* @example
......
"use strict";
// create the tab object once at the right time
const activeTab = new Promise(
resolve =>
{
document.addEventListener("DOMContentLoaded", () =>
{
browser.tabs.query({active: true, lastFocusedWindow: true}, tabs =>
{
resolve({id: tabs[0].id, url: tabs[0].url});
});
}, {once: true});
}
);
function getDocLinks(notification)
{
if (!notification.links)
......@@ -84,6 +98,7 @@ function whenPageReady(tab)
}
module.exports = {
activeTab,
getDocLinks,
getPref,
isPageWhitelisted,
......
......@@ -26,7 +26,7 @@
const {Utils} = require("utils");
const {filterStorage} = require("filterStorage");
const {filterNotifier} = require("filterNotifier");
const {defaultMatcher} = require("matcher");
const {defaultMatcher, Matcher} = require("matcher");
const {Notification: NotificationStorage} = require("notification");
const {getActiveNotification, shouldDisplay,
notificationClicked} = require("notificationHelper");
......@@ -403,6 +403,35 @@
!shouldDisplay(message.displayMethod, notification.type))
return;
// Determine whether to return a notification that's targeting certain sites
// See also https://hg.adblockplus.org/adblockpluscore/file/56c681657836/lib/notification.js#l301
if (notification.urlFilters instanceof Array)
{
const {url} = message;
if (!url)
return;
let host;
try
{
host = new URL(url).hostname;
}
catch (e)
{
return;
}
const matcher = new Matcher();
for (const urlFilter of notification.urlFilters)
{
matcher.add(Filter.fromText(urlFilter));
}
const {DOCUMENT} = RegExpFilter.typeMap;
if (!matcher.matchesAny(url, DOCUMENT, host, false, null))
return;
}
const texts = NotificationStorage.getLocalizedTexts(notification,
message.locale);
return Object.assign({texts}, notification);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment