Skip to content

Commit

Permalink
Add FXIOS-9649 - Password Generator: Use strong password keyboard but…
Browse files Browse the repository at this point in the history
…ton (#22635)

* Completed ticket

* Addressed Comments
  • Loading branch information
DanielDervishi authored Oct 21, 2024
1 parent 410a40f commit 0a7ce9e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
26 changes: 24 additions & 2 deletions firefox-ios/Client/AccessoryViewProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Common
import Shared

enum AccessoryType {
case standard, creditCard, address, login
case standard, creditCard, address, login, passwordGenerator
}

class AccessoryViewProvider: UIView, Themeable, InjectedThemeUUIDIdentifiable {
Expand Down Expand Up @@ -35,6 +35,7 @@ class AccessoryViewProvider: UIView, Themeable, InjectedThemeUUIDIdentifiable {
var savedCardsClosure: (() -> Void)?
var savedAddressesClosure: (() -> Void)?
var savedLoginsClosure: (() -> Void)?
var useStrongPasswordClosure: (() -> Void)?

// MARK: - UI Elements
private let toolbar: UIToolbar = .build {
Expand Down Expand Up @@ -127,6 +128,20 @@ class AccessoryViewProvider: UIView, Themeable, InjectedThemeUUIDIdentifiable {
return accessoryView
}()

private lazy var passwordGeneratorView: AutofillAccessoryViewButtonItem = {
let accessoryView = AutofillAccessoryViewButtonItem(
image: UIImage(named: StandardImageIdentifiers.Large.login),
labelText: .PasswordGenerator.KeyboardAccessoryButtonLabel,
tappedAction: { [weak self] in
self?.tappedUseStrongPasswordButton()
})
accessoryView.accessibilityTraits = .button
accessoryView.accessibilityLabel = .PasswordAutofill.UseSavedPasswordFromKeyboard
accessoryView.accessibilityIdentifier = AccessibilityIdentifiers.Autofill.footerPrimaryAction
accessoryView.isAccessibilityElement = true
return accessoryView
}()

// MARK: - Initialization
init(themeManager: ThemeManager = AppContainer.shared.resolve(),
windowUUID: WindowUUID,
Expand Down Expand Up @@ -169,6 +184,8 @@ class AccessoryViewProvider: UIView, Themeable, InjectedThemeUUIDIdentifiable {
currentAccessoryView = addressAutofillView
case .login:
currentAccessoryView = loginAutofillView
case .passwordGenerator:
currentAccessoryView = passwordGeneratorView
}

setNeedsLayout()
Expand Down Expand Up @@ -224,7 +241,7 @@ class AccessoryViewProvider: UIView, Themeable, InjectedThemeUUIDIdentifiable {
$0.customView?.tintColor = theme.colors.iconAccentBlue
}

[creditCardAutofillView, addressAutofillView, loginAutofillView].forEach {
[creditCardAutofillView, addressAutofillView, loginAutofillView, passwordGeneratorView].forEach {
$0.accessoryImageViewTintColor = theme.colors.iconPrimary
$0.backgroundColor = theme.colors.layer5Hover
}
Expand Down Expand Up @@ -262,6 +279,11 @@ class AccessoryViewProvider: UIView, Themeable, InjectedThemeUUIDIdentifiable {
savedLoginsClosure?()
}

@objc
private func tappedUseStrongPasswordButton() {
useStrongPasswordClosure?()
}

// MARK: - Telemetry
fileprivate func sendCreditCardAutofillPromptShownTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ class PasswordGeneratorViewController: UIViewController, StoreSubscriber, Themea
}

extension PasswordGeneratorViewController: BottomSheetChild {
func willDismiss() { }
func willDismiss() { currentTab.webView?.accessoryView.reloadViewFor(.standard)}
}
20 changes: 16 additions & 4 deletions firefox-ios/Client/Frontend/TabContentsScripts/LoginsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class LoginsHelper: TabContentScript, FeatureFlaggable {

public var foundFieldValues: ((FocusFieldType, String) -> Void)?

public var passwordFieldInteraction: (() -> Void)?

// Exposed for mocking purposes
var logins: RustLogins {
return profile.logins
Expand Down Expand Up @@ -126,10 +128,20 @@ class LoginsHelper: TabContentScript, FeatureFlaggable {

if self.featureFlags.isFeatureEnabled(.passwordGenerator, checking: .buildOnly) {
if type == "generatePassword", let tab = self.tab, !tab.isPrivate {
let newAction = GeneralBrowserAction(
windowUUID: tab.windowUUID,
actionType: GeneralBrowserActionType.showPasswordGenerator)
store.dispatch(newAction)
let userDefaults = UserDefaults.standard
let showPasswordGeneratorClosure = {
let newAction = GeneralBrowserAction(
windowUUID: tab.windowUUID,
actionType: GeneralBrowserActionType.showPasswordGenerator)
store.dispatch(newAction)
}
if userDefaults.value(forKey: PrefsKeys.PasswordGeneratorShown) == nil {
userDefaults.set(true, forKey: PrefsKeys.PasswordGeneratorShown)
showPasswordGeneratorClosure()
} else {
tab.webView?.accessoryView.useStrongPasswordClosure = showPasswordGeneratorClosure
tab.webView?.accessoryView.reloadViewFor(.passwordGenerator)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions firefox-ios/Shared/Prefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public struct PrefsKeys {

// Used to show splash screen only during first time on fresh install
public static let splashScreenShownKey = "splashScreenShownKey"

public static let PasswordGeneratorShown = "PasswordGeneratorShown"
}

public protocol Prefs {
Expand Down

0 comments on commit 0a7ce9e

Please sign in to comment.