Bug 1555226 - Part 4: Implementing the switch flow for the mini panel. r=nhnt11
authorTim Huang <tihuang@mozilla.com>
Tue, 02 Jul 2019 08:14:34 +0000
changeset 543773 ad5b7db6a3c22272f0c87f67c61242929ba4cdb1
parent 543772 ab2c77c1aa02d55eed7d5425263fd0a60a3a65eb
child 543774 734b19770a7ee3e4919a0ea5df4955262d2460e7
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnhnt11
bugs1555226
milestone69.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 1555226 - Part 4: Implementing the switch flow for the mini panel. r=nhnt11 This patch makes the mini panel been shown after page reload due to switch the tracking protection state. The mini panel will be auto hidden after certain time, which can be configured by the pref 'browser.protections_panel.mini_panel_auto_hide_timing'. The default value is 5 seconds. This also implements the behavior that showing the protections panel on clicking the mini panel. Differential Revision: https://phabricator.services.mozilla.com/D36018
browser/base/content/browser-siteProtections.js
browser/base/content/browser.js
browser/components/controlcenter/content/protectionsPanel.inc.xul
--- a/browser/base/content/browser-siteProtections.js
+++ b/browser/base/content/browser-siteProtections.js
@@ -79,16 +79,45 @@ var gProtectionsHandler = {
 
   onPopupHidden(event) {
     if (event.target == this._protectionsPopup) {
       window.removeEventListener("focus", this, true);
       this._protectionsPopup.removeAttribute("open");
     }
   },
 
+  onHeaderClicked(event) {
+    // Display the whole protections panel if the toast has been clicked.
+    if (this._protectionsPopup.hasAttribute("toast")) {
+      // Hide the toast first.
+      PanelMultiView.hidePopup(this._protectionsPopup);
+
+      // Open the full protections panel.
+      this.showProtectionsPopup({event});
+    }
+  },
+
+  onLocationChange() {
+    if (!this._showToastAfterRefresh) {
+      return;
+    }
+
+    this._showToastAfterRefresh = false;
+
+    // We only display the toast if we're still on the same page.
+    if (this._previousURI != gBrowser.currentURI.spec ||
+        this._previousOuterWindowID != gBrowser.selectedBrowser.outerWindowID) {
+      return;
+    }
+
+    this.showProtectionsPopup({
+      toast: true,
+    });
+  },
+
   handleEvent(event) {
     let elem = document.activeElement;
     let position = elem.compareDocumentPosition(this._protectionsPopup);
 
     if (!(position & (Node.DOCUMENT_POSITION_CONTAINS |
                       Node.DOCUMENT_POSITION_CONTAINED_BY)) &&
         !this._protectionsPopup.hasAttribute("noautohide")) {
       // Hide the panel when focusing an element that is
@@ -139,16 +168,23 @@ var gProtectionsHandler = {
     this._TPSwitchCommanding = true;
 
     // Toggling the 'hasException' on the protections panel in order to do some
     // styling after toggling the TP switch.
     let newExceptionState =
       this._protectionsPopup.toggleAttribute("hasException");
     this._protectionsPopupTPSwitch.toggleAttribute("enabled", !newExceptionState);
 
+    // Indicating that we need to show a toast after refreshing the page.
+    // And caching the current URI and window ID in order to only show the mini
+    // panel if it's still on the same page.
+    this._showToastAfterRefresh = true;
+    this._previousURI = gBrowser.currentURI.spec;
+    this._previousOuterWindowID = gBrowser.selectedBrowser.outerWindowID;
+
     await new Promise((resolve) => setTimeout(resolve, 500));
 
     if (newExceptionState) {
       ContentBlocking.disableForCurrentPage();
       gIdentityHandler.recordClick("unblock");
     } else {
       ContentBlocking.enableForCurrentPage();
       gIdentityHandler.recordClick("block");
@@ -169,19 +205,18 @@ var gProtectionsHandler = {
    * Showing the protections popup.
    *
    * @param {Object} options
    *                 The object could have two properties.
    *                 event:
    *                   The event triggers the protections popup to be opened.
    *                 toast:
    *                   A boolean to indicate if we need to open the protections
-   *                   popup as a mini panel. A mini panel only has a header
-   *                   section and will be hidden after a certain amount of
-   *                   time.
+   *                   popup as a toast. A toast only has a header section and
+   *                   will be hidden after a certain amount of time.
    */
   showProtectionsPopup(options = {}) {
     const {event, toast} = options;
 
     // We need to clear the toast timer if it exists before showing the
     // protections popup.
     if (this._toastPanelTimer) {
       clearTimeout(this._toastPanelTimer);
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4895,16 +4895,18 @@ var XULBrowserWindow = {
       // if this is a document navigation then PopupNotifications will be updated
       // via TabsProgressListener.onLocationChange and we do not want it called twice
       URLBarSetURI(aLocationURI, aIsSimulated);
 
       BookmarkingUI.onLocationChange();
 
       gIdentityHandler.onLocationChange();
 
+      gProtectionsHandler.onLocationChange();
+
       BrowserPageActions.onLocationChange();
 
       SafeBrowsingNotificationBox.onLocationChange(aLocationURI);
 
       gTabletModePageCounter.inc();
 
       this._updateElementsForContentType();
 
--- a/browser/components/controlcenter/content/protectionsPanel.inc.xul
+++ b/browser/components/controlcenter/content/protectionsPanel.inc.xul
@@ -10,17 +10,18 @@
        onpopupshown="gProtectionsHandler.onPopupShown(event);"
        onpopuphidden="gProtectionsHandler.onPopupHidden(event);"
        orient="vertical">
 
   <panelmultiview id="protections-popup-multiView"
                   mainViewId="protections-popup-mainView">
     <panelview id="protections-popup-mainView"
                descriptionheightworkaround="true">
-      <hbox id="protections-popup-mainView-panel-header">
+      <hbox id="protections-popup-mainView-panel-header"
+            onclick="gProtectionsHandler.onHeaderClicked(event);">
         <label id="protections-popup-main-header-label">
           <html:span id="protections-popup-mainView-panel-header-span"/>
         </label>
         <description id="protections-popup-toast-panel-tp-on-desc">Enhanced Tracking Protection is ON for this site</description>
         <description id="protections-popup-toast-panel-tp-off-desc">Enhanced Tracking Protection is OFF for this site</description>
       </hbox>
 
       <hbox id="protections-popup-tp-switch-section" class="identity-popup-section">