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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsOSPermissionRequestBase.h"
9 #include "mozilla/dom/Promise.h"
11 using namespace mozilla
;
13 using mozilla::dom::Promise
;
15 NS_IMPL_ISUPPORTS(nsOSPermissionRequestBase
, nsIOSPermissionRequest
,
16 nsISupportsWeakReference
)
19 nsOSPermissionRequestBase::GetMediaCapturePermissionState(
20 uint16_t* aCamera
, uint16_t* aMicrophone
) {
21 nsresult rv
= GetVideoCapturePermissionState(aCamera
);
25 return GetAudioCapturePermissionState(aMicrophone
);
29 nsOSPermissionRequestBase::GetAudioCapturePermissionState(uint16_t* aAudio
) {
31 *aAudio
= PERMISSION_STATE_AUTHORIZED
;
36 nsOSPermissionRequestBase::GetVideoCapturePermissionState(uint16_t* aVideo
) {
38 *aVideo
= PERMISSION_STATE_AUTHORIZED
;
43 nsOSPermissionRequestBase::GetScreenCapturePermissionState(uint16_t* aScreen
) {
45 *aScreen
= PERMISSION_STATE_AUTHORIZED
;
49 nsresult
nsOSPermissionRequestBase::GetPromise(JSContext
* aCx
,
50 RefPtr
<Promise
>& aPromiseOut
) {
51 nsIGlobalObject
* globalObject
= xpc::CurrentNativeGlobal(aCx
);
52 if (NS_WARN_IF(!globalObject
)) {
53 return NS_ERROR_UNEXPECTED
;
57 aPromiseOut
= Promise::Create(globalObject
, result
);
58 if (NS_WARN_IF(result
.Failed())) {
59 return result
.StealNSResult();
66 nsOSPermissionRequestBase::RequestVideoCapturePermission(
67 JSContext
* aCx
, Promise
** aPromiseOut
) {
68 RefPtr
<Promise
> promiseHandle
;
69 nsresult rv
= GetPromise(aCx
, promiseHandle
);
74 promiseHandle
->MaybeResolve(true /* access authorized */);
75 promiseHandle
.forget(aPromiseOut
);
80 nsOSPermissionRequestBase::RequestAudioCapturePermission(
81 JSContext
* aCx
, Promise
** aPromiseOut
) {
82 RefPtr
<Promise
> promiseHandle
;
83 nsresult rv
= GetPromise(aCx
, promiseHandle
);
88 promiseHandle
->MaybeResolve(true /* access authorized */);
89 promiseHandle
.forget(aPromiseOut
);
94 nsOSPermissionRequestBase::MaybeRequestScreenCapturePermission() {