Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8514: Add a custom prompt for media capture permissions #8467

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down