morgan pushed to branch tor-browser-128.3.0esr-14.0-1 at The Tor Project / Applications / Tor Browser
Commits:
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:
... | ... | @@ -626,7 +626,13 @@ void ScreenOrientation::CleanupFullscreenListener() { |
626 | 626 | OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const {
|
627 | 627 | if (nsContentUtils::ShouldResistFingerprinting(
|
628 | 628 | aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
|
629 | - return OrientationType::Landscape_primary;
|
|
629 | + Document* doc = GetResponsibleDocument();
|
|
630 | + BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
|
|
631 | + if (!bc) {
|
|
632 | + return nsRFPService::GetDefaultOrientationType();
|
|
633 | + }
|
|
634 | + CSSIntSize size = bc->GetTopInnerSizeForRFP();
|
|
635 | + return nsRFPService::ViewportSizeToOrientationType(size.width, size.height);
|
|
630 | 636 | }
|
631 | 637 | return mType;
|
632 | 638 | }
|
... | ... | @@ -634,18 +640,19 @@ OrientationType ScreenOrientation::DeviceType(CallerType aCallerType) const { |
634 | 640 | uint16_t ScreenOrientation::DeviceAngle(CallerType aCallerType) const {
|
635 | 641 | if (nsContentUtils::ShouldResistFingerprinting(
|
636 | 642 | aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
|
637 | - return 0;
|
|
643 | + Document* doc = GetResponsibleDocument();
|
|
644 | + BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
|
|
645 | + if (!bc) {
|
|
646 | + return 0;
|
|
647 | + }
|
|
648 | + CSSIntSize size = bc->GetTopInnerSizeForRFP();
|
|
649 | + return nsRFPService::ViewportSizeToAngle(size.width, size.height);
|
|
638 | 650 | }
|
639 | 651 | return mAngle;
|
640 | 652 | }
|
641 | 653 | |
642 | 654 | OrientationType ScreenOrientation::GetType(CallerType aCallerType,
|
643 | 655 | ErrorResult& aRv) const {
|
644 | - if (nsContentUtils::ShouldResistFingerprinting(
|
|
645 | - aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
|
|
646 | - return OrientationType::Landscape_primary;
|
|
647 | - }
|
|
648 | - |
|
649 | 656 | Document* doc = GetResponsibleDocument();
|
650 | 657 | BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
|
651 | 658 | if (!bc) {
|
... | ... | @@ -653,16 +660,17 @@ OrientationType ScreenOrientation::GetType(CallerType aCallerType, |
653 | 660 | return OrientationType::Portrait_primary;
|
654 | 661 | }
|
655 | 662 | |
656 | - return bc->GetCurrentOrientationType();
|
|
657 | -}
|
|
658 | - |
|
659 | -uint16_t ScreenOrientation::GetAngle(CallerType aCallerType,
|
|
660 | - ErrorResult& aRv) const {
|
|
663 | + OrientationType orientation = bc->GetCurrentOrientationType();
|
|
661 | 664 | if (nsContentUtils::ShouldResistFingerprinting(
|
662 | 665 | aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
|
663 | - return 0;
|
|
666 | + CSSIntSize size = bc->GetTopInnerSizeForRFP();
|
|
667 | + return nsRFPService::ViewportSizeToOrientationType(size.width, size.height);
|
|
664 | 668 | }
|
669 | + return orientation;
|
|
670 | +}
|
|
665 | 671 | |
672 | +uint16_t ScreenOrientation::GetAngle(CallerType aCallerType,
|
|
673 | + ErrorResult& aRv) const {
|
|
666 | 674 | Document* doc = GetResponsibleDocument();
|
667 | 675 | BrowsingContext* bc = doc ? doc->GetBrowsingContext() : nullptr;
|
668 | 676 | if (!bc) {
|
... | ... | @@ -670,7 +678,13 @@ uint16_t ScreenOrientation::GetAngle(CallerType aCallerType, |
670 | 678 | return 0;
|
671 | 679 | }
|
672 | 680 | |
673 | - return bc->GetCurrentOrientationAngle();
|
|
681 | + uint16_t angle = static_cast<uint16_t>(bc->GetCurrentOrientationAngle());
|
|
682 | + if (nsContentUtils::ShouldResistFingerprinting(
|
|
683 | + aCallerType, GetOwnerGlobal(), RFPTarget::ScreenOrientation)) {
|
|
684 | + CSSIntSize size = bc->GetTopInnerSizeForRFP();
|
|
685 | + return nsRFPService::ViewportSizeToAngle(size.width, size.height);
|
|
686 | + }
|
|
687 | + return angle;
|
|
674 | 688 | }
|
675 | 689 | |
676 | 690 | ScreenOrientation::LockPermission
|
... | ... | @@ -7306,11 +7306,13 @@ void nsGlobalWindowInner::InitWasOffline() { mWasOffline = NS_IsOffline(); } |
7306 | 7306 | int16_t nsGlobalWindowInner::Orientation(CallerType aCallerType) {
|
7307 | 7307 | // GetOrientationAngle() returns 0, 90, 180 or 270.
|
7308 | 7308 | // window.orientation returns -90, 0, 90 or 180.
|
7309 | + uint16_t screenAngle = Screen()->GetOrientationAngle();
|
|
7309 | 7310 | if (nsIGlobalObject::ShouldResistFingerprinting(
|
7310 | 7311 | aCallerType, RFPTarget::ScreenOrientation)) {
|
7311 | - return 0;
|
|
7312 | + CSSIntSize size = mBrowsingContext->GetTopInnerSizeForRFP();
|
|
7313 | + screenAngle = nsRFPService::ViewportSizeToAngle(size.width, size.height);
|
|
7312 | 7314 | }
|
7313 | - int16_t angle = AssertedCast<int16_t>(Screen()->GetOrientationAngle());
|
|
7315 | + int16_t angle = AssertedCast<int16_t>(screenAngle);
|
|
7314 | 7316 | return angle <= 180 ? angle : angle - 360;
|
7315 | 7317 | }
|
7316 | 7318 |
... | ... | @@ -32,9 +32,6 @@ var test = function (isContent) { |
32 | 32 | ["screen.availTop", 0],
|
33 | 33 | ["screen.width", "outerWidth"],
|
34 | 34 | ["screen.height", "outerHeight"],
|
35 | - ["screen.orientation.type", "'landscape-primary'"],
|
|
36 | - ["screen.orientation.angle", 0],
|
|
37 | - ["screen.mozOrientation", "'landscape-primary'"],
|
|
38 | 35 | ["devicePixelRatio", 2],
|
39 | 36 | ];
|
40 | 37 |
... | ... | @@ -79,19 +79,20 @@ void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo) { |
79 | 79 | |
80 | 80 | static bool IsSupportedScreenOrientation(hal::ScreenOrientation aOrientation) {
|
81 | 81 | // The Android backend only supports these orientations.
|
82 | - static constexpr ScreenOrientation kSupportedOrientations[] = {
|
|
83 | - ScreenOrientation::PortraitPrimary,
|
|
84 | - ScreenOrientation::PortraitSecondary,
|
|
85 | - ScreenOrientation::PortraitPrimary | ScreenOrientation::PortraitSecondary,
|
|
86 | - ScreenOrientation::LandscapePrimary,
|
|
87 | - ScreenOrientation::LandscapeSecondary,
|
|
88 | - ScreenOrientation::LandscapePrimary |
|
|
89 | - ScreenOrientation::LandscapeSecondary,
|
|
90 | - ScreenOrientation::PortraitPrimary |
|
|
91 | - ScreenOrientation::PortraitSecondary |
|
|
92 | - ScreenOrientation::LandscapePrimary |
|
|
93 | - ScreenOrientation::LandscapeSecondary,
|
|
94 | - ScreenOrientation::Default,
|
|
82 | + static constexpr hal::ScreenOrientation kSupportedOrientations[] = {
|
|
83 | + hal::ScreenOrientation::PortraitPrimary,
|
|
84 | + hal::ScreenOrientation::PortraitSecondary,
|
|
85 | + hal::ScreenOrientation::PortraitPrimary |
|
|
86 | + hal::ScreenOrientation::PortraitSecondary,
|
|
87 | + hal::ScreenOrientation::LandscapePrimary,
|
|
88 | + hal::ScreenOrientation::LandscapeSecondary,
|
|
89 | + hal::ScreenOrientation::LandscapePrimary |
|
|
90 | + hal::ScreenOrientation::LandscapeSecondary,
|
|
91 | + hal::ScreenOrientation::PortraitPrimary |
|
|
92 | + hal::ScreenOrientation::PortraitSecondary |
|
|
93 | + hal::ScreenOrientation::LandscapePrimary |
|
|
94 | + hal::ScreenOrientation::LandscapeSecondary,
|
|
95 | + hal::ScreenOrientation::Default,
|
|
95 | 96 | };
|
96 | 97 | for (auto supportedOrientation : kSupportedOrientations) {
|
97 | 98 | if (aOrientation == supportedOrientation) {
|
... | ... | @@ -2284,3 +2284,34 @@ Maybe<RFPTarget> nsRFPService::GetOverriddenFingerprintingSettingsForURI( |
2284 | 2284 | |
2285 | 2285 | return result;
|
2286 | 2286 | }
|
2287 | + |
|
2288 | +/* static */
|
|
2289 | +uint16_t nsRFPService::ViewportSizeToAngle(int32_t aWidth, int32_t aHeight) {
|
|
2290 | +#ifdef MOZ_WIDGET_ANDROID
|
|
2291 | + bool neutral = aHeight >= aWidth;
|
|
2292 | +#else
|
|
2293 | + bool neutral = aWidth >= aHeight;
|
|
2294 | +#endif
|
|
2295 | + if (neutral) {
|
|
2296 | + return 0;
|
|
2297 | + }
|
|
2298 | + return 90;
|
|
2299 | +}
|
|
2300 | + |
|
2301 | +/* static */
|
|
2302 | +dom::OrientationType nsRFPService::ViewportSizeToOrientationType(
|
|
2303 | + int32_t aWidth, int32_t aHeight) {
|
|
2304 | + if (aWidth >= aHeight) {
|
|
2305 | + return dom::OrientationType::Landscape_primary;
|
|
2306 | + }
|
|
2307 | + return dom::OrientationType::Portrait_primary;
|
|
2308 | +}
|
|
2309 | + |
|
2310 | +/* static */
|
|
2311 | +dom::OrientationType nsRFPService::GetDefaultOrientationType() {
|
|
2312 | +#ifdef MOZ_WIDGET_ANDROID
|
|
2313 | + return dom::OrientationType::Portrait_primary;
|
|
2314 | +#else
|
|
2315 | + return dom::OrientationType::Landscape_primary;
|
|
2316 | +#endif
|
|
2317 | +} |
... | ... | @@ -14,6 +14,7 @@ |
14 | 14 | #include "mozilla/ContentBlockingLog.h"
|
15 | 15 | #include "mozilla/gfx/Types.h"
|
16 | 16 | #include "mozilla/TypedEnumBits.h"
|
17 | +#include "mozilla/dom/ScreenOrientationBinding.h"
|
|
17 | 18 | #include "js/RealmOptions.h"
|
18 | 19 | #include "nsHashtablesFwd.h"
|
19 | 20 | #include "nsICookieJarSettings.h"
|
... | ... | @@ -368,6 +369,16 @@ class nsRFPService final : public nsIObserver, public nsIRFPService { |
368 | 369 | static bool CheckSuspiciousFingerprintingActivity(
|
369 | 370 | nsTArray<ContentBlockingLog::LogEntry>& aLogs);
|
370 | 371 | |
372 | + // Converts the viewport size to the angle.
|
|
373 | + static uint16_t ViewportSizeToAngle(int32_t aWidth, int32_t aHeight);
|
|
374 | + |
|
375 | + // Converts the viewport size to the orientation type.
|
|
376 | + static dom::OrientationType ViewportSizeToOrientationType(int32_t aWidth,
|
|
377 | + int32_t aHeight);
|
|
378 | + |
|
379 | + // Returns the default orientation type for the given platform.
|
|
380 | + static dom::OrientationType GetDefaultOrientationType();
|
|
381 | + |
|
371 | 382 | private:
|
372 | 383 | nsresult Init();
|
373 | 384 |