Bug 1869544 - Use const declarations in LoginManagerPrompter.sys.mjs r=credential-management-reviewers,issammani

Differential Revision: https://phabricator.services.mozilla.com/D196178
This commit is contained in:
jneuberger 2023-12-13 23:10:06 +00:00
Родитель 81938d0fa0
Коммит 23c80b5e4c
1 изменённых файлов: 83 добавлений и 83 удалений

Просмотреть файл

@ -57,11 +57,11 @@ const NOTIFICATION_TIMEOUT_MS = 10 * 1000; // 10 seconds
const ATTENTION_NOTIFICATION_TIMEOUT_MS = 60 * 1000; // 1 minute
function autocompleteSelected(popup) {
let doc = popup.ownerDocument;
let nameField = doc.getElementById("password-notification-username");
let passwordField = doc.getElementById("password-notification-password");
const doc = popup.ownerDocument;
const nameField = doc.getElementById("password-notification-username");
const passwordField = doc.getElementById("password-notification-password");
let activeElement = nameField.ownerDocument.activeElement;
const activeElement = nameField.ownerDocument.activeElement;
if (activeElement == nameField) {
popup.onUsernameSelect();
} else if (activeElement == passwordField) {
@ -76,7 +76,7 @@ const observer = {
observe(subject, topic, data) {
switch (topic) {
case "autocomplete-did-enter-text": {
let input = subject.QueryInterface(Ci.nsIAutoCompleteInput);
const input = subject.QueryInterface(Ci.nsIAutoCompleteInput);
autocompleteSelected(input.popupElement);
break;
}
@ -127,8 +127,8 @@ export class LoginManagerPrompter {
possibleValues = undefined
) {
lazy.log.debug("Prompting user to save login.");
let inPrivateBrowsing = PrivateBrowsingUtils.isBrowserPrivate(aBrowser);
let notification = LoginManagerPrompter._showLoginCaptureDoorhanger(
const inPrivateBrowsing = PrivateBrowsingUtils.isBrowserPrivate(aBrowser);
const notification = LoginManagerPrompter._showLoginCaptureDoorhanger(
aBrowser,
aLogin,
"password-save",
@ -146,7 +146,7 @@ export class LoginManagerPrompter {
return {
dismiss() {
let { PopupNotifications } = aBrowser.ownerGlobal.wrappedJSObject;
const { PopupNotifications } = aBrowser.ownerGlobal.wrappedJSObject;
PopupNotifications.remove(notification);
},
};
@ -197,35 +197,35 @@ export class LoginManagerPrompter {
`Got autoSavedLoginGuid: ${autoSavedLoginGuid} and autoFilledLoginGuid ${autoFilledLoginGuid}.`
);
let saveMessageIds = {
const saveMessageIds = {
prompt: "password-manager-save-password-message",
mainButton: "password-manager-save-password-button-allow",
secondaryButton: "password-manager-save-password-button-deny",
};
let changeMessageIds = {
const changeMessageIds = {
prompt: messageStringID ?? "password-manager-update-password-message",
mainButton: "password-manager-password-password-button-allow",
secondaryButton: "password-manager-update-password-button-deny",
};
let initialMessageIds =
const initialMessageIds =
type == "password-save" ? saveMessageIds : changeMessageIds;
let promptId = initialMessageIds.prompt;
let host = this._getShortDisplayHost(login.origin);
let promptMessage = lazy.l10n.formatValueSync(promptId, { host });
const promptId = initialMessageIds.prompt;
const host = this._getShortDisplayHost(login.origin);
const promptMessage = lazy.l10n.formatValueSync(promptId, { host });
let histogramName =
const histogramName =
type == "password-save"
? "PWMGR_PROMPT_REMEMBER_ACTION"
: "PWMGR_PROMPT_UPDATE_ACTION";
let histogram = Services.telemetry.getHistogramById(histogramName);
const histogram = Services.telemetry.getHistogramById(histogramName);
let chromeDoc = browser.ownerDocument;
const chromeDoc = browser.ownerDocument;
let currentNotification;
let wasModifiedEvent = {
const wasModifiedEvent = {
// Values are mutated
did_edit_un: "false",
did_select_un: "false",
@ -233,8 +233,8 @@ export class LoginManagerPrompter {
did_select_pw: "false",
};
let updateButtonStatus = element => {
let mainActionButton = element.button;
const updateButtonStatus = element => {
const mainActionButton = element.button;
// Disable the main button inside the menu-button if the password field is empty.
if (!login.password.length) {
mainActionButton.setAttribute("disabled", true);
@ -249,34 +249,34 @@ export class LoginManagerPrompter {
}
};
let updateButtonLabel = () => {
const updateButtonLabel = () => {
if (!currentNotification) {
console.error("updateButtonLabel, no currentNotification");
}
let foundLogins = lazy.LoginHelper.searchLoginsWithObject({
const foundLogins = lazy.LoginHelper.searchLoginsWithObject({
formActionOrigin: login.formActionOrigin,
origin: login.origin,
httpRealm: login.httpRealm,
schemeUpgrades: lazy.LoginHelper.schemeUpgrades,
});
let logins = this._filterUpdatableLogins(
const logins = this._filterUpdatableLogins(
login,
foundLogins,
autoSavedLoginGuid
);
let messageIds = !logins.length ? saveMessageIds : changeMessageIds;
const messageIds = !logins.length ? saveMessageIds : changeMessageIds;
// Update the label based on whether this will be a new login or not.
let mainButton = this.getLabelAndAccessKey(messageIds.mainButton);
const mainButton = this.getLabelAndAccessKey(messageIds.mainButton);
// Update the labels for the next time the panel is opened.
currentNotification.mainAction.label = mainButton.label;
currentNotification.mainAction.accessKey = mainButton.accessKey;
// Update the labels in real time if the notification is displayed.
let element = [...currentNotification.owner.panel.childNodes].find(
const element = [...currentNotification.owner.panel.childNodes].find(
n => n.notification == currentNotification
);
if (element) {
@ -286,19 +286,19 @@ export class LoginManagerPrompter {
}
};
let writeDataToUI = () => {
let nameField = chromeDoc.getElementById(
const writeDataToUI = () => {
const nameField = chromeDoc.getElementById(
"password-notification-username"
);
nameField.placeholder = usernamePlaceholder;
nameField.value = login.username;
let toggleCheckbox = chromeDoc.getElementById(
const toggleCheckbox = chromeDoc.getElementById(
"password-notification-visibilityToggle"
);
toggleCheckbox.removeAttribute("checked");
let passwordField = chromeDoc.getElementById(
const passwordField = chromeDoc.getElementById(
"password-notification-password"
);
// Ensure the type is reset so the field is masked.
@ -308,7 +308,7 @@ export class LoginManagerPrompter {
updateButtonLabel();
};
let readDataFromUI = () => {
const readDataFromUI = () => {
login.username = chromeDoc.getElementById(
"password-notification-username"
).value;
@ -317,46 +317,46 @@ export class LoginManagerPrompter {
).value;
};
let onInput = () => {
const onInput = () => {
readDataFromUI();
updateButtonLabel();
};
let onUsernameInput = () => {
const onUsernameInput = () => {
wasModifiedEvent.did_edit_un = "true";
wasModifiedEvent.did_select_un = "false";
onInput();
};
let onUsernameSelect = () => {
const onUsernameSelect = () => {
wasModifiedEvent.did_edit_un = "false";
wasModifiedEvent.did_select_un = "true";
};
let onPasswordInput = () => {
const onPasswordInput = () => {
wasModifiedEvent.did_edit_pw = "true";
wasModifiedEvent.did_select_pw = "false";
onInput();
};
let onPasswordSelect = () => {
const onPasswordSelect = () => {
wasModifiedEvent.did_edit_pw = "false";
wasModifiedEvent.did_select_pw = "true";
};
let onKeyUp = e => {
const onKeyUp = e => {
if (e.key == "Enter") {
e.target.closest("popupnotification").button.doCommand();
}
};
let onVisibilityToggle = commandEvent => {
let passwordField = chromeDoc.getElementById(
const onVisibilityToggle = commandEvent => {
const passwordField = chromeDoc.getElementById(
"password-notification-password"
);
// Gets the caret position before changing the type of the textbox
let selectionStart = passwordField.selectionStart;
let selectionEnd = passwordField.selectionEnd;
const selectionStart = passwordField.selectionStart;
const selectionEnd = passwordField.selectionEnd;
passwordField.setAttribute(
"type",
commandEvent.target.checked ? "" : "password"
@ -368,14 +368,14 @@ export class LoginManagerPrompter {
passwordField.selectionEnd = selectionEnd;
};
let togglePopup = event => {
const togglePopup = event => {
event.target.parentElement
.getElementsByClassName("ac-has-end-icon")[0]
.toggleHistoryPopup();
};
let persistData = async () => {
let foundLogins = lazy.LoginHelper.searchLoginsWithObject({
const persistData = async () => {
const foundLogins = lazy.LoginHelper.searchLoginsWithObject({
formActionOrigin: login.formActionOrigin,
origin: login.origin,
httpRealm: login.httpRealm,
@ -387,7 +387,7 @@ export class LoginManagerPrompter {
foundLogins,
autoSavedLoginGuid
);
let resolveBy = ["scheme", "timePasswordChanged"];
const resolveBy = ["scheme", "timePasswordChanged"];
logins = lazy.LoginHelper.dedupeLogins(
logins,
["username"],
@ -400,7 +400,7 @@ export class LoginManagerPrompter {
lazy.log.debug(`Matched ${logins.length} logins.`);
let loginToRemove;
let loginToUpdate = logins.shift();
const loginToUpdate = logins.shift();
if (logins.length && logins[0].guid == autoSavedLoginGuid) {
loginToRemove = logins.shift();
@ -470,10 +470,10 @@ export class LoginManagerPrompter {
PWMGR_PROMPT_UPDATE_ACTION: true,
};
let mainButton = this.getLabelAndAccessKey(initialMessageIds.mainButton);
const mainButton = this.getLabelAndAccessKey(initialMessageIds.mainButton);
// The main action is the "Save" or "Update" button.
let mainAction = {
const mainAction = {
label: mainButton.label,
accessKey: mainButton.accessKey,
callback: async () => {
@ -542,11 +542,11 @@ export class LoginManagerPrompter {
},
};
let secondaryButton = this.getLabelAndAccessKey(
const secondaryButton = this.getLabelAndAccessKey(
initialMessageIds.secondaryButton
);
let secondaryActions = [
const secondaryActions = [
{
label: secondaryButton.label,
accessKey: secondaryButton.accessKey,
@ -563,7 +563,7 @@ export class LoginManagerPrompter {
];
// Include a "Never for this site" button when saving a new password.
if (type == "password-save") {
let neverSaveButton = this.getLabelAndAccessKey(
const neverSaveButton = this.getLabelAndAccessKey(
"password-manager-save-password-button-never"
);
secondaryActions.push({
@ -582,7 +582,7 @@ export class LoginManagerPrompter {
});
}
let updatePasswordButtonDelete = this.getLabelAndAccessKey(
const updatePasswordButtonDelete = this.getLabelAndAccessKey(
"password-manager-update-password-button-delete"
);
@ -617,24 +617,24 @@ export class LoginManagerPrompter {
});
}
let usernamePlaceholder = lazy.l10n.formatValueSync(
const usernamePlaceholder = lazy.l10n.formatValueSync(
"password-manager-no-username-placeholder"
);
let togglePassword = this.getLabelAndAccessKey(
const togglePassword = this.getLabelAndAccessKey(
"password-manager-toggle-password"
);
// .wrappedJSObject needed here -- see bug 422974 comment 5.
let { PopupNotifications } = browser.ownerGlobal.wrappedJSObject;
const { PopupNotifications } = browser.ownerGlobal.wrappedJSObject;
let notificationID = "password";
const notificationID = "password";
// keep attention notifications around for longer after a locationchange
const timeoutMs =
showOptions.dismissed && showOptions.extraAttr == "attention"
? ATTENTION_NOTIFICATION_TIMEOUT_MS
: NOTIFICATION_TIMEOUT_MS;
let options = Object.assign(
const options = Object.assign(
{
timeout: Date.now() + timeoutMs,
persistWhileVisible: true,
@ -682,14 +682,14 @@ export class LoginManagerPrompter {
login,
possibleValues?.usernames
).then(usernameSuggestions => {
let dropmarker = chromeDoc?.getElementById(
const dropmarker = chromeDoc?.getElementById(
"password-notification-username-dropmarker"
);
if (dropmarker) {
dropmarker.hidden = !usernameSuggestions.length;
}
let usernameField = chromeDoc?.getElementById(
const usernameField = chromeDoc?.getElementById(
"password-notification-username"
);
if (usernameField) {
@ -700,7 +700,7 @@ export class LoginManagerPrompter {
}
});
let toggleBtn = chromeDoc.getElementById(
const toggleBtn = chromeDoc.getElementById(
"password-notification-visibilityToggle"
);
@ -714,7 +714,7 @@ export class LoginManagerPrompter {
toggleBtn.setAttribute("label", togglePassword.label);
toggleBtn.setAttribute("accesskey", togglePassword.accessKey);
let hideToggle =
const hideToggle =
lazy.LoginHelper.isPrimaryPasswordSet() ||
// Don't show the toggle when the login was autofilled
!!autoFilledLoginGuid ||
@ -744,7 +744,7 @@ export class LoginManagerPrompter {
case "shown": {
lazy.log.debug("shown");
writeDataToUI();
let anchorIcon = this.anchorElement;
const anchorIcon = this.anchorElement;
if (anchorIcon && this.options.extraAttr == "attention") {
anchorIcon.removeAttribute("extraAttr");
delete this.options.extraAttr;
@ -761,12 +761,12 @@ export class LoginManagerPrompter {
lazy.log.debug(topic);
currentNotification = null;
let usernameField = chromeDoc.getElementById(
const usernameField = chromeDoc.getElementById(
"password-notification-username"
);
usernameField.removeEventListener("input", onUsernameInput);
usernameField.removeEventListener("keyup", onKeyUp);
let passwordField = chromeDoc.getElementById(
const passwordField = chromeDoc.getElementById(
"password-notification-password"
);
passwordField.removeEventListener("input", onPasswordInput);
@ -784,7 +784,7 @@ export class LoginManagerPrompter {
showOptions
);
let notification = PopupNotifications.show(
const notification = PopupNotifications.show(
browser,
notificationID,
promptMessage,
@ -839,7 +839,7 @@ export class LoginManagerPrompter {
autoFilledLoginGuid = "",
possibleValues = undefined
) {
let login = aOldLogin.clone();
const login = aOldLogin.clone();
login.origin = aNewLogin.origin;
login.formActionOrigin = aNewLogin.formActionOrigin;
login.password = aNewLogin.password;
@ -857,7 +857,7 @@ export class LoginManagerPrompter {
messageStringID = "password-manager-update-login-add-username";
}
let notification = LoginManagerPrompter._showLoginCaptureDoorhanger(
const notification = LoginManagerPrompter._showLoginCaptureDoorhanger(
aBrowser,
login,
"password-change",
@ -874,7 +874,7 @@ export class LoginManagerPrompter {
}
);
let oldGUID = aOldLogin.QueryInterface(Ci.nsILoginMetaInfo).guid;
const oldGUID = aOldLogin.QueryInterface(Ci.nsILoginMetaInfo).guid;
Services.obs.notifyObservers(
aNewLogin,
"passwordmgr-prompt-change",
@ -883,7 +883,7 @@ export class LoginManagerPrompter {
return {
dismiss() {
let { PopupNotifications } = aBrowser.ownerGlobal.wrappedJSObject;
const { PopupNotifications } = aBrowser.ownerGlobal.wrappedJSObject;
PopupNotifications.remove(notification);
},
};
@ -1047,20 +1047,20 @@ export class LoginManagerPrompter {
* @param {Set<String>?} possibleUsernames - values that we believe may be new/changed login usernames.
*/
static async _setUsernameAutocomplete(login, possibleUsernames = new Set()) {
let result = Cc["@mozilla.org/autocomplete/simple-result;1"].createInstance(
Ci.nsIAutoCompleteSimpleResult
);
const result = Cc[
"@mozilla.org/autocomplete/simple-result;1"
].createInstance(Ci.nsIAutoCompleteSimpleResult);
result.setDefaultIndex(0);
let usernames = await this._getUsernameSuggestions(
const usernames = await this._getUsernameSuggestions(
login,
possibleUsernames
);
for (let { text, style } of usernames) {
let value = text;
let comment = "";
let image = "";
let _style = style;
for (const { text, style } of usernames) {
const value = text;
const comment = "";
const image = "";
const _style = style;
result.appendMatch(value, comment, image, _style);
}
@ -1090,28 +1090,28 @@ export class LoginManagerPrompter {
return [];
}
let baseDomainLogins = await Services.logins.searchLoginsAsync({
const baseDomainLogins = await Services.logins.searchLoginsAsync({
origin: login.origin,
schemeUpgrades: lazy.LoginHelper.schemeUpgrades,
acceptDifferentSubdomains: true,
});
let saved = baseDomainLogins.map(login => {
const saved = baseDomainLogins.map(login => {
return { text: login.username, style: "login" };
});
let possible = [...possibleUsernames].map(username => {
const possible = [...possibleUsernames].map(username => {
return { text: username, style: "possible-username" };
});
return possible
.concat(saved)
.reduce((acc, next) => {
let alreadyInAcc =
const alreadyInAcc =
acc.findIndex(entry => entry.text == next.text) != -1;
if (!alreadyInAcc) {
acc.push(next);
} else if (next.style == "possible-username") {
let existingIndex = acc.findIndex(entry => entry.text == next.text);
const existingIndex = acc.findIndex(entry => entry.text == next.text);
acc[existingIndex] = next;
}
return acc;