Title: [267414] trunk
Revision
267414
Author
[email protected]
Date
2020-09-22 09:32:11 -0700 (Tue, 22 Sep 2020)

Log Message

Implement a default prompt for getUserMedia
https://bugs.webkit.org/show_bug.cgi?id=216821

Reviewed by Eric Carlson.

Source/WebCore:

Manually tested by running Minibrowser.

* en.lproj/Localizable.strings:

Source/WebKit:

Move preferences used by WebRTC develop menu to internals.
This allows having them in MiniBrowser.

Enable video capture in UIProcess by default for non Safari applications.
Add support for a getUserMedia prompt, very similar to iOS current prompt.
Use the prompt in case the application does not implement any of the two delegates.

* Shared/WebPreferences.yaml:
* Shared/WebPreferencesDefaultValues.cpp:
(WebKit::defaultCaptureVideoInUIProcessEnabled):
* Shared/WebPreferencesDefaultValues.h:
* Shared/WebPreferencesExperimental.yaml:
* Shared/WebPreferencesInternal.yaml:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::requestUserMediaAuthorizationForFrame):
(WebKit::UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest):
* UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.h: Added.
* UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.mm: Added.
(WebKit::visibleDomain):
(WebKit::alertMessageText):
(WebKit::presentUserMediaCaptureAccessAlert):
* WebKit.xcodeproj/project.pbxproj:

Tools:

Remove getUserMedia delegate implementations to use WebKit built-in prompt.
Add camera and microphone entitlements to allow using real cameras and microphones.
Keep using mock devices as the default.

* MiniBrowser/MiniBrowser.entitlements:
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController _webView:requestMediaCaptureAuthorization:decisionHandler:]): Deleted.
(-[WK2BrowserWindowController _webView:includeSensitiveMediaDeviceDetails:]): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (267413 => 267414)


--- trunk/Source/WebCore/ChangeLog	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebCore/ChangeLog	2020-09-22 16:32:11 UTC (rev 267414)
@@ -1,3 +1,14 @@
+2020-09-22  Youenn Fablet  <[email protected]>
+
+        Implement a default prompt for getUserMedia
+        https://bugs.webkit.org/show_bug.cgi?id=216821
+
+        Reviewed by Eric Carlson.
+
+        Manually tested by running Minibrowser.
+
+        * en.lproj/Localizable.strings:
+
 2020-09-22  Chris Dumez  <[email protected]>
 
         webaudio/AudioParam/audioparam-setTarget-timeConstant-0.html is crashing

Modified: trunk/Source/WebCore/en.lproj/Localizable.strings (267413 => 267414)


--- trunk/Source/WebCore/en.lproj/Localizable.strings	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebCore/en.lproj/Localizable.strings	2020-09-22 16:32:11 UTC (rev 267414)
@@ -124,6 +124,21 @@
 /* Message for requesting cross-site cookie and website data access. */
 "Allow “%@” to use cookies and website data while browsing “%@”?" = "Allow “%@” to use cookies and website data while browsing “%@”?";
 
+/* Message for user media prompt */
+"Allow “%@” to use your camera and microphone?" = "Allow “%@” to use your camera and microphone?";
+
+/* Message for user camera access prompt */
+"Allow “%@” to use your camera?" = "Allow “%@” to use your camera?";
+
+/* Message for user microphone access prompt */
+"Allow “%@” to use your microphone?" = "Allow “%@” to use your microphone?";
+
+/* Allow button title in user media prompt */
+"Allow (usermedia)" = "Allow";
+
+/* Disallow button title in user media prompt */
+"Don’t Allow (usermedia)" = "Don’t Allow";
+
 /* WKErrorUnknown description */
 "An unknown error occurred" = "An unknown error occurred";
 

Modified: trunk/Source/WebKit/ChangeLog (267413 => 267414)


--- trunk/Source/WebKit/ChangeLog	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/ChangeLog	2020-09-22 16:32:11 UTC (rev 267414)
@@ -1,3 +1,35 @@
+2020-09-22  Youenn Fablet  <[email protected]>
+
+        Implement a default prompt for getUserMedia
+        https://bugs.webkit.org/show_bug.cgi?id=216821
+
+        Reviewed by Eric Carlson.
+
+        Move preferences used by WebRTC develop menu to internals.
+        This allows having them in MiniBrowser.
+
+        Enable video capture in UIProcess by default for non Safari applications.
+        Add support for a getUserMedia prompt, very similar to iOS current prompt.
+        Use the prompt in case the application does not implement any of the two delegates.
+
+        * Shared/WebPreferences.yaml:
+        * Shared/WebPreferencesDefaultValues.cpp:
+        (WebKit::defaultCaptureVideoInUIProcessEnabled):
+        * Shared/WebPreferencesDefaultValues.h:
+        * Shared/WebPreferencesExperimental.yaml:
+        * Shared/WebPreferencesInternal.yaml:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::requestUserMediaAuthorizationForFrame):
+        (WebKit::UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest):
+        * UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.h: Added.
+        * UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.mm: Added.
+        (WebKit::visibleDomain):
+        (WebKit::alertMessageText):
+        (WebKit::presentUserMediaCaptureAccessAlert):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2020-09-22  Brady Eidson  <[email protected]>
 
         Crashtracer inside PDFPlugin::createScrollbar.

Modified: trunk/Source/WebKit/Shared/WebPreferences.yaml (267413 => 267414)


--- trunk/Source/WebKit/Shared/WebPreferences.yaml	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/Shared/WebPreferences.yaml	2020-09-22 16:32:11 UTC (rev 267414)
@@ -994,19 +994,3 @@
   humanReadableDescription: "Enable an accessibility hierarchy for VoiceOver that can be accessed on a secondary thread for improved performance"
   webcoreBinding: RuntimeEnabledFeatures
   condition: ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-
-# Deprecated
-
-ICECandidateFilteringEnabled:
-  type: bool
-  defaultValue: true
-
-MockCaptureDevicesEnabled:
-  type: bool
-  defaultValue: DEFAULT_MOCK_CAPTURE_DEVICES_ENABLED
-  condition: ENABLE(MEDIA_STREAM)
-
-MediaCaptureRequiresSecureConnection:
-  type: bool
-  defaultValue: true
-  condition: ENABLE(MEDIA_STREAM)

Modified: trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp (267413 => 267414)


--- trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.cpp	2020-09-22 16:32:11 UTC (rev 267414)
@@ -169,6 +169,15 @@
     return false;
 }
 
+bool defaultCaptureVideoInUIProcessEnabled()
+{
+#if PLATFORM(MAC)
+    return !MacApplication::isSafari();
+#endif
+
+    return false;
+}
+
 #endif // ENABLE(MEDIA_STREAM)
 
 #if ENABLE(WEB_RTC)

Modified: trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h (267413 => 267414)


--- trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h	2020-09-22 16:32:11 UTC (rev 267414)
@@ -344,6 +344,7 @@
 bool defaultCaptureAudioInGPUProcessEnabled();
 bool defaultCaptureAudioInUIProcessEnabled();
 bool defaultCaptureVideoInGPUProcessEnabled();
+bool defaultCaptureVideoInUIProcessEnabled();
 #endif
 
 #if ENABLE(WEB_RTC)

Modified: trunk/Source/WebKit/Shared/WebPreferencesExperimental.yaml (267413 => 267414)


--- trunk/Source/WebKit/Shared/WebPreferencesExperimental.yaml	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/Shared/WebPreferencesExperimental.yaml	2020-09-22 16:32:11 UTC (rev 267414)
@@ -393,14 +393,6 @@
   humanReadableDescription: "Enable Generic Text Track Cue API"
   webcoreName: genericCueAPIEnabled
 
-CaptureVideoInUIProcessEnabled:
-  type: bool
-  defaultValue: false
-  humanReadableName: "Capture video in UI Process"
-  humanReadableDescription: "Enable video capture in UI Process"
-  webcoreBinding: none
-  condition: ENABLE(MEDIA_STREAM)
-
 AspectRatioOfImgFromWidthAndHeightEnabled:
   type: bool
   defaultValue: true

Modified: trunk/Source/WebKit/Shared/WebPreferencesInternal.yaml (267413 => 267414)


--- trunk/Source/WebKit/Shared/WebPreferencesInternal.yaml	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/Shared/WebPreferencesInternal.yaml	2020-09-22 16:32:11 UTC (rev 267414)
@@ -106,6 +106,30 @@
   humanReadableName: "Block small plugins"
   humanReadableDescription: "Stop plugins smaller than a certain threshold from loading."
 
+CaptureAudioInUIProcessEnabled:
+  type: bool
+  defaultValue: defaultCaptureAudioInUIProcessEnabled()
+  humanReadableName: "Capture audio in UI Process"
+  humanReadableDescription: "Enable audio capture in UI Process"
+  webcoreBinding: none
+  condition: ENABLE(MEDIA_STREAM)
+
+CaptureAudioInGPUProcessEnabled:
+  type: bool
+  defaultValue: defaultCaptureAudioInGPUProcessEnabled()
+  humanReadableName: "Use GPU Process to capture audio"
+  humanReadableDescription: "Enable audio capture in GPU Process"
+  webcoreBinding: none
+  condition: ENABLE(MEDIA_STREAM)
+
+CaptureVideoInUIProcessEnabled:
+  type: bool
+  defaultValue: defaultCaptureVideoInUIProcessEnabled()
+  humanReadableName: "Capture video in UI Process"
+  humanReadableDescription: "Enable video capture in UI Process"
+  webcoreBinding: none
+  condition: ENABLE(MEDIA_STREAM)
+
 CaptureVideoInGPUProcessEnabled:
   type: bool
   defaultValue: defaultCaptureVideoInGPUProcessEnabled()
@@ -299,22 +323,6 @@
   webcoreBinding: RuntimeEnabledFeatures
   condition: ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
-CaptureAudioInUIProcessEnabled:
-  type: bool
-  defaultValue: defaultCaptureAudioInUIProcessEnabled()
-  humanReadableName: "Capture audio in UI Process"
-  humanReadableDescription: "Enable audio capture in UI Process"
-  webcoreBinding: none
-  condition: ENABLE(MEDIA_STREAM)
-
-CaptureAudioInGPUProcessEnabled:
-  type: bool
-  defaultValue: defaultCaptureAudioInGPUProcessEnabled()
-  humanReadableName: "Use GPU Process to capture audio"
-  humanReadableDescription: "Enable audio capture in GPU Process"
-  webcoreBinding: none
-  condition: ENABLE(MEDIA_STREAM)
-
 RenderCanvasInGPUProcessEnabled:
   type: bool
   defaultValue: defaultRenderCanvasInGPUProcessEnabled()
@@ -407,4 +415,23 @@
   defaultValue: false
   humanReadableName: "Live Ranges in Selection"
   humanReadableDescription: "Live range behavior for ranges in the Selection object"
-  category: internal
+
+ICECandidateFilteringEnabled:
+  type: bool
+  defaultValue: true
+  humanReadableName: "Enable ICE Candidate Filtering"
+  humanReadableDescription: "Enable ICE Candidate Filtering"
+
+MockCaptureDevicesEnabled:
+  type: bool
+  defaultValue: DEFAULT_MOCK_CAPTURE_DEVICES_ENABLED
+  condition: ENABLE(MEDIA_STREAM)
+  humanReadableName: "Enable Mock Capture Devices"
+  humanReadableDescription: "Enable Mock Capture Devices"
+
+MediaCaptureRequiresSecureConnection:
+  type: bool
+  defaultValue: true
+  condition: ENABLE(MEDIA_STREAM)
+  humanReadableName: "Limit Media Capture to Secure Sites"
+  humanReadableDescription: "Limit Media Capture to Secure Sites"

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (267413 => 267414)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2020-09-22 16:32:11 UTC (rev 267414)
@@ -215,7 +215,6 @@
         bool webViewFullscreenMayReturnToInline : 1;
         bool webViewDidEnterFullscreen : 1;
         bool webViewDidExitFullscreen : 1;
-        bool webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler : 1;
         bool webViewIsMediaCaptureAuthorizedForFrameDecisionHandler : 1;
         bool webViewMediaCaptureStateDidChange : 1;
         bool webViewDidChangeFontAttributes : 1;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (267413 => 267414)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2020-09-22 16:32:11 UTC (rev 267414)
@@ -44,6 +44,7 @@
 #import "WKSecurityOriginInternal.h"
 #import "WKStorageAccessAlert.h"
 #import "WKUIDelegatePrivate.h"
+#import "WKUserMediaCaptureAccessAlert.h"
 #import "WKWebViewConfigurationInternal.h"
 #import "WKWebViewInternal.h"
 #import "WKWindowFeaturesInternal.h"
@@ -153,7 +154,6 @@
     m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint = [delegate respondsToSelector:@selector(_webView:didNotHandleTapAsClickAtPoint:)];
     m_delegateMethods.presentingViewControllerForWebView = [delegate respondsToSelector:@selector(_presentingViewControllerForWebView:)];
 #endif
-    m_delegateMethods.webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestUserMediaAuthorizationForDevices:url:mainFrameURL:decisionHandler:)] || [delegate respondsToSelector:@selector(_webView:requestMediaCaptureAuthorization:decisionHandler:)];
     m_delegateMethods.webViewIsMediaCaptureAuthorizedForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:checkUserMediaPermissionForURL:mainFrameURL:frameIdentifier:decisionHandler:)] || [delegate respondsToSelector:@selector(_webView:includeSensitiveMediaDeviceDetails:)];
 
     m_delegateMethods.webViewMediaCaptureStateDidChange = [delegate respondsToSelector:@selector(_webView:mediaCaptureStateDidChange:)];
@@ -921,17 +921,23 @@
         ASSERT(!(devices & _WKCaptureDeviceCamera));
     }
 
-    const auto* mainFrame = frame.page()->mainFrame();
+    bool respondsToRequestMediaCaptureAuthorization = [delegate respondsToSelector:@selector(_webView:requestMediaCaptureAuthorization:decisionHandler:)];
+    bool respondsToRequestUserMediaAuthorizationForDevices = [delegate respondsToSelector:@selector(_webView:requestUserMediaAuthorizationForDevices:url:mainFrameURL:decisionHandler:)];
+    if (!request.requiresDisplayCapture() && !respondsToRequestUserMediaAuthorizationForDevices && !respondsToRequestMediaCaptureAuthorization) {
+        presentUserMediaCaptureAccessAlert(&webView, topLevelOrigin, devices, [decisionHandler = WTFMove(decisionHandler)](bool authorized) mutable {
+            decisionHandler(authorized);
+        });
+        return;
+    }
 
     // FIXME: Provide a specific delegate for display capture.
-    if (!request.requiresDisplayCapture() && [delegate respondsToSelector:@selector(_webView:requestMediaCaptureAuthorization:decisionHandler:)]) {
-
+    if (!request.requiresDisplayCapture() && respondsToRequestMediaCaptureAuthorization) {
         [delegate _webView:&webView requestMediaCaptureAuthorization:devices decisionHandler:decisionHandler.get()];
         return;
     }
 
     URL requestFrameURL { frame.url() };
-    URL mainFrameURL { mainFrame->url() };
+    URL mainFrameURL { frame.page()->mainFrame()->url() };
 
     [delegate _webView:&webView requestUserMediaAuthorizationForDevices:devices url:requestFrameURL mainFrameURL:mainFrameURL decisionHandler:decisionHandler.get()];
 }
@@ -941,7 +947,7 @@
 {
 #if ENABLE(MEDIA_STREAM)
     auto delegate = m_uiDelegate.m_delegate.get();
-    if (!delegate || !m_uiDelegate.m_delegateMethods.webViewRequestMediaCaptureAuthorizationForFrameDecisionHandler) {
+    if (!delegate) {
         request.deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled);
         return;
     }

Added: trunk/Source/WebKit/UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.h (0 => 267414)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.h	2020-09-22 16:32:11 UTC (rev 267414)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(MEDIA_STREAM)
+
+#import "WKWebViewPrivate.h"
+#import <wtf/Forward.h>
+
+@class WKWebView;
+
+namespace API {
+class SecurityOrigin;
+}
+
+namespace WebKit {
+
+void presentUserMediaCaptureAccessAlert(WKWebView *, API::SecurityOrigin&, _WKCaptureDevices, CompletionHandler<void(bool)>&&);
+
+}
+
+#endif // ENABLE(DEVICE_ORIENTATION)

Added: trunk/Source/WebKit/UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.mm (0 => 267414)


--- trunk/Source/WebKit/UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKUserMediaCaptureAccessAlert.mm	2020-09-22 16:32:11 UTC (rev 267414)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKUserMediaCaptureAccessAlert.h"
+
+#if ENABLE(MEDIA_STREAM)
+
+#import "WKWebViewInternal.h"
+#import "WKWebViewPrivate.h"
+#import "WebPageProxy.h"
+#import <WebCore/LocalizedStrings.h>
+#import <wtf/BlockPtr.h>
+#import <wtf/URLHelpers.h>
+#import <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+static NSString* visibleDomain(const String& host)
+{
+    auto domain = WTF::URLHelpers::userVisibleURL(host.utf8());
+    return startsWithLettersIgnoringASCIICase(domain, "www.") ? domain.substring(4) : domain;
+}
+
+static NSString *alertMessageText(API::SecurityOrigin& topLevelOrigin, _WKCaptureDevices devices)
+{
+    bool shouldAskUserForAccessToCamera = devices & _WKCaptureDeviceCamera;
+    bool shouldAskUserForAccessToMicrophone = devices & _WKCaptureDeviceMicrophone;
+
+    auto& origin = topLevelOrigin.securityOrigin();
+    if (origin.protocol() != "http" && origin.protocol() != "https")
+        return nil;
+
+    if (shouldAskUserForAccessToCamera && shouldAskUserForAccessToMicrophone)
+        return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your camera and microphone?", @"Message for user media prompt"), visibleDomain(origin.host())];
+    if (shouldAskUserForAccessToCamera)
+        return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your camera?", @"Message for user camera access prompt"), visibleDomain(origin.host())];
+    if (shouldAskUserForAccessToMicrophone)
+        return [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allow “%@” to use your microphone?", @"Message for user microphone access prompt"), visibleDomain(origin.host())];
+    return nil;
+}
+
+void presentUserMediaCaptureAccessAlert(WKWebView *webView, API::SecurityOrigin& topLevelOrigin, _WKCaptureDevices devices, CompletionHandler<void(bool)>&& completionHandler)
+{
+    auto *alertTitle = alertMessageText(topLevelOrigin, devices);
+    if (!alertTitle) {
+        completionHandler(false);
+        return;
+    }
+
+    auto completionBlock = makeBlockPtr([completionHandler = WTFMove(completionHandler)](bool shouldAllow) mutable {
+        completionHandler(shouldAllow);
+    });
+
+    NSString *allowButtonString = WEB_UI_STRING_KEY(@"Allow", "Allow (usermedia)", @"Allow button title in user media prompt");
+    NSString *doNotAllowButtonString = WEB_UI_STRING_KEY(@"Don’t Allow", "Don’t Allow (usermedia)", @"Disallow button title in user media prompt");
+
+#if PLATFORM(MAC)
+    auto alert = adoptNS([NSAlert new]);
+    [alert setMessageText:alertTitle];
+    [alert addButtonWithTitle:allowButtonString];
+    [alert addButtonWithTitle:doNotAllowButtonString];
+    [alert beginSheetModalForWindow:webView.window completionHandler:[completionBlock](NSModalResponse returnCode) {
+        auto shouldAllow = returnCode == NSAlertFirstButtonReturn;
+        completionBlock(shouldAllow);
+    }];
+#else
+    UIAlertController* alert = [UIAlertController alertControllerWithTitle:alertTitle message:nil preferredStyle:UIAlertControllerStyleAlert];
+    UIAlertAction* allowAction = [UIAlertAction actionWithTitle:allowButtonString style:UIAlertActionStyleCancel handler:[completionBlock](UIAlertAction *action) {
+        completionBlock(true);
+    }];
+
+    UIAlertAction* doNotAllowAction = [UIAlertAction actionWithTitle:doNotAllowButtonString style:UIAlertActionStyleDefault handler:[completionBlock](UIAlertAction *action) {
+        completionBlock(false);
+    }];
+
+    [alert addAction:doNotAllowAction];
+    [alert addAction:allowAction];
+
+    [[UIViewController _viewControllerForFullScreenPresentationFromView:webView] presentViewController:alert animated:YES completion:nil];
+#endif
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(DEVICE_ORIENTATION)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (267413 => 267414)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-09-22 16:32:11 UTC (rev 267414)
@@ -905,6 +905,7 @@
 		413075B41DE85F580039EC69 /* LibWebRTCProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 413075A81DE85EE70039EC69 /* LibWebRTCProvider.h */; };
 		413CCD5020DEBC740065A21A /* com.google.googletalkbrowserplugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 413CCD4F20DEBC2F0065A21A /* com.google.googletalkbrowserplugin.sb */; };
 		4143751C20EAEA2D00FAD06C /* cn.microdone.cmb.safari.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 4143751B20EAEA1E00FAD06C /* cn.microdone.cmb.safari.sb */; };
+		4147DC692519EC3300214EE7 /* WKUserMediaCaptureAccessAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4147DC672519E29D00214EE7 /* WKUserMediaCaptureAccessAlert.mm */; };
 		414DD37920BF43F5006959FB /* com.cisco.webex.plugin.gpc64.sb in Resources */ = {isa = PBXBuildFile; fileRef = 414DD37820BF43EA006959FB /* com.cisco.webex.plugin.gpc64.sb */; };
 		414DD37A20BF49A5006959FB /* com.cisco.webex.plugin.gpc64.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 414DD37820BF43EA006959FB /* com.cisco.webex.plugin.gpc64.sb */; };
 		4157E4B020E2ECDF00A6C0D7 /* com.google.o1dbrowserplugin.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 4157E4AF20E2EC9800A6C0D7 /* com.google.o1dbrowserplugin.sb */; };
@@ -3418,6 +3419,8 @@
 		4135FBD01F4FB7F20074C47B /* CacheStorageEngineCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageEngineCaches.h; sourceTree = "<group>"; };
 		413CCD4F20DEBC2F0065A21A /* com.google.googletalkbrowserplugin.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.google.googletalkbrowserplugin.sb; sourceTree = "<group>"; };
 		4143751B20EAEA1E00FAD06C /* cn.microdone.cmb.safari.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = cn.microdone.cmb.safari.sb; sourceTree = "<group>"; };
+		4147DC672519E29D00214EE7 /* WKUserMediaCaptureAccessAlert.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKUserMediaCaptureAccessAlert.mm; sourceTree = "<group>"; };
+		4147DC682519E29D00214EE7 /* WKUserMediaCaptureAccessAlert.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKUserMediaCaptureAccessAlert.h; sourceTree = "<group>"; };
 		414DD37820BF43EA006959FB /* com.cisco.webex.plugin.gpc64.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.cisco.webex.plugin.gpc64.sb; sourceTree = "<group>"; };
 		4150A5A023E06C910051264A /* GPUProcessSessionParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUProcessSessionParameters.h; sourceTree = "<group>"; };
 		41518535222704F5005430C6 /* ServiceWorkerFetchTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerFetchTask.h; sourceTree = "<group>"; };
@@ -6401,6 +6404,8 @@
 				2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
 				2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
 				2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
+				4147DC682519E29D00214EE7 /* WKUserMediaCaptureAccessAlert.h */,
+				4147DC672519E29D00214EE7 /* WKUserMediaCaptureAccessAlert.mm */,
 				C1710CF224A7BD0300D7C112 /* XPCEventHandler.h */,
 			);
 			path = Cocoa;
@@ -12990,6 +12995,7 @@
 				2D11B7BF2126A283006F8878 /* UnifiedSource56-mm.mm in Sources */,
 				2D11B7C12126A283006F8878 /* UnifiedSource57-mm.mm in Sources */,
 				2D11B7C22126A283006F8878 /* UnifiedSource57.cpp in Sources */,
+				4147DC692519EC3300214EE7 /* WKUserMediaCaptureAccessAlert.mm in Sources */,
 				2D11B7C32126A283006F8878 /* UnifiedSource58-mm.mm in Sources */,
 				2D11B7C42126A283006F8878 /* UnifiedSource58.cpp in Sources */,
 				2D11B7C62126A283006F8878 /* UnifiedSource59.cpp in Sources */,

Modified: trunk/Tools/ChangeLog (267413 => 267414)


--- trunk/Tools/ChangeLog	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Tools/ChangeLog	2020-09-22 16:32:11 UTC (rev 267414)
@@ -1,3 +1,19 @@
+2020-09-22  Youenn Fablet  <[email protected]>
+
+        Implement a default prompt for getUserMedia
+        https://bugs.webkit.org/show_bug.cgi?id=216821
+
+        Reviewed by Eric Carlson.
+
+        Remove getUserMedia delegate implementations to use WebKit built-in prompt.
+        Add camera and microphone entitlements to allow using real cameras and microphones.
+        Keep using mock devices as the default.
+
+        * MiniBrowser/MiniBrowser.entitlements:
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController _webView:requestMediaCaptureAuthorization:decisionHandler:]): Deleted.
+        (-[WK2BrowserWindowController _webView:includeSensitiveMediaDeviceDetails:]): Deleted.
+
 2020-09-22  Brian Burg  <[email protected]>
 
         [Cocoa] _WKInspectorDelegate should handle showing external resources

Modified: trunk/Tools/MiniBrowser/MiniBrowser.entitlements (267413 => 267414)


--- trunk/Tools/MiniBrowser/MiniBrowser.entitlements	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Tools/MiniBrowser/MiniBrowser.entitlements	2020-09-22 16:32:11 UTC (rev 267414)
@@ -22,5 +22,9 @@
 	<array>
 		<string>(allow mach-issue-extension (require-all (extension-class &quot;com.apple.webkit.extension.mach&quot;)))</string>
 	</array>
+	<key>com.apple.security.device.camera</key>
+	<true/>
+	<key>com.apple.security.device.microphone</key>
+	<true/>
 </dict>
 </plist>

Modified: trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m (267413 => 267414)


--- trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m	2020-09-22 16:29:35 UTC (rev 267413)
+++ trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m	2020-09-22 16:32:11 UTC (rev 267414)
@@ -873,16 +873,6 @@
 {
 }
 
-- (void)_webView:(WKWebView *)webView requestMediaCaptureAuthorization: (_WKCaptureDevices)devices decisionHandler:(void (^)(BOOL authorized))decisionHandler
-{
-    decisionHandler(true);
-}
-
-- (void)_webView:(WKWebView *)webView includeSensitiveMediaDeviceDetails:(void (^)(BOOL includeSensitiveDetails))decisionHandler
-{
-    decisionHandler(false);
-}
-
 - (IBAction)saveAsPDF:(id)sender
 {
     NSSavePanel *panel = [NSSavePanel savePanel];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to