Bug 180206

Summary: [MediaStream] Use CaptureDevice instead of device ID to identify devices
Product: WebKit Reporter: Eric Carlson <eric.carlson>
Component: MediaAssignee: Eric Carlson <eric.carlson>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ews-watchlist, rniwa, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Proposed patch.
ews-watchlist: commit-queue-
Archive of layout-test-results from ews105 for mac-elcapitan-wk2
none
Updated patch.
none
Updated patch.
none
Patch for landing. none

Description Eric Carlson 2017-11-30 10:29:07 PST
Use CaptureDevice instead of device ID to identify devices when requesting user permission.
Comment 1 Radar WebKit Bug Importer 2017-11-30 10:29:48 PST
<rdar://problem/35775758>
Comment 2 Eric Carlson 2017-11-30 11:44:31 PST
Created attachment 328001 [details]
Proposed patch.
Comment 3 EWS Watchlist 2017-11-30 12:55:05 PST
Comment on attachment 328001 [details]
Proposed patch.

Attachment 328001 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5421399

New failing tests:
fast/mediastream/getUserMedia-grant-persistency.html
fast/mediastream/getUserMedia-grant-persistency2.html
http/tests/media/media-stream/get-user-media-prompt.html
Comment 4 EWS Watchlist 2017-11-30 12:55:06 PST
Created attachment 328008 [details]
Archive of layout-test-results from ews105 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 5 Eric Carlson 2017-11-30 13:53:30 PST
Created attachment 328018 [details]
Updated patch.
Comment 6 Eric Carlson 2017-11-30 14:13:17 PST
Created attachment 328025 [details]
Updated patch.
Comment 7 youenn fablet 2017-11-30 21:18:09 PST
Comment on attachment 328025 [details]
Updated patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=328025&action=review

> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:158
> +void UserMediaRequest::allow(std::optional<CaptureDevice>&& audioDevice, std::optional<CaptureDevice>&& videoDevice, String&& deviceIdentifierHashSalt)

An alternative to std::optional would be to consider that there is no CaptureDevice if CaptureDevice.persistentId is the null string or its type is none (i.e. default constructed CaptureDevice).
We could also have added an operator bool or helper method to know whether CaptureDevice was valid or not like optional has.
Not sure what is best, but optional is fine to me.

> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:162
> +    m_allowedVideoDevice = videoDevice;

We can probably move audioDevice/videoDevice.

> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:219
> +void UserMediaPermissionRequestManagerProxy::grantAccess(uint64_t userMediaID, std::optional<CaptureDevice> audioDevice, std::optional<CaptureDevice> videoDevice, const String& deviceIdentifierHashSalt)

Should be const std::optional<CaptureDevice>& probably.

> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:221
> +    UserMediaProcessManager::singleton().willCreateMediaStream(*this, audioDevice.has_value(), videoDevice.has_value());

could use !!audioDevice instead of has_value.

> Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.h:54
> +    const Vector<String> audioDeviceUIDs() const;

Can we use Vector<> instead of const Vector<>?
Comment 8 Eric Carlson 2017-12-01 09:19:30 PST
Comment on attachment 328025 [details]
Updated patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=328025&action=review

>> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:158
>> +void UserMediaRequest::allow(std::optional<CaptureDevice>&& audioDevice, std::optional<CaptureDevice>&& videoDevice, String&& deviceIdentifierHashSalt)
> 
> An alternative to std::optional would be to consider that there is no CaptureDevice if CaptureDevice.persistentId is the null string or its type is none (i.e. default constructed CaptureDevice).
> We could also have added an operator bool or helper method to know whether CaptureDevice was valid or not like optional has.
> Not sure what is best, but optional is fine to me.

Good idea. I added an operator bool that checks type != Unknown.

>> Source/WebCore/Modules/mediastream/UserMediaRequest.cpp:162
>> +    m_allowedVideoDevice = videoDevice;
> 
> We can probably move audioDevice/videoDevice.

That doesn't work because we have to WTFMove() the device parameters to RealtimeMediaSourceCenter::createMediaStream.

>> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:219
>> +void UserMediaPermissionRequestManagerProxy::grantAccess(uint64_t userMediaID, std::optional<CaptureDevice> audioDevice, std::optional<CaptureDevice> videoDevice, const String& deviceIdentifierHashSalt)
> 
> Should be const std::optional<CaptureDevice>& probably.

Fixed.

>> Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp:221
>> +    UserMediaProcessManager::singleton().willCreateMediaStream(*this, audioDevice.has_value(), videoDevice.has_value());
> 
> could use !!audioDevice instead of has_value.

I did that at first but changed to has_value at some point. Reconsidering, I think you are right.

>> Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.h:54
>> +    const Vector<String> audioDeviceUIDs() const;
> 
> Can we use Vector<> instead of const Vector<>?

Fixed.
Comment 9 Eric Carlson 2017-12-01 09:21:25 PST
Created attachment 328098 [details]
Patch for landing.
Comment 10 WebKit Commit Bot 2017-12-01 10:09:07 PST
Comment on attachment 328098 [details]
Patch for landing.

Clearing flags on attachment: 328098

Committed r225395: <https://trac.webkit.org/changeset/225395>