Bug 1484312 - Add UI for restricting third-party cookies to the Control Centre; r=johannh,flod
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 17 Aug 2018 13:55:52 -0400
changeset 488053 ee539247d48b32d1be2d70863987c3e2a7ddeb6f
parent 488052 40ee8078a913d4377527f577151433218fef8bb8
child 488054 8c43fcd785b9561d85983d1a4deeee16f8c40887
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, flod
bugs1484312
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1484312 - Add UI for restricting third-party cookies to the Control Centre; r=johannh,flod
browser/app/profile/firefox.js
browser/base/content/browser-contentblocking.js
browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js
browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js
browser/components/controlcenter/content/panel.inc.xul
browser/locales/en-US/chrome/browser/browser.dtd
browser/themes/shared/controlcenter/3rdpartycookies-disabled.svg
browser/themes/shared/controlcenter/3rdpartycookies.svg
browser/themes/shared/controlcenter/panel.inc.css
browser/themes/shared/jar.inc.mn
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1487,19 +1487,21 @@ pref("browser.ping-centre.production.end
 // Enable GMP support in the addon manager.
 pref("media.gmp-provider.enabled", true);
 
 pref("browser.contentblocking.enabled", true);
 pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.recommended", true);
 #ifdef NIGHTLY_BUILD
 pref("browser.contentblocking.ui.enabled", true);
 pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.enabled", true);
+pref("browser.contentblocking.rejecttrackers.control-center.ui.enabled", true);
 #else
 pref("browser.contentblocking.ui.enabled", false);
 pref("browser.contentblocking.cookies-site-data.ui.reject-trackers.enabled", false);
+pref("browser.contentblocking.rejecttrackers.control-center.ui.enabled", false);
 #endif
 #ifdef NIGHTLY_BUILD
 pref("browser.contentblocking.reportBreakage.enabled", true);
 #else
 pref("browser.contentblocking.reportBreakage.enabled", false);
 #endif
 pref("browser.contentblocking.reportBreakage.url", "https://tracking-protection-issues.herokuapp.com/new");
 // Content Blocking has a separate pref for the intro count, since the former TP intro
--- a/browser/base/content/browser-contentblocking.js
+++ b/browser/base/content/browser-contentblocking.js
@@ -120,16 +120,41 @@ var TrackingProtection = {
           this.strings.disableTooltip : this.strings.enableTooltip);
         appMenuButton.setAttribute("enabled", this.enabledGlobally);
         appMenuButton.setAttribute("aria-pressed", this.enabledGlobally);
       }
     }
   },
 };
 
+var ThirdPartyCookies = {
+  PREF_ENABLED: "network.cookie.cookieBehavior",
+  PREF_ENABLED_VALUE: Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER,
+  PREF_UI_ENABLED: "browser.contentblocking.rejecttrackers.control-center.ui.enabled",
+
+  get categoryItem() {
+    delete this.categoryItem;
+    return this.categoryItem =
+      document.getElementById("identity-popup-content-blocking-category-3rdpartycookies");
+  },
+
+  init() {
+    XPCOMUtils.defineLazyPreferenceGetter(this, "behaviorPref", this.PREF_ENABLED,
+                                          Ci.nsICookieService.BEHAVIOR_ACCEPT);
+    XPCOMUtils.defineLazyPreferenceGetter(this, "uiPref", this.PREF_UI_ENABLED, false);
+
+    if (!this.uiPref) {
+      this.categoryItem.hidden = "true";
+    }
+  },
+  get enabled() {
+    return this.behaviorPref == this.PREF_ENABLED_VALUE;
+  },
+};
+
 
 var ContentBlocking = {
   // If the user ignores the doorhanger, we stop showing it after some time.
   MAX_INTROS: 20,
   PREF_ENABLED: "browser.contentblocking.enabled",
   PREF_UI_ENABLED: "browser.contentblocking.ui.enabled",
   PREF_ANIMATIONS_ENABLED: "toolkit.cosmeticAnimations.enabled",
   PREF_REPORT_BREAKAGE_ENABLED: "browser.contentblocking.reportBreakage.enabled",
@@ -184,17 +209,17 @@ var ContentBlocking = {
   // A list of blockers that will be displayed in the categories list
   // when blockable content is detected. A blocker must be an object
   // with at least the following two properties:
   //  - enabled: Whether the blocker is currently turned on.
   //  - categoryItem: The DOM item that represents the entry in the category list.
   //
   // It may also contain an init() and uninit() function, which will be called
   // on ContentBlocking.init() and ContentBlocking.uninit().
-  blockers: [FastBlock, TrackingProtection],
+  blockers: [FastBlock, TrackingProtection, ThirdPartyCookies],
 
   get _baseURIForChannelClassifier() {
     // Convert document URI into the format used by
     // nsChannelClassifier::ShouldEnableTrackingProtection.
     // Any scheme turned into https is correct.
     try {
       return Services.io.newURI("https://" + gBrowser.selectedBrowser.currentURI.hostPort);
     } catch (e) {
@@ -333,17 +358,18 @@ var ContentBlocking = {
     body += `userAgent: ${this.reportBreakageUA.textContent}\n`;
 
     body += "\n**Preferences**\n";
     body += `${TrackingProtection.PREF_ENABLED_GLOBALLY}: ${Services.prefs.getBoolPref(TrackingProtection.PREF_ENABLED_GLOBALLY)}\n`;
     body += `${TrackingProtection.PREF_ENABLED_IN_PRIVATE_WINDOWS}: ${Services.prefs.getBoolPref(TrackingProtection.PREF_ENABLED_IN_PRIVATE_WINDOWS)}\n`;
     body += `urlclassifier.trackingTable: ${Services.prefs.getStringPref("urlclassifier.trackingTable")}\n`;
     body += `network.http.referer.defaultPolicy: ${Services.prefs.getIntPref("network.http.referer.defaultPolicy")}\n`;
     body += `network.http.referer.defaultPolicy.pbmode: ${Services.prefs.getIntPref("network.http.referer.defaultPolicy.pbmode")}\n`;
-    body += `network.cookie.cookieBehavior: ${Services.prefs.getIntPref("network.cookie.cookieBehavior")}\n`;
+    body += `${ThirdPartyCookies.PREF_UI_ENABLED}: ${Services.prefs.getBoolPref(ThirdPartyCookies.PREF_UI_ENABLED)}\n`;
+    body += `${ThirdPartyCookies.PREF_ENABLED}: ${Services.prefs.getIntPref(ThirdPartyCookies.PREF_ENABLED)}\n`;
     body += `network.cookie.lifetimePolicy: ${Services.prefs.getIntPref("network.cookie.lifetimePolicy")}\n`;
     body += `privacy.restrict3rdpartystorage.expiration: ${Services.prefs.getIntPref("privacy.restrict3rdpartystorage.expiration")}\n`;
     body += `${FastBlock.PREF_ENABLED}: ${Services.prefs.getBoolPref(FastBlock.PREF_ENABLED)}\n`;
     body += `browser.fastblock.timeout: ${Services.prefs.getIntPref("browser.fastblock.timeout")}\n`;
 
     let comments = document.getElementById("identity-popup-breakageReportView-collection-comments");
     body += "\n**Comments**\n" + comments.value;
 
--- a/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_open_preferences.js
@@ -2,16 +2,18 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const CB_PREF = "browser.contentblocking.enabled";
 const CB_UI_PREF = "browser.contentblocking.ui.enabled";
 const TP_PREF = "privacy.trackingprotection.enabled";
 const FB_PREF = "browser.fastblock.enabled";
+const TPC_PREF = "network.cookie.cookieBehavior";
+const RT_PREF = "browser.contentblocking.rejecttrackers.control-center.ui.enabled";
 const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
 
 async function waitAndAssertPreferencesShown() {
   await BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popuphidden");
   await TestUtils.waitForCondition(() => gBrowser.currentURI.spec == "about:preferences#privacy",
     "Should open about:preferences.");
 
   await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function() {
@@ -50,16 +52,18 @@ add_task(async function testOpenPreferen
 // Tests that clicking the contentblocking category items "add blocking" labels
 // links to about:preferences
 add_task(async function testOpenPreferencesFromAddBlockingButtons() {
   SpecialPowers.pushPrefEnv({set: [
     [CB_PREF, true],
     [CB_UI_PREF, true],
     [FB_PREF, false],
     [TP_PREF, false],
+    [TPC_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT],
+    [RT_PREF, true],
   ]});
 
   await BrowserTestUtils.withNewTab(TRACKING_PAGE, async function() {
     let addBlockingButtons = document.querySelectorAll(".identity-popup-content-blocking-category-add-blocking");
     for (let button of addBlockingButtons) {
       let promisePanelOpen = BrowserTestUtils.waitForEvent(gIdentityHandler._identityPopup, "popupshown");
       gIdentityHandler._identityBox.click();
       await promisePanelOpen;
--- a/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js
+++ b/browser/base/content/test/trackingUI/browser_trackingUI_report_breakage.js
@@ -178,16 +178,17 @@ add_task(async function testReportBreaka
         let sections = body.split(regex);
 
         let prefs = [
           "privacy.trackingprotection.enabled",
           "privacy.trackingprotection.pbmode.enabled",
           "urlclassifier.trackingTable",
           "network.http.referer.defaultPolicy",
           "network.http.referer.defaultPolicy.pbmode",
+          "browser.contentblocking.rejecttrackers.control-center.ui.enabled",
           "network.cookie.cookieBehavior",
           "network.cookie.lifetimePolicy",
           "privacy.restrict3rdpartystorage.expiration",
           "browser.fastblock.enabled",
           "browser.fastblock.timeout",
         ];
         let prefsBody = "";
 
--- a/browser/components/controlcenter/content/panel.inc.xul
+++ b/browser/components/controlcenter/content/panel.inc.xul
@@ -89,16 +89,24 @@
             <hbox id="identity-popup-content-blocking-category-tracking-protection"
                   class="identity-popup-content-blocking-category" align="center" role="group">
               <image class="identity-popup-content-blocking-category-icon tracking-protection-icon"/>
               <label flex="1" class="identity-popup-content-blocking-category-label">&contentBlocking.trackingProtection.label;</label>
               <label flex="1" class="identity-popup-content-blocking-category-state-label">&contentBlocking.trackingProtection.blocked.label;</label>
               <label flex="1" class="identity-popup-content-blocking-category-add-blocking text-link"
                      onclick="ContentBlocking.openPreferences('identityPopup-CB-tracking-protection');">&contentBlocking.trackingProtection.add.label;</label>
             </hbox>
+            <hbox id="identity-popup-content-blocking-category-3rdpartycookies"
+                  class="identity-popup-content-blocking-category" align="center" role="group">
+              <image class="identity-popup-content-blocking-category-icon thirdpartycookies-icon"/>
+              <label flex="1" class="identity-popup-content-blocking-category-label">&contentBlocking.3rdPartyCookies.label;</label>
+              <label flex="1" class="identity-popup-content-blocking-category-state-label">&contentBlocking.3rdPartyCookies.blocked.label;</label>
+              <label flex="1" class="identity-popup-content-blocking-category-add-blocking text-link"
+                     onclick="ContentBlocking.openPreferences('identityPopup-CB-3rdpartycookies');">&contentBlocking.3rdPartyCookies.add.label;</label>
+            </hbox>
           </vbox>
 
           <button id="tracking-action-unblock"
                   class="tracking-protection-button"
                   label="&trackingProtection.unblock4.label;"
                   accesskey="&trackingProtection.unblock4.accesskey;"
                   oncommand="ContentBlocking.disableForCurrentPage();" />
           <button id="tracking-action-unblock-private"
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -936,26 +936,39 @@ you can use these alternative items. Oth
      This is displayed as a link to preferences, where the user can add
      this specific type of content blocking. When this text is shown
      the type of content blocking is currently not enabled. -->
 <!ENTITY contentBlocking.fastBlock.add.label "Add Blocking…">
 
 <!ENTITY contentBlocking.trackingProtection.label "Trackers">
 <!-- LOCALIZATION NOTE (contentBlocking.trackingProtection.blocked.label):
      This label signals that this type of content blocking is turned
-     ON and is successfully blocking malicious/slow content, so this is
+     ON and is successfully blocking tracker content, so this is
      a positive thing. It forms the end of the (imaginary) sentence
      "Trackers [are] Blocked"-->
 <!ENTITY contentBlocking.trackingProtection.blocked.label "Blocked">
 <!-- LOCALIZATION NOTE (contentBlocking.trackingProtection.add.label):
      This is displayed as a link to preferences, where the user can add
      this specific type of content blocking. When this text is shown
      the type of content blocking is currently not enabled. -->
 <!ENTITY contentBlocking.trackingProtection.add.label "Add Blocking…">
 
+<!ENTITY contentBlocking.3rdPartyCookies.label "Third-Party Cookies">
+<!-- LOCALIZATION NOTE (contentBlocking.3rdPartyCookies.blocked.label):
+     This label signals that this type of content blocking is turned
+     ON and is successfully blocking third-party cookies, so this is
+     a positive thing. It forms the end of the (imaginary) sentence
+     "Third-Party Cookies [are] Blocked"-->
+<!ENTITY contentBlocking.3rdPartyCookies.blocked.label "Blocked">
+<!-- LOCALIZATION NOTE (contentBlocking.3rdPartyCookies.add.label):
+     This is displayed as a link to preferences, where the user can add
+     this specific type of content blocking. When this text is shown
+     the type of content blocking is currently not enabled. -->
+<!ENTITY contentBlocking.3rdPartyCookies.add.label "Add Blocking…">
+
 <!ENTITY contentBlocking.openBreakageReportView.label "Report Problems">
 <!ENTITY contentBlocking.breakageReportView.label "Report Problems">
 <!ENTITY contentBlocking.breakageReportView.description "Content blocking can cause problems with some websites. When you report problems, you’ll help make &brandShortName; better for everyone. (This will send a URL as well as information about your privacy and content blocking settings to Mozilla.)">
 <!ENTITY contentBlocking.breakageReportView.learnMore "Learn More">
 <!ENTITY contentBlocking.breakageReportView.collection.url.label "URL">
 <!ENTITY contentBlocking.breakageReportView.collection.userAgent.label "&brandShortName; Version Number">
 <!ENTITY contentBlocking.breakageReportView.collection.comments.label "What problems did you have? (Optional)">
 <!ENTITY contentBlocking.breakageReportView.sendReport.label "Send Report">
new file mode 100644
--- /dev/null
+++ b/browser/themes/shared/controlcenter/3rdpartycookies-disabled.svg
@@ -0,0 +1,7 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="context-fill" fill-opacity="context-fill-opacity">
+  <path d="M15.379,8a.142.142,0,0,0,.02,0,7.978,7.978,0,0,1-1.858-.356.981.981,0,0,1-.054.847,1,1,0,1,1-1.735-.994.981.981,0,0,1,.481-.407c-.069-.036-.13-.083-.2-.121L6.613,12.387a.977.977,0,0,1-.4.476.85.85,0,0,1-.117.04L4.031,14.969c.509.219,1,.24,1.161-.147-.424,1.025,2.823,1.668,2.822.558,0,1.11,3.246.461,2.821-.564.425,1.025,3.175-.816,2.39-1.6.785.784,2.621-1.97,1.6-2.394C15.846,11.246,16.489,8,15.379,8Zm-5.073,5a1,1,0,1,1,1-1A1,1,0,0,1,10.306,13Z"/>
+  <path d="M14.707,1.293a1,1,0,0,0-1.414,0L9.679,4.907A7.942,7.942,0,0,1,8,.61C8,.619,8,.626,8,.635,8-.474,4.753.174,5.179,1.2,4.753.174,2,2.016,2.788,2.8,2,2.016.167,4.77,1.193,5.193.167,4.77-.476,8.016.634,8.015c-1.11,0-.461,3.247.564,2.821-.639.265-.163,1.428.475,2.077l-.38.38a1,1,0,1,0,1.414,1.414l12-12A1,1,0,0,0,14.707,1.293Zm-9,1.7a1,1,0,1,1-1,1A1,1,0,0,1,5.706,3ZM2.524,7.508a1,1,0,1,1,.37,1.364A1,1,0,0,1,2.524,7.508Zm4.769-.215Z"/>
+</svg>
new file mode 100644
--- /dev/null
+++ b/browser/themes/shared/controlcenter/3rdpartycookies.svg
@@ -0,0 +1,6 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="context-fill" fill-opacity="context-fill-opacity">
+  <path d="M15.379,8a.142.142,0,0,0,.02,0,7.978,7.978,0,0,1-1.858-.356.981.981,0,0,1-.054.847,1,1,0,1,1-1.735-.994.981.981,0,0,1,.481-.407A8.02,8.02,0,0,1,8,.61C8,.619,8,.626,8,.635,8-.474,4.753.174,5.179,1.2,4.753.174,2,2.016,2.788,2.8,2,2.016.167,4.77,1.193,5.193.167,4.77-.476,8.016.634,8.015c-1.11,0-.461,3.247.564,2.821-1.025.426.817,3.175,1.6,2.39-.784.785,1.969,2.621,2.393,1.6-.424,1.025,2.823,1.668,2.822.558,0,1.11,3.246.461,2.821-.564.425,1.025,3.175-.816,2.39-1.6.785.784,2.621-1.97,1.6-2.394C15.846,11.246,16.489,8,15.379,8Zm-11.12.5a1,1,0,1,1-.37-1.365A1,1,0,0,1,4.259,8.5Zm1.955,4.361a1,1,0,1,1,.36-1.367A1,1,0,0,1,6.214,12.863ZM5.706,5a1,1,0,1,1,1-1A1,1,0,0,1,5.706,5ZM8,9A1,1,0,1,1,9,8,1,1,0,0,1,8,9Zm2.306,4a1,1,0,1,1,1-1A1,1,0,0,1,10.306,13Z"/>
+</svg>
--- a/browser/themes/shared/controlcenter/panel.inc.css
+++ b/browser/themes/shared/controlcenter/panel.inc.css
@@ -454,16 +454,24 @@ description#identity-popup-content-verif
 .tracking-protection-icon {
   list-style-image: url(chrome://browser/skin/controlcenter/trackers.svg);
 }
 
 #identity-popup-content-blocking-category-tracking-protection.blocked > .tracking-protection-icon {
   list-style-image: url(chrome://browser/skin/controlcenter/trackers-disabled.svg);
 }
 
+.thirdpartycookies-icon {
+  list-style-image: url(chrome://browser/skin/controlcenter/3rdpartycookies.svg);
+}
+
+#identity-popup-content-blocking-category-3rdpartycookies.blocked > .thirdpartycookies-icon {
+  list-style-image: url(chrome://browser/skin/controlcenter/3rdpartycookies-disabled.svg);
+}
+
 /* Content Blocking action button */
 
 .tracking-protection-button {
   margin: 1em 0 0;
   display: none;
 }
 
 #identity-popup-content-blocking-report-breakage {
--- a/browser/themes/shared/jar.inc.mn
+++ b/browser/themes/shared/jar.inc.mn
@@ -17,16 +17,18 @@
   skin/classic/browser/aboutTabCrashed.css                     (../shared/aboutTabCrashed.css)
   skin/classic/browser/aboutWelcomeBack.css                    (../shared/aboutWelcomeBack.css)
   skin/classic/browser/addons/addon-install-blocked.svg        (../shared/addons/addon-install-blocked.svg)
   skin/classic/browser/addons/addon-install-confirm.svg        (../shared/addons/addon-install-confirm.svg)
   skin/classic/browser/addons/addon-install-downloading.svg    (../shared/addons/addon-install-downloading.svg)
   skin/classic/browser/addons/addon-install-error.svg          (../shared/addons/addon-install-error.svg)
   skin/classic/browser/addons/addon-install-installed.svg      (../shared/addons/addon-install-installed.svg)
   skin/classic/browser/addons/addon-install-warning.svg        (../shared/addons/addon-install-warning.svg)
+  skin/classic/browser/controlcenter/3rdpartycookies.svg       (../shared/controlcenter/3rdpartycookies.svg)
+  skin/classic/browser/controlcenter/3rdpartycookies-disabled.svg (../shared/controlcenter/3rdpartycookies-disabled.svg)
   skin/classic/browser/controlcenter/conn-not-secure.svg       (../shared/controlcenter/conn-not-secure.svg)
   skin/classic/browser/controlcenter/connection.svg            (../shared/controlcenter/connection.svg)
   skin/classic/browser/controlcenter/mcb-disabled.svg          (../shared/controlcenter/mcb-disabled.svg)
   skin/classic/browser/controlcenter/extension.svg             (../shared/controlcenter/extension.svg)
   skin/classic/browser/controlcenter/permissions.svg           (../shared/controlcenter/permissions.svg)
   skin/classic/browser/controlcenter/slowtrackers.svg          (../shared/controlcenter/slowtrackers.svg)
   skin/classic/browser/controlcenter/slowtrackers-disabled.svg (../shared/controlcenter/slowtrackers-disabled.svg)
   skin/classic/browser/controlcenter/trackers.svg              (../shared/controlcenter/trackers.svg)