From c20006a04b2800826a8b4dd961f9aafc312fac0a Mon Sep 17 00:00:00 2001 From: Christopher Tino Date: Fri, 7 Jun 2019 12:58:14 -0400 Subject: [PATCH] CMP windows and Rewards hotdog should not be shown when Ghostery is paused. Fixes #389 --- src/background.js | 7 ++++--- src/classes/EventHandlers.js | 8 +++++++- src/classes/Rewards.js | 5 ++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/background.js b/src/background.js index 1cad93d52..79fab4457 100644 --- a/src/background.js +++ b/src/background.js @@ -1312,7 +1312,7 @@ offers.on('enabled', () => { * Set listener for 'enabled' event for Offers module. * It registers message handler for messages with the offers. * This handler adds incoming message data to the array of - * notimication messages (CMP_DATA) to be eventually displayed. + * notification messages (CMP_DATA) to be eventually displayed. * @memberOf Background */ messageCenter.on('enabled', () => { @@ -1320,7 +1320,7 @@ messageCenter.on('enabled', () => { log('IN MESSAGE CENTER ON ENABLED', offers, messageCenter); // const messageCenter = cliqz.modules['message-center']; return messageCenter.action('registerMessageHandler', OFFERS_HANDLER_ID, (msg) => { - // ffers enabled at the moment when message received + // offers enabled at the moment when message received messageCenter.action('hideMessage', OFFERS_HANDLER_ID, msg); msg.Dismiss = 1; // to be immediately dismissed once shown /** @@ -1357,7 +1357,8 @@ messageCenter.on('enabled', () => { rewards.unreadOfferIds.push(msg.data.offer_id); button.update(); - if (msg.data.offer_data.ui_info.notif_type !== 'star') { + // Don't show the Rewards hotdog if Ghostery is currently paused + if (msg.data.offer_data.ui_info.notif_type !== 'star' && !globals.SESSION.paused_blocking) { // We use getTabByUrl() instead of getActiveTab() // because user may open the offer-triggering url in a new tab // through the context menu, which may not switch to the new tab diff --git a/src/classes/EventHandlers.js b/src/classes/EventHandlers.js index 24776e50a..1fe511ab8 100644 --- a/src/classes/EventHandlers.js +++ b/src/classes/EventHandlers.js @@ -147,11 +147,17 @@ class EventHandlers { onDOMContentLoaded(details) { const tab_id = details.tabId; + // ignore if this is a sub-frame if (!utils.isValidTopLevelNavigation(details)) { return; } - // show upgrade notifications + // do not show CMP notifications if Ghostery is paused + if (globals.SESSION.paused_blocking) { + return; + } + + // show CMP upgrade notifications utils.getActiveTab((tab) => { if (!tab || tab.id !== tab_id || tab.incognito) { return; diff --git a/src/classes/Rewards.js b/src/classes/Rewards.js index 1175a0555..74ded9fd6 100644 --- a/src/classes/Rewards.js +++ b/src/classes/Rewards.js @@ -107,9 +107,8 @@ class Rewards { this.currentOffer = offer; const tab = tabInfo.getTabInfo(tab_id); - // If the tab is prefetched, we can't add purplebox to it. - if (!conf.enable_offers || - !tab || tab.rewards) { + // If the tab is prefetched, we can't add Rewards hotdog to it + if (!conf.enable_offers || !tab || tab.rewards) { return Promise.resolve(false); }