Bug 1470020 - Part 4 - Don't handle Tracking Protection UI on file: and about: URIs. r=florian draft
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 21 Jun 2018 12:23:42 +0200
changeset 809316 b6aae33385ed3166c59c0c8733de0a9609f05d92
parent 809315 8ee2fa80246f592f5a0f7157728cdf812892ca3f
push id113633
push userjhofmann@mozilla.com
push dateThu, 21 Jun 2018 20:14:40 +0000
reviewersflorian
bugs1470020
milestone62.0a1
Bug 1470020 - Part 4 - Don't handle Tracking Protection UI on file: and about: URIs. r=florian ... because these URIs are incompatible with TP. We now show it on moz-extension: instead, which was forgotten previously. This should probably have been in its own separate bug, but the changes in bug 1470020 surfaced this issue by throwing a lot of console errors when the baseURI was accessed, so I didn't want to defer the fix. MozReview-Commit-ID: 8KNV0oabv7Y
browser/base/content/browser-trackingprotection.js
browser/components/controlcenter/content/panel.inc.xul
--- a/browser/base/content/browser-trackingprotection.js
+++ b/browser/base/content/browser-trackingprotection.js
@@ -14,17 +14,23 @@ var TrackingProtection = {
   icon: null,
   activeTooltipText: null,
   disabledTooltipText: null,
 
   get _baseURIForChannelClassifier() {
     // Convert document URI into the format used by
     // nsChannelClassifier::ShouldEnableTrackingProtection.
     // Any scheme turned into https is correct.
-    return Services.io.newURI("https://" + gBrowser.selectedBrowser.currentURI.hostPort);
+    try {
+      return Services.io.newURI("https://" + gBrowser.selectedBrowser.currentURI.hostPort);
+    } catch (e) {
+      // Getting the hostPort for about: and file: URIs fails, but TP doesn't work with
+      // these URIs anyway, so just return null here.
+      return null;
+    }
   },
 
   init() {
     let $ = selector => document.querySelector(selector);
     this.container = $("#tracking-protection-container");
     this.content = $("#tracking-protection-content");
     this.icon = $("#tracking-protection-icon");
     this.broadcaster = $("#trackingProtectionBroadcaster");
@@ -128,33 +134,40 @@ var TrackingProtection = {
   shieldHistogramAdd(value) {
     if (PrivateBrowsingUtils.isWindowPrivate(window)) {
       return;
     }
     Services.telemetry.getHistogramById("TRACKING_PROTECTION_SHIELD").add(value);
   },
 
   onSecurityChange(state, isSimulated) {
+    let baseURI = this._baseURIForChannelClassifier;
+
+    // Don't deal with about:, file: etc.
+    if (!baseURI) {
+      return;
+    }
+
     // Only animate the shield if the event was not fired directly from
     // the tabbrowser (due to a browser change).
     if (isSimulated) {
       this.icon.removeAttribute("animate");
     } else {
       this.icon.setAttribute("animate", "true");
     }
 
     let isBlocking = state & Ci.nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT;
     let isAllowing = state & Ci.nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT;
 
     // Check whether the user has added an exception for this site.
     let hasException = false;
     if (PrivateBrowsingUtils.isBrowserPrivate(gBrowser.selectedBrowser)) {
-      hasException = PrivateBrowsingUtils.existsInTrackingAllowlist(this._baseURIForChannelClassifier);
+      hasException = PrivateBrowsingUtils.existsInTrackingAllowlist(baseURI);
     } else {
-      hasException = Services.perms.testExactPermission(this._baseURIForChannelClassifier,
+      hasException = Services.perms.testExactPermission(baseURI,
         "trackingprotection") == Services.perms.ALLOW_ACTION;
     }
 
     if (hasException) {
       this.content.setAttribute("hasException", "true");
     } else {
       this.content.removeAttribute("hasException");
     }
--- a/browser/components/controlcenter/content/panel.inc.xul
+++ b/browser/components/controlcenter/content/panel.inc.xul
@@ -50,17 +50,17 @@
                 class="identity-popup-expander"
                 when-connection="not-secure secure secure-ev secure-cert-user-overridden"
                 oncommand="gIdentityHandler.showSecuritySubView();"/>
       </hbox>
 
       <!-- Tracking Protection Section -->
       <hbox id="tracking-protection-container"
             class="identity-popup-section"
-            when-connection="not-secure secure secure-ev secure-cert-user-overridden file">
+            when-connection="not-secure secure secure-ev secure-cert-user-overridden extension">
         <vbox id="tracking-protection-content" flex="1">
           <hbox class="identity-popup-preferences-button-container">
             <label id="tracking-protection-label-on"
                    class="identity-popup-headline"
                    crop="end"
                    value="&trackingProtection.on;" />
             <label id="tracking-protection-label-off"
                    class="identity-popup-headline"