1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "GetUserMediaRequest.h"
7 #include "base/basictypes.h"
8 #include "MediaManager.h"
9 #include "mozilla/dom/MediaDevicesBinding.h"
10 #include "mozilla/dom/MediaStreamBinding.h"
11 #include "mozilla/dom/GetUserMediaRequestBinding.h"
12 #include "nsIMediaDevice.h"
13 #include "nsIScriptGlobalObject.h"
14 #include "nsPIDOMWindow.h"
16 namespace mozilla::dom
{
18 GetUserMediaRequest::GetUserMediaRequest(
19 nsPIDOMWindowInner
* aInnerWindow
, const nsAString
& aCallID
,
20 RefPtr
<LocalMediaDeviceSetRefCnt
> aMediaDeviceSet
,
21 const MediaStreamConstraints
& aConstraints
, bool aIsSecure
,
22 bool aIsHandlingUserInput
)
23 : mInnerWindowID(aInnerWindow
->WindowID()),
24 mOuterWindowID(aInnerWindow
->GetOuterWindow()->WindowID()),
26 mMediaDeviceSet(std::move(aMediaDeviceSet
)),
27 mConstraints(new MediaStreamConstraints(aConstraints
)),
28 mType(GetUserMediaRequestType::Getusermedia
),
30 mIsHandlingUserInput(aIsHandlingUserInput
) {}
32 GetUserMediaRequest::GetUserMediaRequest(
33 nsPIDOMWindowInner
* aInnerWindow
, const nsAString
& aCallID
,
34 RefPtr
<LocalMediaDeviceSetRefCnt
> aMediaDeviceSet
,
35 const AudioOutputOptions
& aAudioOutputOptions
, bool aIsSecure
,
36 bool aIsHandlingUserInput
)
37 : mInnerWindowID(aInnerWindow
->WindowID()),
38 mOuterWindowID(aInnerWindow
->GetOuterWindow()->WindowID()),
40 mMediaDeviceSet(std::move(aMediaDeviceSet
)),
41 mAudioOutputOptions(new AudioOutputOptions(aAudioOutputOptions
)),
42 mType(GetUserMediaRequestType::Selectaudiooutput
),
44 mIsHandlingUserInput(aIsHandlingUserInput
) {}
46 GetUserMediaRequest::GetUserMediaRequest(nsPIDOMWindowInner
* aInnerWindow
,
47 const nsAString
& aRawId
,
48 const nsAString
& aMediaSource
,
49 bool aIsHandlingUserInput
)
53 mMediaSource(aMediaSource
),
54 mType(GetUserMediaRequestType::Recording_device_stopped
),
56 mIsHandlingUserInput(aIsHandlingUserInput
) {
57 if (aInnerWindow
&& aInnerWindow
->GetOuterWindow()) {
58 mOuterWindowID
= aInnerWindow
->GetOuterWindow()->WindowID();
62 GetUserMediaRequest::~GetUserMediaRequest() = default;
64 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(GetUserMediaRequest
)
65 NS_IMPL_CYCLE_COLLECTING_ADDREF(GetUserMediaRequest
)
66 NS_IMPL_CYCLE_COLLECTING_RELEASE(GetUserMediaRequest
)
67 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GetUserMediaRequest
)
68 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
69 NS_INTERFACE_MAP_ENTRY(nsISupports
)
72 JSObject
* GetUserMediaRequest::WrapObject(JSContext
* aCx
,
73 JS::Handle
<JSObject
*> aGivenProto
) {
74 return GetUserMediaRequest_Binding::Wrap(aCx
, this, aGivenProto
);
77 nsISupports
* GetUserMediaRequest::GetParentObject() { return nullptr; }
79 GetUserMediaRequestType
GetUserMediaRequest::Type() { return mType
; }
81 void GetUserMediaRequest::GetCallID(nsString
& retval
) { retval
= mCallID
; }
83 void GetUserMediaRequest::GetRawID(nsString
& retval
) { retval
= mRawID
; }
85 void GetUserMediaRequest::GetMediaSource(nsString
& retval
) {
86 retval
= mMediaSource
;
89 uint64_t GetUserMediaRequest::WindowID() { return mOuterWindowID
; }
91 uint64_t GetUserMediaRequest::InnerWindowID() { return mInnerWindowID
; }
93 bool GetUserMediaRequest::IsSecure() { return mIsSecure
; }
95 bool GetUserMediaRequest::IsHandlingUserInput() const {
96 return mIsHandlingUserInput
;
99 void GetUserMediaRequest::GetDevices(
100 nsTArray
<RefPtr
<nsIMediaDevice
>>& retval
) const {
101 MOZ_ASSERT(retval
.Length() == 0);
102 if (!mMediaDeviceSet
) {
105 for (const auto& device
: *mMediaDeviceSet
) {
106 retval
.AppendElement(device
);
110 void GetUserMediaRequest::GetConstraints(MediaStreamConstraints
& result
) {
111 MOZ_ASSERT(result
.mAudio
.IsBoolean() && !result
.mAudio
.GetAsBoolean() &&
112 result
.mVideo
.IsBoolean() && !result
.mVideo
.GetAsBoolean(),
113 "result should be default initialized");
115 result
= *mConstraints
;
119 void GetUserMediaRequest::GetAudioOutputOptions(AudioOutputOptions
& result
) {
120 MOZ_ASSERT(result
.mDeviceId
.IsEmpty(),
121 "result should be default initialized");
122 if (mAudioOutputOptions
) {
123 result
= *mAudioOutputOptions
;
127 } // namespace mozilla::dom