@@ -62,7 +62,6 @@ class TabManagerImplementation: NSObject,
62
62
return tabs [ selectedIndex]
63
63
}
64
64
65
- @MainActor
66
65
var normalActiveTabs : [ Tab ] {
67
66
let inactiveTabs = getInactiveTabs ( )
68
67
let activeTabs = tabs. filter { $0. isPrivate == false && !inactiveTabs. contains ( $0) }
@@ -81,7 +80,6 @@ class TabManagerImplementation: NSObject,
81
80
return tabs. filter { $0. isPrivate }
82
81
}
83
82
84
- @MainActor
85
83
var recentlyAccessedNormalTabs : [ Tab ] {
86
84
// If inactive tabs are enabled, do not include inactive tabs, as they are not "recently" accessed
87
85
var eligibleTabs = isInactiveTabsEnabled ? normalActiveTabs : normalTabs
@@ -121,7 +119,7 @@ class TabManagerImplementation: NSObject,
121
119
var tabRestoreHasFinished = false
122
120
private( set) var selectedIndex : Int = - 1
123
121
124
- @ MainActor private lazy var tabConfigurationProvider = {
122
+ private lazy var tabConfigurationProvider = {
125
123
return TabConfigurationProvider ( prefs: profile. prefs)
126
124
} ( )
127
125
@@ -193,7 +191,6 @@ class TabManagerImplementation: NSObject,
193
191
}
194
192
195
193
// MARK: - Add/Remove Delegate
196
- @MainActor
197
194
func removeDelegate( _ delegate: any TabManagerDelegate , completion: ( ( ) -> Void ) ? ) {
198
195
for index in 0 ..< delegates. count {
199
196
let del = delegates [ index]
@@ -387,7 +384,6 @@ class TabManagerImplementation: NSObject,
387
384
commitChanges ( )
388
385
}
389
386
390
- @MainActor
391
387
private func addTab( _ request: URLRequest ? = nil ,
392
388
afterTab: Tab ? = nil ,
393
389
flushToDisk: Bool ,
@@ -407,13 +403,11 @@ class TabManagerImplementation: NSObject,
407
403
return filterdTabs. first
408
404
}
409
405
410
- @MainActor
411
406
func getTabForURL( _ url: URL ) -> Tab ? {
412
407
return tabs. first ( where: { $0. webView? . url == url } )
413
408
}
414
409
415
410
// MARK: - Undo Close Tab
416
- @MainActor
417
411
func undoCloseTab( ) {
418
412
assert ( Thread . isMainThread)
419
413
guard let backupCloseTab = self . backupCloseTab else { return }
@@ -435,7 +429,6 @@ class TabManagerImplementation: NSObject,
435
429
commitChanges ( )
436
430
}
437
431
438
- @MainActor
439
432
func undoCloseAllTabs( ) {
440
433
assert ( Thread . isMainThread)
441
434
guard !backupCloseTabs. isEmpty else { return }
@@ -450,7 +443,6 @@ class TabManagerImplementation: NSObject,
450
443
451
444
// MARK: - Restore tabs
452
445
453
- @MainActor
454
446
func restoreTabs( _ forced: Bool = false ) {
455
447
assert ( Thread . isMainThread)
456
448
if isDeeplinkOptimizationRefactorEnabled {
@@ -488,7 +480,6 @@ class TabManagerImplementation: NSObject,
488
480
restoreTabs ( )
489
481
}
490
482
491
- @MainActor
492
483
private func updateSelectedTabAfterRemovalOf( _ removedTab: Tab , deletedIndex: Int ) {
493
484
assert ( Thread . isMainThread)
494
485
// If the currently selected tab has been deleted, try to select the next most reasonable tab.
@@ -547,7 +538,6 @@ class TabManagerImplementation: NSObject,
547
538
}
548
539
}
549
540
550
- @MainActor
551
541
private func blockPopUpDidChange( ) {
552
542
assert ( Thread . isMainThread)
553
543
let allowPopups = !( profile. prefs. boolForKey ( PrefsKeys . KeyBlockPopups) ?? true )
@@ -559,7 +549,6 @@ class TabManagerImplementation: NSObject,
559
549
tabConfigurationProvider. updateAllowsPopups ( allowPopups)
560
550
}
561
551
562
- @MainActor
563
552
private func autoPlayDidChange( ) {
564
553
assert ( Thread . isMainThread)
565
554
let mediaType = AutoplayAccessors . getMediaTypesRequiringUserActionForPlayback ( profile. prefs)
@@ -569,7 +558,6 @@ class TabManagerImplementation: NSObject,
569
558
tabConfigurationProvider. updateMediaTypesRequiringUserActionForPlayback ( mediaType)
570
559
}
571
560
572
- @MainActor
573
561
private func buildTabRestore( window: WindowData ? ) {
574
562
defer {
575
563
isRestoringTabs = false
@@ -625,7 +613,6 @@ class TabManagerImplementation: NSObject,
625
613
}
626
614
627
615
/// Creates the webview so needs to live on the main thread
628
- @MainActor
629
616
private func generateTabs( from windowData: WindowData ) {
630
617
let filteredTabs = filterPrivateTabs ( from: windowData,
631
618
clearPrivateTabs: shouldClearPrivateTabs ( ) )
@@ -650,7 +637,6 @@ class TabManagerImplementation: NSObject,
650
637
handleTabSelectionAfterRestore ( tabToSelect: tabToSelect)
651
638
}
652
639
653
- @MainActor
654
640
private func configureNewTab( with tabData: TabData ) -> Tab ? {
655
641
let newTab : Tab
656
642
@@ -700,7 +686,6 @@ class TabManagerImplementation: NSObject,
700
686
return newTab
701
687
}
702
688
703
- @MainActor
704
689
private func handleTabSelectionAfterRestore( tabToSelect: Tab ? ) {
705
690
assert ( Thread . isMainThread)
706
691
if isDeeplinkOptimizationRefactorEnabled, let deeplinkTab {
@@ -737,7 +722,6 @@ class TabManagerImplementation: NSObject,
737
722
}
738
723
739
724
/// Creates the webview so needs to live on the main thread
740
- @MainActor
741
725
private func generateEmptyTab( ) {
742
726
let newTab = addTab ( )
743
727
selectTab ( newTab)
@@ -815,20 +799,17 @@ class TabManagerImplementation: NSObject,
815
799
return tabData
816
800
}
817
801
818
- @MainActor
819
802
func commitChanges( ) {
820
803
preserveTabs ( )
821
804
saveSessionData ( forTab: selectedTab)
822
805
}
823
806
824
- @MainActor
825
807
func notifyCurrentTabDidFinishLoading( ) {
826
808
delegates. forEach {
827
809
$0. get ( ) ? . tabManagerTabDidFinishLoading ( )
828
810
}
829
811
}
830
812
831
- @MainActor
832
813
private func saveSessionData( forTab tab: Tab ? ) {
833
814
guard let tab = tab,
834
815
let tabSession = tab. webView? . interactionState as? Data ,
@@ -838,7 +819,6 @@ class TabManagerImplementation: NSObject,
838
819
self . tabSessionStore. saveTabSession ( tabID: tabID, sessionData: tabSession)
839
820
}
840
821
841
- @MainActor
842
822
private func saveAllTabData( ) {
843
823
// Only preserve tabs after the restore has finished
844
824
guard tabRestoreHasFinished, let url = selectedTab? . url, !url. isFxHomeUrl else { return }
@@ -852,7 +832,6 @@ class TabManagerImplementation: NSObject,
852
832
/// This function updates the selectedIndex.
853
833
/// Note: it is safe to call this with `tab` and `previous` as the same tab, for use in the case
854
834
/// where the index of the tab has changed (such as after deletion).
855
- @MainActor
856
835
func selectTab( _ tab: Tab ? , previous: Tab ? = nil ) {
857
836
assert ( Thread . isMainThread)
858
837
// Fallback everywhere to selectedTab if no previous tab
@@ -934,7 +913,6 @@ class TabManagerImplementation: NSObject,
934
913
forKey: PrefsKeys . LastSessionWasPrivate)
935
914
}
936
915
937
- @MainActor
938
916
private func removeAllPrivateTabs( ) {
939
917
// reset the selectedTabIndex if we are on a private tab because we will be removing it.
940
918
if selectedTab? . isPrivate ?? false {
@@ -969,7 +947,6 @@ class TabManagerImplementation: NSObject,
969
947
store. dispatchLegacy ( action)
970
948
}
971
949
972
- @MainActor
973
950
private func selectTabWithSession( tab: Tab , sessionData: Data ? ) {
974
951
MainActor . assertIsolated ( " Expected to be called only on main actor. " )
975
952
let configuration : WKWebViewConfiguration = tabConfigurationProvider. configuration (
@@ -1027,15 +1004,13 @@ class TabManagerImplementation: NSObject,
1027
1004
}
1028
1005
1029
1006
// MARK: - Inactive tabs
1030
- @MainActor
1031
1007
func getInactiveTabs( ) -> [ Tab ] {
1032
1008
let inactiveTabsPrefEnabled = profile. prefs. boolForKey ( PrefsKeys . FeatureFlags. InactiveTabs) ?? true
1033
1009
let inactiveTabsEnabled = inactiveTabsPrefEnabled && !isTabTrayUIExperimentsEnabled
1034
1010
guard inactiveTabsEnabled else { return [ ] }
1035
1011
return inactiveTabsManager. getInactiveTabs ( tabs: tabs)
1036
1012
}
1037
1013
1038
- @MainActor
1039
1014
func removeAllInactiveTabs( ) {
1040
1015
let currentModeTabs = getInactiveTabs ( )
1041
1016
backupCloseTabs = currentModeTabs
@@ -1045,14 +1020,12 @@ class TabManagerImplementation: NSObject,
1045
1020
commitChanges ( )
1046
1021
}
1047
1022
1048
- @MainActor
1049
1023
func undoCloseInactiveTabs( ) {
1050
1024
tabs. append ( contentsOf: backupCloseTabs)
1051
1025
commitChanges ( )
1052
1026
backupCloseTabs = [ Tab] ( )
1053
1027
}
1054
1028
1055
- @MainActor
1056
1029
func clearAllTabsHistory( ) {
1057
1030
assert ( Thread . isMainThread)
1058
1031
guard let selectedTab = selectedTab, let url = selectedTab. url else { return }
@@ -1076,7 +1049,6 @@ class TabManagerImplementation: NSObject,
1076
1049
}
1077
1050
}
1078
1051
1079
- @MainActor
1080
1052
func reorderTabs( isPrivate privateMode: Bool , fromIndex visibleFromIndex: Int , toIndex visibleToIndex: Int ) {
1081
1053
let currentTabs = privateMode ? privateTabs : normalActiveTabs
1082
1054
@@ -1103,7 +1075,6 @@ class TabManagerImplementation: NSObject,
1103
1075
}
1104
1076
}
1105
1077
1106
- @MainActor
1107
1078
func switchPrivacyMode( ) -> SwitchPrivacyModeResult {
1108
1079
assert ( Thread . isMainThread)
1109
1080
var result = SwitchPrivacyModeResult . usedExistingTab
@@ -1128,7 +1099,6 @@ class TabManagerImplementation: NSObject,
1128
1099
return result
1129
1100
}
1130
1101
1131
- @MainActor
1132
1102
func addPopupForParentTab( profile: any Profile , parentTab: Tab , configuration: WKWebViewConfiguration ) -> Tab {
1133
1103
assert ( Thread . isMainThread)
1134
1104
let popup = Tab ( profile: profile,
@@ -1156,7 +1126,6 @@ class TabManagerImplementation: NSObject,
1156
1126
}
1157
1127
1158
1128
/// Note: Inserts AND configures the given tab.
1159
- @MainActor
1160
1129
private func configureTab(
1161
1130
_ tab: Tab ,
1162
1131
request: URLRequest ? ,
@@ -1260,7 +1229,6 @@ class TabManagerImplementation: NSObject,
1260
1229
}
1261
1230
1262
1231
// MARK: - Update Menu Items
1263
- @MainActor
1264
1232
private func updateMenuItemsForSelectedTab( ) {
1265
1233
guard let selectedTab,
1266
1234
var menuItems = UIMenuController . shared. menuItems
@@ -1292,7 +1260,6 @@ class TabManagerImplementation: NSObject,
1292
1260
}
1293
1261
1294
1262
// MARK: - SessionCreator
1295
- @MainActor
1296
1263
func createPopupSession( configuration: WKWebViewConfiguration , parent: WKWebView ) -> WKWebView ? {
1297
1264
guard let parentTab = self [ parent] else { return nil }
1298
1265
return addPopupForParentTab ( profile: profile, parentTab: parentTab, configuration: configuration) . webView
@@ -1304,17 +1271,17 @@ extension TabManagerImplementation: Notifiable {
1304
1271
func handleNotifications( _ notification: Notification ) {
1305
1272
let name = notification. name
1306
1273
let notificationWindowUUID = notification. windowUUID
1307
- Task { @ MainActor in
1274
+ ensureMainThread {
1308
1275
switch name {
1309
1276
case UIApplication . willResignActiveNotification:
1310
- saveAllTabData ( )
1277
+ self . saveAllTabData ( )
1311
1278
case . TabMimeTypeDidSet:
1312
- guard windowUUID == notificationWindowUUID else { return }
1313
- updateMenuItemsForSelectedTab ( )
1279
+ guard self . windowUUID == notificationWindowUUID else { return }
1280
+ self . updateMenuItemsForSelectedTab ( )
1314
1281
case . BlockPopup:
1315
- blockPopUpDidChange ( )
1282
+ self . blockPopUpDidChange ( )
1316
1283
case . AutoPlayChanged:
1317
- autoPlayDidChange ( )
1284
+ self . autoPlayDidChange ( )
1318
1285
default :
1319
1286
break
1320
1287
}
0 commit comments