/src/mozilla-central/dom/system/nsOSPermissionRequestBase.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsOSPermissionRequestBase.h" |
8 | | |
9 | | #include "mozilla/dom/Promise.h" |
10 | | |
11 | | using namespace mozilla; |
12 | | |
13 | | using mozilla::dom::Promise; |
14 | | |
15 | | NS_IMPL_ISUPPORTS( |
16 | | nsOSPermissionRequestBase, |
17 | | nsIOSPermissionRequest, |
18 | | nsISupportsWeakReference) |
19 | | |
20 | | NS_IMETHODIMP |
21 | | nsOSPermissionRequestBase::GetMediaCapturePermissionState(uint16_t* aCamera, |
22 | | uint16_t* aMicrophone) |
23 | 0 | { |
24 | 0 | nsresult rv = GetVideoCapturePermissionState(aCamera); |
25 | 0 | if (NS_FAILED(rv)) { |
26 | 0 | return rv; |
27 | 0 | } |
28 | 0 | return GetAudioCapturePermissionState(aMicrophone); |
29 | 0 | } |
30 | | |
31 | | NS_IMETHODIMP |
32 | | nsOSPermissionRequestBase::GetAudioCapturePermissionState(uint16_t* aAudio) |
33 | 0 | { |
34 | 0 | MOZ_ASSERT(aAudio); |
35 | 0 | *aAudio = PERMISSION_STATE_AUTHORIZED; |
36 | 0 | return NS_OK; |
37 | 0 | } |
38 | | |
39 | | NS_IMETHODIMP |
40 | | nsOSPermissionRequestBase::GetVideoCapturePermissionState(uint16_t* aVideo) |
41 | 0 | { |
42 | 0 | MOZ_ASSERT(aVideo); |
43 | 0 | *aVideo = PERMISSION_STATE_AUTHORIZED; |
44 | 0 | return NS_OK; |
45 | 0 | } |
46 | | |
47 | | nsresult |
48 | | nsOSPermissionRequestBase::GetPromise(JSContext* aCx, |
49 | | RefPtr<Promise>& aPromiseOut) |
50 | 0 | { |
51 | 0 | nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aCx); |
52 | 0 | if (NS_WARN_IF(!globalObject)) { |
53 | 0 | return NS_ERROR_UNEXPECTED; |
54 | 0 | } |
55 | 0 | |
56 | 0 | ErrorResult result; |
57 | 0 | aPromiseOut = Promise::Create(globalObject, result); |
58 | 0 | if (NS_WARN_IF(result.Failed())) { |
59 | 0 | return result.StealNSResult(); |
60 | 0 | } |
61 | 0 | |
62 | 0 | return NS_OK; |
63 | 0 | } |
64 | | |
65 | | NS_IMETHODIMP |
66 | | nsOSPermissionRequestBase::RequestVideoCapturePermission(JSContext* aCx, |
67 | | Promise** aPromiseOut) |
68 | 0 | { |
69 | 0 | RefPtr<Promise> promiseHandle; |
70 | 0 | nsresult rv = GetPromise(aCx, promiseHandle); |
71 | 0 | if (NS_FAILED(rv)) { |
72 | 0 | return rv; |
73 | 0 | } |
74 | 0 | |
75 | 0 | promiseHandle->MaybeResolve(true /* access authorized */); |
76 | 0 | promiseHandle.forget(aPromiseOut); |
77 | 0 | return NS_OK; |
78 | 0 | } |
79 | | |
80 | | NS_IMETHODIMP |
81 | | nsOSPermissionRequestBase::RequestAudioCapturePermission(JSContext* aCx, |
82 | | Promise** aPromiseOut) |
83 | 0 | { |
84 | 0 | RefPtr<Promise> promiseHandle; |
85 | 0 | nsresult rv = GetPromise(aCx, promiseHandle); |
86 | 0 | if (NS_FAILED(rv)) { |
87 | 0 | return rv; |
88 | 0 | } |
89 | 0 | |
90 | 0 | promiseHandle->MaybeResolve(true /* access authorized */); |
91 | 0 | promiseHandle.forget(aPromiseOut); |
92 | 0 | return NS_OK; |
93 | 0 | } |