Verified Commit 6311a7c9 authored by Fatih's avatar Fatih Committed by Pier Angelo Vendrame
Browse files

Bug 1607032: Spoof screen orientation and angle to primary values. r=tjr,geckoview-reviewers,owlish

parent 0fa3ced9
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -626,7 +626,7 @@ void ScreenOrientation::CleanupFullscreenListener() {
OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const {
  if (nsContentUtils::ShouldResistFingerprinting(
          aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
    return OrientationType::Landscape_primary;
    return nsRFPService::OrientationSecondaryToPrimary(mType);
  }
  return mType;
}
@@ -634,18 +634,13 @@ OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const {
uint16_t ScreenOrientation::DeviceAngle(CallerType aCallerType) const {
  if (nsContentUtils::ShouldResistFingerprinting(
          aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
    return 0;
    return nsRFPService::OrientationSecondaryToPrimary(mAngle);
  }
  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 +648,16 @@ 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;
    return nsRFPService::OrientationSecondaryToPrimary(orientation);
  }
  return orientation;
}

uint16_t ScreenOrientation::GetAngle(CallerType aCallerType,
                                     ErrorResult& aRv) const {
  Document* doc = GetResponsibleDocument();
  BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
  if (!bc) {
@@ -670,7 +665,12 @@ 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)) {
    return nsRFPService::OrientationSecondaryToPrimary(angle);
  }
  return angle;
}

ScreenOrientation::LockPermission
+3 −2
Original line number Diff line number Diff line
@@ -7306,11 +7306,12 @@ 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;
    screenAngle = nsRFPService::OrientationSecondaryToPrimary(screenAngle);
  }
  int16_t angle = AssertedCast<int16_t>(Screen()->GetOrientationAngle());
  int16_t angle = AssertedCast<int16_t>(screenAngle);
  return angle <= 180 ? angle : angle - 360;
}

+0 −3
Original line number Diff line number Diff line
@@ -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],
  ];

+14 −13
Original line number Diff line number Diff line
@@ -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) {
+25 −0
Original line number Diff line number Diff line
@@ -2279,3 +2279,28 @@ Maybe<RFPTarget> nsRFPService::GetOverriddenFingerprintingSettingsForURI(

  return result;
}

/* static */
dom::OrientationType nsRFPService::OrientationSecondaryToPrimary(
    dom::OrientationType aOrientation) {
  switch (aOrientation) {
    case dom::OrientationType::Landscape_secondary:
      return dom::OrientationType::Landscape_primary;
    case dom::OrientationType::Portrait_secondary:
      return dom::OrientationType::Portrait_primary;
    default:
      return aOrientation;
  }
}

/* static */
uint16_t nsRFPService::OrientationSecondaryToPrimary(uint16_t aAngle) {
  switch (aAngle) {
    case 180:
      return 0;
    case 270:
      return 90;
    default:
      return aAngle;
  }
}
Loading