1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/*
* Struct for holding fullscreen request.
*/
#ifndef mozilla_FullscreenRequest_h
#define mozilla_FullscreenRequest_h
#include "mozilla/LinkedList.h"
#include "mozilla/PendingFullscreenEvent.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/Document.h"
#include "nsIScriptError.h"
#include "nsRefreshDriver.h"
namespace mozilla {
class FullscreenChange : public LinkedListElement<FullscreenChange> {
public:
FullscreenChange(const FullscreenChange&) = delete;
enum ChangeType {
eEnter,
eExit,
};
ChangeType Type() const { return mType; }
dom::Document* Document() const { return mDocument; }
dom::Promise* GetPromise() const { return mPromise; }
void MayResolvePromise() const {
if (mPromise) {
MOZ_ASSERT(mPromise->State() == Promise::PromiseState::Pending);
mPromise->MaybeResolveWithUndefined();
}
}
void MayRejectPromise(const nsACString& aMessage) {
if (mPromise) {
MOZ_ASSERT(mPromise->State() == Promise::PromiseState::Pending);
mPromise->MaybeRejectWithTypeError(aMessage);
}
}
template <int N>
void MayRejectPromise(const char (&aMessage)[N]) {
MayRejectPromise(nsLiteralCString(aMessage));
}
protected:
typedef dom::Promise Promise;
FullscreenChange(ChangeType aType, dom::Document* aDocument,
already_AddRefed<Promise> aPromise)
: mType(aType), mDocument(aDocument), mPromise(aPromise) {
MOZ_ASSERT(aDocument);
}
~FullscreenChange() {
MOZ_ASSERT_IF(mPromise,
mPromise->State() != Promise::PromiseState::Pending);
}
private:
ChangeType mType;
nsCOMPtr<dom::Document> mDocument;
RefPtr<Promise> mPromise;
};
class FullscreenRequest : public FullscreenChange {
public:
static const ChangeType kType = eEnter;
static UniquePtr<FullscreenRequest> Create(dom::Element* aElement,
dom::CallerType aCallerType,
ErrorResult& aRv) {
RefPtr<Promise> promise = Promise::Create(aElement->GetOwnerGlobal(), aRv);
return WrapUnique(
new FullscreenRequest(aElement, promise.forget(), aCallerType, true));
}
static UniquePtr<FullscreenRequest> CreateForRemote(dom::Element* aElement) {
return WrapUnique(new FullscreenRequest(aElement, nullptr,
dom::CallerType::NonSystem, false));
}
MOZ_COUNTED_DTOR(FullscreenRequest)
dom::Element* Element() const { return mElement; }
// Reject the fullscreen request with the given reason.
// It will dispatch the fullscreenerror event.
void Reject(const char* aReason) {
if (nsPresContext* presContext = Document()->GetPresContext()) {
auto pendingEvent = MakeUnique<PendingFullscreenEvent>(
FullscreenEventType::Error, Document(), mElement);
presContext->RefreshDriver()->ScheduleFullscreenEvent(
std::move(pendingEvent));
}
MayRejectPromise("Fullscreen request denied");
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns,
Document(), nsContentUtils::eDOM_PROPERTIES,
aReason);
}
private:
RefPtr<dom::Element> mElement;
public:
// This value should be true if the fullscreen request is
// originated from system code.
const dom::CallerType mCallerType;
// This value denotes whether we should trigger a NewOrigin event if
// requesting fullscreen in its document causes the origin which is
// fullscreen to change. We may want *not* to trigger that event if
// we're calling RequestFullscreen() as part of a continuation of a
// request in a subdocument in different process, whereupon the caller
// need to send some notification itself with the real origin.
const bool mShouldNotifyNewOrigin;
private:
FullscreenRequest(dom::Element* aElement,
already_AddRefed<dom::Promise> aPromise,
dom::CallerType aCallerType, bool aShouldNotifyNewOrigin)
: FullscreenChange(kType, aElement->OwnerDoc(), std::move(aPromise)),
mElement(aElement),
mCallerType(aCallerType),
mShouldNotifyNewOrigin(aShouldNotifyNewOrigin) {
MOZ_COUNT_CTOR(FullscreenRequest);
}
};
class FullscreenExit : public FullscreenChange {
public:
static const ChangeType kType = eExit;
static UniquePtr<FullscreenExit> Create(dom::Document* aDoc,
ErrorResult& aRv) {
RefPtr<Promise> promise = Promise::Create(aDoc->GetOwnerGlobal(), aRv);
return WrapUnique(new FullscreenExit(aDoc, promise.forget()));
}
static UniquePtr<FullscreenExit> CreateForRemote(dom::Document* aDoc) {
return WrapUnique(new FullscreenExit(aDoc, nullptr));
}
MOZ_COUNTED_DTOR(FullscreenExit)
private:
FullscreenExit(dom::Document* aDoc, already_AddRefed<Promise> aPromise)
: FullscreenChange(kType, aDoc, std::move(aPromise)) {
MOZ_COUNT_CTOR(FullscreenExit);
}
};
} // namespace mozilla
#endif // mozilla_FullscreenRequest_h
|