/work/obj-fuzz/dist/include/mozilla/dom/KeyboardEvent.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | #ifndef mozilla_dom_KeyboardEvent_h_ |
8 | | #define mozilla_dom_KeyboardEvent_h_ |
9 | | |
10 | | #include "mozilla/dom/UIEvent.h" |
11 | | #include "mozilla/dom/KeyboardEventBinding.h" |
12 | | #include "mozilla/EventForwards.h" |
13 | | #include "nsRFPService.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | class KeyboardEvent : public UIEvent |
19 | | { |
20 | | public: |
21 | | KeyboardEvent(EventTarget* aOwner, |
22 | | nsPresContext* aPresContext, |
23 | | WidgetKeyboardEvent* aEvent); |
24 | | |
25 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(KeyboardEvent, UIEvent) |
26 | | |
27 | | virtual KeyboardEvent* AsKeyboardEvent() override |
28 | 0 | { |
29 | 0 | return this; |
30 | 0 | } |
31 | | |
32 | | static already_AddRefed<KeyboardEvent> Constructor( |
33 | | const GlobalObject& aGlobal, |
34 | | const nsAString& aType, |
35 | | const KeyboardEventInit& aParam, |
36 | | ErrorResult& aRv); |
37 | | |
38 | | virtual JSObject* |
39 | | WrapObjectInternal(JSContext* aCx, |
40 | | JS::Handle<JSObject*> aGivenProto) override |
41 | 0 | { |
42 | 0 | return KeyboardEvent_Binding::Wrap(aCx, this, aGivenProto); |
43 | 0 | } |
44 | | |
45 | | bool AltKey(CallerType aCallerType = CallerType::System); |
46 | | bool CtrlKey(CallerType aCallerType = CallerType::System); |
47 | | bool ShiftKey(CallerType aCallerType = CallerType::System); |
48 | | bool MetaKey(); |
49 | | |
50 | | bool GetModifierState(const nsAString& aKey, |
51 | | CallerType aCallerType = CallerType::System) |
52 | 0 | { |
53 | 0 | bool modifierState = GetModifierStateInternal(aKey); |
54 | 0 |
|
55 | 0 | if (!ShouldResistFingerprinting(aCallerType)) { |
56 | 0 | return modifierState; |
57 | 0 | } |
58 | 0 | |
59 | 0 | Modifiers modifier = WidgetInputEvent::GetModifier(aKey); |
60 | 0 | return GetSpoofedModifierStates(modifier, modifierState); |
61 | 0 | } |
62 | | |
63 | | bool Repeat(); |
64 | | bool IsComposing(); |
65 | | void GetKey(nsAString& aKey) const; |
66 | | uint32_t CharCode(); |
67 | | uint32_t KeyCode(CallerType aCallerType = CallerType::System); |
68 | | virtual uint32_t Which(CallerType aCallerType = CallerType::System) override; |
69 | | uint32_t Location(); |
70 | | |
71 | | void GetCode(nsAString& aCode, CallerType aCallerType = CallerType::System); |
72 | | void GetInitDict(KeyboardEventInit& aParam); |
73 | | |
74 | | void InitKeyEvent(const nsAString& aType, bool aCanBubble, bool aCancelable, |
75 | | nsGlobalWindowInner* aView, bool aCtrlKey, bool aAltKey, |
76 | | bool aShiftKey, bool aMetaKey, |
77 | | uint32_t aKeyCode, uint32_t aCharCode); |
78 | | |
79 | | void InitKeyboardEvent(const nsAString& aType, |
80 | | bool aCanBubble, bool aCancelable, |
81 | | nsGlobalWindowInner* aView, const nsAString& aKey, |
82 | | uint32_t aLocation, bool aCtrlKey, bool aAltKey, |
83 | | bool aShiftKey, bool aMetaKey, ErrorResult& aRv); |
84 | | |
85 | | protected: |
86 | 0 | ~KeyboardEvent() {} |
87 | | |
88 | | void InitWithKeyboardEventInit(EventTarget* aOwner, |
89 | | const nsAString& aType, |
90 | | const KeyboardEventInit& aParam, |
91 | | ErrorResult& aRv); |
92 | | |
93 | | private: |
94 | | // True, if the instance is created with Constructor(). |
95 | | bool mInitializedByCtor; |
96 | | |
97 | | // If the instance is created with Constructor(), which may have independent |
98 | | // value. mInitializedWhichValue stores it. I.e., this is invalid when |
99 | | // mInitializedByCtor is false. |
100 | | uint32_t mInitializedWhichValue; |
101 | | |
102 | | // This method returns the boolean to indicate whether spoofing keyboard |
103 | | // event for fingerprinting resistance. It will return true when pref |
104 | | // 'privacy.resistFingerprinting' is true and the event target is content. |
105 | | // Otherwise, it will return false. |
106 | | bool ShouldResistFingerprinting(CallerType aCallerType); |
107 | | |
108 | | // This method returns the nsIDocument which is associated with the event |
109 | | // target. |
110 | | already_AddRefed<nsIDocument> GetDocument(); |
111 | | |
112 | | // This method returns the spoofed modifier state of the given modifier key |
113 | | // for fingerprinting resistance. |
114 | | bool GetSpoofedModifierStates(const Modifiers aModifierKey, |
115 | | const bool aRawModifierState); |
116 | | }; |
117 | | |
118 | | } // namespace dom |
119 | | } // namespace mozilla |
120 | | |
121 | | already_AddRefed<mozilla::dom::KeyboardEvent> |
122 | | NS_NewDOMKeyboardEvent(mozilla::dom::EventTarget* aOwner, |
123 | | nsPresContext* aPresContext, |
124 | | mozilla::WidgetKeyboardEvent* aEvent); |
125 | | |
126 | | #endif // mozilla_dom_KeyboardEvent_h_ |