-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Promote password import in autofill menu (#3220)
Task/Issue URL: https://app.asana.com/0/72649045549333/1207617229892922/f BSK PR: duckduckgo/BrowserServicesKit#976 **Description**: When adopting a new browser after a long time using something else, you expect your browser to have all your data. If you skipped import during onboarding you will find out about the missing data at the time when you're trying to use the password. This creates huge friction right in the middle of a task. See [Comment by Peter Dolanjski on Password and autofill issues](https://app.asana.com/0/0/1207533847538452/1207544369978642/f). Reminding users of the option to import right when that friction happens could be a way to quickly give recourse and solve the problem for all subsequent browsing needs. This feature promotes the import in autofill scenarios when the user has few or no passwords saved. **Steps to test this PR**: https://app.asana.com/0/72649045549333/1208245520043990/f **Definition of Done**: * [ ] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? --- ###### Internal references: [Pull Request Review Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f) [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) [Pull Request Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
- Loading branch information
Showing
16 changed files
with
276 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
DuckDuckGo/Autofill/AutofillCredentialsImportManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// AutofillCredentialsImportManager.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import PixelKit | ||
import BrowserServicesKit | ||
|
||
public protocol AutofillCredentialsImportPresentationDelegate: AnyObject { | ||
func autofillDidRequestCredentialsImportFlow(onFinished: @escaping () -> Void, onCancelled: @escaping () -> Void) | ||
} | ||
|
||
final public class AutofillCredentialsImportManager { | ||
private let userDefaults: UserDefaults | ||
|
||
weak var presentationDelegate: AutofillCredentialsImportPresentationDelegate? | ||
|
||
init(userDefaults: UserDefaults = .standard) { | ||
self.userDefaults = userDefaults | ||
} | ||
} | ||
|
||
extension AutofillCredentialsImportManager: AutofillPasswordImportDelegate { | ||
|
||
private struct CredentialsImportInputContext: Decodable { | ||
var inputType: String | ||
var credentialsImport: Bool | ||
} | ||
|
||
public func autofillUserScriptDidRequestPasswordImportFlow(_ completion: @escaping () -> Void) { | ||
PixelKit.fire(AutofillPixelKitEvent.importCredentialsFlowStarted.withoutMacPrefix) | ||
presentationDelegate?.autofillDidRequestCredentialsImportFlow( | ||
onFinished: { | ||
PixelKit.fire(AutofillPixelKitEvent.importCredentialsFlowEnded.withoutMacPrefix) | ||
completion() | ||
}, | ||
onCancelled: { | ||
PixelKit.fire(AutofillPixelKitEvent.importCredentialsFlowCancelled.withoutMacPrefix) | ||
completion() | ||
} | ||
) | ||
} | ||
|
||
public func autofillUserScriptDidFinishImportWithImportedCredentialForCurrentDomain() { | ||
PixelKit.fire(AutofillPixelKitEvent.importCredentialsFlowHadCredentials.withoutMacPrefix) | ||
} | ||
|
||
public func autofillUserScriptWillDisplayOverlay(_ serializedInputContext: String) { | ||
if let data = serializedInputContext.data(using: .utf8), | ||
let decoded = try? JSONDecoder().decode(CredentialsImportInputContext.self, from: data) { | ||
if decoded.credentialsImport { | ||
AutofillLoginImportState().credentialsImportPromptPresentationCount += 1 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// AutofillPixelEvent.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import PixelKit | ||
|
||
enum AutofillPixelKitEvent: PixelKitEventV2 { | ||
case importCredentialsFlowStarted | ||
case importCredentialsFlowCancelled | ||
case importCredentialsFlowHadCredentials | ||
case importCredentialsFlowEnded | ||
|
||
var name: String { | ||
switch self { | ||
case .importCredentialsFlowStarted: "autofill_import_credentials_flow_started" | ||
case .importCredentialsFlowCancelled: "autofill_import_credentials_flow_cancelled" | ||
case .importCredentialsFlowHadCredentials: "autofill_import_credentials_flow_had_credentials" | ||
case .importCredentialsFlowEnded: "autofill_import_credentials_flow_ended" | ||
} | ||
} | ||
|
||
var parameters: [String: String]? { | ||
nil | ||
} | ||
|
||
var error: (any Error)? { | ||
nil | ||
} | ||
|
||
var withoutMacPrefix: NonStandardEvent { | ||
NonStandardEvent(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.