Skip to content

Commit

Permalink
[nobug, cleanup] Rename blacklist to blocklist (#6783)
Browse files Browse the repository at this point in the history
* [nobug, cleanup] Rename blacklist to blocklist
* rename whitelist to safelist
  • Loading branch information
garvankeeley authored Jun 11, 2020
1 parent c7a498f commit 7819c1b
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 95 deletions.
8 changes: 4 additions & 4 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1851,7 +1851,7 @@
EBB894F5219398E500EB91A0 /* TrackingProtectionPageStats.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackingProtectionPageStats.swift; sourceTree = "<group>"; };
EBB894F7219398E500EB91A0 /* TabContentBlocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabContentBlocker.swift; sourceTree = "<group>"; };
EBB894F8219398E500EB91A0 /* ContentBlocker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlocker.swift; sourceTree = "<group>"; };
EBB894F9219398E500EB91A0 /* ContentBlocker+Whitelist.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ContentBlocker+Whitelist.swift"; sourceTree = "<group>"; };
EBB894F9219398E500EB91A0 /* ContentBlocker+Safelist.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ContentBlocker+Safelist.swift"; sourceTree = "<group>"; };
EBB894FA219398E500EB91A0 /* TabContentBlocker+ContentScript.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TabContentBlocker+ContentScript.swift"; sourceTree = "<group>"; };
EBB8950B2193994A00EB91A0 /* FirefoxTabContentBlocker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirefoxTabContentBlocker.swift; sourceTree = "<group>"; };
EBB895322193FFF400EB91A0 /* ContentBlockerSettingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlockerSettingViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */,
Expand Down
2 changes: 1 addition & 1 deletion Client/Application/LeanplumIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion Client/Application/WebServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [:])
Expand Down
8 changes: 4 additions & 4 deletions Client/Frontend/Browser/TabLocationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion Client/Frontend/Settings/Clearables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Client/Frontend/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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 []
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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]]
}
}

2 changes: 1 addition & 1 deletion Client/Telemetry/UnifiedTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions ClientTests/TPStatsBlocklistsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let fallbackPath: String = (#file as NSString).deletingLastPathComponent + "/../
// We expect this command to be executed as 'cd <dir of swift package>; 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"

Expand All @@ -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]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import XCTest
@testable import ContentBlockerGenLib

let blacklist = """
let blocklist = """
{
"license": "Copyright 2010-2019 Disconnect, Inc.",
"categories": {
Expand All @@ -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]()
Expand Down
Loading

0 comments on commit 7819c1b

Please sign in to comment.