Skip to content

Commit

Permalink
fix crash when handling JS prompts with invalid origins, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Feb 25, 2025
1 parent 0c44c6e commit 05a1e92
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ protocol TabWebDelegate: AnyObject {
defaultText: String?,
pageURL: URL
) async -> String?

func tab(
_ tab: Tab,
didRequestHTTPAuthFor protectionSpace: URLProtectionSpace,
Expand Down Expand Up @@ -93,8 +92,7 @@ extension TabWebDelegate {
defaultText: String?,
pageURL: URL
) async -> String? {
return
nil
return nil
}

func tab(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protocol TabWebPolicyDecider: AnyObject {
shouldAllowRequest request: URLRequest,
requestInfo: WebRequestInfo
) async -> WebPolicyDecision

/// Decide whether or not a response should be allowed
func tab(
_ tab: Tab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,10 @@ extension BrowserViewController: WKUIDelegate {
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping () -> Void
) {
guard let tab = tabManager[webView], let url = frame.origin?.url else { return }
guard let tab = tabManager[webView], let url = frame.origin?.url else {
completionHandler()
return
}
Task {
await self.tab(tab, runJavaScriptAlertPanelWithMessage: message, pageURL: url)
completionHandler()
Expand All @@ -541,7 +544,10 @@ extension BrowserViewController: WKUIDelegate {
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (Bool) -> Void
) {
guard let tab = tabManager[webView], let url = frame.origin?.url else { return }
guard let tab = tabManager[webView], let url = frame.origin?.url else {
completionHandler(false)
return
}
Task {
let result = await self.tab(tab, runJavaScriptConfirmPanelWithMessage: message, pageURL: url)
completionHandler(result)
Expand All @@ -555,7 +561,10 @@ extension BrowserViewController: WKUIDelegate {
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (String?) -> Void
) {
guard let tab = tabManager[webView], let url = frame.origin?.url else { return }
guard let tab = tabManager[webView], let url = frame.origin?.url else {
completionHandler(nil)
return
}
Task {
let result = await self.tab(
tab,
Expand Down Expand Up @@ -685,7 +694,12 @@ extension WKFrameInfo {
if securityOrigin.protocol.isEmpty || securityOrigin.host.isEmpty {
return nil
}
let defaultPort: UInt16 = securityOrigin.protocol == "https" ? 443 : 80
let defaultPort: UInt16 =
switch securityOrigin.protocol {
case "https": 443
case "http": 80
default: 0
}
return URLOrigin(
scheme: securityOrigin.protocol,
host: securityOrigin.host,
Expand Down

0 comments on commit 05a1e92

Please sign in to comment.