[tbb-commits] [Git][tpo/applications/tor-browser][base-browser-128.3.0esr-14.0-1] 2 commits: Bug 1607032: Spoof screen orientation and angle to primary values. r=tjr, geckoview-reviewers, owlish

morgan (@morgan) git at gitlab.torproject.org
Wed Oct 2 19:27:13 UTC 2024



morgan pushed to branch base-browser-128.3.0esr-14.0-1 at The Tor Project / Applications / Tor Browser


Commits:
9f066a06 by Fatih at 2024-10-02T19:25:48+00:00
Bug 1607032: Spoof screen orientation and angle to primary values. r=tjr,geckoview-reviewers,owlish

Differential Revision: https://phabricator.services.mozilla.com/D220904

- - - - -
6112a1c3 by Fatih at 2024-10-02T19:25:48+00:00
Bug 1918202: Spoof orientation based on screen size. r=tjr

Differential Revision: https://phabricator.services.mozilla.com/D221863

- - - - -


6 changed files:

- dom/base/ScreenOrientation.cpp
- dom/base/nsGlobalWindowInner.cpp
- dom/base/test/chrome/bug418986-1.js
- hal/android/AndroidHal.cpp
- toolkit/components/resistfingerprinting/nsRFPService.cpp
- toolkit/components/resistfingerprinting/nsRFPService.h


Changes:

=====================================
dom/base/ScreenOrientation.cpp
=====================================
@@ -626,7 +626,13 @@ void ScreenOrientation::CleanupFullscreenListener() {
 OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const {
   if (nsContentUtils::ShouldResistFingerprinting(
           aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
-    return OrientationType::Landscape_primary;
+    Document* doc = GetResponsibleDocument();
+    BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
+    if (!bc) {
+      return nsRFPService::GetDefaultOrientationType();
+    }
+    CSSIntSize size = bc->GetTopInnerSizeForRFP();
+    return nsRFPService::ViewportSizeToOrientationType(size.width, size.height);
   }
   return mType;
 }
@@ -634,18 +640,19 @@ OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const {
 uint16_t ScreenOrientation::DeviceAngle(CallerType aCallerType) const {
   if (nsContentUtils::ShouldResistFingerprinting(
           aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
-    return 0;
+    Document* doc = GetResponsibleDocument();
+    BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
+    if (!bc) {
+      return 0;
+    }
+    CSSIntSize size = bc->GetTopInnerSizeForRFP();
+    return nsRFPService::ViewportSizeToAngle(size.width, size.height);
   }
   return mAngle;
 }
 
 OrientationType ScreenOrientation::GetType(CallerType aCallerType,
                                            ErrorResult& aRv) const {
-  if (nsContentUtils::ShouldResistFingerprinting(
-          aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
-    return OrientationType::Landscape_primary;
-  }
-
   Document* doc = GetResponsibleDocument();
   BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
   if (!bc) {
@@ -653,16 +660,17 @@ OrientationType ScreenOrientation::GetType(CallerType aCallerType,
     return OrientationType::Portrait_primary;
   }
 
-  return bc->GetCurrentOrientationType();
-}
-
-uint16_t ScreenOrientation::GetAngle(CallerType aCallerType,
-                                     ErrorResult& aRv) const {
+  OrientationType orientation = bc->GetCurrentOrientationType();
   if (nsContentUtils::ShouldResistFingerprinting(
           aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
-    return 0;
+    CSSIntSize size = bc->GetTopInnerSizeForRFP();
+    return nsRFPService::ViewportSizeToOrientationType(size.width, size.height);
   }
+  return orientation;
+}
 
+uint16_t ScreenOrientation::GetAngle(CallerType aCallerType,
+                                     ErrorResult& aRv) const {
   Document* doc = GetResponsibleDocument();
   BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
   if (!bc) {
@@ -670,7 +678,13 @@ uint16_t ScreenOrientation::GetAngle(CallerType aCallerType,
     return 0;
   }
 
-  return bc->GetCurrentOrientationAngle();
+  uint16_t angle = static_cast<uint16_t>(bc->GetCurrentOrientationAngle());
+  if (nsContentUtils::ShouldResistFingerprinting(
+          aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
+    CSSIntSize size = bc->GetTopInnerSizeForRFP();
+    return nsRFPService::ViewportSizeToAngle(size.width, size.height);
+  }
+  return angle;
 }
 
 ScreenOrientation::LockPermission


=====================================
dom/base/nsGlobalWindowInner.cpp
=====================================
@@ -7306,11 +7306,13 @@ void nsGlobalWindowInner::InitWasOffline() { mWasOffline = NS_IsOffline(); }
 int16_t nsGlobalWindowInner::Orientation(CallerType aCallerType) {
   // GetOrientationAngle() returns 0, 90, 180 or 270.
   // window.orientation returns -90, 0, 90 or 180.
+  uint16_t screenAngle = Screen()->GetOrientationAngle();
   if (nsIGlobalObject::ShouldResistFingerprinting(
           aCallerType, RFPTarget::ScreenOrientation)) {
-    return 0;
+    CSSIntSize size = mBrowsingContext->GetTopInnerSizeForRFP();
+    screenAngle = nsRFPService::ViewportSizeToAngle(size.width, size.height);
   }
-  int16_t angle = AssertedCast<int16_t>(Screen()->GetOrientationAngle());
+  int16_t angle = AssertedCast<int16_t>(screenAngle);
   return angle <= 180 ? angle : angle - 360;
 }
 


=====================================
dom/base/test/chrome/bug418986-1.js
=====================================
@@ -32,9 +32,6 @@ var test = function (isContent) {
     ["screen.availTop", 0],
     ["screen.width", "outerWidth"],
     ["screen.height", "outerHeight"],
-    ["screen.orientation.type", "'landscape-primary'"],
-    ["screen.orientation.angle", 0],
-    ["screen.mozOrientation", "'landscape-primary'"],
     ["devicePixelRatio", 2],
   ];
 


=====================================
hal/android/AndroidHal.cpp
=====================================
@@ -79,19 +79,20 @@ void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo) {
 
 static bool IsSupportedScreenOrientation(hal::ScreenOrientation aOrientation) {
   // The Android backend only supports these orientations.
-  static constexpr ScreenOrientation kSupportedOrientations[] = {
-      ScreenOrientation::PortraitPrimary,
-      ScreenOrientation::PortraitSecondary,
-      ScreenOrientation::PortraitPrimary | ScreenOrientation::PortraitSecondary,
-      ScreenOrientation::LandscapePrimary,
-      ScreenOrientation::LandscapeSecondary,
-      ScreenOrientation::LandscapePrimary |
-          ScreenOrientation::LandscapeSecondary,
-      ScreenOrientation::PortraitPrimary |
-          ScreenOrientation::PortraitSecondary |
-          ScreenOrientation::LandscapePrimary |
-          ScreenOrientation::LandscapeSecondary,
-      ScreenOrientation::Default,
+  static constexpr hal::ScreenOrientation kSupportedOrientations[] = {
+      hal::ScreenOrientation::PortraitPrimary,
+      hal::ScreenOrientation::PortraitSecondary,
+      hal::ScreenOrientation::PortraitPrimary |
+          hal::ScreenOrientation::PortraitSecondary,
+      hal::ScreenOrientation::LandscapePrimary,
+      hal::ScreenOrientation::LandscapeSecondary,
+      hal::ScreenOrientation::LandscapePrimary |
+          hal::ScreenOrientation::LandscapeSecondary,
+      hal::ScreenOrientation::PortraitPrimary |
+          hal::ScreenOrientation::PortraitSecondary |
+          hal::ScreenOrientation::LandscapePrimary |
+          hal::ScreenOrientation::LandscapeSecondary,
+      hal::ScreenOrientation::Default,
   };
   for (auto supportedOrientation : kSupportedOrientations) {
     if (aOrientation == supportedOrientation) {


=====================================
toolkit/components/resistfingerprinting/nsRFPService.cpp
=====================================
@@ -2284,3 +2284,34 @@ Maybe<RFPTarget> nsRFPService::GetOverriddenFingerprintingSettingsForURI(
 
   return result;
 }
+
+/* static */
+uint16_t nsRFPService::ViewportSizeToAngle(int32_t aWidth, int32_t aHeight) {
+#ifdef MOZ_WIDGET_ANDROID
+  bool neutral = aHeight >= aWidth;
+#else
+  bool neutral = aWidth >= aHeight;
+#endif
+  if (neutral) {
+    return 0;
+  }
+  return 90;
+}
+
+/* static */
+dom::OrientationType nsRFPService::ViewportSizeToOrientationType(
+    int32_t aWidth, int32_t aHeight) {
+  if (aWidth >= aHeight) {
+    return dom::OrientationType::Landscape_primary;
+  }
+  return dom::OrientationType::Portrait_primary;
+}
+
+/* static */
+dom::OrientationType nsRFPService::GetDefaultOrientationType() {
+#ifdef MOZ_WIDGET_ANDROID
+  return dom::OrientationType::Portrait_primary;
+#else
+  return dom::OrientationType::Landscape_primary;
+#endif
+}


=====================================
toolkit/components/resistfingerprinting/nsRFPService.h
=====================================
@@ -14,6 +14,7 @@
 #include "mozilla/ContentBlockingLog.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/TypedEnumBits.h"
+#include "mozilla/dom/ScreenOrientationBinding.h"
 #include "js/RealmOptions.h"
 #include "nsHashtablesFwd.h"
 #include "nsICookieJarSettings.h"
@@ -368,6 +369,16 @@ class nsRFPService final : public nsIObserver, public nsIRFPService {
   static bool CheckSuspiciousFingerprintingActivity(
       nsTArray<ContentBlockingLog::LogEntry>& aLogs);
 
+  // Converts the viewport size to the angle.
+  static uint16_t ViewportSizeToAngle(int32_t aWidth, int32_t aHeight);
+
+  // Converts the viewport size to the orientation type.
+  static dom::OrientationType ViewportSizeToOrientationType(int32_t aWidth,
+                                                            int32_t aHeight);
+
+  // Returns the default orientation type for the given platform.
+  static dom::OrientationType GetDefaultOrientationType();
+
  private:
   nsresult Init();
 



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/dbdddf48102fd0baa659405d478195c60c4638de...6112a1c356ecc5f544014759dbb702b9894ee689

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/dbdddf48102fd0baa659405d478195c60c4638de...6112a1c356ecc5f544014759dbb702b9894ee689
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20241002/8795cabd/attachment-0001.htm>


More information about the tbb-commits mailing list