diff --git a/mozilla/extensions/cookie/Makefile.in b/mozilla/extensions/cookie/Makefile.in index 048d6e18a66..a3ab29b8163 100644 --- a/mozilla/extensions/cookie/Makefile.in +++ b/mozilla/extensions/cookie/Makefile.in @@ -29,7 +29,7 @@ include $(DEPTH)/config/autoconf.mk MODULE = cookie LIBRARY_NAME = cookie IS_COMPONENT = 1 -REQUIRES = xpcom necko caps dom js widget layout appshell pref intl locale +REQUIRES = xpcom necko caps dom js widget layout appshell pref intl locale profile ifdef ENABLE_TESTS DIRS = tests diff --git a/mozilla/extensions/cookie/nsCookie.cpp b/mozilla/extensions/cookie/nsCookie.cpp index b425a0e41e6..b09f41feb5f 100644 --- a/mozilla/extensions/cookie/nsCookie.cpp +++ b/mozilla/extensions/cookie/nsCookie.cpp @@ -2236,14 +2236,11 @@ cookie_Load() { PUBLIC int COOKIE_ReadCookies() { - static PRBool sReadCookies = PR_FALSE; - - if (sReadCookies) - NS_WARNING("We are reading the cookies more than once. Probably bad"); + if (cookie_cookieList || cookie_permissionList) + NS_WARNING("We are reading the cookies when we already have some. Probably bad"); cookie_Load(); permission_Load(); - sReadCookies = PR_TRUE; return 0; } diff --git a/mozilla/extensions/cookie/nsCookieService.cpp b/mozilla/extensions/cookie/nsCookieService.cpp index 07cae8e40ab..af6a4a01b19 100644 --- a/mozilla/extensions/cookie/nsCookieService.cpp +++ b/mozilla/extensions/cookie/nsCookieService.cpp @@ -30,6 +30,8 @@ #include "nsIScriptGlobalObject.h" #include "nsIDOMWindowInternal.h" #include "nsIPrompt.h" +#include "nsIObserverService.h" +#include "nsIProfileChangeStatus.h" //////////////////////////////////////////////////////////////////////////////// @@ -37,7 +39,7 @@ //////////////////////////////////////////////////////////////////////////////// // nsCookieService Implementation -NS_IMPL_ISUPPORTS1(nsCookieService, nsICookieService); +NS_IMPL_ISUPPORTS3(nsCookieService, nsICookieService, nsIObserver, nsISupportsWeakReference); nsCookieService::nsCookieService() : mInitted(PR_FALSE) @@ -62,6 +64,13 @@ nsresult nsCookieService::Init() COOKIE_RegisterCookiePrefCallbacks(); COOKIE_ReadCookies(); + + nsresult rv; + NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv); + if (observerService) { + observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC); + } + mInitted = PR_TRUE; return NS_OK; } @@ -185,6 +194,33 @@ NS_IMETHODIMP nsCookieService::CookieEnabled(PRBool* aEnabled) } +NS_IMETHODIMP nsCookieService::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) +{ + nsresult rv = NS_OK; + + if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC)) { + // The profile has aleady changed. + + // Dump current cookies. This will be done by calling + // COOKIE_RemoveAllCookies which clears the memory-resident + // cookie table. This call does not modify the per-profile + // cookie file so it is not necessary to make this call prior + // to changing the profile. The reason the cookie file does not + // need to be updated is because the file was updated every time + // the memory-resident table changed (i.e., whenever a new cookie + // was accepted). If this condition ever changes, + // COOKIE_RemoveAllCookies would need to be done on + // PROFILE_BEFORE_CHANGE_TOPIC + + COOKIE_RemoveAllCookies(); + // Now just read them from the new profile location + COOKIE_ReadCookies(); + } + + return rv; +} + + //---------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/extensions/cookie/nsCookieService.h b/mozilla/extensions/cookie/nsCookieService.h index 3e933fbc3ea..0767f3973f3 100644 --- a/mozilla/extensions/cookie/nsCookieService.h +++ b/mozilla/extensions/cookie/nsCookieService.h @@ -24,14 +24,19 @@ #define nsCookieService_h__ #include "nsICookieService.h" +#include "nsIObserver.h" +#include "nsWeakReference.h" //////////////////////////////////////////////////////////////////////////////// -class nsCookieService : public nsICookieService { +class nsCookieService : public nsICookieService, + public nsIObserver, + public nsSupportsWeakReference { public: // nsISupports NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER NS_IMETHOD GetCookieString(nsIURI *aURL, nsString& aCookie); NS_IMETHOD GetCookieStringFromHTTP(nsIURI *aURL, nsIURI *aFirstURL, nsString& aCookie); diff --git a/mozilla/extensions/wallet/public/nsIWalletService.idl b/mozilla/extensions/wallet/public/nsIWalletService.idl index 6eedb99c8d9..5b3b79e6f28 100644 --- a/mozilla/extensions/wallet/public/nsIWalletService.idl +++ b/mozilla/extensions/wallet/public/nsIWalletService.idl @@ -80,7 +80,7 @@ interface nsIWalletService : nsISupports { [scriptable, uuid(6228d644-17fe-11d4-8cee-0060b0fc14a3)] interface nsISingleSignOnPrompt : nsIPrompt { - void init(in nsIPrompt dialogs); + void setPromptDialogs(in nsIPrompt dialogs); }; %{C++ diff --git a/mozilla/extensions/wallet/src/nsWalletFactory.cpp b/mozilla/extensions/wallet/src/nsWalletFactory.cpp index 6a103685caa..70db98ec030 100644 --- a/mozilla/extensions/wallet/src/nsWalletFactory.cpp +++ b/mozilla/extensions/wallet/src/nsWalletFactory.cpp @@ -27,15 +27,15 @@ #include "nsWalletService.h" // Define the constructor function for the nsWalletlibService -NS_GENERIC_FACTORY_CONSTRUCTOR(nsWalletlibService) - +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWalletlibService, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSingleSignOnPrompt, Init) // The list of components we register static nsModuleComponentInfo components[] = { { NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID, NS_WALLETSERVICE_CONTRACTID, nsWalletlibServiceConstructor }, { NS_SINGLESIGNONPROMPT_CLASSNAME, NS_SINGLESIGNONPROMPT_CID, - NS_SINGLESIGNONPROMPT_CONTRACTID, nsSingleSignOnPrompt::Create } + NS_SINGLESIGNONPROMPT_CONTRACTID, nsSingleSignOnPromptConstructor } }; NS_IMPL_NSGETMODULE("nsWalletModule", components) diff --git a/mozilla/extensions/wallet/src/nsWalletService.cpp b/mozilla/extensions/wallet/src/nsWalletService.cpp index 0fc7fb147cf..d9b07ada5ef 100644 --- a/mozilla/extensions/wallet/src/nsWalletService.cpp +++ b/mozilla/extensions/wallet/src/nsWalletService.cpp @@ -43,6 +43,7 @@ #include "nsINetSupportDialogService.h" #include "nsIInterfaceRequestor.h" #include "nsIPrompt.h" +#include "nsIProfileChangeStatus.h" // for making the leap from nsIDOMWindowInternal -> nsIPresShell #include "nsIScriptGlobalObject.h" @@ -53,9 +54,6 @@ static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); nsWalletlibService::nsWalletlibService() { NS_INIT_REFCNT(); - ++mRefCnt; // Stabilization that can't accidentally |Release()| me - Init(); - --mRefCnt; } nsWalletlibService::~nsWalletlibService() @@ -200,9 +198,12 @@ NS_IMETHODIMP nsWalletlibService::SI_SignonViewerReturn(nsAutoString results){ return NS_OK; } -NS_IMETHODIMP nsWalletlibService::Observe(nsISupports*, const PRUnichar*, const PRUnichar*) +NS_IMETHODIMP nsWalletlibService::Observe(nsISupports*, const PRUnichar *aTopic, const PRUnichar*) { - return NS_ERROR_NOT_IMPLEMENTED; + if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC)) { + WLLT_ClearUserData(); + } + return NS_OK; } #define CRLF "\015\012" @@ -215,28 +216,31 @@ NS_IMETHODIMP nsWalletlibService::Notify(nsIContent* formNode, nsIDOMWindowInter return NS_OK; } -void nsWalletlibService::Init() +nsresult nsWalletlibService::Init() { - nsIObserverService *svc = 0; - nsIDocumentLoader *docLoaderService; + nsresult rv; - nsresult rv = nsServiceManager::GetService - (NS_OBSERVERSERVICE_CONTRACTID, NS_GET_IID(nsIObserverService), (nsISupports**)&svc ); - if ( NS_SUCCEEDED( rv ) && svc ) { - nsString topic; topic.AssignWithConversion(NS_FORMSUBMIT_SUBJECT); - rv = svc->AddObserver( this, topic.GetUnicode()); - nsServiceManager::ReleaseService( NS_OBSERVERSERVICE_CONTRACTID, svc ); + NS_WITH_SERVICE(nsIObserverService, svc, NS_OBSERVERSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && svc) { + // Register as an observer of form submission + nsAutoString topic; topic.AssignWithConversion(NS_FORMSUBMIT_SUBJECT); + svc->AddObserver(this, topic.GetUnicode()); + // Register as an observer of profile changes + svc->AddObserver(this, PROFILE_DO_CHANGE_TOPIC); } + else + NS_ASSERTION(PR_FALSE, "Could not get nsIObserverService"); // Get the global document loader service... - rv = nsServiceManager::GetService - (kDocLoaderServiceCID, NS_GET_IID(nsIDocumentLoader), (nsISupports **)&docLoaderService); + NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv) if (NS_SUCCEEDED(rv) && docLoaderService) { //Register ourselves as an observer for the new doc loader docLoaderService->AddObserver((nsIDocumentLoaderObserver*)this); - nsServiceManager::ReleaseService(kDocLoaderServiceCID, docLoaderService ); } - + else + NS_ASSERTION(PR_FALSE, "Could not get nsIDocumentLoader"); + + return NS_OK; } NS_IMETHODIMP @@ -462,7 +466,26 @@ nsWalletlibService::WALLET_Decrypt (const char *crypt, PRUnichar **text) { //////////////////////////////////////////////////////////////////////////////// // nsSingleSignOnPrompt -NS_IMPL_THREADSAFE_ISUPPORTS2(nsSingleSignOnPrompt, nsISingleSignOnPrompt, nsIPrompt) +NS_IMPL_THREADSAFE_ISUPPORTS4(nsSingleSignOnPrompt, + nsISingleSignOnPrompt, + nsIPrompt, + nsIObserver, + nsISupportsWeakReference) + +nsresult +nsSingleSignOnPrompt::Init() +{ + nsresult rv; + NS_WITH_SERVICE(nsIObserverService, svc, NS_OBSERVERSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && svc) { + // Register as an observer of profile changes + svc->AddObserver(this, PROFILE_DO_CHANGE_TOPIC); + } + else + NS_ASSERTION(PR_FALSE, "Could not get nsIObserverService"); + + return NS_OK; +} NS_IMETHODIMP nsSingleSignOnPrompt::Alert(const PRUnichar *dialogTitle, const PRUnichar *text) @@ -556,25 +579,21 @@ nsSingleSignOnPrompt::UniversalDialog(const PRUnichar *titleMessage, const PRUni // nsISingleSignOnPrompt methods: NS_IMETHODIMP -nsSingleSignOnPrompt::Init(nsIPrompt* dialogs) +nsSingleSignOnPrompt::SetPromptDialogs(nsIPrompt* dialogs) { mPrompt = dialogs; return NS_OK; } -NS_METHOD -nsSingleSignOnPrompt::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - if (aOuter) - return NS_ERROR_NO_AGGREGATION; +// nsIObserver methods: - nsSingleSignOnPrompt* prompt = new nsSingleSignOnPrompt(); - if (prompt == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(prompt); - nsresult rv = prompt->QueryInterface(aIID, aResult); - NS_RELEASE(prompt); - return rv; +NS_IMETHODIMP +nsSingleSignOnPrompt::Observe(nsISupports*, const PRUnichar *aTopic, const PRUnichar*) +{ + if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC)) { + SI_ClearUserData(); + } + return NS_OK; } //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/extensions/wallet/src/nsWalletService.h b/mozilla/extensions/wallet/src/nsWalletService.h index 3f9ddad5ffd..4dadd33a73e 100644 --- a/mozilla/extensions/wallet/src/nsWalletService.h +++ b/mozilla/extensions/wallet/src/nsWalletService.h @@ -49,32 +49,32 @@ public: // NS_DECL_NSSUPPORTSWEAKREFERENCE nsWalletlibService(); + nsresult Init(); // NS_DECL_NSIFORMSUBMITOBSERVER NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindowInternal* window, nsIURI* actionURL, PRBool* cancelSubmit); protected: virtual ~nsWalletlibService(); - -private: - void Init(); }; //////////////////////////////////////////////////////////////////////////////// -class nsSingleSignOnPrompt : public nsISingleSignOnPrompt +class nsSingleSignOnPrompt : public nsISingleSignOnPrompt, + public nsIObserver, + public nsSupportsWeakReference { public: NS_DECL_ISUPPORTS NS_DECL_NSIPROMPT NS_DECL_NSISINGLESIGNONPROMPT + NS_DECL_NSIOBSERVER nsSingleSignOnPrompt() { NS_INIT_REFCNT(); } virtual ~nsSingleSignOnPrompt() {} - - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - + + nsresult Init(); + protected: nsCOMPtr mPrompt; }; diff --git a/mozilla/extensions/wallet/src/singsign.cpp b/mozilla/extensions/wallet/src/singsign.cpp index c4f2f4cd7cb..49caba89ef9 100644 --- a/mozilla/extensions/wallet/src/singsign.cpp +++ b/mozilla/extensions/wallet/src/singsign.cpp @@ -88,6 +88,7 @@ si_SaveSignonDataInKeychain(); ******************/ char* signonFileName = nsnull; +static PRBool gLoadedUserData = FALSE; /*************************** @@ -287,6 +288,11 @@ si_RegisterSignonPrefCallbacks(void) { static PRBool first_time = PR_TRUE; if(first_time) { first_time = PR_FALSE; + SI_RegisterCallback(pref_rememberSignons, si_SignonRememberingPrefChanged, NULL); + } + + if (!gLoadedUserData) { + gLoadedUserData = PR_TRUE; SI_LoadSignonData(); #ifdef DefaultIsOff x = SI_GetBoolPref(pref_Notified, PR_FALSE); @@ -294,7 +300,6 @@ si_RegisterSignonPrefCallbacks(void) { #endif x = SI_GetBoolPref(pref_rememberSignons, PR_FALSE); si_SetSignonRememberingPref(x); - SI_RegisterCallback(pref_rememberSignons, si_SignonRememberingPrefChanged, NULL); } } @@ -1202,6 +1207,12 @@ SI_DeleteAll() { si_SaveSignonDataLocked(); } +PUBLIC void +SI_ClearUserData() { + SI_RemoveAllSignonData(); + gLoadedUserData = PR_FALSE; +} + /**************************** * Managing the Reject List * ****************************/ diff --git a/mozilla/extensions/wallet/src/singsign.h b/mozilla/extensions/wallet/src/singsign.h index 9cbcd609b89..675394a7b7b 100644 --- a/mozilla/extensions/wallet/src/singsign.h +++ b/mozilla/extensions/wallet/src/singsign.h @@ -116,6 +116,9 @@ SI_FindValueInArgs(const nsString& results, const nsString& name, nsString& valu extern void SI_DeleteAll(); +extern void +SI_ClearUserData(); + extern PRBool SINGSIGN_ReencryptAll(); diff --git a/mozilla/extensions/wallet/src/wallet.cpp b/mozilla/extensions/wallet/src/wallet.cpp index c53ee28b013..fd0eb999fb8 100644 --- a/mozilla/extensions/wallet/src/wallet.cpp +++ b/mozilla/extensions/wallet/src/wallet.cpp @@ -2545,11 +2545,13 @@ Wallet_ReleaseAllLists() { * initialization for wallet session (done only once) */ +static PRBool wallet_tablesInitialized = PR_FALSE; +static PRBool wallet_ValuesReadIn = PR_FALSE; +static PRBool namesInitialized = PR_FALSE; +static PRBool wallet_URLListInitialized = PR_FALSE; + static void wallet_Initialize(PRBool unlockDatabase=PR_TRUE) { - static PRBool wallet_tablesInitialized = PR_FALSE; - static PRBool wallet_ValuesReadIn = PR_FALSE; - static PRBool namesInitialized = PR_FALSE; #ifdef DEBUG //wallet_ClearStopwatch(); @@ -2638,8 +2640,8 @@ wallet_Initialize(PRBool unlockDatabase=PR_TRUE) { static void wallet_InitializeURLList() { - static PRBool wallet_URLListInitialized = PR_FALSE; if (!wallet_URLListInitialized) { + wallet_Clear(&wallet_URL_list); wallet_ReadFromFile(URLFileName, wallet_URL_list, PR_TRUE); wallet_URLListInitialized = PR_TRUE; } @@ -3085,6 +3087,13 @@ WLLT_DeleteAll() { SI_SetBoolPref(pref_Crypto, PR_FALSE); } +PUBLIC void +WLLT_ClearUserData() { + wallet_ValuesReadIn = PR_FALSE; + namesInitialized = PR_FALSE; + wallet_URLListInitialized = PR_FALSE; +} + MODULE_PRIVATE int PR_CALLBACK wallet_ReencryptAll(const char * newpref, void* window) { PRUnichar * message; diff --git a/mozilla/extensions/wallet/src/wallet.h b/mozilla/extensions/wallet/src/wallet.h index 25bb15af5cf..3b5b201b989 100644 --- a/mozilla/extensions/wallet/src/wallet.h +++ b/mozilla/extensions/wallet/src/wallet.h @@ -51,6 +51,9 @@ WLLT_ChangePassword(PRBool* status); extern void WLLT_DeleteAll(); +extern void +WLLT_ClearUserData(); + extern void WLLT_PreEdit(nsString& walletList); diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 74c213cbaa7..4f1f7c87b81 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -2114,7 +2114,7 @@ nsWebShellWindow::GetPrompter(nsIPrompt* *result) nsCOMPtr siPrompt = do_CreateInstance(kSingleSignOnPromptCID, &rv); if (NS_SUCCEEDED(rv)) { // then single sign-on is installed - rv = siPrompt->Init(prompt); + rv = siPrompt->SetPromptDialogs(prompt); if (NS_FAILED(rv)) return rv; mPrompter = siPrompt; }