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

Commit

Permalink
Localization and preferences setting for private browsing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Aug 2, 2023
1 parent 037a3d2 commit a685ad9
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class TabTrayController: AuthenticationController {
var tabTrayMode: TabTrayMode = .local
private var privateModeCancellable: AnyCancellable?
private var initialScrollCompleted = false
private var localAuthObservers = Set<AnyCancellable>()

// MARK: User Interface Elements

Expand Down Expand Up @@ -188,7 +189,7 @@ class TabTrayController: AuthenticationController {
self.tabManager = tabManager
self.braveCore = braveCore

super.init(windowProtection: windowProtection)
super.init(windowProtection: windowProtection, isCancellable: true)

if !UIAccessibility.isReduceMotionEnabled {
transitioningDelegate = self
Expand Down Expand Up @@ -302,6 +303,11 @@ class TabTrayController: AuthenticationController {
.sink(receiveValue: { [weak self] isPrivateBrowsing in
self?.updateColors(isPrivateBrowsing)
})

windowProtection?.cancelPressed
.sink { [weak self] _ in
self?.navigationController?.popViewController(animated: true)
}.store(in: &localAuthObservers)

reloadOpenTabsSession()

Expand Down Expand Up @@ -585,6 +591,14 @@ class TabTrayController: AuthenticationController {
}

@objc func togglePrivateModeAction() {
if !privateMode, Preferences.Privacy.privateBrowsingLock.value {
askForAuthentication(viewType: .tabTray)
} else {
toggleModeChanger()
}
}

func toggleModeChanger() {
tabTraySearchController.isActive = false

// Mode Change action disabled while drap-drop is active
Expand Down Expand Up @@ -622,7 +636,6 @@ class TabTrayController: AuthenticationController {

navigationController?.setNavigationBarHidden(privateMode, animated: false)
tabTypeSelector.isHidden = privateMode

}

func remove(tab: Tab) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Brave/Frontend/ClientPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ extension Preferences {

final public class Privacy {
static let lockWithPasscode = Option<Bool>(key: "privacy.lock-with-passcode", default: false)
static let privateBrowsingLock = Option<Bool>(key: "privacy.private-browsing-lock", default: false)
/// Forces all private tabs
public static let privateBrowsingOnly = Option<Bool>(key: "privacy.private-only", default: false)
/// Blocks all cookies and access to local storage
Expand Down
9 changes: 8 additions & 1 deletion Sources/Brave/Frontend/Passcode/WindowProtection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ public class WindowProtection {
}

private let onCancelPressed = PassthroughSubject<Void, Never>()

private let didFinalizeAuthentication = PassthroughSubject<Bool, Never>()

var cancelPressed: AnyPublisher<Void, Never> {
onCancelPressed.eraseToAnyPublisher()
}

var finalizedAuthentication: AnyPublisher<Bool, Never> {
didFinalizeAuthentication.eraseToAnyPublisher()
}

public init?(window: UIWindow) {
guard let scene = window.windowScene else { return nil }
protectedWindow = window
Expand Down Expand Up @@ -208,6 +213,8 @@ public class WindowProtection {
Logger.module.error("Failed to unlock browser using local authentication: \(error.localizedDescription)")
}
}

self.didFinalizeAuthentication.send(success)
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion Sources/Brave/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,16 @@ class SettingsViewController: TableViewController {
return Section(
header: .title(Strings.security),
rows: [
.boolRow(title: Strings.browserLock, detailText: Strings.browserLockDescription, option: Preferences.Privacy.lockWithPasscode, image: UIImage(braveSystemNamed: "leo.biometric.login")),
.boolRow(
title: Strings.Privacy.browserLock,
detailText: Strings.Privacy.browserLockDescription,
option: Preferences.Privacy.lockWithPasscode,
image: UIImage(braveSystemNamed: "leo.biometric.login")),
.boolRow(
title: Strings.Privacy.privateBrowsingLock,
detailText: Strings.Privacy.privateBrowsingLockDescription,
option: Preferences.Privacy.privateBrowsingLock,
image: UIImage(braveSystemNamed: "leo.lock")),
Row(
text: Strings.Login.loginListNavigationTitle,
selection: { [unowned self] in
Expand Down
1 change: 0 additions & 1 deletion Sources/Brave/Frontend/Sync/SyncViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SyncViewController: AuthenticationController {
isAuthenticationCancellable: Bool = true,
isModallyPresented: Bool = false) {
self.isModallyPresented = isModallyPresented

super.init(windowProtection: windowProtection, requiresAuthentication: requiresAuthentication)

windowProtection?.isCancellable = isAuthenticationCancellable
Expand Down
17 changes: 12 additions & 5 deletions Sources/Brave/Frontend/Widgets/LoadingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,24 @@ public class LoadingViewController: UIViewController {
}

public class AuthenticationController: LoadingViewController {
enum AuthViewType {
case sync, tabTray
}

let windowProtection: WindowProtection?
let requiresAuthentication: Bool

// MARK: Lifecycle

init(windowProtection: WindowProtection? = nil,
requiresAuthentication: Bool = false) {
requiresAuthentication: Bool = false,
isCancellable: Bool = false) {
self.windowProtection = windowProtection
self.requiresAuthentication = requiresAuthentication

super.init(nibName: nil, bundle: nil)

self.windowProtection?.isCancellable = isCancellable
}

required init?(coder: NSCoder) {
Expand All @@ -54,14 +61,14 @@ public class AuthenticationController: LoadingViewController {

/// A method to ask biometric authentication to user
/// - Parameter completion: block returning authentication status
func askForAuthentication(completion: ((Bool, LAError.Code?) -> Void)? = nil) {
func askForAuthentication(viewType: AuthViewType = .sync, completion: ((Bool, LAError.Code?) -> Void)? = nil) {
guard let windowProtection = windowProtection else {
completion?(false, nil)
return
}

if !windowProtection.isPassCodeAvailable {
showSetPasscodeError() {
showSetPasscodeError(viewType: viewType) {
completion?(false, LAError.passcodeNotSet)
}
} else {
Expand All @@ -74,10 +81,10 @@ public class AuthenticationController: LoadingViewController {

/// An alert presenter for passcode error to warn user to setup passcode to use feature
/// - Parameter completion: block after Ok button is pressed
func showSetPasscodeError(completion: @escaping (() -> Void)) {
func showSetPasscodeError(viewType: AuthViewType, completion: @escaping (() -> Void)) {
let alert = UIAlertController(
title: Strings.Sync.syncSetPasscodeAlertTitle,
message: Strings.Sync.syncSetPasscodeAlertDescription,
message: viewType == .sync ? Strings.Sync.syncSetPasscodeAlertDescription : Strings.Privacy.tabTraySetPasscodeAlertDescription,
preferredStyle: .alert)

alert.addAction(
Expand Down
36 changes: 33 additions & 3 deletions Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,6 @@ extension Strings {
public static let confirm = NSLocalizedString("Confirm", tableName: "BraveShared", bundle: .module, value: "Confirm", comment: "")
public static let privacy = NSLocalizedString("Privacy", tableName: "BraveShared", bundle: .module, value: "Privacy", comment: "Settings privacy section title")
public static let security = NSLocalizedString("Security", tableName: "BraveShared", bundle: .module, value: "Security", comment: "Settings security section title")
public static let browserLock = NSLocalizedString("BrowserLock", tableName: "BraveShared", bundle: .module, value: "Browser Lock", comment: "Setting to enable the browser lock privacy feature")
public static let browserLockDescription = NSLocalizedString("BrowserLockDescription", tableName: "BraveShared", bundle: .module, value: "Unlock Brave with Touch ID, Face ID or system passcode.", comment: "")
public static let saveLogins = NSLocalizedString("SaveLogins", tableName: "BraveShared", bundle: .module, value: "Save Logins", comment: "Setting to enable the built-in password manager")
public static let showBookmarkButtonInTopToolbar = NSLocalizedString("ShowBookmarkButtonInTopToolbar", tableName: "BraveShared", bundle: .module, value: "Show Bookmarks Shortcut", comment: "Setting to show a bookmark button on the top level menu that triggers a panel of the user's bookmarks.")
public static let alwaysRequestDesktopSite = NSLocalizedString("AlwaysRequestDesktopSite", tableName: "BraveShared", bundle: .module, value: "Always Request Desktop Site", comment: "Setting to always request the desktop version of a website.")
Expand Down Expand Up @@ -3256,7 +3254,7 @@ extension Strings {
"login.syncSetPasscodeAlertDescription",
tableName: "BraveShared",
bundle: .module,
value: "To setup sync chain or see settings, you must first set a passcode on your device..",
value: "To setup sync chain or see settings, you must first set a passcode on your device.",
comment: "The message displayed in alert when a user needs to set a passcode")
}
}
Expand Down Expand Up @@ -3298,6 +3296,38 @@ extension Strings {
}
}

extension Strings {
public struct Privacy {
public static let browserLock =
NSLocalizedString(
"BrowserLock", tableName: "BraveShared", bundle: .module,
value: "Browser Lock",
comment: "Title for setting to enable the browser lock privacy feature")
public static let browserLockDescription =
NSLocalizedString(
"BrowserLockDescription", tableName: "BraveShared", bundle: .module,
value: "Unlock Brave with Touch ID, Face ID or system passcode.",
comment: "Description for setting to enable the browser lock privacy feature")
public static let privateBrowsingLock =
NSLocalizedString(
"privacy.private.browsing.lock.title", tableName: "BraveShared", bundle: .module,
value: "Private Browsing Lock",
comment: "Title for setting to enable the private browsing lock privacy feature")
public static let privateBrowsingLockDescription =
NSLocalizedString(
"privacy.private.browsing.lock.description", tableName: "BraveShared", bundle: .module,
value: "Require Passcode to Unlock Private Browsing",
comment: "Description for setting to enable the browser lock privacy feature")
public static let tabTraySetPasscodeAlertDescription =
NSLocalizedString(
"privacy.tab.tray.passcode.alert",
tableName: "BraveShared",
bundle: .module,
value: "To switch private browsing mode, you must first set a passcode on your device.",
comment: "The message displayed in alert when a user needs to set a passcode")
}
}

extension Strings {
public struct Login {
public static let loginListEmptyScreenTitle =
Expand Down

0 comments on commit a685ad9

Please sign in to comment.