NotReadableError when calling getUserMedia
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Aug 2018 18:33:25 +0000 (18:33 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Aug 2018 18:33:25 +0000 (18:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188309
<rdar://problem/42916838>

Reviewed by Brent Fulgham.

* UIProcess/UserMediaProcessManager.cpp:
(WebKit::UserMediaProcessManager::willCreateMediaStream): Deal with audio and video sandbox
extensions being issued at different times. Use new ProcessState methods.
(WebKit::UserMediaProcessManager::endedCaptureSession): Use new ProcessState methods.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/UserMediaProcessManager.cpp

index 1772a01..7096045 100644 (file)
@@ -1,3 +1,16 @@
+2018-08-07  Eric Carlson  <eric.carlson@apple.com>
+
+        NotReadableError when calling getUserMedia
+        https://bugs.webkit.org/show_bug.cgi?id=188309
+        <rdar://problem/42916838>
+
+        Reviewed by Brent Fulgham.
+
+        * UIProcess/UserMediaProcessManager.cpp:
+        (WebKit::UserMediaProcessManager::willCreateMediaStream): Deal with audio and video sandbox
+        extensions being issued at different times. Use new ProcessState methods.
+        (WebKit::UserMediaProcessManager::endedCaptureSession): Use new ProcessState methods.
+
 2018-08-07  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         REGRESSION (r233778): Text selection sometimes cannot be extended in iframes
index ae6df74..7ae6909 100644 (file)
@@ -44,18 +44,25 @@ public:
     void removeRequestManager(UserMediaPermissionRequestManagerProxy&);
     Vector<UserMediaPermissionRequestManagerProxy*>& managers() { return m_managers; }
 
-    enum SandboxExtensionsGranted {
+    enum SandboxExtensionType : uint32_t {
         None = 0,
         Video = 1 << 0,
         Audio = 1 << 1
     };
+    typedef uint32_t SandboxExtensionsGranted;
 
-    SandboxExtensionsGranted sandboxExtensionsGranted() { return m_pageSandboxExtensionsGranted; }
-    void setSandboxExtensionsGranted(unsigned granted) { m_pageSandboxExtensionsGranted = static_cast<SandboxExtensionsGranted>(granted); }
+    bool hasVideoExtension() const { return m_pageSandboxExtensionsGranted & Video; }
+    void grantVideoExtension()  { m_pageSandboxExtensionsGranted |= Video; }
+    void revokeVideoExtension()  { m_pageSandboxExtensionsGranted &= ~Video; }
+
+    bool hasAudioExtension() const { return m_pageSandboxExtensionsGranted & Audio; }
+    void grantAudioExtension()  { m_pageSandboxExtensionsGranted |= Audio; }
+    void revokeAudioExtension()  { m_pageSandboxExtensionsGranted &= ~Audio; }
 
 private:
+
     Vector<UserMediaPermissionRequestManagerProxy*> m_managers;
-    SandboxExtensionsGranted m_pageSandboxExtensionsGranted { SandboxExtensionsGranted::None };
+    SandboxExtensionsGranted m_pageSandboxExtensionsGranted { SandboxExtensionType::None };
 };
 
 static HashMap<WebProcessProxy*, std::unique_ptr<ProcessState>>& stateMap()
@@ -128,6 +135,8 @@ void UserMediaProcessManager::muteCaptureMediaStreamsExceptIn(WebPageProxy& page
 
 bool UserMediaProcessManager::willCreateMediaStream(UserMediaPermissionRequestManagerProxy& proxy, bool withAudio, bool withVideo)
 {
+    ASSERT(withAudio || withVideo);
+
     if (m_denyNextRequest) {
         m_denyNextRequest = false;
         return false;
@@ -143,46 +152,39 @@ bool UserMediaProcessManager::willCreateMediaStream(UserMediaPermissionRequestMa
 
     auto& state = processState(processStartingCapture);
     size_t extensionCount = 0;
-    unsigned requiredExtensions = ProcessState::SandboxExtensionsGranted::None;
 
-    if (withAudio) {
-        requiredExtensions |= ProcessState::SandboxExtensionsGranted::Audio;
-        extensionCount++;
-    }
-    if (withVideo) {
-        requiredExtensions |= ProcessState::SandboxExtensionsGranted::Video;
+    if (withAudio && !state.hasAudioExtension())
         extensionCount++;
-    }
+    else
+        withAudio = false;
 
-    unsigned currentExtensions = state.sandboxExtensionsGranted();
+    if (withVideo && !state.hasVideoExtension())
+        extensionCount++;
+    else
+        withVideo = false;
 
-    if (!(requiredExtensions & currentExtensions)) {
+    if (extensionCount) {
         SandboxExtension::HandleArray handles;
         handles.allocate(extensionCount);
 
         Vector<String> ids;
         ids.reserveCapacity(extensionCount);
 
-        if (withAudio && requiredExtensions & ProcessState::SandboxExtensionsGranted::Audio) {
-            if (SandboxExtension::createHandleForGenericExtension(audioExtensionPath, handles[--extensionCount])) {
-                ids.append(audioExtensionPath);
-                currentExtensions |= ProcessState::SandboxExtensionsGranted::Audio;
-            }
-        }
+        if (withAudio && SandboxExtension::createHandleForGenericExtension(audioExtensionPath, handles[--extensionCount]))
+            ids.append(audioExtensionPath);
 
-        if (withVideo && requiredExtensions & ProcessState::SandboxExtensionsGranted::Video) {
-            if (SandboxExtension::createHandleForGenericExtension(videoExtensionPath, handles[--extensionCount])) {
-                ids.append(videoExtensionPath);
-                currentExtensions |= ProcessState::SandboxExtensionsGranted::Video;
-            }
-        }
+        if (withVideo && SandboxExtension::createHandleForGenericExtension(videoExtensionPath, handles[--extensionCount]))
+            ids.append(videoExtensionPath);
 
         if (ids.size() != handles.size()) {
             WTFLogAlways("Could not create a required sandbox extension, capture will fail!");
             return false;
         }
 
-        state.setSandboxExtensionsGranted(currentExtensions);
+        if (withAudio)
+            state.grantAudioExtension();
+        if (withVideo)
+            state.grantVideoExtension();
         processStartingCapture.send(Messages::WebPage::GrantUserMediaDeviceSandboxExtensions(MediaDeviceSandboxExtensions(ids, WTFMove(handles))), proxy.page().pageID());
     }
 #else
@@ -220,20 +222,18 @@ void UserMediaProcessManager::endedCaptureSession(UserMediaPermissionRequestMana
         return;
 
     Vector<String> params;
-    unsigned currentExtensions = state.sandboxExtensionsGranted();
-    if (!hasAudioCapture && currentExtensions & ProcessState::SandboxExtensionsGranted::Audio) {
+    if (!hasAudioCapture && state.hasAudioExtension()) {
         params.append(audioExtensionPath);
-        currentExtensions &= ~ProcessState::SandboxExtensionsGranted::Audio;
+        state.revokeAudioExtension();
     }
-    if (!hasVideoCapture && currentExtensions & ProcessState::SandboxExtensionsGranted::Video) {
+    if (!hasVideoCapture && state.hasVideoExtension()) {
         params.append(videoExtensionPath);
-        currentExtensions &= ~ProcessState::SandboxExtensionsGranted::Video;
+        state.revokeVideoExtension();
     }
 
     if (params.isEmpty())
         return;
 
-    state.setSandboxExtensionsGranted(currentExtensions);
     proxy.page().process().send(Messages::WebPage::RevokeUserMediaDeviceSandboxExtensions(params), proxy.page().pageID());
 #endif
 }