Add an option to disable getUserMedia prompt in case of mock capture sources
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Jun 2017 16:53:55 +0000 (16:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Jun 2017 16:53:55 +0000 (16:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172981
<rdar://problem/32580325>

Patch by Youenn Fablet <youenn@apple.com> on 2017-06-06
Reviewed by Eric Carlson.

Source/WebKit/mac:

Defining the option, getter and setter.

* WebView/WebPreferences.mm:
(+[WebPreferences initialize]):
(-[WebPreferences mockCaptureDevicesPromptEnabled]):
(-[WebPreferences setMockCaptureDevicesPromptEnabled:]):
* WebView/WebPreferencesPrivate.h:

Source/WebKit2:

Adding mockCaptureDevicesPromptEnabled option.
Allowing any getUserMedia request if mock is on and prompt is off.

Renaming UserMediaProcessManager::willEnableMediaStreamInPage to muteCaptureMediaStreamsExceptIn.
This eases reading the code.
Making sure that a page for which a new getUserMedia MediaStream will be created is capture-unmuted.

* Shared/WebPreferencesDefinitions.h:
* UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
(WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame):
* UIProcess/UserMediaProcessManager.cpp:
(WebKit::UserMediaProcessManager::muteCaptureMediaStreamsExceptIn):
(WebKit::UserMediaProcessManager::willCreateMediaStream):
* UIProcess/UserMediaProcessManager.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setMuted):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::activateMediaStreamCaptureInPage):

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

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKit/mac/WebView/WebPreferences.mm
Source/WebKit/mac/WebView/WebPreferencesPrivate.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPreferencesDefinitions.h
Source/WebKit2/UIProcess/UserMediaPermissionRequestManagerProxy.cpp
Source/WebKit2/UIProcess/UserMediaProcessManager.cpp
Source/WebKit2/UIProcess/UserMediaProcessManager.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h

index c93dafa..6b5c6a2 100644 (file)
@@ -1,3 +1,19 @@
+2017-06-06  Youenn Fablet  <youenn@apple.com>
+
+        Add an option to disable getUserMedia prompt in case of mock capture sources
+        https://bugs.webkit.org/show_bug.cgi?id=172981
+        <rdar://problem/32580325>
+
+        Reviewed by Eric Carlson.
+
+        Defining the option, getter and setter.
+
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences initialize]):
+        (-[WebPreferences mockCaptureDevicesPromptEnabled]):
+        (-[WebPreferences setMockCaptureDevicesPromptEnabled:]):
+        * WebView/WebPreferencesPrivate.h:
+
 2017-06-05  Dan Bernstein  <mitz@apple.com>
 
         Tried to fix the build when targrting macOS 10.12 using the macOS 10.13 developer beta SDK.
index 0380f02..61dc8e8 100644 (file)
 #define WebKitEnableInheritURIQueryComponentPreferenceKey @"WebKitEnableInheritURIQueryComponent"
 #define WebKitMediaDataLoadsAutomaticallyPreferenceKey @"WebKitMediaDataLoadsAutomatically"
 #define WebKitMockCaptureDevicesEnabledPreferenceKey @"WebKitMockCaptureDevicesEnabled"
+#define WebKitMockCaptureDevicesPromptEnabledPreferenceKey @"WebKitMockCaptureDevicesPromptEnabled"
 #define WebKitEnumeratingAllNetworkInterfacesEnabledPreferenceKey @"WebKitEnumeratingAllNetworkInterfacesEnabled"
 #define WebKitICECandidateFilteringEnabledPreferenceKey @"WebKitICECandidateFilteringEnabled"
 #define WebKitMediaCaptureRequiresSecureConnectionPreferenceKey @"WebKitMediaCaptureRequiresSecureConnection"
index 6e9425a..38bf921 100644 (file)
@@ -618,6 +618,7 @@ public:
 #endif
 #if ENABLE(MEDIA_STREAM)
         [NSNumber numberWithBool:NO], WebKitMockCaptureDevicesEnabledPreferenceKey,
+        [NSNumber numberWithBool:YES], WebKitMockCaptureDevicesPromptEnabledPreferenceKey,
         [NSNumber numberWithBool:YES], WebKitMediaCaptureRequiresSecureConnectionPreferenceKey,
 #endif
         [NSNumber numberWithBool:YES], WebKitShadowDOMEnabledPreferenceKey,
@@ -2883,6 +2884,16 @@ static NSString *classIBCreatorID = nil;
     [self _setBoolValue:flag forKey:WebKitMockCaptureDevicesEnabledPreferenceKey];
 }
 
+- (BOOL)mockCaptureDevicesPromptEnabled
+{
+    return [self _boolValueForKey:WebKitMockCaptureDevicesPromptEnabledPreferenceKey];
+}
+
+- (void)setMockCaptureDevicesPromptEnabled:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitMockCaptureDevicesPromptEnabledPreferenceKey];
+}
+
 - (BOOL)enumeratingAllNetworkInterfacesEnabled
 {
     return [self _boolValueForKey:WebKitEnumeratingAllNetworkInterfacesEnabledPreferenceKey];
index defbd26..cf3d988 100644 (file)
@@ -505,6 +505,9 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification;
 - (void)setMockCaptureDevicesEnabled:(BOOL)flag;
 - (BOOL)mockCaptureDevicesEnabled;
 
+- (void)setMockCaptureDevicesPromptEnabled:(BOOL)flag;
+- (BOOL)mockCaptureDevicesPromptEnabled;
+
 - (void)setEnumeratingAllNetworkInterfacesEnabled:(BOOL)flag;
 - (BOOL)enumeratingAllNetworkInterfacesEnabled;
 
index 5fd94e4..bd725f8 100644 (file)
@@ -1,3 +1,30 @@
+2017-06-06  Youenn Fablet  <youenn@apple.com>
+
+        Add an option to disable getUserMedia prompt in case of mock capture sources
+        https://bugs.webkit.org/show_bug.cgi?id=172981
+        <rdar://problem/32580325>
+
+        Reviewed by Eric Carlson.
+
+        Adding mockCaptureDevicesPromptEnabled option.
+        Allowing any getUserMedia request if mock is on and prompt is off.
+
+        Renaming UserMediaProcessManager::willEnableMediaStreamInPage to muteCaptureMediaStreamsExceptIn.
+        This eases reading the code.
+        Making sure that a page for which a new getUserMedia MediaStream will be created is capture-unmuted.
+
+        * Shared/WebPreferencesDefinitions.h:
+        * UIProcess/UserMediaPermissionRequestManagerProxy.cpp:
+        (WebKit::UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame):
+        * UIProcess/UserMediaProcessManager.cpp:
+        (WebKit::UserMediaProcessManager::muteCaptureMediaStreamsExceptIn):
+        (WebKit::UserMediaProcessManager::willCreateMediaStream):
+        * UIProcess/UserMediaProcessManager.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setMuted):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::activateMediaStreamCaptureInPage):
+
 2017-06-06  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [WPE] Enable remote inspector
index 1eda2e4..a2530df 100644 (file)
     macro(DeferredCSSParserEnabled, deferredCSSParserEnabled, Bool, bool, false, "", "") \
     macro(HTTPEquivEnabled, httpEquivEnabled, Bool, bool, true, "", "") \
     macro(MockCaptureDevicesEnabled, mockCaptureDevicesEnabled, Bool, bool, false, "", "") \
+    macro(MockCaptureDevicesPromptEnabled, mockCaptureDevicesPromptEnabled, Bool, bool, true, "", "") \
     macro(MediaCaptureRequiresSecureConnection, mediaCaptureRequiresSecureConnection, Bool, bool, true, "", "") \
     macro(EnumeratingAllNetworkInterfacesEnabled, enumeratingAllNetworkInterfacesEnabled, Bool, bool, false, "", "") \
     macro(ICECandidateFilteringEnabled, iceCandidateFilteringEnabled, Bool, bool, true, "", "") \
index 35a56b3..97fdf6f 100644 (file)
@@ -209,6 +209,14 @@ void UserMediaPermissionRequestManagerProxy::requestUserMediaPermissionForFrame(
         auto topLevelOrigin = API::SecurityOrigin::create(topLevelDocumentOrigin.get());
         auto request = createRequest(userMediaID, frameID, WTFMove(userMediaDocumentOrigin), WTFMove(topLevelDocumentOrigin), WTFMove(audioDeviceUIDs), WTFMove(videoDeviceUIDs), WTFMove(deviceIdentifierHashSalt));
 
+        if (m_page.preferences().mockCaptureDevicesEnabled() && !m_page.preferences().mockCaptureDevicesPromptEnabled()) {
+            // FIXME: https://bugs.webkit.org/show_bug.cgi?id=172989
+            // We should probably only allow this if page is already actively capturing or page is visible.
+            // If page is hidden and not capturing, we should wait for page to be visible before allowing the request.
+            request->allow(request->audioDeviceUIDs().isEmpty() ? String() : request->audioDeviceUIDs()[0], request->videoDeviceUIDs().isEmpty() ? String() : request->videoDeviceUIDs()[0]);
+            return;
+        }
+
         if (!m_page.uiClient().decidePolicyForUserMediaPermissionRequest(m_page, *m_page.process().webFrame(frameID), WTFMove(userMediaOrigin), WTFMove(topLevelOrigin), request.get()))
             userMediaAccessWasDenied(userMediaID, UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled);
     };
index 17635df..80a488d 100644 (file)
@@ -109,14 +109,13 @@ void UserMediaProcessManager::removeUserMediaPermissionRequestManagerProxy(UserM
     }
 }
 
-void UserMediaProcessManager::willEnableMediaStreamInPage(WebPageProxy& pageStartingCapture)
+void UserMediaProcessManager::muteCaptureMediaStreamsExceptIn(WebPageProxy& pageStartingCapture)
 {
 #if PLATFORM(COCOA)
     for (auto& state : stateMap()) {
         for (auto& manager : state.value->managers()) {
             if (&manager->page() == &pageStartingCapture)
                 continue;
-
             manager->page().setMuted(WebCore::MediaProducer::CaptureDevicesAreMuted);
         }
     }
@@ -132,7 +131,7 @@ void UserMediaProcessManager::willCreateMediaStream(UserMediaPermissionRequestMa
 
     ASSERT(stateMap().contains(&processStartingCapture));
 
-    willEnableMediaStreamInPage(proxy.page());
+    proxy.page().activateMediaStreamCaptureInPage();
 
     auto& state = processState(processStartingCapture);
     size_t extensionCount = 0;
index 8c5bc68..e14252f 100644 (file)
@@ -35,7 +35,7 @@ public:
     void removeUserMediaPermissionRequestManagerProxy(UserMediaPermissionRequestManagerProxy&);
 
     void willCreateMediaStream(UserMediaPermissionRequestManagerProxy&, bool withAudio, bool withVideo);
-    void willEnableMediaStreamInPage(WebPageProxy&);
+    void muteCaptureMediaStreamsExceptIn(WebPageProxy&);
 
     void startedCaptureSession(UserMediaPermissionRequestManagerProxy&);
     void endedCaptureSession(UserMediaPermissionRequestManagerProxy&);
index cb17f60..17e00e6 100644 (file)
@@ -4184,7 +4184,7 @@ void WebPageProxy::setMuted(WebCore::MediaProducer::MutedStateFlags state)
 
 #if ENABLE(MEDIA_STREAM)
     if (!(state & WebCore::MediaProducer::CaptureDevicesAreMuted))
-        UserMediaProcessManager::singleton().willEnableMediaStreamInPage(*this);
+        UserMediaProcessManager::singleton().muteCaptureMediaStreamsExceptIn(*this);
 #endif
 
     m_process->send(Messages::WebPage::SetMuted(state), m_pageID);
index a8271ba..7166aba 100644 (file)
@@ -470,6 +470,8 @@ public:
     void setEditable(bool);
     bool isEditable() const { return m_isEditable; }
 
+    void activateMediaStreamCaptureInPage() { setMuted(m_mutedState & ~WebCore::MediaProducer::CaptureDevicesAreMuted); }
+
 #if PLATFORM(IOS)
     void executeEditCommand(const String& commandName, std::function<void (CallbackBase::Error)>);
     double displayedContentScale() const { return m_lastVisibleContentRectUpdate.scale(); }