Title: [252878] trunk/Source/WebCore
Revision
252878
Author
[email protected]
Date
2019-11-26 00:30:42 -0800 (Tue, 26 Nov 2019)

Log Message

Queuing a task in EventLoop is not working with UserMediaRequest allow completion handler
Queuing a task in EventLoop is not working with completion handlers
https://bugs.webkit.org/show_bug.cgi?id=204565
<rdar://problem/57466280>

Reviewed by Ryosuke Niwa.

Do not capture the completion handler in lambda passed to the event queue.
Instead, keep it in UserMediqRequest and call it either when running the task or when destroying UserMediaRequest.
Covered by existing tests failing the debug assertion.

* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::UserMediaRequest::~UserMediaRequest):
(WebCore::UserMediaRequest::allow):
* Modules/mediastream/UserMediaRequest.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (252877 => 252878)


--- trunk/Source/WebCore/ChangeLog	2019-11-26 08:24:57 UTC (rev 252877)
+++ trunk/Source/WebCore/ChangeLog	2019-11-26 08:30:42 UTC (rev 252878)
@@ -1,3 +1,21 @@
+2019-11-26  youenn fablet  <[email protected]>
+
+        Queuing a task in EventLoop is not working with UserMediaRequest allow completion handler
+        Queuing a task in EventLoop is not working with completion handlers
+        https://bugs.webkit.org/show_bug.cgi?id=204565
+        <rdar://problem/57466280>
+
+        Reviewed by Ryosuke Niwa.
+
+        Do not capture the completion handler in lambda passed to the event queue.
+        Instead, keep it in UserMediqRequest and call it either when running the task or when destroying UserMediaRequest.
+        Covered by existing tests failing the debug assertion.
+
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::UserMediaRequest::~UserMediaRequest):
+        (WebCore::UserMediaRequest::allow):
+        * Modules/mediastream/UserMediaRequest.h:
+
 2019-11-25  Yusuke Suzuki  <[email protected]>
 
         [JSC] InternalFunction should be non-destructible

Modified: trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp (252877 => 252878)


--- trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp	2019-11-26 08:24:57 UTC (rev 252877)
+++ trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp	2019-11-26 08:30:42 UTC (rev 252878)
@@ -67,7 +67,11 @@
 {
 }
 
-UserMediaRequest::~UserMediaRequest() = default;
+UserMediaRequest::~UserMediaRequest()
+{
+    if (m_allowCompletionHandler)
+        m_allowCompletionHandler();
+}
 
 SecurityOrigin* UserMediaRequest::userMediaDocumentOrigin() const
 {
@@ -230,10 +234,10 @@
 void UserMediaRequest::allow(CaptureDevice&& audioDevice, CaptureDevice&& videoDevice, String&& deviceIdentifierHashSalt, CompletionHandler<void()>&& completionHandler)
 {
     RELEASE_LOG(MediaStream, "UserMediaRequest::allow %s %s", audioDevice ? audioDevice.persistentId().utf8().data() : "", videoDevice ? videoDevice.persistentId().utf8().data() : "");
-
-    queueTaskKeepingObjectAlive(*this, TaskSource::UserInteraction, [this, audioDevice = WTFMove(audioDevice), videoDevice = WTFMove(videoDevice), deviceIdentifierHashSalt = WTFMove(deviceIdentifierHashSalt), completionHandler = WTFMove(completionHandler)]() mutable {
-        auto callback = [this, protector = makePendingActivity(*this), completionHandler = WTFMove(completionHandler)](RefPtr<MediaStreamPrivate>&& privateStream) mutable {
-            auto scopeExit = makeScopeExit([completionHandler = WTFMove(completionHandler)]() mutable {
+    m_allowCompletionHandler = WTFMove(completionHandler);
+    queueTaskKeepingObjectAlive(*this, TaskSource::UserInteraction, [this, audioDevice = WTFMove(audioDevice), videoDevice = WTFMove(videoDevice), deviceIdentifierHashSalt = WTFMove(deviceIdentifierHashSalt)]() mutable {
+        auto callback = [this, protector = makePendingActivity(*this)](RefPtr<MediaStreamPrivate>&& privateStream) mutable {
+            auto scopeExit = makeScopeExit([completionHandler = WTFMove(m_allowCompletionHandler)]() mutable {
                 completionHandler();
             });
             if (isContextStopped())

Modified: trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h (252877 => 252878)


--- trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h	2019-11-26 08:24:57 UTC (rev 252877)
+++ trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.h	2019-11-26 08:30:42 UTC (rev 252878)
@@ -94,6 +94,7 @@
     Vector<String> m_audioDeviceUIDs;
 
     UniqueRef<DOMPromiseDeferred<IDLInterface<MediaStream>>> m_promise;
+    CompletionHandler<void()> m_allowCompletionHandler;
     MediaStreamRequest m_request;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to