tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsScreen.h (3859B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 #ifndef nsScreen_h___
      7 #define nsScreen_h___
      8 
      9 #include "Units.h"
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 #include "mozilla/StaticPrefs_media.h"
     12 #include "mozilla/dom/ScreenBinding.h"
     13 #include "mozilla/dom/ScreenLuminance.h"
     14 #include "mozilla/dom/ScreenOrientation.h"
     15 
     16 class nsDeviceContext;
     17 
     18 namespace mozilla {
     19 enum class RFPTarget : uint64_t;
     20 }
     21 
     22 // Script "screen" object
     23 class nsScreen : public mozilla::DOMEventTargetHelper {
     24 public:
     25  explicit nsScreen(nsPIDOMWindowInner* aWindow);
     26 
     27  NS_DECL_ISUPPORTS_INHERITED
     28  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsScreen,
     29                                           mozilla::DOMEventTargetHelper)
     30 
     31  nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
     32 
     33  nsPIDOMWindowOuter* GetOuter() const;
     34 
     35  int32_t Top() { return GetRect().y; }
     36  int32_t Left() { return GetRect().x; }
     37  int32_t Width() { return GetRect().Width(); }
     38  int32_t Height() { return GetRect().Height(); }
     39 
     40  int32_t AvailTop() { return GetAvailRect().y; }
     41  int32_t AvailLeft() { return GetAvailRect().x; }
     42  int32_t AvailWidth() { return GetAvailRect().Width(); }
     43  int32_t AvailHeight() { return GetAvailRect().Height(); }
     44 
     45  int32_t PixelDepth();
     46  int32_t ColorDepth() { return PixelDepth(); }
     47 
     48  // Media Capabilities extension
     49  mozilla::dom::ScreenColorGamut ColorGamut() const {
     50    return mozilla::dom::ScreenColorGamut::Srgb;
     51  }
     52 
     53  already_AddRefed<mozilla::dom::ScreenLuminance> GetLuminance() const {
     54    return nullptr;
     55  }
     56 
     57  static bool MediaCapabilitiesEnabled(JSContext* aCx, JSObject* aGlobal) {
     58    return mozilla::StaticPrefs::media_media_capabilities_screen_enabled();
     59  }
     60 
     61  IMPL_EVENT_HANDLER(change);
     62 
     63  uint16_t GetOrientationAngle() const;
     64  mozilla::hal::ScreenOrientation GetOrientationType() const;
     65 
     66  // Deprecated
     67  void GetMozOrientation(nsString& aOrientation,
     68                         mozilla::dom::CallerType aCallerType) const;
     69 
     70  IMPL_EVENT_HANDLER(mozorientationchange)
     71 
     72  // This function is deprecated, use ScreenOrientation API instead.
     73  bool MozLockOrientation(const nsAString&) { return false; };
     74  bool MozLockOrientation(const mozilla::dom::Sequence<nsString>&) {
     75    return false;
     76  }
     77  void MozUnlockOrientation() {}
     78 
     79  virtual JSObject* WrapObject(JSContext* aCx,
     80                               JS::Handle<JSObject*> aGivenProto) override;
     81 
     82  mozilla::dom::ScreenOrientation* Orientation() const;
     83  mozilla::dom::ScreenOrientation* GetOrientationIfExists() const {
     84    return mScreenOrientation.get();
     85  }
     86 
     87  bool IsScreen() const override { return true; }
     88 
     89 protected:
     90  nsDeviceContext* GetDeviceContext() const;
     91  mozilla::CSSIntRect GetRect();
     92  mozilla::CSSIntRect GetAvailRect();
     93  mozilla::CSSIntRect GetTopWindowInnerRectForRFP();
     94  bool IsFullscreen() const;
     95 
     96 private:
     97  virtual ~nsScreen();
     98 
     99  bool ShouldResistFingerprinting(mozilla::RFPTarget aTarget) const;
    100 
    101  mozilla::dom::Document* TopContentDocumentInRDMPane() const;
    102 
    103  RefPtr<mozilla::dom::ScreenOrientation> mScreenOrientation;
    104 };
    105 
    106 namespace mozilla::dom {
    107 
    108 inline nsScreen* EventTarget::GetAsScreen() {
    109  return IsScreen() ? AsScreen() : nullptr;
    110 }
    111 
    112 inline const nsScreen* EventTarget::GetAsScreen() const {
    113  return IsScreen() ? AsScreen() : nullptr;
    114 }
    115 
    116 inline nsScreen* EventTarget::AsScreen() {
    117  MOZ_DIAGNOSTIC_ASSERT(IsScreen());
    118  return static_cast<nsScreen*>(this);
    119 }
    120 
    121 inline const nsScreen* EventTarget::AsScreen() const {
    122  MOZ_DIAGNOSTIC_ASSERT(IsScreen());
    123  return static_cast<const nsScreen*>(this);
    124 }
    125 
    126 }  // namespace mozilla::dom
    127 
    128 #endif /* nsScreen_h___ */