-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only replace widgets that were actually blocked #2484
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghostwords
added
the
widgets
Click-to-activate placeholders for blocked but potentially useful social buttons/widgets
label
Oct 21, 2019
ghostwords
force-pushed
the
only-replace-actually-blocked-widgets
branch
2 times, most recently
from
October 22, 2019 16:48
9e14a35
to
6adfcf5
Compare
Instead of hypothetically blocked (which doesn't account for page context, for instance).
ghostwords
force-pushed
the
only-replace-actually-blocked-widgets
branch
from
October 22, 2019 17:13
6adfcf5
to
8cd0215
Compare
As we only actually need domains.
Should adapt 94863c7 following #2438. Needs to be updated to accommodate new users of 94863c7.patchMove replacement widget data loading.
To the place it's used.
---
src/js/background.js | 6 ------
src/js/webrequest.js | 31 ++++++++++++++++++++++++-------
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/js/background.js b/src/js/background.js
index f79f64851..49dfe6187 100644
--- a/src/js/background.js
+++ b/src/js/background.js
@@ -27,7 +27,6 @@ var pbStorage = require("storage");
var HeuristicBlocking = require("heuristicblocking");
var FirefoxAndroid = require("firefoxandroid");
var webrequest = require("webrequest");
-var widgetLoader = require("widgetloader");
var Migrations = require("migrations").Migrations;
var incognito = require("incognito");
@@ -50,11 +49,6 @@ function Badger(from_qunit) {
self.webRTCAvailable = checkWebRTCBrowserSupport();
self.firstPartyDomainPotentiallyRequired = testCookiesFirstPartyDomain();
- self.widgetList = [];
- widgetLoader.loadWidgetsFromFile("data/socialwidgets.json", (response) => {
- self.widgetList = response;
- });
-
self.storage = new pbStorage.BadgerPen(async function (thisStorage) {
self.initializeDefaultSettings();
self.heuristicBlocking = new HeuristicBlocking.HeuristicBlocker(thisStorage);
diff --git a/src/js/webrequest.js b/src/js/webrequest.js
index 2099e92a6..d477b04c7 100644
--- a/src/js/webrequest.js
+++ b/src/js/webrequest.js
@@ -32,6 +32,7 @@ var constants = require("constants");
var getSurrogateURI = require("surrogates").getSurrogateURI;
var incognito = require("incognito");
var utils = require("utils");
+var widgetLoader = require("widgetloader");
/************ Local Variables *****************/
let temporaryWidgetUnblock = {};
@@ -513,7 +514,17 @@ let getWidgetBlockList = (function () {
{ key: "allow_once" },
];
- return function () {
+ // cached widget list
+ let widgetList;
+
+ // start loading the widget list from disk
+ let widgetListPromise = new Promise(resolve => {
+ widgetLoader.loadWidgetsFromFile("data/socialwidgets.json", response => {
+ resolve(response);
+ });
+ }).catch(console.error);
+
+ return async function () {
// A mapping of individual SocialWidget objects to boolean values that determine
// whether the content script should replace that tracker's button/widget
var widgetsToReplace = {};
@@ -527,7 +538,9 @@ let getWidgetBlockList = (function () {
}, {});
}
- badger.widgetList.forEach(function (widget) {
+ widgetList = await widgetListPromise;
+
+ widgetList.forEach(function (widget) {
// Only replace blocked and yellowlisted widgets
widgetsToReplace[widget.name] = constants.BLOCKED_ACTIONS.has(
badger.storage.getBestAction(widget.domain)
@@ -536,7 +549,7 @@ let getWidgetBlockList = (function () {
return {
translations,
- trackers: badger.widgetList,
+ trackers: widgetList,
trackerButtonsToReplace: widgetsToReplace
};
};
@@ -612,8 +625,12 @@ function dispatcher(request, sender, sendResponse) {
} else if (request.checkReplaceButton) {
if (badger.isPrivacyBadgerEnabled(window.extractHostFromURL(sender.tab.url)) && badger.isWidgetReplacementEnabled()) {
- let widgetBlockList = getWidgetBlockList();
- sendResponse(widgetBlockList);
+ getWidgetBlockList().then(widgetBlockList => {
+ sendResponse(widgetBlockList);
+ }).catch(console.error);
+
+ // indicate this is an async response to chrome.runtime.onMessage
+ return true;
}
} else if (request.unblockWidget) {
@@ -760,7 +777,7 @@ function dispatcher(request, sender, sendResponse) {
});
}
});
- //indicate this is an async response to chrome.runtime.onMessage
+ // indicate this is an async response to chrome.runtime.onMessage
return true;
} else if (request.type == "uploadCloud") {
@@ -773,7 +790,7 @@ function dispatcher(request, sender, sendResponse) {
sendResponse({success: true});
}
});
- //indicate this is an async response to chrome.runtime.onMessage
+ // indicate this is an async response to chrome.runtime.onMessage
return true;
} else if (request.type == "savePopupToggle") { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
widgets
Click-to-activate placeholders for blocked but potentially useful social buttons/widgets
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of hypothetically blocked (which doesn't account for page context, for instance).
Fixes pointless first-party replacement (for example).
Should follow #2267.