Bug 1834737 - Make RFPTarget parameter of Document::ShouldResistFingerprinting non-optional. r=tjr

Differential Revision: https://phabricator.services.mozilla.com/D178925
This commit is contained in:
Tom Schuster
2023-05-31 09:46:54 +00:00
parent 591c5f154e
commit f33200529a
17 changed files with 52 additions and 43 deletions

View File

@@ -16203,8 +16203,7 @@ bool Document::RecomputeResistFingerprinting() {
return previous != mShouldResistFingerprinting;
}
bool Document::ShouldResistFingerprinting(
RFPTarget aTarget /* = RFPTarget::Unknown */) const {
bool Document::ShouldResistFingerprinting(RFPTarget aTarget) const {
return mShouldResistFingerprinting && nsRFPService::IsRFPEnabledFor(aTarget);
}

View File

@@ -4177,7 +4177,7 @@ class Document : public nsINode,
*/
class HighlightRegistry& HighlightRegistry();
bool ShouldResistFingerprinting(RFPTarget aTarget = RFPTarget::Unknown) const;
bool ShouldResistFingerprinting(RFPTarget aTarget) const;
// Recompute the current resist fingerprinting state. Returns true when
// the state was changed.

View File

@@ -280,7 +280,7 @@ nsDOMAttributeMap* Element::Attributes() {
}
void Element::SetPointerCapture(int32_t aPointerId, ErrorResult& aError) {
if (OwnerDoc()->ShouldResistFingerprinting() &&
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown) &&
aPointerId != PointerEventHandler::GetSpoofedPointerIdForRFP()) {
aError.ThrowNotFoundError("Invalid pointer id");
return;
@@ -309,7 +309,7 @@ void Element::SetPointerCapture(int32_t aPointerId, ErrorResult& aError) {
}
void Element::ReleasePointerCapture(int32_t aPointerId, ErrorResult& aError) {
if (OwnerDoc()->ShouldResistFingerprinting() &&
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown) &&
aPointerId != PointerEventHandler::GetSpoofedPointerIdForRFP()) {
aError.ThrowNotFoundError("Invalid pointer id");
return;

View File

@@ -654,7 +654,8 @@ uint64_t Navigator::HardwareConcurrency() {
}
return rts->ClampedHardwareConcurrency(
nsGlobalWindowInner::Cast(mWindow)->ShouldResistFingerprinting());
nsGlobalWindowInner::Cast(mWindow)->ShouldResistFingerprinting(
RFPTarget::Unknown));
}
namespace {
@@ -1572,9 +1573,10 @@ void Navigator::ValidateShareData(const ShareData& aData, ErrorResult& aRv) {
}
}
static bool ShouldResistFingerprinting(const Document* aDoc) {
return aDoc ? aDoc->ShouldResistFingerprinting()
: nsContentUtils::ShouldResistFingerprinting("Fallback");
static bool ShouldResistFingerprinting(const Document* aDoc,
RFPTarget aTarget) {
return aDoc ? aDoc->ShouldResistFingerprinting(aTarget)
: nsContentUtils::ShouldResistFingerprinting("Fallback", aTarget);
}
already_AddRefed<LegacyMozTCPSocket> Navigator::MozTCPSocket() {
@@ -1948,7 +1950,7 @@ nsresult Navigator::GetPlatform(nsAString& aPlatform, Document* aCallerDoc,
if (aUsePrefOverriddenValue) {
// If fingerprinting resistance is on, we will spoof this value. See
// nsRFPService.h for details about spoofed values.
if (ShouldResistFingerprinting(aCallerDoc)) {
if (ShouldResistFingerprinting(aCallerDoc, RFPTarget::Unknown)) {
aPlatform.AssignLiteral(SPOOFED_PLATFORM);
return NS_OK;
}
@@ -1991,7 +1993,7 @@ nsresult Navigator::GetAppVersion(nsAString& aAppVersion, Document* aCallerDoc,
if (aUsePrefOverriddenValue) {
// If fingerprinting resistance is on, we will spoof this value. See
// nsRFPService.h for details about spoofed values.
if (ShouldResistFingerprinting(aCallerDoc)) {
if (ShouldResistFingerprinting(aCallerDoc, RFPTarget::Unknown)) {
aAppVersion.AssignLiteral(SPOOFED_APPVERSION);
return NS_OK;
}
@@ -2035,7 +2037,7 @@ void Navigator::AppName(nsAString& aAppName, Document* aCallerDoc,
if (aUsePrefOverriddenValue) {
// If fingerprinting resistance is on, we will spoof this value. See
// nsRFPService.h for details about spoofed values.
if (ShouldResistFingerprinting(aCallerDoc)) {
if (ShouldResistFingerprinting(aCallerDoc, RFPTarget::Unknown)) {
aAppName.AssignLiteral(SPOOFED_APPNAME);
return;
}
@@ -2080,7 +2082,7 @@ nsresult Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow,
bool shouldResistFingerprinting =
aShouldResistFingerprinting.isSome()
? aShouldResistFingerprinting.value()
: ShouldResistFingerprinting(aCallerDoc);
: ShouldResistFingerprinting(aCallerDoc, RFPTarget::Unknown);
// We will skip the override and pass to httpHandler to get spoofed userAgent
// when 'privacy.resistFingerprinting' is true.

View File

@@ -2684,8 +2684,9 @@ NS_IMETHODIMP
nsDOMWindowUtils::GetCurrentPreferredSampleRate(uint32_t* aRate) {
nsCOMPtr<Document> doc = GetDocument();
*aRate = CubebUtils::PreferredSampleRate(
doc ? doc->ShouldResistFingerprinting()
: nsContentUtils::ShouldResistFingerprinting("Fallback"));
doc ? doc->ShouldResistFingerprinting(RFPTarget::Unknown)
: nsContentUtils::ShouldResistFingerprinting("Fallback",
RFPTarget::Unknown));
return NS_OK;
}

View File

@@ -336,7 +336,8 @@ void PointerEventHandler::CheckPointerCaptureState(WidgetPointerEvent* aEvent) {
// content to set pointer capture other than the spoofed one. Thus, it must be
// from chrome if the capture info exists in this case. And we don't have to
// do anything if the pointer id is the same as the spoofed one.
if (nsContentUtils::ShouldResistFingerprinting("Efficiency Check") &&
if (nsContentUtils::ShouldResistFingerprinting("Efficiency Check",
RFPTarget::PointerEvents) &&
aEvent->pointerId != (uint32_t)GetSpoofedPointerIdForRFP() &&
!captureInfo) {
PointerCaptureInfo* spoofedCaptureInfo =
@@ -348,7 +349,7 @@ void PointerEventHandler::CheckPointerCaptureState(WidgetPointerEvent* aEvent) {
// in this case.
if (!spoofedCaptureInfo || !spoofedCaptureInfo->mPendingElement ||
!spoofedCaptureInfo->mPendingElement->OwnerDoc()
->ShouldResistFingerprinting()) {
->ShouldResistFingerprinting(RFPTarget::PointerEvents)) {
return;
}

View File

@@ -6318,8 +6318,8 @@ bool HTMLMediaElement::HadCrossOriginRedirects() {
return false;
}
bool HTMLMediaElement::ShouldResistFingerprinting() const {
return OwnerDoc()->ShouldResistFingerprinting();
bool HTMLMediaElement::ShouldResistFingerprinting(RFPTarget aTarget) const {
return OwnerDoc()->ShouldResistFingerprinting(aTarget);
}
already_AddRefed<nsIPrincipal> HTMLMediaElement::GetCurrentVideoPrincipal() {

View File

@@ -353,7 +353,7 @@ class HTMLMediaElement : public nsGenericHTMLElement,
// redirects.
bool HadCrossOriginRedirects();
bool ShouldResistFingerprinting() const override;
bool ShouldResistFingerprinting(RFPTarget aTarget) const override;
// Principal of the currently playing video resource. Anything accessing the
// image container of this element must have a principal that subsumes this

View File

@@ -258,7 +258,7 @@ uint32_t HTMLVideoElement::MozParsedFrames() const {
return 0;
}
if (OwnerDoc()->ShouldResistFingerprinting()) {
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
}
@@ -271,7 +271,7 @@ uint32_t HTMLVideoElement::MozDecodedFrames() const {
return 0;
}
if (OwnerDoc()->ShouldResistFingerprinting()) {
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
}
@@ -284,7 +284,7 @@ uint32_t HTMLVideoElement::MozPresentedFrames() {
return 0;
}
if (OwnerDoc()->ShouldResistFingerprinting()) {
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
VideoWidth(), VideoHeight());
}
@@ -298,7 +298,7 @@ uint32_t HTMLVideoElement::MozPaintedFrames() {
return 0;
}
if (OwnerDoc()->ShouldResistFingerprinting()) {
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return nsRFPService::GetSpoofedPresentedFrames(TotalPlayTime(),
VideoWidth(), VideoHeight());
}
@@ -310,7 +310,8 @@ uint32_t HTMLVideoElement::MozPaintedFrames() {
double HTMLVideoElement::MozFrameDelay() {
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
if (!IsVideoStatsEnabled() || OwnerDoc()->ShouldResistFingerprinting()) {
if (!IsVideoStatsEnabled() ||
OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return 0.0;
}
@@ -347,7 +348,7 @@ HTMLVideoElement::GetVideoPlaybackQuality() {
}
if (mDecoder) {
if (OwnerDoc()->ShouldResistFingerprinting()) {
if (OwnerDoc()->ShouldResistFingerprinting(RFPTarget::Unknown)) {
totalFrames = nsRFPService::GetSpoofedTotalFrames(TotalPlayTime());
droppedFrames = nsRFPService::GetSpoofedDroppedFrames(
TotalPlayTime(), VideoWidth(), VideoHeight());

View File

@@ -68,7 +68,7 @@ void MediaError::GetMessage(nsAString& aResult) const {
}
if (!nsContentUtils::IsCallerChrome() &&
ownerDoc->ShouldResistFingerprinting()) {
ownerDoc->ShouldResistFingerprinting(RFPTarget::Unknown)) {
aResult.Truncate();
return;
}

View File

@@ -108,7 +108,7 @@ WindowGlobalInit WindowGlobalActor::WindowInitializer(
fields.Get<Indexes::IDX_IsThirdPartyTrackingResourceWindow>() =
nsContentUtils::IsThirdPartyTrackingResourceWindow(aWindow);
fields.Get<Indexes::IDX_ShouldResistFingerprinting>() =
doc->ShouldResistFingerprinting();
doc->ShouldResistFingerprinting(RFPTarget::IsAlwaysEnabledForPrecompute);
fields.Get<Indexes::IDX_IsSecureContext>() = aWindow->IsSecureContext();
// Initialze permission fields

View File

@@ -270,7 +270,8 @@ MediaDecoder::MediaDecoder(MediaDecoderInit& aInit)
mIsOwnerConnected(false),
mForcedHidden(false),
mHasSuspendTaint(aInit.mHasSuspendTaint),
mShouldResistFingerprinting(aInit.mOwner->ShouldResistFingerprinting()),
mShouldResistFingerprinting(
aInit.mOwner->ShouldResistFingerprinting(RFPTarget::Unknown)),
mPlaybackRate(aInit.mPlaybackRate),
mLogicallySeeking(false, "MediaDecoder::mLogicallySeeking"),
INIT_MIRROR(mBuffered, TimeIntervals()),

View File

@@ -18,6 +18,7 @@ class GMPCrashHelper;
class VideoFrameContainer;
class MediaInfo;
class MediaResult;
enum class RFPTarget : uint32_t;
namespace dom {
class Document;
@@ -186,7 +187,7 @@ class MediaDecoderOwner {
virtual bool IsActuallyInvisible() const = 0;
// Returns true if the owner should resist fingerprinting.
virtual bool ShouldResistFingerprinting() const = 0;
virtual bool ShouldResistFingerprinting(RFPTarget aTarget) const = 0;
/*
* Servo only methods go here. Please provide default implementations so they

View File

@@ -246,7 +246,7 @@ RefPtr<MediaDeviceSetRefCnt> MediaDevices::FilterExposedDevices(
!Preferences::GetBool("media.setsinkid.enabled") ||
!FeaturePolicyUtils::IsFeatureAllowed(doc, u"speaker-selection"_ns);
if (doc->ShouldResistFingerprinting()) {
if (doc->ShouldResistFingerprinting(RFPTarget::Unknown)) {
RefPtr fakeEngine = new MediaEngineFake();
fakeEngine->EnumerateDevices(MediaSourceEnum::Microphone,
MediaSinkEnum::Other, exposed);
@@ -725,7 +725,8 @@ void MediaDevices::OnDeviceChange() {
// privacy.resistFingerprinting is true.
if (nsContentUtils::ShouldResistFingerprinting(
"Guarding the more expensive RFP check with a simple one")) {
"Guarding the more expensive RFP check with a simple one",
RFPTarget::Unknown)) {
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
auto* wrapper = GetWrapper();
if (!window && wrapper) {
@@ -736,7 +737,8 @@ void MediaDevices::OnDeviceChange() {
return;
}
if (nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting()) {
if (nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting(
RFPTarget::Unknown)) {
return;
}
}

View File

@@ -8609,7 +8609,8 @@ nsresult PresShell::EventHandler::DispatchEventToDOM(
}
}
if (eventTarget) {
if (eventTarget->OwnerDoc()->ShouldResistFingerprinting() &&
if (eventTarget->OwnerDoc()->ShouldResistFingerprinting(
RFPTarget::Unknown) &&
aEvent->IsBlockedForFingerprintingResistance()) {
aEvent->mFlags.mOnlySystemGroupDispatchInContent = true;
} else if (aEvent->mMessage == eKeyPress) {

View File

@@ -768,7 +768,7 @@ bool nsPresContext::UpdateFontVisibility() {
// Read the relevant pref depending on RFP/trackingProtection state
// to determine the visibility level to use.
int32_t level;
if (mDocument->ShouldResistFingerprinting()) {
if (mDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
level = StaticPrefs::layout_css_font_visibility_resistFingerprinting();
} else if (StaticPrefs::privacy_trackingprotection_enabled() ||
(isPrivate &&

View File

@@ -62,7 +62,7 @@ static nsSize GetSize(const Document& aDocument) {
// A helper for three features below.
static nsSize GetDeviceSize(const Document& aDocument) {
if (aDocument.ShouldResistFingerprinting()) {
if (aDocument.ShouldResistFingerprinting(RFPTarget::Unknown)) {
return GetSize(aDocument);
}
@@ -154,7 +154,7 @@ int32_t Gecko_MediaFeatures_GetMonochromeBitsPerPixel(
dom::ScreenColorGamut Gecko_MediaFeatures_ColorGamut(
const Document* aDocument) {
auto colorGamut = dom::ScreenColorGamut::Srgb;
if (!aDocument->ShouldResistFingerprinting()) {
if (!aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
if (auto* dx = GetDeviceContextFor(aDocument)) {
colorGamut = dx->GetColorGamut();
}
@@ -172,7 +172,7 @@ int32_t Gecko_MediaFeatures_GetColorDepth(const Document* aDocument) {
// rendered.
int32_t depth = 24;
if (!aDocument->ShouldResistFingerprinting()) {
if (!aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
depth = dx->GetDepth();
}
@@ -198,7 +198,7 @@ float Gecko_MediaFeatures_GetResolution(const Document* aDocument) {
return pc->GetOverrideDPPX();
}
if (aDocument->ShouldResistFingerprinting()) {
if (aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return pc->DeviceContext()->GetFullZoom();
}
// Get the actual device pixel ratio, which also takes zoom into account.
@@ -285,7 +285,7 @@ bool Gecko_MediaFeatures_PrefersReducedMotion(const Document* aDocument) {
}
bool Gecko_MediaFeatures_PrefersReducedTransparency(const Document* aDocument) {
if (aDocument->ShouldResistFingerprinting()) {
if (aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return false;
}
return LookAndFeel::GetInt(LookAndFeel::IntID::PrefersReducedTransparency,
@@ -327,7 +327,7 @@ StylePrefersContrast Gecko_MediaFeatures_PrefersContrast(
}
bool Gecko_MediaFeatures_InvertedColors(const Document* aDocument) {
if (aDocument->ShouldResistFingerprinting()) {
if (aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return false;
}
return LookAndFeel::GetInt(LookAndFeel::IntID::InvertedColors, 0) == 1;
@@ -352,7 +352,7 @@ StyleDynamicRange Gecko_MediaFeatures_DynamicRange(const Document* aDocument) {
StyleDynamicRange Gecko_MediaFeatures_VideoDynamicRange(
const Document* aDocument) {
if (aDocument->ShouldResistFingerprinting()) {
if (aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return StyleDynamicRange::Standard;
}
// video-dynamic-range: high has 3 requirements:
@@ -393,7 +393,7 @@ static PointerCapabilities GetPointerCapabilities(const Document* aDocument,
#else
PointerCapabilities::Fine | PointerCapabilities::Hover;
#endif
if (aDocument->ShouldResistFingerprinting()) {
if (aDocument->ShouldResistFingerprinting(RFPTarget::Unknown)) {
return kDefaultCapabilities;
}