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

--HG--
extra : rebase_source : b6aae33385ed3166c59c0c8733de0a9609f05d92
This commit is contained in:
Johann Hofmann 2018-06-21 12:23:42 +02:00
parent 6d3223de0f
commit 3fe5e7fa6c
2 changed files with 17 additions and 4 deletions

View File

@ -19,7 +19,13 @@ var TrackingProtection = {
// 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() {
@ -133,6 +139,13 @@ var TrackingProtection = {
},
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) {
@ -147,9 +160,9 @@ var TrackingProtection = {
// 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;
}

View File

@ -55,7 +55,7 @@
<!-- 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"