[GTK][WPE] Add mediaDevices.enumerateDevices support
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Oct 2018 10:26:52 +0000 (10:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Oct 2018 10:26:52 +0000 (10:26 +0000)
commit84049f81c40cd3ed4c267b9974013fc4d94f9a14
tree20dc6ec8d3bf4bfe37495aeab495abd18b9c1ffe
parentb8c79c72b9eff77fc74c697141442a950e3e596f
[GTK][WPE] Add mediaDevices.enumerateDevices support
https://bugs.webkit.org/show_bug.cgi?id=185761

Patch by Alejandro G. Castro <alex@igalia.com> on 2018-10-11
Reviewed by Youenn Fablet.

Source/WebCore:

We are adopting the same policy COCOA is using when returning the
list of media devices if the user does not have persistent
access. Namely, we just return the first media device for audio
and video capture.

* Modules/mediastream/MediaDevicesRequest.cpp:
(WebCore::MediaDevicesRequest::filterDeviceList): Add support for
other platforms when filtering devices if there is no persistent
access to the origin.

Source/WebKit:

Implemented the enumerateDevices API using a new WebKit class
(DeviceIdHashSaltStorage) that generates and stores the device ids
hash salts per origin, used to avoid fingerprinting in the
webpages.

The patch also adds a new type of data for the WebsiteDataStore.
That way the users can call the WebsiteDataStore to show what
origins have hash salt generated and remove them at some point.

For the moment just GTK+ and WPE ports are using this class to
generate the hash salts. The patch adds code to the
checkUserMediaPermissionForOrigin API implementation, it was empty
until now for these ports. In this function we create an instance
of a new class WebKitDeviceInfoPermissionRequest that implements
the WebKitPermissionRequestIface interface, that allows the ports
to use the current permission managers implemented in the
embedders to handle this new kind of request the way they like
it. The default implementation is deny.

The class WebKitDeviceInfoPermissionRequest takes care of
contacting the DeviceIdHashSaltStorage and request/regenerate the
hash salts accordingly.

Persistency is still not implemented, we will add it in a
future patch.

* Shared/WebsiteData/WebsiteDataType.h: Added the new type of
webside data: DeviceIdHashSalt.
* Sources.txt: Added new files to compilation.
* SourcesGTK.txt: Ditto.
* SourcesWPE.txt: Ditto.
* UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp: Added
this class to represent a request of permission to access the
devices information. This is specific for glib ports and implements
the policies regarding the hash salts when the embedder allows or
denies the access using the DeviceIdHashSaltStorage class.
(webkitDeviceInfoPermissionRequestAllow): Get the device hash salt
when the origin is allowed and set it in the original request.
(webkitDeviceInfoPermissionRequestDeny): Regenerate the device id
hash salt when the user does not allow to access the device information.
(webkit_permission_request_interface_init):
(webkitDeviceInfoPermissionRequestDispose):
(webkit_device_info_permission_request_class_init):
(webkitDeviceInfoPermissionRequestCreate): Create the class using
the proxy request from the webprocess and a reference to the
DeviceIdHashSaltStorage.
* UIProcess/API/glib/WebKitDeviceInfoPermissionRequestPrivate.h:
Ditto.
* UIProcess/API/glib/WebKitUIClient.cpp: Added the implementation
for the checkUserMediaPermissionForOrigin API for the glib ports,
it creates the device info request and calls the permission
request API.
* UIProcess/API/glib/WebKitWebsiteData.cpp:
(recordContainsSupportedDataTypes): Added the DeviceIdHashSalt
type.
(toWebKitWebsiteDataTypes): Added the conversion from the WebKit
types to the glib types for the WebsiteDataType::DeviceIdHashSalt.
* UIProcess/API/glib/WebKitWebsiteDataManager.cpp:
(toWebsiteDataTypes): Added the conversion from the glib type
WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT to the WebKit type.
(webkit_website_data_manager_remove): Make sure we remote the
DeviceIdHashSalt if the Cookies are selected.
* UIProcess/API/gtk/WebKitDeviceInfoPermissionRequest.h: Added
this new class that represents a permission request for the device
information in the GTK+ port.
* UIProcess/API/gtk/WebKitWebsiteData.h: Added the new type of
website that in the GTK+ port:
WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT.
* UIProcess/API/wpe/WebKitDeviceInfoPermissionRequest.h: Added
this new class that represents a permission request for the device
information in the WPE port.
* UIProcess/API/wpe/WebKitWebsiteData.h: Added the new type of
website that in the WPE port:
WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT.
* UIProcess/DeviceIdHashSaltStorage.cpp: Added this new class that
handles how to generate and store the hash salts inside
WebKit. Persistency is still not implemented, we will add it in a
future patch.
(WebKit::DeviceIdHashSaltStorage::create):
(WebKit::DeviceIdHashSaltStorage::deviceIdentifierHashSaltForOrigin):
Check the map to get the hash salt for an origin, if there is none
create a new random one.
(WebKit::DeviceIdHashSaltStorage::regenerateDeviceIdentifierHashSaltForOrigin):
Delete the hash salt of an origin if it already exists and create a new one.
(WebKit::DeviceIdHashSaltStorage::getDeviceIdHashSaltOrigins):
Returns the list of origins that have a hash salt generated for
them. It is used in the WebsiteDataStore.
(WebKit::DeviceIdHashSaltStorage::deleteDeviceIdHashSaltForOrigins):
Deletes the hash salts in the map for an origin.
(WebKit::DeviceIdHashSaltStorage::deleteDeviceIdHashSaltOriginsModifiedSince):
Delete the origins that have not been modified since a time.
* UIProcess/DeviceIdHashSaltStorage.h: Ditto.
* UIProcess/UserMediaPermissionCheckProxy.h: Remove uneeded class
definition.
* UIProcess/WebsiteData/WebsiteDataStore.cpp: Added support to
return and remove the origins with a generate hash salt used to
generate the device ids.
(WebKit::WebsiteDataStore::WebsiteDataStore): Added the new
reference to the DeviceIdHashSaltStorage class, used to handle the
hash salts.
(WebKit::WebsiteDataStore::fetchDataAndApply): Get the list of
origins with a hash salts in the DeviceIdHashSaltStorage.
(WebKit::WebsiteDataStore::removeData): Remove the hash salts in
DeviceIdHashSaltStorage for an origin.
* UIProcess/WebsiteData/WebsiteDataStore.h: Ditto.
(WebKit::WebsiteDataStore::deviceIdHashSaltStorage):
* WebKit.xcodeproj/project.pbxproj: Added the
DeviceIdHashSaltStorage to the compilation.

Tools:

Added new API test for the mediaDevices.enumerateDevices:
usermedia-enumeratedevices-permission-check. And a new API test
for the WebsiteDataStore: testWebsiteDataDeviceIdHashSalt.

* MiniBrowser/gtk/main.c:
(gotWebsiteDataCallback): Added a new section to the about:data
webpage to include the information about the hash salt.
* TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
(testWebViewUserMediaEnumerateDevicesPermissionCheck): Added the
new test checking the enumerateDevices API when permission is
denied and when permission is allowed for the origin.
(beforeAll): Defined the new test.
* TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp:
(serverCallback): Register a new URI for the enumerateDevices.
(testWebsiteDataConfiguration): Remove the hash salts from the
directories.
(testWebsiteDataDeviceIdHashSalt): New test cheking the
enumerateDevices API.
(beforeAll): Added the new test testWebsiteDataDeviceIdHashSalt to
the init structure.
* TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp:
(WebViewTest::initializeWebView): Make sure the media-stream is
activated in the webView.

LayoutTests:

Remove the failure expectation for the test
media-devices-enumerate-devices.html. Just for the record we have
also checked the following tests.

fast/mediastream/media-devices-enumerate-devices.html
fast/mediastream/resources/enumerate-devices-frame.html
http/tests/media/media-stream/enumerate-devices-source-id.html
http/tests/media/media-stream/enumerate-devices-source-id-persistent.html
http/tests/media/media-stream/resources/enumerate-devices-source-id-frame.html

* platform/gtk/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237031 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/gtk/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebsiteData/WebsiteDataType.h
Source/WebKit/Sources.txt
Source/WebKit/SourcesGTK.txt
Source/WebKit/SourcesWPE.txt
Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequestPrivate.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp
Source/WebKit/UIProcess/API/glib/WebKitWebsiteData.cpp
Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp
Source/WebKit/UIProcess/API/gtk/WebKitDeviceInfoPermissionRequest.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/gtk/WebKitWebsiteData.h
Source/WebKit/UIProcess/API/wpe/WebKitDeviceInfoPermissionRequest.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/wpe/WebKitWebsiteData.h
Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/DeviceIdHashSaltStorage.h [new file with mode: 0644]
Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.h
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Tools/ChangeLog
Tools/MiniBrowser/gtk/main.c
Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp
Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp
Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp