Skip to content

Commit

Permalink
Merge branch 'main' into daniel/private-email-autofill
Browse files Browse the repository at this point in the history
# Conflicts:
#	Sources/BrowserServicesKit/SecureVault/SecureVaultManager.swift
  • Loading branch information
afterxleep committed Aug 2, 2023
2 parents a5d33aa + 289d6fe commit 5206c6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/BrowserServicesKit/SecureVault/SecureVaultManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,26 @@ extension SecureVaultManager: AutofillSecureVaultDelegate {

private func existingCredentials(with autofillData: AutofillUserScript.DetectedAutofillData,
domain: String,
automaticallySavedCredentials: Bool,
shouldSilentlySave: Bool,
vault: any AutofillSecureVault) throws -> SecureVaultModels.WebsiteCredentials? {
if let credentials = autofillData.credentials, let passwordData = credentials.password.data(using: .utf8) {
let accounts = try vault.accountsFor(domain: domain)
if let account = accounts.first(where: { $0.username == credentials.username ?? "" }) {
if let existingAccountID = account.id,
let existingCredentials = try vault.websiteCredentialsFor(accountId: existingAccountID),
existingCredentials.password == passwordData {
if automaticallySavedCredentials || shouldSilentlySave {
os_log("Found duplicate credentials which were just saved, notifying user", log: .passwordManager)
return SecureVaultModels.WebsiteCredentials(account: account, password: passwordData)
} else {
os_log("Found duplicate credentials which were previously saved, avoid notifying user", log: .passwordManager)
return nil
}
} else {
os_log("Found existing credentials to update", log: .passwordManager)
return SecureVaultModels.WebsiteCredentials(account: account, password: passwordData)
}

guard let credentials = autofillData.credentials,
let passwordData = credentials.password?.data(using: .utf8) else {
Expand Down Expand Up @@ -712,6 +731,7 @@ extension SecureVaultManager: AutofillSecureVaultDelegate {

private func existingCredentialsInPasswordManager(with autofillData: AutofillUserScript.DetectedAutofillData,
domain: String,
automaticallySavedCredentials: Bool,
vault: any AutofillSecureVault) -> SecureVaultModels.WebsiteCredentials? {
guard let passwordManager = passwordManager, passwordManager.isEnabled else {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ private class MockSecureVaultManagerDelegate: SecureVaultManagerDelegate {
true
}

func secureVaultManagerShouldSaveData(_: BrowserServicesKit.SecureVaultManager) -> Bool {
true
}

func secureVaultManager(_: SecureVaultManager, didRequestCreditCardsManagerForDomain domain: String) {}

func secureVaultManager(_: SecureVaultManager, didRequestIdentitiesManagerForDomain domain: String) {}
Expand Down

0 comments on commit 5206c6d

Please sign in to comment.