Bug 1799435 - Make RFP checks faster. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D161447
This commit is contained in:
@@ -1413,6 +1413,12 @@ Document::Document(const char* aContentType)
|
|||||||
mIsRunningExecCommand(false),
|
mIsRunningExecCommand(false),
|
||||||
mSetCompleteAfterDOMContentLoaded(false),
|
mSetCompleteAfterDOMContentLoaded(false),
|
||||||
mDidHitCompleteSheetCache(false),
|
mDidHitCompleteSheetCache(false),
|
||||||
|
mUseCountersInitialized(false),
|
||||||
|
mShouldReportUseCounters(false),
|
||||||
|
mShouldSendPageUseCounters(false),
|
||||||
|
mUserHasInteracted(false),
|
||||||
|
mHasUserInteractionTimerScheduled(false),
|
||||||
|
mShouldResistFingerprinting(false),
|
||||||
mPendingFullscreenRequests(0),
|
mPendingFullscreenRequests(0),
|
||||||
mXMLDeclarationBits(0),
|
mXMLDeclarationBits(0),
|
||||||
mOnloadBlockCount(0),
|
mOnloadBlockCount(0),
|
||||||
@@ -1441,11 +1447,6 @@ Document::Document(const char* aContentType)
|
|||||||
mBFCacheEntry(nullptr),
|
mBFCacheEntry(nullptr),
|
||||||
mInSyncOperationCount(0),
|
mInSyncOperationCount(0),
|
||||||
mBlockDOMContentLoaded(0),
|
mBlockDOMContentLoaded(0),
|
||||||
mUseCountersInitialized(false),
|
|
||||||
mShouldReportUseCounters(false),
|
|
||||||
mShouldSendPageUseCounters(false),
|
|
||||||
mUserHasInteracted(false),
|
|
||||||
mHasUserInteractionTimerScheduled(false),
|
|
||||||
mStackRefCnt(0),
|
mStackRefCnt(0),
|
||||||
mUpdateNestLevel(0),
|
mUpdateNestLevel(0),
|
||||||
mHttpsOnlyStatus(nsILoadInfo::HTTPS_ONLY_UNINITIALIZED),
|
mHttpsOnlyStatus(nsILoadInfo::HTTPS_ONLY_UNINITIALIZED),
|
||||||
@@ -2833,6 +2834,7 @@ void Document::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mChannel = aChannel;
|
mChannel = aChannel;
|
||||||
|
RecomputeResistFingerprinting();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::DisconnectNodeTree() {
|
void Document::DisconnectNodeTree() {
|
||||||
@@ -3454,6 +3456,7 @@ nsresult Document::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
|||||||
RetrieveRelevantHeaders(aChannel);
|
RetrieveRelevantHeaders(aChannel);
|
||||||
|
|
||||||
mChannel = aChannel;
|
mChannel = aChannel;
|
||||||
|
RecomputeResistFingerprinting();
|
||||||
nsCOMPtr<nsIInputStreamChannel> inStrmChan = do_QueryInterface(mChannel);
|
nsCOMPtr<nsIInputStreamChannel> inStrmChan = do_QueryInterface(mChannel);
|
||||||
if (inStrmChan) {
|
if (inStrmChan) {
|
||||||
bool isSrcdocChannel;
|
bool isSrcdocChannel;
|
||||||
@@ -11867,6 +11870,7 @@ nsresult Document::CloneDocHelper(Document* clone) const {
|
|||||||
uri = Document::GetDocumentURI();
|
uri = Document::GetDocumentURI();
|
||||||
}
|
}
|
||||||
clone->mChannel = channel;
|
clone->mChannel = channel;
|
||||||
|
clone->mShouldResistFingerprinting = mShouldResistFingerprinting;
|
||||||
if (uri) {
|
if (uri) {
|
||||||
clone->ResetToURI(uri, loadGroup, NodePrincipal(), mPartitionedPrincipal);
|
clone->ResetToURI(uri, loadGroup, NodePrincipal(), mPartitionedPrincipal);
|
||||||
}
|
}
|
||||||
@@ -15687,6 +15691,12 @@ void Document::SendPageUseCounters() {
|
|||||||
wgc->SendAccumulatePageUseCounters(counters);
|
wgc->SendAccumulatePageUseCounters(counters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Document::RecomputeResistFingerprinting() {
|
||||||
|
mShouldResistFingerprinting =
|
||||||
|
!nsContentUtils::IsChromeDoc(this) &&
|
||||||
|
nsContentUtils::ShouldResistFingerprinting(mChannel);
|
||||||
|
}
|
||||||
|
|
||||||
WindowContext* Document::GetWindowContextForPageUseCounters() const {
|
WindowContext* Document::GetWindowContextForPageUseCounters() const {
|
||||||
if (mDisplayDocument) {
|
if (mDisplayDocument) {
|
||||||
// If we are a resource document, then go through it to find the
|
// If we are a resource document, then go through it to find the
|
||||||
@@ -17842,8 +17852,7 @@ ColorScheme Document::DefaultColorScheme() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ColorScheme Document::PreferredColorScheme(IgnoreRFP aIgnoreRFP) const {
|
ColorScheme Document::PreferredColorScheme(IgnoreRFP aIgnoreRFP) const {
|
||||||
if (aIgnoreRFP == IgnoreRFP::No &&
|
if (ShouldResistFingerprinting() && aIgnoreRFP == IgnoreRFP::No) {
|
||||||
nsContentUtils::ShouldResistFingerprinting(this)) {
|
|
||||||
return ColorScheme::Light;
|
return ColorScheme::Light;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4087,6 +4087,12 @@ class Document : public nsINode,
|
|||||||
|
|
||||||
bool DidHitCompleteSheetCache() const { return mDidHitCompleteSheetCache; }
|
bool DidHitCompleteSheetCache() const { return mDidHitCompleteSheetCache; }
|
||||||
|
|
||||||
|
bool ShouldResistFingerprinting() const {
|
||||||
|
return mShouldResistFingerprinting;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecomputeResistFingerprinting();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Returns the WindowContext for the document that we will contribute
|
// Returns the WindowContext for the document that we will contribute
|
||||||
// page use counters to.
|
// page use counters to.
|
||||||
@@ -4827,6 +4833,29 @@ class Document : public nsINode,
|
|||||||
// Set the true if a completed cached stylesheet was created for the document.
|
// Set the true if a completed cached stylesheet was created for the document.
|
||||||
bool mDidHitCompleteSheetCache : 1;
|
bool mDidHitCompleteSheetCache : 1;
|
||||||
|
|
||||||
|
// Whether we have initialized mShouldReportUseCounters and
|
||||||
|
// mShouldSendPageUseCounters, and sent any needed message to the parent
|
||||||
|
// process to indicate that use counter data will be sent at some later point.
|
||||||
|
bool mUseCountersInitialized : 1;
|
||||||
|
|
||||||
|
// Whether this document should report use counters.
|
||||||
|
bool mShouldReportUseCounters : 1;
|
||||||
|
|
||||||
|
// Whether this document should send page use counters. Set to true after
|
||||||
|
// we've called SendExpectPageUseCounters on the top-level WindowGlobal.
|
||||||
|
bool mShouldSendPageUseCounters : 1;
|
||||||
|
|
||||||
|
// Whether the user has interacted with the document or not:
|
||||||
|
bool mUserHasInteracted : 1;
|
||||||
|
|
||||||
|
// We constantly update the user-interaction anti-tracking permission at any
|
||||||
|
// user-interaction using a timer. This boolean value is set to true when this
|
||||||
|
// timer is scheduled.
|
||||||
|
bool mHasUserInteractionTimerScheduled : 1;
|
||||||
|
|
||||||
|
// Whether we should resist fingerprinting.
|
||||||
|
bool mShouldResistFingerprinting : 1;
|
||||||
|
|
||||||
uint8_t mPendingFullscreenRequests;
|
uint8_t mPendingFullscreenRequests;
|
||||||
|
|
||||||
uint8_t mXMLDeclarationBits;
|
uint8_t mXMLDeclarationBits;
|
||||||
@@ -5033,26 +5062,6 @@ class Document : public nsINode,
|
|||||||
// The CSS property use counters.
|
// The CSS property use counters.
|
||||||
UniquePtr<StyleUseCounters> mStyleUseCounters;
|
UniquePtr<StyleUseCounters> mStyleUseCounters;
|
||||||
|
|
||||||
// Whether we have initialized mShouldReportUseCounters and
|
|
||||||
// mShouldSendPageUseCounters, and sent any needed message to the parent
|
|
||||||
// process to indicate that use counter data will be sent at some later point.
|
|
||||||
bool mUseCountersInitialized : 1;
|
|
||||||
|
|
||||||
// Whether this document should report use counters.
|
|
||||||
bool mShouldReportUseCounters : 1;
|
|
||||||
|
|
||||||
// Whether this document should send page use counters. Set to true after
|
|
||||||
// we've called SendExpectPageUseCounters on the top-level WindowGlobal.
|
|
||||||
bool mShouldSendPageUseCounters : 1;
|
|
||||||
|
|
||||||
// Whether the user has interacted with the document or not:
|
|
||||||
bool mUserHasInteracted;
|
|
||||||
|
|
||||||
// We constantly update the user-interaction anti-tracking permission at any
|
|
||||||
// user-interaction using a timer. This boolean value is set to true when this
|
|
||||||
// timer is scheduled.
|
|
||||||
bool mHasUserInteractionTimerScheduled;
|
|
||||||
|
|
||||||
TimeStamp mPageUnloadingEventTimeStamp;
|
TimeStamp mPageUnloadingEventTimeStamp;
|
||||||
|
|
||||||
RefPtr<DocGroup> mDocGroup;
|
RefPtr<DocGroup> mDocGroup;
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ nsDOMAttributeMap* Element::Attributes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Element::SetPointerCapture(int32_t aPointerId, ErrorResult& aError) {
|
void Element::SetPointerCapture(int32_t aPointerId, ErrorResult& aError) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(GetComposedDoc()) &&
|
if (OwnerDoc()->ShouldResistFingerprinting() &&
|
||||||
aPointerId != PointerEventHandler::GetSpoofedPointerIdForRFP()) {
|
aPointerId != PointerEventHandler::GetSpoofedPointerIdForRFP()) {
|
||||||
aError.ThrowNotFoundError("Invalid pointer id");
|
aError.ThrowNotFoundError("Invalid pointer id");
|
||||||
return;
|
return;
|
||||||
@@ -307,7 +307,7 @@ void Element::SetPointerCapture(int32_t aPointerId, ErrorResult& aError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Element::ReleasePointerCapture(int32_t aPointerId, ErrorResult& aError) {
|
void Element::ReleasePointerCapture(int32_t aPointerId, ErrorResult& aError) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(GetComposedDoc()) &&
|
if (OwnerDoc()->ShouldResistFingerprinting() &&
|
||||||
aPointerId != PointerEventHandler::GetSpoofedPointerIdForRFP()) {
|
aPointerId != PointerEventHandler::GetSpoofedPointerIdForRFP()) {
|
||||||
aError.ThrowNotFoundError("Invalid pointer id");
|
aError.ThrowNotFoundError("Invalid pointer id");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ uint64_t Navigator::HardwareConcurrency() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return rts->ClampedHardwareConcurrency(
|
return rts->ClampedHardwareConcurrency(
|
||||||
nsContentUtils::ShouldResistFingerprinting(mWindow->GetExtantDoc()));
|
nsGlobalWindowInner::Cast(mWindow)->ShouldResistFingerprinting());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -1564,6 +1564,11 @@ void Navigator::ValidateShareData(const ShareData& aData, ErrorResult& aRv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ShouldResistFingerprinting(const Document* aDoc) {
|
||||||
|
return aDoc ? aDoc->ShouldResistFingerprinting()
|
||||||
|
: nsContentUtils::ShouldResistFingerprinting("Fallback");
|
||||||
|
}
|
||||||
|
|
||||||
already_AddRefed<LegacyMozTCPSocket> Navigator::MozTCPSocket() {
|
already_AddRefed<LegacyMozTCPSocket> Navigator::MozTCPSocket() {
|
||||||
RefPtr<LegacyMozTCPSocket> socket = new LegacyMozTCPSocket(GetWindow());
|
RefPtr<LegacyMozTCPSocket> socket = new LegacyMozTCPSocket(GetWindow());
|
||||||
return socket.forget();
|
return socket.forget();
|
||||||
@@ -1808,9 +1813,9 @@ network::Connection* Navigator::GetConnection(ErrorResult& aRv) {
|
|||||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
nsCOMPtr<Document> doc = mWindow->GetExtantDoc();
|
|
||||||
mConnection = network::Connection::CreateForWindow(
|
mConnection = network::Connection::CreateForWindow(
|
||||||
mWindow, nsContentUtils::ShouldResistFingerprinting(doc));
|
mWindow,
|
||||||
|
nsGlobalWindowInner::Cast(mWindow)->ShouldResistFingerprinting());
|
||||||
}
|
}
|
||||||
|
|
||||||
return mConnection;
|
return mConnection;
|
||||||
@@ -1918,7 +1923,7 @@ nsresult Navigator::GetPlatform(nsAString& aPlatform, Document* aCallerDoc,
|
|||||||
if (aUsePrefOverriddenValue) {
|
if (aUsePrefOverriddenValue) {
|
||||||
// If fingerprinting resistance is on, we will spoof this value. See
|
// If fingerprinting resistance is on, we will spoof this value. See
|
||||||
// nsRFPService.h for details about spoofed values.
|
// nsRFPService.h for details about spoofed values.
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aCallerDoc)) {
|
if (ShouldResistFingerprinting(aCallerDoc)) {
|
||||||
aPlatform.AssignLiteral(SPOOFED_PLATFORM);
|
aPlatform.AssignLiteral(SPOOFED_PLATFORM);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
@@ -1961,7 +1966,7 @@ nsresult Navigator::GetAppVersion(nsAString& aAppVersion, Document* aCallerDoc,
|
|||||||
if (aUsePrefOverriddenValue) {
|
if (aUsePrefOverriddenValue) {
|
||||||
// If fingerprinting resistance is on, we will spoof this value. See
|
// If fingerprinting resistance is on, we will spoof this value. See
|
||||||
// nsRFPService.h for details about spoofed values.
|
// nsRFPService.h for details about spoofed values.
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aCallerDoc)) {
|
if (ShouldResistFingerprinting(aCallerDoc)) {
|
||||||
aAppVersion.AssignLiteral(SPOOFED_APPVERSION);
|
aAppVersion.AssignLiteral(SPOOFED_APPVERSION);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
@@ -2005,7 +2010,7 @@ void Navigator::AppName(nsAString& aAppName, Document* aCallerDoc,
|
|||||||
if (aUsePrefOverriddenValue) {
|
if (aUsePrefOverriddenValue) {
|
||||||
// If fingerprinting resistance is on, we will spoof this value. See
|
// If fingerprinting resistance is on, we will spoof this value. See
|
||||||
// nsRFPService.h for details about spoofed values.
|
// nsRFPService.h for details about spoofed values.
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aCallerDoc)) {
|
if (ShouldResistFingerprinting(aCallerDoc)) {
|
||||||
aAppName.AssignLiteral(SPOOFED_APPNAME);
|
aAppName.AssignLiteral(SPOOFED_APPNAME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2050,7 +2055,7 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow,
|
|||||||
bool shouldResistFingerprinting =
|
bool shouldResistFingerprinting =
|
||||||
aShouldResistFingerprinting.isSome()
|
aShouldResistFingerprinting.isSome()
|
||||||
? aShouldResistFingerprinting.value()
|
? aShouldResistFingerprinting.value()
|
||||||
: nsContentUtils::ShouldResistFingerprinting(aCallerDoc);
|
: ShouldResistFingerprinting(aCallerDoc);
|
||||||
|
|
||||||
// We will skip the override and pass to httpHandler to get spoofed userAgent
|
// We will skip the override and pass to httpHandler to get spoofed userAgent
|
||||||
// when 'privacy.resistFingerprinting' is true.
|
// when 'privacy.resistFingerprinting' is true.
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
#include "mozilla/MacroForEach.h"
|
#include "mozilla/MacroForEach.h"
|
||||||
#include "mozilla/ManualNAC.h"
|
#include "mozilla/ManualNAC.h"
|
||||||
#include "mozilla/Maybe.h"
|
#include "mozilla/Maybe.h"
|
||||||
|
#include "mozilla/MediaFeatureChange.h"
|
||||||
#include "mozilla/MouseEvents.h"
|
#include "mozilla/MouseEvents.h"
|
||||||
#include "mozilla/NotNull.h"
|
#include "mozilla/NotNull.h"
|
||||||
#include "mozilla/NullPrincipal.h"
|
#include "mozilla/NullPrincipal.h"
|
||||||
@@ -731,6 +732,33 @@ class nsContentUtils::UserInteractionObserver final
|
|||||||
~UserInteractionObserver() = default;
|
~UserInteractionObserver() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr nsLiteralCString kRfpPrefs[] = {
|
||||||
|
"privacy.resistFingerprinting"_ns,
|
||||||
|
"privacy.resistFingerprinting.testGranularityMask"_ns,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void RecomputeResistFingerprintingAllDocs(const char*, void*) {
|
||||||
|
AutoTArray<RefPtr<BrowsingContextGroup>, 5> bcGroups;
|
||||||
|
BrowsingContextGroup::GetAllGroups(bcGroups);
|
||||||
|
for (auto& bcGroup : bcGroups) {
|
||||||
|
AutoTArray<DocGroup*, 5> docGroups;
|
||||||
|
bcGroup->GetDocGroups(docGroups);
|
||||||
|
for (auto* docGroup : docGroups) {
|
||||||
|
for (Document* doc : *docGroup) {
|
||||||
|
const bool old = doc->ShouldResistFingerprinting();
|
||||||
|
doc->RecomputeResistFingerprinting();
|
||||||
|
if (old != doc->ShouldResistFingerprinting()) {
|
||||||
|
if (auto* pc = doc->GetPresContext()) {
|
||||||
|
pc->MediaFeatureValuesChanged(
|
||||||
|
{MediaFeatureChangeReason::PreferenceChange},
|
||||||
|
MediaFeatureChangePropagation::JustThisDocument);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
nsresult nsContentUtils::Init() {
|
nsresult nsContentUtils::Init() {
|
||||||
if (sInitialized) {
|
if (sInitialized) {
|
||||||
@@ -804,6 +832,10 @@ nsresult nsContentUtils::Init() {
|
|||||||
uio->Init();
|
uio->Init();
|
||||||
uio.forget(&sUserInteractionObserver);
|
uio.forget(&sUserInteractionObserver);
|
||||||
|
|
||||||
|
for (const auto& pref : kRfpPrefs) {
|
||||||
|
Preferences::RegisterCallback(RecomputeResistFingerprintingAllDocs, pref);
|
||||||
|
}
|
||||||
|
|
||||||
sInitialized = true;
|
sInitialized = true;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
@@ -1932,6 +1964,10 @@ void nsContentUtils::Shutdown() {
|
|||||||
NS_RELEASE(sUserInteractionObserver);
|
NS_RELEASE(sUserInteractionObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& pref : kRfpPrefs) {
|
||||||
|
Preferences::UnregisterCallback(RecomputeResistFingerprintingAllDocs, pref);
|
||||||
|
}
|
||||||
|
|
||||||
TextControlState::Shutdown();
|
TextControlState::Shutdown();
|
||||||
nsMappedAttributes::Shutdown();
|
nsMappedAttributes::Shutdown();
|
||||||
}
|
}
|
||||||
@@ -2179,27 +2215,18 @@ bool nsContentUtils::ShouldResistFingerprinting(const char* aJustification) {
|
|||||||
bool nsContentUtils::ShouldResistFingerprinting(nsIDocShell* aDocShell) {
|
bool nsContentUtils::ShouldResistFingerprinting(nsIDocShell* aDocShell) {
|
||||||
if (!aDocShell) {
|
if (!aDocShell) {
|
||||||
MOZ_LOG(nsContentUtils::ResistFingerprintingLog(), LogLevel::Info,
|
MOZ_LOG(nsContentUtils::ResistFingerprintingLog(), LogLevel::Info,
|
||||||
("Called nsContentUtils::ShouldResistFingerprinting(const "
|
("Called nsContentUtils::ShouldResistFingerprinting(nsIDocShell*) "
|
||||||
"nsIDocShell* aDocShell) with NULL docshell"));
|
"with NULL docshell"));
|
||||||
return ShouldResistFingerprinting();
|
return ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
return ShouldResistFingerprinting(aDocShell->GetDocument());
|
Document* doc = aDocShell->GetDocument();
|
||||||
}
|
if (!doc) {
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
|
||||||
/* static */
|
|
||||||
bool nsContentUtils::ShouldResistFingerprinting(const Document* aDoc) {
|
|
||||||
if (!aDoc) {
|
|
||||||
MOZ_LOG(nsContentUtils::ResistFingerprintingLog(), LogLevel::Info,
|
MOZ_LOG(nsContentUtils::ResistFingerprintingLog(), LogLevel::Info,
|
||||||
("Called nsContentUtils::ShouldResistFingerprinting(const "
|
("Called nsContentUtils::ShouldResistFingerprinting(nsIDocShell*) "
|
||||||
"Document* aDoc) with NULL document"));
|
"with NULL doc"));
|
||||||
return ShouldResistFingerprinting();
|
return ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
bool isChrome = nsContentUtils::IsChromeDoc(aDoc);
|
return doc->ShouldResistFingerprinting();
|
||||||
if (isChrome) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ShouldResistFingerprinting(aDoc->GetChannel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -350,7 +350,6 @@ class nsContentUtils {
|
|||||||
static bool ShouldResistFingerprinting(nsIGlobalObject* aGlobalObject);
|
static bool ShouldResistFingerprinting(nsIGlobalObject* aGlobalObject);
|
||||||
static bool ShouldResistFingerprinting(nsIDocShell* aDocShell);
|
static bool ShouldResistFingerprinting(nsIDocShell* aDocShell);
|
||||||
// These functions are the new, nuanced functions
|
// These functions are the new, nuanced functions
|
||||||
static bool ShouldResistFingerprinting(const Document* aDoc);
|
|
||||||
static bool ShouldResistFingerprinting(nsIChannel* aChannel);
|
static bool ShouldResistFingerprinting(nsIChannel* aChannel);
|
||||||
static bool ShouldResistFingerprinting(nsILoadInfo* aPrincipal);
|
static bool ShouldResistFingerprinting(nsILoadInfo* aPrincipal);
|
||||||
// These functions are labeled as dangerous because they will do the wrong
|
// These functions are labeled as dangerous because they will do the wrong
|
||||||
|
|||||||
@@ -1625,7 +1625,7 @@ bool nsGlobalWindowInner::IsBlackForCC(bool aTracingNeeded) {
|
|||||||
|
|
||||||
bool nsGlobalWindowInner::ShouldResistFingerprinting() const {
|
bool nsGlobalWindowInner::ShouldResistFingerprinting() const {
|
||||||
if (mDoc) {
|
if (mDoc) {
|
||||||
return nsContentUtils::ShouldResistFingerprinting(mDoc);
|
return mDoc->ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
return nsIScriptGlobalObject::ShouldResistFingerprinting();
|
return nsIScriptGlobalObject::ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
@@ -4982,10 +4982,8 @@ Storage* nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError) {
|
|||||||
if (mDoc) {
|
if (mDoc) {
|
||||||
cookieJarSettings = mDoc->CookieJarSettings();
|
cookieJarSettings = mDoc->CookieJarSettings();
|
||||||
} else {
|
} else {
|
||||||
bool shouldResistFingerprinting =
|
|
||||||
nsContentUtils::ShouldResistFingerprinting(this->GetExtantDoc());
|
|
||||||
cookieJarSettings =
|
cookieJarSettings =
|
||||||
net::CookieJarSettings::GetBlockingAll(shouldResistFingerprinting);
|
net::CookieJarSettings::GetBlockingAll(ShouldResistFingerprinting());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that this behavior is observable: if we grant storage permission to a
|
// Note that this behavior is observable: if we grant storage permission to a
|
||||||
@@ -6584,7 +6582,7 @@ void nsGlobalWindowInner::DisableDeviceSensor(uint32_t aType) {
|
|||||||
|
|
||||||
#if defined(MOZ_WIDGET_ANDROID)
|
#if defined(MOZ_WIDGET_ANDROID)
|
||||||
void nsGlobalWindowInner::EnableOrientationChangeListener() {
|
void nsGlobalWindowInner::EnableOrientationChangeListener() {
|
||||||
if (!nsContentUtils::ShouldResistFingerprinting(GetDocShell())) {
|
if (!ShouldResistFingerprinting()) {
|
||||||
mHasOrientationChangeListeners = true;
|
mHasOrientationChangeListeners = true;
|
||||||
mOrientationAngle = Orientation(CallerType::System);
|
mOrientationAngle = Orientation(CallerType::System);
|
||||||
}
|
}
|
||||||
@@ -6911,7 +6909,7 @@ void nsGlobalWindowInner::GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads) {
|
|||||||
|
|
||||||
// navigator.getGamepads() always returns an empty array when
|
// navigator.getGamepads() always returns an empty array when
|
||||||
// privacy.resistFingerprinting is true.
|
// privacy.resistFingerprinting is true.
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(GetDocShell())) {
|
if (ShouldResistFingerprinting()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7559,7 +7557,7 @@ void nsGlobalWindowInner::SetReplaceableWindowCoord(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(GetDocShell())) {
|
if (ShouldResistFingerprinting()) {
|
||||||
bool innerWidthSpecified = false;
|
bool innerWidthSpecified = false;
|
||||||
bool innerHeightSpecified = false;
|
bool innerHeightSpecified = false;
|
||||||
bool outerWidthSpecified = false;
|
bool outerWidthSpecified = false;
|
||||||
|
|||||||
@@ -1668,7 +1668,7 @@ bool nsGlobalWindowOuter::IsBlackForCC(bool aTracingNeeded) {
|
|||||||
|
|
||||||
bool nsGlobalWindowOuter::ShouldResistFingerprinting() const {
|
bool nsGlobalWindowOuter::ShouldResistFingerprinting() const {
|
||||||
if (mDoc) {
|
if (mDoc) {
|
||||||
return nsContentUtils::ShouldResistFingerprinting(mDoc);
|
return mDoc->ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
return nsIScriptGlobalObject::ShouldResistFingerprinting();
|
return nsIScriptGlobalObject::ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "mozilla/dom/MimeTypeArrayBinding.h"
|
#include "mozilla/dom/MimeTypeArrayBinding.h"
|
||||||
#include "mozilla/dom/MimeTypeBinding.h"
|
#include "mozilla/dom/MimeTypeBinding.h"
|
||||||
|
#include "nsGlobalWindowInner.h"
|
||||||
#include "nsPluginArray.h"
|
#include "nsPluginArray.h"
|
||||||
#include "mozilla/StaticPrefs_pdfjs.h"
|
#include "mozilla/StaticPrefs_pdfjs.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
@@ -81,7 +82,7 @@ void nsMimeTypeArray::GetSupportedNames(nsTArray<nsString>& retval) {
|
|||||||
|
|
||||||
bool nsMimeTypeArray::ForceNoPlugins() {
|
bool nsMimeTypeArray::ForceNoPlugins() {
|
||||||
return StaticPrefs::pdfjs_disabled() &&
|
return StaticPrefs::pdfjs_disabled() &&
|
||||||
!nsContentUtils::ShouldResistFingerprinting(mWindow->GetExtantDoc());
|
!nsGlobalWindowInner::Cast(mWindow)->ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsMimeType, AddRef)
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsMimeType, AddRef)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "nsMimeTypeArray.h"
|
#include "nsMimeTypeArray.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
|
#include "nsGlobalWindowInner.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
@@ -99,7 +100,7 @@ void nsPluginArray::GetSupportedNames(nsTArray<nsString>& aRetval) {
|
|||||||
|
|
||||||
bool nsPluginArray::ForceNoPlugins() {
|
bool nsPluginArray::ForceNoPlugins() {
|
||||||
return StaticPrefs::pdfjs_disabled() &&
|
return StaticPrefs::pdfjs_disabled() &&
|
||||||
!nsContentUtils::ShouldResistFingerprinting(mWindow->GetExtantDoc());
|
!nsGlobalWindowInner::Cast(mWindow)->ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPluginArray)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPluginArray)
|
||||||
|
|||||||
@@ -53,12 +53,20 @@ namespace mozilla::CanvasUtils {
|
|||||||
bool IsImageExtractionAllowed(dom::Document* aDocument, JSContext* aCx,
|
bool IsImageExtractionAllowed(dom::Document* aDocument, JSContext* aCx,
|
||||||
Maybe<nsIPrincipal*> aPrincipal) {
|
Maybe<nsIPrincipal*> aPrincipal) {
|
||||||
// Do the rest of the checks only if privacy.resistFingerprinting is on.
|
// Do the rest of the checks only if privacy.resistFingerprinting is on.
|
||||||
if (!nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (!nsContentUtils::ShouldResistFingerprinting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aDocument) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aDocument->ShouldResistFingerprinting()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't proceed if we don't have a document or JavaScript context.
|
// Don't proceed if we don't have a document or JavaScript context.
|
||||||
if (!aDocument || !aCx || !aPrincipal) {
|
if (!aCx || !aPrincipal) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5653,8 +5653,8 @@ void ClientWebGLContext::GetSupportedProfilesASTC(
|
|||||||
|
|
||||||
bool ClientWebGLContext::ShouldResistFingerprinting() const {
|
bool ClientWebGLContext::ShouldResistFingerprinting() const {
|
||||||
if (mCanvasElement) {
|
if (mCanvasElement) {
|
||||||
// If we're constructed from a canvas element
|
// If we're constructed from a canvas element.
|
||||||
return nsContentUtils::ShouldResistFingerprinting(GetOwnerDoc());
|
return mCanvasElement->OwnerDoc()->ShouldResistFingerprinting();
|
||||||
}
|
}
|
||||||
if (mOffscreenCanvas) {
|
if (mOffscreenCanvas) {
|
||||||
// If we're constructed from an offscreen canvas
|
// If we're constructed from an offscreen canvas
|
||||||
|
|||||||
@@ -360,23 +360,22 @@ void KeyboardEvent::InitKeyboardEventJS(
|
|||||||
|
|
||||||
bool KeyboardEvent::ShouldResistFingerprinting(CallerType aCallerType) {
|
bool KeyboardEvent::ShouldResistFingerprinting(CallerType aCallerType) {
|
||||||
// There are five situations we don't need to spoof this keyboard event.
|
// There are five situations we don't need to spoof this keyboard event.
|
||||||
// 1. This event is initialized by scripts.
|
// 1. The pref privcy.resistFingerprinting' is false, we fast return here
|
||||||
// 2. This event is from Numpad.
|
|
||||||
// 3. This event is in the system group.
|
|
||||||
// 4. The caller type is system.
|
|
||||||
// 5. The pref privcy.resistFingerprinting' is false, we fast return here
|
|
||||||
// since we don't need to do any QI of following codes.
|
// since we don't need to do any QI of following codes.
|
||||||
if (mInitializedByJS || aCallerType == CallerType::System ||
|
// 2. This event is initialized by scripts.
|
||||||
mEvent->mFlags.mInSystemGroup ||
|
// 3. This event is from Numpad.
|
||||||
!nsContentUtils::ShouldResistFingerprinting() ||
|
// 4. This event is in the system group.
|
||||||
|
// 5. The caller type is system.
|
||||||
|
if (!nsContentUtils::ShouldResistFingerprinting() || mInitializedByJS ||
|
||||||
|
aCallerType == CallerType::System || mEvent->mFlags.mInSystemGroup ||
|
||||||
mEvent->AsKeyboardEvent()->mLocation ==
|
mEvent->AsKeyboardEvent()->mLocation ==
|
||||||
KeyboardEvent_Binding::DOM_KEY_LOCATION_NUMPAD) {
|
KeyboardEvent_Binding::DOM_KEY_LOCATION_NUMPAD) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<Document> doc = GetDocument();
|
nsCOMPtr<Document> doc = GetDocument();
|
||||||
|
// We've checked the pref above, so use true as fallback if doc is null.
|
||||||
return nsContentUtils::ShouldResistFingerprinting(doc);
|
return doc ? doc->ShouldResistFingerprinting() : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyboardEvent::GetSpoofedModifierStates(const Modifiers aModifierKey,
|
bool KeyboardEvent::GetSpoofedModifierStates(const Modifiers aModifierKey,
|
||||||
|
|||||||
@@ -278,23 +278,23 @@ void PointerEvent::GetPredictedEvents(
|
|||||||
|
|
||||||
bool PointerEvent::ShouldResistFingerprinting(CallerType aCallerType) {
|
bool PointerEvent::ShouldResistFingerprinting(CallerType aCallerType) {
|
||||||
// There are four situations we don't need to spoof this pointer event.
|
// There are four situations we don't need to spoof this pointer event.
|
||||||
// 1. This event is generated by scripts.
|
// 1. The pref privcy.resistFingerprinting' is false, we fast return here
|
||||||
// 2. This event is a mouse pointer event.
|
|
||||||
// 3. The caller type is system.
|
|
||||||
// 4. The pref privcy.resistFingerprinting' is false, we fast return here
|
|
||||||
// since we don't need to do any QI of following codes.
|
// since we don't need to do any QI of following codes.
|
||||||
|
// 2. This event is generated by scripts.
|
||||||
|
// 3. This event is a mouse pointer event.
|
||||||
|
// 4. The caller type is system.
|
||||||
// We don't need to check for the system group since pointer events won't be
|
// We don't need to check for the system group since pointer events won't be
|
||||||
// dispatched to the system group.
|
// dispatched to the system group.
|
||||||
if (!mEvent->IsTrusted() || aCallerType == CallerType::System ||
|
if (!nsContentUtils::ShouldResistFingerprinting() || !mEvent->IsTrusted() ||
|
||||||
!nsContentUtils::ShouldResistFingerprinting() ||
|
aCallerType == CallerType::System ||
|
||||||
mEvent->AsPointerEvent()->mInputSource ==
|
mEvent->AsPointerEvent()->mInputSource ==
|
||||||
MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
|
MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pref is checked above, so use true as fallback.
|
||||||
nsCOMPtr<Document> doc = GetDocument();
|
nsCOMPtr<Document> doc = GetDocument();
|
||||||
|
return doc ? doc->ShouldResistFingerprinting() : true;
|
||||||
return nsContentUtils::ShouldResistFingerprinting(doc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mozilla::dom
|
} // namespace mozilla::dom
|
||||||
|
|||||||
@@ -144,8 +144,7 @@ void GamepadManager::AddListener(nsGlobalWindowInner* aWindow) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mEnabled || mShuttingDown ||
|
if (!mEnabled || mShuttingDown || aWindow->ShouldResistFingerprinting()) {
|
||||||
nsContentUtils::ShouldResistFingerprinting(aWindow->GetExtantDoc())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,8 +279,7 @@ void GamepadManager::NewConnectionEvent(GamepadHandle aHandle,
|
|||||||
|
|
||||||
// Do not fire gamepadconnected and gamepaddisconnected events when
|
// Do not fire gamepadconnected and gamepaddisconnected events when
|
||||||
// privacy.resistFingerprinting is true.
|
// privacy.resistFingerprinting is true.
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(
|
if (listeners[i]->ShouldResistFingerprinting()) {
|
||||||
listeners[i]->GetExtantDoc())) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,8 +312,7 @@ void GamepadManager::NewConnectionEvent(GamepadHandle aHandle,
|
|||||||
|
|
||||||
// Do not fire gamepadconnected and gamepaddisconnected events when
|
// Do not fire gamepadconnected and gamepaddisconnected events when
|
||||||
// privacy.resistFingerprinting is true.
|
// privacy.resistFingerprinting is true.
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(
|
if (listeners[i]->ShouldResistFingerprinting()) {
|
||||||
listeners[i]->GetExtantDoc())) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,8 +347,7 @@ void GamepadManager::FireConnectionEvent(EventTarget* aTarget,
|
|||||||
void GamepadManager::SyncGamepadState(GamepadHandle aHandle,
|
void GamepadManager::SyncGamepadState(GamepadHandle aHandle,
|
||||||
nsGlobalWindowInner* aWindow,
|
nsGlobalWindowInner* aWindow,
|
||||||
Gamepad* aGamepad) {
|
Gamepad* aGamepad) {
|
||||||
if (mShuttingDown || !mEnabled ||
|
if (mShuttingDown || !mEnabled || aWindow->ShouldResistFingerprinting()) {
|
||||||
nsContentUtils::ShouldResistFingerprinting(aWindow->GetExtantDoc())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ uint32_t HTMLVideoElement::MozParsedFrames() const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(OwnerDoc())) {
|
if (OwnerDoc()->ShouldResistFingerprinting()) {
|
||||||
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +272,7 @@ uint32_t HTMLVideoElement::MozDecodedFrames() const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(OwnerDoc())) {
|
if (OwnerDoc()->ShouldResistFingerprinting()) {
|
||||||
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ uint32_t HTMLVideoElement::MozPresentedFrames() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(OwnerDoc())) {
|
if (OwnerDoc()->ShouldResistFingerprinting()) {
|
||||||
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
|
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
|
||||||
VideoWidth(), VideoHeight());
|
VideoWidth(), VideoHeight());
|
||||||
}
|
}
|
||||||
@@ -299,7 +299,7 @@ uint32_t HTMLVideoElement::MozPaintedFrames() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(OwnerDoc())) {
|
if (OwnerDoc()->ShouldResistFingerprinting()) {
|
||||||
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
|
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
|
||||||
VideoWidth(), VideoHeight());
|
VideoWidth(), VideoHeight());
|
||||||
}
|
}
|
||||||
@@ -311,8 +311,7 @@ uint32_t HTMLVideoElement::MozPaintedFrames() {
|
|||||||
double HTMLVideoElement::MozFrameDelay() {
|
double HTMLVideoElement::MozFrameDelay() {
|
||||||
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
|
||||||
|
|
||||||
if (!IsVideoStatsEnabled() ||
|
if (!IsVideoStatsEnabled() || OwnerDoc()->ShouldResistFingerprinting()) {
|
||||||
nsContentUtils::ShouldResistFingerprinting(OwnerDoc())) {
|
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +348,7 @@ HTMLVideoElement::GetVideoPlaybackQuality() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mDecoder) {
|
if (mDecoder) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(OwnerDoc())) {
|
if (OwnerDoc()->ShouldResistFingerprinting()) {
|
||||||
totalFrames = nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
totalFrames = nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
|
||||||
droppedFrames = nsRFPService::GetSpoofedDroppedFrames(
|
droppedFrames = nsRFPService::GetSpoofedDroppedFrames(
|
||||||
TotalPlayTime(), VideoWidth(), VideoHeight());
|
TotalPlayTime(), VideoWidth(), VideoHeight());
|
||||||
|
|||||||
@@ -34,12 +34,13 @@ MediaError::MediaError(HTMLMediaElement* aParent, uint16_t aCode,
|
|||||||
void MediaError::GetMessage(nsAString& aResult) const {
|
void MediaError::GetMessage(nsAString& aResult) const {
|
||||||
// When fingerprinting resistance is enabled, only messages in this list
|
// When fingerprinting resistance is enabled, only messages in this list
|
||||||
// can be returned to content script.
|
// can be returned to content script.
|
||||||
|
// FIXME: An unordered_set seems overkill for this.
|
||||||
static const std::unordered_set<std::string> whitelist = {
|
static const std::unordered_set<std::string> whitelist = {
|
||||||
"404: Not Found"
|
"404: Not Found"
|
||||||
// TODO
|
// TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
bool shouldBlank = (whitelist.find(mMessage.get()) == whitelist.end());
|
const bool shouldBlank = whitelist.find(mMessage.get()) == whitelist.end();
|
||||||
|
|
||||||
if (shouldBlank) {
|
if (shouldBlank) {
|
||||||
// Print a warning message to JavaScript console to alert developers of
|
// Print a warning message to JavaScript console to alert developers of
|
||||||
@@ -65,14 +66,13 @@ void MediaError::GetMessage(nsAString& aResult) const {
|
|||||||
NS_ConvertASCIItoUTF16(message), nsIScriptError::warningFlag,
|
NS_ConvertASCIItoUTF16(message), nsIScriptError::warningFlag,
|
||||||
"MediaError"_ns, ownerDoc);
|
"MediaError"_ns, ownerDoc);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!nsContentUtils::IsCallerChrome() &&
|
if (!nsContentUtils::IsCallerChrome() &&
|
||||||
nsContentUtils::ShouldResistFingerprinting(mParent->OwnerDoc()) &&
|
ownerDoc->ShouldResistFingerprinting()) {
|
||||||
shouldBlank) {
|
|
||||||
aResult.Truncate();
|
aResult.Truncate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CopyUTF8toUTF16(mMessage, aResult);
|
CopyUTF8toUTF16(mMessage, aResult);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "nsINamed.h"
|
#include "nsINamed.h"
|
||||||
#include "nsIScriptGlobalObject.h"
|
#include "nsIScriptGlobalObject.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
|
#include "nsGlobalWindowInner.h"
|
||||||
#include "nsQueryObject.h"
|
#include "nsQueryObject.h"
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
@@ -226,8 +227,7 @@ RefPtr<MediaDeviceSetRefCnt> MediaDevices::FilterExposedDevices(
|
|||||||
!Preferences::GetBool("media.setsinkid.enabled") ||
|
!Preferences::GetBool("media.setsinkid.enabled") ||
|
||||||
!FeaturePolicyUtils::IsFeatureAllowed(doc, u"speaker-selection"_ns);
|
!FeaturePolicyUtils::IsFeatureAllowed(doc, u"speaker-selection"_ns);
|
||||||
|
|
||||||
bool resistFingerprinting = nsContentUtils::ShouldResistFingerprinting(doc);
|
if (doc->ShouldResistFingerprinting()) {
|
||||||
if (resistFingerprinting) {
|
|
||||||
RefPtr fakeEngine = new MediaEngineFake();
|
RefPtr fakeEngine = new MediaEngineFake();
|
||||||
fakeEngine->EnumerateDevices(MediaSourceEnum::Microphone,
|
fakeEngine->EnumerateDevices(MediaSourceEnum::Microphone,
|
||||||
MediaSinkEnum::Other, exposed);
|
MediaSinkEnum::Other, exposed);
|
||||||
@@ -731,8 +731,7 @@ void MediaDevices::OnDeviceChange() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Document* doc = window->GetExtantDoc();
|
if (nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting()) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(doc)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsDeviceSensors.h"
|
#include "nsDeviceSensors.h"
|
||||||
|
|
||||||
|
#include "nsGlobalWindowInner.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
#include "nsIScriptObjectPrincipal.h"
|
#include "nsIScriptObjectPrincipal.h"
|
||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
@@ -509,7 +510,8 @@ bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
|
|||||||
// checks "device.sensors.motion.enabled" pref
|
// checks "device.sensors.motion.enabled" pref
|
||||||
if (!StaticPrefs::device_sensors_motion_enabled()) {
|
if (!StaticPrefs::device_sensors_motion_enabled()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (doc) {
|
}
|
||||||
|
if (doc) {
|
||||||
doc->WarnOnceAbout(DeprecatedOperations::eMotionEvent);
|
doc->WarnOnceAbout(DeprecatedOperations::eMotionEvent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -519,7 +521,8 @@ bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
|
|||||||
// checks "device.sensors.orientation.enabled" pref
|
// checks "device.sensors.orientation.enabled" pref
|
||||||
if (!StaticPrefs::device_sensors_orientation_enabled()) {
|
if (!StaticPrefs::device_sensors_orientation_enabled()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (doc) {
|
}
|
||||||
|
if (doc) {
|
||||||
doc->WarnOnceAbout(DeprecatedOperations::eOrientationEvent);
|
doc->WarnOnceAbout(DeprecatedOperations::eOrientationEvent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -527,7 +530,8 @@ bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
|
|||||||
// checks "device.sensors.proximity.enabled" pref
|
// checks "device.sensors.proximity.enabled" pref
|
||||||
if (!StaticPrefs::device_sensors_proximity_enabled()) {
|
if (!StaticPrefs::device_sensors_proximity_enabled()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (doc) {
|
}
|
||||||
|
if (doc) {
|
||||||
doc->WarnOnceAbout(DeprecatedOperations::eProximityEvent, true);
|
doc->WarnOnceAbout(DeprecatedOperations::eProximityEvent, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -535,7 +539,8 @@ bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
|
|||||||
// checks "device.sensors.ambientLight.enabled" pref
|
// checks "device.sensors.ambientLight.enabled" pref
|
||||||
if (!StaticPrefs::device_sensors_ambientLight_enabled()) {
|
if (!StaticPrefs::device_sensors_ambientLight_enabled()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (doc) {
|
}
|
||||||
|
if (doc) {
|
||||||
doc->WarnOnceAbout(DeprecatedOperations::eAmbientLightEvent, true);
|
doc->WarnOnceAbout(DeprecatedOperations::eAmbientLightEvent, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -547,6 +552,5 @@ bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
|
|||||||
if (!window) {
|
if (!window) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return !nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting();
|
||||||
return !nsContentUtils::ShouldResistFingerprinting(doc);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2887,7 +2887,7 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
|
|||||||
loadInfo.mHasStorageAccessPermissionGranted =
|
loadInfo.mHasStorageAccessPermissionGranted =
|
||||||
document->HasStorageAccessPermissionGranted();
|
document->HasStorageAccessPermissionGranted();
|
||||||
loadInfo.mShouldResistFingerprinting =
|
loadInfo.mShouldResistFingerprinting =
|
||||||
nsContentUtils::ShouldResistFingerprinting(document);
|
document->ShouldResistFingerprinting();
|
||||||
|
|
||||||
// This is an hack to deny the storage-access-permission for workers of
|
// This is an hack to deny the storage-access-permission for workers of
|
||||||
// sub-iframes.
|
// sub-iframes.
|
||||||
|
|||||||
@@ -331,7 +331,6 @@ static const char* gExactCallbackPrefs[] = {
|
|||||||
"intl.accept_languages",
|
"intl.accept_languages",
|
||||||
"layout.css.devPixelsPerPx",
|
"layout.css.devPixelsPerPx",
|
||||||
"layout.css.dpi",
|
"layout.css.dpi",
|
||||||
"privacy.resistFingerprinting",
|
|
||||||
"privacy.trackingprotection.enabled",
|
"privacy.trackingprotection.enabled",
|
||||||
"ui.use_standins_for_native_colors",
|
"ui.use_standins_for_native_colors",
|
||||||
nullptr,
|
nullptr,
|
||||||
@@ -577,7 +576,6 @@ void nsPresContext::PreferenceChanged(const char* aPrefName) {
|
|||||||
// because that pref doesn't just affect the "live" value of the media query;
|
// because that pref doesn't just affect the "live" value of the media query;
|
||||||
// it affects whether it is parsed at all.
|
// it affects whether it is parsed at all.
|
||||||
if (prefName.EqualsLiteral("browser.display.document_color_use") ||
|
if (prefName.EqualsLiteral("browser.display.document_color_use") ||
|
||||||
prefName.EqualsLiteral("privacy.resistFingerprinting") ||
|
|
||||||
prefName.EqualsLiteral("browser.display.foreground_color") ||
|
prefName.EqualsLiteral("browser.display.foreground_color") ||
|
||||||
prefName.EqualsLiteral("browser.display.background_color")) {
|
prefName.EqualsLiteral("browser.display.background_color")) {
|
||||||
MediaFeatureValuesChanged({MediaFeatureChangeReason::PreferenceChange},
|
MediaFeatureValuesChanged({MediaFeatureChangeReason::PreferenceChange},
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ using mozilla::dom::DisplayMode;
|
|||||||
using mozilla::dom::Document;
|
using mozilla::dom::Document;
|
||||||
|
|
||||||
// A helper for four features below
|
// A helper for four features below
|
||||||
static nsSize GetSize(const Document* aDocument) {
|
static nsSize GetSize(const Document& aDocument) {
|
||||||
nsPresContext* pc = aDocument->GetPresContext();
|
nsPresContext* pc = aDocument.GetPresContext();
|
||||||
|
|
||||||
// Per spec, return a 0x0 viewport if we're not being rendered. See:
|
// Per spec, return a 0x0 viewport if we're not being rendered. See:
|
||||||
//
|
//
|
||||||
@@ -60,20 +60,20 @@ static nsSize GetSize(const Document* aDocument) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A helper for three features below.
|
// A helper for three features below.
|
||||||
static nsSize GetDeviceSize(const Document* aDocument) {
|
static nsSize GetDeviceSize(const Document& aDocument) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (aDocument.ShouldResistFingerprinting()) {
|
||||||
return GetSize(aDocument);
|
return GetSize(aDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Media queries in documents in an RDM pane should use the simulated
|
// Media queries in documents in an RDM pane should use the simulated
|
||||||
// device size.
|
// device size.
|
||||||
Maybe<CSSIntSize> deviceSize =
|
Maybe<CSSIntSize> deviceSize =
|
||||||
nsGlobalWindowOuter::GetRDMDeviceSize(*aDocument);
|
nsGlobalWindowOuter::GetRDMDeviceSize(aDocument);
|
||||||
if (deviceSize.isSome()) {
|
if (deviceSize.isSome()) {
|
||||||
return CSSPixel::ToAppUnits(deviceSize.value());
|
return CSSPixel::ToAppUnits(deviceSize.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
nsPresContext* pc = aDocument->GetPresContext();
|
nsPresContext* pc = aDocument.GetPresContext();
|
||||||
// NOTE(emilio): We should probably figure out how to return an appropriate
|
// NOTE(emilio): We should probably figure out how to return an appropriate
|
||||||
// device size here, though in a multi-screen world that makes no sense
|
// device size here, though in a multi-screen world that makes no sense
|
||||||
// really.
|
// really.
|
||||||
@@ -124,7 +124,7 @@ static nsDeviceContext* GetDeviceContextFor(const Document* aDocument) {
|
|||||||
|
|
||||||
void Gecko_MediaFeatures_GetDeviceSize(const Document* aDocument,
|
void Gecko_MediaFeatures_GetDeviceSize(const Document* aDocument,
|
||||||
nscoord* aWidth, nscoord* aHeight) {
|
nscoord* aWidth, nscoord* aHeight) {
|
||||||
nsSize size = GetDeviceSize(aDocument);
|
nsSize size = GetDeviceSize(*aDocument);
|
||||||
*aWidth = size.width;
|
*aWidth = size.width;
|
||||||
*aHeight = size.height;
|
*aHeight = size.height;
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ uint32_t Gecko_MediaFeatures_GetColorDepth(const Document* aDocument) {
|
|||||||
// rendered.
|
// rendered.
|
||||||
uint32_t depth = 24;
|
uint32_t depth = 24;
|
||||||
|
|
||||||
if (!nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (!aDocument->ShouldResistFingerprinting()) {
|
||||||
if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
|
if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
|
||||||
depth = dx->GetDepth();
|
depth = dx->GetDepth();
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ float Gecko_MediaFeatures_GetResolution(const Document* aDocument) {
|
|||||||
return pc->GetOverrideDPPX();
|
return pc->GetOverrideDPPX();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (aDocument->ShouldResistFingerprinting()) {
|
||||||
return pc->DeviceContext()->GetFullZoom();
|
return pc->DeviceContext()->GetFullZoom();
|
||||||
}
|
}
|
||||||
// Get the actual device pixel ratio, which also takes zoom into account.
|
// Get the actual device pixel ratio, which also takes zoom into account.
|
||||||
@@ -264,7 +264,7 @@ bool Gecko_MediaFeatures_MatchesPlatform(StylePlatform aPlatform) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Gecko_MediaFeatures_PrefersReducedMotion(const Document* aDocument) {
|
bool Gecko_MediaFeatures_PrefersReducedMotion(const Document* aDocument) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (aDocument->ShouldResistFingerprinting()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return LookAndFeel::GetInt(LookAndFeel::IntID::PrefersReducedMotion, 0) == 1;
|
return LookAndFeel::GetInt(LookAndFeel::IntID::PrefersReducedMotion, 0) == 1;
|
||||||
@@ -283,7 +283,7 @@ StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme(
|
|||||||
// as a signal.
|
// as a signal.
|
||||||
StylePrefersContrast Gecko_MediaFeatures_PrefersContrast(
|
StylePrefersContrast Gecko_MediaFeatures_PrefersContrast(
|
||||||
const Document* aDocument) {
|
const Document* aDocument) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (aDocument->ShouldResistFingerprinting()) {
|
||||||
return StylePrefersContrast::NoPreference;
|
return StylePrefersContrast::NoPreference;
|
||||||
}
|
}
|
||||||
const auto& prefs = PreferenceSheet::PrefsFor(*aDocument);
|
const auto& prefs = PreferenceSheet::PrefsFor(*aDocument);
|
||||||
@@ -313,7 +313,7 @@ StyleDynamicRange Gecko_MediaFeatures_DynamicRange(const Document* aDocument) {
|
|||||||
|
|
||||||
StyleDynamicRange Gecko_MediaFeatures_VideoDynamicRange(
|
StyleDynamicRange Gecko_MediaFeatures_VideoDynamicRange(
|
||||||
const Document* aDocument) {
|
const Document* aDocument) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
if (aDocument->ShouldResistFingerprinting()) {
|
||||||
return StyleDynamicRange::Standard;
|
return StyleDynamicRange::Standard;
|
||||||
}
|
}
|
||||||
// video-dynamic-range: high has 3 requirements:
|
// video-dynamic-range: high has 3 requirements:
|
||||||
@@ -354,8 +354,7 @@ static PointerCapabilities GetPointerCapabilities(const Document* aDocument,
|
|||||||
#else
|
#else
|
||||||
PointerCapabilities::Fine | PointerCapabilities::Hover;
|
PointerCapabilities::Fine | PointerCapabilities::Hover;
|
||||||
#endif
|
#endif
|
||||||
|
if (aDocument->ShouldResistFingerprinting()) {
|
||||||
if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
|
|
||||||
return kDefaultCapabilities;
|
return kDefaultCapabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user