--- a/toolkit/components/prompts/src/nsPrompter.js
+++ b/toolkit/components/prompts/src/nsPrompter.js
@@ -317,35 +317,16 @@ let PromptUtils = {
else if (!realm)
text = PromptUtils.getLocalizedString("EnterUserPasswordFor", [displayHost]);
else
text = PromptUtils.getLocalizedString("EnterLoginForRealm", [realm, displayHost]);
return text;
},
- objectToPropBag : function (obj) {
- let bag = Cc["@mozilla.org/hash-property-bag;1"].
- createInstance(Ci.nsIWritablePropertyBag2);
- bag.QueryInterface(Ci.nsIWritablePropertyBag);
-
- for (let propName in obj)
- bag.setProperty(propName, obj[propName]);
-
- return bag;
- },
-
- propBagToObject : function (propBag, obj) {
- // Here we iterate over the object's original properties, not the bag
- // (ie, the prompt can't return more/different properties than were
- // passed in). This just helps ensure that the caller provides default
- // values, lest the prompt forget to set them.
- for (let propName in obj)
- obj[propName] = propBag.getProperty(propName);
- },
};
XPCOMUtils.defineLazyGetter(PromptUtils, "strBundle", function () {
let bunService = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService);
let bundle = bunService.createBundle("chrome://global/locale/commonDialogs.properties");
if (!bundle)
throw "String bundle for Prompter not present!";
@@ -357,51 +338,50 @@ XPCOMUtils.defineLazyGetter(PromptUtils,
try {
ellipsis = Services.prefs.getComplexValue("intl.ellipsis", Ci.nsIPrefLocalizedString).data;
} catch (e) { }
return ellipsis;
});
-function openModalWindow(domWin, uri, args) {
- // XXX do we want to do modal state if we fall back to .activeWindow?
- if (!domWin)
- domWin = Services.ww.activeWindow;
-
- // XXX domWin may still be null here if there are _no_ windows open.
-
- // Note that we don't need to fire DOMWillOpenModalDialog and
- // DOMModalDialogClosed events here, wwatcher's OpenWindowJSInternal
- // will do that. Similarly for enterModalState / leaveModalState.
-
- Services.ww.openWindow(domWin, uri, "_blank", "centerscreen,chrome,modal,titlebar", args);
-}
+const COMMON_DIALOG = "chrome://global/content/commonDialog.xul";
+const SELECT_DIALOG = "chrome://global/content/selectDialog.xul";
function ModalPrompter(domWin) {
this.domWin = domWin;
}
ModalPrompter.prototype = {
domWin : null,
QueryInterface : XPCOMUtils.generateQI([Ci.nsIPrompt, Ci.nsIAuthPrompt, Ci.nsIAuthPrompt2]),
/* ---------- internal methods ---------- */
- openPrompt : function (args) {
- const COMMON_DIALOG = "chrome://global/content/commonDialog.xul";
- const SELECT_DIALOG = "chrome://global/content/selectDialog.xul";
+ newPropBag : function () {
+ let bag = Cc["@mozilla.org/hash-property-bag;1"].
+ createInstance(Ci.nsIWritablePropertyBag2);
+ return bag.QueryInterface(Ci.nsIWritablePropertyBag);
+ },
- let uri = (args.promptType == "select") ? SELECT_DIALOG : COMMON_DIALOG;
+ openPrompt : function (uri, args) {
+ // XXX do we want to do modal state if we fall back to .activeWindow?
+ let domWin = this.domWin;
+ if (!domWin)
+ domWin = Services.ww.activeWindow;
- let propBag = PromptUtils.objectToPropBag(args);
- openModalWindow(this.domWin, uri, propBag);
- PromptUtils.propBagToObject(propBag, args);
+ // XXX domWin may still be null here if there are _no_ windows open.
+
+ // Note that we don't need to fire DOMWillOpenModalDialog and
+ // DOMModalDialogClosed events here, wwatcher's OpenWindowJSInternal
+ // will do that. Similarly for enterModalState / leaveModalState.
+
+ Services.ww.openWindow(domWin, uri, "_blank", "centerscreen,chrome,modal,titlebar", args);
},
/*
* ---------- interface disambiguation ----------
*
* nsIPrompt and nsIAuthPrompt share 3 method names with slightly
@@ -436,222 +416,212 @@ ModalPrompter.prototype = {
/* ---------- nsIPrompt ---------- */
alert : function (title, text) {
if (!title)
title = PromptUtils.getLocalizedString("Alert");
- let args = {
- promptType: "alert",
- title: title,
- text: text,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "alert");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
},
alertCheck : function (title, text, checkLabel, checkValue) {
if (!title)
title = PromptUtils.getLocalizedString("Alert");
- let args = {
- promptType: "alertCheck",
- title: title,
- text: text,
- checkLabel: checkLabel,
- checked: checkValue.value,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "alertCheck");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("checkLabel", checkLabel);
+ args.setProperty("checked", checkValue.value);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Checkbox state always returned, even if cancel clicked.
- checkValue.value = args.checked;
+ checkValue.value = args.getProperty("checked");
},
confirm : function (title, text) {
if (!title)
title = PromptUtils.getLocalizedString("Confirm");
- let args = {
- promptType: "confirm",
- title: title,
- text: text,
- ok: false,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "confirm");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("ok", false);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Did user click Ok or Cancel?
- return args.ok;
+ return args.getProperty("ok");
},
confirmCheck : function (title, text, checkLabel, checkValue) {
if (!title)
title = PromptUtils.getLocalizedString("ConfirmCheck");
- let args = {
- promptType: "confirmCheck",
- title: title,
- text: text,
- checkLabel: checkLabel,
- checked: checkValue.value,
- ok: false,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "confirmCheck");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("checkLabel", checkLabel);
+ args.setProperty("checked", checkValue.value);
+ args.setProperty("ok", false);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Checkbox state always returned, even if cancel clicked.
- checkValue.value = args.checked;
+ checkValue.value = args.getProperty("checked");
// Did user click Ok or Cancel?
- return args.ok;
+ return args.getProperty("ok");
},
confirmEx : function (title, text, flags, button0, button1, button2,
checkLabel, checkValue) {
if (!title)
title = PromptUtils.getLocalizedString("Confirm");
- let args = {
- promptType: "confirmEx",
- title: title,
- text: text,
- checkLabel: checkLabel,
- checked: checkValue.value,
- ok: false,
- buttonNumClicked: 1,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "confirmEx");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("checkLabel", checkLabel);
+ args.setProperty("checked", checkValue.value);
+ args.setProperty("ok", false);
+ args.setProperty("buttonNumClicked", 1);
let [label0, label1, label2, defaultButtonNum, isDelayEnabled] =
PromptUtils.confirmExHelper(flags, button0, button1, button2);
- args.defaultButtonNum = defaultButtonNum;
- args.enableDelay = isDelayEnabled;
+ args.setProperty("defaultButtonNum", defaultButtonNum);
+ args.setProperty("enableDelay", isDelayEnabled);
if (label0) {
- args.button0Label = label0;
+ args.setProperty("button0Label", label0);
if (label1) {
- args.button1Label = label1;
+ args.setProperty("button1Label", label1);
if (label2) {
- args.button2Label = label2;
+ args.setProperty("button2Label", label2);
}
}
}
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Checkbox state always returned, even if cancel clicked.
- checkValue.value = args.checked;
+ checkValue.value = args.getProperty("checked");
// Get the number of the button the user clicked.
- return args.buttonNumClicked;
+ return args.getProperty("buttonNumClicked");
},
nsIPrompt_prompt : function (title, text, value, checkLabel, checkValue) {
if (!title)
title = PromptUtils.getLocalizedString("Prompt");
- let args = {
- promptType: "prompt",
- title: title,
- text: text,
- value: value.value,
- checkLabel: checkLabel,
- checked: checkValue.value,
- ok: false,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "prompt");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("value", value.value);
+ args.setProperty("checkLabel", checkLabel);
+ args.setProperty("checked", checkValue.value);
+ args.setProperty("ok", false);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Did user click Ok or Cancel?
- let ok = args.ok;
+ let ok = args.getProperty("ok");
if (ok) {
- checkValue.value = args.checked;
- value.value = args.value;
+ checkValue.value = args.getProperty("checked");
+ value.value = args.getProperty("value");
}
return ok;
},
nsIPrompt_promptUsernameAndPassword : function (title, text, user, pass, checkLabel, checkValue) {
if (!title)
title = PromptUtils.getLocalizedString("PromptUsernameAndPassword2");
- let args = {
- promptType: "promptUserAndPass",
- title: title,
- text: text,
- user: user.value,
- pass: pass.value,
- checkLabel: checkLabel,
- checked: checkValue.value,
- ok: false,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "promptUserAndPass");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("user", user.value);
+ args.setProperty("pass", pass.value);
+ args.setProperty("checkLabel", checkLabel);
+ args.setProperty("checked", checkValue.value);
+ args.setProperty("ok", false);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Did user click Ok or Cancel?
- let ok = args.ok;
+ let ok = args.getProperty("ok");
if (ok) {
- checkValue.value = args.checked;
- user.value = args.user;
- pass.value = args.pass;
+ checkValue.value = args.getProperty("checked");
+ user.value = args.getProperty("user");
+ pass.value = args.getProperty("pass");
}
return ok;
},
nsIPrompt_promptPassword : function (title, text, pass, checkLabel, checkValue) {
if (!title)
title = PromptUtils.getLocalizedString("PromptPassword2");
- let args = {
- promptType: "promptPassword",
- title: title,
- text: text,
- pass: pass.value,
- checkLabel: checkLabel,
- checked: checkValue.value,
- ok: false,
- }
+ let args = this.newPropBag();
+ args.setProperty("promptType", "promptPassword");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("pass", pass.value);
+ args.setProperty("checkLabel", checkLabel);
+ args.setProperty("checked", checkValue.value);
+ args.setProperty("ok", false);
- this.openPrompt(args);
+ this.openPrompt(COMMON_DIALOG, args);
// Did user click Ok or Cancel?
- let ok = args.ok;
+ let ok = args.getProperty("ok");
if (ok) {
- checkValue.value = args.checked;
- pass.value = args.pass;
+ checkValue.value = args.getProperty("checked");
+ pass.value = args.getProperty("pass");
}
return ok;
},
select : function (title, text, count, list, selected) {
if (!title)
title = PromptUtils.getLocalizedString("Select");
- let args = {
- promptType: "select",
- title: title,
- text: text,
- list: list,
- selected: -1,
- ok: false,
- };
+ let args = this.newPropBag();
+ args.setProperty("promptType", "select");
+ args.setProperty("title", title);
+ args.setProperty("text", text);
+ args.setProperty("list", list);
+ args.setProperty("ok", false);
- this.openPrompt(args);
+ this.openPrompt(SELECT_DIALOG, args);
// Did user click Ok or Cancel?
- let ok = args.ok;
+ let ok = args.getProperty("ok");
if (ok)
- selected.value = args.selected;
+ selected.value = args.getProperty("selected");
return ok;
},
/* ---------- nsIAuthPrompt ---------- */