Skip to content

Commit

Permalink
Only replace widgets that were actually blocked.
Browse files Browse the repository at this point in the history
Instead of hypothetically blocked (which doesn't account
for page context, for instance).
  • Loading branch information
ghostwords committed Oct 22, 2019
1 parent db0687b commit 8cd0215
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ function _isTabAnExtension(tabId) {
/**
* Provides the widget replacing content script with list of widgets to replace.
*
* @param {Integer} tab_id the ID of the tab we're replacing widgets in
*
* @returns {Object} dict containing the complete list of widgets
* as well as a mapping to indicate which ones should be replaced
*/
Expand All @@ -544,7 +546,7 @@ let getWidgetBlockList = (function () {
{ key: "allow_once" },
];

return function () {
return function (tab_id) {
// A mapping of individual SocialWidget objects to boolean values that determine
// whether the content script should replace that tracker's button/widget
var widgetsToReplace = {};
Expand All @@ -559,15 +561,23 @@ let getWidgetBlockList = (function () {
}

badger.widgetList.forEach(function (widget) {
// replace blocked widgets only
// and only if the widget is not on the 'do not replace' list
const replace = !badger.getSettings().getItem('widgetReplacementExceptions').includes(widget.name);
const action = badger.storage.getBestAction(widget.domain);

widgetsToReplace[widget.name] = replace && (
action == constants.BLOCK ||
action == constants.USER_BLOCK
);
let replace = false;

// replace only if the widget is not on the 'do not replace' list
if (!badger.getSettings().getItem('widgetReplacementExceptions').includes(widget.name) &&
badger.tabData.hasOwnProperty(tab_id) &&
badger.tabData[tab_id].origins.hasOwnProperty(widget.domain)) {

const action = badger.tabData[tab_id].origins[widget.domain];

// and only if it was blocked
replace = (
action == constants.BLOCK ||
action == constants.USER_BLOCK
);
}

widgetsToReplace[widget.name] = replace;
});

return {
Expand Down Expand Up @@ -679,7 +689,7 @@ function dispatcher(request, sender, sendResponse) {

case "checkReplaceButton": {
if (badger.isPrivacyBadgerEnabled(window.extractHostFromURL(sender.tab.url)) && badger.isWidgetReplacementEnabled()) {
let widgetBlockList = getWidgetBlockList();
let widgetBlockList = getWidgetBlockList(sender.tab.id);
sendResponse(widgetBlockList);
}

Expand Down

0 comments on commit 8cd0215

Please sign in to comment.