From 9d5c6615dff3950a0520c1e91d43d58e41d878fa Mon Sep 17 00:00:00 2001 From: Honza Bambas Date: Mon, 20 Jul 2009 20:00:49 +0200 Subject: [PATCH] backing out 0a13ddc99c95, bug 475053 --- netwerk/base/public/nsIAuthPrompt2.idl | 24 +- netwerk/protocol/http/src/nsHttpChannel.cpp | 270 ++-------- netwerk/protocol/http/src/nsHttpChannel.h | 42 +- .../passwordmgr/src/nsLoginManagerPrompter.js | 163 +----- .../components/passwordmgr/test/Makefile.in | 2 - .../passwordmgr/test/authenticate.sjs | 73 +-- .../passwordmgr/test/subtst_prompt_async.html | 11 - .../passwordmgr/test/test_prompt_async.html | 492 ------------------ 8 files changed, 59 insertions(+), 1018 deletions(-) delete mode 100644 toolkit/components/passwordmgr/test/subtst_prompt_async.html delete mode 100644 toolkit/components/passwordmgr/test/test_prompt_async.html diff --git a/netwerk/base/public/nsIAuthPrompt2.idl b/netwerk/base/public/nsIAuthPrompt2.idl index 6ad51e63c3a8..edf5a70bbf32 100644 --- a/netwerk/base/public/nsIAuthPrompt2.idl +++ b/netwerk/base/public/nsIAuthPrompt2.idl @@ -48,7 +48,7 @@ interface nsIAuthInformation; * It can be used to prompt users for authentication information, either * synchronously or asynchronously. */ -[scriptable, uuid(651395EB-8612-4876-8AC0-A88D4DCE9E1E)] +[scriptable, uuid(447fc780-1d28-412a-91a1-466d48129c65)] interface nsIAuthPrompt2 : nsISupports { /** @name Security Levels */ @@ -110,23 +110,9 @@ interface nsIAuthPrompt2 : nsISupports * dialog and MUST call nsIAuthPromptCallback::onAuthCancelled on the provided * callback. * - * This implementation may: - * - * 1) Coalesce identical prompts. This means prompts that are guaranteed to - * want the same auth information from the user. A single prompt will be - * shown; then the callbacks for all the coalesced prompts will be notified - * with the resulting auth information. - * 2) Serialize prompts that are all in the same "context" (this might mean - * application-wide, for a given window, or something else depending on - * the user interface) so that the user is not deluged with prompts. - * - * @throw - * This method may throw any exception when the prompt fails to queue e.g - * because of out-of-memory error. It must not throw when the prompt - * could already be potentially shown to the user. In that case information - * about the failure has to come through the callback. This way we - * prevent multiple dialogs shown to the user because consumer may fall - * back to synchronous prompt on synchronous failure of this method. + * @throw NS_ERROR_NOT_IMPLEMENTED + * Asynchronous authentication prompts are not supported; + * the caller should fall back to promptUsernameAndPassword(). */ nsICancelable asyncPromptAuth(in nsIChannel aChannel, in nsIAuthPromptCallback aCallback, @@ -134,3 +120,5 @@ interface nsIAuthPrompt2 : nsISupports in PRUint32 level, in nsIAuthInformation authInfo); }; + + diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index 0a7857d7658c..4b8f707e6f63 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -83,7 +83,6 @@ #include "nsAuthInformationHolder.h" #include "nsICacheService.h" #include "nsDNSPrefetch.h" -#include "nsNetSegmentUtils.h" // True if the local cache should be bypassed when processing a request. #define BYPASS_LOCAL_CACHE(loadFlags) \ @@ -126,7 +125,6 @@ nsHttpChannel::nsHttpChannel() , mTransactionReplaced(PR_FALSE) , mUploadStreamHasHeaders(PR_FALSE) , mAuthRetryPending(PR_FALSE) - , mProxyAuth(PR_FALSE) , mSuppressDefensiveAuth(PR_FALSE) , mResuming(PR_FALSE) , mInitedCacheEntry(PR_FALSE) @@ -3119,13 +3117,13 @@ nsHttpChannel::ProcessAuthentication(PRUint32 httpStatus) } const char *challenges; - mProxyAuth = (httpStatus == 407); + PRBool proxyAuth = (httpStatus == 407); - nsresult rv = PrepareForAuthentication(mProxyAuth); + nsresult rv = PrepareForAuthentication(proxyAuth); if (NS_FAILED(rv)) return rv; - if (mProxyAuth) { + if (proxyAuth) { // only allow a proxy challenge if we have a proxy server configured. // otherwise, we could inadvertantly expose the user's proxy // credentials to an origin server. We could attempt to proceed as @@ -3150,24 +3148,12 @@ nsHttpChannel::ProcessAuthentication(PRUint32 httpStatus) NS_ENSURE_TRUE(challenges, NS_ERROR_UNEXPECTED); nsCAutoString creds; - rv = GetCredentials(challenges, mProxyAuth, creds); - if (rv == NS_ERROR_IN_PROGRESS) { - // authentication prompt has been invoked and result - // is expected asynchronously - mAuthRetryPending = PR_TRUE; - // suspend the transaction pump to stop receiving the - // unauthenticated content data. We will throw that data - // away when user provides credentials or resume the pump - // when user refuses to authenticate. - LOG(("Suspending the transaction, asynchronously prompting for credentials")); - mTransactionPump->Suspend(); - return NS_OK; - } - else if (NS_FAILED(rv)) + rv = GetCredentials(challenges, proxyAuth, creds); + if (NS_FAILED(rv)) LOG(("unable to authenticate\n")); else { // set the authentication credentials - if (mProxyAuth) + if (proxyAuth) mRequestHead.SetHeader(nsHttp::Proxy_Authorization, creds); else mRequestHead.SetHeader(nsHttp::Authorization, creds); @@ -3294,15 +3280,6 @@ nsHttpChannel::GetCredentials(const char *challenges, break; } - else if (rv == NS_ERROR_IN_PROGRESS) { - // authentication prompt has been invoked and result is - // expected asynchronously, save current challenge being - // processed and all remaining challenges to use later in - // OnAuthAvailable and now immediately return - mCurrentChallenge = challenge; - mRemainingChallenges = eol ? eol+1 : nsnull; - return rv; - } // reset the auth type and continuation state NS_IF_RELEASE(*currentContinuationState); @@ -3322,43 +3299,6 @@ nsHttpChannel::GetCredentials(const char *challenges, return rv; } -nsresult -nsHttpChannel::GetAuthorizationMembers(PRBool proxyAuth, - nsCSubstring& scheme, - const char*& host, - PRInt32& port, - nsCSubstring& path, - nsHttpAuthIdentity*& ident, - nsISupports**& continuationState) -{ - if (proxyAuth) { - NS_ASSERTION (mConnectionInfo->UsingHttpProxy(), "proxyAuth is true, but no HTTP proxy is configured!"); - - host = mConnectionInfo->ProxyHost(); - port = mConnectionInfo->ProxyPort(); - ident = &mProxyIdent; - scheme.AssignLiteral("http"); - - continuationState = &mProxyAuthContinuationState; - } - else { - host = mConnectionInfo->Host(); - port = mConnectionInfo->Port(); - ident = &mIdent; - - nsresult rv; - rv = GetCurrentPath(path); - if (NS_FAILED(rv)) return rv; - - rv = mURI->GetScheme(scheme); - if (NS_FAILED(rv)) return rv; - - continuationState = &mAuthContinuationState; - } - - return NS_OK; -} - nsresult nsHttpChannel::GetCredentialsForChallenge(const char *challenge, const char *authType, @@ -3400,16 +3340,35 @@ nsHttpChannel::GetCredentialsForChallenge(const char *challenge, PRBool identFromURI = PR_FALSE; nsISupports **continuationState; - rv = GetAuthorizationMembers(proxyAuth, scheme, host, port, path, ident, continuationState); - if (NS_FAILED(rv)) return rv; + if (proxyAuth) { + NS_ASSERTION (mConnectionInfo->UsingHttpProxy(), "proxyAuth is true, but no HTTP proxy is configured!"); + + host = mConnectionInfo->ProxyHost(); + port = mConnectionInfo->ProxyPort(); + ident = &mProxyIdent; + scheme.AssignLiteral("http"); + + continuationState = &mProxyAuthContinuationState; + } + else { + host = mConnectionInfo->Host(); + port = mConnectionInfo->Port(); + ident = &mIdent; + + rv = GetCurrentPath(path); + if (NS_FAILED(rv)) return rv; + + rv = mURI->GetScheme(scheme); + if (NS_FAILED(rv)) return rv; - if (!proxyAuth) { // if this is the first challenge, then try using the identity // specified in the URL. if (mIdent.IsEmpty()) { GetIdentityFromURI(authFlags, mIdent); identFromURI = !mIdent.IsEmpty(); } + + continuationState = &mAuthContinuationState; } // @@ -3663,163 +3622,23 @@ nsHttpChannel::PromptForIdentity(PRUint32 level, nsDependentCString(authType)); if (!holder) return NS_ERROR_OUT_OF_MEMORY; - - rv = authPrompt->AsyncPromptAuth(this, this, nsnull, level, holder, - getter_AddRefs(mAsyncPromptAuthCancelable)); - - if (NS_SUCCEEDED(rv)) { - // indicate using this error code that authentication prompt - // result is expected asynchronously - rv = NS_ERROR_IN_PROGRESS; - } - else { - // Fall back to synchronous prompt - PRBool retval = PR_FALSE; - rv = authPrompt->PromptAuth(this, level, holder, &retval); - if (NS_FAILED(rv)) - return rv; - - if (!retval) - rv = NS_ERROR_ABORT; - else - holder->SetToHttpAuthIdentity(authFlags, ident); - } + PRBool retval = PR_FALSE; + rv = authPrompt->PromptAuth(this, + level, + holder, &retval); + if (NS_FAILED(rv)) + return rv; // remember that we successfully showed the user an auth dialog if (!proxyAuth) mSuppressDefensiveAuth = PR_TRUE; - return rv; -} - -NS_IMETHODIMP nsHttpChannel::OnAuthAvailable(nsISupports *aContext, - nsIAuthInformation *aAuthInfo) -{ - LOG(("nsHttpChannel::OnAuthAvailable [this=%x]", this)); - mAsyncPromptAuthCancelable = nsnull; - - nsresult rv; - - const char *host; - PRInt32 port; - nsHttpAuthIdentity *ident; - nsCAutoString path, scheme; - nsISupports **continuationState; - rv = GetAuthorizationMembers(mProxyAuth, scheme, host, port, path, ident, continuationState); - if (NS_FAILED(rv)) - OnAuthCancelled(aContext, PR_FALSE); - - nsCAutoString realm; - ParseRealm(mCurrentChallenge.get(), realm); - - nsHttpAuthCache *authCache = gHttpHandler->AuthCache(); - nsHttpAuthEntry *entry = nsnull; - authCache->GetAuthEntryForDomain(scheme.get(), host, port, realm.get(), &entry); - - nsCOMPtr sessionStateGrip; - if (entry) - sessionStateGrip = entry->mMetaData; - - nsAuthInformationHolder* holder = - static_cast(aAuthInfo); - ident->Set(holder->Domain().get(), - holder->User().get(), - holder->Password().get()); - - nsCAutoString unused; - nsCOMPtr auth; - rv = GetAuthenticator(mCurrentChallenge.get(), unused, getter_AddRefs(auth)); - if (NS_FAILED(rv)) { - NS_ASSERTION(PR_FALSE, "GetAuthenticator failed"); - OnAuthCancelled(aContext, PR_TRUE); - return NS_OK; - } - - nsXPIDLCString creds; - rv = GenCredsAndSetEntry(auth, mProxyAuth, - scheme.get(), host, port, path.get(), - realm.get(), mCurrentChallenge.get(), *ident, sessionStateGrip, - getter_Copies(creds)); - - mCurrentChallenge.Truncate(); - if (NS_FAILED(rv)) { - OnAuthCancelled(aContext, PR_TRUE); - return NS_OK; - } - - return ContinueOnAuthAvailable(creds); -} - -NS_IMETHODIMP nsHttpChannel::OnAuthCancelled(nsISupports *aContext, - PRBool userCancel) -{ - LOG(("nsHttpChannel::OnAuthCancelled [this=%x]", this)); - mAsyncPromptAuthCancelable = nsnull; - if (userCancel) { - if (!mRemainingChallenges.IsEmpty()) { - // there are still some challenges to process, do so - nsresult rv; - - nsCAutoString creds; - rv = GetCredentials(mRemainingChallenges.get(), mProxyAuth, creds); - if (NS_SUCCEEDED(rv)) { - // GetCredentials loaded the credentials from the cache or - // some other way in a synchronous manner, process those - // credentials now - mRemainingChallenges.Truncate(); - return ContinueOnAuthAvailable(creds); - } - else if (rv == NS_ERROR_IN_PROGRESS) { - // GetCredentials successfully queued another authprompt for - // a challenge from the list, we are now waiting for the user - // to provide the credentials - return NS_OK; - } - - // otherwise, we failed... - } - - mRemainingChallenges.Truncate(); - - // ensure call of OnStartRequest of the current listener here, - // it would not be called otherwise at all - nsresult rv = CallOnStartRequest(); - - // drop mAuthRetryPending flag and resume the transaction - // this resumes load of the unauthenticated content data - mAuthRetryPending = PR_FALSE; - LOG(("Resuming the transaction, user cancelled the auth dialog")); - mTransactionPump->Resume(); - - if (NS_FAILED(rv)) - mTransactionPump->Cancel(rv); - } - - return NS_OK; -} - -nsresult -nsHttpChannel::ContinueOnAuthAvailable(const nsCSubstring& creds) -{ - if (mProxyAuth) - mRequestHead.SetHeader(nsHttp::Proxy_Authorization, creds); + if (!retval) + rv = NS_ERROR_ABORT; else - mRequestHead.SetHeader(nsHttp::Authorization, creds); - - // drop our remaining list of challenges. We don't need them, because we - // have now authenticated against a challenge and will be sending that - // information to the server (or proxy). If it doesn't accept our - // authentication it'll respond with failure and resend the challenge list - mRemainingChallenges.Truncate(); - - // setting mAuthRetryPending flag and resuming the transaction - // triggers process of throwing away the unauthenticated data already - // coming from the network - mAuthRetryPending = PR_TRUE; - LOG(("Resuming the transaction, we got credentials from user")); - mTransactionPump->Resume(); - - return NS_OK; + holder->SetToHttpAuthIdentity(authFlags, ident); + + return rv; } PRBool @@ -4077,7 +3896,6 @@ NS_INTERFACE_MAP_BEGIN(nsHttpChannel) NS_INTERFACE_MAP_ENTRY(nsITraceableChannel) NS_INTERFACE_MAP_ENTRY(nsIApplicationCacheContainer) NS_INTERFACE_MAP_ENTRY(nsIApplicationCacheChannel) - NS_INTERFACE_MAP_ENTRY(nsIAuthPromptCallback) NS_INTERFACE_MAP_END_INHERITING(nsHashPropertyBag) //----------------------------------------------------------------------------- @@ -4125,8 +3943,6 @@ nsHttpChannel::Cancel(nsresult status) mTransactionPump->Cancel(status); if (mCachePump) mCachePump->Cancel(status); - if (mAsyncPromptAuthCancelable) - mAsyncPromptAuthCancelable->Cancel(status); return NS_OK; } @@ -5157,14 +4973,8 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st // keep the connection around after the transaction is finished. // nsRefPtr conn; - if (authRetry && (mCaps & NS_HTTP_STICKY_CONNECTION)) { + if (authRetry && (mCaps & NS_HTTP_STICKY_CONNECTION)) conn = mTransaction->Connection(); - // This is so far a workaround to fix leak when reusing unpersistent - // connection for authentication retry. See bug 459620 comment 4 - // for details. - if (conn && !conn->IsPersistent()) - conn = nsnull; - } // at this point, we're done with the transaction NS_RELEASE(mTransaction); diff --git a/netwerk/protocol/http/src/nsHttpChannel.h b/netwerk/protocol/http/src/nsHttpChannel.h index 6746f164c71b..6b4a304663d3 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.h +++ b/netwerk/protocol/http/src/nsHttpChannel.h @@ -84,7 +84,6 @@ #include "nsICancelable.h" #include "nsIProxiedChannel.h" #include "nsITraceableChannel.h" -#include "nsIAuthPromptCallback.h" class nsHttpResponseHead; class nsAHttpConnection; @@ -110,7 +109,6 @@ class nsHttpChannel : public nsHashPropertyBag , public nsIProxiedChannel , public nsITraceableChannel , public nsIApplicationCacheChannel - , public nsIAuthPromptCallback { public: NS_DECL_ISUPPORTS_INHERITED @@ -132,7 +130,6 @@ public: NS_DECL_NSITRACEABLECHANNEL NS_DECL_NSIAPPLICATIONCACHECONTAINER NS_DECL_NSIAPPLICATIONCACHECHANNEL - NS_DECL_NSIAUTHPROMPTCALLBACK nsHttpChannel(); virtual ~nsHttpChannel(); @@ -226,38 +223,19 @@ private: // auth specific methods nsresult PrepareForAuthentication(PRBool proxyAuth); nsresult GenCredsAndSetEntry(nsIHttpAuthenticator *, PRBool proxyAuth, const char *scheme, const char *host, PRInt32 port, const char *dir, const char *realm, const char *challenge, const nsHttpAuthIdentity &ident, nsCOMPtr &session, char **result); + nsresult GetCredentials(const char *challenges, PRBool proxyAuth, nsAFlatCString &creds); + nsresult GetCredentialsForChallenge(const char *challenge, const char *scheme, PRBool proxyAuth, nsIHttpAuthenticator *auth, nsAFlatCString &creds); nsresult GetAuthenticator(const char *challenge, nsCString &scheme, nsIHttpAuthenticator **auth); void ParseRealm(const char *challenge, nsACString &realm); void GetIdentityFromURI(PRUint32 authFlags, nsHttpAuthIdentity&); - /** - * Following three methods return NS_ERROR_IN_PROGRESS when - * nsIAuthPrompt2.asyncPromptAuth method is called. This result indicates - * the user's decision will be gathered in a callback and is not an actual - * error. - */ - nsresult GetCredentials(const char *challenges, PRBool proxyAuth, nsAFlatCString &creds); - nsresult GetCredentialsForChallenge(const char *challenge, const char *scheme, PRBool proxyAuth, nsIHttpAuthenticator *auth, nsAFlatCString &creds); nsresult PromptForIdentity(PRUint32 level, PRBool proxyAuth, const char *realm, const char *authType, PRUint32 authFlags, nsHttpAuthIdentity &); - PRBool ConfirmAuth(const nsString &bundleKey, PRBool doYesNoPrompt); void CheckForSuperfluousAuth(); void SetAuthorizationHeader(nsHttpAuthCache *, nsHttpAtom header, const char *scheme, const char *host, PRInt32 port, const char *path, nsHttpAuthIdentity &ident); void AddAuthorizationHeaders(); nsresult GetCurrentPath(nsACString &); - /** - * Return all information needed to build authorization information, - * all paramters except proxyAuth are out parameters. proxyAuth specifies - * with what authorization we work (WWW or proxy). - */ - nsresult GetAuthorizationMembers(PRBool proxyAuth, nsCSubstring& scheme, const char*& host, PRInt32& port, nsCSubstring& path, nsHttpAuthIdentity*& ident, nsISupports**& continuationState); nsresult DoAuthRetry(nsAHttpConnection *); PRBool MustValidateBasedOnQueryUrl(); - /** - * Method called to resume suspended transaction after we got credentials - * from the user. Called from OnAuthAvailable callback or OnAuthCancelled - * when credentials for next challenge were obtained synchronously. - */ - nsresult ContinueOnAuthAvailable(const nsCSubstring& creds); private: nsCOMPtr mOriginalURI; @@ -315,19 +293,6 @@ private: nsHttpAuthIdentity mIdent; nsHttpAuthIdentity mProxyIdent; - // Reference to the prompt wating in prompt queue. The channel is - // responsible to call its cancel method when user in any way cancels - // this request. - nsCOMPtr mAsyncPromptAuthCancelable; - // Saved in GetCredentials when prompt is asynchronous, the first challenge - // we obtained from the server with 401/407 response, will be processed in - // OnAuthAvailable callback. - nsCString mCurrentChallenge; - // Saved in GetCredentials when prompt is asynchronous, remaning challenges - // we have to process when user cancels the auth dialog for the current - // challenge. - nsCString mRemainingChallenges; - // Resumable channel specific data nsCString mEntityID; PRUint64 mStartPos; @@ -364,9 +329,6 @@ private: PRUint32 mTransactionReplaced : 1; PRUint32 mUploadStreamHasHeaders : 1; PRUint32 mAuthRetryPending : 1; - // True when we need to authenticate to proxy, i.e. when we get 407 - // response. Used in OnAuthAvailable and OnAuthCancelled callbacks. - PRUint32 mProxyAuth : 1; PRUint32 mSuppressDefensiveAuth : 1; PRUint32 mResuming : 1; PRUint32 mInitedCacheEntry : 1; diff --git a/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js b/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js index d7b204c8769d..4af1738ee28d 100644 --- a/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js +++ b/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js @@ -50,42 +50,18 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); * Invoked by NS_NewAuthPrompter2() * [embedding/components/windowwatcher/src/nsPrompt.cpp] */ -function LoginManagerPromptFactory() { - var observerService = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - observerService.addObserver(this, "quit-application-granted", true); -} +function LoginManagerPromptFactory() {} LoginManagerPromptFactory.prototype = { classDescription : "LoginManagerPromptFactory", contractID : "@mozilla.org/passwordmanager/authpromptfactory;1", classID : Components.ID("{749e62f4-60ae-4569-a8a2-de78b649660e}"), - QueryInterface : XPCOMUtils.generateQI([Ci.nsIPromptFactory, Ci.nsIObserver, Ci.nsISupportsWeakReference]), - - _asyncPrompts : {}, - _asyncPromptInProgress : false, - - observe : function (subject, topic, data) { - if (topic == "quit-application-granted") { - var asyncPrompts = this._asyncPrompts; - this._asyncPrompts = {}; - for each (var asyncPrompt in asyncPrompts) { - for each (var consumer in asyncPrompt.consumers) { - if (consumer.callback) { - this.log("Canceling async auth prompt callback " + consumer.callback); - try { - consumer.callback.onAuthCancelled(consumer.context, true); - } catch (e) { /* Just ignore exceptions from the callback */ } - } - } - } - } - }, + QueryInterface : XPCOMUtils.generateQI([Ci.nsIPromptFactory]), getPrompt : function (aWindow, aIID) { var prompt = new LoginManagerPrompter().QueryInterface(aIID); - prompt.init(aWindow, this); + prompt.init(aWindow); return prompt; } }; // end of LoginManagerPromptFactory implementation @@ -122,7 +98,6 @@ LoginManagerPrompter.prototype = { Ci.nsIAuthPrompt2, Ci.nsILoginManagerPrompter]), - _factory : null, _window : null, _debug : false, // mirrors signon.debug @@ -190,14 +165,6 @@ LoginManagerPrompter.prototype = { return this.__ioService; }, - __threadManager: null, - get _threadManager() { - if (!this.__threadManager) - this.__threadManager = Cc["@mozilla.org/thread-manager;1"]. - getService(Ci.nsIThreadManager); - return this.__threadManager; - }, - __ellipsis : null, get _ellipsis() { @@ -589,114 +556,10 @@ LoginManagerPrompter.prototype = { return ok; }, - asyncPromptAuth : function (aChannel, aCallback, aContext, aLevel, aAuthInfo) { - var cancelable = null; - - try { - this.log("===== asyncPromptAuth called ====="); - - // 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. - var notifyBox = this._getNotifyBox(); - if (notifyBox) - this._removeLoginNotifications(notifyBox); - - cancelable = this._newAsyncPromptConsumer(aCallback, aContext); - - var [hostname, httpRealm] = this._getAuthTarget(aChannel, aAuthInfo); - - var hashKey = aLevel + "|" + hostname + "|" + httpRealm; - this.log("Async prompt key = " + hashKey); - var asyncPrompt = this._factory._asyncPrompts[hashKey]; - if (asyncPrompt) { - this.log("Prompt bound to an existing one in the queue, callback = " + aCallback); - asyncPrompt.consumers.push(cancelable); - return cancelable; - } - - this.log("Adding new prompt to the queue, callback = " + aCallback); - asyncPrompt = { - consumers: [cancelable], - channel: aChannel, - authInfo: aAuthInfo, - level: aLevel - } - - this._factory._asyncPrompts[hashKey] = asyncPrompt; - this._doAsyncPrompt(); - } - catch (e) { - Components.utils.reportError("LoginManagerPrompter: " + - "asyncPromptAuth: " + e + "\nFalling back to promptAuth\n"); - // Fail the prompt operation to let the consumer fall back - // to synchronous promptAuth method - throw e; - } - - return cancelable; + asyncPromptAuth : function () { + return NS_ERROR_NOT_IMPLEMENTED; }, - _doAsyncPrompt : function() { - if (this._factory._asyncPromptInProgress) { - this.log("_doAsyncPrompt bypassed, already in progress"); - return; - } - - // Find the first prompt key we have in the queue - var hashKey = null; - for (hashKey in this._factory._asyncPrompts) - break; - - if (!hashKey) { - this.log("_doAsyncPrompt:run bypassed, no prompts in the queue"); - return; - } - - this._factory._asyncPromptInProgress = true; - - var self = this; - var runnable = { - run : function() { - var ok = false; - var prompt = self._factory._asyncPrompts[hashKey]; - try { - self.log("_doAsyncPrompt:run - performing the prompt for '" + hashKey + "'"); - ok = self.promptAuth( - prompt.channel, - prompt.level, - prompt.authInfo - ); - } catch (e) { - Components.utils.reportError("LoginManagerPrompter: " + - "_doAsyncPrompt:run: " + e + "\n"); - } - - delete self._factory._asyncPrompts[hashKey]; - self._factory._asyncPromptInProgress = false; - - for each (var consumer in prompt.consumers) { - if (!consumer.callback) - // Not having a callback means that consumer didn't provide it - // or canceled the notification - continue; - - self.log("Calling back to " + consumer.callback + " ok=" + ok); - 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(); - } - } - - this._threadManager.mainThread.dispatch(runnable, - Ci.nsIThread.DISPATCH_NORMAL); - this.log("_doAsyncPrompt:run dispatched"); - }, @@ -709,9 +572,8 @@ LoginManagerPrompter.prototype = { * init * */ - init : function (aWindow, aFactory) { + init : function (aWindow) { this._window = aWindow; - this._factory = aFactory || null; var prefBranch = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefService).getBranch("signon."); @@ -1356,19 +1218,6 @@ LoginManagerPrompter.prototype = { aAuthInfo.username = username; } aAuthInfo.password = password; - }, - - _newAsyncPromptConsumer : function(aCallback, aContext) { - return { - QueryInterface: XPCOMUtils.generateQI([Ci.nsICancelable]), - callback: aCallback, - context: aContext, - cancel: function() { - this.callback.onAuthCancelled(this.context, false); - this.callback = null; - this.context = null; - } - } } }; // end of LoginManagerPrompter implementation diff --git a/toolkit/components/passwordmgr/test/Makefile.in b/toolkit/components/passwordmgr/test/Makefile.in index 3dcadf217d65..9e8002d81196 100644 --- a/toolkit/components/passwordmgr/test/Makefile.in +++ b/toolkit/components/passwordmgr/test/Makefile.in @@ -74,7 +74,6 @@ MOCHI_TESTS = \ test_bug_391514.html \ test_bug_427033.html \ test_bug_444968.html \ - test_prompt_async.html \ test_notifications.html \ test_prompt.html \ test_xhr.html \ @@ -102,7 +101,6 @@ MOCHI_CONTENT = \ subtst_notifications_8.html \ subtst_notifications_9.html \ subtst_notifications_10.html \ - subtst_prompt_async.html \ $(NULL) XPCSHELL_TESTS = unit diff --git a/toolkit/components/passwordmgr/test/authenticate.sjs b/toolkit/components/passwordmgr/test/authenticate.sjs index 284aebda3fba..534bb987275c 100644 --- a/toolkit/components/passwordmgr/test/authenticate.sjs +++ b/toolkit/components/passwordmgr/test/authenticate.sjs @@ -11,16 +11,13 @@ function handleRequest(request, response) function reallyHandleRequest(request, response) { var match; - var requestAuth = true, requestProxyAuth = true; + var requestAuth = true; // Allow the caller to drive how authentication is processed via the query. // Eg, http://localhost:8888/authenticate.sjs?user=foo&realm=bar var query = request.queryString; var expected_user = "", expected_pass = "", realm = "mochitest"; - var proxy_expected_user = "", proxy_expected_pass = "", proxy_realm = "mochi-proxy"; - var huge = false; - var authHeaderCount = 1; // user=xxx match = /user=([^&]*)/.exec(query); if (match) @@ -36,31 +33,6 @@ function reallyHandleRequest(request, response) { if (match) realm = match[1]; - // proxy_user=xxx - match = /proxy_user=([^&]*)/.exec(query); - if (match) - proxy_expected_user = match[1]; - - // proxy_pass=xxx - match = /proxy_pass=([^&]*)/.exec(query); - if (match) - proxy_expected_pass = match[1]; - - // proxy_realm=xxx - match = /proxy_realm=([^&]*)/.exec(query); - if (match) - proxy_realm = match[1]; - - // huge=1 - match = /huge=1/.exec(query); - if (match) - huge = true; - - // multiple=1 - match = /multiple=([^&]*)/.exec(query); - if (match) - authHeaderCount = match[1]+0; - // Look for an authentication header, if any, in the request. // @@ -84,40 +56,16 @@ function reallyHandleRequest(request, response) { actual_pass = match[2]; } - var proxy_actual_user = "", proxy_actual_pass = ""; - if (request.hasHeader("Proxy-Authorization")) { - authHeader = request.getHeader("Proxy-Authorization"); - match = /Basic (.+)/.exec(authHeader); - if (match.length != 2) - throw "Couldn't parse auth header: " + authHeader; - - var userpass = base64ToString(match[1]); // no atob() :-( - match = /(.*):(.*)/.exec(userpass); - if (match.length != 3) - throw "Couldn't decode auth header: " + userpass; - proxy_actual_user = match[1]; - proxy_actual_pass = match[2]; - } - // Don't request authentication if the credentials we got were what we // expected. if (expected_user == actual_user && - expected_pass == actual_pass) { - requestAuth = false; - } - if (proxy_expected_user == proxy_actual_user && - proxy_expected_pass == proxy_actual_pass) { - requestProxyAuth = false; + expected_pass == actual_pass) { + requestAuth = false; } - if (requestProxyAuth) { - response.setStatusLine("1.0", 407, "Proxy authentication required"); - for (i = 0; i < authHeaderCount; ++i) - response.setHeader("Proxy-Authenticate", "basic realm=\"" + proxy_realm + "\"", true); - } else if (requestAuth) { + if (requestAuth) { response.setStatusLine("1.0", 401, "Authentication required"); - for (i = 0; i < authHeaderCount; ++i) - response.setHeader("WWW-Authenticate", "basic realm=\"" + realm + "\"", true); + response.setHeader("WWW-Authenticate", "basic realm=\"" + realm + "\"", false); } else { response.setStatusLine("1.0", 200, "OK"); } @@ -125,20 +73,9 @@ function reallyHandleRequest(request, response) { response.setHeader("Content-Type", "application/xhtml+xml", false); response.write(""); response.write("

Login: " + (requestAuth ? "FAIL" : "PASS") + "

\n"); - response.write("

Proxy: " + (requestProxyAuth ? "FAIL" : "PASS") + "

\n"); response.write("

Auth: " + authHeader + "

\n"); response.write("

User: " + actual_user + "

\n"); response.write("

Pass: " + actual_pass + "

\n"); - - if (huge) { - response.write("
"); - for (i = 0; i < 100000; i++) { - response.write("123456789\n"); - } - response.write("
"); - response.write("This is a footnote after the huge content fill"); - } - response.write(""); } diff --git a/toolkit/components/passwordmgr/test/subtst_prompt_async.html b/toolkit/components/passwordmgr/test/subtst_prompt_async.html deleted file mode 100644 index bf5a063df476..000000000000 --- a/toolkit/components/passwordmgr/test/subtst_prompt_async.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - Multiple auth request - - - - - - - diff --git a/toolkit/components/passwordmgr/test/test_prompt_async.html b/toolkit/components/passwordmgr/test/test_prompt_async.html deleted file mode 100644 index 9867cf05a58c..000000000000 --- a/toolkit/components/passwordmgr/test/test_prompt_async.html +++ /dev/null @@ -1,492 +0,0 @@ - - - - Test for Async Auth Prompt - - - - - - - - - - - - -