From d22d7aafa43665ccc5f762c5f4368d376f5ad527 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 22 Dec 2016 11:05:54 -0800 Subject: [PATCH] Bug 1320801 part 5. Switch from ShouldResistFingerprinting to ResistFingerprinting (use the caller type, not the document principal) in nsGlobalWindow's devicePixelRatio getter. r=bkelly --- dom/base/nsDOMWindowUtils.cpp | 4 +++- dom/base/nsGlobalWindow.cpp | 19 +++++++------------ dom/base/nsGlobalWindow.h | 6 +++--- dom/base/nsPIDOMWindow.h | 4 +++- .../webrtc/MediaEngineTabVideoSource.cpp | 3 ++- dom/webidl/Window.webidl | 3 ++- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 5a3d7ed1cbfd..a43faa095d0e 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -18,6 +18,7 @@ #include "nsFocusManager.h" #include "nsFrameManager.h" #include "nsRefreshDriver.h" +#include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/Touch.h" #include "mozilla/PendingAnimationTracker.h" @@ -1848,7 +1849,8 @@ nsDOMWindowUtils::GetScreenPixelsPerCSSPixel(float* aScreenPixels) { nsCOMPtr window = do_QueryReferent(mWindow); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - return window->GetDevicePixelRatio(aScreenPixels); + *aScreenPixels = window->GetDevicePixelRatio(CallerType::System); + return NS_OK; } NS_IMETHODIMP diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index e510fd8ff5ef..ed13064aa77b 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -5572,7 +5572,7 @@ nsGlobalWindow::GetMozInnerScreenY(CallerType aCallerType, ErrorResult& aError) } float -nsGlobalWindow::GetDevicePixelRatioOuter() +nsGlobalWindow::GetDevicePixelRatioOuter(CallerType aCallerType) { MOZ_RELEASE_ASSERT(IsOuterWindow()); @@ -5586,7 +5586,7 @@ nsGlobalWindow::GetDevicePixelRatioOuter() return 1.0; } - if (nsContentUtils::ShouldResistFingerprinting(mDocShell)) { + if (nsContentUtils::ResistFingerprinting(aCallerType)) { return 1.0; } @@ -5601,20 +5601,15 @@ nsGlobalWindow::GetDevicePixelRatioOuter() } float -nsGlobalWindow::GetDevicePixelRatio(ErrorResult& aError) +nsGlobalWindow::GetDevicePixelRatio(CallerType aCallerType, ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(GetDevicePixelRatioOuter, (), aError, 0.0); + FORWARD_TO_OUTER_OR_THROW(GetDevicePixelRatioOuter, (aCallerType), aError, 0.0); } -nsresult -nsGlobalWindow::GetDevicePixelRatio(float* aRatio) +float +nsPIDOMWindowOuter::GetDevicePixelRatio(CallerType aCallerType) { - FORWARD_TO_INNER(GetDevicePixelRatio, (aRatio), NS_ERROR_UNEXPECTED); - - ErrorResult rv; - *aRatio = GetDevicePixelRatio(rv); - - return rv.StealNSResult(); + return nsGlobalWindow::Cast(this)->GetDevicePixelRatioOuter(aCallerType); } uint64_t diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 3d82cfe5cd30..1f63b44e24f4 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -1118,9 +1118,9 @@ public: float GetMozInnerScreenYOuter(mozilla::dom::CallerType aCallerType); float GetMozInnerScreenY(mozilla::dom::CallerType aCallerType, mozilla::ErrorResult& aError); - float GetDevicePixelRatioOuter(); - float GetDevicePixelRatio(mozilla::ErrorResult& aError); - nsresult GetDevicePixelRatio(float* aRatio) override; + float GetDevicePixelRatioOuter(mozilla::dom::CallerType aCallerType); + float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType, + mozilla::ErrorResult& aError); int32_t GetScrollMinX(mozilla::ErrorResult& aError); int32_t GetScrollMinY(mozilla::ErrorResult& aError); int32_t GetScrollMaxX(mozilla::ErrorResult& aError); diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index eafc7e7e4e03..8289babbcd11 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -51,6 +51,7 @@ class ServiceWorkerRegistration; class Timeout; class TimeoutManager; class CustomElementRegistry; +enum class CallerType : uint32_t; } // namespace dom } // namespace mozilla @@ -557,7 +558,6 @@ public: nsISupports* aExtraArgument, nsPIDOMWindowOuter** _retval) = 0; - virtual nsresult GetDevicePixelRatio(float* aRatio) = 0; virtual nsresult GetInnerWidth(int32_t* aWidth) = 0; virtual nsresult GetInnerHeight(int32_t* aHeight) = 0; virtual already_AddRefed @@ -936,6 +936,8 @@ public: void SetServiceWorkersTestingEnabled(bool aEnabled); bool GetServiceWorkersTestingEnabled(); + + float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType); }; NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter, NS_PIDOMWINDOWOUTER_IID) diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.cpp b/dom/media/webrtc/MediaEngineTabVideoSource.cpp index 4dbe0c0d45db..61e2e8a0ce4a 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp @@ -8,6 +8,7 @@ #include "mozilla/gfx/2D.h" #include "mozilla/RefPtr.h" #include "mozilla/UniquePtrExtensions.h" +#include "mozilla/dom/BindingDeclarations.h" #include "nsGlobalWindow.h" #include "nsIDOMClientRect.h" #include "nsIDocShell.h" @@ -284,7 +285,7 @@ MediaEngineTabVideoSource::Draw() { { float pixelRatio; if (mWindow) { - mWindow->GetDevicePixelRatio(&pixelRatio); + pixelRatio = mWindow->GetDevicePixelRatio(CallerType::System); } else { pixelRatio = 1.0f; } diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 415e1681ab2c..ca4d664af6e8 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -287,7 +287,8 @@ partial interface Window { readonly attribute float mozInnerScreenX; [Throws, NeedsCallerType] readonly attribute float mozInnerScreenY; - [Replaceable, Throws] readonly attribute float devicePixelRatio; + [Replaceable, Throws, NeedsCallerType] + readonly attribute float devicePixelRatio; /* The maximum offset that the window can be scrolled to (i.e., the document width/height minus the scrollport width/height) */