1 | /* |
2 | * Copyright (C) 2014 Igalia S.L. |
3 | * Copyright (C) 2016-2019 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
19 | |
20 | #pragma once |
21 | |
22 | #include "APIObject.h" |
23 | #include <WebCore/CaptureDevice.h> |
24 | #include <WebCore/MediaStreamRequest.h> |
25 | #include <wtf/Vector.h> |
26 | #include <wtf/text/WTFString.h> |
27 | |
28 | namespace WebCore { |
29 | class SecurityOrigin; |
30 | } |
31 | |
32 | namespace WebKit { |
33 | |
34 | class UserMediaPermissionRequestManagerProxy; |
35 | |
36 | class UserMediaPermissionRequestProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionRequest> { |
37 | public: |
38 | static Ref<UserMediaPermissionRequestProxy> create(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, WebCore::MediaStreamRequest&& request) |
39 | { |
40 | return adoptRef(*new UserMediaPermissionRequestProxy(manager, userMediaID, mainFrameID, frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(request))); |
41 | } |
42 | |
43 | void allow(const String& audioDeviceUID, const String& videoDeviceUID); |
44 | void allow(WebCore::CaptureDevice&& audioDevice, WebCore::CaptureDevice&& videoDevice); |
45 | void allow(); |
46 | |
47 | enum class UserMediaAccessDenialReason { NoConstraints, UserMediaDisabled, NoCaptureDevices, InvalidConstraint, HardwareError, PermissionDenied, OtherFailure }; |
48 | void deny(UserMediaAccessDenialReason = UserMediaAccessDenialReason::UserMediaDisabled); |
49 | |
50 | void invalidate(); |
51 | bool isPending() const { return m_manager; } |
52 | |
53 | bool requiresAudioCapture() const { return m_eligibleAudioDevices.size(); } |
54 | bool requiresVideoCapture() const { return !requiresDisplayCapture() && m_eligibleVideoDevices.size(); } |
55 | bool requiresDisplayCapture() const { return m_request.type == WebCore::MediaStreamRequest::Type::DisplayMedia && m_eligibleVideoDevices.size(); } |
56 | |
57 | void setEligibleVideoDeviceUIDs(Vector<WebCore::CaptureDevice>&& devices) { m_eligibleVideoDevices = WTFMove(devices); } |
58 | void setEligibleAudioDeviceUIDs(Vector<WebCore::CaptureDevice>&& devices) { m_eligibleAudioDevices = WTFMove(devices); } |
59 | |
60 | Vector<String> videoDeviceUIDs() const; |
61 | Vector<String> audioDeviceUIDs() const; |
62 | bool hasAudioDevice() const { return !m_eligibleAudioDevices.isEmpty(); } |
63 | bool hasVideoDevice() const { return !m_eligibleVideoDevices.isEmpty(); } |
64 | |
65 | bool hasPersistentAccess() const { return m_hasPersistentAccess; } |
66 | void setHasPersistentAccess() { m_hasPersistentAccess = true; } |
67 | |
68 | uint64_t userMediaID() const { return m_userMediaID; } |
69 | uint64_t mainFrameID() const { return m_mainFrameID; } |
70 | uint64_t frameID() const { return m_frameID; } |
71 | |
72 | WebCore::SecurityOrigin& topLevelDocumentSecurityOrigin() { return m_topLevelDocumentSecurityOrigin.get(); } |
73 | WebCore::SecurityOrigin& userMediaDocumentSecurityOrigin() { return m_userMediaDocumentSecurityOrigin.get(); } |
74 | const WebCore::SecurityOrigin& topLevelDocumentSecurityOrigin() const { return m_topLevelDocumentSecurityOrigin.get(); } |
75 | const WebCore::SecurityOrigin& userMediaDocumentSecurityOrigin() const { return m_userMediaDocumentSecurityOrigin.get(); } |
76 | |
77 | const WebCore::MediaStreamRequest& userRequest() const { return m_request; } |
78 | |
79 | WebCore::MediaStreamRequest::Type requestType() const { return m_request.type; } |
80 | |
81 | void setDeviceIdentifierHashSalt(String&& salt) { m_deviceIdentifierHashSalt = WTFMove(salt); } |
82 | const String& deviceIdentifierHashSalt() const { return m_deviceIdentifierHashSalt; } |
83 | |
84 | WebCore::CaptureDevice audioDevice() const { return m_eligibleAudioDevices.isEmpty() ? WebCore::CaptureDevice { } : m_eligibleAudioDevices[0]; } |
85 | WebCore::CaptureDevice videoDevice() const { return m_eligibleVideoDevices.isEmpty() ? WebCore::CaptureDevice { } : m_eligibleVideoDevices[0]; } |
86 | |
87 | private: |
88 | UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy&, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, WebCore::MediaStreamRequest&&); |
89 | |
90 | UserMediaPermissionRequestManagerProxy* m_manager; |
91 | uint64_t m_userMediaID; |
92 | uint64_t m_mainFrameID; |
93 | uint64_t m_frameID; |
94 | Ref<WebCore::SecurityOrigin> m_userMediaDocumentSecurityOrigin; |
95 | Ref<WebCore::SecurityOrigin> m_topLevelDocumentSecurityOrigin; |
96 | Vector<WebCore::CaptureDevice> m_eligibleVideoDevices; |
97 | Vector<WebCore::CaptureDevice> m_eligibleAudioDevices; |
98 | WebCore::MediaStreamRequest m_request; |
99 | bool m_hasPersistentAccess { false }; |
100 | String m_deviceIdentifierHashSalt; |
101 | }; |
102 | |
103 | String convertEnumerationToString(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason); |
104 | |
105 | } // namespace WebKit |
106 | |
107 | namespace WTF { |
108 | |
109 | template<typename Type> |
110 | struct LogArgument; |
111 | |
112 | template <> |
113 | struct LogArgument<WebKit::UserMediaPermissionRequestProxy::UserMediaAccessDenialReason> { |
114 | static String toString(const WebKit::UserMediaPermissionRequestProxy::UserMediaAccessDenialReason type) |
115 | { |
116 | return convertEnumerationToString(type); |
117 | } |
118 | }; |
119 | |
120 | }; // namespace WTF |
121 | |
122 | |