屏幕分辨率|尺寸|颜色深度指纹

一、前端通过window.screen接口获取屏幕分辨率 尺寸 颜色深度,横屏竖屏信息。 

二、window.screen c++接口实现:

1、third_party\blink\renderer\core\frame\screen.idl

// https://drafts.csswg.org/cssom-view/#the-screen-interface

[
    Exposed=Window
] interface Screen : EventTarget {
    [HighEntropy=Direct, Measure] readonly attribute long availWidth;
    [HighEntropy=Direct, Measure] readonly attribute long availHeight;
    [HighEntropy=Direct, Measure] readonly attribute long width;
    [HighEntropy=Direct, Measure] readonly attribute long height;
    [HighEntropy=Direct, Measure] readonly attribute unsigned long colorDepth;
    // pixelDepth() is an alias for colorDepth(), no need to instrument it twice.
    [HighEntropy, Measure] readonly attribute unsigned long pixelDepth;

    // Non-standard
    [HighEntropy=Direct, Measure] readonly attribute long availLeft;
    [HighEntropy=Direct, Measure] readonly attribute long availTop;

    // Fired when the window’s screen or that screen's attributes change.
    // https://w3c.github.io/window-placement/
    [SecureContext, HighEntropy, MeasureAs=WindowScreenChange] attribute EventHandler onchange;

    // Whether the device’s visual output extends over multiple screens.
    // https://w3c.github.io/window-placement/
    [SecureContext, HighEntropy=Direct, MeasureAs=WindowScreenIsExtended] readonly attribute boolean isExtended;
};

2、接口实现c++

third_party\blink\renderer\core\frame\screen.h

third_party\blink\renderer\core\frame\screen.cc

namespace display {
struct ScreenInfo;
}

namespace blink {

class LocalDOMWindow;

class CORE_EXPORT Screen : public EventTarget,
                           public ExecutionContextClient,
                           public Supplementable<Screen> {
  DEFINE_WRAPPERTYPEINFO();

 public:
  Screen(LocalDOMWindow*, int64_t display_id);

  static bool AreWebExposedScreenPropertiesEqual(
      const display::ScreenInfo& prev,
      const display::ScreenInfo& current);

  int height() const;
  int width() const;
  unsigned colorDepth() const;
  unsigned pixelDepth() const;
  int availLeft() const;
  int availTop() const;
  int availHeight() const;
  int availWidth() const;

  void Trace(Visitor*) const override;

  // EventTarget:
  const WTF::AtomicString& InterfaceName() const override;
  ExecutionContext* GetExecutionContext() const override;

  // Whether the device’s visual output extends over multiple screens.
  // https://w3c.github.io/window-placement/
  bool isExtended() const;
  // Fired when the window’s screen or that screen's attributes change.
  // https://w3c.github.io/window-placement/
  DEFINE_ATTRIBUTE_EVENT_LISTENER(change, kChange)

  // Not web-exposed; for internal usage only.
  static constexpr int64_t kInvalidDisplayId = -1;
  int64_t DisplayId() const { return display_id_; }
  void UpdateDisplayId(int64_t display_id) { display_id_ = display_id; }

 protected:
  // Helpers to access screen information.
  gfx::Rect GetRect(bool available) const;
  const display::ScreenInfo& GetScreenInfo() const;

  // The internal id of the underlying display, to support multi-screen devices.
  int64_t display_id_;
};

}  // namespace blink

三、总结:

修改屏幕信息指纹只需要在screen.cc文件种修改即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值