1 | /* |
2 | * Copyright (C) 2011 Ericsson AB. All rights reserved. |
3 | * Copyright (C) 2013-2016 Apple Inc. All rights reserved. |
4 | * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * |
10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer |
14 | * in the documentation and/or other materials provided with the |
15 | * distribution. |
16 | * 3. Neither the name of Ericsson nor the names of its contributors |
17 | * may be used to endorse or promote products derived from this |
18 | * software without specific prior written permission. |
19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | */ |
32 | |
33 | #pragma once |
34 | |
35 | #if ENABLE(MEDIA_STREAM) |
36 | |
37 | #include "ActiveDOMObject.h" |
38 | #include "CaptureDevice.h" |
39 | #include "JSDOMPromiseDeferred.h" |
40 | #include "MediaConstraints.h" |
41 | #include "MediaStreamPrivate.h" |
42 | #include "MediaStreamRequest.h" |
43 | #include <wtf/CompletionHandler.h> |
44 | |
45 | namespace WebCore { |
46 | |
47 | class MediaStream; |
48 | class SecurityOrigin; |
49 | |
50 | class UserMediaRequest : public RefCounted<UserMediaRequest>, public ActiveDOMObject { |
51 | public: |
52 | static Ref<UserMediaRequest> create(Document&, MediaStreamRequest&&, DOMPromiseDeferred<IDLInterface<MediaStream>>&&); |
53 | virtual ~UserMediaRequest(); |
54 | |
55 | void start(); |
56 | |
57 | WEBCORE_EXPORT void setAllowedMediaDeviceUIDs(const String& audioDeviceUID, const String& videoDeviceUID); |
58 | WEBCORE_EXPORT void allow(CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, String&& deviceIdentifierHashSalt, CompletionHandler<void()>&&); |
59 | |
60 | enum MediaAccessDenialReason { NoConstraints, UserMediaDisabled, NoCaptureDevices, InvalidConstraint, HardwareError, PermissionDenied, InvalidAccess, IllegalConstraint, OtherFailure }; |
61 | WEBCORE_EXPORT void deny(MediaAccessDenialReason, const String& errorMessage = emptyString()); |
62 | |
63 | const Vector<String>& audioDeviceUIDs() const { return m_audioDeviceUIDs; } |
64 | const Vector<String>& videoDeviceUIDs() const { return m_videoDeviceUIDs; } |
65 | |
66 | const MediaConstraints& audioConstraints() const { return m_request.audioConstraints; } |
67 | const MediaConstraints& videoConstraints() const { return m_request.videoConstraints; } |
68 | |
69 | WEBCORE_EXPORT SecurityOrigin* userMediaDocumentOrigin() const; |
70 | WEBCORE_EXPORT SecurityOrigin* topLevelDocumentOrigin() const; |
71 | WEBCORE_EXPORT Document* document() const; |
72 | |
73 | const MediaStreamRequest& request() const { return m_request; } |
74 | |
75 | private: |
76 | UserMediaRequest(Document&, MediaStreamRequest&&, DOMPromiseDeferred<IDLInterface<MediaStream>>&&); |
77 | |
78 | void stop() final; |
79 | const char* activeDOMObjectName() const final; |
80 | bool canSuspendForDocumentSuspension() const final; |
81 | |
82 | void mediaStreamIsReady(Ref<MediaStream>&&); |
83 | void mediaStreamDidFail(RealtimeMediaSource::Type); |
84 | |
85 | class PendingActivationMediaStream : public RefCounted<PendingActivationMediaStream>, private MediaStreamPrivate::Observer { |
86 | public: |
87 | static Ref<PendingActivationMediaStream> create(Ref<PendingActivity<UserMediaRequest>>&& protectingUserMediaRequest, UserMediaRequest& userMediaRequest, Ref<MediaStream>&& stream, CompletionHandler<void()>&& completionHandler) |
88 | { |
89 | return adoptRef(*new PendingActivationMediaStream { WTFMove(protectingUserMediaRequest), userMediaRequest, WTFMove(stream), WTFMove(completionHandler) }); |
90 | } |
91 | ~PendingActivationMediaStream(); |
92 | |
93 | private: |
94 | PendingActivationMediaStream(Ref<PendingActivity<UserMediaRequest>>&&, UserMediaRequest&, Ref<MediaStream>&&, CompletionHandler<void()>&&); |
95 | |
96 | void characteristicsChanged() final; |
97 | |
98 | Ref<PendingActivity<UserMediaRequest>> m_protectingUserMediaRequest; |
99 | UserMediaRequest& m_userMediaRequest; |
100 | Ref<MediaStream> m_mediaStream; |
101 | CompletionHandler<void()> m_completionHandler; |
102 | }; |
103 | |
104 | Vector<String> m_videoDeviceUIDs; |
105 | Vector<String> m_audioDeviceUIDs; |
106 | |
107 | DOMPromiseDeferred<IDLInterface<MediaStream>> m_promise; |
108 | RefPtr<PendingActivationMediaStream> m_pendingActivationMediaStream; |
109 | MediaStreamRequest m_request; |
110 | }; |
111 | |
112 | } // namespace WebCore |
113 | |
114 | #endif // ENABLE(MEDIA_STREAM) |
115 | |