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 9e14a35
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 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 @@ -561,13 +563,19 @@ 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);
let replace = !badger.getSettings().getItem('widgetReplacementExceptions').includes(widget.name);

if (replace && badger.tabData.hasOwnProperty(tab_id)) {
if (badger.tabData[tab_id].origins.hasOwnProperty(widget.domain)) {
const action = badger.tabData[tab_id].origins[widget.domain];
replace = (
action == constants.BLOCK ||
action == constants.USER_BLOCK
);
}
}

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

return {
Expand Down Expand Up @@ -679,7 +687,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 9e14a35

Please sign in to comment.