Source code

Revision control

Other Tools

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/. */
6
7
#include "XRPermissionRequest.h"
8
#include "nsIGlobalObject.h"
9
#include "mozilla/Preferences.h"
10
#include "nsContentUtils.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
//-------------------------------------------------
16
// XR Permission Requests
17
//-------------------------------------------------
18
19
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(XRPermissionRequest,
20
ContentPermissionRequestBase)
21
22
NS_IMPL_CYCLE_COLLECTION_INHERITED(XRPermissionRequest,
23
ContentPermissionRequestBase)
24
25
XRPermissionRequest::XRPermissionRequest(nsPIDOMWindowInner* aWindow,
26
uint64_t aWindowId)
27
: ContentPermissionRequestBase(aWindow->GetDoc()->NodePrincipal(), aWindow,
28
NS_LITERAL_CSTRING("dom.vr"),
29
NS_LITERAL_CSTRING("xr")),
30
mWindowId(aWindowId) {
31
MOZ_ASSERT(aWindow);
32
MOZ_ASSERT(aWindow->GetDoc());
33
mPrincipal = aWindow->GetDoc()->NodePrincipal();
34
MOZ_ASSERT(mPrincipal);
35
}
36
37
NS_IMETHODIMP
38
XRPermissionRequest::Cancel() {
39
nsGlobalWindowInner* window =
40
nsGlobalWindowInner::GetInnerWindowWithId(mWindowId);
41
if (!window) {
42
return NS_OK;
43
}
44
window->OnXRPermissionRequestCancel();
45
return NS_OK;
46
}
47
48
NS_IMETHODIMP
49
XRPermissionRequest::Allow(JS::HandleValue aChoices) {
50
MOZ_ASSERT(aChoices.isUndefined());
51
nsGlobalWindowInner* window =
52
nsGlobalWindowInner::GetInnerWindowWithId(mWindowId);
53
if (!window) {
54
return NS_OK;
55
}
56
window->OnXRPermissionRequestAllow();
57
return NS_OK;
58
}
59
60
nsresult XRPermissionRequest::Start() {
61
MOZ_ASSERT(NS_IsMainThread());
62
PromptResult pr = CheckPromptPrefs();
63
if (pr == PromptResult::Granted) {
64
return Allow(JS::UndefinedHandleValue);
65
}
66
if (pr == PromptResult::Denied) {
67
return Cancel();
68
}
69
70
return nsContentPermissionUtils::AskPermission(this, mWindow);
71
}
72
73
} // namespace dom
74
} // namespace mozilla