2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2009-09-02 09:15:26 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-07-13 07:36:09 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-06-12 09:14:57 -07:00
|
|
|
Cu.import("resource://gre/modules/Prompt.jsm");
|
2009-09-02 09:15:26 -07:00
|
|
|
|
2011-01-04 07:35:05 -08:00
|
|
|
// Whitelist of methods we remote - to check against malicious data.
|
|
|
|
// For example, it would be dangerous to allow content to show auth prompts.
|
|
|
|
const REMOTABLE_METHODS = {
|
|
|
|
alert: { outParams: [] },
|
|
|
|
alertCheck: { outParams: [4] },
|
|
|
|
confirm: { outParams: [] },
|
|
|
|
prompt: { outParams: [3, 5] },
|
|
|
|
confirmEx: { outParams: [8] },
|
|
|
|
confirmCheck: { outParams: [4] },
|
|
|
|
select: { outParams: [5] }
|
|
|
|
};
|
|
|
|
|
2010-09-03 12:17:00 -07:00
|
|
|
var gPromptService = null;
|
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
function PromptService() {
|
2010-09-03 12:17:00 -07:00
|
|
|
gPromptService = this;
|
2009-09-02 09:15:26 -07:00
|
|
|
}
|
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
PromptService.prototype = {
|
2009-09-02 09:15:26 -07:00
|
|
|
classID: Components.ID("{9a61149b-2276-4a0a-b79c-be994ad106cf}"),
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIPromptService, Ci.nsIPromptService2]),
|
|
|
|
|
|
|
|
/* ---------- nsIPromptFactory ---------- */
|
|
|
|
// XXX Copied from nsPrompter.js.
|
|
|
|
getPrompt: function getPrompt(domWin, iid) {
|
2009-09-02 09:15:26 -07:00
|
|
|
let doc = this.getDocument();
|
2011-01-04 07:35:05 -08:00
|
|
|
if (!doc) {
|
2010-06-25 13:29:47 -07:00
|
|
|
let fallback = this._getFallbackService();
|
2013-04-11 11:01:52 -07:00
|
|
|
return fallback.QueryInterface(Ci.nsIPromptFactory).getPrompt(domWin, iid);
|
2009-11-12 21:09:38 -08:00
|
|
|
}
|
2011-01-04 07:35:05 -08:00
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = new InternalPrompt(domWin, doc);
|
2010-06-25 13:29:47 -07:00
|
|
|
p.QueryInterface(iid);
|
|
|
|
return p;
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-06-25 13:29:47 -07:00
|
|
|
|
|
|
|
/* ---------- private memebers ---------- */
|
2010-09-03 12:17:00 -07:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
_getFallbackService: function _getFallbackService() {
|
|
|
|
return Components.classesByID["{7ad1b327-6dfa-46ec-9234-f2a620ea7e00}"]
|
|
|
|
.getService(Ci.nsIPromptService);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDocument: function getDocument() {
|
2010-07-13 07:36:09 -07:00
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
2010-06-25 13:29:47 -07:00
|
|
|
return win ? win.document : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIPromptService and nsIPromptService2 methods proxy to our Prompt class
|
|
|
|
// if we can show in-document popups, or to the fallback service otherwise.
|
|
|
|
callProxy: function(aMethod, aArguments) {
|
2011-01-04 07:35:05 -08:00
|
|
|
let prompt;
|
2011-10-24 10:05:18 -07:00
|
|
|
let doc = this.getDocument();
|
|
|
|
if (!doc) {
|
|
|
|
let fallback = this._getFallbackService();
|
|
|
|
return fallback[aMethod].apply(fallback, aArguments);
|
2009-11-12 21:09:38 -08:00
|
|
|
}
|
2011-10-24 10:05:18 -07:00
|
|
|
let domWin = aArguments[0];
|
2013-06-12 09:14:57 -07:00
|
|
|
prompt = new InternalPrompt(domWin, doc);
|
2011-01-04 07:35:05 -08:00
|
|
|
return prompt[aMethod].apply(prompt, Array.prototype.slice.call(aArguments, 1));
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2009-11-12 21:09:38 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
/* ---------- nsIPromptService ---------- */
|
2009-11-12 21:09:38 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
alert: function() {
|
2010-10-31 21:02:40 -07:00
|
|
|
return this.callProxy("alert", arguments);
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-06-25 13:29:47 -07:00
|
|
|
alertCheck: function() {
|
|
|
|
return this.callProxy("alertCheck", arguments);
|
|
|
|
},
|
|
|
|
confirm: function() {
|
|
|
|
return this.callProxy("confirm", arguments);
|
|
|
|
},
|
|
|
|
confirmCheck: function() {
|
|
|
|
return this.callProxy("confirmCheck", arguments);
|
|
|
|
},
|
|
|
|
confirmEx: function() {
|
|
|
|
return this.callProxy("confirmEx", arguments);
|
|
|
|
},
|
|
|
|
prompt: function() {
|
|
|
|
return this.callProxy("prompt", arguments);
|
|
|
|
},
|
|
|
|
promptUsernameAndPassword: function() {
|
|
|
|
return this.callProxy("promptUsernameAndPassword", arguments);
|
|
|
|
},
|
|
|
|
promptPassword: function() {
|
|
|
|
return this.callProxy("promptPassword", arguments);
|
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
return this.callProxy("select", arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* ---------- nsIPromptService2 ---------- */
|
|
|
|
promptAuth: function() {
|
|
|
|
return this.callProxy("promptAuth", arguments);
|
|
|
|
},
|
|
|
|
asyncPromptAuth: function() {
|
|
|
|
return this.callProxy("asyncPromptAuth", arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
function InternalPrompt(aDomWin, aDocument) {
|
2010-06-25 13:29:47 -07:00
|
|
|
this._domWin = aDomWin;
|
|
|
|
this._doc = aDocument;
|
|
|
|
}
|
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
InternalPrompt.prototype = {
|
2010-06-25 13:29:47 -07:00
|
|
|
_domWin: null,
|
|
|
|
_doc: null,
|
2009-11-12 21:09:38 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPrompt, Ci.nsIAuthPrompt, Ci.nsIAuthPrompt2]),
|
|
|
|
|
|
|
|
/* ---------- internal methods ---------- */
|
2013-06-12 09:14:57 -07:00
|
|
|
_getPrompt: function _getPrompt(aTitle, aText, aButtons, aCheckMsg, aCheckState) {
|
|
|
|
let p = new Prompt({
|
|
|
|
window: this._domWin,
|
|
|
|
title: aTitle,
|
|
|
|
message: aText,
|
|
|
|
buttons: aButtons || [
|
|
|
|
PromptUtils.getLocaleString("OK"),
|
|
|
|
PromptUtils.getLocaleString("Cancel")
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't bother to check for aCheckSate. For nsIPomptService interfaces, aCheckState is an
|
|
|
|
// out param and is required to be defined. If we've gotten here without it, something
|
|
|
|
// has probably gone wrong and we should fail
|
|
|
|
if (aCheckMsg) {
|
|
|
|
p.addCheckbox({
|
|
|
|
label: PromptUtils.cleanUpLabel(aCheckMsg),
|
|
|
|
checked: aCheckState.value
|
|
|
|
});
|
|
|
|
}
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
return p;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* Shows a native prompt, and then spins the event loop for this thread while we wait
|
|
|
|
* for a response
|
|
|
|
*/
|
|
|
|
showPrompt: function showPrompt(aPrompt) {
|
2013-03-26 21:53:24 -07:00
|
|
|
let callerWin;
|
|
|
|
if (this._domWin) {
|
2012-03-12 12:53:45 -07:00
|
|
|
PromptUtils.fireDialogEvent(this._domWin, "DOMWillOpenModalDialog");
|
2013-03-26 21:53:24 -07:00
|
|
|
let winUtils = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
callerWin = winUtils.enterModalStateWithWindow();
|
|
|
|
}
|
2012-03-06 13:56:16 -08:00
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
let retval = null;
|
|
|
|
aPrompt.show(function(data) {
|
|
|
|
retval = data;
|
|
|
|
});
|
2013-03-26 21:53:24 -07:00
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
// Spin this thread while we wait for a result
|
|
|
|
let thread = Services.tm.currentThread;
|
|
|
|
while (retval == null)
|
|
|
|
thread.processNextEvent(true);
|
2013-03-26 21:53:24 -07:00
|
|
|
|
|
|
|
if (this._domWin) {
|
|
|
|
let winUtils = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
winUtils.leaveModalStateWithWindow(callerWin);
|
|
|
|
PromptUtils.fireDialogEvent(this._domWin, "DOMModalDialogClosed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-06-25 13:29:47 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ---------- interface disambiguation ----------
|
|
|
|
*
|
|
|
|
* XXX Copied from nsPrompter.js.
|
|
|
|
*
|
|
|
|
* nsIPrompt and nsIAuthPrompt share 3 method names with slightly
|
|
|
|
* different arguments. All but prompt() have the same number of
|
|
|
|
* arguments, so look at the arg types to figure out how we're being
|
|
|
|
* called. :-(
|
|
|
|
*/
|
|
|
|
prompt: function prompt() {
|
2010-11-22 18:31:40 -08:00
|
|
|
if (gPromptService.inContentProcess)
|
|
|
|
return gPromptService.callProxy("prompt", [null].concat(Array.prototype.slice.call(arguments)));
|
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
// also, the nsIPrompt flavor has 5 args instead of 6.
|
|
|
|
if (typeof arguments[2] == "object")
|
|
|
|
return this.nsIPrompt_prompt.apply(this, arguments);
|
|
|
|
else
|
|
|
|
return this.nsIAuthPrompt_prompt.apply(this, arguments);
|
|
|
|
},
|
2009-09-02 09:15:26 -07:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
promptUsernameAndPassword: function promptUsernameAndPassword() {
|
|
|
|
// Both have 6 args, so use types.
|
|
|
|
if (typeof arguments[2] == "object")
|
|
|
|
return this.nsIPrompt_promptUsernameAndPassword.apply(this, arguments);
|
|
|
|
else
|
|
|
|
return this.nsIAuthPrompt_promptUsernameAndPassword.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
promptPassword: function promptPassword() {
|
|
|
|
// Both have 5 args, so use types.
|
|
|
|
if (typeof arguments[2] == "object")
|
|
|
|
return this.nsIPrompt_promptPassword.apply(this, arguments);
|
|
|
|
else
|
|
|
|
return this.nsIAuthPrompt_promptPassword.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
/* ---------- nsIPrompt ---------- */
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
alert: function alert(aTitle, aText) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, [ PromptUtils.getLocaleString("OK") ]);
|
|
|
|
this.showPrompt(p);
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
alertCheck: function alertCheck(aTitle, aText, aCheckMsg, aCheckState) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, [ PromptUtils.getLocaleString("OK") ], aCheckMsg, aCheckState);
|
|
|
|
let data = this.showPrompt(p);
|
|
|
|
if (aCheckState)
|
|
|
|
aCheckState.value = data.checkbox0 == "true";
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
confirm: function confirm(aTitle, aText) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText);
|
|
|
|
let data = this.showPrompt(p);
|
2011-10-24 10:05:18 -07:00
|
|
|
return (data.button == 0);
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
confirmCheck: function confirmCheck(aTitle, aText, aCheckMsg, aCheckState) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, null, aCheckMsg, aCheckState);
|
|
|
|
let data = this.showPrompt(p);
|
2012-07-19 12:08:56 -07:00
|
|
|
let ok = data.button == 0;
|
2013-06-12 09:14:57 -07:00
|
|
|
if (aCheckState)
|
|
|
|
aCheckState.value = data.checkbox0 == "true";
|
2012-07-19 12:08:56 -07:00
|
|
|
return ok;
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
2009-11-12 21:09:38 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
confirmEx: function confirmEx(aTitle, aText, aButtonFlags, aButton0,
|
|
|
|
aButton1, aButton2, aCheckMsg, aCheckState) {
|
2011-10-24 10:05:18 -07:00
|
|
|
let buttons = [];
|
2009-09-02 09:15:26 -07:00
|
|
|
let titles = [aButton0, aButton1, aButton2];
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
let bTitle = null;
|
|
|
|
switch (aButtonFlags & 0xff) {
|
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_OK :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("OK");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_CANCEL :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("Cancel");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_YES :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("Yes");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_NO :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("No");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_SAVE :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("Save");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_DONT_SAVE :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("DontSave");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_REVERT :
|
2010-06-25 13:29:47 -07:00
|
|
|
bTitle = PromptUtils.getLocaleString("Revert");
|
2011-10-24 10:05:18 -07:00
|
|
|
break;
|
2009-09-02 09:15:26 -07:00
|
|
|
case Ci.nsIPromptService.BUTTON_TITLE_IS_STRING :
|
2012-01-06 11:36:35 -08:00
|
|
|
bTitle = PromptUtils.cleanUpLabel(titles[i]);
|
2009-09-02 09:15:26 -07:00
|
|
|
break;
|
|
|
|
}
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2011-10-24 10:05:18 -07:00
|
|
|
if (bTitle)
|
2013-01-15 12:31:24 -08:00
|
|
|
buttons.push(bTitle);
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2009-09-02 09:15:26 -07:00
|
|
|
aButtonFlags >>= 8;
|
|
|
|
}
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, buttons, aCheckMsg, aCheckState);
|
|
|
|
let data = this.showPrompt(p);
|
|
|
|
if (aCheckState)
|
|
|
|
aCheckState.value = data.checkbox0 == "true";
|
2011-10-24 10:05:18 -07:00
|
|
|
return data.button;
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
nsIPrompt_prompt: function nsIPrompt_prompt(aTitle, aText, aValue, aCheckMsg, aCheckState) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, null, aCheckMsg, aCheckState);
|
|
|
|
p.addTextbox({
|
|
|
|
value: aValue.value,
|
|
|
|
autofocus: true
|
|
|
|
});
|
|
|
|
let data = this.showPrompt(p);
|
2011-10-24 10:05:18 -07:00
|
|
|
|
2012-07-19 12:08:56 -07:00
|
|
|
let ok = data.button == 0;
|
2013-06-12 09:14:57 -07:00
|
|
|
if (aCheckState)
|
|
|
|
aCheckState.value = data.checkbox0 == "true";
|
2012-07-19 12:08:56 -07:00
|
|
|
if (ok)
|
2013-06-12 09:14:57 -07:00
|
|
|
aValue.value = data.textbox0;
|
2012-07-19 12:08:56 -07:00
|
|
|
return ok;
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
nsIPrompt_promptPassword: function nsIPrompt_promptPassword(
|
|
|
|
aTitle, aText, aPassword, aCheckMsg, aCheckState) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, null, aCheckMsg, aCheckState);
|
|
|
|
p.addPassword({
|
|
|
|
value: aPassword.value || "",
|
|
|
|
autofocus: true,
|
|
|
|
hint: PromptUtils.getLocaleString("password", "passwdmgr")
|
|
|
|
});
|
|
|
|
let data = this.showPrompt(p);
|
2011-10-24 10:05:18 -07:00
|
|
|
|
2012-07-19 12:08:56 -07:00
|
|
|
let ok = data.button == 0;
|
2013-06-12 09:14:57 -07:00
|
|
|
if (aCheckState)
|
|
|
|
aCheckState.value = data.checkbox0 == "true";
|
2012-07-19 12:08:56 -07:00
|
|
|
if (ok)
|
2013-06-12 09:14:57 -07:00
|
|
|
aPassword.value = data.password0;
|
2012-07-19 12:08:56 -07:00
|
|
|
return ok;
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
nsIPrompt_promptUsernameAndPassword: function nsIPrompt_promptUsernameAndPassword(
|
|
|
|
aTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, null, aCheckMsg, aCheckState);
|
|
|
|
p.addTextbox({
|
|
|
|
value: aUsername.value,
|
|
|
|
autofocus: true,
|
|
|
|
hint: PromptUtils.getLocaleString("username", "passwdmgr")
|
|
|
|
}).addPassword({
|
|
|
|
value: aPassword.value,
|
|
|
|
hint: PromptUtils.getLocaleString("password", "passwdmgr")
|
|
|
|
});
|
|
|
|
let data = this.showPrompt(p);
|
2012-07-19 12:08:56 -07:00
|
|
|
|
|
|
|
let ok = data.button == 0;
|
2013-06-12 09:14:57 -07:00
|
|
|
if (aCheckState)
|
|
|
|
aCheckState.value = data.checkbox0 == "true";
|
2012-07-19 12:08:56 -07:00
|
|
|
if (ok) {
|
2013-06-12 09:14:57 -07:00
|
|
|
aUsername.value = data.textbox0;
|
|
|
|
aPassword.value = data.password0;
|
2012-07-19 12:08:56 -07:00
|
|
|
}
|
|
|
|
return ok;
|
2009-09-02 09:15:26 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
select: function select(aTitle, aText, aCount, aSelectList, aOutSelection) {
|
2013-06-12 09:14:57 -07:00
|
|
|
let p = this._getPrompt(aTitle, aText, [ PromptUtils.getLocaleString("OK") ], "", { value: false });
|
|
|
|
p.addMenulist({ values: aSelectList });
|
|
|
|
let data = this.showPrompt(p);
|
2012-07-19 12:08:56 -07:00
|
|
|
|
|
|
|
let ok = data.button == 0;
|
|
|
|
if (ok)
|
2013-06-12 09:14:57 -07:00
|
|
|
aOutSelection.value = data.menulist0;
|
2012-07-19 12:08:56 -07:00
|
|
|
|
|
|
|
return ok;
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/* ---------- nsIAuthPrompt ---------- */
|
|
|
|
|
|
|
|
nsIAuthPrompt_prompt : function (title, text, passwordRealm, savePassword, defaultText, result) {
|
2010-09-14 14:58:10 -07:00
|
|
|
// TODO: Port functions from nsLoginManagerPrompter.js to here
|
2010-06-25 13:29:47 -07:00
|
|
|
if (defaultText)
|
|
|
|
result.value = defaultText;
|
|
|
|
return this.nsIPrompt_prompt(title, text, result, null, {});
|
|
|
|
},
|
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
nsIAuthPrompt_promptUsernameAndPassword : function (aTitle, aText, aPasswordRealm, aSavePassword, aUser, aPass) {
|
|
|
|
return nsIAuthPrompt_loginPrompt(aTitle, aText, aPasswordRealm, aSavePassword, aUser, aPass);
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
nsIAuthPrompt_promptPassword : function (aTitle, aText, aPasswordRealm, aSavePassword, aPass) {
|
|
|
|
return nsIAuthPrompt_loginPrompt(aTitle, aText, aPasswordRealm, aSavePassword, null, aPass);
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
nsIAuthPrompt_loginPrompt: function(aTitle, aPasswordRealm, aSavePassword, aUser, aPass) {
|
|
|
|
let checkMsg = null;
|
|
|
|
let check = { value: false };
|
|
|
|
let [hostname, realm, aUser] = PromptUtils.getHostnameAndRealm(aPasswordRealm);
|
|
|
|
|
|
|
|
let canSave = PromptUtils.canSaveLogin(hostname, aSavePassword);
|
|
|
|
if (canSave) {
|
|
|
|
// Look for existing logins.
|
|
|
|
let foundLogins = PromptUtils.pwmgr.findLogins({}, hostname, null, realm);
|
|
|
|
[checkMsg, check] = PromptUtils.getUsernameAndPassword(foundLogins, aUser, aPass);
|
|
|
|
}
|
|
|
|
|
|
|
|
let ok = false;
|
|
|
|
if (aUser)
|
|
|
|
ok = this.nsIPrompt_promptUsernameAndPassword(aTitle, aText, aUser, aPass, checkMsg, check);
|
|
|
|
else
|
|
|
|
ok = this.nsIPrompt_promptPassword(aTitle, aText, aPass, checkMsg, check);
|
|
|
|
|
|
|
|
if (ok && canSave && check.value)
|
|
|
|
PromptUtils.savePassword(hostname, realm, aUser, aPass);
|
|
|
|
|
2012-07-19 12:08:56 -07:00
|
|
|
return ok;
|
|
|
|
},
|
2010-09-14 14:58:13 -07:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
/* ---------- nsIAuthPrompt2 ---------- */
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-09-14 14:58:10 -07:00
|
|
|
promptAuth: function promptAuth(aChannel, aLevel, aAuthInfo) {
|
2010-09-14 14:58:13 -07:00
|
|
|
let checkMsg = null;
|
|
|
|
let check = { value: false };
|
2010-06-25 13:29:47 -07:00
|
|
|
let message = PromptUtils.makeDialogText(aChannel, aAuthInfo);
|
2010-09-14 14:58:13 -07:00
|
|
|
let [username, password] = PromptUtils.getAuthInfo(aAuthInfo);
|
|
|
|
let [hostname, httpRealm] = PromptUtils.getAuthTarget(aChannel, aAuthInfo);
|
|
|
|
let foundLogins = PromptUtils.pwmgr.findLogins({}, hostname, null, httpRealm);
|
|
|
|
|
|
|
|
let canSave = PromptUtils.canSaveLogin(hostname, null);
|
|
|
|
if (canSave)
|
|
|
|
[checkMsg, check] = PromptUtils.getUsernameAndPassword(foundLogins, username, password);
|
|
|
|
|
|
|
|
if (username.value && password.value) {
|
|
|
|
PromptUtils.setAuthInfo(aAuthInfo, username.value, password.value);
|
|
|
|
}
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2011-07-28 11:01:05 -07:00
|
|
|
let canAutologin = false;
|
|
|
|
if (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY &&
|
|
|
|
!(aAuthInfo.flags & Ci.nsIAuthInformation.PREVIOUS_FAILED) &&
|
|
|
|
Services.prefs.getBoolPref("signon.autologin.proxy"))
|
|
|
|
canAutologin = true;
|
|
|
|
|
|
|
|
let ok = canAutologin;
|
|
|
|
if (!ok && aAuthInfo.flags & Ci.nsIAuthInformation.ONLY_PASSWORD)
|
2010-09-14 14:58:13 -07:00
|
|
|
ok = this.nsIPrompt_promptPassword(null, message, password, checkMsg, check);
|
2011-07-28 11:01:05 -07:00
|
|
|
else if (!ok)
|
2010-09-14 14:58:13 -07:00
|
|
|
ok = this.nsIPrompt_promptUsernameAndPassword(null, message, username, password, checkMsg, check);
|
|
|
|
|
|
|
|
PromptUtils.setAuthInfo(aAuthInfo, username.value, password.value);
|
|
|
|
|
2011-07-28 11:01:05 -07:00
|
|
|
if (ok && canSave && check.value)
|
2010-09-14 14:58:13 -07:00
|
|
|
PromptUtils.savePassword(foundLogins, username, password, hostname, httpRealm);
|
|
|
|
|
|
|
|
return ok;
|
2009-09-04 10:40:03 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2011-07-28 11:01:05 -07:00
|
|
|
_asyncPrompts: {},
|
|
|
|
_asyncPromptInProgress: false,
|
|
|
|
|
|
|
|
_doAsyncPrompt : function() {
|
|
|
|
if (this._asyncPromptInProgress)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Find the first prompt key we have in the queue
|
|
|
|
let hashKey = null;
|
|
|
|
for (hashKey in this._asyncPrompts)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!hashKey)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If login manger has logins for this host, defer prompting if we're
|
|
|
|
// already waiting on a master password entry.
|
|
|
|
let prompt = this._asyncPrompts[hashKey];
|
|
|
|
let prompter = prompt.prompter;
|
|
|
|
let [hostname, httpRealm] = PromptUtils.getAuthTarget(prompt.channel, prompt.authInfo);
|
|
|
|
let foundLogins = PromptUtils.pwmgr.findLogins({}, hostname, null, httpRealm);
|
|
|
|
if (foundLogins.length > 0 && PromptUtils.pwmgr.uiBusy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._asyncPromptInProgress = true;
|
|
|
|
prompt.inProgress = true;
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
let runnable = {
|
|
|
|
run: function() {
|
|
|
|
let ok = false;
|
|
|
|
try {
|
|
|
|
ok = prompter.promptAuth(prompt.channel, prompt.level, prompt.authInfo);
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("_doAsyncPrompt:run: " + e + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete self._asyncPrompts[hashKey];
|
|
|
|
prompt.inProgress = false;
|
|
|
|
self._asyncPromptInProgress = false;
|
|
|
|
|
|
|
|
for each (let consumer in prompt.consumers) {
|
|
|
|
if (!consumer.callback)
|
|
|
|
// Not having a callback means that consumer didn't provide it
|
|
|
|
// or canceled the notification
|
|
|
|
continue;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (ok)
|
|
|
|
consumer.callback.onAuthAvailable(consumer.context, prompt.authInfo);
|
|
|
|
else
|
|
|
|
consumer.callback.onAuthCancelled(consumer.context, true);
|
|
|
|
} catch (e) { /* Throw away exceptions caused by callback */ }
|
|
|
|
}
|
|
|
|
self._doAsyncPrompt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.tm.mainThread.dispatch(runnable, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
},
|
|
|
|
|
2010-09-14 14:58:10 -07:00
|
|
|
asyncPromptAuth: function asyncPromptAuth(aChannel, aCallback, aContext, aLevel, aAuthInfo) {
|
2011-07-28 11:01:05 -07:00
|
|
|
let cancelable = null;
|
|
|
|
try {
|
|
|
|
// If the user submits a login but it fails, we need to remove the
|
|
|
|
// notification bar that was displayed. Conveniently, the user will
|
|
|
|
// be prompted for authentication again, which brings us here.
|
|
|
|
//this._removeLoginNotifications();
|
|
|
|
|
|
|
|
cancelable = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICancelable]),
|
|
|
|
callback: aCallback,
|
|
|
|
context: aContext,
|
|
|
|
cancel: function() {
|
|
|
|
this.callback.onAuthCancelled(this.context, false);
|
|
|
|
this.callback = null;
|
|
|
|
this.context = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let [hostname, httpRealm] = PromptUtils.getAuthTarget(aChannel, aAuthInfo);
|
|
|
|
let hashKey = aLevel + "|" + hostname + "|" + httpRealm;
|
|
|
|
let asyncPrompt = this._asyncPrompts[hashKey];
|
|
|
|
if (asyncPrompt) {
|
|
|
|
asyncPrompt.consumers.push(cancelable);
|
|
|
|
return cancelable;
|
|
|
|
}
|
|
|
|
|
|
|
|
asyncPrompt = {
|
|
|
|
consumers: [cancelable],
|
|
|
|
channel: aChannel,
|
|
|
|
authInfo: aAuthInfo,
|
|
|
|
level: aLevel,
|
|
|
|
inProgress : false,
|
|
|
|
prompter: this
|
|
|
|
}
|
|
|
|
|
|
|
|
this._asyncPrompts[hashKey] = asyncPrompt;
|
|
|
|
this._doAsyncPrompt();
|
|
|
|
} catch (e) {
|
|
|
|
Cu.reportError("PromptService: " + e + "\n");
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return cancelable;
|
2010-06-25 13:29:47 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let PromptUtils = {
|
2010-09-14 14:58:13 -07:00
|
|
|
getLocaleString: function pu_getLocaleString(aKey, aService) {
|
|
|
|
if (aService == "passwdmgr")
|
2012-01-06 11:36:35 -08:00
|
|
|
return this.cleanUpLabel(this.passwdBundle.GetStringFromName(aKey));
|
|
|
|
|
|
|
|
return this.cleanUpLabel(this.bundle.GetStringFromName(aKey));
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// Copied from chrome://global/content/commonDialog.js
|
|
|
|
//
|
|
|
|
cleanUpLabel: function cleanUpLabel(aLabel) {
|
|
|
|
// This is for labels which may contain embedded access keys.
|
|
|
|
// If we end in (&X) where X represents the access key, optionally preceded
|
|
|
|
// by spaces and/or followed by the ':' character,
|
|
|
|
// remove the access key placeholder + leading spaces from the label.
|
|
|
|
// Otherwise a character preceded by one but not two &s is the access key.
|
|
|
|
|
|
|
|
// Note that if you change the following code, see the comment of
|
|
|
|
// nsTextBoxFrame::UpdateAccessTitle.
|
|
|
|
if (!aLabel)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if (/ *\(\&([^&])\)(:)?$/.test(aLabel)) {
|
|
|
|
aLabel = RegExp.leftContext + RegExp.$2;
|
|
|
|
} else if (/^(.*[^&])?\&(([^&]).*$)/.test(aLabel)) {
|
|
|
|
aLabel = RegExp.$1 + RegExp.$2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special code for using that & symbol
|
|
|
|
aLabel = aLabel.replace(/\&\&/g, "&");
|
2010-09-14 14:58:10 -07:00
|
|
|
|
2012-01-06 11:36:35 -08:00
|
|
|
return aLabel;
|
2010-06-25 13:29:47 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
get pwmgr() {
|
|
|
|
delete this.pwmgr;
|
|
|
|
return this.pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
|
|
},
|
|
|
|
|
|
|
|
getHostnameAndRealm: function pu_getHostnameAndRealm(aRealmString) {
|
|
|
|
let httpRealm = /^.+ \(.+\)$/;
|
|
|
|
if (httpRealm.test(aRealmString))
|
|
|
|
return [null, null, null];
|
|
|
|
|
|
|
|
let uri = Services.io.newURI(aRealmString, null, null);
|
|
|
|
let pathname = "";
|
|
|
|
|
|
|
|
if (uri.path != "/")
|
|
|
|
pathname = uri.path;
|
|
|
|
|
|
|
|
let formattedHostname = this._getFormattedHostname(uri);
|
|
|
|
return [formattedHostname, formattedHostname + pathname, uri.username];
|
|
|
|
},
|
|
|
|
|
|
|
|
canSaveLogin: function pu_canSaveLogin(aHostname, aSavePassword) {
|
|
|
|
let canSave = !this._inPrivateBrowsing && this.pwmgr.getLoginSavingEnabled(aHostname)
|
|
|
|
if (aSavePassword)
|
|
|
|
canSave = canSave && (aSavePassword == Ci.nsIAuthPrompt.SAVE_PASSWORD_PERMANENTLY)
|
|
|
|
return canSave;
|
|
|
|
},
|
|
|
|
|
|
|
|
getUsernameAndPassword: function pu_getUsernameAndPassword(aFoundLogins, aUser, aPass) {
|
|
|
|
let checkLabel = null;
|
|
|
|
let check = { value: false };
|
|
|
|
let selectedLogin;
|
|
|
|
|
2013-03-12 08:47:12 -07:00
|
|
|
checkLabel = this.getLocaleString("saveButton", "passwdmgr");
|
2010-09-14 14:58:13 -07:00
|
|
|
|
|
|
|
// XXX Like the original code, we can't deal with multiple
|
|
|
|
// account selection. (bug 227632)
|
|
|
|
if (aFoundLogins.length > 0) {
|
|
|
|
selectedLogin = aFoundLogins[0];
|
|
|
|
|
|
|
|
// If the caller provided a username, try to use it. If they
|
|
|
|
// provided only a password, this will try to find a password-only
|
|
|
|
// login (or return null if none exists).
|
|
|
|
if (aUser.value)
|
|
|
|
selectedLogin = this.findLogin(aFoundLogins, "username", aUser.value);
|
|
|
|
|
|
|
|
if (selectedLogin) {
|
|
|
|
check.value = true;
|
|
|
|
aUser.value = selectedLogin.username;
|
|
|
|
// If the caller provided a password, prefer it.
|
|
|
|
if (!aPass.value)
|
|
|
|
aPass.value = selectedLogin.password;
|
|
|
|
}
|
2009-09-04 10:40:03 -07:00
|
|
|
}
|
2010-09-14 14:58:13 -07:00
|
|
|
|
|
|
|
return [checkLabel, check];
|
|
|
|
},
|
|
|
|
|
|
|
|
findLogin: function pu_findLogin(aLogins, aName, aValue) {
|
|
|
|
for (let i = 0; i < aLogins.length; i++)
|
|
|
|
if (aLogins[i][aName] == aValue)
|
|
|
|
return aLogins[i];
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
savePassword: function pu_savePassword(aLogins, aUser, aPass, aHostname, aRealm) {
|
|
|
|
let selectedLogin = this.findLogin(aLogins, "username", aUser.value);
|
|
|
|
|
|
|
|
// If we didn't find an existing login, or if the username
|
|
|
|
// changed, save as a new login.
|
|
|
|
if (!selectedLogin) {
|
|
|
|
// add as new
|
|
|
|
var newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
|
|
|
|
newLogin.init(aHostname, null, aRealm, aUser.value, aPass.value, "", "");
|
|
|
|
this.pwmgr.addLogin(newLogin);
|
|
|
|
} else if (aPass.value != selectedLogin.password) {
|
|
|
|
// update password
|
|
|
|
this.updateLogin(selectedLogin, aPass.value);
|
2009-09-04 10:40:03 -07:00
|
|
|
} else {
|
2010-09-14 14:58:13 -07:00
|
|
|
this.updateLogin(selectedLogin);
|
2009-09-04 10:40:03 -07:00
|
|
|
}
|
2010-09-14 14:58:13 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
updateLogin: function pu_updateLogin(aLogin, aPassword) {
|
|
|
|
let now = Date.now();
|
|
|
|
let propBag = Cc["@mozilla.org/hash-property-bag;1"].createInstance(Ci.nsIWritablePropertyBag);
|
|
|
|
if (aPassword) {
|
|
|
|
propBag.setProperty("password", aPassword);
|
|
|
|
// Explicitly set the password change time here (even though it would
|
|
|
|
// be changed automatically), to ensure that it's exactly the same
|
|
|
|
// value as timeLastUsed.
|
|
|
|
propBag.setProperty("timePasswordChanged", now);
|
2009-09-04 10:40:03 -07:00
|
|
|
}
|
2010-09-14 14:58:13 -07:00
|
|
|
propBag.setProperty("timeLastUsed", now);
|
|
|
|
propBag.setProperty("timesUsedIncrement", 1);
|
|
|
|
|
|
|
|
this.pwmgr.modifyLogin(aLogin, propBag);
|
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
// JS port of http://mxr.mozilla.org/mozilla-central/source/embedding/components/windowwatcher/src/nsPrompt.cpp#388
|
|
|
|
makeDialogText: function pu_makeDialogText(aChannel, aAuthInfo) {
|
|
|
|
let isProxy = (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY);
|
|
|
|
let isPassOnly = (aAuthInfo.flags & Ci.nsIAuthInformation.ONLY_PASSWORD);
|
|
|
|
|
|
|
|
let username = aAuthInfo.username;
|
|
|
|
let [displayHost, realm] = this.getAuthTarget(aChannel, aAuthInfo);
|
|
|
|
|
|
|
|
// Suppress "the site says: $realm" when we synthesized a missing realm.
|
|
|
|
if (!aAuthInfo.realm && !isProxy)
|
|
|
|
realm = "";
|
|
|
|
|
|
|
|
// Trim obnoxiously long realms.
|
|
|
|
if (realm.length > 150) {
|
|
|
|
realm = realm.substring(0, 150);
|
|
|
|
// Append "..." (or localized equivalent).
|
|
|
|
realm += this.ellipsis;
|
|
|
|
}
|
|
|
|
|
|
|
|
let text;
|
|
|
|
if (isProxy)
|
|
|
|
text = this.bundle.formatStringFromName("EnterLoginForProxy", [realm, displayHost], 2);
|
|
|
|
else if (isPassOnly)
|
|
|
|
text = this.bundle.formatStringFromName("EnterPasswordFor", [username, displayHost], 2);
|
|
|
|
else if (!realm)
|
|
|
|
text = this.bundle.formatStringFromName("EnterUserPasswordFor", [displayHost], 1);
|
|
|
|
else
|
|
|
|
text = this.bundle.formatStringFromName("EnterLoginForRealm", [realm, displayHost], 2);
|
|
|
|
|
|
|
|
return text;
|
2009-09-04 10:40:03 -07:00
|
|
|
},
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
// JS port of http://mxr.mozilla.org/mozilla-central/source/embedding/components/windowwatcher/public/nsPromptUtils.h#89
|
2010-09-14 14:58:13 -07:00
|
|
|
getAuthHostPort: function pu_getAuthHostPort(aChannel, aAuthInfo) {
|
2010-06-25 13:29:47 -07:00
|
|
|
let uri = aChannel.URI;
|
|
|
|
let res = { host: null, port: -1 };
|
|
|
|
if (aAuthInfo.flags & aAuthInfo.AUTH_PROXY) {
|
|
|
|
let proxy = aChannel.QueryInterface(Ci.nsIProxiedChannel);
|
|
|
|
res.host = proxy.proxyInfo.host;
|
|
|
|
res.port = proxy.proxyInfo.port;
|
|
|
|
} else {
|
|
|
|
res.host = uri.host;
|
|
|
|
res.port = uri.port;
|
2009-09-04 10:40:03 -07:00
|
|
|
}
|
|
|
|
return res;
|
2010-09-14 14:58:13 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getAuthTarget : function pu_getAuthTarget(aChannel, aAuthInfo) {
|
|
|
|
let hostname, realm;
|
|
|
|
// If our proxy is demanding authentication, don't use the
|
|
|
|
// channel's actual destination.
|
|
|
|
if (aAuthInfo.flags & Ci.nsIAuthInformation.AUTH_PROXY) {
|
|
|
|
if (!(aChannel instanceof Ci.nsIProxiedChannel))
|
|
|
|
throw "proxy auth needs nsIProxiedChannel";
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
let info = aChannel.proxyInfo;
|
|
|
|
if (!info)
|
|
|
|
throw "proxy auth needs nsIProxyInfo";
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
// Proxies don't have a scheme, but we'll use "moz-proxy://"
|
|
|
|
// so that it's more obvious what the login is for.
|
|
|
|
let idnService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
|
|
|
|
hostname = "moz-proxy://" + idnService.convertUTF8toACE(info.host) + ":" + info.port;
|
|
|
|
realm = aAuthInfo.realm;
|
|
|
|
if (!realm)
|
|
|
|
realm = hostname;
|
2010-11-22 18:31:40 -08:00
|
|
|
|
2010-09-14 14:58:13 -07:00
|
|
|
return [hostname, realm];
|
|
|
|
}
|
|
|
|
hostname = this.getFormattedHostname(aChannel.URI);
|
|
|
|
|
|
|
|
// If a HTTP WWW-Authenticate header specified a realm, that value
|
|
|
|
// will be available here. If it wasn't set or wasn't HTTP, we'll use
|
|
|
|
// the formatted hostname instead.
|
|
|
|
realm = aAuthInfo.realm;
|
|
|
|
if (!realm)
|
|
|
|
realm = hostname;
|
|
|
|
|
|
|
|
return [hostname, realm];
|
|
|
|
},
|
|
|
|
|
|
|
|
getAuthInfo : function pu_getAuthInfo(aAuthInfo) {
|
|
|
|
let flags = aAuthInfo.flags;
|
|
|
|
let username = {value: ""};
|
|
|
|
let password = {value: ""};
|
|
|
|
|
|
|
|
if (flags & Ci.nsIAuthInformation.NEED_DOMAIN && aAuthInfo.domain)
|
|
|
|
username.value = aAuthInfo.domain + "\\" + aAuthInfo.username;
|
|
|
|
else
|
|
|
|
username.value = aAuthInfo.username;
|
|
|
|
|
|
|
|
password.value = aAuthInfo.password
|
|
|
|
|
|
|
|
return [username, password];
|
|
|
|
},
|
|
|
|
|
|
|
|
setAuthInfo : function (aAuthInfo, username, password) {
|
|
|
|
var flags = aAuthInfo.flags;
|
|
|
|
if (flags & Ci.nsIAuthInformation.NEED_DOMAIN) {
|
|
|
|
// Domain is separated from username by a backslash
|
|
|
|
var idx = username.indexOf("\\");
|
|
|
|
if (idx == -1) {
|
|
|
|
aAuthInfo.username = username;
|
|
|
|
} else {
|
|
|
|
aAuthInfo.domain = username.substring(0, idx);
|
|
|
|
aAuthInfo.username = username.substring(idx+1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aAuthInfo.username = username;
|
|
|
|
}
|
|
|
|
aAuthInfo.password = password;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFormattedHostname : function pu_getFormattedHostname(uri) {
|
|
|
|
let scheme = uri.scheme;
|
|
|
|
let hostname = scheme + "://" + uri.host;
|
|
|
|
|
|
|
|
// If the URI explicitly specified a port, only include it when
|
|
|
|
// it's not the default. (We never want "http://foo.com:80")
|
|
|
|
port = uri.port;
|
|
|
|
if (port != -1) {
|
|
|
|
let handler = Services.io.getProtocolHandler(scheme);
|
|
|
|
if (port != handler.defaultPort)
|
|
|
|
hostname += ":" + port;
|
|
|
|
}
|
|
|
|
return hostname;
|
|
|
|
},
|
2012-03-06 13:56:16 -08:00
|
|
|
|
2011-10-24 10:05:18 -07:00
|
|
|
sendMessageToJava: function(aMsg) {
|
2013-02-01 17:36:38 -08:00
|
|
|
let data = Cc["@mozilla.org/android/bridge;1"].getService(Ci.nsIAndroidBridge).handleGeckoMessage(JSON.stringify(aMsg));
|
2011-10-24 10:05:18 -07:00
|
|
|
return JSON.parse(data);
|
2012-03-06 13:56:16 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
fireDialogEvent: function(aDomWin, aEventName) {
|
2012-10-22 16:20:01 -07:00
|
|
|
// accessing the document object can throw if this window no longer exists. See bug 789888.
|
|
|
|
try {
|
|
|
|
if (!aDomWin.document)
|
|
|
|
return;
|
|
|
|
let event = aDomWin.document.createEvent("Events");
|
|
|
|
event.initEvent(aEventName, true, true);
|
2013-01-16 13:10:20 -08:00
|
|
|
let winUtils = aDomWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
winUtils.dispatchEventToChromeOnly(aDomWin, event);
|
2012-10-22 16:20:01 -07:00
|
|
|
} catch(ex) {
|
|
|
|
}
|
2011-10-24 10:05:18 -07:00
|
|
|
}
|
2009-09-02 09:15:26 -07:00
|
|
|
};
|
|
|
|
|
2010-09-14 14:58:10 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(PromptUtils, "passwdBundle", function () {
|
|
|
|
return Services.strings.createBundle("chrome://passwordmgr/locale/passwordmgr.properties");
|
|
|
|
});
|
|
|
|
|
2010-06-25 13:29:47 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(PromptUtils, "bundle", function () {
|
2010-07-13 07:36:09 -07:00
|
|
|
return Services.strings.createBundle("chrome://global/locale/commonDialogs.properties");
|
2010-06-25 13:29:47 -07:00
|
|
|
});
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PromptService]);
|