Bug 1470020 - Part 4 - Don't handle Tracking Protection UI on file: and about: URIs. r=florian
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 21 Jun 2018 12:23:42 +0200
changeset 477541 6e0fc38940b484f165c4e76551d1bc91ded92ab7
parent 477540 00c94772a661b82c8fae8b520211cd47e8cd6251
child 477542 6fd500bb5dd80e0695920b6ecf343eab05ec46fc
push id9385
push userdluca@mozilla.com
push dateFri, 22 Jun 2018 15:47:18 +0000
treeherdermozilla-beta@82a9a1027e2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1470020
milestone62.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 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"