Backed out changeset 76f3be6b25e1 (bug 1513298) for ES lint failure in test_fingerprinting.html CLOSED TREE

This commit is contained in:
Noemi Erli 2019-01-09 12:15:44 +02:00
Родитель 1981ff9293
Коммит ac42324894
13 изменённых файлов: 8 добавлений и 366 удалений

Просмотреть файл

@ -1784,13 +1784,6 @@ VARCACHE_PREF(
bool, true bool, true
) )
// Block 3rd party fingerprinting resources.
VARCACHE_PREF(
"privacy.trackingprotection.fingerprinting.enabled",
privacy_trackingprotection_fingerprinting_enabled,
bool, true
)
// Lower the priority of network loads for resources on the tracking protection // Lower the priority of network loads for resources on the tracking protection
// list. Note that this requires the // list. Note that this requires the
// privacy.trackingprotection.annotate_channels pref to be on in order to have // privacy.trackingprotection.annotate_channels pref to be on in order to have

Просмотреть файл

@ -87,13 +87,13 @@ LazyLogModule UrlClassifierCommon::sLog("nsChannelClassifier");
pwin->NotifyContentBlockingState(aBlockedReason, aChannel, true, uri); pwin->NotifyContentBlockingState(aBlockedReason, aChannel, true, uri);
} }
/* static */ bool UrlClassifierCommon::ShouldEnableClassifier( /* static */ bool
UrlClassifierCommon::ShouldEnableTrackingProtectionOrAnnotation(
nsIChannel* aChannel, nsIChannel* aChannel,
AntiTrackingCommon::ContentBlockingAllowListPurpose aBlockingPurpose) { AntiTrackingCommon::ContentBlockingAllowListPurpose aBlockingPurpose) {
MOZ_ASSERT(aChannel); MOZ_ASSERT(aChannel);
MOZ_ASSERT(aBlockingPurpose == AntiTrackingCommon::eTrackingProtection || MOZ_ASSERT(aBlockingPurpose == AntiTrackingCommon::eTrackingProtection ||
aBlockingPurpose == AntiTrackingCommon::eTrackingAnnotations || aBlockingPurpose == AntiTrackingCommon::eTrackingAnnotations);
aBlockingPurpose == AntiTrackingCommon::eFingerprinting);
nsCOMPtr<nsIHttpChannelInternal> channel = do_QueryInterface(aChannel); nsCOMPtr<nsIHttpChannelInternal> channel = do_QueryInterface(aChannel);
if (!channel) { if (!channel) {

Просмотреть файл

@ -33,7 +33,7 @@ class UrlClassifierCommon final {
static void NotifyChannelBlocked(nsIChannel* aChannel, static void NotifyChannelBlocked(nsIChannel* aChannel,
unsigned aBlockedReason); unsigned aBlockedReason);
static bool ShouldEnableClassifier( static bool ShouldEnableTrackingProtectionOrAnnotation(
nsIChannel* aChannel, nsIChannel* aChannel,
AntiTrackingCommon::ContentBlockingAllowListPurpose aBlockingPurpose); AntiTrackingCommon::ContentBlockingAllowListPurpose aBlockingPurpose);

Просмотреть файл

@ -7,7 +7,6 @@
#include "mozilla/net/UrlClassifierFeatureFactory.h" #include "mozilla/net/UrlClassifierFeatureFactory.h"
// List of Features // List of Features
#include "UrlClassifierFeatureFingerprinting.h"
#include "UrlClassifierFeatureFlash.h" #include "UrlClassifierFeatureFlash.h"
#include "UrlClassifierFeatureLoginReputation.h" #include "UrlClassifierFeatureLoginReputation.h"
#include "UrlClassifierFeatureTrackingProtection.h" #include "UrlClassifierFeatureTrackingProtection.h"
@ -25,7 +24,6 @@ namespace net {
return; return;
} }
UrlClassifierFeatureFingerprinting::MaybeShutdown();
UrlClassifierFeatureFlash::MaybeShutdown(); UrlClassifierFeatureFlash::MaybeShutdown();
UrlClassifierFeatureLoginReputation::MaybeShutdown(); UrlClassifierFeatureLoginReputation::MaybeShutdown();
UrlClassifierFeatureTrackingAnnotation::MaybeShutdown(); UrlClassifierFeatureTrackingAnnotation::MaybeShutdown();
@ -45,12 +43,6 @@ namespace net {
// feature order, and this could produce different results with a different // feature order, and this could produce different results with a different
// feature ordering. // feature ordering.
// Fingerprinting
feature = UrlClassifierFeatureFingerprinting::MaybeCreate(aChannel);
if (feature) {
aFeatures.AppendElement(feature);
}
// Tracking Protection // Tracking Protection
feature = UrlClassifierFeatureTrackingProtection::MaybeCreate(aChannel); feature = UrlClassifierFeatureTrackingProtection::MaybeCreate(aChannel);
if (feature) { if (feature) {
@ -83,12 +75,6 @@ UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
nsCOMPtr<nsIUrlClassifierFeature> feature; nsCOMPtr<nsIUrlClassifierFeature> feature;
// Fingerprinting
feature = UrlClassifierFeatureFingerprinting::GetIfNameMatches(aName);
if (feature) {
return feature.forget();
}
// Tracking Protection // Tracking Protection
feature = UrlClassifierFeatureTrackingProtection::GetIfNameMatches(aName); feature = UrlClassifierFeatureTrackingProtection::GetIfNameMatches(aName);
if (feature) { if (feature) {
@ -122,14 +108,8 @@ UrlClassifierFeatureFactory::GetFeatureByName(const nsACString& aName) {
return; return;
} }
// Fingerprinting
nsAutoCString name;
name.Assign(UrlClassifierFeatureFingerprinting::Name());
if (!name.IsEmpty()) {
aArray.AppendElement(name);
}
// Tracking Protection // Tracking Protection
nsAutoCString name;
name.Assign(UrlClassifierFeatureTrackingProtection::Name()); name.Assign(UrlClassifierFeatureTrackingProtection::Name());
if (!name.IsEmpty()) { if (!name.IsEmpty()) {
aArray.AppendElement(name); aArray.AppendElement(name);

Просмотреть файл

@ -1,177 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "UrlClassifierFeatureFingerprinting.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/StaticPrefs.h"
#include "nsContentUtils.h"
#include "nsNetUtil.h"
namespace mozilla {
namespace net {
namespace {
#define FINGERPRINTING_FEATURE_NAME "fingerprinting"
#define URLCLASSIFIER_FINGERPRINTING_BLACKLIST \
"urlclassifier.features.fingerprinting.blacklistTables"
#define URLCLASSIFIER_FINGERPRINTING_BLACKLIST_TEST_ENTRIES \
"urlclassifier.features.fingerprinting.blacklistHosts"
#define URLCLASSIFIER_FINGERPRINTING_WHITELIST \
"urlclassifier.features.fingerprinting.whitelistTables"
#define URLCLASSIFIER_FINGERPRINTING_WHITELIST_TEST_ENTRIES \
"urlclassifier.features.fingerprinting.whitelistHosts"
#define TABLE_FINGERPRINTING_BLACKLIST_PREF "fingerprinting-blacklist-pref"
#define TABLE_FINGERPRINTING_WHITELIST_PREF "fingerprinting-whitelist-pref"
StaticRefPtr<UrlClassifierFeatureFingerprinting> gFeatureFingerprinting;
} // namespace
UrlClassifierFeatureFingerprinting::UrlClassifierFeatureFingerprinting()
: UrlClassifierFeatureBase(
NS_LITERAL_CSTRING(FINGERPRINTING_FEATURE_NAME),
NS_LITERAL_CSTRING(URLCLASSIFIER_FINGERPRINTING_BLACKLIST),
NS_LITERAL_CSTRING(URLCLASSIFIER_FINGERPRINTING_WHITELIST),
NS_LITERAL_CSTRING(
URLCLASSIFIER_FINGERPRINTING_BLACKLIST_TEST_ENTRIES),
NS_LITERAL_CSTRING(
URLCLASSIFIER_FINGERPRINTING_WHITELIST_TEST_ENTRIES),
NS_LITERAL_CSTRING(TABLE_FINGERPRINTING_BLACKLIST_PREF),
NS_LITERAL_CSTRING(TABLE_FINGERPRINTING_WHITELIST_PREF),
EmptyCString()) {}
/* static */ const char* UrlClassifierFeatureFingerprinting::Name() {
return FINGERPRINTING_FEATURE_NAME;
}
/* static */ void UrlClassifierFeatureFingerprinting::MaybeInitialize() {
UC_LOG(("UrlClassifierFeatureFingerprinting: MaybeInitialize"));
if (!gFeatureFingerprinting) {
gFeatureFingerprinting = new UrlClassifierFeatureFingerprinting();
gFeatureFingerprinting->InitializePreferences();
}
}
/* static */ void UrlClassifierFeatureFingerprinting::MaybeShutdown() {
UC_LOG(("UrlClassifierFeatureFingerprinting: MaybeShutdown"));
if (gFeatureFingerprinting) {
gFeatureFingerprinting->ShutdownPreferences();
gFeatureFingerprinting = nullptr;
}
}
/* static */ already_AddRefed<UrlClassifierFeatureFingerprinting>
UrlClassifierFeatureFingerprinting::MaybeCreate(nsIChannel* aChannel) {
MOZ_ASSERT(aChannel);
UC_LOG(("UrlClassifierFeatureFingerprinting: MaybeCreate for channel %p",
aChannel));
if (!StaticPrefs::privacy_trackingprotection_fingerprinting_enabled()) {
return nullptr;
}
nsCOMPtr<nsIURI> chanURI;
nsresult rv = aChannel->GetURI(getter_AddRefs(chanURI));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
bool isThirdParty =
nsContentUtils::IsThirdPartyWindowOrChannel(nullptr, aChannel, chanURI);
if (!isThirdParty) {
if (UC_LOG_ENABLED()) {
nsCString spec = chanURI->GetSpecOrDefault();
spec.Truncate(
std::min(spec.Length(), UrlClassifierCommon::sMaxSpecLength));
UC_LOG(
("UrlClassifierFeatureFingerprinting: Skipping fingerprinting checks "
"for first party or top-level load channel[%p] "
"with uri %s",
aChannel, spec.get()));
}
return nullptr;
}
if (!UrlClassifierCommon::ShouldEnableClassifier(
aChannel, AntiTrackingCommon::eFingerprinting)) {
return nullptr;
}
MaybeInitialize();
MOZ_ASSERT(gFeatureFingerprinting);
RefPtr<UrlClassifierFeatureFingerprinting> self = gFeatureFingerprinting;
return self.forget();
}
/* static */ already_AddRefed<nsIUrlClassifierFeature>
UrlClassifierFeatureFingerprinting::GetIfNameMatches(const nsACString& aName) {
if (!aName.EqualsLiteral(FINGERPRINTING_FEATURE_NAME)) {
return nullptr;
}
MaybeInitialize();
MOZ_ASSERT(gFeatureFingerprinting);
RefPtr<UrlClassifierFeatureFingerprinting> self = gFeatureFingerprinting;
return self.forget();
}
NS_IMETHODIMP
UrlClassifierFeatureFingerprinting::ProcessChannel(nsIChannel* aChannel,
const nsACString& aList,
bool* aShouldContinue) {
NS_ENSURE_ARG_POINTER(aChannel);
NS_ENSURE_ARG_POINTER(aShouldContinue);
// This is a blocking feature.
*aShouldContinue = false;
UrlClassifierCommon::SetBlockedContent(aChannel, NS_ERROR_TRACKING_URI, aList,
EmptyCString(), EmptyCString());
UC_LOG(
("UrlClassifierFeatureFingerprinting::ProcessChannel, cancelling "
"channel[%p]",
aChannel));
nsCOMPtr<nsIHttpChannelInternal> httpChannel = do_QueryInterface(aChannel);
// FIXME: the way we cancel the channel depends on what the UI wants to show.
// This needs to change, at some point.
if (httpChannel) {
Unused << httpChannel->CancelForTrackingProtection();
} else {
Unused << aChannel->Cancel(NS_ERROR_TRACKING_URI);
}
return NS_OK;
}
NS_IMETHODIMP
UrlClassifierFeatureFingerprinting::GetURIByListType(
nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,
nsIURI** aURI) {
NS_ENSURE_ARG_POINTER(aChannel);
NS_ENSURE_ARG_POINTER(aURI);
if (aListType == nsIUrlClassifierFeature::blacklist) {
return aChannel->GetURI(aURI);
}
MOZ_ASSERT(aListType == nsIUrlClassifierFeature::whitelist);
return UrlClassifierCommon::CreatePairwiseWhiteListURI(aChannel, aURI);
}
} // namespace net
} // namespace mozilla

Просмотреть файл

@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_net_UrlClassifierFeatureFingerprinting_h
#define mozilla_net_UrlClassifierFeatureFingerprinting_h
#include "UrlClassifierFeatureBase.h"
class nsIChannel;
namespace mozilla {
namespace net {
class UrlClassifierFeatureFingerprinting final
: public UrlClassifierFeatureBase {
public:
static const char* Name();
static void MaybeShutdown();
static already_AddRefed<UrlClassifierFeatureFingerprinting> MaybeCreate(
nsIChannel* aChannel);
static already_AddRefed<nsIUrlClassifierFeature> GetIfNameMatches(
const nsACString& aName);
NS_IMETHOD ProcessChannel(nsIChannel* aChannel, const nsACString& aList,
bool* aShouldContinue) override;
NS_IMETHOD GetURIByListType(nsIChannel* aChannel,
nsIUrlClassifierFeature::listType aListType,
nsIURI** aURI) override;
private:
UrlClassifierFeatureFingerprinting();
static void MaybeInitialize();
};
} // namespace net
} // namespace mozilla
#endif // mozilla_net_UrlClassifierFeatureFingerprinting_h

Просмотреть файл

@ -154,7 +154,7 @@ UrlClassifierFeatureTrackingAnnotation::MaybeCreate(nsIChannel* aChannel) {
return nullptr; return nullptr;
} }
if (!UrlClassifierCommon::ShouldEnableClassifier( if (!UrlClassifierCommon::ShouldEnableTrackingProtectionOrAnnotation(
aChannel, AntiTrackingCommon::eTrackingAnnotations)) { aChannel, AntiTrackingCommon::eTrackingAnnotations)) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -101,7 +101,7 @@ UrlClassifierFeatureTrackingProtection::MaybeCreate(nsIChannel* aChannel) {
return nullptr; return nullptr;
} }
if (!UrlClassifierCommon::ShouldEnableClassifier( if (!UrlClassifierCommon::ShouldEnableTrackingProtectionOrAnnotation(
aChannel, AntiTrackingCommon::eTrackingProtection)) { aChannel, AntiTrackingCommon::eTrackingProtection)) {
return nullptr; return nullptr;
} }

Просмотреть файл

@ -24,7 +24,6 @@ UNIFIED_SOURCES += [
'UrlClassifierFeatureBase.cpp', 'UrlClassifierFeatureBase.cpp',
'UrlClassifierFeatureCustomTables.cpp', 'UrlClassifierFeatureCustomTables.cpp',
'UrlClassifierFeatureFactory.cpp', 'UrlClassifierFeatureFactory.cpp',
'UrlClassifierFeatureFingerprinting.cpp',
'UrlClassifierFeatureFlash.cpp', 'UrlClassifierFeatureFlash.cpp',
'UrlClassifierFeatureLoginReputation.cpp', 'UrlClassifierFeatureLoginReputation.cpp',
'UrlClassifierFeatureResult.cpp', 'UrlClassifierFeatureResult.cpp',

Просмотреть файл

@ -1372,9 +1372,7 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
if ((aPurpose == eStorageChecks && if ((aPurpose == eStorageChecks &&
!StaticPrefs::browser_contentblocking_allowlist_storage_enabled()) || !StaticPrefs::browser_contentblocking_allowlist_storage_enabled()) ||
(aPurpose == eTrackingAnnotations && (aPurpose == eTrackingAnnotations &&
!StaticPrefs::browser_contentblocking_allowlist_annotations_enabled()) || !StaticPrefs::browser_contentblocking_allowlist_annotations_enabled())) {
(aPurpose == eFingerprinting &&
!StaticPrefs::privacy_trackingprotection_fingerprinting_enabled())) {
LOG( LOG(
("Attempting to check the content blocking allow list aborted because " ("Attempting to check the content blocking allow list aborted because "
"the third-party cookies UI has been disabled.")); "the third-party cookies UI has been disabled."));

Просмотреть файл

@ -120,7 +120,6 @@ class AntiTrackingCommon final {
eStorageChecks, eStorageChecks,
eTrackingProtection, eTrackingProtection,
eTrackingAnnotations, eTrackingAnnotations,
eFingerprinting,
}; };
// Check whether a top window URI is on the content blocking allow list. // Check whether a top window URI is on the content blocking allow list.

Просмотреть файл

@ -45,4 +45,3 @@ skip-if = (verify && debug && (os == 'win' || os == 'mac'))
[test_cachemiss.html] [test_cachemiss.html]
skip-if = verify skip-if = verify
[test_annotation_vs_TP.html] [test_annotation_vs_TP.html]
[test_fingerprinting.html]

Просмотреть файл

@ -1,103 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test the fingerprinting classifier</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
var tests = [
// All disabled.
{ config: [ false, false ], loadExpected: true },
// Just whitelisted.
{ config: [ false, true ], loadExpected: true },
// Just blacklisted.
{ config: [ true, false ], loadExpected: false },
// whitelist + blacklist: whitelist wins
{ config: [ true, true ], loadExpected: true },
];
function prefValue(value, what) {
return value ? what : "";
}
async function runTest(test) {
await SpecialPowers.pushPrefEnv({set: [
[ "urlclassifier.features.fingerprinting.blacklistHosts", prefValue(test.config[0], "example.com") ],
[ "urlclassifier.features.fingerprinting.whitelistHosts", prefValue(test.config[1], "mochi.test") ],
[ "urlclassifier.features.fingerprinting.blacklistTables", prefValue(test.config[0], "mochitest1-track-simple") ],
[ "urlclassifier.features.fingerprinting.whitelistTables", "" ],
[ "privacy.trackingprotection.enabled", false ],
[ "privacy.trackingprotection.annotate_channels", false ],
[ "privacy.trackingprotection.fingerprinting.enabled", true ],
]});
info("Testing: " + test.config.toSource() + "\n");
// Let's load an image with a random query string, just to avoid network cache.
let result = await new Promise(resolve => {
let image = new Image();
image.src = "http://example.com/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg?" + Math.random();
image.onload = _ => resolve(true);
image.onerror = _ => resolve(false);
});
is(result, test.loadExpected, "The loading happened correctly");
// Let's load an image with a random query string, just to avoid network cache.
result = await new Promise(resolve => {
let image = new Image();
image.src = "http://tracking.example.org/tests/toolkit/components/url-classifier/tests/mochitest/raptor.jpg?" + Math.random();
image.onload = _ => resolve(true);
image.onerror = _ => resolve(false);
});
is(result, test.loadExpected, "The loading happened correctly (by table)");
}
async function runTests() {
let chromeScript = SpecialPowers.loadChromeScript(_ => {
ChromeUtils.import("resource://testing-common/UrlClassifierTestUtils.jsm");
addMessageListener("loadTrackers", _ => {
UrlClassifierTestUtils.addTestTrackers().then(_ => {
sendAsyncMessage("trackersLoaded");
});
});
addMessageListener("unloadTrackers",_ => {
UrlClassifierTestUtils.cleanupTestTrackers();
sendAsyncMessage("trackersUnloaded");
});
});
await new Promise(resolve => {
chromeScript.addMessageListener("trackersLoaded", resolve);
chromeScript.sendAsyncMessage("loadTrackers");
});
for (let test in tests) {
await runTest(tests[test]);
}
await new Promise(resolve => {
chromeScript.addMessageListener("trackersUnloaded", resolve);
chromeScript.sendSyncMessage("unloadTrackers");
});
chromeScript.destroy();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
runTests();
</script>
</body>
</html>