Skip to content

Commit 379ffc3

Browse files
committed
Hash deviceIds in WebProcess instead of UIProcess to allow audio output device IDs in WebProcess
https://bugs.webkit.org/show_bug.cgi?id=216693 Reviewed by Eric Carlson. LayoutTests/imported/w3c: * web-platform-tests/mediacapture-streams/MediaDevices-enumerateDevices-returned-objects.https-expected.txt: Source/WebCore: Make sure to create new MediaDeviceInfo objects everytime enumerateDevices is called. Covered by updated tests. * Modules/mediastream/MediaDevices.cpp: (WebCore::MediaDevices::MediaDevices): (WebCore::MediaDevices::stop): (WebCore::MediaDevices::computeDevices): (WebCore::MediaDevices::enumerateDevices): (WebCore::MediaDevices::refreshDevices): Deleted. * Modules/mediastream/MediaDevices.h: Source/WebKit: * UIProcess/UserMediaPermissionRequestManagerProxy.cpp: (WebKit::UserMediaPermissionRequestManagerProxy::computeFilteredDeviceList): (WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame): * UIProcess/UserMediaPermissionRequestManagerProxy.h: LayoutTests: * fast/mediastream/device-change-event-2.html: Canonical link: https://commits.webkit.org/229507@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267246 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 7703754 commit 379ffc3

10 files changed

Lines changed: 73 additions & 43 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2020-09-18 Youenn Fablet <youenn@apple.com>
2+
3+
Hash deviceIds in WebProcess instead of UIProcess to allow audio output device IDs in WebProcess
4+
https://bugs.webkit.org/show_bug.cgi?id=216693
5+
6+
Reviewed by Eric Carlson.
7+
8+
* fast/mediastream/device-change-event-2.html:
9+
110
2020-09-18 Chris Dumez <cdumez@apple.com>
211

312
Import Analyser / AudioBuffer / AudioBufferSource layout tests from Blink

LayoutTests/fast/mediastream/device-change-event-2.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
let devices2 = await navigator.mediaDevices.enumerateDevices();
3333

3434
assert_true(!!devices.length, "check there are some devices");
35-
assert_array_equals(devices, devices2);
35+
assert_equals(devices.length, devices2.length, "devices length");
36+
assert_not_equals(devices[0], devices2[0], "devices are different");
37+
assert_equals(devices[0].deviceId, devices2[0].deviceId, "same deviceIds");
3638

3739
testRunner.clearMockMediaDevices();
3840
await new Promise((resolve, reject) => {

LayoutTests/imported/w3c/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2020-09-18 Youenn Fablet <youenn@apple.com>
2+
3+
Hash deviceIds in WebProcess instead of UIProcess to allow audio output device IDs in WebProcess
4+
https://bugs.webkit.org/show_bug.cgi?id=216693
5+
6+
Reviewed by Eric Carlson.
7+
8+
* web-platform-tests/mediacapture-streams/MediaDevices-enumerateDevices-returned-objects.https-expected.txt:
9+
110
2020-09-18 Jer Noble <jer.noble@apple.com>
211

312
REGRESSION(r254031): Captions fail to load on jw.org
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
FAIL enumerateDevices returns new objects in case device-info permission is not granted assert_not_equals: got disallowed value object "[object MediaDeviceInfo]"
3-
FAIL enumerateDevices returns new objects in case device-info permission is granted assert_not_equals: got disallowed value object "[object MediaDeviceInfo]"
2+
PASS enumerateDevices returns new objects in case device-info permission is not granted
3+
PASS enumerateDevices returns new objects in case device-info permission is granted
44

Source/WebCore/ChangeLog

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
2020-09-18 Youenn Fablet <youenn@apple.com>
2+
3+
Hash deviceIds in WebProcess instead of UIProcess to allow audio output device IDs in WebProcess
4+
https://bugs.webkit.org/show_bug.cgi?id=216693
5+
6+
Reviewed by Eric Carlson.
7+
8+
Make sure to create new MediaDeviceInfo objects everytime enumerateDevices is called.
9+
Covered by updated tests.
10+
11+
* Modules/mediastream/MediaDevices.cpp:
12+
(WebCore::MediaDevices::MediaDevices):
13+
(WebCore::MediaDevices::stop):
14+
(WebCore::MediaDevices::computeDevices):
15+
(WebCore::MediaDevices::enumerateDevices):
16+
(WebCore::MediaDevices::refreshDevices): Deleted.
17+
* Modules/mediastream/MediaDevices.h:
18+
119
2020-09-18 Jer Noble <jer.noble@apple.com>
220

321
REGRESSION(r254031): Captions fail to load on jw.org

Source/WebCore/Modules/mediastream/MediaDevices.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ inline MediaDevices::MediaDevices(Document& document)
5757
: ActiveDOMObject(document)
5858
, m_scheduledEventTimer(*this, &MediaDevices::scheduledEventTimerFired)
5959
, m_eventNames(eventNames())
60-
, m_idHashSalt(createCanonicalUUIDString())
60+
, m_groupIdHashSalt(createCanonicalUUIDString())
6161
{
6262
suspendIfNeeded();
6363

@@ -76,7 +76,6 @@ void MediaDevices::stop()
7676
if (controller)
7777
controller->removeDeviceChangeObserver(m_deviceChangeToken);
7878
}
79-
m_devices.clear();
8079
m_scheduledEventTimer.stop();
8180
}
8281

@@ -192,15 +191,16 @@ static inline MediaDeviceInfo::Kind toMediaDeviceInfoKind(CaptureDevice::DeviceT
192191
return MediaDeviceInfo::Kind::Audioinput;
193192
}
194193

195-
void MediaDevices::refreshDevices(const Vector<CaptureDevice>& newDevices)
194+
void MediaDevices::exposeDevices(const Vector<CaptureDevice>& newDevices, const String& deviceIDHashSalt, EnumerateDevicesPromise&& promise)
196195
{
197-
auto* document = this->document();
198-
if (!document)
196+
if (isContextStopped())
199197
return;
200198

201-
bool canAccessCamera = checkCameraAccess(*document);
202-
bool canAccessMicrophone = checkMicrophoneAccess(*document);
203-
bool canAccessSpeaker = checkSpeakerAccess(*document);
199+
auto& document = *this->document();
200+
201+
bool canAccessCamera = checkCameraAccess(document);
202+
bool canAccessMicrophone = checkMicrophoneAccess(document);
203+
bool canAccessSpeaker = checkSpeakerAccess(document);
204204

205205
Vector<Ref<MediaDeviceInfo>> devices;
206206
for (auto& newDevice : newDevices) {
@@ -211,19 +211,12 @@ void MediaDevices::refreshDevices(const Vector<CaptureDevice>& newDevices)
211211
if (!canAccessSpeaker && newDevice.type() == CaptureDevice::DeviceType::Speaker)
212212
continue;
213213

214-
auto deviceKind = toMediaDeviceInfoKind(newDevice.type());
215-
auto index = m_devices.findMatching([deviceKind, &newDevice](auto& oldDevice) {
216-
return oldDevice->deviceId() == newDevice.persistentId() && oldDevice->kind() == deviceKind;
217-
});
218-
if (index != notFound) {
219-
devices.append(m_devices[index].copyRef());
220-
continue;
221-
}
214+
auto deviceId = RealtimeMediaSourceCenter::singleton().hashStringWithSalt(newDevice.persistentId(), deviceIDHashSalt);
215+
auto groupId = RealtimeMediaSourceCenter::singleton().hashStringWithSalt(newDevice.groupId(), m_groupIdHashSalt);
222216

223-
auto groupId = RealtimeMediaSourceCenter::singleton().hashStringWithSalt(newDevice.groupId(), m_idHashSalt);
224-
devices.append(MediaDeviceInfo::create(newDevice.label(), newDevice.persistentId(), WTFMove(groupId), deviceKind));
217+
devices.append(MediaDeviceInfo::create(newDevice.label(), WTFMove(deviceId), WTFMove(groupId), toMediaDeviceInfoKind(newDevice.type())));
225218
}
226-
m_devices = WTFMove(devices);
219+
promise.resolve(devices);
227220
}
228221

229222
void MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise)
@@ -245,12 +238,9 @@ void MediaDevices::enumerateDevices(EnumerateDevicesPromise&& promise)
245238
}
246239

247240
controller->enumerateMediaDevices(*document, [this, weakThis = makeWeakPtr(this), promise = WTFMove(promise)](const auto& newDevices, const auto& deviceIDHashSalt) mutable {
248-
if (!weakThis || isContextStopped())
241+
if (!weakThis)
249242
return;
250-
251-
this->document()->setDeviceIDHashSalt(deviceIDHashSalt);
252-
refreshDevices(newDevices);
253-
promise.resolve(m_devices);
243+
exposeDevices(newDevices, deviceIDHashSalt, WTFMove(promise));
254244
});
255245
}
256246

Source/WebCore/Modules/mediastream/MediaDevices.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class MediaDevices final : public RefCounted<MediaDevices>, public ActiveDOMObje
9898
void scheduledEventTimerFired();
9999
bool addEventListener(const AtomString& eventType, Ref<EventListener>&&, const AddEventListenerOptions&) override;
100100

101-
void refreshDevices(const Vector<CaptureDevice>&);
101+
void exposeDevices(const Vector<CaptureDevice>&, const String&, EnumerateDevicesPromise&&);
102102
void listenForDeviceChanges();
103103

104104
friend class JSMediaDevicesOwner;
@@ -126,8 +126,7 @@ class MediaDevices final : public RefCounted<MediaDevices>, public ActiveDOMObje
126126
const EventNames& m_eventNames; // Need to cache this so we can use it from GC threads.
127127
bool m_listeningForDeviceChanges { false };
128128

129-
Vector<Ref<MediaDeviceInfo>> m_devices;
130-
String m_idHashSalt;
129+
String m_groupIdHashSalt;
131130

132131
OptionSet<GestureAllowedRequest> m_requestTypesForCurrentGesture;
133132
WeakPtr<UserGestureToken> m_currentGestureToken;

Source/WebKit/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-09-18 Youenn Fablet <youenn@apple.com>
2+
3+
Hash deviceIds in WebProcess instead of UIProcess to allow audio output device IDs in WebProcess
4+
https://bugs.webkit.org/show_bug.cgi?id=216693
5+
6+
Reviewed by Eric Carlson.
7+
8+
* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
9+
(WebKit::UserMediaPermissionRequestManagerProxy::computeFilteredDeviceList):
10+
(WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame):
11+
* UIProcess/UserMediaPermissionRequestManagerProxy.h:
12+
113
2020-09-18 Youenn Fablet <youenn@apple.com>
214

315
Unified build fixes in media code

Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ static inline bool haveMicrophoneDevice(const Vector<WebCore::CaptureDevice>& de
605605
});
606606
}
607607

608-
Vector<CaptureDevice> UserMediaPermissionRequestManagerProxy::computeFilteredDeviceList(bool revealIdsAndLabels, const String& deviceIDHashSalt)
608+
Vector<CaptureDevice> UserMediaPermissionRequestManagerProxy::computeFilteredDeviceList(bool revealIdsAndLabels)
609609
{
610610
static const int defaultMaximumCameraCount = 1;
611611
static const int defaultMaximumMicrophoneCount = 1;
@@ -632,16 +632,7 @@ Vector<CaptureDevice> UserMediaPermissionRequestManagerProxy::computeFilteredDev
632632
continue;
633633
}
634634

635-
auto label = emptyString();
636-
auto id = emptyString();
637-
auto groupId = emptyString();
638-
if (revealIdsAndLabels) {
639-
label = device.label();
640-
id = RealtimeMediaSourceCenter::singleton().hashStringWithSalt(device.persistentId(), deviceIDHashSalt);
641-
groupId = RealtimeMediaSourceCenter::singleton().hashStringWithSalt(device.groupId(), deviceIDHashSalt);
642-
}
643-
644-
filteredDevices.append(CaptureDevice(id, device.type(), label, groupId));
635+
filteredDevices.append(revealIdsAndLabels ? device : CaptureDevice({ }, device.type(), { }, { }));
645636
}
646637

647638
m_hasFilteredDeviceList = !revealIdsAndLabels;
@@ -699,7 +690,7 @@ void UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame(Frame
699690
bool revealIdsAndLabels = originHasPersistentAccess || wasGrantedVideoOrAudioAccess(frameID, userMediaDocumentOrigin.get(), topLevelDocumentOrigin.get());
700691

701692
callCompletionHandler.release();
702-
completionHandler(computeFilteredDeviceList(revealIdsAndLabels, deviceIDHashSalt), deviceIDHashSalt);
693+
completionHandler(computeFilteredDeviceList(revealIdsAndLabels), deviceIDHashSalt);
703694
});
704695
};
705696

Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class UserMediaPermissionRequestManagerProxy
112112

113113
bool wasGrantedVideoOrAudioAccess(WebCore::FrameIdentifier, const WebCore::SecurityOrigin& userMediaDocumentOrigin, const WebCore::SecurityOrigin& topLevelDocumentOrigin);
114114

115-
Vector<WebCore::CaptureDevice> computeFilteredDeviceList(bool revealIdsAndLabels, const String& deviceIDHashSalt);
115+
Vector<WebCore::CaptureDevice> computeFilteredDeviceList(bool revealIdsAndLabels);
116116

117117
void processUserMediaPermissionRequest();
118118
void processUserMediaPermissionInvalidRequest(const String& invalidConstraint);

0 commit comments

Comments
 (0)