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

Commit

Permalink
Fixed clearing of all tabs and data when switching to private-browsin…
Browse files Browse the repository at this point in the history
…g-only.

Fixes #580
  • Loading branch information
Brandon-T committed Nov 6, 2019
1 parent 0910207 commit 87c7500
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ extension Strings {
public static let Private_Tab_Body = NSLocalizedString("PrivateTabBody", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Private Tabs aren’t saved in Brave, but they don’t make you anonymous online. Sites you visit in a private tab won’t show up in your history and their cookies always vanish when you close them — there won’t be any trace of them left in Brave. However, downloads will be saved.\nYour mobile carrier (or the owner of the WiFi network or VPN you’re connected to) can see which sites you visit and those sites will learn your public IP address, even in Private Tabs.", comment: "Private tab details")
public static let Private_Tab_Details = NSLocalizedString("PrivateTabDetails", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Using Private Tabs only changes what Brave does on your device, it doesn't change anyone else's behavior.\n\nSites always learn your IP address when you visit them. From this, they can often guess roughly where you are — typically your city. Sometimes that location guess can be much more specific. Sites also know everything you specifically tell them, such as search terms. If you log into a site, they'll know you're the owner of that account. You'll still be logged out when you close the Private Tabs because Brave will throw away the cookie which keeps you logged in.\n\nWhoever connects you to the Internet (your ISP) can see all of your network activity. Often, this is your mobile carrier. If you're connected to a WiFi network, this is the owner of that network, and if you're using a VPN, then it's whoever runs that VPN. Your ISP can see which sites you visit as you visit them. If those sites use HTTPS, they can't make much more than an educated guess about what you do on those sites. But if a site only uses HTTP then your ISP can see everything: your search terms, which pages you read, and which links you follow.\n\nIf an employer manages your device, they might also keep track of what you do with it. Using Private Tabs probably won't stop them from knowing which sites you've visited. Someone else with access to your device could also have installed software which monitors your activity, and Private Tabs won't protect you from this either.", comment: "Private tab detail text")
public static let Private_Tab_Link = NSLocalizedString("PrivateTabLink", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Learn about private tabs.", comment: "Private tab information link")
public static let Private_Browsing_Only_Warning = NSLocalizedString("PrivateBrowsingOnlyWarning", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Private Browsing Only mode will close all your current tabs and log you out of all sites.", comment: "When 'Private Browsing Only' is enabled, we need to alert the user of their normal tabs being destroyed")
public static let Brave_Panel = NSLocalizedString("BravePanel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Brave Panel", comment: "Button to show the brave panel")
public static let RewardsPanel = NSLocalizedString("RewardsPanel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Rewards Panel", comment: "Button to show the rewards panel")
public static let Individual_Controls = NSLocalizedString("IndividualControls", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Individual Controls", comment: "title for per-site shield toggles")
Expand Down
47 changes: 36 additions & 11 deletions Client/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,23 +293,48 @@ class SettingsViewController: TableViewController {
BoolRow(
title: Strings.Private_Browsing_Only,
option: Preferences.Privacy.privateBrowsingOnly,
onValueChange: {
Preferences.Privacy.privateBrowsingOnly.value = $0

// Need to flush the table, hacky, but works consistenly and well
let superView = self.tableView.superview
self.tableView.removeFromSuperview()
DispatchQueue.main.async {
// Let shield toggle change propagate, otherwise theme may not be set properly
superView?.addSubview(self.tableView)
self.applyTheme(self.theme)
onValueChange: { value in

if value {
let alert = UIAlertController(title: Strings.Private_Browsing_Only, message: Strings.Private_Browsing_Only_Warning, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: { _ in
DispatchQueue.main.async {
self.toggleSwitch(on: false, section: self.privacySection, rowUUID: Preferences.Privacy.privateBrowsingOnly.key)
}
}))

alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: { _ in
Preferences.Privacy.privateBrowsingOnly.value = value

// Need to flush the table, hacky, but works consistenly and well
let superView = self.tableView.superview
self.tableView.removeFromSuperview()
DispatchQueue.main.async {
// Let shield toggle change propagate, otherwise theme may not be set properly
superView?.addSubview(self.tableView)
self.applyTheme(self.theme)
}
}))

self.present(alert, animated: true, completion: nil)
} else {
Preferences.Privacy.privateBrowsingOnly.value = value

// Need to flush the table, hacky, but works consistenly and well
let superView = self.tableView.superview
self.tableView.removeFromSuperview()
DispatchQueue.main.async {
// Let shield toggle change propagate, otherwise theme may not be set properly
superView?.addSubview(self.tableView)
self.applyTheme(self.theme)
}
}
}
)
)
return privacy
}()

private lazy var securitySection: Section = {
let passcodeTitle: String = {
let localAuthContext = LAContext()
Expand Down
7 changes: 5 additions & 2 deletions Data/models/TabMO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ public final class TabMO: NSManagedObject, CRUD {
deleteAll(context: .new(inMemory: false))
}

public class func deleteAllNormalTabs() {
deleteAll(predicate: NSPredicate(format: "isPrivate != true"), context: .new(inMemory: false))
}

public class func deleteAllPrivateTabs() {
deleteAll(predicate: NSPredicate(format: "isPrivate == true"), context: .new(inMemory: false))
}

}
}

// MARK: - Internal implementations
extension TabMO {
Expand Down

0 comments on commit 87c7500

Please sign in to comment.