From 65ffbf08486959be41a46fe1fc071785e9ae8dd3 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 12:31:22 -0700 Subject: [PATCH 01/52] add messages to english locale for firstparty protections info in popup --- src/_locales/en_US/messages.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index 53fc47f061..e62ec4b484 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -417,6 +417,14 @@ "message": "user-controlled", "description": "Dropdown control setting on the Tracking Domains options page tab." }, + "popup_info_firstparty_description": { + "message": "Some websites, such as the one you're on right now, use hyperlinks to track where you're going. When you click on these links, instead of going straight to where you expect, it first directs you to one of this website's tracking servers, then to the final destination that you intended to navigate to. This happens in miliseconds without you even noticing! Privacy Badger removes all that creepy tracking stuff this website puts on these links, and once again provides you with faster, more private browsing.", + "description": "message show under the firstparty protections collapsible container on popup" + }, + "popup_info_firstparty_protections": { + "message": "Link tracking protection is enforced on this site", + "description": "message shown on a site where first party outgoing link tracking protections are enabled" + }, "popup_instructions": { "message": "$COUNT$ potential $LINK_START$trackers$LINK_END$ blocked", "description": "Popup message shown when at least one tracker was blocked.", From d14a37b94ffbb42e8ccb54c1faef26ac65dad5a8 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 12:34:10 -0700 Subject: [PATCH 02/52] add section to popup html for firstparty protections --- src/skin/popup.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/skin/popup.html b/src/skin/popup.html index 2cd43ff4cf..fe944070b5 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -133,6 +133,13 @@

+
+ + + +
+
+ -
+
From 4e59434ac9c837302a075b7671f677229c274099 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 12:51:11 -0700 Subject: [PATCH 04/52] add click handlers to toggle firstparty info visibility on popup --- src/js/popup.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/js/popup.js b/src/js/popup.js index 4add6a2112..c63df6a64c 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -194,6 +194,33 @@ function init() { chrome.i18n.getMessage("version", chrome.runtime.getManifest().version) ); + $('#expand-firstparty-popup').on('click', showFirstPartyInfoHandler); + $('#collapse-firstparty-popup').on('click', hideFirstPartyInfoHandler); + + $('#instructions-firstparty-description').hide(); + $('#collapse-firstparty-popup').hide(); + + // check if any firstparty scripts are run on current tab & show message in popup + async function fetchFirstPartiesManifest() { + // fetch the manifest + const response = await fetch('../manifest.json'); + const blob = await response.json(); + + // remove the 'www.' from current tab for string matching against first parties manifest url schemes + let current_tab = POPUP_DATA.tabHost.slice(4); + + // if current tab is in first parties list, show the popup message + for (let firstPartyObj of blob.content_scripts) { + firstPartyObj.matches.forEach((urlScheme) => { + if (urlScheme.includes(current_tab)) { + $("#firstpartyProtectionsContainer").show(); + } + }); + } + } + + fetchFirstPartiesManifest(); + // improve on Firefox's built-in options opening logic if (typeof browser == "object" && typeof browser.runtime.getBrowserInfo == "function") { browser.runtime.getBrowserInfo().then(function (info) { @@ -436,6 +463,21 @@ function share() { $("#share_output").val(share_msg); } +/** + * Click handlers for showing/hiding the firstparty popup info text + */ +function showFirstPartyInfoHandler() { + $("#collapse-firstparty-popup").show(); + $("#expand-firstparty-popup").hide(); + $("#instructions-firstparty-description").show(); +} + +function hideFirstPartyInfoHandler() { + $("#collapse-firstparty-popup").hide(); + $("#expand-firstparty-popup").show(); + $("#instructions-firstparty-description").hide(); +} + /** * Handler to undo user selection for a tracker */ From 108661ef4c0396e9c5bb5eeaf5445440e51fc68b Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 13:02:42 -0700 Subject: [PATCH 05/52] add popup html for toggling blocked resources visibility --- src/skin/popup.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/skin/popup.html b/src/skin/popup.html index 31c5c5cec3..10e1552171 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -128,6 +128,10 @@

+
+ + +

From 7938eb2b9dfe0dacfe4f3d880b141b55c9920f0d Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 13:04:38 -0700 Subject: [PATCH 06/52] add click handlers for toggling blocked resources visibility in popup --- src/js/popup.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/js/popup.js b/src/js/popup.js index c63df6a64c..a143416246 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -194,9 +194,22 @@ function init() { chrome.i18n.getMessage("version", chrome.runtime.getManifest().version) ); + $('#expand-blocked-resources').on('click', showBlockedResourcesHandler); + $('#collapse-blocked-resources').on('click', hideBlockedResourcesHandler); + $('#expand-firstparty-popup').on('click', showFirstPartyInfoHandler); $('#collapse-firstparty-popup').on('click', hideFirstPartyInfoHandler); + if (POPUP_DATA.showExpandedTrackingSection) { + $('#expand-blocked-resources').hide(); + $('#collapse-blocked-resources').show(); + $('#blockedResources').show(); + } else if (!POPUP_DATA.showExpandedTrackingSection) { + $('#expand-blocked-resources').show(); + $('#collapse-blocked-resources').hide(); + $('#blockedResources').hide(); + } + $('#instructions-firstparty-description').hide(); $('#collapse-firstparty-popup').hide(); @@ -462,7 +475,26 @@ function share() { } $("#share_output").val(share_msg); } +/** + * Click handlers for showing/hiding the blocked resources section + */ +function showBlockedResourcesHandler() { + $("#collapse-blocked-resources").show(); + $("#expand-blocked-resources").hide(); + $("#blockedResources").show(); + chrome.runtime.sendMessage({ + type: "showTrackingDomainsSection" + }); +} +function hideBlockedResourcesHandler() { + $("#collapse-blocked-resources").hide(); + $("#expand-blocked-resources").show(); + $("#blockedResources").hide(); + chrome.runtime.sendMessage({ + type: "hideTrackingDomainsSection" + }); +} /** * Click handlers for showing/hiding the firstparty popup info text */ @@ -552,6 +584,7 @@ function refreshPopup() { // hide the number of trackers and slider instructions message // if no sliders will be displayed $("#instructions-many-trackers").hide(); + $("#toggleBlockedResourcesContainer").hide(); // show "no trackers" message $("#instructions-no-trackers").show(); From 330322c5ab8cae5602747ee82222b163af582135 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 13:05:12 -0700 Subject: [PATCH 07/52] basic persistence of blocked resources visibility preference in popup --- src/js/background.js | 1 + src/js/webrequest.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/js/background.js b/src/js/background.js index fcb48c653b..026a229d0c 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -815,6 +815,7 @@ Badger.prototype = { seenComic: false, sendDNTSignal: true, showCounter: true, + showExpandedTrackingSection: false, showIntroPage: true, showNonTrackingDomains: false, showTrackingDomains: false, diff --git a/src/js/webrequest.js b/src/js/webrequest.js index 26c0731316..883bacff86 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -1038,6 +1038,7 @@ function dispatcher(request, sender, sendResponse) { noTabData: false, origins, seenComic: badger.getSettings().getItem("seenComic"), + showExpandedTrackingSection: badger.getSettings().getItem("showExpandedTrackingSection"), showLearningPrompt: badger.getPrivateSettings().getItem("showLearningPrompt"), showNonTrackingDomains: badger.getSettings().getItem("showNonTrackingDomains"), tabHost: tab_host, @@ -1125,6 +1126,18 @@ function dispatcher(request, sender, sendResponse) { break; } + case "showTrackingDomainsSection": { + badger.getSettings().setItem("showExpandedTrackingSection", true); + sendResponse(); + break; + } + + case "hideTrackingDomainsSection": { + badger.getSettings().setItem("showExpandedTrackingSection", false); + sendResponse(); + break; + } + case "downloadCloud": { chrome.storage.sync.get("disabledSites", function (store) { if (chrome.runtime.lastError) { From abb3fa886fa69d14351f19b59f4e82f1c0c44b38 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 28 Mar 2021 13:07:06 -0700 Subject: [PATCH 08/52] fix selenium popup test by clicking to expand blocked resources section --- tests/selenium/popup_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/selenium/popup_test.py b/tests/selenium/popup_test.py index e2f1c56c41..4f96cb2422 100644 --- a/tests/selenium/popup_test.py +++ b/tests/selenium/popup_test.py @@ -230,6 +230,9 @@ def test_reverting_control(self): self.open_popup(origins={DOMAIN:"cookieblock"}) + # expand the blocked resources container so that sliders are visible + self.driver.find_element_by_id("expand-blocked-resources").click() + # set the domain to user control # click input with JavaScript to avoid "Element ... is not clickable" / # "Other element would receive the click" Selenium limitation From d959710ee356bafafd7a6aac2a415ac98650c246 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Mon, 29 Mar 2021 10:11:50 -0700 Subject: [PATCH 09/52] fix styling edge case where no trackers detected but firstparty protection is enabled --- src/js/popup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/popup.js b/src/js/popup.js index a143416246..0d809404b0 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -226,7 +226,9 @@ function init() { for (let firstPartyObj of blob.content_scripts) { firstPartyObj.matches.forEach((urlScheme) => { if (urlScheme.includes(current_tab)) { - $("#firstpartyProtectionsContainer").show(); + $("#firstparty-protections-container").show(); + // in the edge case that no-trackers are detected, align text to left to match + $("#instructions-no-trackers").css("text-align","left"); } }); } From 7040294f08d07e8b5695e88aa704d8ee99212400 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Mon, 29 Mar 2021 10:15:16 -0700 Subject: [PATCH 10/52] styling cleanup on firstparty text and hidden sliders in popup --- src/skin/popup.css | 32 +++++++++++++++++++++++++++----- src/skin/popup.html | 6 ++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/skin/popup.css b/src/skin/popup.css index a1758636cc..3c3557072b 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -171,6 +171,7 @@ font-size: 16px; #blockedResourcesContainer { min-height: 70px; + margin-top: 10px; } #intro-reminder-btn, #critical-error-link, #learning-prompt-btn { @@ -307,14 +308,14 @@ font-size: 16px; } #instructions-firstparty-description { font-size: 14px; + margin-top: -30px; } -#instructions-no-trackers, #special-browser-page, #disabled-site-message, #instructions-firstparty-protections { +#instructions-no-trackers, #special-browser-page, #disabled-site-message { text-align: center; margin: 45px 0; padding: 0; } #instructions-many-trackers { - text-align: center; margin: 10px 0; } #instructions-many-trackers, #instructions-no-trackers, #no-third-parties, #instructions-firstparty-description { @@ -470,10 +471,31 @@ div.overlay.active { .tooltipster-sidetip .tooltipster-arrow-border { border: none; } -/* #firstparty-protections-container { +#firstparty-protections-container { display: none; -} */ - + border-top: 1px solid #707070; + padding: 0; + margin: 0; + text-align: left; +} +#instructions-firstparty-protections { + margin: 45px 0; + padding: 0; +} +#toggle-firstparty-info-section { + float: right; + margin-top: -65px; +} +#toggle-blocked-resources-container { + float: right; + margin-top: -30px; +} +.ui-icon.ui-icon-caret-d, .ui-icon.ui-icon-caret-u { + font-size: 18px; +} +.ui-icon.ui-icon-caret-d, .ui-icon.ui-icon-caret-u { + font-size: 18px; +} @media screen and (max-width: 400px){ .origin { max-width: 150px; diff --git a/src/skin/popup.html b/src/skin/popup.html index 10e1552171..e3404bfdfe 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -139,8 +139,10 @@

- - +
+ + +
From bc6e930fbefa4e1777b81ff1a6aa72e26a648412 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Wed, 14 Apr 2021 14:48:27 -0700 Subject: [PATCH 11/52] add en_us message for popup click to expand tooltips --- src/_locales/en_US/messages.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index e62ec4b484..ea068e1fd7 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -644,6 +644,10 @@ "message": "Share", "description": "Tooltip that comes up when you hover over the share button in the upper right corner of the popup." }, + "show_more_information": { + "message": "Click to show more information", + "description": "Tooltip that shows when you hover on the click-to-expand popup information sections." + }, "share_tracker_header": { "message": "Privacy Badger blocked $COUNT$ potential trackers on $DOMAIN$:", "description": "Header above the list of tracking domains in the share message.", From 0bedddbbfcba3b67e295da3defe3132eab103dcd Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Wed, 14 Apr 2021 14:49:55 -0700 Subject: [PATCH 12/52] cleanup click to expand section event listeners in popup script --- src/js/popup.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 0d809404b0..2130d21e3d 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -197,8 +197,8 @@ function init() { $('#expand-blocked-resources').on('click', showBlockedResourcesHandler); $('#collapse-blocked-resources').on('click', hideBlockedResourcesHandler); - $('#expand-firstparty-popup').on('click', showFirstPartyInfoHandler); - $('#collapse-firstparty-popup').on('click', hideFirstPartyInfoHandler); + // set up visibility click handler for firstparty protections header section + $('#expand-firstparty-popup, #collapse-firstparty-popup, #instructions-firstparty-protections').on('click', toggleFirstPartyInfoHandler); if (POPUP_DATA.showExpandedTrackingSection) { $('#expand-blocked-resources').hide(); @@ -225,10 +225,8 @@ function init() { // if current tab is in first parties list, show the popup message for (let firstPartyObj of blob.content_scripts) { firstPartyObj.matches.forEach((urlScheme) => { - if (urlScheme.includes(current_tab)) { + if (urlScheme.includes(current_tab) && POPUP_DATA.enabled) { $("#firstparty-protections-container").show(); - // in the edge case that no-trackers are detected, align text to left to match - $("#instructions-no-trackers").css("text-align","left"); } }); } @@ -498,18 +496,16 @@ function hideBlockedResourcesHandler() { }); } /** - * Click handlers for showing/hiding the firstparty popup info text + * Click handler for showing/hiding the firstparty popup info text */ -function showFirstPartyInfoHandler() { - $("#collapse-firstparty-popup").show(); - $("#expand-firstparty-popup").hide(); - $("#instructions-firstparty-description").show(); -} - -function hideFirstPartyInfoHandler() { - $("#collapse-firstparty-popup").hide(); - $("#expand-firstparty-popup").show(); - $("#instructions-firstparty-description").hide(); +function toggleFirstPartyInfoHandler() { + if($('#collapse-firstparty-popup').is(":visible")) { + $("#collapse-firstparty-popup, #instructions-firstparty-description").hide(); + $("#expand-firstparty-popup").show(); + } else { + $("#collapse-firstparty-popup, #instructions-firstparty-description").show(); + $("#expand-firstparty-popup").hide(); + } } /** From 9af80f279cc15718332c934a1fb55f060156679b Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Wed, 14 Apr 2021 15:36:53 -0700 Subject: [PATCH 13/52] cleanup click handler for blocked resources section in popup --- src/js/popup.js | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 2130d21e3d..7ae17057a4 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -194,8 +194,8 @@ function init() { chrome.i18n.getMessage("version", chrome.runtime.getManifest().version) ); - $('#expand-blocked-resources').on('click', showBlockedResourcesHandler); - $('#collapse-blocked-resources').on('click', hideBlockedResourcesHandler); + $('#expand-blocked-resources, #collapse-blocked-resources, #instructions-many-trackers').on('click', toggleBlockedResourcesHandler); + // $('#collapse-blocked-resources, #instructions-many-trackers').on('click', hideBlockedResourcesHandler); // set up visibility click handler for firstparty protections header section $('#expand-firstparty-popup, #collapse-firstparty-popup, #instructions-firstparty-protections').on('click', toggleFirstPartyInfoHandler); @@ -225,14 +225,14 @@ function init() { // if current tab is in first parties list, show the popup message for (let firstPartyObj of blob.content_scripts) { firstPartyObj.matches.forEach((urlScheme) => { - if (urlScheme.includes(current_tab) && POPUP_DATA.enabled) { + if (urlScheme.includes(current_tab)) { $("#firstparty-protections-container").show(); } }); } } - fetchFirstPartiesManifest(); + if (POPUP_DATA.enabled) { fetchFirstPartiesManifest(); } // improve on Firefox's built-in options opening logic if (typeof browser == "object" && typeof browser.runtime.getBrowserInfo == "function") { @@ -478,28 +478,27 @@ function share() { /** * Click handlers for showing/hiding the blocked resources section */ -function showBlockedResourcesHandler() { - $("#collapse-blocked-resources").show(); - $("#expand-blocked-resources").hide(); - $("#blockedResources").show(); - chrome.runtime.sendMessage({ - type: "showTrackingDomainsSection" - }); +function toggleBlockedResourcesHandler() { + if ($("#expand-blocked-resources").is(":visible")) { + $("#collapse-blocked-resources, #blockedResources").show(); + $("#expand-blocked-resources").hide(); + chrome.runtime.sendMessage({ + type: "showTrackingDomainsSection" + }); + } else { + $("#collapse-blocked-resources, #blockedResources").hide(); + $("#expand-blocked-resources").show(); + chrome.runtime.sendMessage({ + type: "hideTrackingDomainsSection" + }); + } } -function hideBlockedResourcesHandler() { - $("#collapse-blocked-resources").hide(); - $("#expand-blocked-resources").show(); - $("#blockedResources").hide(); - chrome.runtime.sendMessage({ - type: "hideTrackingDomainsSection" - }); -} /** * Click handler for showing/hiding the firstparty popup info text */ function toggleFirstPartyInfoHandler() { - if($('#collapse-firstparty-popup').is(":visible")) { + if ($('#collapse-firstparty-popup').is(":visible")) { $("#collapse-firstparty-popup, #instructions-firstparty-description").hide(); $("#expand-firstparty-popup").show(); } else { From ca7c71d96b6076a89388007d090422072e9f7256 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Wed, 14 Apr 2021 15:41:37 -0700 Subject: [PATCH 14/52] cleanup styling for dropdown portions of popup --- src/skin/popup.css | 14 +++++++------- src/skin/popup.html | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/skin/popup.css b/src/skin/popup.css index 3c3557072b..40453220ce 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -284,18 +284,19 @@ font-size: 16px; #options { margin-inline-end: 3px; } -#pbInstructions, #special-browser-page, #disabled-site-message, #firstparty-protections-container { +.pbInstructions, #special-browser-page, #disabled-site-message, #firstparty-protections-container { color: #505050; font-size: 16px; margin: 0; padding-top: 10px; + cursor: pointer; } -#pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a { +.pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a { text-decoration: underline; color: black; font-weight: bold; } -#pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a:hover { +.pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a:hover { color: #ec9329 } #firstparty-protections-container a { @@ -310,7 +311,7 @@ font-size: 16px; font-size: 14px; margin-top: -30px; } -#instructions-no-trackers, #special-browser-page, #disabled-site-message { +#instructions-no-trackers, #special-browser-page, #disabled-site-message, #instructions-many-trackers, #firstparty-protections-container { text-align: center; margin: 45px 0; padding: 0; @@ -476,7 +477,6 @@ div.overlay.active { border-top: 1px solid #707070; padding: 0; margin: 0; - text-align: left; } #instructions-firstparty-protections { margin: 45px 0; @@ -541,8 +541,8 @@ div.overlay.active { } button, - #pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a, - #pbInstructions, + .pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a, + .pbInstructions, #special-browser-page, #disabled-site-message { color: #ddd; diff --git a/src/skin/popup.html b/src/skin/popup.html index e3404bfdfe..322fa646d5 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -122,15 +122,15 @@

-

+

- - + +

@@ -139,9 +139,9 @@

-
- - +
+ +
From 111e8a7e71fcd2593c2e159b6b24ead2fcd9dc15 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Wed, 14 Apr 2021 17:23:31 -0700 Subject: [PATCH 15/52] more css cleanup for expandable popup sections --- src/skin/popup.css | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/skin/popup.css b/src/skin/popup.css index 40453220ce..ea735d79ce 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -291,6 +291,9 @@ font-size: 16px; padding-top: 10px; cursor: pointer; } +#toggle-blocked-resources-container { + cursor: pointer; +} .pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a { text-decoration: underline; color: black; @@ -474,9 +477,9 @@ div.overlay.active { } #firstparty-protections-container { display: none; - border-top: 1px solid #707070; + border-top: 1px solid #d3d3d3; + margin: auto; padding: 0; - margin: 0; } #instructions-firstparty-protections { margin: 45px 0; From 97ace1f342ad7055d4a5b6e73cf186570b9ab9ba Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 22 Apr 2021 08:55:46 -0700 Subject: [PATCH 16/52] set firstparties url schemes to badger object --- src/js/background.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/js/background.js b/src/js/background.js index 026a229d0c..9de8668e5d 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -93,6 +93,19 @@ function Badger() { await dntHashesPromise; await tabDataPromise; + // gather list of url schemes that firstparty content scripts run on + let manifestBlob = await chrome.runtime.getManifest(); + let firstParties = []; + + for (let contentScriptObj of manifestBlob.content_scripts) { + // only include parts from content scripts that have firstparties entries + if (contentScriptObj.js[0].includes("firstparties")) { + firstParties.push(contentScriptObj.matches); + } + } + // set list of firstparty url schemes onto badger object + self.firstPartiesList = [].concat.apply([], firstParties); + if (badger.isFirstRun || badger.isUpdate) { // block all widget domains // only need to do this when the widget list could have gotten updated From 786691f3f582571dadf4004e1612d5f5e8cfe064 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 22 Apr 2021 08:57:17 -0700 Subject: [PATCH 17/52] handle checking if current tab is in firstparty protections in webrequest --- src/js/webrequest.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/js/webrequest.js b/src/js/webrequest.js index 883bacff86..a65c985de7 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -819,6 +819,23 @@ function initializeAllowedWidgets(tab_id, tab_host) { } } +// checks to see if a given tab host is in url schemes of our first parties content scripts list +function checkHostIsFirstParty(tab_host) { + // trim www from tab_host if need be + if (tab_host.startsWith('www.')) { + tab_host = tab_host.slice(4); + } + // trim trailing wildcard + + for (let url_scheme of badger.firstPartiesList) { + // if given tab_host is matched in our firstparties list, return true + if (url_scheme.includes(tab_host)) { + return true; + } + } + return false; +} + // NOTE: sender.tab is available for content script (not popup) messages only function dispatcher(request, sender, sendResponse) { @@ -1020,7 +1037,8 @@ function dispatcher(request, sender, sendResponse) { let tab_host = window.extractHostFromURL(request.tabUrl), origins = badger.tabData[tab_id].origins, - cookieblocked = {}; + cookieblocked = {}, + isOnFirstParty = checkHostIsFirstParty(tab_host); for (let origin in origins) { // see if origin would be cookieblocked if not for user override @@ -1034,6 +1052,7 @@ 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, From 501ccaa29a141b384e2721bb749d36688fc90216 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 22 Apr 2021 08:58:30 -0700 Subject: [PATCH 18/52] cleanup popup script handlers showing firstparty and blocked resources messages --- src/js/popup.js | 28 ++++++---------------------- src/skin/popup.html | 2 +- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 7ae17057a4..07a4a0dff6 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -194,10 +194,10 @@ function init() { chrome.i18n.getMessage("version", chrome.runtime.getManifest().version) ); + // add event listeners for click-to-expand blocked resources popup section $('#expand-blocked-resources, #collapse-blocked-resources, #instructions-many-trackers').on('click', toggleBlockedResourcesHandler); - // $('#collapse-blocked-resources, #instructions-many-trackers').on('click', hideBlockedResourcesHandler); - // set up visibility click handler for firstparty protections header section + // add event listeners for click-to-expand first party protections popup section $('#expand-firstparty-popup, #collapse-firstparty-popup, #instructions-firstparty-protections').on('click', toggleFirstPartyInfoHandler); if (POPUP_DATA.showExpandedTrackingSection) { @@ -213,27 +213,11 @@ function init() { $('#instructions-firstparty-description').hide(); $('#collapse-firstparty-popup').hide(); - // check if any firstparty scripts are run on current tab & show message in popup - async function fetchFirstPartiesManifest() { - // fetch the manifest - const response = await fetch('../manifest.json'); - const blob = await response.json(); - - // remove the 'www.' from current tab for string matching against first parties manifest url schemes - let current_tab = POPUP_DATA.tabHost.slice(4); - - // if current tab is in first parties list, show the popup message - for (let firstPartyObj of blob.content_scripts) { - firstPartyObj.matches.forEach((urlScheme) => { - if (urlScheme.includes(current_tab)) { - $("#firstparty-protections-container").show(); - } - }); - } + // show firstparty protections message if current tab is in our content scripts + if (POPUP_DATA.enabled && POPUP_DATA.isOnFirstParty) { + $("#firstparty-protections-container").show(); } - if (POPUP_DATA.enabled) { fetchFirstPartiesManifest(); } - // improve on Firefox's built-in options opening logic if (typeof browser == "object" && typeof browser.runtime.getBrowserInfo == "function") { browser.runtime.getBrowserInfo().then(function (info) { @@ -581,7 +565,7 @@ function refreshPopup() { // hide the number of trackers and slider instructions message // if no sliders will be displayed $("#instructions-many-trackers").hide(); - $("#toggleBlockedResourcesContainer").hide(); + $("#toggle-blocked-resources-container").hide(); // show "no trackers" message $("#instructions-no-trackers").show(); diff --git a/src/skin/popup.html b/src/skin/popup.html index 322fa646d5..554961374d 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -128,7 +128,7 @@

-
+
From c2a7b79db3a02c58a874105cd0361117083e3ef5 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 22 Apr 2021 09:16:54 -0700 Subject: [PATCH 19/52] fix broken selenium popup test selecting wrong element type --- tests/selenium/popup_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/selenium/popup_test.py b/tests/selenium/popup_test.py index 4f96cb2422..56d5af912e 100644 --- a/tests/selenium/popup_test.py +++ b/tests/selenium/popup_test.py @@ -138,7 +138,7 @@ def test_trackers_link(self): self.open_popup() # Get all possible tracker links (none, one, multiple) - trackers_links = self.driver.find_elements_by_css_selector("#pbInstructions a") + trackers_links = self.driver.find_elements_by_css_selector(".pbInstructions a") if not trackers_links: self.fail("Unable to find trackers link on popup") From 874c3f01bc7080bbc1bcaac118955fd55b4744ad Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 11:00:22 -0700 Subject: [PATCH 20/52] simplify firstparty popup message --- src/_locales/en_US/messages.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index ea068e1fd7..d9e85ed95f 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -418,11 +418,11 @@ "description": "Dropdown control setting on the Tracking Domains options page tab." }, "popup_info_firstparty_description": { - "message": "Some websites, such as the one you're on right now, use hyperlinks to track where you're going. When you click on these links, instead of going straight to where you expect, it first directs you to one of this website's tracking servers, then to the final destination that you intended to navigate to. This happens in miliseconds without you even noticing! Privacy Badger removes all that creepy tracking stuff this website puts on these links, and once again provides you with faster, more private browsing.", + "message": "Some websites, such as the one you're on right now, use hyperlinks to secretly track you. Privacy Badger works behind the scenes to prevent them from doing that.", "description": "message show under the firstparty protections collapsible container on popup" }, "popup_info_firstparty_protections": { - "message": "Link tracking protection is enforced on this site", + "message": "Link tracking protection is enforced on this site", "description": "message shown on a site where first party outgoing link tracking protections are enabled" }, "popup_instructions": { From 380156ab62e716786508e973be0fae9355e73aa1 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 11:01:12 -0700 Subject: [PATCH 21/52] add hover transform effect on popup dropdown carets --- src/skin/popup.css | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/skin/popup.css b/src/skin/popup.css index ea735d79ce..5f740a3762 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -495,9 +495,13 @@ div.overlay.active { } .ui-icon.ui-icon-caret-d, .ui-icon.ui-icon-caret-u { font-size: 18px; + transition: 250ms; } -.ui-icon.ui-icon-caret-d, .ui-icon.ui-icon-caret-u { - font-size: 18px; +.ui-icon.ui-icon-caret-d:hover { + transform: translateY(5px); +} +.ui-icon.ui-icon-caret-u:hover { + transform: translateY(-5px); } @media screen and (max-width: 400px){ .origin { From 53fa187728309148a05062778b8e750b42b1863f Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 11:02:59 -0700 Subject: [PATCH 22/52] remove tooltip from dropdown sections popup --- src/_locales/en_US/messages.json | 4 ---- src/skin/popup.html | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index d9e85ed95f..75a7e036df 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -644,10 +644,6 @@ "message": "Share", "description": "Tooltip that comes up when you hover over the share button in the upper right corner of the popup." }, - "show_more_information": { - "message": "Click to show more information", - "description": "Tooltip that shows when you hover on the click-to-expand popup information sections." - }, "share_tracker_header": { "message": "Privacy Badger blocked $COUNT$ potential trackers on $DOMAIN$:", "description": "Header above the list of tracking domains in the share message.", diff --git a/src/skin/popup.html b/src/skin/popup.html index 554961374d..77e85fc2c3 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -129,8 +129,8 @@

- - + +

@@ -140,8 +140,8 @@

- - + +
From 8d0c014c768a15bfef8e997f728daa22993c4136 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 15:52:30 -0700 Subject: [PATCH 23/52] move firstparty detection method to utils --- src/js/utils.js | 18 ++++++++++++++++++ src/js/webrequest.js | 19 +------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 1adba9eb16..6da0b7d14b 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -445,6 +445,23 @@ function isThirdPartyDomain(domain1, domain2) { return false; } +// checks to see if a given tab host is in url schemes of our first parties content scripts list +function firstPartyProtectionsEnabled(tab_host) { + // trim www from tab_host if need be + if (tab_host.startsWith('www.')) { + tab_host = tab_host.slice(4); + } + // trim trailing wildcard + + for (let url_pattern of badger.firstPartiesList) { + // if given tab_host is matched in our firstparties list, return true + if (url_pattern.includes(tab_host)) { + return true; + } + } + return false; +} + /** * Checks whether a given URL is a special browser page. @@ -469,6 +486,7 @@ let exports = { estimateMaxEntropy, explodeSubdomains, findCommonSubstrings, + firstPartyProtectionsEnabled, getHostFromDomainInput, isRestrictedUrl, isThirdPartyDomain, diff --git a/src/js/webrequest.js b/src/js/webrequest.js index a65c985de7..b1731003d6 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -819,23 +819,6 @@ function initializeAllowedWidgets(tab_id, tab_host) { } } -// checks to see if a given tab host is in url schemes of our first parties content scripts list -function checkHostIsFirstParty(tab_host) { - // trim www from tab_host if need be - if (tab_host.startsWith('www.')) { - tab_host = tab_host.slice(4); - } - // trim trailing wildcard - - for (let url_scheme of badger.firstPartiesList) { - // if given tab_host is matched in our firstparties list, return true - if (url_scheme.includes(tab_host)) { - return true; - } - } - return false; -} - // NOTE: sender.tab is available for content script (not popup) messages only function dispatcher(request, sender, sendResponse) { @@ -1038,7 +1021,7 @@ function dispatcher(request, sender, sendResponse) { let tab_host = window.extractHostFromURL(request.tabUrl), origins = badger.tabData[tab_id].origins, cookieblocked = {}, - isOnFirstParty = checkHostIsFirstParty(tab_host); + isOnFirstParty = utils.firstPartyProtectionsEnabled(tab_host); for (let origin in origins) { // see if origin would be cookieblocked if not for user override From 68b04f8343e2766deea5614725d38c93658d5ef0 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 15:52:52 -0700 Subject: [PATCH 24/52] add unit test for firstparty detection util method --- src/tests/tests/utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tests/tests/utils.js b/src/tests/tests/utils.js index 26c1882542..a88d9ac555 100644 --- a/src/tests/tests/utils.js +++ b/src/tests/tests/utils.js @@ -571,4 +571,19 @@ QUnit.test("estimateMaxEntropy", assert => { }); +QUnit.test("firstPartyProtectionsEnabled", assert => { + assert.equal( + utils.firstPartyProtectionsEnabled("google.com"), + true, + "properly identifies a url pattern from our firstparties list" + ); + + assert.equal( + utils.firstPartyProtectionsEnabled("foobar.com"), + false, + "determines that a url not in the firstparties list is not protected by a firstparty script" + ); + +}); + })(); From 65989536a561cd0254416aba5f796349894a1c93 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 15:53:21 -0700 Subject: [PATCH 25/52] cleanup fetching manifest in background script --- src/js/background.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 9de8668e5d..61139264af 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -93,13 +93,13 @@ function Badger() { await dntHashesPromise; await tabDataPromise; - // gather list of url schemes that firstparty content scripts run on - let manifestBlob = await chrome.runtime.getManifest(); + // gather list of url match patterns that firstparty content scripts run on + let manifestJson = chrome.runtime.getManifest(); let firstParties = []; - for (let contentScriptObj of manifestBlob.content_scripts) { + for (let contentScriptObj of manifestJson.content_scripts) { // only include parts from content scripts that have firstparties entries - if (contentScriptObj.js[0].includes("firstparties")) { + if (contentScriptObj.js[0].includes("/firstparties/")) { firstParties.push(contentScriptObj.matches); } } From 58b68b665f28c0cd6b159c25be0e37886a906f8e Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 18:51:33 -0700 Subject: [PATCH 26/52] cleanup and delint method to check if firstparty protections are enabled on a url --- src/js/utils.js | 20 +++++++++++++------- src/js/webrequest.js | 2 +- src/tests/tests/utils.js | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 6da0b7d14b..8591b62cc9 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -445,17 +445,23 @@ function isThirdPartyDomain(domain1, domain2) { return false; } -// checks to see if a given tab host is in url schemes of our first parties content scripts list -function firstPartyProtectionsEnabled(tab_host) { +/** + * 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 + */ +function firstPartyProtectionsEnabled(domain, firstPartiesList) { // trim www from tab_host if need be - if (tab_host.startsWith('www.')) { - tab_host = tab_host.slice(4); + if (domain.startsWith('www.')) { + domain = domain.slice(4); } // trim trailing wildcard - for (let url_pattern of badger.firstPartiesList) { - // if given tab_host is matched in our firstparties list, return true - if (url_pattern.includes(tab_host)) { + for (let url_pattern of firstPartiesList) { + // if given domain is matched in our firstparties list, return true + if (url_pattern.includes(domain)) { return true; } } diff --git a/src/js/webrequest.js b/src/js/webrequest.js index b1731003d6..8ae8e2d40e 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -1021,7 +1021,7 @@ function dispatcher(request, sender, sendResponse) { let tab_host = window.extractHostFromURL(request.tabUrl), origins = badger.tabData[tab_id].origins, cookieblocked = {}, - isOnFirstParty = utils.firstPartyProtectionsEnabled(tab_host); + isOnFirstParty = utils.firstPartyProtectionsEnabled(tab_host, badger.firstPartiesList); for (let origin in origins) { // see if origin would be cookieblocked if not for user override diff --git a/src/tests/tests/utils.js b/src/tests/tests/utils.js index a88d9ac555..cf6590c578 100644 --- a/src/tests/tests/utils.js +++ b/src/tests/tests/utils.js @@ -573,13 +573,13 @@ QUnit.test("estimateMaxEntropy", assert => { QUnit.test("firstPartyProtectionsEnabled", assert => { assert.equal( - utils.firstPartyProtectionsEnabled("google.com"), + utils.firstPartyProtectionsEnabled("google.com", badger.firstPartiesList), true, "properly identifies a url pattern from our firstparties list" ); assert.equal( - utils.firstPartyProtectionsEnabled("foobar.com"), + utils.firstPartyProtectionsEnabled("foobar.com", badger.firstPartiesList), false, "determines that a url not in the firstparties list is not protected by a firstparty script" ); From 825d69eb012c05760b8e95a70bdff6467103448e Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 29 Apr 2021 18:52:19 -0700 Subject: [PATCH 27/52] fix cursor hovering error on popup expandable sections --- src/skin/popup.css | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/skin/popup.css b/src/skin/popup.css index 5f740a3762..4de5944362 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -284,14 +284,13 @@ font-size: 16px; #options { margin-inline-end: 3px; } -.pbInstructions, #special-browser-page, #disabled-site-message, #firstparty-protections-container { +.pbInstructions, #special-browser-page, #disabled-site-message, #instructions-firstparty-protections { color: #505050; font-size: 16px; margin: 0; padding-top: 10px; - cursor: pointer; } -#toggle-blocked-resources-container { +#instructions-firstparty-protections, #toggle-blocked-resources-container, #instructions-many-trackers, #toggle-firstparty-info-section { cursor: pointer; } .pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a { From 63c7f3dec2932f0f838931c5903d95d0bd2e9e80 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Mon, 3 May 2021 13:26:23 -0700 Subject: [PATCH 28/52] cleanup badger firstparties list obj and avoid false positives when looking through it --- src/js/background.js | 6 +++++- src/js/utils.js | 12 ++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 61139264af..5dc11a12d6 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -100,7 +100,11 @@ function Badger() { for (let contentScriptObj of manifestJson.content_scripts) { // only include parts from content scripts that have firstparties entries if (contentScriptObj.js[0].includes("/firstparties/")) { - firstParties.push(contentScriptObj.matches); + let extractedUrls = []; + for (let match of contentScriptObj.matches) { + extractedUrls.push(window.extractHostFromURL(match)); + } + firstParties.push(extractedUrls); } } // set list of firstparty url schemes onto badger object diff --git a/src/js/utils.js b/src/js/utils.js index 8591b62cc9..4c10541da2 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -453,15 +453,11 @@ function isThirdPartyDomain(domain1, domain2) { * @return {Boolean} true if the domains are third party */ function firstPartyProtectionsEnabled(domain, firstPartiesList) { - // trim www from tab_host if need be - if (domain.startsWith('www.')) { - domain = domain.slice(4); - } - // trim trailing wildcard - for (let url_pattern of firstPartiesList) { - // if given domain is matched in our firstparties list, return true - if (url_pattern.includes(domain)) { + // account for wildcards in entries on firstPartiesList & avoid false positives + if (url_pattern.startsWith("*") && url_pattern.endsWith(domain)) { + return true; + } else if (url_pattern == domain) { return true; } } From 0c098a10e9b71b0b30eff45793f3697dad898e97 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Mon, 3 May 2021 13:27:53 -0700 Subject: [PATCH 29/52] fix broken firstparty detection test script --- src/tests/tests/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/tests/utils.js b/src/tests/tests/utils.js index cf6590c578..7055dc59a5 100644 --- a/src/tests/tests/utils.js +++ b/src/tests/tests/utils.js @@ -573,7 +573,7 @@ QUnit.test("estimateMaxEntropy", assert => { QUnit.test("firstPartyProtectionsEnabled", assert => { assert.equal( - utils.firstPartyProtectionsEnabled("google.com", badger.firstPartiesList), + utils.firstPartyProtectionsEnabled("www.google.com", badger.firstPartiesList), true, "properly identifies a url pattern from our firstparties list" ); From cad1393863eb0854ed0559741ef853b189133e2d Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 6 May 2021 12:27:19 -0700 Subject: [PATCH 30/52] fix wildcard url matching firstparty detection and add test coverage --- src/js/utils.js | 7 +++++-- src/tests/tests/utils.js | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 4c10541da2..0684067673 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -455,8 +455,11 @@ function isThirdPartyDomain(domain1, domain2) { function firstPartyProtectionsEnabled(domain, firstPartiesList) { for (let url_pattern of firstPartiesList) { // account for wildcards in entries on firstPartiesList & avoid false positives - if (url_pattern.startsWith("*") && url_pattern.endsWith(domain)) { - return true; + if (url_pattern.startsWith("*")) { + // compare against pattern without '*.' and the domain without 'www.' + if (url_pattern.slice(2) == domain.slice(4)) { + return true; + } } else if (url_pattern == domain) { return true; } diff --git a/src/tests/tests/utils.js b/src/tests/tests/utils.js index 7055dc59a5..289dcf3d2a 100644 --- a/src/tests/tests/utils.js +++ b/src/tests/tests/utils.js @@ -584,6 +584,12 @@ QUnit.test("firstPartyProtectionsEnabled", assert => { "determines that a url not in the firstparties list is not protected by a firstparty script" ); + assert.equal( + utils.firstPartyProtectionsEnabled("www.messenger.com", badger.firstPartiesList), + true, + "accurately IDs a site with firstparty protections covered by a wildcard url match" + ); + }); })(); From 6408edbe3b3d1b10d0a10f205cdcdb12b22efede Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 6 May 2021 12:47:09 -0700 Subject: [PATCH 31/52] simplify updating setting showing blocked resources container in popup --- src/js/popup.js | 6 ++++-- src/js/webrequest.js | 12 ------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index 07a4a0dff6..f1fa570cfa 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -467,13 +467,15 @@ function toggleBlockedResourcesHandler() { $("#collapse-blocked-resources, #blockedResources").show(); $("#expand-blocked-resources").hide(); chrome.runtime.sendMessage({ - type: "showTrackingDomainsSection" + type: "updateSettings", + data: { showExpandedTrackingSection: true } }); } else { $("#collapse-blocked-resources, #blockedResources").hide(); $("#expand-blocked-resources").show(); chrome.runtime.sendMessage({ - type: "hideTrackingDomainsSection" + type: "updateSettings", + data: { showExpandedTrackingSection: false } }); } } diff --git a/src/js/webrequest.js b/src/js/webrequest.js index 8ae8e2d40e..c97d677a98 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -1128,18 +1128,6 @@ function dispatcher(request, sender, sendResponse) { break; } - case "showTrackingDomainsSection": { - badger.getSettings().setItem("showExpandedTrackingSection", true); - sendResponse(); - break; - } - - case "hideTrackingDomainsSection": { - badger.getSettings().setItem("showExpandedTrackingSection", false); - sendResponse(); - break; - } - case "downloadCloud": { chrome.storage.sync.get("disabledSites", function (store) { if (chrome.runtime.lastError) { From 284907b39fbcbc89da373907946d70ab65b0216d Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Thu, 6 May 2021 13:47:06 -0700 Subject: [PATCH 32/52] visual consistency between descriptions sections in dropdowns on popup --- src/skin/popup.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/skin/popup.css b/src/skin/popup.css index 4de5944362..ae68d87e0d 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -312,6 +312,11 @@ font-size: 16px; #instructions-firstparty-description { font-size: 14px; margin-top: -30px; + background-color: #E8E9EA; + color: #555555; + padding: 8px; + text-align: left; + font-size: 12px; } #instructions-no-trackers, #special-browser-page, #disabled-site-message, #instructions-many-trackers, #firstparty-protections-container { text-align: center; From 123b2a48b5f459d72ed3f70f8b1c57d47dca92f5 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 9 May 2021 17:08:53 -0700 Subject: [PATCH 33/52] only fetch badger firstparties list when its first needed --- src/js/background.js | 17 ----------------- src/js/utils.js | 23 +++++++++++++++++++++-- src/js/webrequest.js | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 5dc11a12d6..026a229d0c 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -93,23 +93,6 @@ function Badger() { await dntHashesPromise; await tabDataPromise; - // gather list of url match patterns that firstparty content scripts run on - 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); - } - } - // set list of firstparty url schemes onto badger object - self.firstPartiesList = [].concat.apply([], firstParties); - if (badger.isFirstRun || badger.isUpdate) { // block all widget domains // only need to do this when the widget list could have gotten updated diff --git a/src/js/utils.js b/src/js/utils.js index 0684067673..c89080103b 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -452,8 +452,27 @@ function isThirdPartyDomain(domain1, domain2) { * * @return {Boolean} true if the domains are third party */ -function firstPartyProtectionsEnabled(domain, firstPartiesList) { - for (let url_pattern of firstPartiesList) { +function firstPartyProtectionsEnabled(domain, badger) { + // if the firstparties list hasn't been set yet, fetch it and set it + if (!badger.firstPartiesList) { + 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); + } + } + // clean up the gathered sets of url matches into a single flat list + badger.firstPartiesList = [].concat.apply([], firstParties); + } + // check for presence of given domain in firstparties list + for (let url_pattern of badger.firstPartiesList) { // account for wildcards in entries on firstPartiesList & avoid false positives if (url_pattern.startsWith("*")) { // compare against pattern without '*.' and the domain without 'www.' diff --git a/src/js/webrequest.js b/src/js/webrequest.js index c97d677a98..76886820fb 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -1021,7 +1021,7 @@ function dispatcher(request, sender, sendResponse) { let tab_host = window.extractHostFromURL(request.tabUrl), origins = badger.tabData[tab_id].origins, cookieblocked = {}, - isOnFirstParty = utils.firstPartyProtectionsEnabled(tab_host, badger.firstPartiesList); + isOnFirstParty = utils.firstPartyProtectionsEnabled(tab_host, badger); for (let origin in origins) { // see if origin would be cookieblocked if not for user override From 743881336da42c1dd0b4424836438d6d9e69d391 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Sun, 9 May 2021 17:12:31 -0700 Subject: [PATCH 34/52] fix broken utils text --- src/js/utils.js | 1 - src/tests/tests/utils.js | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index c89080103b..dd0f4fcc9f 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -486,7 +486,6 @@ function firstPartyProtectionsEnabled(domain, badger) { return false; } - /** * Checks whether a given URL is a special browser page. * TODO account for browser-specific pages: diff --git a/src/tests/tests/utils.js b/src/tests/tests/utils.js index 289dcf3d2a..2e9ba93d9d 100644 --- a/src/tests/tests/utils.js +++ b/src/tests/tests/utils.js @@ -573,19 +573,19 @@ QUnit.test("estimateMaxEntropy", assert => { QUnit.test("firstPartyProtectionsEnabled", assert => { assert.equal( - utils.firstPartyProtectionsEnabled("www.google.com", badger.firstPartiesList), + utils.firstPartyProtectionsEnabled("www.google.com", badger), true, "properly identifies a url pattern from our firstparties list" ); assert.equal( - utils.firstPartyProtectionsEnabled("foobar.com", badger.firstPartiesList), + utils.firstPartyProtectionsEnabled("foobar.com", badger), false, "determines that a url not in the firstparties list is not protected by a firstparty script" ); assert.equal( - utils.firstPartyProtectionsEnabled("www.messenger.com", badger.firstPartiesList), + utils.firstPartyProtectionsEnabled("www.messenger.com", badger), true, "accurately IDs a site with firstparty protections covered by a wildcard url match" ); From 98b2e8422cfbf2c3519fd6f22acfc1f75d19f9cb Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 12 May 2021 15:05:11 -0400 Subject: [PATCH 35/52] Move HTML link into a placeholder Friendlier to translators and easier to update the link in the future (avoids having to "retranslate" every message). --- src/_locales/en_US/messages.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index 75a7e036df..026a0a2afa 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -418,8 +418,16 @@ "description": "Dropdown control setting on the Tracking Domains options page tab." }, "popup_info_firstparty_description": { - "message": "Some websites, such as the one you're on right now, use hyperlinks to secretly track you. Privacy Badger works behind the scenes to prevent them from doing that.", - "description": "message show under the firstparty protections collapsible container on popup" + "message": "Some websites, such as the one you're on right now, $LINK_START$use hyperlinks to secretly track you.$LINK_END$ Privacy Badger works behind the scenes to prevent them from doing that.", + "description": "message show under the firstparty protections collapsible container on popup", + "placeholders": { + "link_start": { + "content": "" + }, + "link_end": { + "content": "" + } + } }, "popup_info_firstparty_protections": { "message": "Link tracking protection is enforced on this site", From c5fb566dc64cbbaad1c8cc7d8359cd5f7ce3bfea Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 12 May 2021 15:08:34 -0400 Subject: [PATCH 36/52] Tweak locale message order More logical for translators: in the UI the header comes first, before the "more info" text. --- src/_locales/en_US/messages.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index 026a0a2afa..986093b827 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -417,6 +417,10 @@ "message": "user-controlled", "description": "Dropdown control setting on the Tracking Domains options page tab." }, + "popup_info_firstparty_protections": { + "message": "Link tracking protection is enforced on this site", + "description": "message shown on a site where first party outgoing link tracking protections are enabled" + }, "popup_info_firstparty_description": { "message": "Some websites, such as the one you're on right now, $LINK_START$use hyperlinks to secretly track you.$LINK_END$ Privacy Badger works behind the scenes to prevent them from doing that.", "description": "message show under the firstparty protections collapsible container on popup", @@ -429,10 +433,6 @@ } } }, - "popup_info_firstparty_protections": { - "message": "Link tracking protection is enforced on this site", - "description": "message shown on a site where first party outgoing link tracking protections are enabled" - }, "popup_instructions": { "message": "$COUNT$ potential $LINK_START$trackers$LINK_END$ blocked", "description": "Popup message shown when at least one tracker was blocked.", From 09a602a3bbaa8ec412299299c69c0b16032b1338 Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 12 May 2021 15:11:19 -0400 Subject: [PATCH 37/52] Tweak link tracking protection messages --- src/_locales/en_US/messages.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_locales/en_US/messages.json b/src/_locales/en_US/messages.json index 986093b827..47cb308323 100644 --- a/src/_locales/en_US/messages.json +++ b/src/_locales/en_US/messages.json @@ -418,12 +418,12 @@ "description": "Dropdown control setting on the Tracking Domains options page tab." }, "popup_info_firstparty_protections": { - "message": "Link tracking protection is enforced on this site", - "description": "message shown on a site where first party outgoing link tracking protections are enabled" + "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 hyperlinks to secretly track you.$LINK_END$ Privacy Badger works behind the scenes to prevent them from doing that.", - "description": "message show under the firstparty protections collapsible container on popup", + "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": "" From b778566afca07949d1cde77242c7d11c0c4703b7 Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 12 May 2021 15:37:10 -0400 Subject: [PATCH 38/52] Restyle popup categories Also: - Link tracking protection moved above sliders - Keyboard support - Dark mode styles - RTL locale support --- src/js/popup.js | 42 +++++++------ src/skin/popup.css | 139 ++++++++++++++++++++++++++------------------ src/skin/popup.html | 41 +++++++------ 3 files changed, 130 insertions(+), 92 deletions(-) diff --git a/src/js/popup.js b/src/js/popup.js index f1fa570cfa..bca910305d 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -195,27 +195,34 @@ function init() { ); // add event listeners for click-to-expand blocked resources popup section - $('#expand-blocked-resources, #collapse-blocked-resources, #instructions-many-trackers').on('click', toggleBlockedResourcesHandler); + $('#tracker-list-header').on('click', toggleBlockedResourcesHandler); // add event listeners for click-to-expand first party protections popup section - $('#expand-firstparty-popup, #collapse-firstparty-popup, #instructions-firstparty-protections').on('click', toggleFirstPartyInfoHandler); + $('#firstparty-protections-header').on('click', toggleFirstPartyInfoHandler); if (POPUP_DATA.showExpandedTrackingSection) { $('#expand-blocked-resources').hide(); $('#collapse-blocked-resources').show(); $('#blockedResources').show(); - } else if (!POPUP_DATA.showExpandedTrackingSection) { + } else { $('#expand-blocked-resources').show(); $('#collapse-blocked-resources').hide(); - $('#blockedResources').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(); + } } - $('#instructions-firstparty-description').hide(); - $('#collapse-firstparty-popup').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 @@ -459,20 +466,23 @@ function share() { } $("#share_output").val(share_msg); } + /** * Click handlers for showing/hiding the blocked resources section */ function toggleBlockedResourcesHandler() { if ($("#expand-blocked-resources").is(":visible")) { - $("#collapse-blocked-resources, #blockedResources").show(); + $("#collapse-blocked-resources").show(); $("#expand-blocked-resources").hide(); + $("#blockedResources").slideDown(); chrome.runtime.sendMessage({ type: "updateSettings", data: { showExpandedTrackingSection: true } }); } else { - $("#collapse-blocked-resources, #blockedResources").hide(); + $("#collapse-blocked-resources").hide(); $("#expand-blocked-resources").show(); + $("#blockedResources").slideUp(); chrome.runtime.sendMessage({ type: "updateSettings", data: { showExpandedTrackingSection: false } @@ -485,11 +495,13 @@ function toggleBlockedResourcesHandler() { */ function toggleFirstPartyInfoHandler() { if ($('#collapse-firstparty-popup').is(":visible")) { - $("#collapse-firstparty-popup, #instructions-firstparty-description").hide(); + $("#collapse-firstparty-popup").hide(); $("#expand-firstparty-popup").show(); + $("#instructions-firstparty-description").slideUp(); } else { - $("#collapse-firstparty-popup, #instructions-firstparty-description").show(); + $("#collapse-firstparty-popup").show(); $("#expand-firstparty-popup").hide(); + $("#instructions-firstparty-description").slideDown(); } } @@ -567,7 +579,6 @@ function refreshPopup() { // hide the number of trackers and slider instructions message // if no sliders will be displayed $("#instructions-many-trackers").hide(); - $("#toggle-blocked-resources-container").hide(); // show "no trackers" message $("#instructions-no-trackers").show(); @@ -621,9 +632,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) { @@ -639,9 +647,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) { @@ -660,6 +665,7 @@ function refreshPopup() { $("#instructions-no-trackers").show(); } else { + $('#tracker-list-header').show(); $('#instructions-many-trackers').html(chrome.i18n.getMessage( "popup_instructions", [ POPUP_DATA.trackerCount, diff --git a/src/skin/popup.css b/src/skin/popup.css index ae68d87e0d..0fa8013b80 100644 --- a/src/skin/popup.css +++ b/src/skin/popup.css @@ -30,7 +30,7 @@ body { min-width: 430px; /* Chrome */ max-width: 100%; /* FF android */ - min-height: 270px; + min-height: 300px; } @media screen and (min--moz-device-pixel-ratio:0) { body { @@ -39,6 +39,12 @@ body { } } +/* popup only (not options page) */ +body#main { + display: flex; + flex-direction: column; +} + @font-face { font-family: "Chunk-Five"; src: url("./fonts/Chunk.ttf"); @@ -139,9 +145,10 @@ a:hover { color: #ec9329 } display: inline-block; } -#privacyBadgerHeader{ -color: #505050; -font-size: 16px; +#privacyBadgerHeader { + color: #505050; + font-size: 16px; + margin-bottom: 5px; } #title { @@ -169,9 +176,12 @@ font-size: 16px; float: left; } -#blockedResourcesContainer { - min-height: 70px; - margin-top: 10px; +/* body#main to avoid applying this to options page */ +body#main #blockedResourcesContainer { + flex: 1; + display: flex; + flex-direction: column; + justify-content: center; } #intro-reminder-btn, #critical-error-link, #learning-prompt-btn { @@ -196,7 +206,7 @@ font-size: 16px; .clickerContainer { max-height: 290px; overflow-y: auto; - background-color: #E8E9EA; + background-color: #e8e9ea; position: relative; margin-top: 25px; } @@ -284,49 +294,33 @@ font-size: 16px; #options { margin-inline-end: 3px; } -.pbInstructions, #special-browser-page, #disabled-site-message, #instructions-firstparty-protections { +.pbInstructions, .toggle-header-title, #special-browser-page, #disabled-site-message { color: #505050; font-size: 16px; margin: 0; - padding-top: 10px; -} -#instructions-firstparty-protections, #toggle-blocked-resources-container, #instructions-many-trackers, #toggle-firstparty-info-section { - cursor: pointer; -} -.pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a { - text-decoration: underline; - color: black; - font-weight: bold; -} -.pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a:hover { - color: #ec9329 } -#firstparty-protections-container a { +/* body#main to avoid applying this to options page */ +body#main .pbInstructions a, #firstparty-protections-container a { text-decoration: underline; color: black; font-weight: bold; } -#firstparty-protections-container a:hover { +body#main .pbInstructions a:hover, #firstparty-protections-container a:hover { color: #ec9329 } #instructions-firstparty-description { font-size: 14px; - margin-top: -30px; - background-color: #E8E9EA; - color: #555555; + background-color: #e8e9ea; + color: #555; padding: 8px; - text-align: left; font-size: 12px; } -#instructions-no-trackers, #special-browser-page, #disabled-site-message, #instructions-many-trackers, #firstparty-protections-container { +#special-browser-page, #disabled-site-message { text-align: center; - margin: 45px 0; + margin: 40px 0; padding: 0; } -#instructions-many-trackers { - margin: 10px 0; -} -#instructions-many-trackers, #instructions-no-trackers, #no-third-parties, #instructions-firstparty-description { +#instructions-many-trackers, #no-third-parties { display: block; } #no-third-parties { @@ -337,12 +331,8 @@ font-size: 16px; display: flex; flex-wrap: wrap; justify-content: space-between; - margin-top: 5px; text-align: center; } -button { - color: #333; -} .pbButton { background-color: #fefefe; border: 2px solid; @@ -480,32 +470,49 @@ div.overlay.active { border: none; } #firstparty-protections-container { - display: none; - border-top: 1px solid #d3d3d3; - margin: auto; - padding: 0; + border-bottom: 1px solid #d3d3d3; + margin: 10px 0; + padding-bottom: 5px; +} +.basic-header { + text-align: center; + margin: 15px 0; } -#instructions-firstparty-protections { - margin: 45px 0; +.toggle-header { + display: flex; + align-items: center; + cursor: pointer; + transition: border 0.25s ease-out; + background-color: #fff; + border: 2px solid #fff; + border-radius: 3px; padding: 0; + width: 100%; } -#toggle-firstparty-info-section { - float: right; - margin-top: -65px; +.toggle-header:hover { + border: 2px solid #f06a0a; } -#toggle-blocked-resources-container { - float: right; - margin-top: -30px; +.toggle-header:hover .toggle-header-title { + color: #000; } -.ui-icon.ui-icon-caret-d, .ui-icon.ui-icon-caret-u { +.toggle-header-title { + flex: 1; + transition: color 0.25s ease-out; + margin: 10px 0; +} +.toggle-header::before { + content: ''; font-size: 18px; - transition: 250ms; + padding: 0 4px; + width: 1.2em; + visibility: hidden; } -.ui-icon.ui-icon-caret-d:hover { - transform: translateY(5px); +.toggle-header-icon { + margin-inline-end: auto; + padding: 0 4px; } -.ui-icon.ui-icon-caret-u:hover { - transform: translateY(-5px); +.ui-icon.ui-icon-caret-d, .ui-icon.ui-icon-caret-u { + font-size: 18px; } @media screen and (max-width: 400px){ .origin { @@ -552,13 +559,28 @@ div.overlay.active { } button, - .pbInstructions :not(#options_domain_list_trackers):not(#options_domain_list_no_trackers) a, + /* body#main to avoid applying this to options page */ + body#main .pbInstructions a, + #firstparty-protections-container a, .pbInstructions, + .toggle-header-title, #special-browser-page, #disabled-site-message { color: #ddd; } + .toggle-header { + background-color: #333; + border: 2px solid #333; + } + .toggle-header:hover .toggle-header-title { + color: #fff; + } + + #firstparty-protections-container { + border-bottom: 1px solid #555; + } + /* TODO: * - Add f06a0a color on hover */ @@ -591,6 +613,11 @@ div.overlay.active { background-color: #3a3a3a; } + #instructions-firstparty-description { + background-color: #3a3a3a; + color: #ddd; + } + .pbButton { background-color: #333; border: solid 2px #ddd; diff --git a/src/skin/popup.html b/src/skin/popup.html index 77e85fc2c3..3e3906e7ff 100644 --- a/src/skin/popup.html +++ b/src/skin/popup.html @@ -121,31 +121,36 @@

+ +
-

- -

+ +
-
- -
- - -
-
-
-
-
+