Skip to content

Commit

Permalink
pass along replaced widgets info to popup and append to expandable se…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
ablanathtanalba committed Sep 23, 2021
1 parent 90abda2 commit ad1265d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,13 @@ function refreshPopup() {

// if there are replaced widgets, get their names and append to that popup section
if (Object.keys(POPUP_DATA.replacedWidgets).length) {
let name = POPUP_DATA.replacedWidgets.name;
// prevent duplicate names from appearing, only append if it doesn't already exist
if (!$('#instructions-widgets-description li:contains("' + name + '")').length) {
$("#instructions-widgets-description").append("<li>" + name + "</li>");
for (let widget in POPUP_DATA.replacedWidgets) {
POPUP_DATA.replacedWidgets[widget].forEach((widgetType) => {
// prevent duplicate names from appearing, only append if it doesn't already exist
if (!$('#instructions-widgets-description li:contains("' + widgetType + '")').length) {
$("#instructions-widgets-description").append("<li>" + widgetType + "</li>");
}
});
}
}

Expand Down
31 changes: 30 additions & 1 deletion src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ let constants = require("constants"),

/************ Local Variables *****************/
let tempAllowlist = {},
tempAllowedWidgets = {};
tempAllowedWidgets = {},
replacedWidgets = {};

/***************** Blocking Listener Functions **************/

Expand Down Expand Up @@ -882,6 +883,7 @@ function dispatcher(request, sender, sendResponse) {
"getBlockedFrameUrls",
"getReplacementButton",
"inspectLocalStorage",
"sendReplacedWidgetsToPopup",
"supercookieReport",
"unblockWidget",
];
Expand Down Expand Up @@ -1062,6 +1064,25 @@ function dispatcher(request, sender, sendResponse) {
break;
}

case "sendReplacedWidgetsToPopup": {
let tab_host;
// iframes send unreliable host responses, sender url and falsey frameId is to get top-level host
if (sender.frameId == 0 && sender.url) {
tab_host = sender.url;
}

// avoid setting undefined properties on local replaced widgets array, but establish a property for known host
if (!replacedWidgets[tab_host] && tab_host) {
replacedWidgets[tab_host] = [];
}

// only save widget name if it's not already present in local widgets array
if (!replacedWidgets[tab_host].includes(request.widgetName)) {
replacedWidgets[tab_host].push(request.widgetName);
}
break;
}

case "getPopupData": {
let tab_id = request.tabId;

Expand All @@ -1085,6 +1106,13 @@ function dispatcher(request, sender, sendResponse) {
}
}

// before sending response, remove old replaced widgets information from previous tabs
for (let host in replacedWidgets) {
if (!host.includes(tab_host)) {
delete replacedWidgets[host];
}
}

sendResponse({
cookieblocked,
criticalError: badger.criticalError,
Expand All @@ -1093,6 +1121,7 @@ function dispatcher(request, sender, sendResponse) {
isOnFirstParty: utils.firstPartyProtectionsEnabled(tab_host),
noTabData: false,
origins,
replacedWidgets: replacedWidgets,
settings: badger.getSettings().getItemClones(),
showLearningPrompt: badger.getPrivateSettings().getItem("showLearningPrompt"),
showWebRtcDeprecation: !!badger.getPrivateSettings().getItem("showWebRtcDeprecation"),
Expand Down

0 comments on commit ad1265d

Please sign in to comment.