1 | /* |
2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
3 | * Copyright (C) 2016-2018 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
21 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(MEDIA_STREAM) |
29 | |
30 | #include "Page.h" |
31 | #include "UserMediaClient.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | class UserMediaRequest; |
36 | |
37 | class UserMediaController : public Supplement<Page> { |
38 | WTF_MAKE_FAST_ALLOCATED; |
39 | public: |
40 | explicit UserMediaController(UserMediaClient*); |
41 | ~UserMediaController(); |
42 | |
43 | UserMediaClient* client() const { return m_client; } |
44 | |
45 | void requestUserMediaAccess(UserMediaRequest&); |
46 | void cancelUserMediaAccessRequest(UserMediaRequest&); |
47 | |
48 | void enumerateMediaDevices(MediaDevicesEnumerationRequest&); |
49 | void cancelMediaDevicesEnumerationRequest(MediaDevicesEnumerationRequest&); |
50 | |
51 | UserMediaClient::DeviceChangeObserverToken addDeviceChangeObserver(WTF::Function<void()>&&); |
52 | void removeDeviceChangeObserver(UserMediaClient::DeviceChangeObserverToken); |
53 | |
54 | enum class GetUserMediaAccess { |
55 | CanCall, |
56 | InsecureDocument, |
57 | InsecureParent, |
58 | BlockedByParent, |
59 | BlockedByFeaturePolicy, |
60 | }; |
61 | enum class CaptureType { |
62 | Microphone = 1 << 0, |
63 | Camera = 1 << 1, |
64 | Display = 1 << 3 |
65 | }; |
66 | GetUserMediaAccess canCallGetUserMedia(Document&, OptionSet<CaptureType>); |
67 | |
68 | enum class BlockedCaller { |
69 | GetUserMedia, |
70 | GetDisplayMedia, |
71 | EnumerateDevices, |
72 | }; |
73 | void logGetUserMediaDenial(Document&, GetUserMediaAccess, BlockedCaller); |
74 | |
75 | WEBCORE_EXPORT static const char* supplementName(); |
76 | static UserMediaController* from(Page* page) { return static_cast<UserMediaController*>(Supplement<Page>::from(page, supplementName())); } |
77 | |
78 | private: |
79 | UserMediaClient* m_client; |
80 | }; |
81 | |
82 | inline void UserMediaController::requestUserMediaAccess(UserMediaRequest& request) |
83 | { |
84 | m_client->requestUserMediaAccess(request); |
85 | } |
86 | |
87 | inline void UserMediaController::cancelUserMediaAccessRequest(UserMediaRequest& request) |
88 | { |
89 | m_client->cancelUserMediaAccessRequest(request); |
90 | } |
91 | |
92 | inline void UserMediaController::enumerateMediaDevices(MediaDevicesEnumerationRequest& request) |
93 | { |
94 | m_client->enumerateMediaDevices(request); |
95 | } |
96 | |
97 | inline void UserMediaController::cancelMediaDevicesEnumerationRequest(MediaDevicesEnumerationRequest& request) |
98 | { |
99 | m_client->cancelMediaDevicesEnumerationRequest(request); |
100 | } |
101 | |
102 | inline UserMediaClient::DeviceChangeObserverToken UserMediaController::addDeviceChangeObserver(WTF::Function<void()>&& observer) |
103 | { |
104 | return m_client->addDeviceChangeObserver(WTFMove(observer)); |
105 | } |
106 | |
107 | inline void UserMediaController::removeDeviceChangeObserver(UserMediaClient::DeviceChangeObserverToken token) |
108 | { |
109 | m_client->removeDeviceChangeObserver(token); |
110 | } |
111 | |
112 | } // namespace WebCore |
113 | |
114 | #endif // ENABLE(MEDIA_STREAM) |
115 | |