Skip to content

Commit b7362bb

Browse files
authored
Refactor FXIOS-14338 ⁃ TabContentBlocker should use Notifiable protocol (#31120)
* FXIOS-14338 #31067 ⁃ TabContentBlocker should use Notifiable protocol * Quick refactor * Listen to contentBlockerTabSetupRequired
1 parent 2b0efcb commit b7362bb

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

firefox-ios/Client/ContentBlocker/TabContentBlocker.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ protocol ContentBlockerTab: AnyObject {
2020
}
2121

2222
@MainActor
23-
class TabContentBlocker {
23+
class TabContentBlocker: Notifiable {
2424
weak var tab: ContentBlockerTab?
2525
let logger: Logger
2626

2727
var isEnabled: Bool {
2828
return false
2929
}
3030

31-
@objc
32-
nonisolated func notifiedTabSetupRequired() {}
31+
func notifiedTabSetupRequired() {}
3332

3433
func currentlyEnabledLists() -> [String] {
3534
return []
@@ -60,11 +59,12 @@ class TabContentBlocker {
6059
init(tab: ContentBlockerTab, logger: Logger = DefaultLogger.shared) {
6160
self.tab = tab
6261
self.logger = logger
63-
NotificationCenter.default.addObserver(
64-
self,
65-
selector: #selector(notifiedTabSetupRequired),
66-
name: .contentBlockerTabSetupRequired,
67-
object: nil
62+
startObservingNotifications(
63+
withNotificationCenter: NotificationCenter.default,
64+
forObserver: self,
65+
observing: [
66+
.contentBlockerTabSetupRequired
67+
]
6868
)
6969
}
7070

@@ -80,4 +80,17 @@ class TabContentBlocker {
8080
deinit {
8181
NotificationCenter.default.removeObserver(self)
8282
}
83+
84+
// MARK: - Notifiable
85+
86+
public func handleNotifications(_ notification: Notification) {
87+
switch notification.name {
88+
case .contentBlockerTabSetupRequired:
89+
ensureMainThread {
90+
self.notifiedTabSetupRequired
91+
}
92+
default:
93+
return
94+
}
95+
}
8396
}

firefox-ios/Client/Frontend/Browser/FirefoxTabContentBlocker.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,11 @@ final class FirefoxTabContentBlocker: TabContentBlocker, TabContentScript {
114114
)
115115
}
116116

117-
override nonisolated func notifiedTabSetupRequired() {
118-
ensureMainThread {
119-
guard let tab = self.tab as? Tab else { return }
120-
self.logger.log("Notified tab setup required", level: .info, category: .adblock)
121-
self.setupForTab(completion: { tab.reloadPage() })
122-
TabEvent.post(.didChangeContentBlocking, for: tab)
123-
}
117+
override func notifiedTabSetupRequired() {
118+
guard let tab = self.tab as? Tab else { return }
119+
self.logger.log("Notified tab setup required", level: .info, category: .adblock)
120+
self.setupForTab(completion: { tab.reloadPage() })
121+
TabEvent.post(.didChangeContentBlocking, for: tab)
124122
}
125123

126124
override func currentlyEnabledLists() -> [String] {

0 commit comments

Comments
 (0)