commit a086a5d0070821b1c4dfd2492bdc993c91353a2b Author: Arthur Edelstein arthuredelstein@gmail.com Date: Sun May 8 22:23:42 2016 -0700
Bug 18958: Spoof screen.orientation values
Make sure that screen.orientation.angle -> 0 and screen.orientation.type -> "landscape-primary"
Also refactors screen.mozOrientation. --- dom/base/ScreenOrientation.cpp | 29 +++++++++++++++++++++++++++-- dom/base/ScreenOrientation.h | 2 ++ dom/base/nsGlobalWindow.cpp | 7 ++++--- dom/base/nsScreen.cpp | 38 ++++++++++++++++++++------------------ 4 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/dom/base/ScreenOrientation.cpp b/dom/base/ScreenOrientation.cpp index 868a1d5..fdea67a 100644 --- a/dom/base/ScreenOrientation.cpp +++ b/dom/base/ScreenOrientation.cpp @@ -15,6 +15,7 @@ #include "mozilla/Preferences.h"
#include "mozilla/dom/Promise.h" +#include "nsContentUtils.h"
using namespace mozilla; using namespace mozilla::dom; @@ -403,18 +404,23 @@ ScreenOrientation::UnlockDeviceOrientation() OrientationType ScreenOrientation::DeviceType() const { - return mType; + return ShouldResistFingerprinting() ? OrientationType::Landscape_primary + : mType; }
uint16_t ScreenOrientation::DeviceAngle() const { - return mAngle; + return ShouldResistFingerprinting() ? 0 : mAngle; }
OrientationType ScreenOrientation::GetType(ErrorResult& aRv) const { + if (ShouldResistFingerprinting()) { + return OrientationType::Landscape_primary; + } + nsIDocument* doc = GetResponsibleDocument(); if (!doc) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -427,6 +433,10 @@ ScreenOrientation::GetType(ErrorResult& aRv) const uint16_t ScreenOrientation::GetAngle(ErrorResult& aRv) const { + if (ShouldResistFingerprinting()) { + return 0; + } + nsIDocument* doc = GetResponsibleDocument(); if (!doc) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -489,6 +499,10 @@ ScreenOrientation::GetResponsibleDocument() const void ScreenOrientation::Notify(const hal::ScreenConfiguration& aConfiguration) { + if (ShouldResistFingerprinting()) { + return; + } + nsIDocument* doc = GetResponsibleDocument(); if (!doc) { return; @@ -564,6 +578,17 @@ ScreenOrientation::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) return ScreenOrientationBinding::Wrap(aCx, this, aGivenProto); }
+bool +ScreenOrientation::ShouldResistFingerprinting() const +{ + bool resist = false; + nsCOMPtr<nsPIDOMWindow> owner = GetOwner(); + if (owner) { + resist = nsContentUtils::ShouldResistFingerprinting(owner->GetDocShell()); + } + return resist; +} + NS_IMPL_ISUPPORTS(ScreenOrientation::VisibleEventListener, nsIDOMEventListener)
NS_IMETHODIMP diff --git a/dom/base/ScreenOrientation.h b/dom/base/ScreenOrientation.h index afb5e77..a6e51c7 100644 --- a/dom/base/ScreenOrientation.h +++ b/dom/base/ScreenOrientation.h @@ -102,6 +102,8 @@ private:
void DispatchChangeEvent();
+ bool ShouldResistFingerprinting() const; + LockPermission GetLockOrientationPermission(bool aCheckSandbox) const;
// Gets the responsible document as defined in the spec. diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index ed42538..6dc06b1 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -12820,8 +12820,8 @@ void nsGlobalWindow::EnableOrientationChangeListener() { MOZ_ASSERT(IsInnerWindow()); - - if (!mOrientationChangeObserver) { + if (!nsContentUtils::ShouldResistFingerprinting(mDocShell) + && !mOrientationChangeObserver) { mOrientationChangeObserver = new WindowOrientationObserver(this); } @@ -13671,7 +13671,8 @@ nsGlobalWindow::IsModalContentWindow(JSContext* aCx, JSObject* aGlobal) int16_t nsGlobalWindow::Orientation() const { - return WindowOrientationObserver::OrientationAngle(); + return nsContentUtils::ShouldResistFingerprinting(mDocShell) ? + 0 : WindowOrientationObserver::OrientationAngle(); } #endif
diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index ad1642b..49c12eb 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -166,25 +166,21 @@ nsScreen::Orientation() const void nsScreen::GetMozOrientation(nsString& aOrientation) const { - if (ShouldResistFingerprinting()) { + switch (mScreenOrientation->DeviceType()) { + case OrientationType::Portrait_primary: + aOrientation.AssignLiteral("portrait-primary"); + break; + case OrientationType::Portrait_secondary: + aOrientation.AssignLiteral("portrait-secondary"); + break; + case OrientationType::Landscape_primary: aOrientation.AssignLiteral("landscape-primary"); - } else { - switch (mScreenOrientation->DeviceType()) { - case OrientationType::Portrait_primary: - aOrientation.AssignLiteral("portrait-primary"); - break; - case OrientationType::Portrait_secondary: - aOrientation.AssignLiteral("portrait-secondary"); - break; - case OrientationType::Landscape_primary: - aOrientation.AssignLiteral("landscape-primary"); - break; - case OrientationType::Landscape_secondary: - aOrientation.AssignLiteral("landscape-secondary"); - break; - default: - MOZ_CRASH("Unacceptable screen orientation type."); - } + break; + case OrientationType::Landscape_secondary: + aOrientation.AssignLiteral("landscape-secondary"); + break; + default: + MOZ_CRASH("Unacceptable screen orientation type."); } }
@@ -236,6 +232,9 @@ bool nsScreen::MozLockOrientation(const Sequence<nsString>& aOrientations, ErrorResult& aRv) { + if (ShouldResistFingerprinting()) { + return false; + } ScreenOrientationInternal orientation = eScreenOrientation_None;
for (uint32_t i = 0; i < aOrientations.Length(); ++i) { @@ -283,6 +282,9 @@ nsScreen::MozLockOrientation(const Sequence<nsString>& aOrientations, void nsScreen::MozUnlockOrientation() { + if (ShouldResistFingerprinting()) { + return; + } UpdateDocShellOrientationLock(GetOwner(), eScreenOrientation_None); mScreenOrientation->UnlockDeviceOrientation(); }
tbb-commits@lists.torproject.org