[MediaStream] Use DeviceIdHashSaltStorage to generate device ID hash salt
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 15:53:43 +0000 (15:53 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 15:53:43 +0000 (15:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190825
<rdar://problem/45486085>

Source/WebKit:

Reviewed by Youenn Fablet.

* UIProcess/API/C/WKUserMediaPermissionCheck.cpp:
(WKUserMediaPermissionCheckSetUserMediaAccessInfo):
* UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp:
(webkitDeviceInfoPermissionRequestAllow):
(webkitDeviceInfoPermissionRequestDeny):
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::checkUserMediaPermissionForOrigin):
* UIProcess/DeviceIdHashSaltStorage.cpp:
(WebKit::DeviceIdHashSaltStorage::regenerateDeviceIdHashSaltForOrigin):
(WebKit::DeviceIdHashSaltStorage::deleteDeviceIdHashSaltForOrigin):
* UIProcess/DeviceIdHashSaltStorage.h:
* UIProcess/UserMediaPermissionCheckProxy.cpp:
(WebKit::UserMediaPermissionCheckProxy::setUserMediaAccessInfo):
* UIProcess/UserMediaPermissionCheckProxy.h:
* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::createPermissionRequest):
(WebKit::UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted):
(WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame):
(WebKit::UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo):
(WebKit::UserMediaPermissionRequestManagerProxy::updateDeviceIDHashSalt):
(WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame):
* UIProcess/UserMediaPermissionRequestManagerProxy.h:
* UIProcess/UserMediaPermissionRequestProxy.cpp:
(WebKit::UserMediaPermissionRequestProxy::UserMediaPermissionRequestProxy):
* UIProcess/UserMediaPermissionRequestProxy.h:
(WebKit::UserMediaPermissionRequestProxy::create):
(WebKit::UserMediaPermissionRequestProxy::deviceIdentifierHashSalt const): Deleted.

LayoutTests:

Update enumerate-devices-source-id to expect the same device to have the same ID in all
iframes, remove enumerate-devices-source-id-persistent because the logic was faulty.

Reviewed by Youenn Fablet.

* TestExpectations: Unskip http/tests/media/media-stream/enumerate-devices-source-id.html
* http/tests/media/media-stream/enumerate-devices-source-id-expected.txt:
* http/tests/media/media-stream/enumerate-devices-source-id-persistent-expected.txt: Removed.
* http/tests/media/media-stream/enumerate-devices-source-id-persistent.html: Removed.
* http/tests/media/media-stream/enumerate-devices-source-id.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237988 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-expected.txt
LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-persistent-expected.txt [deleted file]
LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-persistent.html [deleted file]
LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id.html
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/WKUserMediaPermissionCheck.cpp
Source/WebKit/UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp
Source/WebKit/UIProcess/DeviceIdHashSaltStorage.h
Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.h
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h
Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.h

index d5ae09e..bf82c05 100644 (file)
@@ -1,3 +1,20 @@
+2018-11-08  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Use DeviceIdHashSaltStorage to generate device ID hash salt
+        https://bugs.webkit.org/show_bug.cgi?id=190825
+        <rdar://problem/45486085>
+
+        Update enumerate-devices-source-id to expect the same device to have the same ID in all
+        iframes, remove enumerate-devices-source-id-persistent because the logic was faulty.
+
+        Reviewed by Youenn Fablet.
+
+        * TestExpectations: Unskip http/tests/media/media-stream/enumerate-devices-source-id.html
+        * http/tests/media/media-stream/enumerate-devices-source-id-expected.txt:
+        * http/tests/media/media-stream/enumerate-devices-source-id-persistent-expected.txt: Removed.
+        * http/tests/media/media-stream/enumerate-devices-source-id-persistent.html: Removed.
+        * http/tests/media/media-stream/enumerate-devices-source-id.html:
+
 2018-11-08  Jonathan Hammer  <jonathan@e3software.com>
 
         Plain text drag in contenteditable is always DragOperationCopy, never DragOperationMove
index ccd1256..3639447 100644 (file)
@@ -2906,6 +2906,3 @@ fast/mediacapturefromelement/CanvasCaptureMediaStream-imagebitmaprenderingcontex
 fast/mediacapturefromelement/CanvasCaptureMediaStream-framerate-0.html [ Skip ]
 fast/mediacapturefromelement/CanvasCaptureMediaStream-capture-out-of-DOM-element.html [ Skip ]
 
-# FIXME: The behavior of navigator.mediaDevices.enumerateDevices is in flux, skip these tests for now.
-http/tests/media/media-stream/enumerate-devices-source-id-persistent.html [ Skip ]
-http/tests/media/media-stream/enumerate-devices-source-id.html [ Skip ]
index b7988ab..9acc1ba 100644 (file)
@@ -1,25 +1,25 @@
  
  
 
-Tests that mediaDevices.enumerateDevices returns a unique ID for deviceId in each domain.
+Tests that mediaDevices.enumerateDevices returns the same value for a device ID in all subframes.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS : device id 1 is unique
-PASS : device id 2 is unique
-PASS : device id 3 is unique
-PASS : device id 4 is unique
-PASS : device id 5 is unique
-PASS : device id 6 is unique
-PASS : device id 7 is unique
-PASS : device id 8 is unique
-PASS : device id 9 is unique
-PASS : device id 10 is unique
-PASS : device id 11 is unique
-PASS : device id 12 is unique
-
-PASS : all device IDs are unique
+PASS : device id 1 is not unique
+PASS : device id 2 is not unique
+PASS : device id 3 is not unique
+PASS : device id 4 is not unique
+PASS : device id 5 is not unique
+PASS : device id 6 is not unique
+PASS : device id 7 is not unique
+PASS : device id 8 is not unique
+PASS : device id 9 is not unique
+PASS : device id 10 is not unique
+PASS : device id 11 is not unique
+PASS : device id 12 is not unique
+
+PASS : device IDs are not unique
 
 PASS successfullyParsed is true
 
diff --git a/LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-persistent-expected.txt b/LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-persistent-expected.txt
deleted file mode 100644 (file)
index f009c5e..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-
-Tests that mediaDevices.enumerateDevices returns a persistent deviceId when appropriate.
-http://localhost:8000 has persistent permission, so IDs must persist across frames.
-
-On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
-
-
-
-PASS : device IDs in http://localhost:8000 persist, all others are unique
-
-PASS successfullyParsed is true
-
-TEST COMPLETE
-
diff --git a/LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-persistent.html b/LayoutTests/http/tests/media/media-stream/enumerate-devices-source-id-persistent.html
deleted file mode 100644 (file)
index a132209..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <style>
-            iframe { border: 1px solid black; }
-        </style>
-        <script src="../../../../resources/js-test-pre.js"></script>
-        <script>
-            var frameInfos = [];
-            var idCounts = new Map();
-            window.jsTestIsAsync = true;
-
-            if (window.testRunner) {
-                testRunner.setUserMediaPermission(true);
-                testRunner.setUserMediaPersistentPermissionForOrigin(true, "http://localhost:8000", location.href);
-            }
-
-            function setup()
-            {
-                description("Tests that mediaDevices.enumerateDevices returns a persistent deviceId when appropriate." 
-                + "<br>http://localhost:8000 has persistent permission, so IDs must persist across frames.");
-            }
-
-            function handler(event) 
-            {
-                event.data.deviceIds.forEach(function(id) {
-                    frameInfos.push({origin : event.data.origin, deviceId : id});
-                    if (idCounts.has(id))
-                        idCounts.set(id, idCounts.get(id) + 1);
-                    else
-                        idCounts.set(id, 1);
-                });
-
-                if (frameInfos.length != 6)
-                    return;
-
-                var success = true;
-                for (var i = 0; i < frameInfos.length; i++) {
-                    var deviceId = frameInfos[i].deviceId;
-                    if (frameInfos[i].origin.indexOf("http://localhost:8000") == 0) {
-                        if (idCounts.get(deviceId) < 2) {
-                            testFailed(`: device ID in ${frameInfos[i].origin} is unique`);
-                            success = false;
-                        }
-                    } else {
-                        if (idCounts.get(deviceId) != 1) {
-                            testFailed(`: device ID in ${frameInfos[i].origin} is not unique`);
-                            success = false;
-                        }
-                    }
-                }
-
-                debug('');
-                if (success)
-                    testPassed(`: device IDs in http://localhost:8000 persist, all others are unique`);
-
-                debug('');
-                finishJSTest();
-            }
-
-            addEventListener("message", handler, false);
-
-        </script> 
-    </head>
-    <body onload="setup()">
-        <iframe src="http://localhost:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
-        <br>
-        <iframe src="http://127.0.0.1:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
-        <br>
-        <iframe src="http://localhost:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
-        <div id="console"></div>
-        <script src="../../../../resources/js-test-post.js"></script>
-    </body>
-</html>
index fa07c94..48e7dfe 100644 (file)
@@ -7,6 +7,7 @@
         <script src="../../../../resources/js-test-pre.js"></script>
         <script>
             var frameInfos = [];
+            var idCounts = { };
             window.jsTestIsAsync = true;
 
             if (window.testRunner)
 
             function setup()
             {
-                description("Tests that mediaDevices.enumerateDevices returns a unique ID for deviceId in each domain.");
+                description("Tests that mediaDevices.enumerateDevices returns the same value for a device ID in all subframes.");
             }
 
             function handler(event) 
             {
                 event.data.deviceIds.forEach(function(id) {
                     frameInfos.push({origin : event.data.origin, deviceId : id});
+                    let count = idCounts[id] || 0;
+                    idCounts[id] = ++count;
                 });
 
                 if (frameInfos.length != 12)
                     return;
 
                 var success = true;
-                var idOrigins = [];
                 for (var i = 0; i < frameInfos.length; i++) {
                     var deviceId = frameInfos[i].deviceId;
-                    if (idOrigins[deviceId] === undefined) {
-                        idOrigins[deviceId] = frameInfos[i].origin;
-                        testPassed(`: device id ${i + 1} is unique`);
-                    } else {
-                        testFailed(`Duplicate device IDs in ${frameInfos[i].origin} and ${idOrigins[deviceId]}`);
+                    let count = idCounts[deviceId] || 0;
+                    if (!count) {
+                        testFailed(`: device id ${i + 1} is unique`);
                         success = false;
-                    }
+                    } else
+                        testPassed(`: device id ${i + 1} is not unique`);
                 }
 
                 debug('');
                 if (success)
-                    testPassed(`: all device IDs are unique`);
+                    testPassed(`: device IDs are not unique`);
 
                 debug('');
                 finishJSTest();
         </script> 
     </head>
     <body onload="setup()">
-        <iframe src="http://localhost:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
+        <iframe allow="camera;microphone" src="http://localhost:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
         <br>
-        <iframe src="http://127.0.0.1:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
+        <iframe allow="camera;microphone" src="http://127.0.0.1:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
         <br>
-        <iframe src="http://localhost:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
+        <iframe allow="camera;microphone" src="http://localhost:8000/media/media-stream/resources/enumerate-devices-source-id-frame.html"></iframe>
         <div id="console"></div>
         <script src="../../../../resources/js-test-post.js"></script>
     </body>
index b0bd4f6..53018fd 100644 (file)
@@ -1,3 +1,39 @@
+2018-11-08  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Use DeviceIdHashSaltStorage to generate device ID hash salt
+        https://bugs.webkit.org/show_bug.cgi?id=190825
+        <rdar://problem/45486085>
+
+        Reviewed by Youenn Fablet.
+
+        * UIProcess/API/C/WKUserMediaPermissionCheck.cpp:
+        (WKUserMediaPermissionCheckSetUserMediaAccessInfo):
+        * UIProcess/API/glib/WebKitDeviceInfoPermissionRequest.cpp:
+        (webkitDeviceInfoPermissionRequestAllow):
+        (webkitDeviceInfoPermissionRequestDeny):
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::UIClient::checkUserMediaPermissionForOrigin):
+        * UIProcess/DeviceIdHashSaltStorage.cpp:
+        (WebKit::DeviceIdHashSaltStorage::regenerateDeviceIdHashSaltForOrigin):
+        (WebKit::DeviceIdHashSaltStorage::deleteDeviceIdHashSaltForOrigin):
+        * UIProcess/DeviceIdHashSaltStorage.h:
+        * UIProcess/UserMediaPermissionCheckProxy.cpp:
+        (WebKit::UserMediaPermissionCheckProxy::setUserMediaAccessInfo):
+        * UIProcess/UserMediaPermissionCheckProxy.h:
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        (WebKit::UserMediaPermissionRequestManagerProxy::createPermissionRequest):
+        (WebKit::UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted):
+        (WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame):
+        (WebKit::UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo):
+        (WebKit::UserMediaPermissionRequestManagerProxy::updateDeviceIDHashSalt):
+        (WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame):
+        * UIProcess/UserMediaPermissionRequestManagerProxy.h:
+        * UIProcess/UserMediaPermissionRequestProxy.cpp:
+        (WebKit::UserMediaPermissionRequestProxy::UserMediaPermissionRequestProxy):
+        * UIProcess/UserMediaPermissionRequestProxy.h:
+        (WebKit::UserMediaPermissionRequestProxy::create):
+        (WebKit::UserMediaPermissionRequestProxy::deviceIdentifierHashSalt const): Deleted.
+
 2018-11-08  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Crash when running with sandbox enabled
index 4403cd7..89cfeaa 100644 (file)
@@ -40,8 +40,8 @@ WKTypeID WKUserMediaPermissionCheckGetTypeID()
     return toAPI(UserMediaPermissionCheckProxy::APIType);
 }
 
-void WKUserMediaPermissionCheckSetUserMediaAccessInfo(WKUserMediaPermissionCheckRef userMediaPermissionRequestRef, WKStringRef mediaDeviceIdentifierHashSalt, bool allowed)
+void WKUserMediaPermissionCheckSetUserMediaAccessInfo(WKUserMediaPermissionCheckRef userMediaPermissionRequestRef, WKStringRef, bool allowed)
 {
-    toImpl(userMediaPermissionRequestRef)->setUserMediaAccessInfo(toWTFString(mediaDeviceIdentifierHashSalt), allowed);
+    toImpl(userMediaPermissionRequestRef)->setUserMediaAccessInfo(allowed);
 }
 
index 3f9485e..c0ebc1f 100644 (file)
@@ -64,7 +64,7 @@ static void webkitDeviceInfoPermissionRequestAllow(WebKitPermissionRequest* requ
     auto& priv = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(request)->priv;
 
     if (!priv->deviceIdHashSaltStorage) {
-        priv->request->setUserMediaAccessInfo(String(), false);
+        priv->request->setUserMediaAccessInfo(false);
         return;
     }
 
@@ -73,8 +73,7 @@ static void webkitDeviceInfoPermissionRequestAllow(WebKitPermissionRequest* requ
         return;
 
     priv->madeDecision = true;
-    auto salt = priv->deviceIdHashSaltStorage->deviceIdHashSaltForOrigin(priv->request->topLevelDocumentSecurityOrigin());
-    priv->request->setUserMediaAccessInfo(WTFMove(salt), true);
+    priv->request->setUserMediaAccessInfo(true);
 }
 
 static void webkitDeviceInfoPermissionRequestDeny(WebKitPermissionRequest* request)
@@ -84,7 +83,7 @@ static void webkitDeviceInfoPermissionRequestDeny(WebKitPermissionRequest* reque
     auto& priv = WEBKIT_DEVICE_INFO_PERMISSION_REQUEST(request)->priv;
 
     if (!priv->deviceIdHashSaltStorage) {
-        priv->request->setUserMediaAccessInfo(String(), false);
+        priv->request->setUserMediaAccessInfo(false);
         return;
     }
 
@@ -93,8 +92,7 @@ static void webkitDeviceInfoPermissionRequestDeny(WebKitPermissionRequest* reque
         return;
 
     priv->madeDecision = true;
-    auto salt = priv->deviceIdHashSaltStorage->regenerateDeviceIdHashSaltForOrigin(*priv->request);
-    priv->request->setUserMediaAccessInfo(WTFMove(salt), false);
+    priv->request->setUserMediaAccessInfo(false);
 }
 
 static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface)
index f1aeb81..872a51d 100644 (file)
@@ -978,7 +978,7 @@ bool UIDelegate::UIClient::checkUserMediaPermissionForOrigin(WebPageProxy& page,
 {
     auto delegate = m_uiDelegate.m_delegate.get();
     if (!delegate || !m_uiDelegate.m_delegateMethods.webViewCheckUserMediaPermissionForURLMainFrameURLFrameIdentifierDecisionHandler) {
-        request.setUserMediaAccessInfo(String(), false);
+        request.setUserMediaAccessInfo(false);
         return true;
     }
 
@@ -987,8 +987,8 @@ bool UIDelegate::UIClient::checkUserMediaPermissionForOrigin(WebPageProxy& page,
     WebCore::URL requestFrameURL(WebCore::URL(), frame.url());
     WebCore::URL mainFrameURL(WebCore::URL(), mainFrame->url());
 
-    auto decisionHandler = BlockPtr<void(NSString *, BOOL)>::fromCallable([protectedRequest = makeRef(request)](NSString *salt, BOOL authorized) {
-        protectedRequest->setUserMediaAccessInfo(String(salt), authorized);
+    auto decisionHandler = BlockPtr<void(NSString*, BOOL)>::fromCallable([protectedRequest = makeRef(request)](NSString*, BOOL authorized) {
+        protectedRequest->setUserMediaAccessInfo(authorized);
     });
 
     [(id <WKUIDelegatePrivate>)delegate _webView:webView checkUserMediaPermissionForURL:requestFrameURL mainFrameURL:mainFrameURL frameIdentifier:frame.frameID() decisionHandler:decisionHandler.get()];
index 12c100d..2638a07 100644 (file)
@@ -46,19 +46,7 @@ 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)
+const String& DeviceIdHashSaltStorage::deviceIdHashSaltForOrigin(const SecurityOrigin& documentOrigin)
 {
     auto& deviceIdHashSalt = m_deviceIdHashSaltForOrigins.ensure(documentOrigin.toRawString(), [&documentOrigin] () {
         uint64_t randomData[randomDataSize];
index e8ab832..b3945f5 100644 (file)
@@ -38,8 +38,7 @@ public:
     static Ref<DeviceIdHashSaltStorage> create();
     ~DeviceIdHashSaltStorage() = default;
 
-    const String& deviceIdHashSaltForOrigin(WebCore::SecurityOrigin&);
-    const String& regenerateDeviceIdHashSaltForOrigin(UserMediaPermissionCheckProxy&);
+    const String& deviceIdHashSaltForOrigin(const WebCore::SecurityOrigin&);
 
     void getDeviceIdHashSaltOrigins(CompletionHandler<void(HashSet<WebCore::SecurityOriginData>&&)>&&);
     void deleteDeviceIdHashSaltForOrigins(const Vector<WebCore::SecurityOriginData>&, CompletionHandler<void()>&&);
index d2dfc62..953bbb1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -42,12 +42,13 @@ UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy(uint64_t userMediaI
 {
 }
 
-void UserMediaPermissionCheckProxy::setUserMediaAccessInfo(String&& mediaDeviceIdentifierHashSalt, bool allowed)
+void UserMediaPermissionCheckProxy::setUserMediaAccessInfo(bool allowed)
 {
+    ASSERT(m_completionHandler);
     if (!m_completionHandler)
         return;
 
-    m_completionHandler(m_userMediaID, WTFMove(mediaDeviceIdentifierHashSalt), allowed);
+    m_completionHandler(m_userMediaID, allowed);
     m_completionHandler = nullptr;
 }
 
index fbcc4cf..618d663 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -39,14 +39,14 @@ namespace WebKit {
 class UserMediaPermissionCheckProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionCheck> {
 public:
 
-    using CompletionHandler = WTF::Function<void(uint64_t, String&&, bool allowed)>;
+    using CompletionHandler = WTF::Function<void(uint64_t, bool allowed)>;
 
     static Ref<UserMediaPermissionCheckProxy> create(uint64_t userMediaID, uint64_t frameID, CompletionHandler&& handler, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin)
     {
         return adoptRef(*new UserMediaPermissionCheckProxy(userMediaID, frameID, WTFMove(handler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin)));
     }
 
-    void setUserMediaAccessInfo(String&&, bool allowed);
+    void setUserMediaAccessInfo(bool);
     void invalidate();
 
     uint64_t frameID() const { return m_frameID; }
index 8bda0c7..e642f74 100644 (file)
 
 #include "APISecurityOrigin.h"
 #include "APIUIClient.h"
+#include "DeviceIdHashSaltStorage.h"
 #include "UserMediaPermissionRequestManager.h"
 #include "UserMediaProcessManager.h"
 #include "WebAutomationSession.h"
 #include "WebPageMessages.h"
 #include "WebPageProxy.h"
-#include "WebProcessPool.h"
+#include "WebProcess.h"
 #include "WebProcessProxy.h"
 #include <WebCore/MediaConstraints.h>
 #include <WebCore/MockRealtimeMediaSourceCenter.h>
@@ -91,9 +92,9 @@ void UserMediaPermissionRequestManagerProxy::clearCachedState()
     invalidatePendingRequests();
 }
 
-Ref<UserMediaPermissionRequestProxy> UserMediaPermissionRequestManagerProxy::createPermissionRequest(uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<SecurityOrigin>&& userMediaDocumentOrigin, Ref<SecurityOrigin>&& topLevelDocumentOrigin, Vector<CaptureDevice>&& audioDevices, Vector<CaptureDevice>&& videoDevices, String&& deviceIDHashSalt, MediaStreamRequest&& request)
+Ref<UserMediaPermissionRequestProxy> UserMediaPermissionRequestManagerProxy::createPermissionRequest(uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<SecurityOrigin>&& userMediaDocumentOrigin, Ref<SecurityOrigin>&& topLevelDocumentOrigin, Vector<CaptureDevice>&& audioDevices, Vector<CaptureDevice>&& videoDevices, MediaStreamRequest&& request)
 {
-    auto permissionRequest = UserMediaPermissionRequestProxy::create(*this, userMediaID, mainFrameID, frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(deviceIDHashSalt), WTFMove(request));
+    auto permissionRequest = UserMediaPermissionRequestProxy::create(*this, userMediaID, mainFrameID, frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(request));
     m_pendingUserMediaRequests.add(userMediaID, permissionRequest.ptr());
     return permissionRequest;
 }
@@ -154,7 +155,7 @@ void UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted(uint64_t
 {
     ASSERT(audioDevice || videoDevice);
 
-    if (!m_page.isValid())
+    if (!m_page.isValid() || !m_page.websiteDataStore().deviceIdHashSaltStorage())
         return;
 
 #if ENABLE(MEDIA_STREAM)
@@ -162,9 +163,9 @@ void UserMediaPermissionRequestManagerProxy::userMediaAccessWasGranted(uint64_t
     if (!request)
         return;
 
-    if (grantAccess(userMediaID, WTFMove(audioDevice), WTFMove(videoDevice), request->deviceIdentifierHashSalt()))
+    auto deviceIDHashSalt = m_page.websiteDataStore().deviceIdHashSaltStorage()->deviceIdHashSaltForOrigin(request->topLevelDocumentSecurityOrigin());
+    if (grantAccess(userMediaID, WTFMove(audioDevice), WTFMove(videoDevice), WTFMove(deviceIDHashSalt)))
         m_grantedRequests.append(request.releaseNonNull());
-
 #else
     UNUSED_PARAM(userMediaID);
     UNUSED_PARAM(audioDevice);
@@ -321,14 +322,14 @@ void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(
                 auto videoDevice = !videoDevices.isEmpty() ? videoDevices[0] : CaptureDevice();
                 grantAccess(userMediaID, WTFMove(audioDevice), WTFMove(videoDevice), WTFMove(deviceIdentifierHashSalt));
             } else
-                m_pregrantedRequests.append(createPermissionRequest(userMediaID, m_page.mainFrame()->frameID(), frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(deviceIdentifierHashSalt), WTFMove(localUserRequest)));
+                m_pregrantedRequests.append(createPermissionRequest(userMediaID, m_page.mainFrame()->frameID(), frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(localUserRequest)));
 
             return;
         }
 
         auto userMediaOrigin = API::SecurityOrigin::create(userMediaDocumentOrigin.get());
         auto topLevelOrigin = API::SecurityOrigin::create(topLevelDocumentOrigin.get());
-        auto pendingRequest = createPermissionRequest(userMediaID, m_page.mainFrame()->frameID(), frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(deviceIdentifierHashSalt), WTFMove(localUserRequest));
+        auto pendingRequest = createPermissionRequest(userMediaID, m_page.mainFrame()->frameID(), frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(localUserRequest));
 
         if (m_page.isControlledByAutomation()) {
             if (WebAutomationSession* automationSession = m_page.process().processPool().automationSession()) {
@@ -350,21 +351,22 @@ void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(
             userMediaAccessWasDenied(userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled);
     };
 
-    auto haveDeviceSaltHandler = [this, validHandler = WTFMove(validHandler), invalidHandler = WTFMove(invalidHandler), localUserRequest = userRequest](uint64_t userMediaID, String&& deviceIdentifierHashSalt, bool originHasPersistentAccess) mutable {
+    auto havePermissionInfoHandler = [this, validHandler = WTFMove(validHandler), invalidHandler = WTFMove(invalidHandler), localUserRequest = userRequest](uint64_t userMediaID, bool originHasPersistentAccess) mutable {
 
         auto pendingRequest = m_pendingDeviceRequests.take(userMediaID);
         if (!pendingRequest)
             return;
 
-        if (!m_page.isValid())
+        if (!m_page.isValid() || !m_page.websiteDataStore().deviceIdHashSaltStorage())
             return;
-        
+
         syncWithWebCorePrefs();
-        
-        RealtimeMediaSourceCenter::singleton().validateRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), WTFMove(localUserRequest), WTFMove(deviceIdentifierHashSalt));
+
+        auto deviceIDHashSalt = m_page.websiteDataStore().deviceIdHashSaltStorage()->deviceIdHashSaltForOrigin(pendingRequest.value()->topLevelDocumentSecurityOrigin());
+        RealtimeMediaSourceCenter::singleton().validateRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), WTFMove(localUserRequest), WTFMove(deviceIDHashSalt));
     };
 
-    getUserMediaPermissionInfo(userMediaID, frameID, WTFMove(haveDeviceSaltHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
+    getUserMediaPermissionInfo(userMediaID, frameID, WTFMove(havePermissionInfoHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
 #else
     UNUSED_PARAM(userMediaID);
     UNUSED_PARAM(frameID);
@@ -377,26 +379,32 @@ void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(
 #if ENABLE(MEDIA_STREAM)
 void UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo(uint64_t userMediaID, uint64_t frameID, UserMediaPermissionCheckProxy::CompletionHandler&& handler, Ref<SecurityOrigin>&& userMediaDocumentOrigin, Ref<SecurityOrigin>&& topLevelDocumentOrigin)
 {
+    if (!m_page.websiteDataStore().deviceIdHashSaltStorage()) {
+        handler(userMediaID, false);
+        return;
+    }
+
     auto userMediaOrigin = API::SecurityOrigin::create(userMediaDocumentOrigin.get());
     auto topLevelOrigin = API::SecurityOrigin::create(topLevelDocumentOrigin.get());
-
     auto request = UserMediaPermissionCheckProxy::create(userMediaID, frameID, WTFMove(handler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
-    m_pendingDeviceRequests.add(userMediaID, request.copyRef());
 
-    if (!m_page.uiClient().checkUserMediaPermissionForOrigin(m_page, *m_page.process().webFrame(frameID), userMediaOrigin.get(), topLevelOrigin.get(), request.get()))
-        request->completionHandler()(userMediaID, String(), false);
+    m_pendingDeviceRequests.add(userMediaID, request.copyRef());
+    if (!m_page.uiClient().checkUserMediaPermissionForOrigin(m_page, *m_page.process().webFrame(frameID), userMediaOrigin.get(), topLevelOrigin.get(), request.get())) {
+        m_pendingDeviceRequests.take(userMediaID);
+        request->completionHandler()(userMediaID, false);
+    }
 } 
 #endif
 
 void UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame(uint64_t userMediaID, uint64_t frameID, Ref<SecurityOrigin>&& userMediaDocumentOrigin, Ref<SecurityOrigin>&& topLevelDocumentOrigin)
 {
 #if ENABLE(MEDIA_STREAM)
-    auto completionHandler = [this](uint64_t userMediaID, String&& deviceIdentifierHashSalt, bool originHasPersistentAccess) {
-        auto request = m_pendingDeviceRequests.take(userMediaID);
-        if (!request)
+    auto completionHandler = [this, topOrigin = topLevelDocumentOrigin.copyRef()](uint64_t userMediaID, bool originHasPersistentAccess) {
+        auto pendingRequest = m_pendingDeviceRequests.take(userMediaID);
+        if (!pendingRequest)
             return;
 
-        if (!m_page.isValid())
+        if (!m_page.isValid() || !m_page.websiteDataStore().deviceIdHashSaltStorage())
             return;
 
         syncWithWebCorePrefs();
@@ -406,7 +414,8 @@ void UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame(uint6
             return !device.enabled() || (device.type() != WebCore::CaptureDevice::DeviceType::Camera && device.type() != WebCore::CaptureDevice::DeviceType::Microphone);
         });
 
-        m_page.process().send(Messages::WebPage::DidCompleteMediaDeviceEnumeration(userMediaID, devices, deviceIdentifierHashSalt, originHasPersistentAccess), m_page.pageID());
+        auto deviceIDHashSalt = m_page.websiteDataStore().deviceIdHashSaltStorage()->deviceIdHashSaltForOrigin(topOrigin.get());
+        m_page.process().send(Messages::WebPage::DidCompleteMediaDeviceEnumeration(userMediaID, WTFMove(devices), WTFMove(deviceIDHashSalt), WTFMove(originHasPersistentAccess)), m_page.pageID());
     };
 
     getUserMediaPermissionInfo(userMediaID, frameID, WTFMove(completionHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
index bffe353..847f324 100644 (file)
@@ -67,7 +67,7 @@ public:
     void syncWithWebCorePrefs() const;
 
 private:
-    Ref<UserMediaPermissionRequestProxy> createPermissionRequest(uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, String&&, WebCore::MediaStreamRequest&&);
+    Ref<UserMediaPermissionRequestProxy> createPermissionRequest(uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, WebCore::MediaStreamRequest&&);
     void denyRequest(uint64_t userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason, const String& invalidConstraint);
 #if ENABLE(MEDIA_STREAM)
     bool grantAccess(uint64_t userMediaID, const WebCore::CaptureDevice audioDevice, const WebCore::CaptureDevice videoDevice, const String& deviceIdentifierHashSalt);
index f74a503..528fbc2 100644 (file)
@@ -30,7 +30,7 @@
 namespace WebKit {
 using namespace WebCore;
 
-UserMediaPermissionRequestProxy::UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, String&& deviceIDHashSalt, WebCore::MediaStreamRequest&& request)
+UserMediaPermissionRequestProxy::UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, WebCore::MediaStreamRequest&& request)
     : m_manager(&manager)
     , m_userMediaID(userMediaID)
     , m_mainFrameID(mainFrameID)
@@ -39,7 +39,6 @@ UserMediaPermissionRequestProxy::UserMediaPermissionRequestProxy(UserMediaPermis
     , m_topLevelDocumentSecurityOrigin(WTFMove(topLevelDocumentOrigin))
     , m_eligibleVideoDevices(WTFMove(videoDevices))
     , m_eligibleAudioDevices(WTFMove(audioDevices))
-    , m_deviceIdentifierHashSalt(WTFMove(deviceIDHashSalt))
     , m_request(WTFMove(request))
 {
 }
index 0a1f18f..5980dc7 100644 (file)
@@ -35,9 +35,9 @@ class UserMediaPermissionRequestManagerProxy;
 
 class UserMediaPermissionRequestProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionRequest> {
 public:
-    static Ref<UserMediaPermissionRequestProxy> create(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, String&& deviceIDHashSalt, WebCore::MediaStreamRequest&& request)
+    static Ref<UserMediaPermissionRequestProxy> create(UserMediaPermissionRequestManagerProxy& manager, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, WebCore::MediaStreamRequest&& request)
     {
-        return adoptRef(*new UserMediaPermissionRequestProxy(manager, userMediaID, mainFrameID, frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(deviceIDHashSalt), WTFMove(request)));
+        return adoptRef(*new UserMediaPermissionRequestProxy(manager, userMediaID, mainFrameID, frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDevices), WTFMove(videoDevices), WTFMove(request)));
     }
 
     void allow(const String& audioDeviceUID, const String& videoDeviceUID);
@@ -61,12 +61,10 @@ public:
     WebCore::SecurityOrigin& topLevelDocumentSecurityOrigin() { return m_topLevelDocumentSecurityOrigin.get(); }
     WebCore::SecurityOrigin& userMediaDocumentSecurityOrigin() { return m_userMediaDocumentSecurityOrigin.get(); }
 
-    const String& deviceIdentifierHashSalt() const { return m_deviceIdentifierHashSalt; }
-
     WebCore::MediaStreamRequest::Type requestType() const { return m_request.type; }
 
 private:
-    UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy&, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, String&&, WebCore::MediaStreamRequest&&);
+    UserMediaPermissionRequestProxy(UserMediaPermissionRequestManagerProxy&, uint64_t userMediaID, uint64_t mainFrameID, uint64_t frameID, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin, Vector<WebCore::CaptureDevice>&& audioDevices, Vector<WebCore::CaptureDevice>&& videoDevices, WebCore::MediaStreamRequest&&);
 
     UserMediaPermissionRequestManagerProxy* m_manager;
     uint64_t m_userMediaID;
@@ -76,7 +74,6 @@ private:
     Ref<WebCore::SecurityOrigin> m_topLevelDocumentSecurityOrigin;
     Vector<WebCore::CaptureDevice> m_eligibleVideoDevices;
     Vector<WebCore::CaptureDevice> m_eligibleAudioDevices;
-    String m_deviceIdentifierHashSalt;
     WebCore::MediaStreamRequest m_request;
 };