[MediaStream] deviceId constraint doesn't work with getUserMedia
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 14 May 2017 05:27:18 +0000 (05:27 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 14 May 2017 05:27:18 +0000 (05:27 +0000)
commit9352d7f093d9515af58d05c6b2f91879b23ccddb
tree5f6a4b74cd5e3dfc2b01a95cb76cb9af234f52bf
parentdae3b9df90307ea809d9d9b9642bfe9e4ac45dad
[MediaStream] deviceId constraint doesn't work with getUserMedia
https://bugs.webkit.org/show_bug.cgi?id=171877
<rdar://problem/31899730>

Reviewed by Jer Noble.

Source/WebCore:

Test: fast/mediastream/get-user-media-device-id.html

* Modules/mediastream/MediaConstraintsImpl.h:
(WebCore::MediaConstraintsData::MediaConstraintsData): Add a constructor that
takes a const MediaConstraints&.

* Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::~MediaDevices): m_deviceChangedToken is a std::optional<>.
* Modules/mediastream/MediaDevices.h:

* Modules/mediastream/MediaDevicesEnumerationRequest.cpp:
(WebCore::MediaDevicesEnumerationRequest::topLevelDocumentOrigin): Don't return
NULL for the main frame so the origin matches that returned for a UserMediaRequest.

* Modules/mediastream/UserMediaController.h:
(WebCore::UserMediaController::setDeviceIDHashSalt): Deleted, not used.
(WebCore::UserMediaController::deviceIDHashSalt): Deleted, not used.

* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::allow): Add device ID hash salt parameter, set it on
constraints.
* Modules/mediastream/UserMediaRequest.h:

* platform/mediastream/MediaConstraints.h:
* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::fitnessDistance): ASSERT if called for DeviceId.
(WebCore::RealtimeMediaSource::selectSettings): Special case DeviceId because it
we have to hash the device ID before comparing, and because the DeviceId can't be
changed so it should never be added to the flattened constraints.
(WebCore::RealtimeMediaSource::supportsConstraints):
(WebCore::RealtimeMediaSource::applyConstraints):
* platform/mediastream/RealtimeMediaSource.h:

* platform/mediastream/RealtimeMediaSourceCenter.cpp:
(WebCore::RealtimeMediaSourceCenter::validateRequestConstraints): Implement.
* platform/mediastream/RealtimeMediaSourceCenter.h:

* platform/mediastream/RealtimeMediaSourceSupportedConstraints.cpp:
(WebCore::RealtimeMediaSourceSupportedConstraints::nameForConstraint): Deleted, unused.
(WebCore::RealtimeMediaSourceSupportedConstraints::constraintFromName): Deleted, unused.
* platform/mediastream/RealtimeMediaSourceSupportedConstraints.h:

* platform/mediastream/mac/AVVideoCaptureSource.mm:
* platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp:
(WebCore::RealtimeMediaSourceCenterMac::bestSourcesForTypeAndConstraints): Pass device
id, not empty string.
(WebCore::RealtimeMediaSourceCenterMac::validateRequestConstraints): Deleted.
* platform/mediastream/mac/RealtimeMediaSourceCenterMac.h:

* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::MockRealtimeMediaSourceCenter::validateRequestConstraints): Deleted.
* platform/mock/MockRealtimeMediaSourceCenter.h:

Source/WebKit2:

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<MediaConstraintsData>::encode): Encode deviceIDHashSalt.
(IPC::ArgumentCoder<MediaConstraintsData>::decode): Decode deviceIDHashSalt.

* UIProcess/UserMediaPermissionCheckProxy.cpp:
(WebKit::UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy): Initialize
completion handler, frame ID, and security origins.
(WebKit::UserMediaPermissionCheckProxy::setUserMediaAccessInfo): Complete by calling
completion handler because we now sometimes request access info before calling gUM.
(WebKit::UserMediaPermissionCheckProxy::invalidate): Clear completion handler.
* UIProcess/UserMediaPermissionCheckProxy.h:

* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::FrameAuthorizationState::FrameAuthorizationState): Take security origins, not
UserMediaPermissionRequestProxy, so it can be constructed with a UserMediaPermissionCheckProxy.
(WebKit::FrameAuthorizationState::ensureSecurityOriginsAreEqual): Ditto. Clear has salt
when origins don't match.
(WebKit::UserMediaPermissionRequestManagerProxy::stateForRequest): Templatize.
(WebKit::UserMediaPermissionRequestManagerProxy::userMediaAccessWasDenied): Fix typo.
(WebKit::UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted): Ditto.
Don't set state for empty UIDs. Pass hash salt to web process.
(WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame):
The device ID hash salt is now required to validate constraints, so get it first.
(WebKit::UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo): Helper
method used to get the device ID hash salt.
(WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame): Restructure
to use getUserMediaPermissionInfo.
(WebKit::UserMediaPermissionRequestManagerProxy::didCompleteUserMediaPermissionCheck): Deleted.
* UIProcess/UserMediaPermissionRequestManagerProxy.h:

* WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp:
(WebKit::UserMediaPermissionRequestManager::userMediaAccessWasGranted): Add device ID
hash salt parameter.
* WebProcess/MediaStream/UserMediaPermissionRequestManager.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::userMediaAccessWasGranted): Ditto.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

* WebProcess/cocoa/UserMediaCaptureManager.cpp:
(WebKit::UserMediaCaptureManager::createCaptureSource): Use new MediaConstraintsData
constructor.

Tools:

The device ID hash salt is now required for getUserMedia to check deviceId constraint, so
implement the "checkUserMediaPermission" callback.
* TestWebKitAPI/Tests/WebKit2/UserMedia.cpp:
(TestWebKitAPI::decidePolicyForUserMediaPermissionRequestCallBack):
(TestWebKitAPI::checkUserMediaPermissionCallback):
(TestWebKitAPI::TEST):

* TestWebKitAPI/Tests/WebKit2Cocoa/UserMediaDisabled.mm:
(-[UserMediaUIDelegate _webView:checkUserMediaPermissionForURL:mainFrameURL:frameIdentifier:decisionHandler:]):

LayoutTests:

* fast/mediastream/get-user-media-device-id-expected.txt: Added.
* fast/mediastream/get-user-media-device-id.html: Added.
* fast/mediastream/apply-constraints-video-expected.txt: Updated.
* fast/mediastream/apply-constraints-video.html: Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@216836 268f45cc-cd09-0410-ab3c-d52691b4dbfc
41 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/apply-constraints-video-expected.txt
LayoutTests/fast/mediastream/apply-constraints-video.html
LayoutTests/fast/mediastream/get-user-media-device-id-expected.txt [new file with mode: 0644]
LayoutTests/fast/mediastream/get-user-media-device-id.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaConstraintsImpl.h
Source/WebCore/Modules/mediastream/MediaDevices.cpp
Source/WebCore/Modules/mediastream/MediaDevices.h
Source/WebCore/Modules/mediastream/MediaDevicesEnumerationRequest.cpp
Source/WebCore/Modules/mediastream/UserMediaController.h
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/Modules/mediastream/UserMediaRequest.h
Source/WebCore/platform/mediastream/MediaConstraints.h
Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSource.h
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h
Source/WebCore/platform/mediastream/RealtimeMediaSourceSupportedConstraints.cpp
Source/WebCore/platform/mediastream/RealtimeMediaSourceSupportedConstraints.h
Source/WebCore/platform/mediastream/mac/AVVideoCaptureSource.mm
Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.cpp
Source/WebCore/platform/mediastream/mac/RealtimeMediaSourceCenterMac.h
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.cpp
Source/WebKit2/UIProcess/UserMediaPermissionCheckProxy.h
Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp
Source/WebKit2/WebProcess/MediaStream/UserMediaPermissionRequestManager.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/cocoa/UserMediaCaptureManager.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2/UserMedia.cpp
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserMediaDisabled.mm