Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / vr / XRSystem.h
blob2a49dfb68f883b34114b3de66f40d801d12130e7
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_XRsystem_h_
8 #define mozilla_dom_XRsystem_h_
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/WebXRBinding.h"
12 #include "nsContentPermissionHelper.h"
13 #include "VRManagerChild.h"
15 #include "gfxVR.h"
17 namespace mozilla::dom {
19 struct XRSessionCreationOptions;
21 class IsSessionSupportedRequest {
22 public:
23 IsSessionSupportedRequest(XRSessionMode aSessionMode, Promise* aPromise)
24 : mPromise(aPromise), mSessionMode(aSessionMode) {}
25 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(IsSessionSupportedRequest)
26 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(IsSessionSupportedRequest)
28 RefPtr<Promise> mPromise;
29 XRSessionMode GetSessionMode() const;
31 private:
32 ~IsSessionSupportedRequest() = default;
33 XRSessionMode mSessionMode;
36 class RequestSessionRequest {
37 public:
38 RequestSessionRequest(
39 XRSessionMode aSessionMode, uint32_t aPresentationGroup,
40 Promise* aPromise,
41 const nsTArray<XRReferenceSpaceType>& aRequiredReferenceSpaceTypes,
42 const nsTArray<XRReferenceSpaceType>& aOptionalReferenceSpaceTypes);
43 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(RequestSessionRequest)
44 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(RequestSessionRequest)
45 RefPtr<Promise> mPromise;
47 bool ResolveSupport(
48 const gfx::VRDisplayClient* aDisplay,
49 nsTArray<XRReferenceSpaceType>& aEnabledReferenceSpaceTypes) const;
50 bool IsImmersive() const;
51 bool WantsHardware() const;
52 bool NeedsHardware() const;
53 XRSessionMode GetSessionMode() const;
54 uint32_t GetPresentationGroup() const;
56 private:
57 ~RequestSessionRequest() = default;
58 XRSessionMode mSessionMode;
59 uint32_t mPresentationGroup;
60 nsTArray<XRReferenceSpaceType> mRequiredReferenceSpaceTypes;
61 nsTArray<XRReferenceSpaceType> mOptionalReferenceSpaceTypes;
64 class XRRequestSessionPermissionRequest final
65 : public ContentPermissionRequestBase {
66 public:
67 NS_DECL_ISUPPORTS_INHERITED
68 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XRRequestSessionPermissionRequest,
69 ContentPermissionRequestBase)
71 // nsIContentPermissionRequest
72 NS_IMETHOD Cancel(void) override;
73 NS_IMETHOD Allow(JS::Handle<JS::Value> choices) override;
75 using AllowCallback = std::function<void()>;
76 using AllowAnySiteCallback = std::function<void()>;
77 using CancelCallback = std::function<void()>;
79 static already_AddRefed<XRRequestSessionPermissionRequest> Create(
80 nsPIDOMWindowInner* aWindow, AllowCallback&& aAllowCallback,
81 AllowAnySiteCallback&& aAllowAnySiteCallback,
82 CancelCallback&& aCancelCallback);
84 using AutoGrantDelayPromise = MozPromise<bool, bool, true>;
85 RefPtr<AutoGrantDelayPromise> MaybeDelayAutomaticGrants();
87 private:
88 XRRequestSessionPermissionRequest(
89 nsPIDOMWindowInner* aWindow, nsIPrincipal* aNodePrincipal,
90 AllowCallback&& aAllowCallback,
91 AllowAnySiteCallback&& aAllowAnySiteCallback,
92 CancelCallback&& aCancelCallback);
93 ~XRRequestSessionPermissionRequest();
95 AllowCallback mAllowCallback;
96 AllowAnySiteCallback mAllowAnySiteCallback;
97 CancelCallback mCancelCallback;
98 nsTArray<PermissionRequest> mPermissionRequests;
99 bool mCallbackCalled;
102 class XRSystem final : public DOMEventTargetHelper,
103 public gfx::VRManagerEventObserver {
104 public:
105 NS_DECL_ISUPPORTS_INHERITED
106 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XRSystem, DOMEventTargetHelper)
108 void Shutdown();
109 void SessionEnded(XRSession* aSession);
110 bool FeaturePolicyBlocked() const;
111 bool OnXRPermissionRequestAllow();
112 void OnXRPermissionRequestCancel();
113 bool HasActiveImmersiveSession() const;
115 // WebIDL Boilerplate
116 static already_AddRefed<XRSystem> Create(nsPIDOMWindowInner* aWindow);
117 JSObject* WrapObject(JSContext* aCx,
118 JS::Handle<JSObject*> aGivenProto) override;
120 // WebIDL Members
121 already_AddRefed<Promise> IsSessionSupported(XRSessionMode aMode,
122 ErrorResult& aRv);
123 already_AddRefed<Promise> RequestSession(JSContext* aCx, XRSessionMode aMode,
124 const XRSessionInit& aOptions,
125 CallerType aCallerType,
126 ErrorResult& aRv);
127 IMPL_EVENT_HANDLER(devicechange);
129 // VRManagerEventObserver interface
130 void NotifyVRDisplayMounted(uint32_t aDisplayID) override;
131 void NotifyVRDisplayUnmounted(uint32_t aDisplayID) override;
132 void NotifyVRDisplayConnect(uint32_t aDisplayID) override;
133 void NotifyVRDisplayDisconnect(uint32_t aDisplayID) override;
134 void NotifyVRDisplayPresentChange(uint32_t aDisplayID) override;
135 void NotifyPresentationGenerationChanged(uint32_t aDisplayID) override;
136 void NotifyEnumerationCompleted() override;
137 void NotifyDetectRuntimesCompleted() override;
138 bool GetStopActivityStatus() const override;
140 private:
141 explicit XRSystem(nsPIDOMWindowInner* aWindow);
142 virtual ~XRSystem() = default;
143 void ResolveIsSessionSupportedRequests();
144 void ProcessSessionRequestsWaitingForRuntimeDetection();
145 bool CancelHardwareRequest(RequestSessionRequest* aRequest);
146 void QueueSessionRequestWithEnumeration(RequestSessionRequest* aRequest);
147 void QueueSessionRequestWithoutEnumeration(RequestSessionRequest* aRequest);
148 void ResolveSessionRequestsWithoutHardware();
149 void ResolveSessionRequests(
150 nsTArray<RefPtr<RequestSessionRequest>>& aRequests,
151 const nsTArray<RefPtr<gfx::VRDisplayClient>>& aDisplays);
153 bool mShuttingDown;
154 // https://immersive-web.github.io/webxr/#pending-immersive-session
155 bool mPendingImmersiveSession;
156 // https://immersive-web.github.io/webxr/#active-immersive-session
157 RefPtr<XRSession> mActiveImmersiveSession;
158 // https://immersive-web.github.io/webxr/#list-of-inline-sessions
159 nsTArray<RefPtr<XRSession>> mInlineSessions;
161 bool mEnumerationInFlight;
163 nsTArray<RefPtr<IsSessionSupportedRequest>> mIsSessionSupportedRequests;
164 nsTArray<RefPtr<RequestSessionRequest>>
165 mRequestSessionRequestsWithoutHardware;
166 nsTArray<RefPtr<RequestSessionRequest>>
167 mRequestSessionRequestsWaitingForRuntimeDetection;
168 nsTArray<RefPtr<RequestSessionRequest>>
169 mRequestSessionRequestsWaitingForEnumeration;
172 } // namespace mozilla::dom
174 #endif // mozilla_dom_XRsystem_h_