Loading dom/base/ScreenOrientation.cpp +18 −4 Original line number Diff line number Diff line Loading @@ -626,7 +626,13 @@ void ScreenOrientation::CleanupFullscreenListener() { OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const { if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(mType); Document* doc = GetResponsibleDocument(); BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; if (!bc) { return nsRFPService::GetDefaultOrientationType(); } CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToOrientationType(size.width, size.height); } return mType; } Loading @@ -634,7 +640,13 @@ OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const { uint16_t ScreenOrientation::DeviceAngle(CallerType aCallerType) const { if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(mAngle); Document* doc = GetResponsibleDocument(); BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; if (!bc) { return 0; } CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToAngle(size.width, size.height); } return mAngle; } Loading @@ -651,7 +663,8 @@ OrientationType ScreenOrientation::GetType(CallerType aCallerType, OrientationType orientation = bc->GetCurrentOrientationType(); if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(orientation); CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToOrientationType(size.width, size.height); } return orientation; } Loading @@ -668,7 +681,8 @@ uint16_t ScreenOrientation::GetAngle(CallerType aCallerType, uint16_t angle = static_cast<uint16_t>(bc->GetCurrentOrientationAngle()); if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(angle); CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToAngle(size.width, size.height); } return angle; } Loading dom/base/nsGlobalWindowInner.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -7309,7 +7309,8 @@ int16_t nsGlobalWindowInner::Orientation(CallerType aCallerType) { uint16_t screenAngle = Screen()->GetOrientationAngle(); if (nsIGlobalObject::ShouldResistFingerprinting( aCallerType, RFPTarget::ScreenOrientation)) { screenAngle = nsRFPService::OrientationSecondaryToPrimary(screenAngle); CSSIntSize size = mBrowsingContext->GetTopInnerSizeForRFP(); screenAngle = nsRFPService::ViewportSizeToAngle(size.width, size.height); } int16_t angle = AssertedCast<int16_t>(screenAngle); return angle <= 180 ? angle : angle - 360; Loading toolkit/components/resistfingerprinting/nsRFPService.cpp +23 −17 Original line number Diff line number Diff line Loading @@ -2295,26 +2295,32 @@ Maybe<RFPTarget> nsRFPService::GetOverriddenFingerprintingSettingsForURI( } /* static */ dom::OrientationType nsRFPService::OrientationSecondaryToPrimary( dom::OrientationType aOrientation) { switch (aOrientation) { case dom::OrientationType::Landscape_secondary: return dom::OrientationType::Landscape_primary; case dom::OrientationType::Portrait_secondary: return dom::OrientationType::Portrait_primary; default: return aOrientation; uint16_t nsRFPService::ViewportSizeToAngle(int32_t aWidth, int32_t aHeight) { #ifdef MOZ_WIDGET_ANDROID bool neutral = aHeight >= aWidth; #else bool neutral = aWidth >= aHeight; #endif if (neutral) { return 0; } return 90; } /* static */ uint16_t nsRFPService::OrientationSecondaryToPrimary(uint16_t aAngle) { switch (aAngle) { case 180: return 0; case 270: return 90; default: return aAngle; dom::OrientationType nsRFPService::ViewportSizeToOrientationType( int32_t aWidth, int32_t aHeight) { if (aWidth >= aHeight) { return dom::OrientationType::Landscape_primary; } return dom::OrientationType::Portrait_primary; } /* static */ dom::OrientationType nsRFPService::GetDefaultOrientationType() { #ifdef MOZ_WIDGET_ANDROID return dom::OrientationType::Portrait_primary; #else return dom::OrientationType::Landscape_primary; #endif } toolkit/components/resistfingerprinting/nsRFPService.h +8 −6 Original line number Diff line number Diff line Loading @@ -369,13 +369,15 @@ class nsRFPService final : public nsIObserver, public nsIRFPService { static bool CheckSuspiciousFingerprintingActivity( nsTArray<ContentBlockingLog::LogEntry>& aLogs); // Converts any OrientationType::SOMETHING_secondary to // OrientationType::SOMETHING_primary static mozilla::dom::OrientationType OrientationSecondaryToPrimary( mozilla::dom::OrientationType aOrientation); // Converts the viewport size to the angle. static uint16_t ViewportSizeToAngle(int32_t aWidth, int32_t aHeight); // Converts (exactly) 180 degrees to 0 degrees, 270 degrees to 90 degrees. static uint16_t OrientationSecondaryToPrimary(uint16_t aAngle); // Converts the viewport size to the orientation type. static dom::OrientationType ViewportSizeToOrientationType(int32_t aWidth, int32_t aHeight); // Returns the default orientation type for the given platform. static dom::OrientationType GetDefaultOrientationType(); private: nsresult Init(); Loading Loading
dom/base/ScreenOrientation.cpp +18 −4 Original line number Diff line number Diff line Loading @@ -626,7 +626,13 @@ void ScreenOrientation::CleanupFullscreenListener() { OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const { if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(mType); Document* doc = GetResponsibleDocument(); BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; if (!bc) { return nsRFPService::GetDefaultOrientationType(); } CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToOrientationType(size.width, size.height); } return mType; } Loading @@ -634,7 +640,13 @@ OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const { uint16_t ScreenOrientation::DeviceAngle(CallerType aCallerType) const { if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(mAngle); Document* doc = GetResponsibleDocument(); BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr; if (!bc) { return 0; } CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToAngle(size.width, size.height); } return mAngle; } Loading @@ -651,7 +663,8 @@ OrientationType ScreenOrientation::GetType(CallerType aCallerType, OrientationType orientation = bc->GetCurrentOrientationType(); if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(orientation); CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToOrientationType(size.width, size.height); } return orientation; } Loading @@ -668,7 +681,8 @@ uint16_t ScreenOrientation::GetAngle(CallerType aCallerType, uint16_t angle = static_cast<uint16_t>(bc->GetCurrentOrientationAngle()); if (nsContentUtils::ShouldResistFingerprinting( aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) { return nsRFPService::OrientationSecondaryToPrimary(angle); CSSIntSize size = bc->GetTopInnerSizeForRFP(); return nsRFPService::ViewportSizeToAngle(size.width, size.height); } return angle; } Loading
dom/base/nsGlobalWindowInner.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -7309,7 +7309,8 @@ int16_t nsGlobalWindowInner::Orientation(CallerType aCallerType) { uint16_t screenAngle = Screen()->GetOrientationAngle(); if (nsIGlobalObject::ShouldResistFingerprinting( aCallerType, RFPTarget::ScreenOrientation)) { screenAngle = nsRFPService::OrientationSecondaryToPrimary(screenAngle); CSSIntSize size = mBrowsingContext->GetTopInnerSizeForRFP(); screenAngle = nsRFPService::ViewportSizeToAngle(size.width, size.height); } int16_t angle = AssertedCast<int16_t>(screenAngle); return angle <= 180 ? angle : angle - 360; Loading
toolkit/components/resistfingerprinting/nsRFPService.cpp +23 −17 Original line number Diff line number Diff line Loading @@ -2295,26 +2295,32 @@ Maybe<RFPTarget> nsRFPService::GetOverriddenFingerprintingSettingsForURI( } /* static */ dom::OrientationType nsRFPService::OrientationSecondaryToPrimary( dom::OrientationType aOrientation) { switch (aOrientation) { case dom::OrientationType::Landscape_secondary: return dom::OrientationType::Landscape_primary; case dom::OrientationType::Portrait_secondary: return dom::OrientationType::Portrait_primary; default: return aOrientation; uint16_t nsRFPService::ViewportSizeToAngle(int32_t aWidth, int32_t aHeight) { #ifdef MOZ_WIDGET_ANDROID bool neutral = aHeight >= aWidth; #else bool neutral = aWidth >= aHeight; #endif if (neutral) { return 0; } return 90; } /* static */ uint16_t nsRFPService::OrientationSecondaryToPrimary(uint16_t aAngle) { switch (aAngle) { case 180: return 0; case 270: return 90; default: return aAngle; dom::OrientationType nsRFPService::ViewportSizeToOrientationType( int32_t aWidth, int32_t aHeight) { if (aWidth >= aHeight) { return dom::OrientationType::Landscape_primary; } return dom::OrientationType::Portrait_primary; } /* static */ dom::OrientationType nsRFPService::GetDefaultOrientationType() { #ifdef MOZ_WIDGET_ANDROID return dom::OrientationType::Portrait_primary; #else return dom::OrientationType::Landscape_primary; #endif }
toolkit/components/resistfingerprinting/nsRFPService.h +8 −6 Original line number Diff line number Diff line Loading @@ -369,13 +369,15 @@ class nsRFPService final : public nsIObserver, public nsIRFPService { static bool CheckSuspiciousFingerprintingActivity( nsTArray<ContentBlockingLog::LogEntry>& aLogs); // Converts any OrientationType::SOMETHING_secondary to // OrientationType::SOMETHING_primary static mozilla::dom::OrientationType OrientationSecondaryToPrimary( mozilla::dom::OrientationType aOrientation); // Converts the viewport size to the angle. static uint16_t ViewportSizeToAngle(int32_t aWidth, int32_t aHeight); // Converts (exactly) 180 degrees to 0 degrees, 270 degrees to 90 degrees. static uint16_t OrientationSecondaryToPrimary(uint16_t aAngle); // Converts the viewport size to the orientation type. static dom::OrientationType ViewportSizeToOrientationType(int32_t aWidth, int32_t aHeight); // Returns the default orientation type for the given platform. static dom::OrientationType GetDefaultOrientationType(); private: nsresult Init(); Loading