Bug 1551206 - Introduce new Protections Panel behind a pref. r=johannh
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 14 May 2019 16:17:07 +0000
changeset 473801 e1437ba34a4afff6cee82968503144f15e9e1949
parent 473800 9437ce7f56f17a5f38e3c64f165005845a50fc69
child 473802 01fcbba06f1c5a79a6881c4a4378b0bd2476e22e
push id36015
push usercbrindusan@mozilla.com
push dateTue, 14 May 2019 21:40:04 +0000
treeherdermozilla-central@f17162f343b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1551206
milestone68.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 1551206 - Introduce new Protections Panel behind a pref. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D30921
browser/app/profile/firefox.js
browser/base/content/browser-siteIdentity.js
browser/base/content/browser-siteProtections.js
browser/base/content/browser.js
browser/base/content/browser.xul
browser/base/jar.mn
browser/components/controlcenter/content/identityPanel.inc.xul
browser/components/controlcenter/content/panel.inc.xul
browser/components/controlcenter/content/protectionsPanel.inc.xul
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1634,16 +1634,21 @@ pref("browser.contentblocking.rejecttrac
 pref("browser.contentblocking.reportBreakage.url", "https://tracking-protection-issues.herokuapp.com/new");
 
 pref("browser.contentblocking.introCount", 0);
 
 pref("browser.contentblocking.maxIntroCount", 5);
 // 1800 = 30 min in seconds
 pref("browser.contentblocking.introDelaySeconds", 1800);
 
+// Enables the new Protections Panel.
+#ifdef NIGHTLY_BUILD
+pref("browser.protections_panel.enabled", true);
+#endif
+
 pref("privacy.trackingprotection.introURL", "https://www.mozilla.org/%LOCALE%/firefox/%VERSION%/content-blocking/start/");
 
 // Always enable newtab segregation using containers
 pref("privacy.usercontext.about_newtab_segregation.enabled", true);
 // Enable Contextual Identity Containers
 #ifdef NIGHTLY_BUILD
 pref("privacy.userContext.enabled", true);
 pref("privacy.userContext.ui.enabled", true);
--- a/browser/base/content/browser-siteIdentity.js
+++ b/browser/base/content/browser-siteIdentity.js
@@ -227,16 +227,23 @@ var gIdentityHandler = {
     return this._insecureConnectionTextEnabled;
   },
   get _insecureConnectionTextPBModeEnabled() {
     delete this._insecureConnectionTextPBModeEnabled;
     XPCOMUtils.defineLazyPreferenceGetter(this, "_insecureConnectionTextPBModeEnabled",
                                           "security.insecure_connection_text.pbmode.enabled");
     return this._insecureConnectionTextPBModeEnabled;
   },
+  get _protectionsPanelEnabled() {
+    delete this._protectionsPanelEnabled;
+    XPCOMUtils.defineLazyPreferenceGetter(this, "_protectionsPanelEnabled",
+                                          "browser.protections_panel.enabled",
+                                          false);
+    return this._protectionsPanelEnabled;
+  },
 
   /**
    * Handles clicks on the "Clear Cookies and Site Data" button.
    */
   async clearSiteData(event) {
     if (!this._uriHasHost) {
       return;
     }
@@ -827,16 +834,24 @@ var gIdentityHandler = {
       // NetUtil's methods will throw for malformed URIs and the like
     }
   },
 
   /**
    * Click handler for the identity-box element in primary chrome.
    */
   handleIdentityButtonEvent(event) {
+    // For Nightly users, show the WIP protections panel if the tracking
+    // protection icon was clicked.
+    if (this._protectionsPanelEnabled &&
+        event.originalTarget.id == "tracking-protection-icon-animatable-image") {
+      gProtectionsHandler.handleProtectionsButtonEvent(event);
+      return;
+    }
+
     event.stopPropagation();
 
     if ((event.type == "click" && event.button != 0) ||
         (event.type == "keypress" && event.charCode != KeyEvent.DOM_VK_SPACE &&
          event.keyCode != KeyEvent.DOM_VK_RETURN)) {
       return; // Left click, space or enter only
     }
 
new file mode 100644
--- /dev/null
+++ b/browser/base/content/browser-siteProtections.js
@@ -0,0 +1,39 @@
+/* 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/. */
+
+/* eslint-env mozilla/browser-window */
+
+/**
+ * Utility object to handle manipulations of the protections indicators in the UI
+ */
+var gProtectionsHandler = {
+  // smart getters
+  get _protectionsPopup() {
+    delete this._protectionsPopup;
+    return this._protectionsPopup = document.getElementById("protections-popup");
+  },
+  get _protectionsIconBox() {
+    delete this._protectionsIconBox;
+    return this._protectionsIconBox = document.getElementById("tracking-protection-icon-animatable-box");
+  },
+
+  handleProtectionsButtonEvent(event) {
+    event.stopPropagation();
+    if ((event.type == "click" && event.button != 0) ||
+        (event.type == "keypress" && event.charCode != KeyEvent.DOM_VK_SPACE &&
+         event.keyCode != KeyEvent.DOM_VK_RETURN)) {
+      return; // Left click, space or enter only
+    }
+
+    // Make sure that the display:none style we set in xul is removed now that
+    // the popup is actually needed
+    this._protectionsPopup.hidden = false;
+
+    // Now open the popup, anchored off the primary chrome element
+    PanelMultiView.openPopup(this._protectionsPopup, this._protectionsIconBox, {
+      position: "bottomcenter topleft",
+      triggerEvent: event,
+    }).catch(Cu.reportError);
+  },
+};
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -108,16 +108,18 @@ XPCOMUtils.defineLazyScriptGetter(this, 
 XPCOMUtils.defineLazyScriptGetter(this, "ctrlTab",
                                   "chrome://browser/content/browser-ctrlTab.js");
 XPCOMUtils.defineLazyScriptGetter(this, ["CustomizationHandler", "AutoHideMenubar"],
                                   "chrome://browser/content/browser-customization.js");
 XPCOMUtils.defineLazyScriptGetter(this, ["PointerLock", "FullScreen"],
                                   "chrome://browser/content/browser-fullScreenAndPointerLock.js");
 XPCOMUtils.defineLazyScriptGetter(this, "gIdentityHandler",
                                   "chrome://browser/content/browser-siteIdentity.js");
+XPCOMUtils.defineLazyScriptGetter(this, "gProtectionsHandler",
+                                  "chrome://browser/content/browser-siteProtections.js");
 XPCOMUtils.defineLazyScriptGetter(this, ["gGestureSupport", "gHistorySwipeAnimation"],
                                   "chrome://browser/content/browser-gestureSupport.js");
 XPCOMUtils.defineLazyScriptGetter(this, "gSafeBrowsing",
                                   "chrome://browser/content/browser-safebrowsing.js");
 XPCOMUtils.defineLazyScriptGetter(this, "gSync",
                                   "chrome://browser/content/browser-sync.js");
 XPCOMUtils.defineLazyScriptGetter(this, "gBrowserThumbnails",
                                   "chrome://browser/content/browser-thumbnails.js");
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -603,17 +603,18 @@
 #else
       <description class="tooltip-label" value="&backForwardButtonMenu.tooltip;"/>
 #endif
     </tooltip>
 
 #include popup-notifications.inc
 
 #include ../../components/customizableui/content/panelUI.inc.xul
-#include ../../components/controlcenter/content/panel.inc.xul
+#include ../../components/controlcenter/content/identityPanel.inc.xul
+#include ../../components/controlcenter/content/protectionsPanel.inc.xul
 #include ../../components/downloads/content/downloadsPanel.inc.xul
 #include browser-allTabsMenu.inc.xul
 
     <hbox id="downloads-animation-container" mousethrough="always">
       <vbox id="downloads-notification-anchor" hidden="true">
         <vbox id="downloads-indicator-notification"/>
       </vbox>
     </hbox>
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -47,16 +47,17 @@ browser.jar:
         content/browser/browser-gestureSupport.js     (content/browser-gestureSupport.js)
         content/browser/browser-media.js              (content/browser-media.js)
         content/browser/browser-pageActions.js        (content/browser-pageActions.js)
         content/browser/browser-places.js             (content/browser-places.js)
         content/browser/browser-plugins.js            (content/browser-plugins.js)
         content/browser/browser-safebrowsing.js       (content/browser-safebrowsing.js)
         content/browser/browser-sidebar.js            (content/browser-sidebar.js)
         content/browser/browser-siteIdentity.js       (content/browser-siteIdentity.js)
+        content/browser/browser-siteProtections.js    (content/browser-siteProtections.js)
         content/browser/browser-sync.js               (content/browser-sync.js)
         content/browser/browser-tabsintitlebar.js     (content/browser-tabsintitlebar.js)
         content/browser/browser-toolbarKeyNav.js      (content/browser-toolbarKeyNav.js)
         content/browser/browser-thumbnails.js         (content/browser-thumbnails.js)
         content/browser/browser-graphics-utils.js     (content/browser-graphics-utils.js)
         content/browser/tab-content.js                (content/tab-content.js)
         content/browser/content.js                    (content/content.js)
         content/browser/defaultthemes/1.header.jpg    (content/defaultthemes/1.header.jpg)
rename from browser/components/controlcenter/content/panel.inc.xul
rename to browser/components/controlcenter/content/identityPanel.inc.xul
new file mode 100644
--- /dev/null
+++ b/browser/components/controlcenter/content/protectionsPanel.inc.xul
@@ -0,0 +1,25 @@
+<!-- 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/. -->
+
+<panel id="protections-popup"
+       type="arrow"
+       hidden="true"
+       photon="true"
+       role="alertdialog"
+       orient="vertical">
+
+  <panelmultiview id="protections-popup-multiView"
+                  mainViewId="protections-popup-mainView">
+    <panelview id="protections-popup-mainView"
+               descriptionheightworkaround="true">
+      <vbox id="protections-popup-mainView-panel-header">
+        <label>
+          <html:span id="protections-popup-mainView-panel-header-span">
+            <html:h1>Watch this space! :)</html:h1>
+          </html:span>
+        </label>
+      </vbox>
+    </panelview>
+  </panelmultiview>
+</panel>