Commit 03ade0a6 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1753995 - Move devicePixelRatio getter from outer to inner window. r=smaug

It only pokes at the document's pres context, there's no need to
roundtrip through the outer window. No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D138019
parent fdd4b40d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -2193,7 +2193,12 @@ NS_IMETHODIMP
nsDOMWindowUtils::GetScreenPixelsPerCSSPixel(float* aScreenPixels) {
  nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
  NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
  *aScreenPixels = window->GetDevicePixelRatio(CallerType::System);
  nsCOMPtr<nsPIDOMWindowInner> innerWindow = window->GetCurrentInnerWindow();
  NS_ENSURE_STATE(innerWindow);
  // XXX Why does this API exist? Callers should just use devicePixelRatio!
  *aScreenPixels =
      nsGlobalWindowInner::Cast(innerWindow)
          ->GetDevicePixelRatio(CallerType::System, IgnoreErrors());
  return NS_OK;
}

+44 −2
Original line number Diff line number Diff line
@@ -3521,8 +3521,50 @@ float nsGlobalWindowInner::GetMozInnerScreenY(CallerType aCallerType,

double nsGlobalWindowInner::GetDevicePixelRatio(CallerType aCallerType,
                                                ErrorResult& aError) {
  FORWARD_TO_OUTER_OR_THROW(GetDevicePixelRatioOuter, (aCallerType), aError,
                            0.0);
  ENSURE_ACTIVE_DOCUMENT(aError, 0.0);

  RefPtr<nsPresContext> presContext = mDoc->GetPresContext();
  if (NS_WARN_IF(!presContext)) {
    // We're in an undisplayed subdocument... There's not really an awesome way
    // to tell what the right DPI is from here, so we try to walk up our parent
    // document chain to the extent that the docs can observe each other.
    Document* doc = mDoc;
    while (doc->StyleOrLayoutObservablyDependsOnParentDocumentLayout()) {
      doc = doc->GetInProcessParentDocument();
      presContext = doc->GetPresContext();
      if (presContext) {
        break;
      }
    }

    if (!presContext) {
      // Still nothing, oh well.
      return 1.0;
    }
  }

  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
    // Spoofing the DevicePixelRatio causes blurriness in some situations
    // on HiDPI displays. pdf.js is a non-system caller; but it can't
    // expose the fingerprintable information, so we can safely disable
    // spoofing in this situation. It doesn't address the issue for
    // web-rendered content (including pdf.js instances on the web.)
    // In the future we hope to have a better solution to fix all HiDPI
    // blurriness...
    nsAutoCString origin;
    nsresult rv = this->GetPrincipal()->GetOrigin(origin);
    if (NS_FAILED(rv) || origin != "resource://pdf.js"_ns) {
      return 1.0;
    }
  }

  float overrideDPPX = presContext->GetOverrideDPPX();
  if (overrideDPPX > 0.0f) {
    return overrideDPPX;
  }

  return double(AppUnitsPerCSSPixel()) /
         double(presContext->AppUnitsPerDevPixel());
}

uint64_t nsGlobalWindowInner::GetMozPaintCount(ErrorResult& aError) {
+0 −54
Original line number Diff line number Diff line
@@ -3849,60 +3849,6 @@ float nsGlobalWindowOuter::GetMozInnerScreenYOuter(CallerType aCallerType) {
  return nsPresContext::AppUnitsToFloatCSSPixels(r.y);
}

double nsGlobalWindowOuter::GetDevicePixelRatioOuter(CallerType aCallerType) {
  if (NS_WARN_IF(!mDoc)) {
    return 1.0;
  }

  RefPtr<nsPresContext> presContext = mDoc->GetPresContext();
  if (NS_WARN_IF(!presContext)) {
    // We're in an undisplayed subdocument... There's not really an awesome way
    // to tell what the right DPI is from here, so we try to walk up our parent
    // document chain to the extent that the docs can observe each other.
    Document* doc = mDoc;
    while (doc->StyleOrLayoutObservablyDependsOnParentDocumentLayout()) {
      doc = doc->GetInProcessParentDocument();
      presContext = doc->GetPresContext();
      if (presContext) {
        break;
      }
    }

    if (!presContext) {
      // Still nothing, oh well.
      return 1.0;
    }
  }

  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
    // Spoofing the DevicePixelRatio causes blurriness in some situations
    // on HiDPI displays. pdf.js is a non-system caller; but it can't
    // expose the fingerprintable information, so we can safely disable
    // spoofing in this situation. It doesn't address the issue for
    // web-rendered content (including pdf.js instances on the web.)
    // In the future we hope to have a better solution to fix all HiDPI
    // blurriness...
    nsAutoCString origin;
    nsresult rv = this->GetPrincipal()->GetOrigin(origin);
    if (NS_FAILED(rv) || origin != "resource://pdf.js"_ns) {
      return 1.0;
    }
  }

  float overrideDPPX = presContext->GetOverrideDPPX();

  if (overrideDPPX > 0) {
    return overrideDPPX;
  }

  return double(AppUnitsPerCSSPixel()) /
         double(presContext->AppUnitsPerDevPixel());
}

float nsPIDOMWindowOuter::GetDevicePixelRatio(CallerType aCallerType) {
  return nsGlobalWindowOuter::Cast(this)->GetDevicePixelRatioOuter(aCallerType);
}

uint64_t nsGlobalWindowOuter::GetMozPaintCountOuter() {
  if (!mDocShell) {
    return 0;
+0 −1
Original line number Diff line number Diff line
@@ -623,7 +623,6 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
  nsresult GetControllers(nsIControllers** aControllers) override;
  float GetMozInnerScreenXOuter(mozilla::dom::CallerType aCallerType);
  float GetMozInnerScreenYOuter(mozilla::dom::CallerType aCallerType);
  double GetDevicePixelRatioOuter(mozilla::dom::CallerType aCallerType);
  bool GetFullscreenOuter();
  bool GetFullScreen() override;
  void SetFullscreenOuter(bool aFullscreen, mozilla::ErrorResult& aError);
+0 −2
Original line number Diff line number Diff line
@@ -820,8 +820,6 @@ class nsPIDOMWindowOuter : public mozIDOMWindowProxy {

  void RefreshMediaElementsVolume();

  float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType);

  virtual nsPIDOMWindowOuter* GetPrivateRoot() = 0;

  /**