[MediaStream] defer resolution of getUserMedia promise made in a background tab
[WebKit-https.git] / Source / WebKit2 / WebProcess / MediaStream / UserMediaPermissionRequestManager.h
1 /*
2  * Copyright (C) 2014 Igalia S.L.
3  * Copyright (C) 2016 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 #ifndef UserMediaPermissionRequestManager_h
21 #define UserMediaPermissionRequestManager_h
22
23 #if ENABLE(MEDIA_STREAM)
24
25 #include "SandboxExtension.h"
26 #include <WebCore/MediaCanStartListener.h>
27 #include <WebCore/MediaConstraints.h>
28 #include <WebCore/MediaDevicesEnumerationRequest.h>
29 #include <WebCore/UserMediaClient.h>
30 #include <WebCore/UserMediaRequest.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/Ref.h>
33 #include <wtf/RefPtr.h>
34
35 namespace WebKit {
36
37 class WebPage;
38
39 class UserMediaPermissionRequestManager
40     : private WebCore::MediaCanStartListener {
41 public:
42     explicit UserMediaPermissionRequestManager(WebPage&);
43     ~UserMediaPermissionRequestManager();
44
45     void startUserMediaRequest(WebCore::UserMediaRequest&);
46     void cancelUserMediaRequest(WebCore::UserMediaRequest&);
47     void userMediaAccessWasGranted(uint64_t, const String& audioDeviceUID, const String& videoDeviceUID);
48     void userMediaAccessWasDenied(uint64_t, WebCore::UserMediaRequest::MediaAccessDenialReason, const String&);
49
50     void enumerateMediaDevices(WebCore::MediaDevicesEnumerationRequest&);
51     void cancelMediaDevicesEnumeration(WebCore::MediaDevicesEnumerationRequest&);
52     void didCompleteMediaDeviceEnumeration(uint64_t, const Vector<WebCore::CaptureDevice>& deviceList, const String& deviceIdentifierHashSalt, bool originHasPersistentAccess);
53
54     void grantUserMediaDevicesSandboxExtension(const SandboxExtension::HandleArray&);
55
56 private:
57     void sendUserMediaRequest(WebCore::UserMediaRequest&);
58
59     // WebCore::MediaCanStartListener
60     void mediaCanStart(WebCore::Document&) override;
61
62     void removeMediaRequestFromMaps(WebCore::UserMediaRequest&);
63
64     WebPage& m_page;
65
66     HashMap<uint64_t, RefPtr<WebCore::UserMediaRequest>> m_idToUserMediaRequestMap;
67     HashMap<RefPtr<WebCore::UserMediaRequest>, uint64_t> m_userMediaRequestToIDMap;
68
69     HashMap<uint64_t, RefPtr<WebCore::MediaDevicesEnumerationRequest>> m_idToMediaDevicesEnumerationRequestMap;
70     HashMap<RefPtr<WebCore::MediaDevicesEnumerationRequest>, uint64_t> m_mediaDevicesEnumerationRequestToIDMap;
71
72     Vector<RefPtr<SandboxExtension>> m_userMediaDeviceSandboxExtensions;
73
74     HashMap<RefPtr<WebCore::Document>, Vector<RefPtr<WebCore::UserMediaRequest>>> m_blockedRequests;
75 };
76
77 } // namespace WebKit
78
79 #endif // ENABLE(MEDIA_STREAM)
80
81 #endif // UserMediaPermissionRequestManager_h