Remote WebInspector should enable mock capture devices in UIProcess if doing it in...
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Jul 2019 00:55:16 +0000 (00:55 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Jul 2019 00:55:16 +0000 (00:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199924
<rdar://problem/50552067>

Reviewed by Devin Rousso.

Source/WebCore:

Add necessary API to set mock capture devices override.
In case of desynchronization between webprocess and uiprocess, make sure to return early
and fail capture instead of crashing.

* inspector/InspectorClient.h:
(WebCore::InspectorClient::setMockCaptureDevicesEnabled):
* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::disable):
(WebCore::InspectorPageAgent::overrideSetting):
* platform/mock/MockRealtimeMediaSourceCenter.cpp:

Source/WebKit:

Add IPC plumbery to pass inspector override value for mock capture devices.
Add an override in UserMediaPermissionRequestManagerProxy so that the value stays in sync with web inspector.
The override will be removed when web inspector goes away.

* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs const):
* UIProcess/UserMediaPermissionRequestManagerProxy.h:
(WebKit::UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride):
* UIProcess/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::setMockCaptureDevicesEnabled):
* UIProcess/WebInspectorProxy.h:
* UIProcess/WebInspectorProxy.messages.in:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setMockCaptureDevicesEnabledOverride):
* UIProcess/WebPageProxy.h:
* WebProcess/WebCoreSupport/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::setMockCaptureDevicesEnabled):
* WebProcess/WebCoreSupport/WebInspectorClient.h:
* WebProcess/WebPage/WebInspector.cpp:
(WebKit::WebInspector::setMockCaptureDevicesEnabled):
* WebProcess/WebPage/WebInspector.h:

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorClient.h
Source/WebCore/inspector/agents/InspectorPageAgent.cpp
Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.h
Source/WebKit/UIProcess/WebInspectorProxy.cpp
Source/WebKit/UIProcess/WebInspectorProxy.h
Source/WebKit/UIProcess/WebInspectorProxy.messages.in
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.h
Source/WebKit/WebProcess/WebPage/WebInspector.cpp
Source/WebKit/WebProcess/WebPage/WebInspector.h

index 44c414c..0178670 100644 (file)
@@ -1,3 +1,22 @@
+2019-07-19  Youenn Fablet  <youenn@apple.com>
+
+        Remote WebInspector should enable mock capture devices in UIProcess if doing it in WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=199924
+        <rdar://problem/50552067>
+
+        Reviewed by Devin Rousso.
+
+        Add necessary API to set mock capture devices override.
+        In case of desynchronization between webprocess and uiprocess, make sure to return early
+        and fail capture instead of crashing.
+
+        * inspector/InspectorClient.h:
+        (WebCore::InspectorClient::setMockCaptureDevicesEnabled):
+        * inspector/agents/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::disable):
+        (WebCore::InspectorPageAgent::overrideSetting):
+        * platform/mock/MockRealtimeMediaSourceCenter.cpp:
+
 2019-07-19  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] Log less in PaymentCoordinator::shouldEnableApplePayAPIs()
index 609d125..acf9d57 100644 (file)
@@ -27,6 +27,7 @@
 #pragma once
 
 #include <wtf/Forward.h>
+#include <wtf/Optional.h>
 
 namespace Inspector {
 class FrontendChannel;
@@ -62,6 +63,8 @@ public:
     virtual void didSetSearchingForNode(bool) { }
     virtual void elementSelectionChanged(bool) { }
 
+    virtual void setMockCaptureDevicesEnabledOverride(Optional<bool>) { }
+
 #if ENABLE(REMOTE_INSPECTOR)
     virtual bool allowRemoteInspectionToPageDirectly() const { return false; }
 #endif
index a0f4ad8..ccd7159 100644 (file)
@@ -388,6 +388,8 @@ void InspectorPageAgent::disable(ErrorString&)
 
 #undef DISABLE_INSPECTOR_OVERRIDE_SETTING
 
+    m_client->setMockCaptureDevicesEnabledOverride(WTF::nullopt);
+
     m_instrumentingAgents.setInspectorPageAgent(nullptr);
 }
 
@@ -435,20 +437,22 @@ void InspectorPageAgent::overrideSetting(ErrorString& errorString, const String&
 
     switch (setting.value()) {
 #define CASE_INSPECTOR_OVERRIDE_SETTING(name) \
-    case Inspector::Protocol::Page::Setting::name: { \
-        if (value) \
-            m_inspectedPage.settings().set##name##InspectorOverride(*value); \
-        else \
+    case Inspector::Protocol::Page::Setting::name: {                               \
+        if (value)                                                                 \
+            m_inspectedPage.settings().set##name##InspectorOverride(*value);       \
+        else                                                                       \
             m_inspectedPage.settings().set##name##InspectorOverride(WTF::nullopt); \
-        return; \
-    } \
+        break;                                                                     \
+    }                                                                              \
 
     FOR_EACH_INSPECTOR_OVERRIDE_SETTING(CASE_INSPECTOR_OVERRIDE_SETTING)
 
 #undef CASE_INSPECTOR_OVERRIDE_SETTING
     }
 
-    ASSERT_NOT_REACHED();
+    // Update the UIProcess / client for particular overrides.
+    if (setting.value() == Inspector::Protocol::Page::Setting::MockCaptureDevicesEnabled)
+        m_client->setMockCaptureDevicesEnabledOverride(value);
 }
 
 static Inspector::Protocol::Page::CookieSameSitePolicy cookieSameSitePolicyJSON(Cookie::SameSitePolicy policy)
index 6d83b50..d431683 100644 (file)
@@ -89,7 +89,8 @@ public:
     CaptureSourceOrError createVideoCaptureSource(const CaptureDevice& device, String&& hashSalt, const MediaConstraints* constraints) final
     {
         ASSERT(device.type() == CaptureDevice::DeviceType::Camera);
-        ASSERT(MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(CaptureDevice::DeviceType::Camera, device.persistentId()));
+        if (!MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(CaptureDevice::DeviceType::Camera, device.persistentId()))
+            return { };
 
         return MockRealtimeVideoSource::create(String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt), constraints);
     }
@@ -109,7 +110,8 @@ class MockRealtimeDisplaySourceFactory : public DisplayCaptureFactory {
 public:
     CaptureSourceOrError createDisplayCaptureSource(const CaptureDevice& device, const MediaConstraints* constraints) final
     {
-        ASSERT(MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(device.type(), device.persistentId()));
+        if (!MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(device.type(), device.persistentId()))
+            return { };
 
         switch (device.type()) {
         case CaptureDevice::DeviceType::Screen:
@@ -134,7 +136,8 @@ public:
     CaptureSourceOrError createAudioCaptureSource(const CaptureDevice& device, String&& hashSalt, const MediaConstraints* constraints) final
     {
         ASSERT(device.type() == CaptureDevice::DeviceType::Microphone);
-        ASSERT(MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(CaptureDevice::DeviceType::Microphone, device.persistentId()));
+        if (!MockRealtimeMediaSourceCenter::captureDeviceWithPersistentID(CaptureDevice::DeviceType::Microphone, device.persistentId()))
+            return { };
 
         return MockRealtimeAudioSource::create(String { device.persistentId() }, String { device.label() }, WTFMove(hashSalt), constraints);
     }
index ca865e3..fec2492 100644 (file)
@@ -1,3 +1,33 @@
+2019-07-19  Youenn Fablet  <youenn@apple.com>
+
+        Remote WebInspector should enable mock capture devices in UIProcess if doing it in WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=199924
+        <rdar://problem/50552067>
+
+        Reviewed by Devin Rousso.
+
+        Add IPC plumbery to pass inspector override value for mock capture devices.
+        Add an override in UserMediaPermissionRequestManagerProxy so that the value stays in sync with web inspector.
+        The override will be removed when web inspector goes away.
+
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        (WebKit::UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs const):
+        * UIProcess/UserMediaPermissionRequestManagerProxy.h:
+        (WebKit::UserMediaPermissionRequestManagerProxy::setMockCaptureDevicesEnabledOverride):
+        * UIProcess/WebInspectorProxy.cpp:
+        (WebKit::WebInspectorProxy::setMockCaptureDevicesEnabled):
+        * UIProcess/WebInspectorProxy.h:
+        * UIProcess/WebInspectorProxy.messages.in:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setMockCaptureDevicesEnabledOverride):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
+        (WebKit::WebInspectorClient::setMockCaptureDevicesEnabled):
+        * WebProcess/WebCoreSupport/WebInspectorClient.h:
+        * WebProcess/WebPage/WebInspector.cpp:
+        (WebKit::WebInspector::setMockCaptureDevicesEnabled):
+        * WebProcess/WebPage/WebInspector.h:
+
 2019-07-19  Tim Horton  <timothy_horton@apple.com>
 
         Web Content process gets stuck suspended after navigating away from a system preview
index de5598b..f9fb117 100644 (file)
@@ -651,7 +651,7 @@ void UserMediaPermissionRequestManagerProxy::syncWithWebCorePrefs() const
 #if ENABLE(MEDIA_STREAM)
     // Enable/disable the mock capture devices for the UI process as per the WebCore preferences. Note that
     // this is a noop if the preference hasn't changed since the last time this was called.
-    bool mockDevicesEnabled = m_page.preferences().mockCaptureDevicesEnabled();
+    bool mockDevicesEnabled = m_mockDevicesEnabledOverride ? *m_mockDevicesEnabledOverride : m_page.preferences().mockCaptureDevicesEnabled();
     MockRealtimeMediaSourceCenter::setMockRealtimeMediaSourceCenterEnabled(mockDevicesEnabled);
 #endif
 }
index 6f13410..f505e28 100644 (file)
@@ -85,6 +85,8 @@ public:
         Prompt
     };
 
+    void setMockCaptureDevicesEnabledOverride(Optional<bool> enabled) { m_mockDevicesEnabledOverride = enabled; }
+
 private:
 #if !RELEASE_LOG_DISABLED
     const Logger& logger() const final;
@@ -150,6 +152,7 @@ private:
 #endif
     bool m_hasFilteredDeviceList { false };
     uint64_t m_hasPendingCapture { 0 };
+    Optional<bool> m_mockDevicesEnabledOverride;
 };
 
 String convertEnumerationToString(UserMediaPermissionRequestManagerProxy::RequestAction);
index 6bbf85b..7a33e69 100644 (file)
@@ -42,6 +42,7 @@
 #include "WebProcessPool.h"
 #include "WebProcessProxy.h"
 #include <WebCore/CertificateInfo.h>
+#include <WebCore/MockRealtimeMediaSourceCenter.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/TextEncoding.h>
 #include <wtf/SetForScope.h>
@@ -592,6 +593,18 @@ void WebInspectorProxy::elementSelectionChanged(bool active)
         bringToFront();
 }
 
+void WebInspectorProxy::setMockCaptureDevicesEnabledOverride(Optional<bool> enabled)
+{
+#if ENABLE(MEDIA_STREAM)
+    if (!m_inspectedPage)
+        return;
+
+    m_inspectedPage->setMockCaptureDevicesEnabledOverride(enabled);
+#else
+    UNUSED_PARAM(enabled);
+#endif
+}
+
 void WebInspectorProxy::save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs)
 {
     platformSave(filename, content, base64Encoded, forceSaveAs);
index 8be27d4..4b31b6a 100644 (file)
@@ -227,6 +227,7 @@ private:
     void inspectedURLChanged(const String&);
     void showCertificate(const WebCore::CertificateInfo&);
     void elementSelectionChanged(bool);
+    void setMockCaptureDevicesEnabledOverride(Optional<bool>);
 
     void save(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
     void append(const String& filename, const String& content);
index 7d4a99d..d9da795 100644 (file)
@@ -35,6 +35,7 @@ messages -> WebInspectorProxy {
     InspectedURLChanged(String urlString)
     ShowCertificate(WebCore::CertificateInfo certificateInfo)
     ElementSelectionChanged(bool active)
+    SetMockCaptureDevicesEnabledOverride(Optional<bool> enabled)
 
     Save(String filename, String content, bool base64Encoded, bool forceSaveAs)
     Append(String filename, String content)
index 18ca17f..7c81784 100644 (file)
@@ -7394,6 +7394,11 @@ UserMediaPermissionRequestManagerProxy& WebPageProxy::userMediaPermissionRequest
     m_userMediaPermissionRequestManager = std::make_unique<UserMediaPermissionRequestManagerProxy>(*this);
     return *m_userMediaPermissionRequestManager;
 }
+
+void WebPageProxy::setMockCaptureDevicesEnabledOverride(Optional<bool> enabled)
+{
+    userMediaPermissionRequestManager().setMockCaptureDevicesEnabledOverride(enabled);
+}
 #endif
 
 void WebPageProxy::requestUserMediaPermissionForFrame(uint64_t userMediaID, uint64_t frameID, const WebCore::SecurityOriginData&  userMediaDocumentOriginData, const WebCore::SecurityOriginData& topLevelDocumentOriginData, WebCore::MediaStreamRequest&& request)
index 01831b9..f56778d 100644 (file)
@@ -1561,6 +1561,10 @@ public:
 
     URL currentResourceDirectoryURL() const;
 
+#if ENABLE(MEDIA_STREAM)
+    void setMockCaptureDevicesEnabledOverride(Optional<bool>);
+#endif
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, WebCore::PageIdentifier, Ref<API::PageConfiguration>&&);
     void platformInitialize();
index 2966c3d..3e20a7f 100644 (file)
@@ -211,6 +211,12 @@ void WebInspectorClient::elementSelectionChanged(bool active)
         m_page->inspector()->elementSelectionChanged(active);
 }
 
+void WebInspectorClient::setMockCaptureDevicesEnabledOverride(Optional<bool> enabled)
+{
+    if (m_page->inspector())
+        m_page->inspector()->setMockCaptureDevicesEnabledOverride(enabled);
+}
+
 void WebInspectorClient::willMoveToPage(PageOverlay&, Page* page)
 {
     if (page)
index d5dabf1..6ab8b20 100644 (file)
@@ -71,6 +71,8 @@ private:
     bool overridesShowPaintRects() const override { return true; }
     void showPaintRect(const WebCore::FloatRect&) override;
 
+    void setMockCaptureDevicesEnabledOverride(Optional<bool>) final;
+
     // PageOverlay::Client
     void willMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override;
     void didMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override;
index d77e637..b6d38ac 100644 (file)
@@ -284,6 +284,11 @@ void WebInspector::elementSelectionChanged(bool active)
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::ElementSelectionChanged(active), m_page->pageID());
 }
 
+void WebInspector::setMockCaptureDevicesEnabledOverride(Optional<bool> enabled)
+{
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::SetMockCaptureDevicesEnabledOverride(enabled), m_page->pageID());
+}
+
 bool WebInspector::canAttachWindow()
 {
     if (!m_page->corePage())
index 69029eb..89cb83b 100644 (file)
@@ -73,6 +73,7 @@ public:
     void startElementSelection();
     void stopElementSelection();
     void elementSelectionChanged(bool);
+    void setMockCaptureDevicesEnabledOverride(Optional<bool>);
 
     void setFrontendConnection(IPC::Attachment);