(From update of attachment 295350)
*sigh* I still think propagating the nsIPromptService/nsIPromptService2 mess further up into consumers isn't the right thing to do, and is likely to cause more headaches down the road. I guess if bsmedberg says this is the lesser of two evils, then I'm probably grudgingly willing to defer to him, and grind my teeth until Mozilla 2 can save us. :-/
>+ _makeDialogText : function (aChannel,
>+ aAuthInfo) {
Nit: 1 line.
>+ var stringBundleSvc = Cc["@mozilla.org/intl/stringbundle;1"].
>+ getService(Ci.nsIStringBundleService);
>+ var stringBundle = stringBundleSvc.createBundle("chrome://global/locale/prompts.properties");
Nit: Align "Cc" and "getService" to same column. stringBundle assignment line is > 80 columns. Maybe s/stringBundleSvc/bundleSvc/ to help keep things short?
>+ var port = aChannel.URI.hostPort;
>+ var host = aChannel.URI.host;
>+ var scheme = aChannel.URI.scheme;
>+ var username = aAuthInfo.username;
>+ var password = aAuthInfo.password;
>+ var proxyAuth = aAuthInfo.AUTH_PROXY & aAuthInfo.flags;
>+ var realm = aAuthInfo.realm;
>+ var text = "";
>
>+ if (port > -1)
>+ host = host + ":" + port;
This can all be replaced with:
var [hostname, httpRealm] = this._getAuthTarget(aChannel, aAuthInfo);
>+ if (proxyAuth) {
>+ text = "EnterUserPasswordForProxy";
>+ } else {
>+ text = "EnterUserPasswordForRealm";
>+ host = scheme + "://" + host;
>+ }
Tweaking host not needed here with _getAuthTarget, can also then remove brackets.
>+ if (aAuthInfo.flags & aAuthInfo.ONLY_PASSWORD) {
>+ text = password;
This should be |text = "EnterPasswordFor";|
>+ } else if (!proxyAuth && !realm) {
>+ text = "EnterUserPasswordFor";
>+ count--;
>+ strings[0] = strings[1];
>+ }
This case goes away with _getAuthTarget(). It returns the hostname as the realm when there's no realm.
This isn't right, see next comment. [Sorry, was reviewing bits in a random order. :-)]
>+ else {
>+ var defaultUserObject = new Object();
>+ defaultUserObject.value = defaultUser;
>+ var defaultPassObject = new Object();
>+ defaultPassObject.value = defaultPass;
>+ rv = aPromptService.promptUsernameAndPassword(aParentDOMWindow, null, message, defaultUserObject, defaultPassObject, aCheckLabel, aCheckValueInOut);
This isn't right, the values entered by the user will be ignored.
You want:
var usernameInOut = { value : defaultUser }
var passwordInOut = { value : defaultPass }
rv = aPromptService.promptUsernameAndPassword(...)
if (!rv) this._SetAuthInfo(aAuthInfo, usernameInOut.value, passwordInOut.value);
(Check that rv works as expected there)
Also, nit, line is > 80 columns.
>- var ok = this._promptService.promptAuth(this._window, aChannel,
>- aLevel, aAuthInfo, checkboxLabel, checkbox);
>+ var ok = false;
>+ try {
>+ ok = this._promptService2.promptAuth(this._window, aChannel,
>+ aLevel, aAuthInfo, checkboxLabel, checkbox);
>+ } catch (e) {
>+ try {
>+ ok = this._promptPasswordAdapter (this._promptService, this._window, aChannel,
>+ aLevel, aAuthInfo, checkboxLabel, checkbox);
>+ } catch(e) { dump("exception in _promptPasswordAdapter ::: "+e+" \n"); throw e; }
>+ }
>+
I'd rather contain all this in promptPasswordAdapter()... Just s/promptAuth/promptPasswordAdapter/ in the original code, and have promptPasswordAdapter() handle the try/catch fallback.
Is there some to determine which promptService to use, without a try/catch? I'm a bit concerned that we could get into a case where promptService2.promptAuth() is what we really do want to be calling, it throws an exception [on purpose or accidentally]. Now we would be ignoring the failure and trying again with promptService1.
(From update of attachment 295350) e/nsIPromptServ ice2 mess further up into consumers isn't the right thing to do, and is likely to cause more headaches down the road. I guess if bsmedberg says this is the lesser of two evils, then I'm probably grudgingly willing to defer to him, and grind my teeth until Mozilla 2 can save us. :-/
*sigh* I still think propagating the nsIPromptServic
>Index: toolkit/ components/ passwordmgr/ src/nsLoginMana gerPrompter. js ======= ======= ======= ======= ======= ======= ======= ======= =====
>======
>+ _makeDialogText : function (aChannel,
>+ aAuthInfo) {
Nit: 1 line.
>+ var stringBundleSvc = Cc["@mozilla. org/intl/ stringbundle; 1"]. Ci.nsIStringBun dleService) ; .createBundle( "chrome: //global/ locale/ prompts. properties" );
>+ getService(
>+ var stringBundle = stringBundleSvc
Nit: Align "Cc" and "getService" to same column. stringBundle assignment line is > 80 columns. Maybe s/stringBundleS vc/bundleSvc/ to help keep things short?
>+ var port = aChannel. URI.hostPort; URI.scheme; AUTH_PROXY & aAuthInfo.flags;
>+ var host = aChannel.URI.host;
>+ var scheme = aChannel.
>+ var username = aAuthInfo.username;
>+ var password = aAuthInfo.password;
>+ var proxyAuth = aAuthInfo.
>+ var realm = aAuthInfo.realm;
>+ var text = "";
>
>+ if (port > -1)
>+ host = host + ":" + port;
This can all be replaced with:
var [hostname, httpRealm] = this._getAuthTa rget(aChannel, aAuthInfo);
>+ if (proxyAuth) { ordForProxy" ; ordForRealm" ;
>+ text = "EnterUserPassw
>+ } else {
>+ text = "EnterUserPassw
>+ host = scheme + "://" + host;
>+ }
Tweaking host not needed here with _getAuthTarget, can also then remove brackets.
>+ if (aAuthInfo.flags & aAuthInfo. ONLY_PASSWORD) {
>+ text = password;
This should be |text = "EnterPasswordF or";|
>+ } else if (!proxyAuth && !realm) { ordFor" ;
>+ text = "EnterUserPassw
>+ count--;
>+ strings[0] = strings[1];
>+ }
This case goes away with _getAuthTarget(). It returns the hostname as the realm when there's no realm.
>+ _promptPassword Adapter : function (aPromptService, ONLY_PASSWORD) { promptPassword( aParentDOMWindo w, null, message, defaultPass, aCheckLabel, aCheckValue);
...
>+ if(flags & aAuthInfo.
>+ rv = aPromptService.
>+ }
This isn't right, see next comment. [Sorry, was reviewing bits in a random order. :-)]
>+ else { ct.value = defaultUser; ct.value = defaultPass; promptUsernameA ndPassword( aParentDOMWindo w, null, message, defaultUserObject, defaultPassObject, aCheckLabel, aCheckValueInOut);
>+ var defaultUserObject = new Object();
>+ defaultUserObje
>+ var defaultPassObject = new Object();
>+ defaultPassObje
>+ rv = aPromptService.
This isn't right, the values entered by the user will be ignored.
You want:
var usernameInOut = { value : defaultUser } promptUsernameA ndPassword( ...)
this. _SetAuthInfo( aAuthInfo, usernameInOut. value, passwordInOut. value);
var passwordInOut = { value : defaultPass }
rv = aPromptService.
if (!rv)
(Check that rv works as expected there)
Also, nit, line is > 80 columns.
>- var ok = this._promptSer vice.promptAuth (this._ window, aChannel, vice2.promptAut h(this. _window, aChannel, swordAdapter (this._ promptService, this._window, aChannel, Adapter ::: "+e+" \n"); throw e; }
>- aLevel, aAuthInfo, checkboxLabel, checkbox);
>+ var ok = false;
>+ try {
>+ ok = this._promptSer
>+ aLevel, aAuthInfo, checkboxLabel, checkbox);
>+ } catch (e) {
>+ try {
>+ ok = this._promptPas
>+ aLevel, aAuthInfo, checkboxLabel, checkbox);
>+ } catch(e) { dump("exception in _promptPassword
>+ }
>+
I'd rather contain all this in promptPasswordA dapter( )... Just s/promptAuth/ promptPasswordA dapter/ in the original code, and have promptPasswordA dapter( ) handle the try/catch fallback.
Is there some to determine which promptService to use, without a try/catch? I'm a bit concerned that we could get into a case where promptService2. promptAuth( ) is what we really do want to be calling, it throws an exception [on purpose or accidentally]. Now we would be ignoring the failure and trying again with promptService1.