Permalink
Browse files

#1121: Multiple password prompts [was: Password required sites should

take credentials before attempting to download.]
  • Loading branch information...
1 parent bb00c34 commit ce114280dfa2054a7034e71d5d9998c29ba558dd @nmaier nmaier committed Jun 9, 2012
Showing with 42 additions and 5 deletions.
  1. +1 −0 chrome/content/dta/manager/tree.js
  2. +9 −5 modules/manager/connection.js
  3. +32 −0 modules/support/loggedprompter.js
View
1 chrome/content/dta/manager/tree.js
@@ -908,6 +908,7 @@ const Tree = {
},
_resume_item: function T_resumeItem(d) {
if (d.isOf(PAUSED | CANCELED)) {
+ d.liftLoginRestriction = true;
d.queue();
}
return true;
View
14 modules/manager/connection.js
@@ -206,15 +206,16 @@ Connection.prototype = {
},
// nsIInterfaceRequestor
getInterface: function DL_getInterface(iid) {
- if (iid.equals(Ci.nsIAuthPrompt)) {
- return this.d.AuthPrompts.authPrompter;
+ if (iid.equals(Ci.nsIAuthPrompt) || iid.equals(Ci.nsIAuthPrompt2)) {
+ if (this.d.liftLoginRestriction) {
+ delete this.d.liftLoginRestriction;
+ this.d.AuthPrompts.authPrompter.allowLogin(this._chan.URI);
+ }
+ return this.d.AuthPrompts.authPrompter.QueryInterface(iid);
}
if (iid.equals(Ci.nsIPrompt)) {
return this.d.AuthPrompts.prompter;
}
- if ('nsIAuthPrompt2' in Ci && iid.equals(Ci.nsIAuthPrompt2)) {
- return this.d.AuthPrompts.authPrompter.QueryInterface(Ci.nsIAuthPrompt2);
- }
return this.QueryInterface(iid);
},
@@ -475,6 +476,9 @@ Connection.prototype = {
}
if (!this.handleError()) {
log(LOG_ERROR, "handleError: Cannot recover from problem!", code);
+ if (code == 401) {
+ d.AuthPrompts.authPrompter.restrictLogin(aChannel.URI);
+ }
if ([401, 402, 407, 500, 502, 503, 504].indexOf(code) != -1 || Preferences.getExt('recoverallhttperrors', false)) {
log(LOG_DEBUG, "we got temp failure!", code);
d.pauseAndRetry();
View
32 modules/support/loggedprompter.js
@@ -10,11 +10,16 @@
* @param window Associated window (that will be the parent of any prompt dialogs)
*/
function LoggedPrompter(window) {
+ function uriToKey(uri) {
+ return JSON.stringify([uri.scheme, uri.host]);
+ }
+
/**
* Property providing nsIAuthPrompt
*/
lazy(this, "authPrompter", function() {
let _p = Services.ww.getNewAuthPrompter(window).QueryInterface(Ci.nsIAuthPrompt);
+ let restricted = new Map();
let proxy = Proxy.create({
has: function(name) name in _p,
hasOwn: function(name) name in _p,
@@ -26,6 +31,33 @@ function LoggedPrompter(window) {
return proxy;
};
}
+ if (name == "restrictLogin") {
+ return function(uri) {
+ const key = uriToKey(uri);
+ restricted.set(key, true);
+ };
+ }
+ if (name == "allowLogin") {
+ return function(uri) {
+ const key = uriToKey(uri);
+ log(LOG_DEBUG, "Lifting restriction " + key);
+ restricted.delete(key, true);
+ }
+ }
+ if (name == "asyncPromptAuth") {
+ return function(channel, cb, ctx, level, info) {
+ const key = uriToKey(channel.URI);
+ if (restricted.has(key)) {
+ log(LOG_DEBUG, "Restricted " + key);
+ cb.onAuthCancelled(ctx, true);
+ return {
+ cancel: function() {}
+ };
+ }
+ log(LOG_DEBUG, "Not restricted " + key);
+ return _p.asyncPromptAuth(channel, cb, ctx, level, info);
+ };
+ }
return _p[name];
}
});

0 comments on commit ce11428

Please sign in to comment.