Skip to content

Commit

Permalink
Bugfix FXIOS-10315 Fix WebKit exceptions from JS alert completion han…
Browse files Browse the repository at this point in the history
…dlers (backport #22602) (#22604)

Bugfix FXIOS-10315 Fix WebKit exceptions from JS alert completion handlers (#22602)

* [FXIOS-10315] Fix redundant completion handler call.

* [FXIOS-10315] Fix crash occurring in some scenarios where we might attempt to dequeue and present a JS alert when there was already a presented VC on screen

(cherry picked from commit f387704)

Co-authored-by: mattreaganmozilla <[email protected]>
  • Loading branch information
mergify[bot] and mattreaganmozilla authored Oct 16, 2024
1 parent 898dfa8 commit a3a9741
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions firefox-ios/Client/Frontend/Browser/BrowserPrompts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ protocol JSAlertInfo {
struct MessageAlert: JSAlertInfo {
let message: String
let frame: WKFrameInfo
let completionHandler: (() -> Void)?
let completionHandler: () -> Void

func alertController() -> JSPromptAlertController {
let alertController = JSPromptAlertController(
title: titleForJavaScriptPanelInitiatedByFrame(frame),
message: message,
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: .OKString, style: .default) { _ in
completionHandler?()
completionHandler()
})
alertController.alertInfo = self
return alertController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ extension BrowserViewController: WKUIDelegate {
logger.log("Javascript message alert is queued.", level: .info, category: .webview)

promptingTab.queueJavascriptAlertPrompt(messageAlert)
completionHandler()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,11 +1225,12 @@ class BrowserViewController: UIViewController,
}

fileprivate func showQueuedAlertIfAvailable() {
if let queuedAlertInfo = tabManager.selectedTab?.dequeueJavascriptAlertPrompt() {
let alertController = queuedAlertInfo.alertController()
alertController.delegate = self
present(alertController, animated: true, completion: nil)
}
// See also: similar safety checks in `shouldDisplayJSAlertForWebView`
guard presentedViewController == nil else { return }
guard let queuedAlertInfo = tabManager.selectedTab?.dequeueJavascriptAlertPrompt() else { return }
let alertController = queuedAlertInfo.alertController()
alertController.delegate = self
present(alertController, animated: true, completion: nil)
}

func resetBrowserChrome() {
Expand Down Expand Up @@ -3937,6 +3938,9 @@ extension BrowserViewController: TabTrayDelegate {

extension BrowserViewController: JSPromptAlertControllerDelegate {
func promptAlertControllerDidDismiss(_ alertController: JSPromptAlertController) {
logger.log("JS prompt was dismissed. Will dequeue next alert.",
level: .info,
category: .webview)
showQueuedAlertIfAvailable()
}
}
Expand Down

1 comment on commit a3a9741

@firefoxci-taskcluster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error!

InterpreterError at template.tasks[0].extra[0].treeherder[1].symbol: unknown context value cron

Please sign in to comment.