[MediaStream] 'devicechange' event should not fire in frames that can't access captur...
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Dec 2018 03:11:36 +0000 (03:11 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Dec 2018 03:11:36 +0000 (03:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192511
<rdar://problem/46562063>

Reviewed by Youenn Fablet.

Source/WebCore:

Test: http/tests/media/media-stream/device-change-event-in-iframe.html

* Modules/mediastream/MediaDevices.cpp:
(WebCore::MediaDevices::addEventListener): Don't fire the event unless the document can
access a camera or microphone.

Source/WebKit:

* UIProcess/UserMediaPermissionCheckProxy.cpp:
(WebKit::UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy): Remove userMediaID parameter.
(WebKit::UserMediaPermissionCheckProxy::setUserMediaAccessInfo): ID not passed to callback.
* UIProcess/UserMediaPermissionCheckProxy.h:
(WebKit::UserMediaPermissionCheckProxy::create):
(WebKit::UserMediaPermissionCheckProxy::completionHandler): Deleted.

* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::generateRequestID): New.
(WebKit::UserMediaPermissionRequestManagerProxy::captureDevicesChanged): Don't notify if
the page does not have a granted request and does not have persistent access.
(WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame): Use generateRequestID.
(WebKit::UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo): Change variable name.
(WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame): Use generateRequestID.
* UIProcess/UserMediaPermissionRequestManagerProxy.h:

LayoutTests:

* fast/mediastream/device-change-event.html: Fix bogus title.
* http/tests/media/media-stream/device-change-event-in-iframe-expected.txt: Added.
* http/tests/media/media-stream/device-change-event-in-iframe.html: Added.
* http/tests/media/media-stream/resources/device-change-iframe.html: Added.

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/device-change-event.html
LayoutTests/http/tests/media/media-stream/device-change-event-in-iframe-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/media-stream/device-change-event-in-iframe.html [new file with mode: 0644]
LayoutTests/http/tests/media/media-stream/resources/device-change-iframe.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaDevices.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionCheckProxy.h
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h
Source/WebKit/WebProcess/MediaStream/UserMediaPermissionRequestManager.cpp
Source/WebKit/WebProcess/MediaStream/UserMediaPermissionRequestManager.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in

index 4440b4e..c7e2389 100644 (file)
@@ -1,3 +1,16 @@
+2018-12-07  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] 'devicechange' event should not fire in frames that can't access capture devices
+        https://bugs.webkit.org/show_bug.cgi?id=192511
+        <rdar://problem/46562063>
+
+        Reviewed by Youenn Fablet.
+
+        * fast/mediastream/device-change-event.html: Fix bogus title.
+        * http/tests/media/media-stream/device-change-event-in-iframe-expected.txt: Added.
+        * http/tests/media/media-stream/device-change-event-in-iframe.html: Added.
+        * http/tests/media/media-stream/resources/device-change-iframe.html: Added.
+
 2018-12-07  Truitt Savell  <tsavell@apple.com>
 
         [ MacOS Debug ] Layout Test webgl/2.0.0/conformance2/textures/misc/tex-unpack-params.html is flaky timeout
index 41124c9..9b8316a 100644 (file)
@@ -2,7 +2,7 @@
 <html>
 <head>
     <meta charset="utf-8">
-    <title>Testing local audio capture playback causes "playing" event to fire</title>
+    <title>'devicechange' event tests</title>
     <script src="../../resources/testharness.js"></script>
     <script src="../../resources/testharnessreport.js"></script>
     <script>
diff --git a/LayoutTests/http/tests/media/media-stream/device-change-event-in-iframe-expected.txt b/LayoutTests/http/tests/media/media-stream/device-change-event-in-iframe-expected.txt
new file mode 100644 (file)
index 0000000..383c6c3
--- /dev/null
@@ -0,0 +1,8 @@
+     
+<iframe id=camera> got a 'devicechange' event
+<iframe id=main> got a 'devicechange' event
+<iframe id=microphone> got a 'devicechange' event
+<iframe id=same-origin> got a 'devicechange' event
+
+PASS: 'devicechange' only fired on frames with access to devices
+
diff --git a/LayoutTests/http/tests/media/media-stream/device-change-event-in-iframe.html b/LayoutTests/http/tests/media/media-stream/device-change-event-in-iframe.html
new file mode 100644 (file)
index 0000000..9e3a8a5
--- /dev/null
@@ -0,0 +1,63 @@
+<!doctype html>
+<html>
+<script src="../../../../resources/js-test-pre.js"></script>
+<body onload="start()">
+    <iframe id="none"" src="http://localhost:8000/media/media-stream/resources/device-change-iframe.html?1"></iframe>
+    <iframe id="camera" allow="camera" src="http://localhost:8000/media/media-stream/resources/device-change-iframe.html?2"></iframe>
+    <iframe id="microphone" allow="camera" src="http://localhost:8000/media/media-stream/resources/device-change-iframe.html?2"></iframe>
+    <iframe id="same-origin" src="http://127.0.0.1:8000/media/media-stream/resources/device-change-iframe.html?3"></iframe>
+
+    <script>
+
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.waitUntilDone();
+            testRunner.setUserMediaPermission(true);
+        }
+
+        let count = new Set();
+        let success = true;
+        let results = [];
+        function countEvent(id)
+        {
+            results.push(`&LT;iframe id=${id}> got a 'devicechange' event`);
+            if (id == "none") {
+                result.innerHTML += `FAIL: &LT;iframe id=${id}> got 'devicechange' event<br>`;
+                success = false;
+            } else
+                count.add(id);
+
+            if (count.size == 4) {
+                setTimeout(() => {
+                    result.innerHTML = results.sort().join('<br>');
+                    if (success)
+                        result.innerHTML += "<br><br>PASS: 'devicechange' only fired on frames with access to devices<br>";
+                    if (window.testRunner) {
+                        testRunner.notifyDone();
+                        testRunner.resetMockMediaDevices();
+                    }
+                }, 500);
+            }
+        }
+        
+        async function start()
+        {
+            await window.navigator.mediaDevices.getUserMedia({audio:true});
+            if (window.testRunner)
+                testRunner.addMockMicrophoneDevice("id4", "microphone 3");
+        }
+
+        window.onmessage = (event) => { countEvent(event.data); };
+        navigator.mediaDevices.ondevicechange = (event) => { countEvent('main'); };
+
+        Array.from(document.getElementsByTagName('iframe')).forEach(element => {
+            element.onload = (evt) => { 
+                evt.target.contentWindow.postMessage(evt.target.id, '*'); 
+            }
+        });
+
+    </script>
+
+    <div id="result"></div>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/media/media-stream/resources/device-change-iframe.html b/LayoutTests/http/tests/media/media-stream/resources/device-change-iframe.html
new file mode 100644 (file)
index 0000000..66b153c
--- /dev/null
@@ -0,0 +1,12 @@
+<script>
+    let myID;
+    navigator.mediaDevices.ondevicechange = (event) => {
+        parent.postMessage(myID, '*');
+        result.innerHTML = `${myID} got 'devicechange' event`;
+    };
+    window.addEventListener("message", (event) => { myID = event.data; });
+</script>
+
+<div id='result'></div>
+
+
index f16fae2..e440931 100644 (file)
@@ -1,5 +1,19 @@
 2018-12-07  Eric Carlson  <eric.carlson@apple.com>
 
+        [MediaStream] 'devicechange' event should not fire in frames that can't access capture devices
+        https://bugs.webkit.org/show_bug.cgi?id=192511
+        <rdar://problem/46562063>
+
+        Reviewed by Youenn Fablet.
+
+        Test: http/tests/media/media-stream/device-change-event-in-iframe.html
+
+        * Modules/mediastream/MediaDevices.cpp:
+        (WebCore::MediaDevices::addEventListener): Don't fire the event unless the document can
+        access a camera or microphone.
+
+2018-12-07  Eric Carlson  <eric.carlson@apple.com>
+
         [MediaStream] Address post-review comments after r238904
         https://bugs.webkit.org/show_bug.cgi?id=192514
         <rdar://problem/46564302>
index 91c51ad..14bb977 100644 (file)
@@ -190,6 +190,16 @@ bool MediaDevices::addEventListener(const AtomicString& eventType, Ref<EventList
                 if (!weakThis || m_scheduledEventTimer.isActive())
                     return;
 
+                auto* document = this->document();
+                auto* controller = document ? UserMediaController::from(document->page()) : nullptr;
+                if (!controller)
+                    return;
+
+                bool canAccessMicrophone = controller->canCallGetUserMedia(*document, { UserMediaController::CaptureType::Microphone }) == UserMediaController::GetUserMediaAccess::CanCall;
+                bool canAccessCamera = controller->canCallGetUserMedia(*document, { UserMediaController::CaptureType::Camera }) == UserMediaController::GetUserMediaAccess::CanCall;
+                if (!canAccessMicrophone && !canAccessCamera)
+                    return;
+
                 m_scheduledEventTimer.startOneShot(Seconds(randomNumber() / 2));
             });
         }
index e346f81..d82c3a9 100644 (file)
@@ -177,7 +177,7 @@ private:
     void trackEnabledChanged(MediaStreamTrackPrivate&) final;
 
     Vector<Observer*> m_observers;
-    
+
 
     MediaTrackConstraints m_constraints;
     std::optional<DOMPromiseDeferred<void>> m_promise;
index c6f280c..e570310 100644 (file)
@@ -1,3 +1,27 @@
+2018-12-07  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] 'devicechange' event should not fire in frames that can't access capture devices
+        https://bugs.webkit.org/show_bug.cgi?id=192511
+        <rdar://problem/46562063>
+
+        Reviewed by Youenn Fablet.
+
+        * UIProcess/UserMediaPermissionCheckProxy.cpp:
+        (WebKit::UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy): Remove userMediaID parameter.
+        (WebKit::UserMediaPermissionCheckProxy::setUserMediaAccessInfo): ID not passed to callback.
+        * UIProcess/UserMediaPermissionCheckProxy.h:
+        (WebKit::UserMediaPermissionCheckProxy::create):
+        (WebKit::UserMediaPermissionCheckProxy::completionHandler): Deleted.
+
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        (WebKit::generateRequestID): New.
+        (WebKit::UserMediaPermissionRequestManagerProxy::captureDevicesChanged): Don't notify if
+        the page does not have a granted request and does not have persistent access.
+        (WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame): Use generateRequestID.
+        (WebKit::UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo): Change variable name.
+        (WebKit::UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame): Use generateRequestID.
+        * UIProcess/UserMediaPermissionRequestManagerProxy.h:
+
 2018-12-07  Saam Barati  <sbarati@apple.com>
 
         WKWebProcessPlugInLoadDelegate should have API for saying which rendering events it wants to listen for
index 2c84168..2b6fa52 100644 (file)
@@ -440,7 +440,6 @@ def headers_for_type(type):
         'WebCore::SelectionRect': ['"EditorState.h"'],
         'WebKit::ActivityStateChangeID': ['"DrawingAreaInfo.h"'],
         'WebKit::BackForwardListItemState': ['"SessionState.h"'],
-        'WebKit::DeviceAccessState': ['"UserMediaPermissionRequestManager.h"'],
         'WebKit::LayerHostingMode': ['"LayerTreeContext.h"'],
         'WebKit::PageState': ['"SessionState.h"'],
         'WebKit::WebGestureEvent': ['"WebEvent.h"'],
index 953bbb1..96513eb 100644 (file)
@@ -33,9 +33,8 @@
 namespace WebKit {
 using namespace WebCore;
 
-UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy(uint64_t userMediaID, uint64_t frameID, CompletionHandler&& handler, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin)
-    : m_userMediaID(userMediaID)
-    , m_frameID(frameID)
+UserMediaPermissionCheckProxy::UserMediaPermissionCheckProxy(uint64_t frameID, CompletionHandler&& handler, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin)
+    : m_frameID(frameID)
     , m_completionHandler(WTFMove(handler))
     , m_userMediaDocumentSecurityOrigin(WTFMove(userMediaDocumentOrigin))
     , m_topLevelDocumentSecurityOrigin(WTFMove(topLevelDocumentOrigin))
@@ -48,7 +47,7 @@ void UserMediaPermissionCheckProxy::setUserMediaAccessInfo(bool allowed)
     if (!m_completionHandler)
         return;
 
-    m_completionHandler(m_userMediaID, allowed);
+    m_completionHandler(allowed);
     m_completionHandler = nullptr;
 }
 
index 618d663..d91f04f 100644 (file)
@@ -39,11 +39,11 @@ namespace WebKit {
 class UserMediaPermissionCheckProxy : public API::ObjectImpl<API::Object::Type::UserMediaPermissionCheck> {
 public:
 
-    using CompletionHandler = WTF::Function<void(uint64_t, bool allowed)>;
+    using CompletionHandler = WTF::Function<void(bool allowed)>;
 
-    static Ref<UserMediaPermissionCheckProxy> create(uint64_t userMediaID, uint64_t frameID, CompletionHandler&& handler, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin)
+    static Ref<UserMediaPermissionCheckProxy> create(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)));
+        return adoptRef(*new UserMediaPermissionCheckProxy(frameID, WTFMove(handler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin)));
     }
 
     void setUserMediaAccessInfo(bool);
@@ -53,12 +53,9 @@ public:
     WebCore::SecurityOrigin& userMediaDocumentSecurityOrigin() { return m_userMediaDocumentSecurityOrigin.get(); }
     WebCore::SecurityOrigin& topLevelDocumentSecurityOrigin() { return m_topLevelDocumentSecurityOrigin.get(); }
     
-    CompletionHandler& completionHandler() { return m_completionHandler; }
-    
 private:
-    UserMediaPermissionCheckProxy(uint64_t userMediaID, uint64_t frameID, CompletionHandler&&, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin);
+    UserMediaPermissionCheckProxy(uint64_t frameID, CompletionHandler&&, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin);
 
-    uint64_t m_userMediaID;
     uint64_t m_frameID;
     CompletionHandler m_completionHandler;
     Ref<WebCore::SecurityOrigin> m_userMediaDocumentSecurityOrigin;
index 1a06620..95f553d 100644 (file)
@@ -43,6 +43,12 @@ using namespace WebCore;
 static const MediaProducer::MediaStateFlags activeCaptureMask = MediaProducer::HasActiveAudioCaptureDevice | MediaProducer::HasActiveVideoCaptureDevice;
 #endif
 
+static uint64_t generateRequestID()
+{
+    static uint64_t uniqueRequestID = 1;
+    return uniqueRequestID++;
+}
+
 UserMediaPermissionRequestManagerProxy::UserMediaPermissionRequestManagerProxy(WebPageProxy& page)
     : m_page(page)
     , m_rejectionTimer(RunLoop::main(), this, &UserMediaPermissionRequestManagerProxy::rejectionTimerFired)
@@ -81,9 +87,24 @@ void UserMediaPermissionRequestManagerProxy::stopCapture()
 void UserMediaPermissionRequestManagerProxy::captureDevicesChanged()
 {
 #if ENABLE(MEDIA_STREAM)
-    // FIXME: a page with persistent access should always get device change notifications.
-    auto accessState = m_grantedRequests.isEmpty() ? DeviceAccessState::NoAccess : DeviceAccessState::SessionAccess;
-    m_page.process().send(Messages::WebPage::CaptureDevicesChanged(accessState), m_page.pageID());
+    if (!m_page.isValid() || !m_page.mainFrame())
+        return;
+
+    auto requestID = generateRequestID();
+    auto handler = [this, requestID](bool originHasPersistentAccess) mutable {
+
+        auto pendingRequest = m_pendingDeviceRequests.take(requestID);
+        if (!pendingRequest || !m_page.isValid())
+            return;
+
+        if (m_grantedRequests.isEmpty() && !originHasPersistentAccess)
+            return;
+
+        m_page.process().send(Messages::WebPage::CaptureDevicesChanged(), m_page.pageID());
+    };
+
+    auto origin = WebCore::SecurityOrigin::create(m_page.mainFrame()->url());
+    getUserMediaPermissionInfo(requestID, m_page.mainFrame()->frameID(), WTFMove(handler), origin.get(), WTFMove(origin));
 #endif
 }
 
@@ -357,9 +378,10 @@ void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(
             userMediaAccessWasDenied(userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled);
     };
 
-    auto havePermissionInfoHandler = [this, validHandler = WTFMove(validHandler), invalidHandler = WTFMove(invalidHandler), localUserRequest = userRequest](uint64_t userMediaID, bool originHasPersistentAccess) mutable {
+    auto requestID = generateRequestID();
+    auto havePermissionInfoHandler = [this, requestID, validHandler = WTFMove(validHandler), invalidHandler = WTFMove(invalidHandler), localUserRequest = userRequest](bool originHasPersistentAccess) mutable {
 
-        auto pendingRequest = m_pendingDeviceRequests.take(userMediaID);
+        auto pendingRequest = m_pendingDeviceRequests.take(requestID);
         if (!pendingRequest)
             return;
 
@@ -372,7 +394,7 @@ void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(
         RealtimeMediaSourceCenter::singleton().validateRequestConstraints(WTFMove(validHandler), WTFMove(invalidHandler), WTFMove(localUserRequest), WTFMove(deviceIDHashSalt));
     };
 
-    getUserMediaPermissionInfo(userMediaID, frameID, WTFMove(havePermissionInfoHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
+    getUserMediaPermissionInfo(requestID, frameID, WTFMove(havePermissionInfoHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
 #else
     UNUSED_PARAM(userMediaID);
     UNUSED_PARAM(frameID);
@@ -383,21 +405,21 @@ 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)
+void UserMediaPermissionRequestManagerProxy::getUserMediaPermissionInfo(uint64_t requestID, uint64_t frameID, UserMediaPermissionCheckProxy::CompletionHandler&& handler, Ref<SecurityOrigin>&& userMediaDocumentOrigin, Ref<SecurityOrigin>&& topLevelDocumentOrigin)
 {
     if (!m_page.websiteDataStore().deviceIdHashSaltStorage()) {
-        handler(userMediaID, false);
+        handler(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));
+    auto request = UserMediaPermissionCheckProxy::create(frameID, WTFMove(handler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
 
-    m_pendingDeviceRequests.add(userMediaID, request.copyRef());
+    m_pendingDeviceRequests.add(requestID, 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);
+        m_pendingDeviceRequests.take(requestID);
+        handler(false);
     }
 }
 
@@ -432,8 +454,9 @@ void UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame(uint6
 #endif
     static const int defaultMaximumMicrophoneCount = 1;
 
-    auto completionHandler = [this, requestOrigin = userMediaDocumentOrigin.copyRef(), topOrigin = topLevelDocumentOrigin.copyRef()](uint64_t userMediaID, bool originHasPersistentAccess) {
-        auto pendingRequest = m_pendingDeviceRequests.take(userMediaID);
+    auto requestID = generateRequestID();
+    auto completionHandler = [this, requestID, userMediaID, requestOrigin = userMediaDocumentOrigin.copyRef(), topOrigin = topLevelDocumentOrigin.copyRef()](bool originHasPersistentAccess) {
+        auto pendingRequest = m_pendingDeviceRequests.take(requestID);
         if (!pendingRequest)
             return;
 
@@ -478,7 +501,7 @@ void UserMediaPermissionRequestManagerProxy::enumerateMediaDevicesForFrame(uint6
         m_page.process().send(Messages::WebPage::DidCompleteMediaDeviceEnumeration(userMediaID, WTFMove(filteredDevices), WTFMove(deviceIDHashSalt), originHasPersistentAccess), m_page.pageID());
     };
 
-    getUserMediaPermissionInfo(userMediaID, frameID, WTFMove(completionHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
+    getUserMediaPermissionInfo(requestID, frameID, WTFMove(completionHandler), WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin));
 #else
     UNUSED_PARAM(userMediaID);
     UNUSED_PARAM(frameID);
index 24443db..16acded 100644 (file)
@@ -75,7 +75,7 @@ private:
     const UserMediaPermissionRequestProxy* searchForGrantedRequest(uint64_t frameID, const WebCore::SecurityOrigin& userMediaDocumentOrigin, const WebCore::SecurityOrigin& topLevelDocumentOrigin, bool needsAudio, bool needsVideo) const;
     bool wasRequestDenied(uint64_t mainFrameID, const WebCore::SecurityOrigin& userMediaDocumentOrigin, const WebCore::SecurityOrigin& topLevelDocumentOrigin, bool needsAudio, bool needsVideo, bool needsScreenCapture);
 
-    void getUserMediaPermissionInfo(uint64_t userMediaID, uint64_t frameID, UserMediaPermissionCheckProxy::CompletionHandler&&, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin);
+    void getUserMediaPermissionInfo(uint64_t requestID, uint64_t frameID, UserMediaPermissionCheckProxy::CompletionHandler&&, Ref<WebCore::SecurityOrigin>&& userMediaDocumentOrigin, Ref<WebCore::SecurityOrigin>&& topLevelDocumentOrigin);
 
     enum class RequestAction {
         Deny,
index 81824b0..acb99fc 100644 (file)
@@ -53,8 +53,6 @@ UserMediaPermissionRequestManager::UserMediaPermissionRequestManager(WebPage& pa
 
 UserMediaPermissionRequestManager::~UserMediaPermissionRequestManager()
 {
-    if (m_monitoringActivityStateChange)
-        m_page.corePage()->removeActivityStateChangeObserver(*this);
     for (auto& sandboxExtension : m_userMediaDeviceSandboxExtensions)
         sandboxExtension.value->revoke();
 }
@@ -245,7 +243,7 @@ void UserMediaPermissionRequestManager::removeDeviceChangeObserver(UserMediaClie
     ASSERT_UNUSED(wasRemoved, wasRemoved);
 }
 
-void UserMediaPermissionRequestManager::captureDevicesChanged(DeviceAccessState accessState)
+void UserMediaPermissionRequestManager::captureDevicesChanged()
 {
     // When new media input and/or output devices are made available, or any available input and/or
     // output device becomes unavailable, the User Agent MUST run the following steps in browsing
@@ -255,19 +253,6 @@ void UserMediaPermissionRequestManager::captureDevicesChanged(DeviceAccessState
     // * any of the input devices are attached to an active MediaStream in the browsing context, or
     // * the active document is fully active and has focus.
 
-    bool isActive = m_page.corePage()->activityState().containsAll(focusedActiveWindow);
-    if (!isActive && accessState == DeviceAccessState::NoAccess) {
-        if (!isActive) {
-            if (!m_monitoringActivityStateChange) {
-                m_monitoringActivityStateChange = true;
-                m_page.corePage()->addActivityStateChangeObserver(*this);
-            }
-            m_pendingDeviceChangeEvent = true;
-            m_accessStateWhenDevicesChanged = accessState;
-        }
-        return;
-    }
-
     auto identifiers = m_deviceChangeObserverMap.keys();
     for (auto& identifier : identifiers) {
         auto iterator = m_deviceChangeObserverMap.find(identifier);
@@ -276,28 +261,6 @@ void UserMediaPermissionRequestManager::captureDevicesChanged(DeviceAccessState
     }
 }
 
-void UserMediaPermissionRequestManager::activityStateDidChange(OptionSet<WebCore::ActivityState::Flag> oldActivityState, OptionSet<WebCore::ActivityState::Flag> newActivityState)
-{
-    if (!newActivityState.containsAll(focusedActiveWindow))
-        return;
-
-    RunLoop::main().dispatch([this, weakThis = makeWeakPtr(*this)]() mutable {
-        if (!weakThis || !m_monitoringActivityStateChange)
-            return;
-
-        m_monitoringActivityStateChange = false;
-        m_page.corePage()->removeActivityStateChangeObserver(*this);
-    });
-
-    if (!m_pendingDeviceChangeEvent)
-        return;
-
-    m_pendingDeviceChangeEvent = false;
-    auto accessState = m_accessStateWhenDevicesChanged;
-    m_accessStateWhenDevicesChanged = DeviceAccessState::NoAccess;
-    captureDevicesChanged(accessState);
-}
-
 } // namespace WebKit
 
 #endif // ENABLE(MEDIA_STREAM)
index 8b86eac..6004290 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "MediaDeviceSandboxExtensions.h"
 #include "SandboxExtension.h"
-#include <WebCore/ActivityStateChangeObserver.h>
 #include <WebCore/MediaCanStartListener.h>
 #include <WebCore/MediaConstraints.h>
 #include <WebCore/MediaDevicesEnumerationRequest.h>
@@ -37,9 +36,7 @@ namespace WebKit {
 
 class WebPage;
 
-enum class DeviceAccessState : uint8_t { NoAccess, SessionAccess, PersistentAccess };
-
-class UserMediaPermissionRequestManager : public CanMakeWeakPtr<UserMediaPermissionRequestManager>, private WebCore::MediaCanStartListener, private WebCore::ActivityStateChangeObserver {
+class UserMediaPermissionRequestManager : public CanMakeWeakPtr<UserMediaPermissionRequestManager>, private WebCore::MediaCanStartListener {
 public:
     explicit UserMediaPermissionRequestManager(WebPage&);
     ~UserMediaPermissionRequestManager();
@@ -59,7 +56,7 @@ public:
     WebCore::UserMediaClient::DeviceChangeObserverToken addDeviceChangeObserver(WTF::Function<void()>&&);
     void removeDeviceChangeObserver(WebCore::UserMediaClient::DeviceChangeObserverToken);
 
-    void captureDevicesChanged(DeviceAccessState);
+    void captureDevicesChanged();
 
 private:
     void sendUserMediaRequest(WebCore::UserMediaRequest&);
@@ -67,9 +64,6 @@ private:
     // WebCore::MediaCanStartListener
     void mediaCanStart(WebCore::Document&) final;
 
-    // WebCore::ActivityStateChangeObserver
-    void activityStateDidChange(OptionSet<WebCore::ActivityState::Flag> oldActivityState, OptionSet<WebCore::ActivityState::Flag> newActivityState) final;
-
     void removeMediaRequestFromMaps(WebCore::UserMediaRequest&);
 
     WebPage& m_page;
@@ -84,25 +78,13 @@ private:
     HashMap<String, RefPtr<SandboxExtension>> m_userMediaDeviceSandboxExtensions;
 
     HashMap<WebCore::UserMediaClient::DeviceChangeObserverToken, WTF::Function<void()>> m_deviceChangeObserverMap;
-    DeviceAccessState m_accessStateWhenDevicesChanged { DeviceAccessState::NoAccess };
     bool m_monitoringDeviceChange { false };
-    bool m_pendingDeviceChangeEvent { false };
-    bool m_monitoringActivityStateChange { false };
 };
 
 } // namespace WebKit
 
 namespace WTF {
 
-template<> struct EnumTraits<WebKit::DeviceAccessState> {
-    using values = EnumValues<
-        WebKit::DeviceAccessState,
-        WebKit::DeviceAccessState::NoAccess,
-        WebKit::DeviceAccessState::SessionAccess,
-        WebKit::DeviceAccessState::PersistentAccess
-    >;
-};
-
 } // namespace WTF
 
 #endif // ENABLE(MEDIA_STREAM)
index 3e0c914..c5542b2 100644 (file)
@@ -3978,9 +3978,9 @@ void WebPage::didCompleteMediaDeviceEnumeration(uint64_t userMediaID, const Vect
     m_userMediaPermissionRequestManager->didCompleteMediaDeviceEnumeration(userMediaID, devices, WTFMove(deviceIdentifierHashSalt), originHasPersistentAccess);
 }
 
-void WebPage::captureDevicesChanged(DeviceAccessState accessState)
+void WebPage::captureDevicesChanged()
 {
-    m_userMediaPermissionRequestManager->captureDevicesChanged(accessState);
+    m_userMediaPermissionRequestManager->captureDevicesChanged();
 }
 
 #if ENABLE(SANDBOX_EXTENSIONS)
index c880029..83892e5 100644 (file)
@@ -234,7 +234,6 @@ class WebUserContentController;
 class WebWheelEvent;
 class RemoteLayerTreeTransaction;
 
-enum class DeviceAccessState : uint8_t;
 enum FindOptions : uint16_t;
 enum class DragControllerAction : uint8_t;
 
@@ -578,7 +577,7 @@ public:
 #if ENABLE(MEDIA_STREAM)
     UserMediaPermissionRequestManager& userMediaPermissionRequestManager() { return *m_userMediaPermissionRequestManager; }
     void prepareToSendUserMediaPermissionRequest();
-    void captureDevicesChanged(DeviceAccessState);
+    void captureDevicesChanged();
 #endif
 
     void elementDidFocus(WebCore::Node*);
index 520abe7..6f917bc 100644 (file)
@@ -340,7 +340,7 @@ messages -> WebPage LegacyReceiver {
     UserMediaAccessWasGranted(uint64_t userMediaID, WebCore::CaptureDevice audioDevice, WebCore::CaptureDevice videoDevice, String mediaDeviceIdentifierHashSalt)
     UserMediaAccessWasDenied(uint64_t userMediaID, uint64_t reason, String invalidConstraint)
     DidCompleteMediaDeviceEnumeration(uint64_t userMediaID, Vector<WebCore::CaptureDevice> devices, String mediaDeviceIdentifierHashSalt, bool hasPersistentAccess)
-    CaptureDevicesChanged(enum:uint8_t WebKit::DeviceAccessState accessState)
+    CaptureDevicesChanged()
 #if ENABLE(SANDBOX_EXTENSIONS)
     GrantUserMediaDeviceSandboxExtensions(WebKit::MediaDeviceSandboxExtensions sandboxExtensions)
     RevokeUserMediaDeviceSandboxExtensions(Vector<String> sandboxExtensionIDs)