Skip to content
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

Organize sliders into expandable summary, add first party protections section #2748

Merged
merged 52 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
65ffbf0
add messages to english locale for firstparty protections info in popup
ablanathtanalba Mar 28, 2021
d14a37b
add section to popup html for firstparty protections
ablanathtanalba Mar 28, 2021
ae0809e
basic styling to firstparty section in popup
ablanathtanalba Mar 28, 2021
4e59434
add click handlers to toggle firstparty info visibility on popup
ablanathtanalba Mar 28, 2021
108661e
add popup html for toggling blocked resources visibility
ablanathtanalba Mar 28, 2021
7938eb2
add click handlers for toggling blocked resources visibility in popup
ablanathtanalba Mar 28, 2021
330322c
basic persistence of blocked resources visibility preference in popup
ablanathtanalba Mar 28, 2021
abb3fa8
fix selenium popup test by clicking to expand blocked resources section
ablanathtanalba Mar 28, 2021
d959710
fix styling edge case where no trackers detected but firstparty prote…
ablanathtanalba Mar 29, 2021
7040294
styling cleanup on firstparty text and hidden sliders in popup
ablanathtanalba Mar 29, 2021
bc6e930
add en_us message for popup click to expand tooltips
ablanathtanalba Apr 14, 2021
0bedddb
cleanup click to expand section event listeners in popup script
ablanathtanalba Apr 14, 2021
9af80f2
cleanup click handler for blocked resources section in popup
ablanathtanalba Apr 14, 2021
ca7c71d
cleanup styling for dropdown portions of popup
ablanathtanalba Apr 14, 2021
111e8a7
more css cleanup for expandable popup sections
ablanathtanalba Apr 15, 2021
97ace1f
set firstparties url schemes to badger object
ablanathtanalba Apr 22, 2021
786691f
handle checking if current tab is in firstparty protections in webreq…
ablanathtanalba Apr 22, 2021
501ccaa
cleanup popup script handlers showing firstparty and blocked resource…
ablanathtanalba Apr 22, 2021
c2a7b79
fix broken selenium popup test selecting wrong element type
ablanathtanalba Apr 22, 2021
874c3f0
simplify firstparty popup message
ablanathtanalba Apr 29, 2021
380156a
add hover transform effect on popup dropdown carets
ablanathtanalba Apr 29, 2021
53fa187
remove tooltip from dropdown sections popup
ablanathtanalba Apr 29, 2021
8d0c014
move firstparty detection method to utils
ablanathtanalba Apr 29, 2021
68b04f8
add unit test for firstparty detection util method
ablanathtanalba Apr 29, 2021
6598953
cleanup fetching manifest in background script
ablanathtanalba Apr 29, 2021
58b68b6
cleanup and delint method to check if firstparty protections are enab…
ablanathtanalba Apr 30, 2021
825d69e
fix cursor hovering error on popup expandable sections
ablanathtanalba Apr 30, 2021
63c7f3d
cleanup badger firstparties list obj and avoid false positives when l…
ablanathtanalba May 3, 2021
0c098a1
fix broken firstparty detection test script
ablanathtanalba May 3, 2021
cad1393
fix wildcard url matching firstparty detection and add test coverage
ablanathtanalba May 6, 2021
6408edb
simplify updating setting showing blocked resources container in popup
ablanathtanalba May 6, 2021
284907b
visual consistency between descriptions sections in dropdowns on popup
ablanathtanalba May 6, 2021
123b2a4
only fetch badger firstparties list when its first needed
ablanathtanalba May 10, 2021
7438813
fix broken utils text
ablanathtanalba May 10, 2021
98b2e84
Move HTML link into a placeholder
ghostwords May 12, 2021
c5fb566
Tweak locale message order
ghostwords May 12, 2021
09a602a
Tweak link tracking protection messages
ghostwords May 12, 2021
b778566
Restyle popup categories
ghostwords May 12, 2021
e4f0d64
Don't toggle slider visibility when clicking links
ghostwords May 12, 2021
5b3453a
Fix reverting control test
ghostwords May 12, 2021
1a97a81
Revert "pbInstructions" to ID as there is only one
ghostwords May 12, 2021
d2b7f5b
cleanup util method to check if firstparty protections are enabled
ablanathtanalba May 13, 2021
95dfb69
simplify checking against wildcards in firstPartyProtectionsEnabled u…
ablanathtanalba May 13, 2021
b86df58
Expand sliders always on any breakage warnings
ghostwords May 13, 2021
75127cd
Show breakage warning sliders above the rest
ghostwords May 13, 2021
48d2b2a
Tweak unit tests
ghostwords May 13, 2021
ea35530
Tweak firstPartyProtectionsEnabled() documentation
ghostwords May 13, 2021
ff82451
Tweak link tracking protection wording
ghostwords May 13, 2021
7abed9e
Fix no-tab-data (special browser page) popup state
ghostwords May 13, 2021
d6e318b
Tweak link tracking protection wording again
ghostwords May 14, 2021
9089db1
Remove unnecessary CSS IDs
ghostwords May 14, 2021
aa4fe37
Send all settings in single object to popup too
ghostwords May 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@
"message": "user-controlled",
"description": "Dropdown control setting on the Tracking Domains options page tab."
},
"popup_info_firstparty_protections": {
"message": "Link tracking protection active",
"description": "Clickable status header text in the popup. Shown when Privacy Badger's link tracking protection is active (for example, on facebook.com)."
},
"popup_info_firstparty_description": {
"message": "Some websites, such as the one you're on right now, $LINK_START$use link tracking to follow you$LINK_END$ whenever you click a link to leave the website. Privacy Badger removes this link tracking.",
"description": "Text revealed by clicking on the link tracking protection header in the popup",
"placeholders": {
"link_start": {
"content": "<a href='https://privacybadger.org/#What-about-tracking-by-the-sites-I-actively-visit%2c-like-NYTimes.com-or-Facebook.com' target='_blank'>"
},
"link_end": {
"content": "</a>"
}
}
},
"popup_instructions": {
"message": "$COUNT$ potential $LINK_START$trackers$LINK_END$ blocked",
"description": "Popup message shown when at least one tracker was blocked.",
Expand Down
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ Badger.prototype = {
seenComic: false,
sendDNTSignal: true,
showCounter: true,
showExpandedTrackingSection: false,
showIntroPage: true,
showNonTrackingDomains: false,
showTrackingDomains: false,
Expand Down
80 changes: 74 additions & 6 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ function init() {
chrome.i18n.getMessage("version", chrome.runtime.getManifest().version)
);

// add event listeners for click-to-expand blocked resources popup section
$('#tracker-list-header').on('click', toggleBlockedResourcesHandler);

// add event listeners for click-to-expand first party protections popup section
$('#firstparty-protections-header').on('click', toggleFirstPartyInfoHandler);

if (POPUP_DATA.showExpandedTrackingSection) {
$('#expand-blocked-resources').hide();
$('#collapse-blocked-resources').show();
$('#blockedResources').show();
} else {
$('#expand-blocked-resources').show();
$('#collapse-blocked-resources').hide();
// show sliders regardless when the button
// that lets you toggle slider visibility
// isn't shown for whatever reason
// (for ex.: "no trackers blocked" but we need to show
// one or more "don't appear to be tracking you" sliders)
if (!$('#tracker-list-header').is(':visible')) {
$('#blockedResources').show();
} else {
$('#blockedResources').hide();
}
}

// show firstparty protections message if current tab is in our content scripts
if (POPUP_DATA.enabled && POPUP_DATA.isOnFirstParty) {
$("#firstparty-protections-container").show();
$('#expand-firstparty-popup').show();
}

// improve on Firefox's built-in options opening logic
if (typeof browser == "object" && typeof browser.runtime.getBrowserInfo == "function") {
browser.runtime.getBrowserInfo().then(function (info) {
Expand Down Expand Up @@ -436,6 +467,48 @@ function share() {
$("#share_output").val(share_msg);
}

/**
* Click handlers for showing/hiding the blocked resources section
*/
function toggleBlockedResourcesHandler(e) {
if (e.target.nodeName.toLowerCase() == 'a') {
// don't toggle contents when clicking links in the header
return;
}
if ($("#expand-blocked-resources").is(":visible")) {
$("#collapse-blocked-resources").show();
$("#expand-blocked-resources").hide();
$("#blockedResources").slideDown();
chrome.runtime.sendMessage({
type: "updateSettings",
data: { showExpandedTrackingSection: true }
});
} else {
$("#collapse-blocked-resources").hide();
$("#expand-blocked-resources").show();
$("#blockedResources").slideUp();
chrome.runtime.sendMessage({
type: "updateSettings",
data: { showExpandedTrackingSection: false }
});
}
}

/**
* Click handler for showing/hiding the firstparty popup info text
*/
function toggleFirstPartyInfoHandler() {
if ($('#collapse-firstparty-popup').is(":visible")) {
$("#collapse-firstparty-popup").hide();
$("#expand-firstparty-popup").show();
$("#instructions-firstparty-description").slideUp();
} else {
$("#collapse-firstparty-popup").show();
$("#expand-firstparty-popup").hide();
$("#instructions-firstparty-description").slideDown();
}
}

/**
* Handler to undo user selection for a tracker
*/
Expand Down Expand Up @@ -563,9 +636,6 @@ function refreshPopup() {
htmlUtils.getOriginHtml(domain, constants.ALLOW)
);
});

// reduce margin if we have hasn't-decided-yet-to-block domains to show
$("#instructions-no-trackers").css("margin", "10px 0");
}

if (POPUP_DATA.learnLocally && POPUP_DATA.showNonTrackingDomains && nonTracking.length) {
Expand All @@ -581,9 +651,6 @@ function refreshPopup() {
htmlUtils.getOriginHtml(nonTracking[i], constants.NO_TRACKING)
);
}

// reduce margin if we have non-tracking domains to show
$("#instructions-no-trackers").css("margin", "10px 0");
}

if (printable.length) {
Expand All @@ -602,6 +669,7 @@ function refreshPopup() {
$("#instructions-no-trackers").show();

} else {
$('#tracker-list-header').show();
$('#instructions-many-trackers').html(chrome.i18n.getMessage(
"popup_instructions", [
POPUP_DATA.trackerCount,
Expand Down
45 changes: 45 additions & 0 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,50 @@ function isThirdPartyDomain(domain1, domain2) {
return false;
}

/**
* checks to see if a given url has firstparty protections scripts run on it
* @param {String} domain
* @param {Object} firstPartiesList a second fqdn
*
* @return {Boolean} true if the domains are third party
*/
let firstPartyProtectionsEnabled = (function () {
let firstPartiesList;

function getFirstParties() {
let manifestJson = chrome.runtime.getManifest();
let firstParties = [];

for (let contentScriptObj of manifestJson.content_scripts) {
// only include parts from content scripts that have firstparties entries
if (contentScriptObj.js[0].includes("/firstparties/")) {
let extractedUrls = [];
for (let match of contentScriptObj.matches) {
extractedUrls.push(window.extractHostFromURL(match));
}
firstParties.push(extractedUrls);
}
}
return [].concat.apply([], firstParties);
}

return function (tab_host) {
if (!firstPartiesList) {
firstPartiesList = getFirstParties();
}

for (let url_pattern of firstPartiesList) {
if (url_pattern.startsWith("*")) {
if ((url_pattern.slice(2) == tab_host.slice(4)) || url_pattern.slice(2) == tab_host.slice(2)) {
ghostwords marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
} else if (url_pattern == tab_host) {
return true;
}
}
return false;
};
})();

/**
* Checks whether a given URL is a special browser page.
Expand All @@ -469,6 +513,7 @@ let exports = {
estimateMaxEntropy,
explodeSubdomains,
findCommonSubstrings,
firstPartyProtectionsEnabled,
getHostFromDomainInput,
isRestrictedUrl,
isThirdPartyDomain,
Expand Down
5 changes: 4 additions & 1 deletion src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,8 @@ function dispatcher(request, sender, sendResponse) {

let tab_host = window.extractHostFromURL(request.tabUrl),
origins = badger.tabData[tab_id].origins,
cookieblocked = {};
cookieblocked = {},
isOnFirstParty = utils.firstPartyProtectionsEnabled(tab_host);

for (let origin in origins) {
// see if origin would be cookieblocked if not for user override
Expand All @@ -1034,10 +1035,12 @@ function dispatcher(request, sender, sendResponse) {
criticalError: badger.criticalError,
enabled: badger.isPrivacyBadgerEnabled(tab_host),
errorText: badger.tabData[tab_id].errorText,
isOnFirstParty: isOnFirstParty,
learnLocally: badger.getSettings().getItem("learnLocally"),
noTabData: false,
origins,
seenComic: badger.getSettings().getItem("seenComic"),
showExpandedTrackingSection: badger.getSettings().getItem("showExpandedTrackingSection"),
ghostwords marked this conversation as resolved.
Show resolved Hide resolved
showLearningPrompt: badger.getPrivateSettings().getItem("showLearningPrompt"),
showNonTrackingDomains: badger.getSettings().getItem("showNonTrackingDomains"),
tabHost: tab_host,
Expand Down
Loading