Bug 1122225 - Add context menu for about:passwords actions. r=ally

This commit is contained in:
Chenxia Liu 2015-03-09 14:40:32 -07:00
parent 9629d1ce2b
commit fd3efd9e23
2 changed files with 33 additions and 2 deletions

View File

@ -17,6 +17,9 @@ XPCOMUtils.defineLazyGetter(window, "gChromeWin", function()
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow));
XPCOMUtils.defineLazyModuleGetter(this, "Prompt",
"resource://gre/modules/Prompt.jsm");
let debug = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.d.bind(null, "AboutPasswords");
let gStringBundle = Services.strings.createBundle("chrome://browser/locale/aboutPasswords.properties");
@ -125,9 +128,33 @@ let Passwords = {
loginItem.setAttribute("loginID", login.guid);
loginItem.className = "login-item list-item";
loginItem.addEventListener("click", () => {
this._showDetails(loginItem);
history.pushState({ id: login.guid }, document.title);
let prompt = new Prompt({
window: window,
});
let menuItems = [
{ label: gStringBundle.GetStringFromName("passwordsMenu.copyPassword") },
{ label: gStringBundle.GetStringFromName("passwordsMenu.copyUsername") },
{ label: gStringBundle.GetStringFromName("passwordsMenu.details") } ];
prompt.setSingleChoiceItems(menuItems);
prompt.show((data) => {
// Switch on indices of buttons, as they were added when creating login item.
switch (data.button) {
case 0:
copyStringAndToast(login.password, gStringBundle.GetStringFromName("passwordsDetails.passwordCopied"));
break;
case 1:
copyStringAndToast(login.username, gStringBundle.GetStringFromName("passwordsDetails.usernameCopied"));
break;
case 2:
this._showDetails(loginItem);
history.pushState({ id: login.guid }, document.title);
break;
}
});
}, true);
// Create item icon.

View File

@ -2,6 +2,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
passwordsMenu.copyPassword=Copy password
passwordsMenu.copyUsername=Copy username
passwordsMenu.details=Details
passwordsDetails.age=Age: %S days
passwordsDetails.copyFailed=Copy failed