Skip to content

Commit

Permalink
Fix WKDownload cancellation under Xcode 16 (#986)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1201037661562251/1208253341015124/f
iOS PR: not affected
macOS PR: not affected (under Xcode 15)
What kind of version bump will this require?: Patch
  • Loading branch information
mallexxx authored Sep 11, 2024
1 parent dc04bd2 commit e2545b6
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ private class PermanentScriptMessageHandler: NSObject, WKScriptMessageHandler, W
handler.userContentController(userContentController, didReceive: message)
}

@available(macOS 11.0, iOS 14.0, *)
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage, replyHandler: @escaping (Any?, String?) -> Void) {
guard let box = self.registeredMessageHandlers[message.messageName] else {
assertionFailure("no registered message handler for \(message.messageName)")
Expand Down
45 changes: 0 additions & 45 deletions Sources/Common/Concurrency/MainActorExtension.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/CxxCrashHandler/NSException+cxxHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ + (NSException * _Nullable)currentCxxException {
}

// prevent crashes if `NSException` has no `reserved` field
- (id)valueForUndefinedKey:(NSString *)key {}
- (id)valueForUndefinedKey:(NSString *)key { return nil; }
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {}

@end
2 changes: 0 additions & 2 deletions Sources/Navigation/DistributedNavigationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,6 @@ extension DistributedNavigationDelegate: WKNavigationDelegate {
}

@MainActor
@available(macOS 11.3, iOS 14.5, *) // objc does‘t care about availability
@objc(webView:navigationAction:didBecomeDownload:)
public func webView(_ webView: WKWebView, navigationAction wkNavigationAction: WKNavigationAction, didBecome download: WKDownload) {
let navigationAction = wkNavigationAction.navigationAction ?? {
Expand Down Expand Up @@ -981,7 +980,6 @@ extension DistributedNavigationDelegate: WKNavigationDelegate {
}

@MainActor
@available(macOS 11.3, iOS 14.5, *) // objc does‘t care about availability
@objc(webView:navigationResponse:didBecomeDownload:)
public func webView(_ webView: WKWebView, navigationResponse wkNavigationResponse: WKNavigationResponse, didBecome download: WKDownload) {
let navigationResponse = wkNavigationResponse.navigationResponse ?? {
Expand Down
11 changes: 2 additions & 9 deletions Sources/Navigation/NavigationAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ public struct NavigationPreferences: Equatable {
public var contentMode: WKWebpagePreferences.ContentMode

fileprivate var javaScriptEnabledValue: Bool
@available(macOS 11.0, iOS 14.0, *)
public var javaScriptEnabled: Bool {
get {
javaScriptEnabledValue
Expand Down Expand Up @@ -212,11 +211,7 @@ public struct NavigationPreferences: Equatable {

internal init(userAgent: String?, preferences: WKWebpagePreferences) {
self.contentMode = preferences.preferredContentMode
if #available(macOS 11.0, iOS 14.0, *) {
self.javaScriptEnabledValue = preferences.allowsContentJavaScript
} else {
self.javaScriptEnabledValue = true
}
self.javaScriptEnabledValue = preferences.allowsContentJavaScript
#if _WEBPAGE_PREFS_CUSTOM_HEADERS_ENABLED
if Self.customHeadersSupported {
self.customHeaders = preferences.customHeaderFields
Expand All @@ -226,9 +221,7 @@ public struct NavigationPreferences: Equatable {

internal func applying(to preferences: WKWebpagePreferences) -> WKWebpagePreferences {
preferences.preferredContentMode = contentMode
if #available(macOS 11.0, iOS 14.0, *) {
preferences.allowsContentJavaScript = javaScriptEnabled
}
preferences.allowsContentJavaScript = javaScriptEnabled
#if _WEBPAGE_PREFS_CUSTOM_HEADERS_ENABLED
if Self.customHeadersSupported, let customHeaders = customHeaders {
preferences.customHeaderFields = customHeaders
Expand Down
14 changes: 3 additions & 11 deletions Sources/Navigation/WebKitDownload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@ import WebKit
var originalRequest: URLRequest? { get }
var webView: WKWebView? { get }
var delegate: WKDownloadDelegate? { get set }
func cancel(_ completionHandler: ((Data?) -> Void)?)
}

extension WebKitDownload {
public func cancel(_ completionHandler: ((Data?) -> Void)? = nil) {
if #available(macOS 11.3, iOS 14.5, *),
let download = self as? WKDownload {

download.cancel(completionHandler)
} else {
// perform objc _WKDownload.cancel selector
self.perform(#selector(Progress.cancel))
completionHandler?(nil)
}
public func cancel() {
cancel(/*completionHandler:*/ nil)
}
}

@available(macOS 11.3, iOS 14.5, *)
extension WKDownload: WebKitDownload {}

0 comments on commit e2545b6

Please sign in to comment.