Bug 1595915 - Move the password generation context menu item to the top-level. r=sfoster,fluent-reviewers,flod

Differential Revision: https://phabricator.services.mozilla.com/D60640

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Matthew Noorenberghe 2020-01-23 20:19:17 +00:00
parent 5b0fdb451b
commit cb2556b19d
4 changed files with 83 additions and 69 deletions

View File

@ -233,6 +233,11 @@
data-l10n-id="main-context-menu-view-background-image" data-l10n-id="main-context-menu-view-background-image"
oncommand="gContextMenu.viewBGImage(event);" oncommand="gContextMenu.viewBGImage(event);"
onclick="checkForMiddleClick(this, event);"/> onclick="checkForMiddleClick(this, event);"/>
<menuitem id="fill-login-generated-password"
data-l10n-id="main-context-menu-generate-new-password"
hidden="true"
oncommand="gContextMenu.useGeneratedPassword();"/>
<menuseparator id="generated-password-separator"/>
<menuitem id="context-undo" <menuitem id="context-undo"
data-l10n-id="text-action-undo" data-l10n-id="text-action-undo"
command="cmd_undo"/> command="cmd_undo"/>
@ -365,12 +370,6 @@
label="&noLoginSuggestions.label;" label="&noLoginSuggestions.label;"
disabled="true" disabled="true"
hidden="true"/> hidden="true"/>
<menuseparator id="generated-password-separator"/>
<menuitem id="fill-login-generated-password"
label="&useGeneratedPassword.label;"
accesskey="&useGeneratedPassword.accesskey;"
hidden="true"
oncommand="gContextMenu.useGeneratedPassword();"/>
<menuseparator id="saved-logins-separator"/> <menuseparator id="saved-logins-separator"/>
<menuitem id="fill-login-saved-passwords" <menuitem id="fill-login-saved-passwords"
label="&viewSavedLogins.label;" label="&viewSavedLogins.label;"

View File

@ -909,73 +909,86 @@ class nsContextMenu {
} }
initPasswordManagerItems() { initPasswordManagerItems() {
let loginFillInfo = this.contentData && this.contentData.loginFillInfo; let showFill = false;
let documentURI = this.contentData.documentURIObject; let showGenerate = false;
try {
let loginFillInfo = this.contentData && this.contentData.loginFillInfo;
let documentURI = this.contentData.documentURIObject;
// If we could not find a password field we // If we could not find a password field we
// don't want to show the form fill option. // don't want to show the form fill option.
let showFill = if (
loginFillInfo && !loginFillInfo ||
loginFillInfo.passwordField.found && !loginFillInfo.passwordField.found ||
!documentURI.schemeIs("about"); documentURI.schemeIs("about")
) {
// Both generation and fill will default to disabled.
return;
}
showFill = true;
// Disable the fill option if the user hasn't unlocked with their master password // Disable the fill option if the user hasn't unlocked with their master password
// or if the password field or target field are disabled. // or if the password field or target field are disabled.
// XXX: Bug 1529025 to respect signon.rememberSignons // XXX: Bug 1529025 to respect signon.rememberSignons
let disableFill = let disableFill =
!loginFillInfo || !loginFillInfo ||
!Services.logins || !Services.logins ||
!Services.logins.isLoggedIn || !Services.logins.isLoggedIn ||
loginFillInfo.passwordField.disabled || loginFillInfo.passwordField.disabled ||
(!this.onPassword && loginFillInfo.usernameField.disabled); (!this.onPassword && loginFillInfo.usernameField.disabled);
this.showItem("fill-login-separator", showFill); this.setItemAttr("fill-login", "disabled", disableFill);
this.showItem("fill-login", showFill);
this.setItemAttr("fill-login", "disabled", disableFill);
// Set the correct label for the fill menu // Set the correct label for the fill menu
let fillMenu = document.getElementById("fill-login"); let fillMenu = document.getElementById("fill-login");
if (this.onPassword) { if (this.onPassword) {
fillMenu.setAttribute("label", fillMenu.getAttribute("label-password")); fillMenu.setAttribute("label", fillMenu.getAttribute("label-password"));
fillMenu.setAttribute( fillMenu.setAttribute(
"accesskey", "accesskey",
fillMenu.getAttribute("accesskey-password") fillMenu.getAttribute("accesskey-password")
); );
} else { } else {
fillMenu.setAttribute("label", fillMenu.getAttribute("label-login")); fillMenu.setAttribute("label", fillMenu.getAttribute("label-login"));
fillMenu.setAttribute( fillMenu.setAttribute(
"accesskey", "accesskey",
fillMenu.getAttribute("accesskey-login") fillMenu.getAttribute("accesskey-login")
);
}
let formOrigin = LoginHelper.getLoginOrigin(documentURI.spec);
let isGeneratedPasswordEnabled =
LoginHelper.generationAvailable && LoginHelper.generationEnabled;
showGenerate =
this.onPassword &&
isGeneratedPasswordEnabled &&
Services.logins.getLoginSavingEnabled(formOrigin);
if (disableFill) {
// No need to update the submenu if the fill item is disabled.
return;
}
// Update sub-menu items.
let fragment = nsContextMenu.LoginManagerContextMenu.addLoginsToMenu(
this.targetIdentifier,
this.browser,
formOrigin
); );
this.showItem("fill-login-no-logins", !fragment);
if (!fragment) {
return;
}
let popup = document.getElementById("fill-login-popup");
let insertBeforeElement = document.getElementById("fill-login-no-logins");
popup.insertBefore(fragment, insertBeforeElement);
} finally {
this.showItem("fill-login-separator", showFill);
this.showItem("fill-login", showFill);
this.showItem("fill-login-generated-password", showGenerate);
this.showItem("generated-password-separator", showGenerate);
} }
if (!showFill || disableFill) {
return;
}
let formOrigin = LoginHelper.getLoginOrigin(documentURI.spec);
let fragment = nsContextMenu.LoginManagerContextMenu.addLoginsToMenu(
this.targetIdentifier,
this.browser,
formOrigin
);
let isGeneratedPasswordEnabled =
LoginHelper.generationAvailable && LoginHelper.generationEnabled;
let canFillGeneratedPassword =
this.onPassword &&
isGeneratedPasswordEnabled &&
Services.logins.getLoginSavingEnabled(formOrigin);
this.showItem("fill-login-no-logins", !fragment);
this.showItem("fill-login-generated-password", canFillGeneratedPassword);
this.showItem("generated-password-separator", canFillGeneratedPassword);
if (!fragment) {
return;
}
let popup = document.getElementById("fill-login-popup");
let insertBeforeElement = document.getElementById("fill-login-no-logins");
popup.insertBefore(fragment, insertBeforeElement);
} }
initSyncItems() { initSyncItems() {

View File

@ -285,6 +285,10 @@ main-context-menu-view-background-image =
.label = View Background Image .label = View Background Image
.accesskey = w .accesskey = w
main-context-menu-generate-new-password =
.label = Use Generated Password…
.accesskey = G
main-context-menu-keyword = main-context-menu-keyword =
.label = Add a Keyword for this Search… .label = Add a Keyword for this Search…
.accesskey = K .accesskey = K

View File

@ -16,8 +16,6 @@
<!ENTITY fillLoginMenu.label "Fill Login"> <!ENTITY fillLoginMenu.label "Fill Login">
<!ENTITY fillLoginMenu.accesskey "F"> <!ENTITY fillLoginMenu.accesskey "F">
<!ENTITY useGeneratedPassword.label "Use a Securely Generated Password…">
<!ENTITY useGeneratedPassword.accesskey "S">
<!ENTITY fillPasswordMenu.label "Fill Password"> <!ENTITY fillPasswordMenu.label "Fill Password">
<!ENTITY fillPasswordMenu.accesskey "F"> <!ENTITY fillPasswordMenu.accesskey "F">
<!ENTITY fillUsernameMenu.label "Fill Username"> <!ENTITY fillUsernameMenu.label "Fill Username">