File: fullscreen.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (207 lines) | stat: -rw-r--r-- 8,164 bytes parent folder | download | duplicates (6)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 *           (C) 2001 Dirk Mueller (mueller@kde.org)
 *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All
 * rights reserved.
 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
 * (http://www.torchmobile.com/)
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
 * Copyright (C) 2013 Google Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FULLSCREEN_FULLSCREEN_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FULLSCREEN_FULLSCREEN_H_

#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen_request_type.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class LocalDOMWindow;
class FullscreenOptions;

// Internal type used when checking RequestFullscreen conditions.
enum class RequestFullscreenError {
  kNone = 0,
  kElementTypeNotHTMLNorSVG,
  kElementTypeDialog,
  kElementNotConnected,
  kElementOpenAsPopover,
  kDisallowedByPermissionsPolicy,
  kFullscreenNotSupported,
  kPermissionCheckFailed,
  kDocumentIncorrect,
  kNotGranted,
};

// The Fullscreen class implements most of the Fullscreen API Standard,
// https://fullscreen.spec.whatwg.org/, especially its algorithms. It is a
// Document supplement as each document has some fullscreen state, and to
// actually enter and exit fullscreen it (indirectly) uses FullscreenController.
class CORE_EXPORT Fullscreen final : public GarbageCollected<Fullscreen>,
                                     public Supplement<LocalDOMWindow>,
                                     public ExecutionContextLifecycleObserver {
 public:
  static const char kSupplementName[];

  explicit Fullscreen(LocalDOMWindow&);
  ~Fullscreen() override;

  static Element* FullscreenElementFrom(Document&);
  static Element* FullscreenElementForBindingFrom(TreeScope&);
  // Returns true if the Element is the topmost element in its document's top
  // layer whose fullscreen flag is set.
  static bool IsFullscreenElement(const Element&);
  static bool IsInFullscreenElementStack(const Element&);
  static bool HasFullscreenElements();
  // Returns true if the Element's fullscreen flag is set. A Document may have
  // multiple elements with the fullscreen flag set.
  static bool IsFullscreenFlagSetFor(const Element&);

  static void RequestFullscreen(Element&);
  static ScriptPromise<IDLUndefined> RequestFullscreen(
      Element&,
      const FullscreenOptions*,
      FullscreenRequestType,
      ScriptState* state = nullptr,
      ExceptionState* exception_state = nullptr);

  static void FullyExitFullscreen(Document&, bool ua_originated = false);
  static ScriptPromise<IDLUndefined> ExitFullscreen(
      Document&,
      ScriptState* state = nullptr,
      ExceptionState* exception_state = nullptr,
      bool ua_originated = false);

  static bool FullscreenEnabled(
      Document&,
      ReportOptions report_on_failure = ReportOptions::kDoNotReport);

  // Called by FullscreenController to notify that we've entered or exited
  // fullscreen. All frames are notified, so there may be no pending request.
  static void DidResolveEnterFullscreenRequest(Document&, bool granted);
  static void DidExitFullscreen(Document&);

  static void DidUpdateSize(Element&);

  static void ElementRemoved(Element&);

  // ExecutionContextLifecycleObserver:
  void ContextDestroyed() override;

  void Trace(Visitor*) const override;

  base::TimeTicks block_automatic_fullscreen_until() const {
    return block_automatic_fullscreen_until_;
  }

 private:
  static Fullscreen& From(LocalDOMWindow&);

  // Run by RequestFullscreen to check conditions and invoke `callback` with any
  // error or `kNone` to proceed. The callback may be invoked asynchronously to
  // check permission when requests do not have transient user activation, etc.
  static void EnforceRequestFullscreenConditions(
      Element& pending,
      Document& document,
      base::OnceCallback<void(RequestFullscreenError)> callback);

  // Run after EnforceRequestFullscreenConditions checks for any `error`.
  static void ContinueRequestFullscreenAfterConditionsEnforcement(
      Element* pending,
      FullscreenRequestType request_type,
      const FullscreenOptions* options,
      ScriptPromiseResolver<IDLUndefined>* resolver,
      RequestFullscreenError error);

  static void ContinueRequestFullscreen(
      Document&,
      Element&,
      FullscreenRequestType,
      const FullscreenOptions*,
      ScriptPromiseResolver<IDLUndefined>* resolver,
      RequestFullscreenError error);

  static void ContinueExitFullscreen(
      Document*,
      ScriptPromiseResolver<IDLUndefined>* resolver,
      bool resize);

  void FullscreenElementChanged(Element* old_element,
                                Element* new_element,
                                FullscreenRequestType new_request_type);

  // Stores the pending request, promise and the type for executing
  // the asynchronous portion of the request.
  class PendingRequest : public GarbageCollected<PendingRequest> {
   public:
    PendingRequest(Element* element,
                   FullscreenRequestType type,
                   const FullscreenOptions* options,
                   ScriptPromiseResolver<IDLUndefined>* resolver);
    PendingRequest(const PendingRequest&) = delete;
    PendingRequest& operator=(const PendingRequest&) = delete;
    virtual ~PendingRequest();
    virtual void Trace(Visitor* visitor) const;

    Element* element() { return element_.Get(); }
    FullscreenRequestType type() { return type_; }
    const FullscreenOptions* options() { return options_.Get(); }
    ScriptPromiseResolver<IDLUndefined>* resolver() { return resolver_.Get(); }

   private:
    Member<Element> element_;
    FullscreenRequestType type_;
    Member<const FullscreenOptions> options_;
    Member<ScriptPromiseResolver<IDLUndefined>> resolver_;
  };
  using PendingRequests = HeapVector<Member<PendingRequest>>;
  PendingRequests pending_requests_;

  using PendingExit = ScriptPromiseResolver<IDLUndefined>;
  using PendingExits = HeapVector<Member<PendingExit>>;
  PendingExits pending_exits_;

  // Used to block automatic fullscreen for a short time after exit.
  base::TimeTicks block_automatic_fullscreen_until_;
};

inline bool Fullscreen::IsFullscreenElement(const Element& element) {
  if (HasFullscreenElements() &&
      FullscreenElementFrom(element.GetDocument()) == &element) [[unlikely]] {
    return true;
  }
  return false;
}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FULLSCREEN_FULLSCREEN_H_