Title: [237031] trunk
Revision
237031
Author
[email protected]
Date
2018-10-11 03:26:52 -0700 (Thu, 11 Oct 2018)

Log Message

[GTK][WPE] Add mediaDevices.enumerateDevices support
https://bugs.webkit.org/show_bug.cgi?id=185761

Patch by Alejandro G. Castro <[email protected]> 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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237030 => 237031)


--- trunk/LayoutTests/ChangeLog	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/LayoutTests/ChangeLog	2018-10-11 10:26:52 UTC (rev 237031)
@@ -1,3 +1,22 @@
+2018-10-11  Alejandro G. Castro  <[email protected]>
+
+        [GTK][WPE] Add mediaDevices.enumerateDevices support
+        https://bugs.webkit.org/show_bug.cgi?id=185761
+
+        Reviewed by Youenn Fablet.
+
+        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:
+
 2018-10-10  Devin Rousso  <[email protected]>
 
         Web Inspector: create special Network waterfall for media events

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (237030 => 237031)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2018-10-11 10:26:52 UTC (rev 237031)
@@ -640,7 +640,6 @@
 webkit.org/b/151344 fast/mediastream/MediaStream-add-ended-tracks.html [ Timeout ]
 # Crash is bug #176801
 webkit.org/b/160996 fast/mediastream/MediaStream-video-element-video-tracks-disabled.html [ ImageOnlyFailure Crash ]
-webkit.org/b/172269 fast/mediastream/media-devices-enumerate-devices.html [ Failure ]
 webkit.org/b/173257 fast/mediastream/getUserMedia-grant-persistency3.html [ Pass Failure ]
 
 # Canvas captureStream support is not implemented

Modified: trunk/Source/WebCore/ChangeLog (237030 => 237031)


--- trunk/Source/WebCore/ChangeLog	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebCore/ChangeLog	2018-10-11 10:26:52 UTC (rev 237031)
@@ -1,3 +1,20 @@
+2018-10-11  Alejandro G. Castro  <[email protected]>
+
+        [GTK][WPE] Add mediaDevices.enumerateDevices support
+        https://bugs.webkit.org/show_bug.cgi?id=185761
+
+        Reviewed by Youenn Fablet.
+
+        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.
+
 2018-10-10  Chris Dumez  <[email protected]>
 
         Rename a couple of DOMWindowProperty virtual functions

Modified: trunk/Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp (237030 => 237031)


--- trunk/Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebCore/Modules/mediastream/MediaDevicesRequest.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -81,16 +81,12 @@
 
 void MediaDevicesRequest::filterDeviceList(Vector<Ref<MediaDeviceInfo>>& devices)
 {
-#if !PLATFORM(COCOA)
-    UNUSED_PARAM(devices);
-#else
-
 #if PLATFORM(IOS)
     static const int defaultCameraCount = 2;
-#endif
-#if PLATFORM(MAC)
+#else
     static const int defaultCameraCount = 1;
 #endif
+
     static const int defaultMicrophoneCount = 1;
 
     int cameraCount = 0;
@@ -103,8 +99,6 @@
 
         return false;
     });
-
-#endif
 }
 
 void MediaDevicesRequest::start()

Modified: trunk/Source/WebKit/ChangeLog (237030 => 237031)


--- trunk/Source/WebKit/ChangeLog	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/ChangeLog	2018-10-11 10:26:52 UTC (rev 237031)
@@ -1,3 +1,119 @@
+2018-10-11  Alejandro G. Castro  <[email protected]>
+
+        [GTK][WPE] Add mediaDevices.enumerateDevices support
+        https://bugs.webkit.org/show_bug.cgi?id=185761
+
+        Reviewed by Youenn Fablet.
+
+        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.
+
 2018-10-10  Tim Horton  <[email protected]>
 
         Safari crashes when attempting to share a YouTube video while in full-screen

Modified: trunk/Source/WebKit/Shared/WebsiteData/WebsiteDataType.h (237030 => 237031)


--- trunk/Source/WebKit/Shared/WebsiteData/WebsiteDataType.h	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/Shared/WebsiteData/WebsiteDataType.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -49,6 +49,7 @@
     ServiceWorkerRegistrations = 1 << 14,
 #endif
     DOMCache = 1 << 15,
+    DeviceIdHashSalt = 1 << 16,
 };
 
 };

Modified: trunk/Source/WebKit/Sources.txt (237030 => 237031)


--- trunk/Source/WebKit/Sources.txt	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/Sources.txt	2018-10-11 10:26:52 UTC (rev 237031)
@@ -228,6 +228,7 @@
 UIProcess/GeolocationPermissionRequestManagerProxy.cpp
 UIProcess/GeolocationPermissionRequestProxy.cpp
 UIProcess/PageLoadState.cpp
+UIProcess/DeviceIdHashSaltStorage.cpp
 UIProcess/ProcessAssertion.cpp
 UIProcess/ProcessThrottler.cpp
 UIProcess/RemoteWebInspectorProxy.cpp

Modified: trunk/Source/WebKit/SourcesGTK.txt (237030 => 237031)


--- trunk/Source/WebKit/SourcesGTK.txt	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/SourcesGTK.txt	2018-10-11 10:26:52 UTC (rev 237031)
@@ -133,6 +133,7 @@
 UIProcess/API/glib/WebKitCookieManager.cpp @no-unify
 UIProcess/API/glib/WebKitCredential.cpp @no-unify
 UIProcess/API/glib/WebKitCustomProtocolManagerClient.cpp @no-unify
+UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp @no-unify
 UIProcess/API/glib/WebKitDownload.cpp @no-unify
 UIProcess/API/glib/WebKitDownloadClient.cpp @no-unify
 UIProcess/API/glib/WebKitEditorState.cpp @no-unify

Modified: trunk/Source/WebKit/SourcesWPE.txt (237030 => 237031)


--- trunk/Source/WebKit/SourcesWPE.txt	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/SourcesWPE.txt	2018-10-11 10:26:52 UTC (rev 237031)
@@ -120,6 +120,7 @@
 UIProcess/API/glib/WebKitCookieManager.cpp @no-unify
 UIProcess/API/glib/WebKitCredential.cpp @no-unify
 UIProcess/API/glib/WebKitCustomProtocolManagerClient.cpp @no-unify
+UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp @no-unify
 UIProcess/API/glib/WebKitDownload.cpp @no-unify
 UIProcess/API/glib/WebKitDownloadClient.cpp @no-unify
 UIProcess/API/glib/WebKitEditorState.cpp @no-unify

Added: trunk/Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp (0 => 237031)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2018 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "WebKitDeviceInfoPermissionRequest.h"
+
+#include "DeviceIdHashSaltStorage.h"
+#include "UserMediaPermissionCheckProxy.h"
+#include "WebKitDeviceInfoPermissionRequestPrivate.h"
+#include "WebKitPermissionRequest.h"
+#include "WebsiteDataStore.h"
+#include <glib/gi18n-lib.h>
+#include <wtf/glib/WTFGType.h>
+
+using namespace WebKit;
+
+/**
+ * SECTION: WebKitDeviceInfoPermissionRequest
+ * @Short_description: A permission request for accessing user's audio/video devices.
+ * @Title: WebKitDeviceInfoPermissionRequest
+ * @See_also: #WebKitPermissionRequest, #WebKitWebView
+ *
+ * WebKitUserMediaPermissionRequest represents a request for
+ * permission to whether WebKit should be allowed to access the user's
+ * devices information when requested through the enumeraceDevices API.
+ *
+ * When a WebKitDeviceInfoPermissionRequest is not handled by the user,
+ * it is denied by default.
+ *
+ * Since: 2.22
+ */
+
+static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*);
+
+struct _WebKitDeviceInfoPermissionRequestPrivate {
+    RefPtr<UserMediaPermissionCheckProxy> request;
+    RefPtr<DeviceIdHashSaltStorage> deviceIdHashSaltStorage;
+    bool madeDecision;
+};
+
+WEBKIT_DEFINE_TYPE_WITH_CODE(
+    WebKitDeviceInfoPermissionRequest, webkit_device_info_permission_request, G_TYPE_OBJECT,
+    G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST, webkit_permission_request_interface_init))
+
+static void webkitDeviceInfoPermissionRequestAllow(WebKitPermissionRequest* request)
+{
+    ASSERT(WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST(request));
+
+    auto& priv = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(request)->priv;
+
+    if (!priv->deviceIdHashSaltStorage) {
+        priv->request->setUserMediaAccessInfo(String(), false);
+        return;
+    }
+
+    // Only one decision at a time.
+    if (priv->madeDecision)
+        return;
+
+    priv->madeDecision = true;
+    auto salt = priv->deviceIdHashSaltStorage->deviceIdHashSaltForOrigin(priv->request->topLevelDocumentSecurityOrigin());
+    priv->request->setUserMediaAccessInfo(WTFMove(salt), true);
+}
+
+static void webkitDeviceInfoPermissionRequestDeny(WebKitPermissionRequest* request)
+{
+    ASSERT(WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST(request));
+
+    auto& priv = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(request)->priv;
+
+    if (!priv->deviceIdHashSaltStorage) {
+        priv->request->setUserMediaAccessInfo(String(), false);
+        return;
+    }
+
+    // Only one decision at a time.
+    if (priv->madeDecision)
+        return;
+
+    priv->madeDecision = true;
+    auto salt = priv->deviceIdHashSaltStorage->regenerateDeviceIdHashSaltForOrigin(*priv->request);
+    priv->request->setUserMediaAccessInfo(WTFMove(salt), false);
+}
+
+static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface)
+{
+    iface->allow = webkitDeviceInfoPermissionRequestAllow;
+    iface->deny = webkitDeviceInfoPermissionRequestDeny;
+}
+
+static void webkitDeviceInfoPermissionRequestDispose(GObject* object)
+{
+    // Default behaviour when no decision has been made is denying the request.
+    webkitDeviceInfoPermissionRequestDeny(WEBKIT_PERMISSION_REQUEST(object));
+    G_OBJECT_CLASS(webkit_device_info_permission_request_parent_class)->dispose(object);
+}
+
+static void webkit_device_info_permission_request_class_init(WebKitDeviceInfoPermissionRequestClass* klass)
+{
+    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
+    objectClass->dispose = webkitDeviceInfoPermissionRequestDispose;
+}
+
+WebKitDeviceInfoPermissionRequest* webkitDeviceInfoPermissionRequestCreate(UserMediaPermissionCheckProxy& request, DeviceIdHashSaltStorage* deviceIdHashSaltStorage)
+{
+    auto* deviceInfoPermissionRequest = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, nullptr));
+
+    deviceInfoPermissionRequest->priv->request = &request;
+    deviceInfoPermissionRequest->priv->deviceIdHashSaltStorage = deviceIdHashSaltStorage;
+    return deviceInfoPermissionRequest;
+}

Added: trunk/Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequestPrivate.h (0 => 237031)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequestPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequestPrivate.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#pragma once
+
+#include "APISecurityOrigin.h"
+
+typedef struct _WebKitDeviceInfoPermissionRequest WebKitDeviceInfoPermissionRequest;
+
+namespace WebKit {
+class DeviceIdHashSaltStorage;
+};
+
+WebKitDeviceInfoPermissionRequest* webkitDeviceInfoPermissionRequestCreate(WebKit::UserMediaPermissionCheckProxy&, WebKit::DeviceIdHashSaltStorage*);

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -22,6 +22,7 @@
 
 #include "APIUIClient.h"
 #include "DrawingAreaProxy.h"
+#include "WebKitDeviceInfoPermissionRequestPrivate.h"
 #include "WebKitFileChooserRequestPrivate.h"
 #include "WebKitGeolocationPermissionRequestPrivate.h"
 #include "WebKitNavigationActionPrivate.h"
@@ -32,6 +33,7 @@
 #include "WebKitWindowPropertiesPrivate.h"
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
+#include "WebsiteDataStore.h"
 #include <wtf/glib/GRefPtr.h>
 
 #if PLATFORM(GTK)
@@ -189,6 +191,13 @@
         return true;
     }
 
+    bool checkUserMediaPermissionForOrigin(WebPageProxy& page, WebFrameProxy&, API::SecurityOrigin& userMediaDocumentOrigin, API::SecurityOrigin& topLevelDocumentOrigin, UserMediaPermissionCheckProxy& permissionRequest) override
+    {
+        auto deviceInfoPermissionRequest = adoptGRef(webkitDeviceInfoPermissionRequestCreate(permissionRequest, page.websiteDataStore().deviceIdHashSaltStorage()));
+        webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(deviceInfoPermissionRequest.get()));
+        return true;
+    }
+
     void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, Function<void(bool)>&& completionHandler) final
     {
         GRefPtr<WebKitNotificationPermissionRequest> notificationPermissionRequest = adoptGRef(webkitNotificationPermissionRequestCreate(NotificationPermissionRequest::create(WTFMove(completionHandler)).ptr()));

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteData.cpp (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteData.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteData.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -76,7 +76,8 @@
 #if ENABLE(NETSCAPE_PLUGIN_API)
         WebsiteDataType::PlugInData,
 #endif
-        WebsiteDataType::Cookies
+        WebsiteDataType::Cookies,
+        WebsiteDataType::DeviceIdHashSalt
     });
 }
 
@@ -103,6 +104,8 @@
 #endif
     if (types.contains(WebsiteDataType::Cookies))
         returnValue |= WEBKIT_WEBSITE_DATA_COOKIES;
+    if (types.contains(WebsiteDataType::DeviceIdHashSalt))
+        returnValue |= WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT;
     return static_cast<WebKitWebsiteDataTypes>(returnValue);
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -649,6 +649,8 @@
 #endif
     if (types & WEBKIT_WEBSITE_DATA_COOKIES)
         returnValue.add(WebsiteDataType::Cookies);
+    if (types & WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT)
+        returnValue.add(WebsiteDataType::DeviceIdHashSalt);
     return returnValue;
 }
 
@@ -732,7 +734,12 @@
     for (GList* item = websiteData; item; item = g_list_next(item)) {
         WebKitWebsiteData* data = ""
 
-        if (webkit_website_data_get_types(data) & types)
+        // We have to remove the hash salts when cookies are removed.
+        auto dataTypes = webkit_website_data_get_types(data);
+        if (dataTypes & WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT)
+            dataTypes = static_cast<WebKitWebsiteDataTypes>(dataTypes | WEBKIT_WEBSITE_DATA_COOKIES);
+
+        if (dataTypes & types)
             records.append(webkitWebsiteDataGetRecord(data));
     }
 

Added: trunk/Source/WebKit/UIProcess/API/gtk/WebKitDeviceInfoPermissionRequest.h (0 => 237031)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitDeviceInfoPermissionRequest.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitDeviceInfoPermissionRequest.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2018 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitDeviceInfoPermissionRequest_h
+#define WebKitDeviceInfoPermissionRequest_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST            (webkit_device_info_permission_request_get_type())
+#define WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, WebKitDeviceInfoPermissionRequest))
+#define WEBKIT_DEVICE_INFO_PERMISSION_REQUEST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, WebKitDeviceInfoPermissionRequestClass))
+#define WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST))
+#define WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST))
+#define WEBKIT_DEVICE_INFO_PERMISSION_REQUEST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, WebKitDeviceInfoPermissionRequestClass))
+
+typedef struct _WebKitDeviceInfoPermissionRequest        WebKitDeviceInfoPermissionRequest;
+typedef struct _WebKitDeviceInfoPermissionRequestClass   WebKitDeviceInfoPermissionRequestClass;
+typedef struct _WebKitDeviceInfoPermissionRequestPrivate WebKitDeviceInfoPermissionRequestPrivate;
+
+struct _WebKitDeviceInfoPermissionRequest {
+    GObject parent;
+
+    /*< private >*/
+    WebKitDeviceInfoPermissionRequestPrivate *priv;
+};
+
+struct _WebKitDeviceInfoPermissionRequestClass {
+    GObjectClass parent_class;
+
+    void (*_webkit_reserved0) (void);
+    void (*_webkit_reserved1) (void);
+    void (*_webkit_reserved2) (void);
+    void (*_webkit_reserved3) (void);
+};
+
+WEBKIT_API GType
+webkit_device_info_permission_request_get_type    (void);
+
+G_END_DECLS
+
+#endif

Modified: trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteData.h (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteData.h	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebsiteData.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -44,6 +44,7 @@
  * @WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES: IndexedDB databases.
  * @WEBKIT_WEBSITE_DATA_PLUGIN_DATA: Plugins data.
  * @WEBKIT_WEBSITE_DATA_COOKIES: Cookies.
+ * @WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT: Hash salt used to generate the device ids used by webpages.
  * @WEBKIT_WEBSITE_DATA_ALL: All types.
  *
  * Enum values with flags representing types of Website data.
@@ -60,7 +61,8 @@
     WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES       = 1 << 6,
     WEBKIT_WEBSITE_DATA_PLUGIN_DATA               = 1 << 7,
     WEBKIT_WEBSITE_DATA_COOKIES                   = 1 << 8,
-    WEBKIT_WEBSITE_DATA_ALL                       = (1 << 9) - 1
+    WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT       = 1 << 9,
+    WEBKIT_WEBSITE_DATA_ALL                       = (1 << 10) - 1
 } WebKitWebsiteDataTypes;
 
 WEBKIT_API GType

Added: trunk/Source/WebKit/UIProcess/API/wpe/WebKitDeviceInfoPermissionRequest.h (0 => 237031)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitDeviceInfoPermissionRequest.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitDeviceInfoPermissionRequest.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2018 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if !defined(__WEBKIT_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <wpe/webkit.h> can be included directly."
+#endif
+
+#ifndef WebKitDeviceInfoPermissionRequest_h
+#define WebKitDeviceInfoPermissionRequest_h
+
+#include <glib-object.h>
+#include <wpe/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST            (webkit_device_info_permission_request_get_type())
+#define WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, WebKitDeviceInfoPermissionRequest))
+#define WEBKIT_DEVICE_INFO_PERMISSION_REQUEST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, WebKitDeviceInfoPermissionRequestClass))
+#define WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST))
+#define WEBKIT_IS_DEVICE_INFO_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST))
+#define WEBKIT_DEVICE_INFO_PERMISSION_REQUEST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_DEVICE_INFO_PERMISSION_REQUEST, WebKitDeviceInfoPermissionRequestClass))
+
+typedef struct _WebKitDeviceInfoPermissionRequest        WebKitDeviceInfoPermissionRequest;
+typedef struct _WebKitDeviceInfoPermissionRequestClass   WebKitDeviceInfoPermissionRequestClass;
+typedef struct _WebKitDeviceInfoPermissionRequestPrivate WebKitDeviceInfoPermissionRequestPrivate;
+
+struct _WebKitDeviceInfoPermissionRequest {
+    GObject parent;
+
+    /*< private >*/
+    WebKitDeviceInfoPermissionRequestPrivate *priv;
+};
+
+struct _WebKitDeviceInfoPermissionRequestClass {
+    GObjectClass parent_class;
+
+    void (*_webkit_reserved0) (void);
+    void (*_webkit_reserved1) (void);
+    void (*_webkit_reserved2) (void);
+    void (*_webkit_reserved3) (void);
+};
+
+WEBKIT_API GType
+webkit_device_info_permission_request_get_type    (void);
+
+G_END_DECLS
+
+#endif

Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteData.h (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteData.h	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitWebsiteData.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -44,6 +44,7 @@
  * @WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES: IndexedDB databases.
  * @WEBKIT_WEBSITE_DATA_PLUGIN_DATA: Plugins data.
  * @WEBKIT_WEBSITE_DATA_COOKIES: Cookies.
+ * @WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT: Hash salt used to generate the device ids used by webpages.
  * @WEBKIT_WEBSITE_DATA_ALL: All types.
  *
  * Enum values with flags representing types of Website data.
@@ -60,7 +61,8 @@
     WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES       = 1 << 6,
     WEBKIT_WEBSITE_DATA_PLUGIN_DATA               = 1 << 7,
     WEBKIT_WEBSITE_DATA_COOKIES                   = 1 << 8,
-    WEBKIT_WEBSITE_DATA_ALL                       = (1 << 9) - 1
+    WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT       = 1 << 9,
+    WEBKIT_WEBSITE_DATA_ALL                       = (1 << 10) - 1
 } WebKitWebsiteDataTypes;
 
 WEBKIT_API GType

Added: trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp (0 => 237031)


--- trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2018 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DeviceIdHashSaltStorage.h"
+
+#include <WebCore/FileSystem.h>
+#include <wtf/CryptographicallyRandomNumber.h>
+#include <wtf/HexNumber.h>
+#include <wtf/RunLoop.h>
+#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringHash.h>
+
+// FIXME: Implement persistency.
+
+namespace WebKit {
+using namespace WebCore;
+
+static const int hashSaltSize = 48;
+static const int randomDataSize = hashSaltSize / 16;
+
+Ref<DeviceIdHashSaltStorage> DeviceIdHashSaltStorage::create()
+{
+    return adoptRef(*new DeviceIdHashSaltStorage());
+}
+
+const String& DeviceIdHashSaltStorage::regenerateDeviceIdHashSaltForOrigin(UserMediaPermissionCheckProxy& request)
+{
+    auto& documentOrigin = request.topLevelDocumentSecurityOrigin();
+
+    auto documentOriginData = documentOrigin.data();
+    m_deviceIdHashSaltForOrigins.removeIf([&documentOriginData](auto& keyAndValue) {
+        return keyAndValue.value->documentOrigin == documentOriginData;
+    });
+
+    return deviceIdHashSaltForOrigin(documentOrigin);
+}
+
+const String& DeviceIdHashSaltStorage::deviceIdHashSaltForOrigin(SecurityOrigin& documentOrigin)
+{
+    auto& deviceIdHashSalt = m_deviceIdHashSaltForOrigins.ensure(documentOrigin.toRawString(), [&documentOrigin] () {
+        uint64_t randomData[randomDataSize];
+        cryptographicallyRandomValues(reinterpret_cast<unsigned char*>(randomData), sizeof(randomData));
+
+        StringBuilder builder;
+        builder.reserveCapacity(hashSaltSize);
+        for (int i = 0; i < randomDataSize; i++)
+            appendUnsigned64AsHex(randomData[0], builder);
+
+        String deviceIdHashSalt = builder.toString();
+
+        return std::make_unique<HashSaltForOrigin>(documentOrigin.data().isolatedCopy(), WTFMove(deviceIdHashSalt));
+    }).iterator->value;
+
+    deviceIdHashSalt->lastTimeUsed = WallTime::now();
+
+    return deviceIdHashSalt->deviceIdHashSalt;
+}
+
+void DeviceIdHashSaltStorage::getDeviceIdHashSaltOrigins(CompletionHandler<void(HashSet<SecurityOriginData>&&)>&& completionHandler)
+{
+    HashSet<SecurityOriginData> origins;
+
+    for (auto& hashSaltForOrigin : m_deviceIdHashSaltForOrigins)
+        origins.add(hashSaltForOrigin.value->documentOrigin);
+
+    RunLoop::main().dispatch([origins = WTFMove(origins), completionHandler = WTFMove(completionHandler)]() mutable {
+        completionHandler(WTFMove(origins));
+    });
+}
+
+void DeviceIdHashSaltStorage::deleteDeviceIdHashSaltForOrigins(const Vector<SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)
+{
+    m_deviceIdHashSaltForOrigins.removeIf([&origins](auto& keyAndValue) {
+        return origins.contains(keyAndValue.value->documentOrigin);
+    });
+
+    RunLoop::main().dispatch(WTFMove(completionHandler));
+}
+
+void DeviceIdHashSaltStorage::deleteDeviceIdHashSaltOriginsModifiedSince(WallTime time, CompletionHandler<void()>&& completionHandler)
+{
+    m_deviceIdHashSaltForOrigins.removeIf([time](auto& keyAndValue) {
+        return keyAndValue.value->lastTimeUsed > time;
+    });
+
+    RunLoop::main().dispatch(WTFMove(completionHandler));
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.h (0 => 237031)


--- trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2018 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "UserMediaPermissionCheckProxy.h"
+#include <WebCore/SecurityOrigin.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/Ref.h>
+
+namespace WebKit {
+
+class DeviceIdHashSaltStorage : public RefCounted<DeviceIdHashSaltStorage> {
+public:
+    static Ref<DeviceIdHashSaltStorage> create();
+    ~DeviceIdHashSaltStorage() = default;
+
+    const String& deviceIdHashSaltForOrigin(WebCore::SecurityOrigin&);
+    const String& regenerateDeviceIdHashSaltForOrigin(UserMediaPermissionCheckProxy&);
+
+    void getDeviceIdHashSaltOrigins(CompletionHandler<void(HashSet<WebCore::SecurityOriginData>&&)>&&);
+    void deleteDeviceIdHashSaltForOrigins(const Vector<WebCore::SecurityOriginData>&, CompletionHandler<void()>&&);
+    void deleteDeviceIdHashSaltOriginsModifiedSince(WallTime, CompletionHandler<void()>&&);
+
+private:
+    struct HashSaltForOrigin {
+        HashSaltForOrigin(WebCore::SecurityOriginData&& securityOrigin, String&& deviceIdHashSalt)
+            : documentOrigin(securityOrigin)
+            , deviceIdHashSalt(WTFMove(deviceIdHashSalt))
+            , lastTimeUsed(WallTime::now())
+        { };
+
+        WebCore::SecurityOriginData documentOrigin;
+        String deviceIdHashSalt;
+        WallTime lastTimeUsed;
+    };
+
+    DeviceIdHashSaltStorage() = default;
+
+    HashMap<String, std::unique_ptr<HashSaltForOrigin>> m_deviceIdHashSaltForOrigins;
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.h (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.h	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -36,8 +36,6 @@
 
 namespace WebKit {
 
-class UserMediaPermissionRequestManagerProxy;
-
 class UserMediaPermissionCheckProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionCheck> {
 public:
 

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -30,6 +30,7 @@
 #include "APIWebsiteDataRecord.h"
 #include "APIWebsiteDataStore.h"
 #include "AuthenticatorManager.h"
+#include "DeviceIdHashSaltStorage.h"
 #include "MockAuthenticatorManager.h"
 #include "NetworkProcessMessages.h"
 #include "StorageManager.h"
@@ -95,6 +96,7 @@
     : m_sessionID(sessionID)
     , m_configuration(WTFMove(configuration))
     , m_storageManager(StorageManager::create(m_configuration.localStorageDirectory))
+    , m_deviceIdHashSaltStorage(DeviceIdHashSaltStorage::create())
     , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
 #if ENABLE(WEB_AUTHN)
     , m_authenticatorManager(makeUniqueRef<AuthenticatorManager>())
@@ -485,6 +487,19 @@
         });
     }
 
+    if (m_deviceIdHashSaltStorage && dataTypes.contains(WebsiteDataType::DeviceIdHashSalt)) {
+        callbackAggregator->addPendingCallback();
+
+        m_deviceIdHashSaltStorage->getDeviceIdHashSaltOrigins([callbackAggregator](auto&& origins) {
+            WebsiteData websiteData;
+
+            while (!origins.isEmpty())
+                websiteData.entries.append(WebsiteData::Entry { origins.takeAny(), WebsiteDataType::DeviceIdHashSalt, 0 });
+
+            callbackAggregator->removePendingCallback(WTFMove(websiteData));
+        });
+    }
+
     if (dataTypes.contains(WebsiteDataType::OfflineWebApplicationCache) && isPersistent()) {
         callbackAggregator->addPendingCallback();
 
@@ -800,6 +815,14 @@
         });
     }
 
+    if (m_deviceIdHashSaltStorage && (dataTypes.contains(WebsiteDataType::DeviceIdHashSalt) || (dataTypes.contains(WebsiteDataType::Cookies)))) {
+        callbackAggregator->addPendingCallback();
+
+        m_deviceIdHashSaltStorage->deleteDeviceIdHashSaltOriginsModifiedSince(modifiedSince, [callbackAggregator] {
+            callbackAggregator->removePendingCallback();
+        });
+    }
+
     if (dataTypes.contains(WebsiteDataType::OfflineWebApplicationCache) && isPersistent()) {
         callbackAggregator->addPendingCallback();
 
@@ -1074,6 +1097,14 @@
         });
     }
 
+    if (m_deviceIdHashSaltStorage && (dataTypes.contains(WebsiteDataType::DeviceIdHashSalt) || (dataTypes.contains(WebsiteDataType::Cookies)))) {
+        callbackAggregator->addPendingCallback();
+
+        m_deviceIdHashSaltStorage->deleteDeviceIdHashSaltForOrigins(origins, [callbackAggregator] {
+            callbackAggregator->removePendingCallback();
+        });
+    }
+
     if (dataTypes.contains(WebsiteDataType::OfflineWebApplicationCache) && isPersistent()) {
         HashSet<WebCore::SecurityOriginData> origins;
         for (const auto& dataRecord : dataRecords) {

Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h (237030 => 237031)


--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h	2018-10-11 10:26:52 UTC (rev 237031)
@@ -55,6 +55,7 @@
 class AuthenticatorManager;
 class SecKeyProxyStore;
 class StorageManager;
+class DeviceIdHashSaltStorage;
 class WebPageProxy;
 class WebProcessPool;
 class WebResourceLoadStatisticsStore;
@@ -92,6 +93,7 @@
         String webSQLDatabaseDirectory;
         String localStorageDirectory;
         String mediaKeysStorageDirectory;
+        String deviceIdHashSaltsStorageDirectory;
         String resourceLoadStatisticsDirectory;
         String _javascript_ConfigurationDirectory;
         String cookieStorageFile;
@@ -161,6 +163,8 @@
 
     StorageManager* storageManager() { return m_storageManager.get(); }
 
+    DeviceIdHashSaltStorage* deviceIdHashSaltStorage() { return m_deviceIdHashSaltStorage.get(); }
+
     WebProcessPool* processPoolForCookieStorageOperations();
     bool isAssociatedProcessPool(WebProcessPool&) const;
 
@@ -235,6 +239,7 @@
     bool m_hasResolvedDirectories { false };
 
     const RefPtr<StorageManager> m_storageManager;
+    const RefPtr<DeviceIdHashSaltStorage> m_deviceIdHashSaltStorage;
     RefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics;
     bool m_resourceLoadStatisticsDebugMode { false };
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (237030 => 237031)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2018-10-11 10:26:52 UTC (rev 237031)
@@ -76,6 +76,7 @@
 		00B9661618E24CBA00CE1F88 /* APIFindClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 00B9661518E24CBA00CE1F88 /* APIFindClient.h */; };
 		00B9661A18E25AE100CE1F88 /* FindClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 00B9661818E25AE100CE1F88 /* FindClient.h */; };
 		07297F9F1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 07297F9D1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.h */; };
+		07297F9F1C17BBEA015F0735 /* DeviceIdHashSaltStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 07297F9D1C17BBEA223F0735 /* DeviceIdHashSaltStorage.h */; };
 		07297FA31C186ADB003F0735 /* WKUserMediaPermissionCheck.h in Headers */ = {isa = PBXBuildFile; fileRef = 07297FA11C186ADB003F0735 /* WKUserMediaPermissionCheck.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		074E75FE1DF2211900D318EC /* UserMediaProcessManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 074E75FB1DF1FD1300D318EC /* UserMediaProcessManager.h */; };
 		076E884E1A13CADF005E90FC /* APIContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 076E884D1A13CADF005E90FC /* APIContextMenuClient.h */; };
@@ -1834,6 +1835,8 @@
 		00B9661818E25AE100CE1F88 /* FindClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FindClient.h; sourceTree = "<group>"; };
 		07297F9C1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMediaPermissionCheckProxy.cpp; sourceTree = "<group>"; };
 		07297F9D1C17BBEA003F0735 /* UserMediaPermissionCheckProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMediaPermissionCheckProxy.h; sourceTree = "<group>"; };
+		07297F9C1C1711EA003F0735 /* DeviceIdHashSaltStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceIdHashSaltStorage.cpp; sourceTree = "<group>"; };
+		07297F9D1C17BBEA223F0735 /* DeviceIdHashSaltStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceIdHashSaltStorage.h; sourceTree = "<group>"; };
 		07297FA01C186ADB003F0735 /* WKUserMediaPermissionCheck.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserMediaPermissionCheck.cpp; sourceTree = "<group>"; };
 		07297FA11C186ADB003F0735 /* WKUserMediaPermissionCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserMediaPermissionCheck.h; sourceTree = "<group>"; };
 		074E75FB1DF1FD1300D318EC /* UserMediaProcessManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMediaProcessManager.h; sourceTree = "<group>"; };
@@ -7185,6 +7188,8 @@
 				46A2B6071E5675A200C3DEDA /* BackgroundProcessResponsivenessTimer.h */,
 				E1513C64166EABB200149FCB /* ChildProcessProxy.cpp */,
 				E1513C65166EABB200149FCB /* ChildProcessProxy.h */,
+				07297F9C1C1711EA003F0735 /* DeviceIdHashSaltStorage.cpp */,
+				07297F9D1C17BBEA223F0735 /* DeviceIdHashSaltStorage.h */,
 				BC2652121182608100243E12 /* DrawingAreaProxy.cpp */,
 				BC2652131182608100243E12 /* DrawingAreaProxy.h */,
 				1A6422FC12DD08FE00CAAE2C /* DrawingAreaProxy.messages.in */,
@@ -8857,6 +8862,7 @@
 				1AC75380183BE50F0072CB15 /* DataReference.h in Headers */,
 				BC032DA610F437D10058C15A /* Decoder.h in Headers */,
 				57DCEDAB214C60090016B847 /* DeviceIdentitySPI.h in Headers */,
+				07297F9F1C17BBEA015F0735 /* DeviceIdHashSaltStorage.h in Headers */,
 				83891B6C1A68C30B0030F386 /* DiagnosticLoggingClient.h in Headers */,
 				C18173612058424700DFDA65 /* DisplayLink.h in Headers */,
 				5C1427021C23F84C00D41183 /* Download.h in Headers */,
@@ -10594,6 +10600,7 @@
 				2D92A77D212B6A7100F493FD /* Connection.cpp in Sources */,
 				2D92A77E212B6A7100F493FD /* DataReference.cpp in Sources */,
 				2D92A77F212B6A7100F493FD /* Decoder.cpp in Sources */,
+				07297F9E1C17BBEA014F0735 /* DeviceIdHashSaltStorage.cpp in Sources */,
 				1AB7D6191288B9D900CFD08C /* DownloadProxyMessageReceiver.cpp in Sources */,
 				1A64229912DD029200CAAE2C /* DrawingAreaMessageReceiver.cpp in Sources */,
 				1A64230812DD09EB00CAAE2C /* DrawingAreaProxyMessageReceiver.cpp in Sources */,

Modified: trunk/Tools/ChangeLog (237030 => 237031)


--- trunk/Tools/ChangeLog	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Tools/ChangeLog	2018-10-11 10:26:52 UTC (rev 237031)
@@ -1,3 +1,34 @@
+2018-10-11  Alejandro G. Castro  <[email protected]>
+
+        [GTK][WPE] Add mediaDevices.enumerateDevices support
+        https://bugs.webkit.org/show_bug.cgi?id=185761
+
+        Reviewed by Youenn Fablet.
+
+        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.
+
 2018-10-10  Fujii Hironori  <[email protected]>
 
         Add WinCairo to the flakiness dashboard

Modified: trunk/Tools/MiniBrowser/gtk/main.c (237030 => 237031)


--- trunk/Tools/MiniBrowser/gtk/main.c	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Tools/MiniBrowser/gtk/main.c	2018-10-11 10:26:52 UTC (rev 237031)
@@ -402,6 +402,7 @@
 
     guint64 pageID = webkit_web_view_get_page_id(webkit_uri_scheme_request_get_web_view(dataRequest->request));
     aboutDataFillTable(result, dataRequest, dataList, "Cookies", WEBKIT_WEBSITE_DATA_COOKIES, NULL, pageID);
+    aboutDataFillTable(result, dataRequest, dataList, "Device Id Hash Salt", WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT, NULL, pageID);
     aboutDataFillTable(result, dataRequest, dataList, "Memory Cache", WEBKIT_WEBSITE_DATA_MEMORY_CACHE, NULL, pageID);
     aboutDataFillTable(result, dataRequest, dataList, "Disk Cache", WEBKIT_WEBSITE_DATA_DISK_CACHE, webkit_website_data_manager_get_disk_cache_directory(manager), pageID);
     aboutDataFillTable(result, dataRequest, dataList, "Session Storage", WEBKIT_WEBSITE_DATA_SESSION_STORAGE, NULL, pageID);

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp (237030 => 237031)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -834,6 +834,47 @@
 #endif // ENABLE(GEOLOCATION)
 
 #if ENABLE(MEDIA_STREAM)
+static void testWebViewUserMediaEnumerateDevicesPermissionCheck(UIClientTest* test, gconstpointer)
+{
+    WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView);
+    gboolean enabled = webkit_settings_get_enable_media_stream(settings);
+    webkit_settings_set_enable_media_stream(settings, TRUE);
+
+#if PLATFORM(GTK)
+    test->showInWindowAndWaitUntilMapped();
+#endif
+    static const char* userMediaRequestHTML =
+        "<html>"
+        "  <script>"
+        "  function runTest()"
+        "  {"
+        "    navigator.mediaDevices.enumerateDevices().then("
+        "        function(devices) { "
+        "            devices.forEach(function(device) {"
+        "                                if (device.label) document.title = \"OK\";"
+        "                                             else document.title = \"Permission denied\";"
+        "            })"
+        "    })"
+        "  }"
+        "  </script>"
+        "  <body _onload_='runTest();'></body>"
+        "</html>";
+
+    test->m_verifyMediaTypes = TRUE;
+
+    // Test denying a permission request.
+    test->m_allowPermissionRequests = false;
+    test->loadHtml(userMediaRequestHTML, nullptr);
+    test->waitUntilTitleChangedTo("Permission denied");
+
+    // Test allowing a permission request.
+    test->m_allowPermissionRequests = true;
+    test->loadHtml(userMediaRequestHTML, nullptr);
+    test->waitUntilTitleChangedTo("OK");
+
+    webkit_settings_set_enable_media_stream(settings, enabled);
+}
+
 static void testWebViewUserMediaPermissionRequests(UIClientTest* test, gconstpointer)
 {
     WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView);
@@ -1156,6 +1197,7 @@
     UIClientTest::add("WebKitWebView", "geolocation-permission-requests", testWebViewGeolocationPermissionRequests);
 #endif
 #if ENABLE(MEDIA_STREAM)
+    UIClientTest::add("WebKitWebView", "usermedia-enumeratedevices-permission-check", testWebViewUserMediaEnumerateDevicesPermissionCheck);
     UIClientTest::add("WebKitWebView", "usermedia-permission-requests", testWebViewUserMediaPermissionRequests);
     UIClientTest::add("WebKitWebView", "audio-usermedia-permission-request", testWebViewAudioOnlyUserMediaPermissionRequests);
 #endif

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp (237030 => 237031)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -21,6 +21,7 @@
 
 #include "WebKitTestServer.h"
 #include "WebViewTest.h"
+#include <glib/gstdio.h>
 
 static WebKitTestServer* kServer;
 
@@ -61,6 +62,11 @@
         soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, localStorageHTML, strlen(localStorageHTML));
         soup_message_body_complete(message->response_body);
         soup_message_set_status(message, SOUP_STATUS_OK);
+    } else if (g_str_equal(path, "/enumeratedevices")) {
+        const char* enumerateDevicesHTML = "<html><body _onload_=\"navigator.mediaDevices.enumerateDevices().then(function(devices) { document.title = 'Finished'; })\"></body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, enumerateDevicesHTML, strlen(enumerateDevicesHTML));
+        soup_message_body_complete(message->response_body);
+        soup_message_set_status(message, SOUP_STATUS_OK);
     } else
         soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
 }
@@ -163,7 +169,7 @@
 
     // Clear all persistent caches, since the data dir is common to all test cases.
     static const WebKitWebsiteDataTypes persistentCaches = static_cast<WebKitWebsiteDataTypes>(WEBKIT_WEBSITE_DATA_DISK_CACHE | WEBKIT_WEBSITE_DATA_LOCAL_STORAGE
-        | WEBKIT_WEBSITE_DATA_WEBSQL_DATABASES | WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES | WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE);
+        | WEBKIT_WEBSITE_DATA_WEBSQL_DATABASES | WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES | WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE | WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
     test->clear(persistentCaches, 0);
     g_assert(!test->fetch(persistentCaches));
 
@@ -517,6 +523,53 @@
     g_assert(!dataList);
 }
 
+static void testWebsiteDataDeviceIdHashSalt(WebsiteDataTest* test, gconstpointer)
+{
+    test->clear(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT, 0);
+
+    GList* dataList = test->fetch(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+    g_assert(!dataList);
+
+    test->loadURI(kServer->getURIForPath("/enumeratedevices").data());
+    test->waitUntilTitleChangedTo("Finished");
+
+    dataList = test->fetch(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+    g_assert(dataList);
+
+    g_assert_cmpuint(g_list_length(dataList), ==, 1);
+    WebKitWebsiteData* data = ""
+    g_assert(data);
+    WebKitSecurityOrigin* origin = webkit_security_origin_new_for_uri(kServer->getURIForPath("/").data());
+    g_assert_cmpstr(webkit_website_data_get_name(data), ==, webkit_security_origin_get_host(origin));
+    webkit_security_origin_unref(origin);
+    g_assert_cmpuint(webkit_website_data_get_types(data), ==, WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+
+    GList removeList = { data, nullptr, nullptr };
+    test->remove(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT, &removeList);
+    dataList = test->fetch(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+    g_assert(!dataList);
+
+    // Test removing the cookies.
+    test->loadURI(kServer->getURIForPath("/enumeratedevices").data());
+    test->waitUntilTitleChangedTo("Finished");
+
+    dataList = test->fetch(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+    g_assert(dataList);
+    data = ""
+    g_assert(data);
+
+    GList removeCookieList = { data, nullptr, nullptr };
+    test->remove(WEBKIT_WEBSITE_DATA_COOKIES, &removeCookieList);
+    dataList = test->fetch(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+    g_assert(!dataList);
+
+    // Clear all.
+    static const WebKitWebsiteDataTypes cacheAndAppcacheTypes = static_cast<WebKitWebsiteDataTypes>(WEBKIT_WEBSITE_DATA_DEVICE_ID_HASH_SALT);
+    test->clear(cacheAndAppcacheTypes, 0);
+    dataList = test->fetch(cacheAndAppcacheTypes);
+    g_assert(!dataList);
+}
+
 void beforeAll()
 {
     kServer = new WebKitTestServer();
@@ -529,6 +582,7 @@
     WebsiteDataTest::add("WebKitWebsiteData", "databases", testWebsiteDataDatabases);
     WebsiteDataTest::add("WebKitWebsiteData", "appcache", testWebsiteDataAppcache);
     WebsiteDataTest::add("WebKitWebsiteData", "cookies", testWebsiteDataCookies);
+    WebsiteDataTest::add("WebKitWebsiteData", "deviceidhashsalt", testWebsiteDataDeviceIdHashSalt);
 }
 
 void afterAll()

Modified: trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp (237030 => 237031)


--- trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp	2018-10-11 05:10:58 UTC (rev 237030)
+++ trunk/Tools/TestWebKitAPI/glib/WebKitGLib/WebViewTest.cpp	2018-10-11 10:26:52 UTC (rev 237031)
@@ -48,10 +48,15 @@
 void WebViewTest::initializeWebView()
 {
     g_assert(!m_webView);
+
+    WebKitSettings* webkitSettings = webkit_settings_new();
+    webkit_settings_set_enable_media_stream(webkitSettings, TRUE);
+
     m_webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW,
 #if PLATFORM(WPE)
         "backend", Test::createWebViewBackend(),
 #endif
+        "settings", webkitSettings,
         "web-context", m_webContext.get(),
         "user-content-manager", m_userContentManager.get(),
         nullptr));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to