Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / vr / XRPermissionRequest.cpp
blob2661f246cd47a9900703e64fdf1fa6040696bf4d
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,
26 uint64_t aWindowId)
27 : ContentPermissionRequestBase(aWindow->GetDoc()->NodePrincipal(), aWindow,
28 "dom.vr"_ns, "xr"_ns),
29 mWindowId(aWindowId) {
30 MOZ_ASSERT(aWindow);
31 MOZ_ASSERT(aWindow->GetDoc());
32 mPrincipal = aWindow->GetDoc()->NodePrincipal();
33 MOZ_ASSERT(mPrincipal);
36 NS_IMETHODIMP
37 XRPermissionRequest::Cancel() {
38 nsGlobalWindowInner* window =
39 nsGlobalWindowInner::GetInnerWindowWithId(mWindowId);
40 if (!window) {
41 return NS_OK;
43 window->OnXRPermissionRequestCancel();
44 return NS_OK;
47 NS_IMETHODIMP
48 XRPermissionRequest::Allow(JS::Handle<JS::Value> aChoices) {
49 MOZ_ASSERT(aChoices.isUndefined());
50 nsGlobalWindowInner* window =
51 nsGlobalWindowInner::GetInnerWindowWithId(mWindowId);
52 if (!window) {
53 return NS_OK;
55 window->OnXRPermissionRequestAllow();
56 return NS_OK;
59 nsresult XRPermissionRequest::Start() {
60 MOZ_ASSERT(NS_IsMainThread());
61 if (!CheckPermissionDelegate()) {
62 return Cancel();
64 PromptResult pr = CheckPromptPrefs();
65 if (pr == PromptResult::Granted) {
66 return Allow(JS::UndefinedHandleValue);
68 if (pr == PromptResult::Denied) {
69 return Cancel();
72 return nsContentPermissionUtils::AskPermission(this, mWindow);
75 } // namespace mozilla::dom