Skip to content

Commit

Permalink
generation: ensure password gen feature flag is respected (#583)
Browse files Browse the repository at this point in the history
This was originally introduced as a commit squashed into 8b046b1
(Android: enable iframe support (#536), 2024-04-09), but was accidentally
removed via 18dd599 (android: revert "Android: enable iframe support
(#536)" (#582), 2024-06-20). Reintroduce that commit, to ensure the
`password_generation` runtime config flag is again respected and prevent
password prompts after a user clicks "Never save for site".

(cherry picked from commit 4c16e52)
  • Loading branch information
sjbarag authored Jun 21, 2024
1 parent 18dd599 commit 2b81745
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 20 deletions.
19 changes: 15 additions & 4 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,18 @@ export class Settings {
* @param {{
* mainType: SupportedMainTypes
* subtype: import('./Form/matching.js').SupportedSubTypes | "unknown"
* variant?: import('./Form/matching.js').SupportedVariants | ""
* }} types
* @returns {boolean}
*/
isTypeUnavailable ({mainType, subtype}) {
isTypeUnavailable ({mainType, subtype, variant}) {
if (mainType === 'unknown') return true

// Ensure password generation feature flag is respected
if (subtype === 'password' && variant === 'new') {
return !this.featureToggles.password_generation
}

if (!this.featureToggles[`inputType_${mainType}`] && subtype !== 'emailAddress') {
return true
}
Expand All @@ -223,11 +230,12 @@ export class Settings {
* @param {{
* mainType: SupportedMainTypes
* subtype: import('./Form/matching.js').SupportedSubTypes | "unknown"
* variant?: import('./Form/matching.js').SupportedVariants | ""
* }} types
* @returns {Promise<boolean>}
*/
async populateDataIfNeeded ({mainType, subtype}) {
if (this.isTypeUnavailable({mainType, subtype})) return false
async populateDataIfNeeded ({mainType, subtype, variant}) {
if (this.isTypeUnavailable({mainType, subtype, variant})) return false
if (this.availableInputTypes?.[mainType] === undefined) {
await this.populateData()
return true
Expand All @@ -247,7 +255,7 @@ export class Settings {
* @returns {boolean}
*/
canAutofillType ({mainType, subtype, variant}, inContextSignup) {
if (this.isTypeUnavailable({ mainType, subtype })) return false
if (this.isTypeUnavailable({ mainType, subtype, variant })) return false

// If it's an email field and Email Protection is enabled, return true regardless of other options
const isEmailProtectionEnabled = this.featureToggles.emailProtection && this.availableInputTypes.email
Expand Down
11 changes: 11 additions & 0 deletions src/Settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ describe('Settings', () => {
expect(settings.canAutofillType({ mainType: 'credentials', subtype: 'password', variant: 'current' }, null)).toBe(false)
}
],
[
{ password_generation: false },
{
...createAvailableInputTypes({
credentials: {username: true, password: true}
})
},
(settings) => {
expect(settings.canAutofillType({ mainType: 'credentials', subtype: 'password', variant: 'new' }, null)).toBe(false)
}
],
[
{},
{
Expand Down
19 changes: 15 additions & 4 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b81745

Please sign in to comment.