1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 #include "XRPermissionRequest.h"
8 #include "nsGlobalWindowInner.h"
9 #include "mozilla/dom/Document.h"
10 #include "mozilla/Preferences.h"
11 #include "nsContentUtils.h"
13 namespace mozilla::dom
{
15 //-------------------------------------------------
16 // XR Permission Requests
17 //-------------------------------------------------
19 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(XRPermissionRequest
,
20 ContentPermissionRequestBase
)
22 NS_IMPL_CYCLE_COLLECTION_INHERITED(XRPermissionRequest
,
23 ContentPermissionRequestBase
)
25 XRPermissionRequest::XRPermissionRequest(nsPIDOMWindowInner
* aWindow
,
27 : ContentPermissionRequestBase(aWindow
->GetDoc()->NodePrincipal(), aWindow
,
28 "dom.vr"_ns
, "xr"_ns
),
29 mWindowId(aWindowId
) {
31 MOZ_ASSERT(aWindow
->GetDoc());
32 mPrincipal
= aWindow
->GetDoc()->NodePrincipal();
33 MOZ_ASSERT(mPrincipal
);
37 XRPermissionRequest::Cancel() {
38 nsGlobalWindowInner
* window
=
39 nsGlobalWindowInner::GetInnerWindowWithId(mWindowId
);
43 window
->OnXRPermissionRequestCancel();
48 XRPermissionRequest::Allow(JS::Handle
<JS::Value
> aChoices
) {
49 MOZ_ASSERT(aChoices
.isUndefined());
50 nsGlobalWindowInner
* window
=
51 nsGlobalWindowInner::GetInnerWindowWithId(mWindowId
);
55 window
->OnXRPermissionRequestAllow();
59 nsresult
XRPermissionRequest::Start() {
60 MOZ_ASSERT(NS_IsMainThread());
61 if (!CheckPermissionDelegate()) {
64 PromptResult pr
= CheckPromptPrefs();
65 if (pr
== PromptResult::Granted
) {
66 return Allow(JS::UndefinedHandleValue
);
68 if (pr
== PromptResult::Denied
) {
72 return nsContentPermissionUtils::AskPermission(this, mWindow
);
75 } // namespace mozilla::dom