[tor-commits] [Git][tpo/applications/mullvad-browser][mullvad-browser-115.15.0esr-13.5-1] Bug 1885101: Match screen and window properties with top window for...
ma1 (@ma1)
git at gitlab.torproject.org
Sat Aug 31 05:56:57 UTC 2024
ma1 pushed to branch mullvad-browser-115.15.0esr-13.5-1 at The Tor Project / Applications / Mullvad Browser
Commits:
5436ef3f by Fatih at 2024-08-31T13:56:21+08:00
Bug 1885101: Match screen and window properties with top window for ScreenRect, ScreenAvailRect and WindowOuterSize. r=timhuang,emilio
This patch removes test_iframe.html. We remove it because the newly introduced test covers the tests done in that test. The reason for removing it in the first place is now that screen properties are inherited/spoofed xorigin, we get a 4px difference. The reasosn for 4px difference is the test runner runs tests in an iframe with a 2px border on each side.
Differential Revision: https://phabricator.services.mozilla.com/D215509
- - - - -
7 changed files:
- docshell/base/BrowsingContext.h
- docshell/base/CanonicalBrowsingContext.cpp
- dom/base/nsGlobalWindowOuter.cpp
- dom/base/nsScreen.cpp
- dom/base/nsScreen.h
- layout/base/nsPresContext.cpp
- layout/base/nsPresContext.h
Changes:
=====================================
docshell/base/BrowsingContext.h
=====================================
@@ -32,6 +32,9 @@
#include "nsILoadInfo.h"
#include "nsILoadContext.h"
#include "nsThreadUtils.h"
+// It seems ESR-115 is missing the definitions of CSSIntSize, so add this
+// header to include it
+#include "Units.h"
class nsDocShellLoadState;
class nsGlobalWindowInner;
@@ -266,7 +269,10 @@ struct EmbedderColorSchemes {
* a content process. */ \
FIELD(EmbeddedInContentDocument, bool) \
/* If true, this browsing context is within a hidden embedded document. */ \
- FIELD(IsUnderHiddenEmbedderElement, bool)
+ FIELD(IsUnderHiddenEmbedderElement, bool) \
+ /* Used to propagate window.top's inner size for RFPTarget::Window* \
+ * protections */ \
+ FIELD(TopInnerSizeForRFP, mozilla::CSSIntSize)
// BrowsingContext, in this context, is the cross process replicated
// environment in which information about documents is stored. In
@@ -1231,6 +1237,10 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
const bool& aIsUnderHiddenEmbedderElement,
ContentParent* aSource);
+ bool CanSet(FieldIndex<IDX_TopInnerSizeForRFP>, bool, ContentParent*) {
+ return IsTop();
+ }
+
bool CanSet(FieldIndex<IDX_EmbeddedInContentDocument>, bool,
ContentParent* aSource) {
return CheckOnlyEmbedderCanSet(aSource);
=====================================
docshell/base/CanonicalBrowsingContext.cpp
=====================================
@@ -318,6 +318,7 @@ void CanonicalBrowsingContext::ReplacedBy(
txn.SetEmbedderColorSchemes(GetEmbedderColorSchemes());
txn.SetHasRestoreData(GetHasRestoreData());
txn.SetShouldDelayMediaFromStart(GetShouldDelayMediaFromStart());
+ txn.SetTopInnerSizeForRFP(GetTopInnerSizeForRFP());
// Propagate some settings on BrowsingContext replacement so they're not lost
// on bfcached navigations. These are important for GeckoView (see bug
=====================================
dom/base/nsGlobalWindowOuter.cpp
=====================================
@@ -3581,9 +3581,10 @@ CSSIntSize nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType,
ErrorResult& aError) {
if (nsIGlobalObject::ShouldResistFingerprinting(aCallerType,
RFPTarget::Unknown)) {
- CSSSize size;
- aError = GetInnerSize(size);
- return RoundedToInt(size);
+ if (BrowsingContext* bc = GetBrowsingContext()) {
+ return bc->Top()->GetTopInnerSizeForRFP();
+ }
+ return {};
}
// Windows showing documents in RDM panes and any subframes within them
=====================================
dom/base/nsScreen.cpp
=====================================
@@ -81,7 +81,7 @@ nsDeviceContext* nsScreen::GetDeviceContext() const {
nsresult nsScreen::GetRect(CSSIntRect& aRect) {
// Return window inner rect to prevent fingerprinting.
if (ShouldResistFingerprinting()) {
- return GetWindowInnerRect(aRect);
+ return GetTopWindowInnerRectForRFP(aRect);
}
// Here we manipulate the value of aRect to represent the screen size,
@@ -113,7 +113,7 @@ nsresult nsScreen::GetRect(CSSIntRect& aRect) {
nsresult nsScreen::GetAvailRect(CSSIntRect& aRect) {
// Return window inner rect to prevent fingerprinting.
if (ShouldResistFingerprinting()) {
- return GetWindowInnerRect(aRect);
+ return GetTopWindowInnerRectForRFP(aRect);
}
// Here we manipulate the value of aRect to represent the screen size,
@@ -208,20 +208,14 @@ JSObject* nsScreen::WrapObject(JSContext* aCx,
return Screen_Binding::Wrap(aCx, this, aGivenProto);
}
-nsresult nsScreen::GetWindowInnerRect(CSSIntRect& aRect) {
- aRect.x = 0;
- aRect.y = 0;
- nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
- if (!win) {
- return NS_ERROR_FAILURE;
+nsresult nsScreen::GetTopWindowInnerRectForRFP(CSSIntRect& aRect) {
+ aRect = {};
+ if (nsPIDOMWindowInner* inner = GetOwner()) {
+ if (BrowsingContext* bc = inner->GetBrowsingContext()) {
+ CSSIntSize size = bc->Top()->GetTopInnerSizeForRFP();
+ aRect = {0, 0, size.width, size.height};
+ }
}
- double width;
- double height;
- nsresult rv = win->GetInnerWidth(&width);
- NS_ENSURE_SUCCESS(rv, rv);
- rv = win->GetInnerHeight(&height);
- NS_ENSURE_SUCCESS(rv, rv);
- aRect.SizeTo(std::round(width), std::round(height));
return NS_OK;
}
=====================================
dom/base/nsScreen.h
=====================================
@@ -127,7 +127,9 @@ class nsScreen : public mozilla::DOMEventTargetHelper {
nsDeviceContext* GetDeviceContext() const;
nsresult GetRect(mozilla::CSSIntRect& aRect);
nsresult GetAvailRect(mozilla::CSSIntRect& aRect);
- nsresult GetWindowInnerRect(mozilla::CSSIntRect& aRect);
+ // Sometime between ESR-115 and ESR-128 the function signature changed, so we
+ // revert to the ESR-115 way of doing things
+ nsresult GetTopWindowInnerRectForRFP(mozilla::CSSIntRect& aRect);
private:
explicit nsScreen(nsPIDOMWindowInner* aWindow);
=====================================
layout/base/nsPresContext.cpp
=====================================
@@ -1448,6 +1448,26 @@ void nsPresContext::SetOverrideDPPX(float aDPPX) {
MediaFeatureChangePropagation::JustThisDocument);
}
+void nsPresContext::UpdateTopInnerSizeForRFP() {
+// RFPTarget::WindowOuterSize does not exist in ESR-115 so use fallback
+ if (!mDocument->ShouldResistFingerprinting(RFPTarget::Unknown) ||
+ !mDocument->GetBrowsingContext() ||
+ !mDocument->GetBrowsingContext()->IsTop()) {
+ return;
+ }
+
+ CSSSize size = CSSPixel::FromAppUnits(GetVisibleArea().Size());
+
+ // The upstream version of this patch had conditional logic based on the
+ // dom.innerSize.rounding pref which does not exist in ESR-115, so we
+ // pick the branch it would have taken for the pref's default value (2)
+ size.width = std::truncf(size.width);
+ size.height = std::truncf(size.height);
+
+ Unused << mDocument->GetBrowsingContext()->SetTopInnerSizeForRFP(
+ CSSIntSize{(int)size.width, (int)size.height});
+}
+
gfxSize nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged) {
if (aChanged) {
*aChanged = false;
@@ -2979,6 +2999,8 @@ void nsPresContext::SetVisibleArea(const nsRect& r) {
{mozilla::MediaFeatureChangeReason::ViewportChange},
MediaFeatureChangePropagation::JustThisDocument);
}
+
+ UpdateTopInnerSizeForRFP();
}
}
=====================================
layout/base/nsPresContext.h
=====================================
@@ -549,6 +549,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
void SetFullZoom(float aZoom);
void SetOverrideDPPX(float);
void SetInRDMPane(bool aInRDMPane);
+ void UpdateTopInnerSizeForRFP();
public:
float GetFullZoom() { return mFullZoom; }
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/5436ef3f20ddc704ffc6fac7553c763faaa32d9f
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/5436ef3f20ddc704ffc6fac7553c763faaa32d9f
You're receiving this email because of your account on gitlab.torproject.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20240831/07f9475a/attachment-0001.htm>
More information about the tor-commits
mailing list