Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / system / nsOSPermissionRequestBase.cpp
blob32b32c38cddb2f23e4e087a6e6063fd7938cbecd
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)
18 NS_IMETHODIMP
19 nsOSPermissionRequestBase::GetMediaCapturePermissionState(
20 uint16_t* aCamera, uint16_t* aMicrophone) {
21 nsresult rv = GetVideoCapturePermissionState(aCamera);
22 if (NS_FAILED(rv)) {
23 return rv;
25 return GetAudioCapturePermissionState(aMicrophone);
28 NS_IMETHODIMP
29 nsOSPermissionRequestBase::GetAudioCapturePermissionState(uint16_t* aAudio) {
30 MOZ_ASSERT(aAudio);
31 *aAudio = PERMISSION_STATE_AUTHORIZED;
32 return NS_OK;
35 NS_IMETHODIMP
36 nsOSPermissionRequestBase::GetVideoCapturePermissionState(uint16_t* aVideo) {
37 MOZ_ASSERT(aVideo);
38 *aVideo = PERMISSION_STATE_AUTHORIZED;
39 return NS_OK;
42 NS_IMETHODIMP
43 nsOSPermissionRequestBase::GetScreenCapturePermissionState(uint16_t* aScreen) {
44 MOZ_ASSERT(aScreen);
45 *aScreen = PERMISSION_STATE_AUTHORIZED;
46 return NS_OK;
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;
56 ErrorResult result;
57 aPromiseOut = Promise::Create(globalObject, result);
58 if (NS_WARN_IF(result.Failed())) {
59 return result.StealNSResult();
62 return NS_OK;
65 NS_IMETHODIMP
66 nsOSPermissionRequestBase::RequestVideoCapturePermission(
67 JSContext* aCx, Promise** aPromiseOut) {
68 RefPtr<Promise> promiseHandle;
69 nsresult rv = GetPromise(aCx, promiseHandle);
70 if (NS_FAILED(rv)) {
71 return rv;
74 promiseHandle->MaybeResolve(true /* access authorized */);
75 promiseHandle.forget(aPromiseOut);
76 return NS_OK;
79 NS_IMETHODIMP
80 nsOSPermissionRequestBase::RequestAudioCapturePermission(
81 JSContext* aCx, Promise** aPromiseOut) {
82 RefPtr<Promise> promiseHandle;
83 nsresult rv = GetPromise(aCx, promiseHandle);
84 if (NS_FAILED(rv)) {
85 return rv;
88 promiseHandle->MaybeResolve(true /* access authorized */);
89 promiseHandle.forget(aPromiseOut);
90 return NS_OK;
93 NS_IMETHODIMP
94 nsOSPermissionRequestBase::MaybeRequestScreenCapturePermission() {
95 return NS_OK;