Commit a8a015ab authored by Fatih's avatar Fatih Committed by Pier Angelo Vendrame
Browse files

Bug 1885101: Match screen and window properties with top window for...

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
parent ae0c1bb5
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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
+4 −3
Original line number Diff line number Diff line
@@ -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
+9 −15
Original line number Diff line number Diff line
@@ -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;
}

+3 −1
Original line number Diff line number Diff line
@@ -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);
Loading