Skip to content
Open
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
9 changes: 5 additions & 4 deletions BrowserKit/Sources/Common/Utilities/DispatchQueueHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Foundation
// Only push the task async if we are not already on the main thread.
// Unless you want another event to fire before your work happens.
// This is better than using DispatchQueue.main.async to ensure main thread
public func ensureMainThread(execute work: @escaping @MainActor @Sendable @convention(block) () -> Swift.Void) {
public func ensureMainThread(execute work: @escaping @MainActor @convention(block) () -> Swift.Void) {
if Thread.isMainThread {
MainActor.assumeIsolated {
work()
Expand All @@ -19,14 +19,15 @@ public func ensureMainThread(execute work: @escaping @MainActor @Sendable @conve
}
}

public func ensureMainThread<T>(execute work: @escaping @MainActor @Sendable () -> T) {
public func ensureMainThread<T>(execute work: @escaping @MainActor () -> T) -> T? {
if Thread.isMainThread {
MainActor.assumeIsolated {
_ = work()
return MainActor.assumeIsolated {
return work()
}
} else {
DispatchQueue.main.async {
_ = work()
}
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public protocol DispatchQueueInterface: Sendable {
flags: DispatchWorkItemFlags,
execute work: @escaping @Sendable @convention(block) () -> Void)

func ensureMainThread(execute work: @escaping @MainActor @Sendable @convention(block) () -> Swift.Void)
func ensureMainThread(execute work: @escaping @MainActor @convention(block) () -> Swift.Void)

func asyncAfter(deadline: DispatchTime, execute: DispatchWorkItem)

Expand All @@ -35,7 +35,7 @@ extension DispatchQueueInterface {
asyncAfter(deadline: deadline, qos: qos, flags: flags, execute: work)
}

public func ensureMainThread(execute work: @escaping @MainActor @Sendable @convention(block) () -> Swift.Void) {
public func ensureMainThread(execute work: @escaping @MainActor @convention(block) () -> Swift.Void) {
if Thread.isMainThread {
MainActor.assumeIsolated {
work()
Expand Down
4 changes: 2 additions & 2 deletions BrowserKit/Sources/MenuKit/MenuElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct MenuElement: Equatable, Sendable {
let a11yId: String
let isOptional: Bool
let infoTitle: String?
public let action: (@MainActor @Sendable () -> Void)?
public let action: (@MainActor () -> Void)?

// We need this init as by default the init generated by the compiler
// for the struct will be internal and can not be used outside of MenuKit
Expand All @@ -34,7 +34,7 @@ public struct MenuElement: Equatable, Sendable {
a11yId: String,
isOptional: Bool = false,
infoTitle: String? = nil,
action: (@MainActor @Sendable () -> Void)?
action: (@MainActor () -> Void)?
) {
self.title = title
self.description = description
Expand Down
2 changes: 1 addition & 1 deletion BrowserKit/Sources/Redux/Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import Foundation

/// Provide pure functions, that based on the current `Action` and the current app `State`,
/// create a new app state. `Reducers` are the only place in which the application state should be modified.
public typealias Reducer<State> = @Sendable @MainActor (State, Action) -> State
public typealias Reducer<State> = @MainActor (State, Action) -> State
2 changes: 1 addition & 1 deletion BrowserKit/Sources/Shared/UIDeviceDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct UIDeviceDetails {
/// **DO NOT USE THIS METHOD ELSEWHERE IN THE CODE BASE.**
/// This is a workaround to access unchanging `UIDevice.current` values that Apple has needlessly main actor-isolated.
private static func getMainThreadDataSynchronously<T: Sendable>(
work: @MainActor @Sendable () -> (T)
work: @MainActor () -> (T)
) -> T {
if Thread.isMainThread {
MainActor.assumeIsolated {
Expand Down
4 changes: 2 additions & 2 deletions BrowserKit/Sources/WebEngine/WKWebview/WKEngineWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protocol WKEngineWebView: UIView {
_ javaScript: String,
in frame: WKFrameInfo?,
in contentWorld: WKContentWorld,
completionHandler: (@MainActor @Sendable (Result<Any, Error>) -> Void)?
completionHandler: (@MainActor (Result<Any, Error>) -> Void)?
)

func close()
Expand All @@ -86,7 +86,7 @@ extension WKEngineWebView {
_ javaScript: String,
in frame: WKFrameInfo? = nil,
in contentWorld: WKContentWorld,
completionHandler: (@MainActor @Sendable (Result<Any, Error>) -> Void)? = nil
completionHandler: (@MainActor (Result<Any, Error>) -> Void)? = nil
) {
evaluateJavaScript(javaScript,
in: frame,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class MockWKEngineWebView: UIView, WKEngineWebView {
func evaluateJavaScript(_ javaScript: String,
in frame: WKFrameInfo?,
in contentWorld: WKContentWorld,
completionHandler: (@MainActor @Sendable (Result<Any, Error>) -> Void)?) {
completionHandler: (@MainActor (Result<Any, Error>) -> Void)?) {
evaluateJavaScriptCalled += 1
savedJavaScript = javaScript

Expand Down
2 changes: 1 addition & 1 deletion firefox-ios/Client/AccountSyncHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Debouncer {
self.delay = delay
}

func call(action: @escaping @MainActor @Sendable () -> Void) {
func call(action: @escaping @MainActor () -> Void) {
task?.cancel()

let nanos = UInt64(delay) * nanosecondsPerSecond
Expand Down
4 changes: 2 additions & 2 deletions firefox-ios/Client/Application/WebServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protocol WebServerProtocol {

/// FIXME: FXIOS-13989 Make truly thread safe
/// NOTE: FXIOS-14560 -- Be careful; `@MainActor` will cause crashes with GCDWebServer dependency.
final class WebServer: WebServerProtocol, @unchecked Sendable {
class WebServer: WebServerProtocol, @unchecked Sendable {
static let sharedInstance = WebServer()

private let logger: Logger
Expand Down Expand Up @@ -56,7 +56,7 @@ final class WebServer: WebServerProtocol, @unchecked Sendable {
_ method: String,
module: String,
resource: String,
handler: @escaping @Sendable @MainActor (
handler: @escaping @MainActor (
_ request: GCDWebServerRequest?,
_ responseCompletion: @escaping @Sendable (GCDWebServerResponse?) -> Void
) -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ enum AuthenticationState {
protocol AppAuthenticationProtocol {
var canAuthenticateDeviceOwner: Bool { get }

func getAuthenticationState(completion: @MainActor @escaping @Sendable (AuthenticationState) -> Void)
func getAuthenticationState(completion: @MainActor @escaping (AuthenticationState) -> Void)
func authenticateWithDeviceOwnerAuthentication(
_ completion: @MainActor @escaping @Sendable (Result<Void, AuthenticationError>) -> Void
_ completion: @MainActor @escaping (Result<Void, AuthenticationError>) -> Void
)
}

class AppAuthenticator: AppAuthenticationProtocol {
func getAuthenticationState(completion: @MainActor @escaping @Sendable (AuthenticationState) -> Void) {
func getAuthenticationState(completion: @MainActor @escaping (AuthenticationState) -> Void) {
if canAuthenticateDeviceOwner {
authenticateWithDeviceOwnerAuthentication { result in
DispatchQueue.main.async {
Expand All @@ -46,7 +46,7 @@ class AppAuthenticator: AppAuthenticationProtocol {
}

func authenticateWithDeviceOwnerAuthentication(
_ completion: @MainActor @escaping @Sendable (Result<Void, AuthenticationError>) -> Void
_ completion: @MainActor @escaping (Result<Void, AuthenticationError>) -> Void
) {
// Get a fresh context for each login. If you use the same context on multiple attempts
// (by commenting out the next line), then a previously successful authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ final class CreditCardInputViewModel: ObservableObject, @unchecked Sendable {
}

func removeCreditCard(creditCard: CreditCard?,
completion: @escaping @MainActor @Sendable (CreditCardModifiedStatus, Bool) -> Void) {
completion: @escaping @MainActor (CreditCardModifiedStatus, Bool) -> Void) {
guard let currentCreditCard = creditCard,
!currentCreditCard.guid.isEmpty else {
ensureMainThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WebContextMenuActionsProvider {
}

@MainActor
func addOpenInNewTab(url: URL, currentTab: Tab, addTab: @escaping @MainActor @Sendable (URL, Bool, Tab) -> Void) {
func addOpenInNewTab(url: URL, currentTab: Tab, addTab: @escaping @MainActor (URL, Bool, Tab) -> Void) {
actions.append(
UIAction(
title: .ContextMenuOpenInNewTab,
Expand All @@ -41,7 +41,7 @@ class WebContextMenuActionsProvider {
}

@MainActor
func addOpenInNewPrivateTab(url: URL, currentTab: Tab, addTab: @escaping @MainActor @Sendable (URL, Bool, Tab) -> Void) {
func addOpenInNewPrivateTab(url: URL, currentTab: Tab, addTab: @escaping @MainActor (URL, Bool, Tab) -> Void) {
actions.append(
UIAction(
title: .ContextMenuOpenInNewPrivateTab,
Expand Down Expand Up @@ -161,7 +161,7 @@ class WebContextMenuActionsProvider {
@MainActor
func addSaveImage(url: URL,
getImageData: @escaping (URL, @Sendable @escaping (Data) -> Void) -> Void,
writeToPhotoAlbum: @escaping @Sendable @MainActor (UIImage) -> Void) {
writeToPhotoAlbum: @escaping @MainActor (UIImage) -> Void) {
actions.append(UIAction(
title: .ContextMenuSaveImage,
identifier: UIAction.Identifier("linkContextMenu.saveImage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension BrowserViewController: WKUIDelegate {
private func handleJavaScriptAlert<T: WKJavaScriptAlertInfo>(
_ alert: T,
for webView: WKWebView,
spamCallback: @escaping @MainActor @Sendable () -> Void
spamCallback: @escaping @MainActor () -> Void
) {
if jsAlertExceedsSpamLimits(webView) {
handleSpammedJSAlert(spamCallback)
Expand All @@ -95,7 +95,7 @@ extension BrowserViewController: WKUIDelegate {
_ webView: WKWebView,
runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor @Sendable () -> Void
completionHandler: @escaping @MainActor () -> Void
) {
let messageAlert = MessageAlert(message: message,
frame: frame,
Expand All @@ -110,7 +110,7 @@ extension BrowserViewController: WKUIDelegate {
_ webView: WKWebView,
runJavaScriptConfirmPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor @Sendable (Bool) -> Void
completionHandler: @escaping @MainActor (Bool) -> Void
) {
let confirmAlert = ConfirmPanelAlert(message: message, frame: frame) { confirm in
self.logger.log("JavaScript confirm panel was completed with result: \(confirm)", level: .info, category: .webview)
Expand All @@ -127,7 +127,7 @@ extension BrowserViewController: WKUIDelegate {
runJavaScriptTextInputPanelWithPrompt prompt: String,
defaultText: String?,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor @Sendable (String?) -> Void
completionHandler: @escaping @MainActor (String?) -> Void
) {
let textInputAlert = TextInputAlert(message: prompt, frame: frame, defaultText: defaultText) { input in
self.logger.log("JavaScript text input panel was completed with input", level: .info, category: .webview)
Expand All @@ -153,7 +153,7 @@ extension BrowserViewController: WKUIDelegate {
func webView(
_ webView: WKWebView,
contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo,
completionHandler: @escaping @MainActor @Sendable (UIContextMenuConfiguration?) -> Void
completionHandler: @escaping @MainActor (UIContextMenuConfiguration?) -> Void
) {
guard let url = elementInfo.linkURL,
let currentTab = tabManager.selectedTab,
Expand Down Expand Up @@ -184,7 +184,7 @@ extension BrowserViewController: WKUIDelegate {
requestMediaCapturePermissionFor origin: WKSecurityOrigin,
initiatedByFrame frame: WKFrameInfo,
type: WKMediaCaptureType,
decisionHandler: @escaping @MainActor @Sendable (WKPermissionDecision) -> Void
decisionHandler: @escaping @MainActor (WKPermissionDecision) -> Void
) {
// If the tab isn't the selected one or we're on the homepage, do not show the media capture prompt
guard tabManager.selectedTab?.webView === webView, !contentContainer.hasAnyHomepage else {
Expand All @@ -197,7 +197,7 @@ extension BrowserViewController: WKUIDelegate {

// MARK: - Helpers

private func handleSpammedJSAlert(_ callback: @escaping @MainActor @Sendable () -> Void) {
private func handleSpammedJSAlert(_ callback: @escaping @MainActor () -> Void) {
// User is being spammed. Squelch alert. Note that we have to do this after
// a delay to avoid JS that could spin the CPU endlessly.
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { callback() }
Expand Down Expand Up @@ -312,7 +312,7 @@ extension BrowserViewController: WKUIDelegate {

func createActions(isPrivate: Bool,
url: URL,
addTab: @escaping @MainActor @Sendable (URL, Bool, Tab) -> Void,
addTab: @escaping @MainActor (URL, Bool, Tab) -> Void,
title: String?,
image: URL?,
currentTab: Tab,
Expand Down Expand Up @@ -705,7 +705,7 @@ extension BrowserViewController: WKNavigationDelegate {
func webView(
_ webView: WKWebView,
decidePolicyFor navigationResponse: WKNavigationResponse,
decisionHandler: @escaping @MainActor @Sendable (WKNavigationResponsePolicy) -> Void
decisionHandler: @escaping @MainActor (WKNavigationResponsePolicy) -> Void
) {
let response = navigationResponse.response
let responseURL = response.url
Expand Down Expand Up @@ -928,7 +928,7 @@ extension BrowserViewController: WKNavigationDelegate {
// web view don't invoke another download.
pendingDownloadWebView = nil

let downloadAction: @Sendable @MainActor (HTTPDownload) -> Void = { [weak self] download in
let downloadAction: @MainActor (HTTPDownload) -> Void = { [weak self] download in
self?.downloadQueue.enqueue(download)
}

Expand Down Expand Up @@ -1053,7 +1053,7 @@ extension BrowserViewController: WKNavigationDelegate {
func webView(
_ webView: WKWebView,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping @MainActor @Sendable (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
completionHandler: @escaping @MainActor (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
guard challenge.protectionSpace.authenticationMethod != NSURLAuthenticationMethodServerTrust else {
handleServerTrust(
Expand Down Expand Up @@ -1232,7 +1232,7 @@ private extension BrowserViewController {

// Use for sms and mailto, which do not show a confirmation before opening.
func showExternalAlert(withText text: String,
completion: @escaping @MainActor @Sendable (UIAlertAction) -> Void) {
completion: @escaping @MainActor (UIAlertAction) -> Void) {
let alert = UIAlertController(title: nil,
message: text,
preferredStyle: .alert)
Expand Down Expand Up @@ -1329,7 +1329,7 @@ private extension BrowserViewController {
func handleServerTrust(
challenge: URLAuthenticationChallenge,
dispatchQueue: DispatchQueueInterface,
completionHandler: @escaping @MainActor @Sendable (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
completionHandler: @escaping @MainActor (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
dispatchQueue.async {
// If this is a certificate challenge, see if the certificate has previously been
Expand All @@ -1340,9 +1340,7 @@ private extension BrowserViewController {
let cert = SecTrustCopyCertificateChain(trust) as? [SecCertificate],
self.profile.certStore.containsCertificate(cert[0], forOrigin: origin)
else {
ensureMainThread {
completionHandler(.performDefaultHandling, nil)
}
completionHandler(.performDefaultHandling, nil)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BrowserWebUIDelegate: NSObject, WKUIDelegate {
_ webView: WKWebView,
runJavaScriptConfirmPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor @Sendable (Bool) -> Void
completionHandler: @escaping @MainActor (Bool) -> Void
) {
legacyResponder?.webView?(
webView,
Expand All @@ -68,7 +68,7 @@ class BrowserWebUIDelegate: NSObject, WKUIDelegate {
runJavaScriptTextInputPanelWithPrompt prompt: String,
defaultText: String?,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping @MainActor @Sendable (String?) -> Void
completionHandler: @escaping @MainActor (String?) -> Void
) {
legacyResponder?.webView?(
webView,
Expand All @@ -86,7 +86,7 @@ class BrowserWebUIDelegate: NSObject, WKUIDelegate {
func webView(
_ webView: WKWebView,
contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo,
completionHandler: @escaping @MainActor @Sendable (UIContextMenuConfiguration?) -> Void
completionHandler: @escaping @MainActor (UIContextMenuConfiguration?) -> Void
) {
legacyResponder?.webView?(
webView,
Expand All @@ -104,7 +104,7 @@ class BrowserWebUIDelegate: NSObject, WKUIDelegate {
requestMediaCapturePermissionFor origin: WKSecurityOrigin,
initiatedByFrame frame: WKFrameInfo,
type: WKMediaCaptureType,
decisionHandler: @escaping @MainActor @Sendable (WKPermissionDecision) -> Void
decisionHandler: @escaping @MainActor (WKPermissionDecision) -> Void
) {
legacyResponder?.webView?(
webView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DownloadHelper: NSObject {

@MainActor
func downloadViewModel(windowUUID: WindowUUID,
okAction: @Sendable @MainActor @escaping (HTTPDownload) -> Void) -> PhotonActionSheetViewModel? {
okAction: @MainActor @escaping (HTTPDownload) -> Void) -> PhotonActionSheetViewModel? {
var requestUrl = request.url
if let url = requestUrl, url.scheme == "blob" {
requestUrl = url.removeBlobFromUrl()
Expand Down
Loading