Commits:
-
fdbe54d5
by Fatih at 2024-08-29T22:23:54+00: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:
Changes:
docshell/base/BrowsingContext.h
... |
... |
@@ -32,6 +32,9 @@ |
32
|
32
|
#include "nsILoadInfo.h"
|
33
|
33
|
#include "nsILoadContext.h"
|
34
|
34
|
#include "nsThreadUtils.h"
|
|
35
|
+// It seems ESR-115 is missing the definitions of CSSIntSize, so add this
|
|
36
|
+// header to include it
|
|
37
|
+#include "Units.h"
|
35
|
38
|
|
36
|
39
|
class nsDocShellLoadState;
|
37
|
40
|
class nsGlobalWindowInner;
|
... |
... |
@@ -266,7 +269,10 @@ struct EmbedderColorSchemes { |
266
|
269
|
* a content process. */ \
|
267
|
270
|
FIELD(EmbeddedInContentDocument, bool) \
|
268
|
271
|
/* If true, this browsing context is within a hidden embedded document. */ \
|
269
|
|
- FIELD(IsUnderHiddenEmbedderElement, bool)
|
|
272
|
+ FIELD(IsUnderHiddenEmbedderElement, bool) \
|
|
273
|
+ /* Used to propagate window.top's inner size for RFPTarget::Window* \
|
|
274
|
+ * protections */ \
|
|
275
|
+ FIELD(TopInnerSizeForRFP, mozilla::CSSIntSize)
|
270
|
276
|
|
271
|
277
|
// BrowsingContext, in this context, is the cross process replicated
|
272
|
278
|
// environment in which information about documents is stored. In
|
... |
... |
@@ -1231,6 +1237,10 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { |
1231
|
1237
|
const bool& aIsUnderHiddenEmbedderElement,
|
1232
|
1238
|
ContentParent* aSource);
|
1233
|
1239
|
|
|
1240
|
+ bool CanSet(FieldIndex<IDX_TopInnerSizeForRFP>, bool, ContentParent*) {
|
|
1241
|
+ return IsTop();
|
|
1242
|
+ }
|
|
1243
|
+
|
1234
|
1244
|
bool CanSet(FieldIndex<IDX_EmbeddedInContentDocument>, bool,
|
1235
|
1245
|
ContentParent* aSource) {
|
1236
|
1246
|
return CheckOnlyEmbedderCanSet(aSource);
|
docshell/base/CanonicalBrowsingContext.cpp
... |
... |
@@ -318,6 +318,7 @@ void CanonicalBrowsingContext::ReplacedBy( |
318
|
318
|
txn.SetEmbedderColorSchemes(GetEmbedderColorSchemes());
|
319
|
319
|
txn.SetHasRestoreData(GetHasRestoreData());
|
320
|
320
|
txn.SetShouldDelayMediaFromStart(GetShouldDelayMediaFromStart());
|
|
321
|
+ txn.SetTopInnerSizeForRFP(GetTopInnerSizeForRFP());
|
321
|
322
|
|
322
|
323
|
// Propagate some settings on BrowsingContext replacement so they're not lost
|
323
|
324
|
// on bfcached navigations. These are important for GeckoView (see bug
|
dom/base/nsGlobalWindowOuter.cpp
... |
... |
@@ -3582,9 +3582,10 @@ CSSIntSize nsGlobalWindowOuter::GetOuterSize(CallerType aCallerType, |
3582
|
3582
|
ErrorResult& aError) {
|
3583
|
3583
|
if (nsIGlobalObject::ShouldResistFingerprinting(aCallerType,
|
3584
|
3584
|
RFPTarget::Unknown)) {
|
3585
|
|
- CSSSize size;
|
3586
|
|
- aError = GetInnerSize(size);
|
3587
|
|
- return RoundedToInt(size);
|
|
3585
|
+ if (BrowsingContext* bc = GetBrowsingContext()) {
|
|
3586
|
+ return bc->Top()->GetTopInnerSizeForRFP();
|
|
3587
|
+ }
|
|
3588
|
+ return {};
|
3588
|
3589
|
}
|
3589
|
3590
|
|
3590
|
3591
|
// Windows showing documents in RDM panes and any subframes within them
|
dom/base/nsScreen.cpp
... |
... |
@@ -81,7 +81,7 @@ nsDeviceContext* nsScreen::GetDeviceContext() const { |
81
|
81
|
nsresult nsScreen::GetRect(CSSIntRect& aRect) {
|
82
|
82
|
// Return window inner rect to prevent fingerprinting.
|
83
|
83
|
if (ShouldResistFingerprinting()) {
|
84
|
|
- return GetWindowInnerRect(aRect);
|
|
84
|
+ return GetTopWindowInnerRectForRFP(aRect);
|
85
|
85
|
}
|
86
|
86
|
|
87
|
87
|
// Here we manipulate the value of aRect to represent the screen size,
|
... |
... |
@@ -113,7 +113,7 @@ nsresult nsScreen::GetRect(CSSIntRect& aRect) { |
113
|
113
|
nsresult nsScreen::GetAvailRect(CSSIntRect& aRect) {
|
114
|
114
|
// Return window inner rect to prevent fingerprinting.
|
115
|
115
|
if (ShouldResistFingerprinting()) {
|
116
|
|
- return GetWindowInnerRect(aRect);
|
|
116
|
+ return GetTopWindowInnerRectForRFP(aRect);
|
117
|
117
|
}
|
118
|
118
|
|
119
|
119
|
// Here we manipulate the value of aRect to represent the screen size,
|
... |
... |
@@ -208,20 +208,14 @@ JSObject* nsScreen::WrapObject(JSContext* aCx, |
208
|
208
|
return Screen_Binding::Wrap(aCx, this, aGivenProto);
|
209
|
209
|
}
|
210
|
210
|
|
211
|
|
-nsresult nsScreen::GetWindowInnerRect(CSSIntRect& aRect) {
|
212
|
|
- aRect.x = 0;
|
213
|
|
- aRect.y = 0;
|
214
|
|
- nsCOMPtr<nsPIDOMWindowInner> win = GetOwner();
|
215
|
|
- if (!win) {
|
216
|
|
- return NS_ERROR_FAILURE;
|
|
211
|
+nsresult nsScreen::GetTopWindowInnerRectForRFP(CSSIntRect& aRect) {
|
|
212
|
+ aRect = {};
|
|
213
|
+ if (nsPIDOMWindowInner* inner = GetOwner()) {
|
|
214
|
+ if (BrowsingContext* bc = inner->GetBrowsingContext()) {
|
|
215
|
+ CSSIntSize size = bc->Top()->GetTopInnerSizeForRFP();
|
|
216
|
+ aRect = {0, 0, size.width, size.height};
|
|
217
|
+ }
|
217
|
218
|
}
|
218
|
|
- double width;
|
219
|
|
- double height;
|
220
|
|
- nsresult rv = win->GetInnerWidth(&width);
|
221
|
|
- NS_ENSURE_SUCCESS(rv, rv);
|
222
|
|
- rv = win->GetInnerHeight(&height);
|
223
|
|
- NS_ENSURE_SUCCESS(rv, rv);
|
224
|
|
- aRect.SizeTo(std::round(width), std::round(height));
|
225
|
219
|
return NS_OK;
|
226
|
220
|
}
|
227
|
221
|
|
dom/base/nsScreen.h
... |
... |
@@ -127,7 +127,9 @@ class nsScreen : public mozilla::DOMEventTargetHelper { |
127
|
127
|
nsDeviceContext* GetDeviceContext() const;
|
128
|
128
|
nsresult GetRect(mozilla::CSSIntRect& aRect);
|
129
|
129
|
nsresult GetAvailRect(mozilla::CSSIntRect& aRect);
|
130
|
|
- nsresult GetWindowInnerRect(mozilla::CSSIntRect& aRect);
|
|
130
|
+ // Sometime between ESR-115 and ESR-128 the function signature changed, so we
|
|
131
|
+ // revert to the ESR-115 way of doing things
|
|
132
|
+ nsresult GetTopWindowInnerRectForRFP(mozilla::CSSIntRect& aRect);
|
131
|
133
|
|
132
|
134
|
private:
|
133
|
135
|
explicit nsScreen(nsPIDOMWindowInner* aWindow);
|
layout/base/nsPresContext.cpp
... |
... |
@@ -1448,6 +1448,26 @@ void nsPresContext::SetOverrideDPPX(float aDPPX) { |
1448
|
1448
|
MediaFeatureChangePropagation::JustThisDocument);
|
1449
|
1449
|
}
|
1450
|
1450
|
|
|
1451
|
+void nsPresContext::UpdateTopInnerSizeForRFP() {
|
|
1452
|
+// RFPTarget::WindowOuterSize does not exist in ESR-115 so use fallback
|
|
1453
|
+ if (!mDocument->ShouldResistFingerprinting(RFPTarget::Unknown) ||
|
|
1454
|
+ !mDocument->GetBrowsingContext() ||
|
|
1455
|
+ !mDocument->GetBrowsingContext()->IsTop()) {
|
|
1456
|
+ return;
|
|
1457
|
+ }
|
|
1458
|
+
|
|
1459
|
+ CSSSize size = CSSPixel::FromAppUnits(GetVisibleArea().Size());
|
|
1460
|
+
|
|
1461
|
+ // The upstream version of this patch had conditional logic based on the
|
|
1462
|
+ // dom.innerSize.rounding pref which does not exist in ESR-115, so we
|
|
1463
|
+ // pick the branch it would have taken for the pref's default value (2)
|
|
1464
|
+ size.width = std::truncf(size.width);
|
|
1465
|
+ size.height = std::truncf(size.height);
|
|
1466
|
+
|
|
1467
|
+ Unused << mDocument->GetBrowsingContext()->SetTopInnerSizeForRFP(
|
|
1468
|
+ CSSIntSize{(int)size.width, (int)size.height});
|
|
1469
|
+}
|
|
1470
|
+
|
1451
|
1471
|
gfxSize nsPresContext::ScreenSizeInchesForFontInflation(bool* aChanged) {
|
1452
|
1472
|
if (aChanged) {
|
1453
|
1473
|
*aChanged = false;
|
... |
... |
@@ -2979,6 +2999,8 @@ void nsPresContext::SetVisibleArea(const nsRect& r) { |
2979
|
2999
|
{mozilla::MediaFeatureChangeReason::ViewportChange},
|
2980
|
3000
|
MediaFeatureChangePropagation::JustThisDocument);
|
2981
|
3001
|
}
|
|
3002
|
+
|
|
3003
|
+ UpdateTopInnerSizeForRFP();
|
2982
|
3004
|
}
|
2983
|
3005
|
}
|
2984
|
3006
|
|
layout/base/nsPresContext.h
... |
... |
@@ -549,6 +549,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { |
549
|
549
|
void SetFullZoom(float aZoom);
|
550
|
550
|
void SetOverrideDPPX(float);
|
551
|
551
|
void SetInRDMPane(bool aInRDMPane);
|
|
552
|
+ void UpdateTopInnerSizeForRFP();
|
552
|
553
|
|
553
|
554
|
public:
|
554
|
555
|
float GetFullZoom() { return mFullZoom; }
|
|