From 7819c1b730703499f64fd95b0c6d162bbdfd170f Mon Sep 17 00:00:00 2001 From: Garvan Keeley Date: Thu, 11 Jun 2020 16:26:52 -0400 Subject: [PATCH] [nobug, cleanup] Rename blacklist to blocklist (#6783) * [nobug, cleanup] Rename blacklist to blocklist * rename whitelist to safelist --- Client.xcodeproj/project.pbxproj | 8 +-- Client/Application/LeanplumIntegration.swift | 2 +- Client/Application/WebServer.swift | 2 +- ...owserViewController+WebViewDelegates.swift | 2 +- Client/Frontend/Browser/TabLocationView.swift | 8 +-- Client/Frontend/Settings/Clearables.swift | 2 +- Client/Frontend/Strings.swift | 4 +- .../PhotonActionSheetProtocol.swift | 6 +-- .../TrackingProtectionMenu.swift | 38 ++++++------- Client/Telemetry/UnifiedTelemetry.swift | 2 +- ClientTests/TPStatsBlocklistsTests.swift | 10 ++-- .../Sources/ContentBlockerGen/main.swift | 4 +- .../ContentBlockerGenLib.swift | 2 +- .../ContentBlockerGenTests.swift | 4 +- ...st.swift => ContentBlocker+Safelist.swift} | 54 +++++++++---------- .../src/ContentBlocker.swift | 18 +++---- .../src/TabContentBlocker+ContentScript.swift | 2 +- .../src/TabContentBlocker.swift | 12 ++--- .../src/TrackingProtectionPageStats.swift | 10 ++-- 19 files changed, 95 insertions(+), 95 deletions(-) rename content-blocker-lib-ios/src/{ContentBlocker+Whitelist.swift => ContentBlocker+Safelist.swift} (52%) diff --git a/Client.xcodeproj/project.pbxproj b/Client.xcodeproj/project.pbxproj index 855d11e3ad3c..d6b6a4634b39 100644 --- a/Client.xcodeproj/project.pbxproj +++ b/Client.xcodeproj/project.pbxproj @@ -719,7 +719,7 @@ EBB89504219398E500EB91A0 /* TrackingProtectionPageStats.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB894F5219398E500EB91A0 /* TrackingProtectionPageStats.swift */; }; EBB89506219398E500EB91A0 /* TabContentBlocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB894F7219398E500EB91A0 /* TabContentBlocker.swift */; }; EBB89507219398E500EB91A0 /* ContentBlocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB894F8219398E500EB91A0 /* ContentBlocker.swift */; }; - EBB89508219398E500EB91A0 /* ContentBlocker+Whitelist.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB894F9219398E500EB91A0 /* ContentBlocker+Whitelist.swift */; }; + EBB89508219398E500EB91A0 /* ContentBlocker+Safelist.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB894F9219398E500EB91A0 /* ContentBlocker+Safelist.swift */; }; EBB89509219398E500EB91A0 /* TabContentBlocker+ContentScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB894FA219398E500EB91A0 /* TabContentBlocker+ContentScript.swift */; }; EBB8950C21939E4100EB91A0 /* FirefoxTabContentBlocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB8950B2193994A00EB91A0 /* FirefoxTabContentBlocker.swift */; }; EBB895332193FFF400EB91A0 /* ContentBlockerSettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EBB895322193FFF400EB91A0 /* ContentBlockerSettingViewController.swift */; }; @@ -1851,7 +1851,7 @@ EBB894F5219398E500EB91A0 /* TrackingProtectionPageStats.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackingProtectionPageStats.swift; sourceTree = ""; }; EBB894F7219398E500EB91A0 /* TabContentBlocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabContentBlocker.swift; sourceTree = ""; }; EBB894F8219398E500EB91A0 /* ContentBlocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlocker.swift; sourceTree = ""; }; - EBB894F9219398E500EB91A0 /* ContentBlocker+Whitelist.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ContentBlocker+Whitelist.swift"; sourceTree = ""; }; + EBB894F9219398E500EB91A0 /* ContentBlocker+Safelist.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ContentBlocker+Safelist.swift"; sourceTree = ""; }; EBB894FA219398E500EB91A0 /* TabContentBlocker+ContentScript.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TabContentBlocker+ContentScript.swift"; sourceTree = ""; }; EBB8950B2193994A00EB91A0 /* FirefoxTabContentBlocker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirefoxTabContentBlocker.swift; sourceTree = ""; }; EBB895322193FFF400EB91A0 /* ContentBlockerSettingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlockerSettingViewController.swift; sourceTree = ""; }; @@ -3366,7 +3366,7 @@ EBB894F5219398E500EB91A0 /* TrackingProtectionPageStats.swift */, EBB894F7219398E500EB91A0 /* TabContentBlocker.swift */, EBB894F8219398E500EB91A0 /* ContentBlocker.swift */, - EBB894F9219398E500EB91A0 /* ContentBlocker+Whitelist.swift */, + EBB894F9219398E500EB91A0 /* ContentBlocker+Safelist.swift */, EBB894FA219398E500EB91A0 /* TabContentBlocker+ContentScript.swift */, ); path = src; @@ -5243,7 +5243,7 @@ D3968F251A38FE8500CEFD3B /* TabManager.swift in Sources */, C4E398601D22C409004E89BA /* TopTabsLayout.swift in Sources */, 2816F0001B33E05400522243 /* UIConstants.swift in Sources */, - EBB89508219398E500EB91A0 /* ContentBlocker+Whitelist.swift in Sources */, + EBB89508219398E500EB91A0 /* ContentBlocker+Safelist.swift in Sources */, D0B9483422A03468002F4AA1 /* BookmarkDetailPanel.swift in Sources */, 3B6889C51D66950E002AC85E /* UIImageColors.swift in Sources */, 392ED7E41D0AEF56009D9B62 /* NewTabAccessors.swift in Sources */, diff --git a/Client/Application/LeanplumIntegration.swift b/Client/Application/LeanplumIntegration.swift index 6a6ce3591334..fbca153b5931 100644 --- a/Client/Application/LeanplumIntegration.swift +++ b/Client/Application/LeanplumIntegration.swift @@ -67,7 +67,7 @@ enum LPEvent: String { case useReaderView = "E_User_Used_Reader_View" case trackingProtectionSettings = "E_Tracking_Protection_Settings_Changed" case trackingProtectionMenu = "E_Opened_Tracking_Protection_Menu" - case trackingProtectionWhiteList = "E_Added_Site_To_Tracking_Protection_Whitelist" + case trackingProtectionSafeList = "E_Added_Site_To_Tracking_Protection_Safelist" case fxaSyncedNewDevice = "E_FXA_Synced_New_Device" case onboardingTestLoadedTooSlow = "E_Onboarding_Was_Swiped_Before_AB_Test_Could_Start" } diff --git a/Client/Application/WebServer.swift b/Client/Application/WebServer.swift index 3d32f9a94ced..79e3e9241626 100644 --- a/Client/Application/WebServer.swift +++ b/Client/Application/WebServer.swift @@ -48,7 +48,7 @@ class WebServer { /// Convenience method to register a dynamic handler. Will be mounted at $base/$module/$resource func registerHandlerForMethod(_ method: String, module: String, resource: String, handler: @escaping (_ request: GCDWebServerRequest?) -> GCDWebServerResponse?) { - // Prevent serving content if the requested host isn't a whitelisted local host. + // Prevent serving content if the requested host isn't a safelisted local host. let wrappedHandler = {(request: GCDWebServerRequest?) -> GCDWebServerResponse? in guard let request = request, InternalURL.isValid(url: request.url) else { return GCDWebServerResponse(statusCode: 403) diff --git a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WebViewDelegates.swift b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WebViewDelegates.swift index 9e0219b4c87f..784fc62a87dc 100644 --- a/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WebViewDelegates.swift +++ b/Client/Frontend/Browser/BrowserViewController/BrowserViewController+WebViewDelegates.swift @@ -390,7 +390,7 @@ extension BrowserViewController: WKNavigationDelegate { // Second special case are a set of URLs that look like regular http links, but should be handed over to iOS // instead of being loaded in the webview. Note that there is no point in calling canOpenURL() here, because - // iOS will always say yes. TODO Is this the same as isWhitelisted? + // iOS will always say yes. if isAppleMapsURL(url) { UIApplication.shared.open(url, options: [:]) diff --git a/Client/Frontend/Browser/TabLocationView.swift b/Client/Frontend/Browser/TabLocationView.swift index 17d2880915e9..b3dfbbac1c00 100644 --- a/Client/Frontend/Browser/TabLocationView.swift +++ b/Client/Frontend/Browser/TabLocationView.swift @@ -393,14 +393,14 @@ extension TabLocationView: TabEventHandler { guard let blocker = tab.contentBlocker else { return } trackingProtectionButton.alpha = 1.0 switch blocker.status { - case .Blocking: + case .blocking: trackingProtectionButton.setImage(UIImage(imageLiteralResourceName: "tracking-protection-active-block"), for: .normal) - case .NoBlockedURLs: + case .noBlockedURLs: trackingProtectionButton.setImage(UIImage.templateImageNamed("tracking-protection"), for: .normal) trackingProtectionButton.alpha = 0.5 - case .Whitelisted: + case .safelisted: trackingProtectionButton.setImage(UIImage.templateImageNamed("tracking-protection-off"), for: .normal) - case .Disabled: + case .disabled: trackingProtectionButton.isHidden = true } } diff --git a/Client/Frontend/Settings/Clearables.swift b/Client/Frontend/Settings/Clearables.swift index b9228131a5bf..79c52bf798f9 100644 --- a/Client/Frontend/Settings/Clearables.swift +++ b/Client/Frontend/Settings/Clearables.swift @@ -162,7 +162,7 @@ class TrackingProtectionClearable: Clearable { func clear() -> Success { let result = Success() - ContentBlocker.shared.clearWhitelist() { + ContentBlocker.shared.clearSafelist() { result.fill(Maybe(success: ())) } return result diff --git a/Client/Frontend/Strings.swift b/Client/Frontend/Strings.swift index 3cf184bf32cb..fceca86cf78d 100644 --- a/Client/Frontend/Strings.swift +++ b/Client/Frontend/Strings.swift @@ -613,8 +613,8 @@ extension Strings { public static let TPListTitle_Cryptominer = NSLocalizedString("Menu.TrackingProtectionListTitle.Cryptominers", value: "Blocked Cryptominers", comment: "Title for list of domains blocked by category type. eg. Blocked `CryptoMiners`") /// <-- - public static let TPWhiteListOn = NSLocalizedString("Menu.TrackingProtectionOption.WhiteListOnDescription", value: "The site includes elements that may track your browsing. You have disabled protection.", comment: "label for the menu item to show when the website is whitelisted from blocking trackers.") - public static let TPWhiteListRemove = NSLocalizedString("Menu.TrackingProtectionWhitelistRemove.Title", value: "Enable for this site", comment: "label for the menu item that lets you remove a website from the tracking protection whitelist") + public static let TPSafeListOn = NSLocalizedString("Menu.TrackingProtectionOption.WhiteListOnDescription", value: "The site includes elements that may track your browsing. You have disabled protection.", comment: "label for the menu item to show when the website is whitelisted from blocking trackers.") + public static let TPSafeListRemove = NSLocalizedString("Menu.TrackingProtectionWhitelistRemove.Title", value: "Enable for this site", comment: "label for the menu item that lets you remove a website from the tracking protection whitelist") // Settings info public static let TPAccessoryInfoTitleStrict = NSLocalizedString("Settings.TrackingProtection.Info.StrictTitle", value: "Offers stronger protection, but may cause some sites to break.", comment: "Explanation of strict mode.") diff --git a/Client/Frontend/Widgets/PhotonActionSheet/PhotonActionSheetProtocol.swift b/Client/Frontend/Widgets/PhotonActionSheet/PhotonActionSheetProtocol.swift index 4d746d51ea2d..8928b963322d 100644 --- a/Client/Frontend/Widgets/PhotonActionSheet/PhotonActionSheetProtocol.swift +++ b/Client/Frontend/Widgets/PhotonActionSheet/PhotonActionSheetProtocol.swift @@ -93,12 +93,12 @@ extension PhotonActionSheetProtocol { } if let url = tab.webView?.url, let helper = tab.contentBlocker, helper.isEnabled { - let isWhitelisted = helper.status == .Whitelisted + let isSafelisted = helper.status == .safelisted - let title = !isWhitelisted ? Strings.TrackingProtectionReloadWithout : Strings.TrackingProtectionReloadWith + let title = !isSafelisted ? Strings.TrackingProtectionReloadWithout : Strings.TrackingProtectionReloadWith let imageName = helper.isEnabled ? "menu-TrackingProtection-Off" : "menu-TrackingProtection" let toggleTP = PhotonActionSheetItem(title: title, iconString: imageName) { _, _ in - ContentBlocker.shared.whitelist(enable: !isWhitelisted, url: url) { + ContentBlocker.shared.safelist(enable: !isSafelisted, url: url) { tab.reload() } } diff --git a/Client/Frontend/Widgets/PhotonActionSheet/TrackingProtectionMenu.swift b/Client/Frontend/Widgets/PhotonActionSheet/TrackingProtectionMenu.swift index 2d8a86005a73..c2f9c530dd84 100644 --- a/Client/Frontend/Widgets/PhotonActionSheet/TrackingProtectionMenu.swift +++ b/Client/Frontend/Widgets/PhotonActionSheet/TrackingProtectionMenu.swift @@ -50,14 +50,14 @@ extension PhotonActionSheetProtocol { return [] } switch blocker.status { - case .NoBlockedURLs: + case .noBlockedURLs: return menuActionsForTrackingProtectionEnabled(for: tab) - case .Blocking: + case .blocking: return menuActionsForTrackingProtectionEnabled(for: tab) - case .Disabled: + case .disabled: return menuActionsForTrackingProtectionDisabled(for: tab) - case .Whitelisted: - return menuActionsForTrackingProtectionEnabled(for: tab, isWhitelisted: true) + case .safelisted: + return menuActionsForTrackingProtectionEnabled(for: tab, isSafelisted: true) } } @@ -133,7 +133,7 @@ extension PhotonActionSheetProtocol { } @available(iOS 11.0, *) - private func menuActionsForTrackingProtectionEnabled(for tab: Tab, isWhitelisted: Bool = false) -> [[PhotonActionSheetItem]] { + private func menuActionsForTrackingProtectionEnabled(for tab: Tab, isSafelisted: Bool = false) -> [[PhotonActionSheetItem]] { guard let blocker = tab.contentBlocker, let currentURL = tab.url else { return [] } @@ -163,24 +163,24 @@ extension PhotonActionSheetProtocol { self.showDomainTable(title: action.title, description: desc, blocker: blocker, categories: [BlocklistCategory.cryptomining]) } - var addToWhitelist = PhotonActionSheetItem(title: Strings.ETPOn, isEnabled: !isWhitelisted, accessory: .Switch) { _, cell in - LeanPlumClient.shared.track(event: .trackingProtectionWhiteList) - UnifiedTelemetry.recordEvent(category: .action, method: .add, object: .trackingProtectionWhitelist) - ContentBlocker.shared.whitelist(enable: tab.contentBlocker?.status != .Whitelisted, url: currentURL) { + var addToSafelist = PhotonActionSheetItem(title: Strings.ETPOn, isEnabled: !isSafelisted, accessory: .Switch) { _, cell in + LeanPlumClient.shared.track(event: .trackingProtectionSafeList) + UnifiedTelemetry.recordEvent(category: .action, method: .add, object: .trackingProtectionSafelist) + ContentBlocker.shared.safelist(enable: tab.contentBlocker?.status != .safelisted, url: currentURL) { tab.reload() // trigger a call to customRender cell.backgroundView?.setNeedsDisplay() } } - addToWhitelist.customRender = { title, _ in - if tab.contentBlocker?.status == .Whitelisted { + addToSafelist.customRender = { title, _ in + if tab.contentBlocker?.status == .safelisted { title.text = Strings.ETPOff } else { title.text = Strings.ETPOn } } - addToWhitelist.accessibilityId = "tp.add-to-whitelist" - addToWhitelist.customHeight = { _ in + addToSafelist.accessibilityId = "tp.add-to-safelist" + addToSafelist.customHeight = { _ in return PhotonActionSheetUX.RowHeight } @@ -247,22 +247,22 @@ extension PhotonActionSheetProtocol { items = [[noblockeditems]] } - items = [[addToWhitelist]] + items + [[settings]] + items = [[addToSafelist]] + items + [[settings]] return items } @available(iOS 11.0, *) - private func menuActionsForWhitelistedSite(for tab: Tab) -> [[PhotonActionSheetItem]] { + private func menuActionsForSafelistedSite(for tab: Tab) -> [[PhotonActionSheetItem]] { guard let currentURL = tab.url else { return [] } - let removeFromWhitelist = PhotonActionSheetItem(title: Strings.TPWhiteListRemove, iconString: "menu-TrackingProtection") { _, _ in - ContentBlocker.shared.whitelist(enable: false, url: currentURL) { + let removeFromSafelist = PhotonActionSheetItem(title: Strings.TPSafeListRemove, iconString: "menu-TrackingProtection") { _, _ in + ContentBlocker.shared.safelist(enable: false, url: currentURL) { tab.reload() } } - return [[removeFromWhitelist]] + return [[removeFromSafelist]] } } diff --git a/Client/Telemetry/UnifiedTelemetry.swift b/Client/Telemetry/UnifiedTelemetry.swift index f0efbc61917c..421a9188d625 100644 --- a/Client/Telemetry/UnifiedTelemetry.swift +++ b/Client/Telemetry/UnifiedTelemetry.swift @@ -197,7 +197,7 @@ extension UnifiedTelemetry { case setting = "setting" case tab = "tab" case trackingProtectionStatistics = "tracking-protection-statistics" - case trackingProtectionWhitelist = "tracking-protection-whitelist" + case trackingProtectionSafelist = "tracking-protection-safelist" case trackingProtectionMenu = "tracking-protection-menu" case url = "url" case searchText = "searchText" diff --git a/ClientTests/TPStatsBlocklistsTests.swift b/ClientTests/TPStatsBlocklistsTests.swift index 2e40be3c8e63..116de8ea57bc 100644 --- a/ClientTests/TPStatsBlocklistsTests.swift +++ b/ClientTests/TPStatsBlocklistsTests.swift @@ -30,13 +30,13 @@ class TPStatsBlocklistsTests: XCTestCase { func testURLInListPerformance() { blocklists.load() - let whitelistedRegexs = ["*google.com"].compactMap { (domain) -> String? in + let safelistedRegexs = ["*google.com"].compactMap { (domain) -> String? in return wildcardContentBlockerDomainToRegex(domain: domain) } self.measureMetrics([.wallClockTime], automaticallyStartMeasuring: true) { for _ in 0..<100 { - _ = blocklists.urlIsInList(URL(string: "https://www.firefox.com")!, mainDocumentURL: URL(string: "http://foo.com")!, whitelistedDomains: whitelistedRegexs) + _ = blocklists.urlIsInList(URL(string: "https://www.firefox.com")!, mainDocumentURL: URL(string: "http://foo.com")!, safelistedDomains: safelistedRegexs) } self.stopMeasuring() } @@ -45,12 +45,12 @@ class TPStatsBlocklistsTests: XCTestCase { func testURLInList() { blocklists.load() - func blocklist(_ urlString: String, _ mainDoc: String = "https://foo.com", _ whitelistedDomains: [String] = []) -> BlocklistCategory? { - let whitelistedRegexs = whitelistedDomains.compactMap { (domain) -> String? in + func blocklist(_ urlString: String, _ mainDoc: String = "https://foo.com", _ safelistedDomains: [String] = []) -> BlocklistCategory? { + let safelistedRegexs = safelistedDomains.compactMap { (domain) -> String? in return wildcardContentBlockerDomainToRegex(domain: domain) } let mainDoc = URL(string: mainDoc)! - return blocklists.urlIsInList(URL(string: urlString)!, mainDocumentURL: mainDoc, whitelistedDomains: whitelistedRegexs) + return blocklists.urlIsInList(URL(string: urlString)!, mainDocumentURL: mainDoc, safelistedDomains: safelistedRegexs) } XCTAssertEqual(blocklist("https://www.facebook.com", "https://atlassolutions.com"), nil) XCTAssertEqual(blocklist("https://www.firefox.com"), nil) diff --git a/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGen/main.swift b/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGen/main.swift index 27c9d41f85b3..4e4e088f2d4c 100644 --- a/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGen/main.swift +++ b/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGen/main.swift @@ -10,7 +10,7 @@ let fallbackPath: String = (#file as NSString).deletingLastPathComponent + "/../ // We expect this command to be executed as 'cd ; swift run', if not, use the fallback path generated from the path to main.swift. Running from an xcodeproj will use fallbackPath. let execIsFromCorrectDir = fm.fileExists(atPath: fm.currentDirectoryPath + "/Package.swift") let rootdir = execIsFromCorrectDir ? fm.currentDirectoryPath : fallbackPath -let blacklist = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/disconnect-blacklist.json" +let blocklist = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/disconnect-blacklist.json" let entityList = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/disconnect-entitylist.json" let fingerprintingList = "\(rootdir)/../../Carthage/Checkouts/shavar-prod-lists/normalized-lists/base-fingerprinting-track.json" @@ -29,7 +29,7 @@ try! fm.createDirectory(at: outputDir, withIntermediateDirectories: false, attri func write(to outputDir: URL, action: Action, categories: [CategoryTitle]) { for categoryTitle in categories { - let result = gen.parseBlacklist(json: jsonFrom(filename: blacklist), action: action, categoryTitle: categoryTitle) + let result = gen.parseBlocklist(json: jsonFrom(filename: blocklist), action: action, categoryTitle: categoryTitle) let actionName = action == .blockAll ? "block" : "block-cookies" let outputFile = "\(outputDir.path)/disconnect-\(actionName)-\(categoryTitle.rawValue.lowercased()).json" let output = "[\n" + result.joined(separator: ",\n") + "\n]" diff --git a/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGenLib/ContentBlockerGenLib.swift b/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGenLib/ContentBlockerGenLib.swift index db6a7e1d798f..72d6724b55f1 100644 --- a/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGenLib/ContentBlockerGenLib.swift +++ b/content-blocker-lib-ios/ContentBlockerGen/Sources/ContentBlockerGenLib/ContentBlockerGenLib.swift @@ -73,7 +73,7 @@ public class ContentBlockerGenLib { return result } - public func parseBlacklist(json: [String: Any], action: Action, categoryTitle: CategoryTitle) -> [String] { + public func parseBlocklist(json: [String: Any], action: Action, categoryTitle: CategoryTitle) -> [String] { let categories = json["categories"]! as! [String: Any] var result = [String]() let category = categories[categoryTitle.rawValue] as! [Any] diff --git a/content-blocker-lib-ios/ContentBlockerGen/Tests/ContentBlockerGenTests/ContentBlockerGenTests.swift b/content-blocker-lib-ios/ContentBlockerGen/Tests/ContentBlockerGenTests/ContentBlockerGenTests.swift index 531b5e54a7b6..824e37ef28bf 100644 --- a/content-blocker-lib-ios/ContentBlockerGen/Tests/ContentBlockerGenTests/ContentBlockerGenTests.swift +++ b/content-blocker-lib-ios/ContentBlockerGen/Tests/ContentBlockerGenTests/ContentBlockerGenTests.swift @@ -5,7 +5,7 @@ import XCTest @testable import ContentBlockerGenLib -let blacklist = """ +let blocklist = """ { "license": "Copyright 2010-2019 Disconnect, Inc.", "categories": { @@ -30,7 +30,7 @@ final class ContentBlockerGenTests: XCTestCase { let contentBlocker = ContentBlockerGenLib(entityListJson: entityJson) - let json = try! JSONSerialization.jsonObject(with: blacklist.data(using: .utf8)!, options: []) as! [String: Any] + let json = try! JSONSerialization.jsonObject(with: blocklist.data(using: .utf8)!, options: []) as! [String: Any] let categories = json["categories"]! as! [String: Any] let category = categories[CategoryTitle.Advertising.rawValue] as! [Any] var result = [String]() diff --git a/content-blocker-lib-ios/src/ContentBlocker+Whitelist.swift b/content-blocker-lib-ios/src/ContentBlocker+Safelist.swift similarity index 52% rename from content-blocker-lib-ios/src/ContentBlocker+Whitelist.swift rename to content-blocker-lib-ios/src/ContentBlocker+Safelist.swift index 92d83a8601e6..e70c343942f1 100644 --- a/content-blocker-lib-ios/src/ContentBlocker+Whitelist.swift +++ b/content-blocker-lib-ios/src/ContentBlocker+Safelist.swift @@ -4,7 +4,7 @@ import WebKit -struct WhitelistedDomains { +struct SafelistedDomains { var domainSet = Set() { didSet { domainRegex = domainSet.compactMap { wildcardContentBlockerDomainToRegex(domain: "*" + $0) } @@ -16,41 +16,41 @@ struct WhitelistedDomains { extension ContentBlocker { - func whitelistFileURL() -> URL? { + func safelistFileURL() -> URL? { guard let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return nil } - return dir.appendingPathComponent("whitelist") + return dir.appendingPathComponent("safelist") } - // Get the whitelist domain array as a JSON fragment that can be inserted at the end of a blocklist. - func whitelistAsJSON() -> String { - if whitelistedDomains.domainSet.isEmpty { + // Get the safelist domain array as a JSON fragment that can be inserted at the end of a blocklist. + func safelistAsJSON() -> String { + if safelistedDomains.domainSet.isEmpty { return "" } // Note that * is added to the front of domains, so foo.com becomes *foo.com - let list = "'*" + whitelistedDomains.domainSet.joined(separator: "','*") + "'" + let list = "'*" + safelistedDomains.domainSet.joined(separator: "','*") + "'" return ", {'action': { 'type': 'ignore-previous-rules' }, 'trigger': { 'url-filter': '.*', 'if-domain': [\(list)] }}".replacingOccurrences(of: "'", with: "\"") } - func whitelist(enable: Bool, url: URL, completion: (() -> Void)?) { - guard let domain = whitelistableDomain(fromUrl: url) else { return } + func safelist(enable: Bool, url: URL, completion: (() -> Void)?) { + guard let domain = safelistableDomain(fromUrl: url) else { return } if enable { - whitelistedDomains.domainSet.insert(domain) + safelistedDomains.domainSet.insert(domain) } else { - whitelistedDomains.domainSet.remove(domain) + safelistedDomains.domainSet.remove(domain) } - updateWhitelist(completion: completion) + updateSafelist(completion: completion) } - func clearWhitelist(completion: (() -> Void)?) { - whitelistedDomains.domainSet = Set() - updateWhitelist(completion: completion) + func clearSafelist(completion: (() -> Void)?) { + safelistedDomains.domainSet = Set() + updateSafelist(completion: completion) } - private func updateWhitelist(completion: (() -> Void)?) { + private func updateSafelist(completion: (() -> Void)?) { removeAllRulesInStore { self.compileListsNotInStore { completion?() @@ -59,36 +59,36 @@ extension ContentBlocker { } } - guard let fileURL = whitelistFileURL() else { return } - if whitelistedDomains.domainSet.isEmpty { + guard let fileURL = safelistFileURL() else { return } + if safelistedDomains.domainSet.isEmpty { try? FileManager.default.removeItem(at: fileURL) return } - let list = whitelistedDomains.domainSet.joined(separator: "\n") + let list = safelistedDomains.domainSet.joined(separator: "\n") do { try list.write(to: fileURL, atomically: true, encoding: .utf8) } catch { - print("Failed to save whitelist file: \(error)") + print("Failed to save safelist file: \(error)") } } - // Ensure domains used for whitelisting are standardized by using this function. - func whitelistableDomain(fromUrl url: URL) -> String? { + // Ensure domains used for safelisting are standardized by using this function. + func safelistableDomain(fromUrl url: URL) -> String? { guard let domain = url.host, !domain.isEmpty else { return nil } return domain } - func isWhitelisted(url: URL) -> Bool { - guard let domain = whitelistableDomain(fromUrl: url) else { + func isSafelisted(url: URL) -> Bool { + guard let domain = safelistableDomain(fromUrl: url) else { return false } - return whitelistedDomains.domainSet.contains(domain) + return safelistedDomains.domainSet.contains(domain) } - func readWhitelistFile() -> [String]? { - guard let fileURL = whitelistFileURL() else { return nil } + func readSafelistFile() -> [String]? { + guard let fileURL = safelistFileURL() else { return nil } let text = try? String(contentsOf: fileURL, encoding: .utf8) if let text = text, !text.isEmpty { return text.components(separatedBy: .newlines) diff --git a/content-blocker-lib-ios/src/ContentBlocker.swift b/content-blocker-lib-ios/src/ContentBlocker.swift index 5e46c1940788..3e82ba4455e5 100644 --- a/content-blocker-lib-ios/src/ContentBlocker.swift +++ b/content-blocker-lib-ios/src/ContentBlocker.swift @@ -52,10 +52,10 @@ enum BlocklistFileName: String, CaseIterable { } enum BlockerStatus: String { - case Disabled - case NoBlockedURLs // When TP is enabled but nothing is being blocked - case Whitelisted - case Blocking + case disabled + case noBlockedURLs // When TP is enabled but nothing is being blocked + case safelisted + case blocking } struct NoImageModeDefaults { @@ -64,7 +64,7 @@ struct NoImageModeDefaults { } class ContentBlocker { - var whitelistedDomains = WhitelistedDomains() + var safelistedDomains = SafelistedDomains() let ruleStore: WKContentRuleListStore = WKContentRuleListStore.default() var blockImagesRule: WKContentRuleList? var setupCompleted = false @@ -78,9 +78,9 @@ class ContentBlocker { self.blockImagesRule = rule } - // Read the whitelist at startup - if let list = readWhitelistFile() { - whitelistedDomains.domainSet = Set(list) + // Read the safelist at startup + if let list = readSafelistFile() { + safelistedDomains.domainSet = Set(list) } TPStatsBlocklistChecker.shared.startup() @@ -283,7 +283,7 @@ extension ContentBlocker { self.loadJsonFromBundle(forResource: filename) { jsonString in var str = jsonString guard let range = str.range(of: "]", options: String.CompareOptions.backwards) else { return } - str = str.replacingCharacters(in: range, with: self.whitelistAsJSON() + "]") + str = str.replacingCharacters(in: range, with: self.safelistAsJSON() + "]") self.ruleStore.compileContentRuleList(forIdentifier: filename, encodedContentRuleList: str) { rule, error in if let error = error { print("Content blocker error: \(error)") diff --git a/content-blocker-lib-ios/src/TabContentBlocker+ContentScript.swift b/content-blocker-lib-ios/src/TabContentBlocker+ContentScript.swift index d4e9e644b1d4..55bcb2cffe19 100644 --- a/content-blocker-lib-ios/src/TabContentBlocker+ContentScript.swift +++ b/content-blocker-lib-ios/src/TabContentBlocker+ContentScript.swift @@ -19,7 +19,7 @@ extension TabContentBlocker { } // Reset the pageStats to make sure the trackingprotection shield icon knows that a page was whitelisted - guard !ContentBlocker.shared.isWhitelisted(url: mainDocumentUrl) else { + guard !ContentBlocker.shared.isSafelisted(url: mainDocumentUrl) else { clearPageStats() return } diff --git a/content-blocker-lib-ios/src/TabContentBlocker.swift b/content-blocker-lib-ios/src/TabContentBlocker.swift index f144e87977d6..683fa8734bcb 100644 --- a/content-blocker-lib-ios/src/TabContentBlocker.swift +++ b/content-blocker-lib-ios/src/TabContentBlocker.swift @@ -32,19 +32,19 @@ class TabContentBlocker { var status: BlockerStatus { guard isEnabled else { - return .Disabled + return .disabled } guard let url = tab?.currentURL() else { - return .NoBlockedURLs + return .noBlockedURLs } - if ContentBlocker.shared.isWhitelisted(url: url) { - return .Whitelisted + if ContentBlocker.shared.isSafelisted(url: url) { + return .safelisted } if stats.total == 0 { - return .NoBlockedURLs + return .noBlockedURLs } else { - return .Blocking + return .blocking } } diff --git a/content-blocker-lib-ios/src/TrackingProtectionPageStats.swift b/content-blocker-lib-ios/src/TrackingProtectionPageStats.swift index 6bd315d94241..a78bd87ad358 100644 --- a/content-blocker-lib-ios/src/TrackingProtectionPageStats.swift +++ b/content-blocker-lib-ios/src/TrackingProtectionPageStats.swift @@ -50,11 +50,11 @@ class TPStatsBlocklistChecker { } // Make a copy on the main thread - let whitelistRegex = ContentBlocker.shared.whitelistedDomains.domainRegex + let safelistRegex = ContentBlocker.shared.safelistedDomains.domainRegex DispatchQueue.global().async { // Return true in the Deferred if the domain could potentially be blocked - deferred.fill(blockLists.urlIsInList(url, mainDocumentURL: mainDocumentURL, whitelistedDomains: whitelistRegex)) + deferred.fill(blockLists.urlIsInList(url, mainDocumentURL: mainDocumentURL, safelistedDomains: safelistRegex)) } return deferred } @@ -189,7 +189,7 @@ class TPStatsBlocklists { } } - func urlIsInList(_ url: URL, mainDocumentURL: URL, whitelistedDomains: [String]) -> BlocklistCategory? { + func urlIsInList(_ url: URL, mainDocumentURL: URL, safelistedDomains: [String]) -> BlocklistCategory? { let resourceString = url.absoluteString guard let firstPartyDomain = mainDocumentURL.baseDomain, let baseDomain = url.baseDomain, let rules = blockRules[baseDomain] else { @@ -207,8 +207,8 @@ class TPStatsBlocklists { } // Check the whitelist. - if let baseDomain = url.baseDomain, !whitelistedDomains.isEmpty { - for ignoreDomain in whitelistedDomains { + if let baseDomain = url.baseDomain, !safelistedDomains.isEmpty { + for ignoreDomain in safelistedDomains { if baseDomain.range(of: ignoreDomain, options: .regularExpression) != nil { return nil }