diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift index 29b81f63fb6..cceefc7ee83 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift @@ -953,6 +953,44 @@ extension BrowserViewController: WKUIDelegate { tabManager.addTabToRecentlyClosed(tab) tabManager.removeTab(tab) } + + public func webView( + _ webView: WKWebView, + requestMediaCapturePermissionFor origin: WKSecurityOrigin, + initiatedByFrame frame: WKFrameInfo, + type: WKMediaCaptureType, + decisionHandler: @escaping (WKPermissionDecision) -> Void + ) { + let titleFormat: String = { + switch type { + case .camera: + return Strings.requestCameraPermissionPrompt + case .microphone: + return Strings.requestMicrophonePermissionPrompt + case .cameraAndMicrophone: + return Strings.requestCameraAndMicrophonePermissionPrompt + @unknown default: + return Strings.requestCaptureDevicePermissionPrompt + } + }() + let title = String.localizedStringWithFormat(titleFormat, origin.host) + let alertController = UIAlertController(title: title, message: nil, preferredStyle: .alert) + alertController.addAction(.init(title: Strings.requestCaptureDevicePermissionAllowButtonTitle, style: .default, handler: { _ in + decisionHandler(.grant) + })) + alertController.addAction(.init(title: Strings.CancelString, style: .cancel, handler: { _ in + decisionHandler(.deny) + })) + if #available(iOS 16.0, *) { + if webView.fullscreenState == .inFullscreen || webView.fullscreenState == .enteringFullscreen { + webView.closeAllMediaPresentations { + self.present(alertController, animated: true) + } + return + } + } + present(alertController, animated: true) + } fileprivate func shouldDisplayJSAlertForWebView(_ webView: WKWebView) -> Bool { // Only display a JS Alert if we are selected and there isn't anything being shown diff --git a/Sources/BraveStrings/BraveStrings.swift b/Sources/BraveStrings/BraveStrings.swift index e76c7b152fa..99c9aafa228 100644 --- a/Sources/BraveStrings/BraveStrings.swift +++ b/Sources/BraveStrings/BraveStrings.swift @@ -1221,6 +1221,11 @@ extension Strings { public static let openExternalAppURLHost = NSLocalizedString("openExternalAppURLHost", tableName: "BraveShared", bundle: .module, value: "%@ says:", comment: "This will be used to indicate which website is calling the action. %s will replace the name of the website for instance: 'google.com says:'") public static let openExternalAppURLAllow = NSLocalizedString("ExternalAppURLAllow", tableName: "BraveShared", bundle: .module, value: "Allow", comment: "Allow Brave to open the external app URL") public static let openExternalAppURLDontAllow = NSLocalizedString("ExternalAppURLDontAllow", tableName: "BraveShared", bundle: .module, value: "Don't Allow", comment: "Don't allow Brave to open the external app URL") + public static let requestCameraPermissionPrompt = NSLocalizedString("requestCameraPermissionPrompt", tableName: "BraveShared", bundle: .module, value: "\"%@\" Would Like to Access the Camera", comment: "A title that appears on a permissions dialog on whether or not the user wants to allow a web page to access their device's camera. %@ will be replaced with the websites address (for example: \"talk.brave.com\")") + public static let requestMicrophonePermissionPrompt = NSLocalizedString("requestMicrophonePermissionPrompt", tableName: "BraveShared", bundle: .module, value: "\"%@\" Would Like to Access the Microphone", comment: "A title that appears on a permissions dialog on whether or not the user wants to allow a web page to access their device's microphone. %@ will be replaced with the websites address (for example: \"talk.brave.com\")") + public static let requestCameraAndMicrophonePermissionPrompt = NSLocalizedString("requestCameraAndMicrophonePermissionPrompt", tableName: "BraveShared", bundle: .module, value: "\"%@\" Would Like to Access the Camera and Microphone", comment: "A title that appears on a permissions dialog on whether or not the user wants to allow a web page to access their device's camera & microphone. %@ will be replaced with the websites address (for example: \"talk.brave.com\")") + public static let requestCaptureDevicePermissionPrompt = NSLocalizedString("requestCaptureDevicePermissionPrompt", tableName: "BraveShared", bundle: .module, value: "\"%@\" Would Like to Access a Media Capture Device", comment: "A title that appears on a permissions dialog on whether or not the user wants to allow a web page to access some media capture device such as a camera or microphone. %@ will be replaced with the websites address (for example: \"talk.brave.com\")") + public static let requestCaptureDevicePermissionAllowButtonTitle = NSLocalizedString("requestCaptureDevicePermissionAllowButtonTitle", tableName: "BraveShared", bundle: .module, value: "Allow", comment: "A button shown in a permission dialog that will grant the website the ability to use the device's camera or microphone") public static let downloadsMenuItem = NSLocalizedString("DownloadsMenuItem", tableName: "BraveShared", bundle: .module, value: "Downloads", comment: "Title for downloads menu item") public static let downloadsPanelEmptyStateTitle = NSLocalizedString("DownloadsPanelEmptyStateTitle", tableName: "BraveShared", bundle: .module, value: "Downloaded files will show up here.", comment: "Title for when a user has nothing downloaded onto their device, and the list is empty.") public static let playlistMenuItem = NSLocalizedString("PlaylistMenuItem", tableName: "BraveShared", bundle: .module, value: "Playlist", comment: "Playlist menu item")