Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] - Fix crash in Media permissions prompt (uplift to 1.72.x) #26069

Open
wants to merge 1 commit into
base: 1.72.x
Choose a base branch
from
Open
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 @@ -1359,48 +1359,65 @@ extension BrowserViewController: WKUIDelegate {
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 = BrowserAlertController(title: title, message: nil, preferredStyle: .alert)
alertController.addAction(
.init(
title: Strings.requestCaptureDevicePermissionAllowButtonTitle,
style: .default,
handler: { _ in
decisionHandler(.grant)
let presentAlert = { [weak self] in
guard let self = self else { return }

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 = BrowserAlertController(
title: title,
message: nil,
preferredStyle: .alert
)
)
alertController.addAction(
.init(
title: Strings.CancelString,
style: .cancel,
handler: { _ in
decisionHandler(.deny)
}
alertController.addAction(
.init(
title: Strings.requestCaptureDevicePermissionAllowButtonTitle,
style: .default,
handler: { _ in
decisionHandler(.grant)
}
)
)
)
alertController.dismissedWithoutAction = {
decisionHandler(.prompt)
alertController.addAction(
.init(
title: Strings.CancelString,
style: .cancel,
handler: { _ in
decisionHandler(.deny)
}
)
)
alertController.dismissedWithoutAction = {
decisionHandler(.prompt)
}
if webView.fullscreenState == .inFullscreen || webView.fullscreenState == .enteringFullscreen
{
webView.closeAllMediaPresentations {
self.present(alertController, animated: true)
}
return
}
self.present(alertController, animated: true)
}
if webView.fullscreenState == .inFullscreen || webView.fullscreenState == .enteringFullscreen {
webView.closeAllMediaPresentations {
self.present(alertController, animated: true)

if let presentedViewController = presentedViewController as? BrowserAlertController {
presentedViewController.dismiss(animated: true) {
presentAlert()
}
return
} else {
presentAlert()
}
present(alertController, animated: true)
}

fileprivate func shouldDisplayJSAlertForWebView(_ webView: WKWebView) -> Bool {
Expand Down
Loading