From e72871f0fb9074596a965296a3903127f2774160 Mon Sep 17 00:00:00 2001 From: Jacob Sikorski Date: Thu, 11 May 2023 13:48:43 +0200 Subject: [PATCH] Add ad-block level to advanced shield settings --- .../Browser/BrowserViewController.swift | 3 +- .../Shields/AdvancedShieldSettings.swift | 26 +++++++--- .../Shields/DefaultShieldsSectionView.swift | 35 ++++++++++--- .../Shields/AdvancedShieldsView.swift | 4 +- .../Shields/ShieldsViewController.swift | 42 ++++++++-------- .../SiteStateListenerScriptHandler.swift | 7 +-- Sources/Brave/Migration/Migration.swift | 50 +++++++++++++++++-- Sources/BraveShields/BraveShield.swift | 2 +- Sources/BraveShields/ShieldLevel.swift | 32 ++++++++++++ Sources/BraveShields/ShieldPreferences.swift | 24 +++++++++ Sources/BraveShields/ShieldStrings.swift | 35 +++++++++++++ Sources/BraveStrings/BraveStrings.swift | 2 - Sources/Data/models/Domain.swift | 20 ++------ Sources/Preferences/GlobalPreferences.swift | 5 +- 14 files changed, 221 insertions(+), 66 deletions(-) create mode 100644 Sources/BraveShields/ShieldLevel.swift create mode 100644 Sources/BraveShields/ShieldPreferences.swift diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index c9fdebff46e..c2faa02e2a4 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -509,6 +509,7 @@ public class BrowserViewController: UIViewController { Preferences.Playlist.enablePlaylistMenuBadge.observe(from: self) Preferences.Playlist.enablePlaylistURLBarButton.observe(from: self) Preferences.Playlist.syncSharedFoldersAutomatically.observe(from: self) + ShieldPreferences.blockAdsAndTrackingLevelRaw.observe(from: self) pageZoomListener = NotificationCenter.default.addObserver(forName: PageZoomView.notificationName, object: nil, queue: .main) { [weak self] _ in self?.tabManager.allTabs.forEach({ @@ -2990,7 +2991,7 @@ extension BrowserViewController: PreferencesObserver { tabManager.reloadSelectedTab() case Preferences.General.enablePullToRefresh.key: tabManager.selectedTab?.updatePullToRefreshVisibility() - case Preferences.Shields.blockAdsAndTracking.key, + case ShieldPreferences.blockAdsAndTrackingLevelRaw.key, Preferences.Shields.blockScripts.key, Preferences.Shields.blockImages.key, Preferences.Shields.fingerprintingProtection.key, diff --git a/Sources/Brave/Frontend/Settings/Shields/AdvancedShieldSettings.swift b/Sources/Brave/Frontend/Settings/Shields/AdvancedShieldSettings.swift index 36f608dfee0..46b4175c6fd 100644 --- a/Sources/Brave/Frontend/Settings/Shields/AdvancedShieldSettings.swift +++ b/Sources/Brave/Frontend/Settings/Shields/AdvancedShieldSettings.swift @@ -8,6 +8,7 @@ import Combine import BraveCore import BraveNews import Preferences +import BraveShields import Data import Growth import os @@ -42,6 +43,14 @@ import os p3aUtilities.isP3AEnabled = isP3AEnabled } } + @Published var adBlockAndTrackingPreventionLevel: ShieldLevel { + didSet { + ShieldPreferences.blockAdsAndTrackingLevel = adBlockAndTrackingPreventionLevel + if adBlockAndTrackingPreventionLevel != oldValue { + recordGlobalAdBlockShieldsP3A() + } + } + } typealias ClearDataCallback = @MainActor (Bool) -> Void @Published var clearableSettings: [ClearableSetting] @@ -61,6 +70,7 @@ import os self.tabManager = tabManager self.isP3AEnabled = p3aUtilities.isP3AEnabled self.clearDataCallback = clearDataCallback + self.adBlockAndTrackingPreventionLevel = ShieldPreferences.blockAdsAndTrackingLevel cookieConsentBlocking = FilterListStorage.shared.isEnabled( for: FilterList.cookieConsentNoticesComponentID @@ -189,12 +199,6 @@ import os } .store(in: &subscriptions) - Preferences.Shields.blockAdsAndTracking.$value - .sink { [weak self] _ in - self?.recordGlobalAdBlockShieldsP3A() - } - .store(in: &subscriptions) - Preferences.Shields.fingerprintingProtection.$value .sink { [weak self] _ in self?.recordGlobalFingerprintingShieldsP3A() @@ -211,7 +215,15 @@ import os case standard = 1 case aggressive = 2 } - let answer: Answer = Preferences.Shields.blockAdsAndTracking.value ? .standard : .disabled + + let answer = { () -> Answer in + switch ShieldPreferences.blockAdsAndTrackingLevel { + case .disabled: return .disabled + case .standard: return .standard + case .aggressive: return .aggressive + } + }() + UmaHistogramEnumeration("Brave.Shields.AdBlockSetting", sample: answer) } diff --git a/Sources/Brave/Frontend/Settings/Shields/DefaultShieldsSectionView.swift b/Sources/Brave/Frontend/Settings/Shields/DefaultShieldsSectionView.swift index ec8746880b0..ddf250a2475 100644 --- a/Sources/Brave/Frontend/Settings/Shields/DefaultShieldsSectionView.swift +++ b/Sources/Brave/Frontend/Settings/Shields/DefaultShieldsSectionView.swift @@ -9,7 +9,7 @@ import Data import DesignSystem import BraveUI import Preferences -import Strings +import BraveShields struct DefaultShieldsViewView: View { enum CookieAlertType: String, Identifiable { @@ -24,11 +24,20 @@ struct DefaultShieldsViewView: View { var body: some View { Section { - OptionToggleView( - title: Strings.blockAdsAndTracking, - subtitle: Strings.blockAdsAndTrackingDescription, - option: Preferences.Shields.blockAdsAndTracking - ) + Picker(selection: $settings.adBlockAndTrackingPreventionLevel) { + ForEach(ShieldLevel.allCases) { level in + Text(level.localizedTitle) + .foregroundColor(Color(.secondaryBraveLabel)) + .tag(level) + } + } label: { + ShieldLabelView( + title: Strings.Shields.trackersAndAdsBlocking, + subtitle: Strings.Shields.trackersAndAdsBlockingDescription + ) + } + .listRowBackground(Color(.secondaryBraveGroupedBackground)) + OptionToggleView( title: Strings.HTTPSEverywhere, subtitle: Strings.HTTPSEverywhereDescription, @@ -134,3 +143,17 @@ struct DefaultShieldsViewView: View { } } } + +extension ShieldLevel: Identifiable { + public var id: String { + return rawValue + } + + public var localizedTitle: String { + switch self { + case .aggressive: return Strings.Shields.trackersAndAdsBlockingAggressive + case .disabled: return Strings.Shields.trackersAndAdsBlockingDisabled + case .standard: return Strings.Shields.trackersAndAdsBlockingStandard + } + } +} diff --git a/Sources/Brave/Frontend/Shields/AdvancedShieldsView.swift b/Sources/Brave/Frontend/Shields/AdvancedShieldsView.swift index 16639fe86ae..f8158cbf171 100644 --- a/Sources/Brave/Frontend/Shields/AdvancedShieldsView.swift +++ b/Sources/Brave/Frontend/Shields/AdvancedShieldsView.swift @@ -6,10 +6,12 @@ import UIKit import Shared import BraveShared import BraveUI +import Preferences +import BraveShields class AdvancedShieldsView: UIStackView { let siteTitle = HeaderTitleView() - let adsTrackersControl = ToggleView(title: Strings.blockAdsAndTracking) + let adsTrackersControl = ToggleView(title: Strings.Shields.trackersAndAdsBlocking) let blockMalwareControl = ToggleView(title: Strings.blockPhishing) let blockScriptsControl = ToggleView(title: Strings.blockScripts) let fingerprintingControl = ToggleView(title: Strings.fingerprintingProtection) diff --git a/Sources/Brave/Frontend/Shields/ShieldsViewController.swift b/Sources/Brave/Frontend/Shields/ShieldsViewController.swift index 9680f1c447e..f936d5f914f 100644 --- a/Sources/Brave/Frontend/Shields/ShieldsViewController.swift +++ b/Sources/Brave/Frontend/Shields/ShieldsViewController.swift @@ -66,23 +66,23 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { domain = Domain.getOrCreate(forUrl: url, persistent: !isPrivateBrowsing) } - if let domain = domain { - shieldsUpSwitch.isOn = !domain.isShieldExpected(.AllOff, considerAllShieldsOption: false) - } else { - shieldsUpSwitch.isOn = true - } - - shieldControlMapping.forEach { shield, view, option in - // Updating based on global settings - if let option = option { - // Sets the default setting - view.toggleSwitch.isOn = option.value - } - // Domain specific overrides after defaults have already been setup + shieldsUpSwitch.isOn = domain?.isShieldExpected(.AllOff, considerAllShieldsOption: false) == false + shieldControlMapping.forEach { shield, view in if let domain = domain { // site-specific shield has been overridden, update view.toggleSwitch.isOn = domain.isShieldExpected(shield, considerAllShieldsOption: false) + } else { + switch shield { + case .AdblockAndTp: + view.toggleSwitch.isOn = ShieldPreferences.blockAdsAndTrackingLevel.isEnabled + case .AllOff: + assertionFailure() + case .FpProtection: + view.toggleSwitch.isOn = Preferences.Shields.fingerprintingProtection.value + case .NoScript: + view.toggleSwitch.isOn = Preferences.Shields.blockScripts.value + } } } updateGlobalShieldState(shieldsUpSwitch.isOn) @@ -94,7 +94,7 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { ) } - private func updateBraveShieldState(shield: BraveShield, on: Bool, option: Preferences.Option?) { + private func updateBraveShieldState(shield: BraveShield, on: Bool) { guard let url = url else { return } let allOff = shield == .AllOff // `.AllOff` uses inverse logic. Technically we set "all off" when the switch is OFF, unlike all the others @@ -211,10 +211,10 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { // MARK: - /// Groups the shield types with their control and global preference - private lazy var shieldControlMapping: [(BraveShield, AdvancedShieldsView.ToggleView, Preferences.Option?)] = [ - (.AdblockAndTp, shieldsView.advancedShieldView.adsTrackersControl, Preferences.Shields.blockAdsAndTracking), - (.NoScript, shieldsView.advancedShieldView.blockScriptsControl, Preferences.Shields.blockScripts), - (.FpProtection, shieldsView.advancedShieldView.fingerprintingControl, Preferences.Shields.fingerprintingProtection), + private lazy var shieldControlMapping: [(BraveShield, AdvancedShieldsView.ToggleView)] = [ + (.AdblockAndTp, shieldsView.advancedShieldView.adsTrackersControl), + (.NoScript, shieldsView.advancedShieldView.blockScriptsControl), + (.FpProtection, shieldsView.advancedShieldView.fingerprintingControl), ] var shieldsView: View { @@ -264,11 +264,11 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { updatePreferredContentSize() } - shieldControlMapping.forEach { shield, toggle, option in + shieldControlMapping.forEach { shield, toggle in toggle.valueToggled = { [weak self] on in guard let self = self else { return } // Localized / per domain toggles triggered here - self.updateBraveShieldState(shield: shield, on: on, option: option) + self.updateBraveShieldState(shield: shield, on: on) // Wait a fraction of a second to allow DB write to complete otherwise it will not use the // updated shield settings when reloading the page DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { @@ -281,7 +281,7 @@ class ShieldsViewController: UIViewController, PopoverContentComponent { @objc private func shieldsOverrideSwitchValueChanged() { let isOn = shieldsUpSwitch.isOn self.updateGlobalShieldState(isOn, animated: true) - self.updateBraveShieldState(shield: .AllOff, on: isOn, option: nil) + self.updateBraveShieldState(shield: .AllOff, on: isOn) // Wait a fraction of a second to allow DB write to complete otherwise it will not use the updated // shield settings when reloading the page DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { diff --git a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/SiteStateListenerScriptHandler.swift b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/SiteStateListenerScriptHandler.swift index 81941879f6b..c6a9d990e20 100644 --- a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/SiteStateListenerScriptHandler.swift +++ b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/SiteStateListenerScriptHandler.swift @@ -6,6 +6,7 @@ import Foundation import WebKit import Shared +import BraveShields import os.log class SiteStateListenerScriptHandler: TabContentScript { @@ -67,7 +68,7 @@ class SiteStateListenerScriptHandler: TabContentScript { if domain.areAllShieldsOff { return } let models = await AdBlockStats.shared.cosmeticFilterModels(forFrameURL: frameURL, domain: domain) - let args = try self.makeArgs(from: models, frameURL: frameURL) + let args = try self.makeArgs(from: models, frameURL: frameURL, isAggressive: ShieldPreferences.blockAdsAndTrackingLevel.isAggressive) let source = try ScriptFactory.shared.makeScriptSource(of: .selectorsPoller).replacingOccurrences(of: "$", with: args) let secureSource = CosmeticFiltersScriptHandler.secureScript( @@ -97,7 +98,7 @@ class SiteStateListenerScriptHandler: TabContentScript { } } - @MainActor private func makeArgs(from modelTuples: [CachedAdBlockEngine.CosmeticFilterModelTuple], frameURL: URL) throws -> String { + @MainActor private func makeArgs(from modelTuples: [CachedAdBlockEngine.CosmeticFilterModelTuple], frameURL: URL, isAggressive: Bool) throws -> String { var standardSelectors: Set = [] var agressiveSelectors: Set = [] var styleSelectors: [String: Set] = [:] @@ -126,7 +127,7 @@ class SiteStateListenerScriptHandler: TabContentScript { // (i.e. we don't hide first party content on standard mode) let setup = UserScriptType.SelectorsPollerSetup( frameURL: frameURL, - hideFirstPartyContent: false, + hideFirstPartyContent: isAggressive, genericHide: modelTuples.contains { $0.model.genericHide }, firstSelectorsPollingDelayMs: nil, switchToSelectorsPollingThreshold: 1000, diff --git a/Sources/Brave/Migration/Migration.swift b/Sources/Brave/Migration/Migration.swift index ec96be24f0c..32c871d958c 100644 --- a/Sources/Brave/Migration/Migration.swift +++ b/Sources/Brave/Migration/Migration.swift @@ -5,6 +5,7 @@ import Foundation import Shared import Preferences +import BraveShields import SwiftKeychainWrapper import Data import BraveCore @@ -22,8 +23,8 @@ public class Migration { public func launchMigrations(keyPrefix: String, profile: Profile) { Preferences.migratePreferences(keyPrefix: keyPrefix) - Preferences.migrateWalletPreferences() + Preferences.migrateAdAndTrackingProtection() if !Preferences.Migration.documentsDirectoryCleanupCompleted.value { documentsDirectoryCleanup() @@ -182,6 +183,10 @@ public class Migration { } fileprivate extension Preferences { + private final class DeprecatedPreferences { + static let blockAdsAndTracking = Option(key: "shields.block-ads-and-tracking", default: true) + } + /// Migration preferences final class Migration { static let completed = Option(key: "migration.completed", default: false) @@ -202,6 +207,12 @@ fileprivate extension Preferences { Option(key: "migration.wallet-provider-account-request-completed", default: false) static let tabMigrationToInteractionStateCompleted = Option(key: "migration.tab-to-interaction-state", default: false) + + /// A more complicated ad blocking and tracking protection preference in `1.52.x` + /// allows a user to select between `standard`, `aggressive` and `disabled` instead of a simple on/off `Bool` + static let adBlockAndTrackingProtectionShieldLevelCompleted = Option( + key: "migration.ad-block-and-tracking-protection-shield-level-completed", default: false + ) } /// Migrate a given key from `Prefs` into a specific option @@ -282,7 +293,7 @@ fileprivate extension Preferences { } // Shields - migrate(key: "braveBlockAdsAndTracking", to: Preferences.Shields.blockAdsAndTracking) + migrate(key: "braveBlockAdsAndTracking", to: DeprecatedPreferences.blockAdsAndTracking) migrate(key: "braveHttpsEverywhere", to: Preferences.Shields.httpsEverywhere) migrate(key: "noscript_on", to: Preferences.Shields.blockScripts) migrate(key: "fingerprintprotection_on", to: Preferences.Shields.fingerprintingProtection) @@ -309,10 +320,23 @@ fileprivate extension Preferences { // On 1.6 lastLaunchInfo is used to check if it's first app launch or not. // This needs to be translated to our new preference. Preferences.General.isFirstLaunch.value = Preferences.DAU.lastLaunchInfo.value == nil - Preferences.Migration.completed.value = true } + class func migrateAdAndTrackingProtection() { + guard !Migration.adBlockAndTrackingProtectionShieldLevelCompleted.value else { return } + + // Migrate old tracking protection setting to new BraveShields setting + DeprecatedPreferences.blockAdsAndTracking.migrate() { isEnabled in + if !isEnabled { + // We only need to migrate `disabled`. `standard` is the default. + ShieldPreferences.blockAdsAndTrackingLevel = .disabled + } + } + + Migration.adBlockAndTrackingProtectionShieldLevelCompleted.value = true + } + /// Migrate Wallet Preferences from version <1.43 class func migrateWalletPreferences() { guard Preferences.Migration.walletProviderAccountRequestCompleted.value != true else { return } @@ -323,3 +347,23 @@ fileprivate extension Preferences { Preferences.Migration.walletProviderAccountRequestCompleted.value = true } } + +private extension Preferences.Option { + /// Migrate this preference to another one using the given transform + /// + /// This method will return any stored value (if it is available). If nothing is stored, the callback is not triggered. + /// Any stored value is then removed from the container. + func migrate(onStoredValue: ((ValueType) -> Void)) { + // Have to do two checks because T may be an Optional, since object(forKey:) returns Any? it will succeed + // as casting to T if T is Optional even if the key doesnt exist. + if let value = container.object(forKey: key) { + if let value = value as? ValueType { + onStoredValue(value) + } + + container.removeObject(forKey: key) + } else { + Logger.module.info("Could not migrate legacy pref with key: \"\(self.key)\".") + } + } +} diff --git a/Sources/BraveShields/BraveShield.swift b/Sources/BraveShields/BraveShield.swift index 31f1e775d4b..8c10a8b6d41 100644 --- a/Sources/BraveShields/BraveShield.swift +++ b/Sources/BraveShields/BraveShield.swift @@ -17,7 +17,7 @@ public enum BraveShield { case .AllOff: return false case .AdblockAndTp: - return Preferences.Shields.blockAdsAndTracking.value + return ShieldPreferences.blockAdsAndTrackingLevel.isEnabled case .FpProtection: return Preferences.Shields.fingerprintingProtection.value case .NoScript: diff --git a/Sources/BraveShields/ShieldLevel.swift b/Sources/BraveShields/ShieldLevel.swift new file mode 100644 index 00000000000..1fbcd9c3039 --- /dev/null +++ b/Sources/BraveShields/ShieldLevel.swift @@ -0,0 +1,32 @@ +// Copyright 2023 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import Foundation + +/// A 3 part option for shield levels varying in strength of blocking content +public enum ShieldLevel: String, CaseIterable, Hashable { + /// Mode blocks all content + case aggressive + /// Mode indicating that 1st party content is not blocked for default and regional lists + case standard + /// Mode indicating this setting is disabled + case disabled + + /// Wether this setting indicates that the shields are enabled or not + public var isEnabled: Bool { + switch self { + case .aggressive, .standard: return true + case .disabled: return false + } + } + + /// Wether this setting indicates that the shields are aggressive or not + public var isAggressive: Bool { + switch self { + case .aggressive: return true + case .disabled, .standard: return false + } + } +} diff --git a/Sources/BraveShields/ShieldPreferences.swift b/Sources/BraveShields/ShieldPreferences.swift new file mode 100644 index 00000000000..0ad897aa6f1 --- /dev/null +++ b/Sources/BraveShields/ShieldPreferences.swift @@ -0,0 +1,24 @@ +// Copyright 2023 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import Foundation +import Preferences + +public class ShieldPreferences { + private static let defaultBlockAdsAndTrackingLevel: ShieldLevel = .standard + + /// Get the level of the adblock and tracking protection as a stored preference + /// - Warning: You should not access this directly but through ``blockAdsAndTrackingLevel`` + public static var blockAdsAndTrackingLevelRaw = Preferences.Option( + key: "shields.block-ads-and-tracking-level", + default: defaultBlockAdsAndTrackingLevel.rawValue + ) + + /// Get the level of the adblock and tracking protection + public static var blockAdsAndTrackingLevel: ShieldLevel { + get { ShieldLevel(rawValue: blockAdsAndTrackingLevelRaw.value) ?? defaultBlockAdsAndTrackingLevel } + set { blockAdsAndTrackingLevelRaw.value = newValue.rawValue } + } +} diff --git a/Sources/BraveShields/ShieldStrings.swift b/Sources/BraveShields/ShieldStrings.swift index 3802e0e91e1..b92a4913a0c 100644 --- a/Sources/BraveShields/ShieldStrings.swift +++ b/Sources/BraveShields/ShieldStrings.swift @@ -19,3 +19,38 @@ extension Strings { public static let shieldsTimeStatsDays = NSLocalizedString("ShieldsTimeStatsDays", bundle: .module, value: "d", comment: "Time Saved Days") } } + +// MARK: - Trackers and Ad-Blocking + +public extension Strings.Shields { + /// A label for a shield option that allows you to switch between different blocking levels for tracker and ads blocking. Options include disabled, standard and aggressive. + static let trackersAndAdsBlocking = NSLocalizedString( + "TrackersAndAdsBlocking", tableName: "BraveShared", bundle: .module, + value: "Trackers & Ads Blocking", + comment: "A label for a shield option that allows you to switch between different blocking levels for tracker and ads blocking. Options include disabled, standard and aggressive." + ) + /// A description for a shield options that allows you to switch between different blocking levels for trackers and ads blocking. Options include disabled, standard and aggressive. + static let trackersAndAdsBlockingDescription = NSLocalizedString( + "BlockAdsAndTrackingDescription", tableName: "BraveShared", bundle: .module, + value: "Prevents ads, popups, and trackers from loading.", + comment: "A description for a shield options that allows you to switch between different blocking levels for trackers and ads blocking. Options include disabled, standard and aggressive." + ) + /// The option the user can select to disable ad and tracker blocking + static let trackersAndAdsBlockingDisabled = NSLocalizedString( + "BlockAdsAndTrackingDisabled", tableName: "BraveShared", bundle: .module, + value: "Disabled", + comment: "The option the user can select to disable ad and tracker blocking" + ) + /// The option the user can select to do aggressive ad and tracker blocking + static let trackersAndAdsBlockingAggressive = NSLocalizedString( + "BlockAdsAndTrackingAggressive", tableName: "BraveShared", bundle: .module, + value: "Aggressive", + comment: "The option the user can select to do aggressive ad and tracker blocking" + ) + /// The option the user can select to do standard (non-aggressive) ad and tracker blocking + static let trackersAndAdsBlockingStandard = NSLocalizedString( + "BlockAdsAndTrackingStandard", tableName: "BraveShared", bundle: .module, + value: "Standard", + comment: "The option the user can select to do standard (non-aggressive) ad and tracker blocking" + ) +} diff --git a/Sources/BraveStrings/BraveStrings.swift b/Sources/BraveStrings/BraveStrings.swift index 617e823e6ba..02ed0263f1a 100644 --- a/Sources/BraveStrings/BraveStrings.swift +++ b/Sources/BraveStrings/BraveStrings.swift @@ -1036,8 +1036,6 @@ extension Strings { public static let privateBrowsingOnly = NSLocalizedString("PrivateBrowsingOnly", tableName: "BraveShared", bundle: .module, value: "Private Browsing Only", comment: "Setting to keep app in private mode") public static let shieldsDefaults = NSLocalizedString("ShieldsDefaults", tableName: "BraveShared", bundle: .module, value: "Brave Shields Global Defaults", comment: "Section title for adbblock, tracking protection, HTTPS-E, and cookies") public static let shieldsDefaultsFooter = NSLocalizedString("ShieldsDefaultsFooter", tableName: "BraveShared", bundle: .module, value: "These are the default Shields settings for new sites. Changing these won't affect your existing per-site settings.", comment: "Section footer for global shields defaults") - public static let blockAdsAndTracking = NSLocalizedString("BlockAdsAndTracking", tableName: "BraveShared", bundle: .module, value: "Block Cross-Site Trackers", comment: "") - public static let blockAdsAndTrackingDescription = NSLocalizedString("BlockAdsAndTrackingDescription", tableName: "BraveShared", bundle: .module, value: "Prevents ads, popups, and trackers from loading.", comment: "") public static let HTTPSEverywhere = NSLocalizedString("HTTPSEverywhere", tableName: "BraveShared", bundle: .module, value: "Upgrade Connections to HTTPS", comment: "") public static let HTTPSEverywhereDescription = NSLocalizedString("HTTPSEverywhereDescription", tableName: "BraveShared", bundle: .module, value: "Opens sites using secure HTTPS instead of HTTP when possible.", comment: "") public static let googleSafeBrowsing = NSLocalizedString("GoogleSafeBrowsing", tableName: "BraveShared", bundle: .module, value: "Block Dangerous Sites", comment: "") diff --git a/Sources/Data/models/Domain.swift b/Sources/Data/models/Domain.swift index 9688b4c92c0..a8cdae0c8ff 100644 --- a/Sources/Data/models/Domain.swift +++ b/Sources/Data/models/Domain.swift @@ -109,7 +109,7 @@ public final class Domain: NSManagedObject, CRUD { case .AllOff: return self.shield_allOff?.boolValue ?? false case .AdblockAndTp: - return self.shield_adblockAndTp?.boolValue ?? Preferences.Shields.blockAdsAndTracking.value + return self.shield_adblockAndTp?.boolValue ?? ShieldPreferences.blockAdsAndTrackingLevel.isEnabled case .FpProtection: return self.shield_fpProtection?.boolValue ?? Preferences.Shields.fingerprintingProtection.value case .NoScript: @@ -156,7 +156,7 @@ public final class Domain: NSManagedObject, CRUD { } public class func totalDomainsWithAdblockShieldsLoweredFromGlobal() -> Int { - guard Preferences.Shields.blockAdsAndTracking.value, + guard ShieldPreferences.blockAdsAndTrackingLevel.isEnabled, let domains = Domain.all(where: NSPredicate(format: "shield_adblockAndTp != nil")) else { return 0 // Can't be lower than off } @@ -164,7 +164,7 @@ public final class Domain: NSManagedObject, CRUD { } public class func totalDomainsWithAdblockShieldsIncreasedFromGlobal() -> Int { - guard !Preferences.Shields.blockAdsAndTracking.value, + guard !ShieldPreferences.blockAdsAndTrackingLevel.isEnabled, let domains = Domain.all(where: NSPredicate(format: "shield_adblockAndTp != nil")) else { return 0 // Can't be higher than on } @@ -405,20 +405,6 @@ extension Domain { } } - /// Get whether or not a shield override is set for a given shield. - private func getBraveShield(_ shield: BraveShield) -> Bool? { - switch shield { - case .AllOff: - return self.shield_allOff?.boolValue - case .AdblockAndTp: - return self.shield_adblockAndTp?.boolValue - case .FpProtection: - return self.shield_fpProtection?.boolValue - case .NoScript: - return self.shield_noScript?.boolValue - } - } - /// Returns `url` but switches the scheme from `http` <-> `https` private func domainForInverseHttpScheme(context: NSManagedObjectContext) -> Domain? { diff --git a/Sources/Preferences/GlobalPreferences.swift b/Sources/Preferences/GlobalPreferences.swift index 6dabae408dd..4edf5b945d6 100644 --- a/Sources/Preferences/GlobalPreferences.swift +++ b/Sources/Preferences/GlobalPreferences.swift @@ -34,10 +34,7 @@ extension Preferences { } public final class Shields { - public static let allShields = [blockAdsAndTracking, httpsEverywhere, googleSafeBrowsing, blockScripts, fingerprintingProtection, blockImages] - - /// Shields will block ads and tracking if enabled - public static let blockAdsAndTracking = Option(key: "shields.block-ads-and-tracking", default: true) + public static let allShields = [httpsEverywhere, googleSafeBrowsing, blockScripts, fingerprintingProtection, blockImages] /// Websites will be upgraded to HTTPS if a loaded page attempts to use HTTP public static let httpsEverywhere = Option(key: "shields.https-everywhere", default: true) /// Enable Google Safe Browsing