Skip to content

Commit

Permalink
Autofill "Never Save for this Site" support for iOS (#1827)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1205783642285427/f
Tech Design URL:
CC:

Description:
BSK update to support "Never Save for this Site" on iOS including support for getRuntimeConfiguration
  • Loading branch information
amddg44 authored Nov 16, 2023
1 parent c861ba9 commit 70fbdec
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14431,7 +14431,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 84.0.1;
version = 84.1.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "075773533bfca9196115674d2ab1b085570854dd",
"version" : "84.0.1"
"revision" : "641018cef1a3a13e9fdeb490b18639d1cb25569f",
"version" : "84.1.0"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "c8e895c8fd50dc76e8d8dc827a636ad77b7f46ff",
"version" : "9.0.0"
"revision" : "93677cc02cfe650ce7f417246afd0e8e972cd83e",
"version" : "10.0.0"
}
},
{
Expand Down
15 changes: 15 additions & 0 deletions DuckDuckGo/Autofill/ContentOverlayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class ContentOverlayViewController: NSViewController, EmailManagerR

lazy var passwordManagerCoordinator: PasswordManagerCoordinating = PasswordManagerCoordinator.shared

lazy var privacyConfigurationManager: PrivacyConfigurationManaging = AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager

public override func viewDidLoad() {
initWebView()
addTrackingArea()
Expand Down Expand Up @@ -339,4 +341,17 @@ extension ContentOverlayViewController: SecureVaultManagerDelegate {
autofillPreferencesModel.showAutofillPopover(.logins)
}
}

public func secureVaultManager(_: SecureVaultManager, didRequestRuntimeConfigurationForDomain domain: String, completionHandler: @escaping (String?) -> Void) {
let properties = ContentScopeProperties(gpcEnabled: PrivacySecurityPreferences.shared.gpcEnabled,
sessionKey: topAutofillUserScript?.sessionKey ?? "",
featureToggles: ContentScopeFeatureToggles.supportedFeaturesOnMacOS(privacyConfigurationManager.privacyConfig))

let runtimeConfiguration = DefaultAutofillSourceProvider.Builder(privacyConfigurationManager: privacyConfigurationManager,
properties: properties)
.build()
.buildRuntimeConfigResponse()

completionHandler(runtimeConfiguration)
}
}
10 changes: 6 additions & 4 deletions DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ struct ScriptSourceProvider: ScriptSourceProviding {

public func buildAutofillSource() -> AutofillUserScriptSourceProvider {
let privacyConfig = self.privacyConfigurationManager.privacyConfig
return DefaultAutofillSourceProvider(privacyConfigurationManager: self.privacyConfigurationManager,
properties: ContentScopeProperties(gpcEnabled: privacySettings.gpcEnabled,
sessionKey: self.sessionKey ?? "",
featureToggles: ContentScopeFeatureToggles.supportedFeaturesOnMacOS(privacyConfig)))
return DefaultAutofillSourceProvider.Builder(privacyConfigurationManager: privacyConfigurationManager,
properties: ContentScopeProperties(gpcEnabled: privacySettings.gpcEnabled,
sessionKey: self.sessionKey ?? "",
featureToggles: ContentScopeFeatureToggles.supportedFeaturesOnMacOS(privacyConfig)))
.withJSLoading()
.build()
}

private func buildContentBlockerRulesConfig() -> ContentBlockerUserScriptConfig {
Expand Down
24 changes: 24 additions & 0 deletions DuckDuckGo/Tab/TabExtensions/AutofillTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ final class AutofillTabExtension: TabExtension {
autofillScript?.currentOverlayTab = self.delegate
}
}
private lazy var cachedRuntimeConfigurationForDomain: [String: String?] = [:]

private var emailManager: AutofillEmailDelegate?
private var vaultManager: AutofillSecureVaultDelegate?
private var passwordManagerCoordinator: PasswordManagerCoordinating = PasswordManagerCoordinator.shared
private let privacyConfigurationManager: PrivacyConfigurationManaging = AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager
private let isBurner: Bool

@Published var autofillDataToSave: AutofillData?
Expand Down Expand Up @@ -178,6 +181,27 @@ extension AutofillTabExtension: SecureVaultManagerDelegate {
func secureVaultManager(_: SecureVaultManager, didRequestPasswordManagerForDomain domain: String) {
// no-op
}

func secureVaultManager(_: SecureVaultManager, didRequestRuntimeConfigurationForDomain domain: String, completionHandler: @escaping (String?) -> Void) {
if let runtimeConfigurationForDomain = cachedRuntimeConfigurationForDomain[domain] as? String {
completionHandler(runtimeConfigurationForDomain)
return
}
let runtimeConfiguration = DefaultAutofillSourceProvider.Builder(privacyConfigurationManager: privacyConfigurationManager,
properties: buildContentScopePropertiesForDomain(domain))
.build()
.buildRuntimeConfigResponse()

cachedRuntimeConfigurationForDomain = [domain: runtimeConfiguration]
completionHandler(runtimeConfiguration)
}

private func buildContentScopePropertiesForDomain(_ domain: String) -> ContentScopeProperties {
return ContentScopeProperties(gpcEnabled: PrivacySecurityPreferences.shared.gpcEnabled,
sessionKey: autofillScript?.sessionKey ?? "",
featureToggles: ContentScopeFeatureToggles.supportedFeaturesOnMacOS(privacyConfigurationManager.privacyConfig)
)
}
}

extension AutofillType {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/Account/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["Account"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "84.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "84.1.0"),
.package(path: "../Purchase")
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "84.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "84.1.0"),
.package(path: "../PixelKit"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper")
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "84.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "84.1.0"),
.package(path: "../XPCHelper"),
.package(path: "../SwiftUIExtensions")
],
Expand Down
53 changes: 53 additions & 0 deletions UnitTests/DataExport/MockSecureVault.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class MockSecureVault<T: AutofillDatabaseProvider>: AutofillSecureVault {

var storedAccounts: [SecureVaultModels.WebsiteAccount] = []
var storedCredentials: [Int64: SecureVaultModels.WebsiteCredentials] = [:]
var storedNeverPromptWebsites = [SecureVaultModels.NeverPromptWebsites]()
var storedNotes: [SecureVaultModels.Note] = []
var storedIdentities: [SecureVaultModels.Identity] = []
var storedCards: [SecureVaultModels.CreditCard] = []
Expand Down Expand Up @@ -80,6 +81,29 @@ final class MockSecureVault<T: AutofillDatabaseProvider>: AutofillSecureVault {
storedCredentials[accountId] = nil
}

func neverPromptWebsites() throws -> [SecureVaultModels.NeverPromptWebsites] {
return storedNeverPromptWebsites
}

func hasNeverPromptWebsitesFor(domain: String) throws -> Bool {
return !storedNeverPromptWebsites.filter { $0.domain == domain }.isEmpty
}

func storeNeverPromptWebsites(_ neverPromptWebsite: SecureVaultModels.NeverPromptWebsites) throws -> Int64 {
if let neverPromptWebsiteId = neverPromptWebsite.id {
storedNeverPromptWebsites.append(neverPromptWebsite)
return neverPromptWebsiteId
} else {
storedNeverPromptWebsites.append(neverPromptWebsite)
return -1
}

}

func deleteAllNeverPromptWebsites() throws {
storedNeverPromptWebsites = []
}

func notes() throws -> [SecureVaultModels.Note] {
return storedNotes
}
Expand Down Expand Up @@ -210,6 +234,8 @@ class MockDatabaseProvider: AutofillDatabaseProvider {
var _forDomain = [String]()
var _credentialsDict = [Int64: SecureVaultModels.WebsiteCredentials]()
var _note: SecureVaultModels.Note?
var _neverPromptWebsites = [SecureVaultModels.NeverPromptWebsites]()

var db: GRDB.DatabaseWriter
// swiftlint:enable identifier_name

Expand Down Expand Up @@ -253,6 +279,33 @@ class MockDatabaseProvider: AutofillDatabaseProvider {
return _accounts
}

func neverPromptWebsites() throws -> [SecureVaultModels.NeverPromptWebsites] {
return _neverPromptWebsites
}

func hasNeverPromptWebsitesFor(domain: String) throws -> Bool {
return false
}

func storeNeverPromptWebsite(_ neverPromptWebsite: SecureVaultModels.NeverPromptWebsites) throws -> Int64 {
if let neverPromptWebsiteId = neverPromptWebsite.id {
_neverPromptWebsites.append(neverPromptWebsite)
return neverPromptWebsiteId
} else {
return -1
}
}

func deleteAllNeverPromptWebsites() throws {
_neverPromptWebsites.removeAll()
}

func updateNeverPromptWebsite(_ neverPromptWebsite: SecureVaultModels.NeverPromptWebsites) throws {
}

func insertNeverPromptWebsite(_ neverPromptWebsite: SecureVaultModels.NeverPromptWebsites) throws {
}

func notes() throws -> [SecureVaultModels.Note] {
return _notes
}
Expand Down

0 comments on commit 70fbdec

Please sign in to comment.