/work/obj-fuzz/dist/include/mozilla/FullscreenChange.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 https://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* |
8 | | * Struct for holding fullscreen request. |
9 | | */ |
10 | | |
11 | | #ifndef mozilla_FullscreenRequest_h |
12 | | #define mozilla_FullscreenRequest_h |
13 | | |
14 | | #include "mozilla/LinkedList.h" |
15 | | #include "mozilla/PendingFullscreenEvent.h" |
16 | | #include "mozilla/UniquePtr.h" |
17 | | #include "mozilla/dom/Element.h" |
18 | | #include "mozilla/dom/Promise.h" |
19 | | #include "nsIDocument.h" |
20 | | #include "nsIScriptError.h" |
21 | | |
22 | | namespace mozilla { |
23 | | |
24 | | class FullscreenChange : public LinkedListElement<FullscreenChange> |
25 | | { |
26 | | public: |
27 | | FullscreenChange(const FullscreenChange&) = delete; |
28 | | |
29 | | enum ChangeType |
30 | | { |
31 | | eEnter, |
32 | | eExit, |
33 | | }; |
34 | | |
35 | 0 | ChangeType Type() const { return mType; } |
36 | 0 | nsIDocument* Document() const { return mDocument; } |
37 | 0 | dom::Promise* GetPromise() const { return mPromise; } |
38 | | |
39 | | void MayResolvePromise() const |
40 | 0 | { |
41 | 0 | if (mPromise) { |
42 | 0 | MOZ_ASSERT(mPromise->State() == Promise::PromiseState::Pending); |
43 | 0 | mPromise->MaybeResolveWithUndefined(); |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | void MayRejectPromise() const |
48 | 0 | { |
49 | 0 | if (mPromise) { |
50 | 0 | MOZ_ASSERT(mPromise->State() == Promise::PromiseState::Pending); |
51 | 0 | mPromise->MaybeReject(NS_ERROR_DOM_TYPE_ERR); |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | | protected: |
56 | | typedef dom::Promise Promise; |
57 | | |
58 | | FullscreenChange(ChangeType aType, nsIDocument* aDocument, |
59 | | already_AddRefed<Promise> aPromise) |
60 | | : mType(aType) |
61 | | , mDocument(aDocument) |
62 | | , mPromise(aPromise) |
63 | 0 | { |
64 | 0 | MOZ_ASSERT(aDocument); |
65 | 0 | } |
66 | | |
67 | | ~FullscreenChange() |
68 | 0 | { |
69 | 0 | MOZ_ASSERT_IF(mPromise, |
70 | 0 | mPromise->State() != Promise::PromiseState::Pending); |
71 | 0 | } |
72 | | |
73 | | private: |
74 | | ChangeType mType; |
75 | | nsCOMPtr<nsIDocument> mDocument; |
76 | | RefPtr<Promise> mPromise; |
77 | | }; |
78 | | |
79 | | class FullscreenRequest : public FullscreenChange |
80 | | { |
81 | | public: |
82 | | static const ChangeType kType = eEnter; |
83 | | |
84 | | static UniquePtr<FullscreenRequest> Create(Element* aElement, |
85 | | dom::CallerType aCallerType, |
86 | | ErrorResult& aRv) |
87 | 0 | { |
88 | 0 | RefPtr<Promise> promise = Promise::Create(aElement->GetOwnerGlobal(), aRv); |
89 | 0 | return WrapUnique(new FullscreenRequest(aElement, promise.forget(), |
90 | 0 | aCallerType, true)); |
91 | 0 | } |
92 | | |
93 | | static UniquePtr<FullscreenRequest> CreateForRemote(Element* aElement) |
94 | 0 | { |
95 | 0 | return WrapUnique(new FullscreenRequest(aElement, nullptr, |
96 | 0 | dom::CallerType::NonSystem, |
97 | 0 | false)); |
98 | 0 | } |
99 | | |
100 | | ~FullscreenRequest() |
101 | 0 | { |
102 | 0 | MOZ_COUNT_DTOR(FullscreenRequest); |
103 | 0 | } |
104 | | |
105 | 0 | dom::Element* Element() const { return mElement; } |
106 | | |
107 | | // Reject the fullscreen request with the given reason. |
108 | | // It will dispatch the fullscreenerror event. |
109 | | void Reject(const char* aReason) const |
110 | 0 | { |
111 | 0 | if (nsPresContext* presContext = Document()->GetPresContext()) { |
112 | 0 | auto pendingEvent = MakeUnique<PendingFullscreenEvent>( |
113 | 0 | FullscreenEventType::Error, Document(), mElement); |
114 | 0 | presContext->RefreshDriver()-> |
115 | 0 | ScheduleFullscreenEvent(std::move(pendingEvent)); |
116 | 0 | } |
117 | 0 | MayRejectPromise(); |
118 | 0 | nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, |
119 | 0 | NS_LITERAL_CSTRING("DOM"), |
120 | 0 | Document(), |
121 | 0 | nsContentUtils::eDOM_PROPERTIES, |
122 | 0 | aReason); |
123 | 0 | } |
124 | | |
125 | | private: |
126 | | RefPtr<dom::Element> mElement; |
127 | | |
128 | | public: |
129 | | // This value should be true if the fullscreen request is |
130 | | // originated from system code. |
131 | | const dom::CallerType mCallerType; |
132 | | // This value denotes whether we should trigger a NewOrigin event if |
133 | | // requesting fullscreen in its document causes the origin which is |
134 | | // fullscreen to change. We may want *not* to trigger that event if |
135 | | // we're calling RequestFullscreen() as part of a continuation of a |
136 | | // request in a subdocument in different process, whereupon the caller |
137 | | // need to send some notification itself with the real origin. |
138 | | const bool mShouldNotifyNewOrigin; |
139 | | |
140 | | private: |
141 | | FullscreenRequest(dom::Element* aElement, |
142 | | already_AddRefed<dom::Promise> aPromise, |
143 | | dom::CallerType aCallerType, |
144 | | bool aShouldNotifyNewOrigin) |
145 | | : FullscreenChange(kType, aElement->OwnerDoc(), std::move(aPromise)) |
146 | | , mElement(aElement) |
147 | | , mCallerType(aCallerType) |
148 | | , mShouldNotifyNewOrigin(aShouldNotifyNewOrigin) |
149 | 0 | { |
150 | 0 | MOZ_COUNT_CTOR(FullscreenRequest); |
151 | 0 | } |
152 | | }; |
153 | | |
154 | | class FullscreenExit : public FullscreenChange |
155 | | { |
156 | | public: |
157 | | static const ChangeType kType = eExit; |
158 | | |
159 | | static UniquePtr<FullscreenExit> Create(nsIDocument* aDoc, ErrorResult& aRv) |
160 | 0 | { |
161 | 0 | RefPtr<Promise> promise = Promise::Create(aDoc->GetOwnerGlobal(), aRv); |
162 | 0 | return WrapUnique(new FullscreenExit(aDoc, promise.forget())); |
163 | 0 | } |
164 | | |
165 | | static UniquePtr<FullscreenExit> CreateForRemote(nsIDocument* aDoc) |
166 | 0 | { |
167 | 0 | return WrapUnique(new FullscreenExit(aDoc, nullptr)); |
168 | 0 | } |
169 | | |
170 | | ~FullscreenExit() |
171 | 0 | { |
172 | 0 | MOZ_COUNT_DTOR(FullscreenExit); |
173 | 0 | } |
174 | | |
175 | | private: |
176 | | FullscreenExit(nsIDocument* aDoc, already_AddRefed<Promise> aPromise) |
177 | | : FullscreenChange(kType, aDoc, std::move(aPromise)) |
178 | 0 | { |
179 | 0 | MOZ_COUNT_CTOR(FullscreenExit); |
180 | 0 | } |
181 | | }; |
182 | | |
183 | | } // namespace mozilla |
184 | | |
185 | | #endif // mozilla_FullscreenRequest_h |