Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix unwanted removal of content blockers upon launch #8222

Merged
merged 3 commits into from
Oct 11, 2023
Merged
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
31 changes: 25 additions & 6 deletions Sources/Brave/Frontend/Browser/Helpers/LaunchHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ public actor LaunchHelper {
/// Get all possible types of blocklist types available in this app, this includes actual and potential types
/// This is used to delete old filter lists so that we clean up old stuff
@MainActor private func getAllValidBlocklistTypes() -> Set<ContentBlockerManager.BlocklistType> {
return FilterListStorage.shared.filterLists
return FilterListStorage.shared
// All filter lists blocklist types
.reduce(Set<ContentBlockerManager.BlocklistType>()) { partialResult, filterList in
return partialResult.union([
.filterList(componentId: filterList.entry.componentId, isAlwaysAggressive: filterList.isAlwaysAggressive)
])
}
.validBlocklistTypes
// All generic types
.union(
ContentBlockerManager.GenericBlocklistType.allCases.map { .generic($0) }
Expand All @@ -127,6 +123,29 @@ public actor LaunchHelper {
}
}

private extension FilterListStorage {
/// Return all the blocklist types that are valid for filter lists.
var validBlocklistTypes: Set<ContentBlockerManager.BlocklistType> {
if filterLists.isEmpty {
// If we don't have filter lists yet loaded, use the settings
return Set(allFilterListSettings.compactMap { setting in
guard let componentId = setting.componentId else { return nil }
return .filterList(
componentId: componentId,
isAlwaysAggressive: setting.isAlwaysAggressive
)
})
} else {
// If we do have filter lists yet loaded, use them as they are always the most up to date and accurate
return Set(filterLists.map { filterList in
return .filterList(
componentId: filterList.entry.componentId,
isAlwaysAggressive: filterList.isAlwaysAggressive
)
})
}
}
}
private extension ShieldLevel {
/// Return a list of first launch content blocker modes that MUST be precompiled during launch
var firstLaunchBlockingModes: Set<ContentBlockerManager.BlockingMode> {
Expand Down