Bug 141285 - SingleSignon used only from form fields does not observe profile switches. r=morse/sr=alecf

This commit is contained in:
ccarlen%netscape.com 2002-05-09 14:24:24 +00:00
Родитель d9ac94fcd4
Коммит abf8ae8dcf
2 изменённых файлов: 56 добавлений и 39 удалений

Просмотреть файл

@ -73,6 +73,57 @@
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
// nsSingleSignOnProfileObserver
// Signon data is used by both nsSingleSignOnPrompt and the wallet service.
// This observer is global and initialized by the first consumer of signon data.
class nsSingleSignOnProfileObserver : public nsIObserver
{
public:
nsSingleSignOnProfileObserver() { NS_INIT_REFCNT(); }
virtual ~nsSingleSignOnProfileObserver() {}
NS_DECL_ISUPPORTS
NS_IMETHODIMP Observe(nsISupports*, const char *aTopic, const PRUnichar *someData)
{
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
SI_ClearUserData();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
SI_DeletePersistentUserData();
}
return NS_OK;
}
};
NS_IMPL_THREADSAFE_ISUPPORTS1(nsSingleSignOnProfileObserver, nsIObserver)
static nsresult EnsureSingleSignOnProfileObserver()
{
static nsSingleSignOnProfileObserver *gSignOnProfileObserver;
if (!gSignOnProfileObserver) {
nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1"));
if (!observerService)
return NS_ERROR_FAILURE;
gSignOnProfileObserver = new nsSingleSignOnProfileObserver;
if (!gSignOnProfileObserver)
return NS_ERROR_OUT_OF_MEMORY;
// The observer service holds the only ref to the observer
// It thus has the lifespan of the observer service
nsresult rv = observerService->AddObserver(gSignOnProfileObserver, "profile-before-change", PR_FALSE);
if (NS_FAILED(rv)) {
delete gSignOnProfileObserver;
gSignOnProfileObserver = nsnull;
return rv;
}
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
nsWalletlibService::nsWalletlibService()
{
@ -328,6 +379,9 @@ nsresult nsWalletlibService::Init()
}
else
NS_ASSERTION(PR_FALSE, "Could not get nsIObserverService");
rv = EnsureSingleSignOnProfileObserver();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to register profile change observer");
// Get the global document loader service...
nsCOMPtr<nsIDocumentLoader> docLoaderService =
@ -571,37 +625,10 @@ nsWalletlibService::WALLET_Decrypt (const char *crypt, PRUnichar **text) {
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsSingleSignOnProfileObserver
// nsSingleSignOnPrompt itself can't be a profile change observer because, if the
// last instance has been destroyed at the time of a profile change, there's
// nothing to get the notification.
class nsSingleSignOnProfileObserver : public nsIObserver
{
public:
nsSingleSignOnProfileObserver() { NS_INIT_REFCNT(); }
virtual ~nsSingleSignOnProfileObserver() {}
NS_DECL_ISUPPORTS
NS_IMETHODIMP Observe(nsISupports*, const char *aTopic, const PRUnichar *someData)
{
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
SI_ClearUserData();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
SI_DeletePersistentUserData();
}
return NS_OK;
}
};
NS_IMPL_THREADSAFE_ISUPPORTS1(nsSingleSignOnProfileObserver, nsIObserver)
////////////////////////////////////////////////////////////////////////////////
// nsSingleSignOnPrompt
PRBool nsSingleSignOnPrompt::mgRegisteredObserver = PR_FALSE;
NS_IMPL_THREADSAFE_ISUPPORTS2(nsSingleSignOnPrompt,
nsIAuthPromptWrapper,
nsIAuthPrompt)
@ -609,17 +636,8 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(nsSingleSignOnPrompt,
nsresult
nsSingleSignOnPrompt::Init()
{
if (!mgRegisteredObserver) {
nsSingleSignOnProfileObserver *observer = new nsSingleSignOnProfileObserver;
if (!observer)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIObserverService> svc(do_GetService("@mozilla.org/observer-service;1"));
if (!svc) return NS_ERROR_FAILURE;
// The observer service holds the only ref to the observer
// It thus has the lifespan of the observer service
svc->AddObserver(observer, "profile-before-change", PR_FALSE);
mgRegisteredObserver = PR_TRUE;
}
nsresult rv = EnsureSingleSignOnProfileObserver();
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to register profile change observer");
return NS_OK;
}

Просмотреть файл

@ -105,7 +105,6 @@ public:
protected:
nsCOMPtr<nsIPrompt> mPrompt;
static PRBool mgRegisteredObserver;
};
////////////////////////////////////////////////////////////////////////////////