Skip to content

Commit

Permalink
Chromium: Make password saving option independent from autofill optio…
Browse files Browse the repository at this point in the history
…n in Privacy settings

Currently in Privacy settings in Chromium backend, the password saving option depends on the autofill option. If autofill is disabled, password saving doesn't work whether enabled or not. This is because Chromium doesn't provide an autofill option but provides a login selection dialog that asks users whether to autofill the saved password or not. This commit makes password saving option independent from autofill option. The autofill option now only affects whether to show login selection dialog or not.

Fixes Igalia#1707
  • Loading branch information
haanhvu committed Jan 30, 2025
1 parent 1e871dd commit e49f57f
Showing 1 changed file with 48 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ public AutofillManager.Bridge create(AutofillManager.Listener listener) {
public class AutocompleteBridge implements PasswordManager.Bridge, AutofillManager.Bridge {
private PasswordManager.Listener mPasswordManagerListener;
private AutofillManager.Listener mAutofillManagerListener;
private boolean showLoginSelectDialog;

private LoginSavePrompt mLoginSavePrompt;
private LoginSelectPrompt mLoginSelectPrompt;
Expand All @@ -973,7 +974,11 @@ public boolean isAutocompleteEnabled(Context context) {

@Override
public boolean isAutoFillEnabled(Context context) {
return SettingsStore.getInstance(context).isAutoFillEnabled();
// Chromium doesn't provide an autofill option.
// Instead, it provides a login selection dialog that let users decide whether to autofill the saved password or not.
// We'll only show this dialog if users enable autofill.
showLoginSelectDialog = SettingsStore.getInstance(context).isAutoFillEnabled();
return true;
}

@Override
Expand Down Expand Up @@ -1011,56 +1016,62 @@ public boolean saveOrUpdatePassword(PasswordForm form) {

@Override
public boolean onLoginSelect(PasswordForm[] forms) {
dismiss();
assert mPasswordManagerListener != null;

WAutocomplete.LoginSelectOption[] options =
new WAutocomplete.LoginSelectOption[forms.length];
for (int i = 0; i < forms.length; i++) {
options[i] = new WAutocomplete.LoginSelectOption(fromPasswordForm(forms[i]));
}
if (showLoginSelectDialog) {
dismiss();
assert mPasswordManagerListener != null;

WAutocomplete.LoginSelectOption[] options =
new WAutocomplete.LoginSelectOption[forms.length];
for (int i = 0; i < forms.length; i++) {
options[i] = new WAutocomplete.LoginSelectOption(fromPasswordForm(forms[i]));
}

mLoginSelectPrompt = new LoginSelectPrompt<PasswordManager.Listener>(
mPasswordManagerListener, options);
try {
if (mDelegate != null) {
mDelegate.onLoginSelect(mSession, mLoginSelectPrompt);
} else {
mLoginSelectPrompt = new LoginSelectPrompt<PasswordManager.Listener>(
mPasswordManagerListener, options);
try {
if (mDelegate != null) {
mDelegate.onLoginSelect(mSession, mLoginSelectPrompt);
} else {
resetLoginSelectPrompt();
return false;
}
} catch (WindowManager.BadTokenException e) {
resetLoginSelectPrompt();
return false;
}
} catch (WindowManager.BadTokenException e) {
resetLoginSelectPrompt();
return false;
return true;
}
return true;
return false;
}

@Override
public boolean onLoginSelect(String[] username) {
dismiss();
assert mAutofillManagerListener != null;

WAutocomplete.LoginSelectOption[] options =
new WAutocomplete.LoginSelectOption[username.length];
for (int i = 0; i < username.length; i++) {
options[i] = new WAutocomplete.LoginSelectOption(fromUsername(i, username[i]));
}
if (showLoginSelectDialog) {
dismiss();
assert mAutofillManagerListener != null;

WAutocomplete.LoginSelectOption[] options =
new WAutocomplete.LoginSelectOption[username.length];
for (int i = 0; i < username.length; i++) {
options[i] = new WAutocomplete.LoginSelectOption(fromUsername(i, username[i]));
}

mLoginSelectPrompt = new LoginSelectPrompt<AutofillManager.Listener>(
mAutofillManagerListener, options);
try {
if (mDelegate != null) {
mDelegate.onLoginSelect(mSession, mLoginSelectPrompt);
} else {
mLoginSelectPrompt = new LoginSelectPrompt<AutofillManager.Listener>(
mAutofillManagerListener, options);
try {
if (mDelegate != null) {
mDelegate.onLoginSelect(mSession, mLoginSelectPrompt);
} else {
resetLoginSelectPrompt();
return false;
}
} catch (WindowManager.BadTokenException e) {
resetLoginSelectPrompt();
return false;
}
} catch (WindowManager.BadTokenException e) {
resetLoginSelectPrompt();
return false;
return true;
}
return true;
return false;
}


Expand Down

0 comments on commit e49f57f

Please sign in to comment.