fixes bug 199108 "Changes to cookie prefs need restart to take effect"

patch=dwitte r=kaie sr=darin
This commit is contained in:
darin%netscape.com 2003-03-26 02:27:39 +00:00
Родитель fb42cf1bd8
Коммит b9fe63f8b7
3 изменённых файлов: 28 добавлений и 27 удалений

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

@ -89,9 +89,7 @@ nsCookieService::~nsCookieService()
// clean up memory
COOKIE_RemoveAll();
if (gCookiePrefObserver) {
delete gCookiePrefObserver;
}
NS_IF_RELEASE(gCookiePrefObserver);
if (sCookieList) {
delete sCookieList;
}
@ -99,6 +97,8 @@ nsCookieService::~nsCookieService()
nsresult nsCookieService::Init()
{
nsresult rv;
// install the main cookie pref observer (defined in nsCookieService.h)
// this will be integrated into nsCookieService when nsCookies is removed.
gCookiePrefObserver = new nsCookiePrefObserver();
@ -109,8 +109,12 @@ nsresult nsCookieService::Init()
return NS_ERROR_OUT_OF_MEMORY;
}
// init nsCookiePrefObserver, and fail if it can't get the prefbranch
NS_ADDREF(gCookiePrefObserver);
rv = gCookiePrefObserver->Init();
if (NS_FAILED(rv)) return rv;
// cache mCookieFile
nsresult rv;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mCookieFile));
if (NS_SUCCEEDED(rv)) {
rv = mCookieFile->AppendNative(NS_LITERAL_CSTRING(kCookieFileName2));

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

@ -72,9 +72,7 @@ class nsCookiePrefObserver : public nsIObserver
nsCookiePrefObserver();
virtual ~nsCookiePrefObserver();
nsresult Init();
nsresult Install();
nsresult ReadPrefs();
nsresult Remove();
// member variables for caching prefs
#ifdef MOZ_PHOENIX
@ -115,7 +113,7 @@ public:
NS_DECL_NSICOOKIESERVICE
nsCookieService();
virtual ~nsCookieService(void);
virtual ~nsCookieService();
nsresult Init();
protected:

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

@ -125,15 +125,18 @@ static const char kCookiesStrictDomains[] = "network.cookie.strictDomains";
nsCookiePrefObserver::nsCookiePrefObserver()
{
nsresult rv;
}
nsCOMPtr<nsIPrefBranchInternal> prefInternal;
nsresult
nsCookiePrefObserver::Init()
{
nsresult rv;
// install and cache the preferences observer
mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
prefInternal = do_QueryInterface(mPrefBranch, &rv);
}
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIPrefBranchInternal> prefInternal = do_QueryInterface(mPrefBranch, &rv);
// add observers
if (NS_SUCCEEDED(rv)) {
@ -151,20 +154,22 @@ nsCookiePrefObserver::nsCookiePrefObserver()
#endif
prefInternal->AddObserver(kCookiesAskPermission, this, PR_TRUE);
prefInternal->AddObserver(kCookiesStrictDomains, this, PR_TRUE);
// initialize prefs
rv = ReadPrefs();
if (NS_FAILED(rv)) {
NS_WARNING("Error occured reading cookie preferences");
}
}
// initialize prefs
rv = ReadPrefs();
if (NS_FAILED(rv)) {
NS_WARNING("Error occured reading cookie preferences");
}
return NS_OK;
}
nsCookiePrefObserver::~nsCookiePrefObserver()
{
}
NS_IMPL_ISUPPORTS1(nsCookiePrefObserver, nsIObserver)
NS_IMPL_ISUPPORTS2(nsCookiePrefObserver, nsIObserver, nsISupportsWeakReference)
NS_IMETHODIMP
nsCookiePrefObserver::Observe(nsISupports *aSubject,
@ -173,9 +178,8 @@ nsCookiePrefObserver::Observe(nsISupports *aSubject,
{
nsresult rv;
// check the topic, and the cached prefservice
if (!mPrefBranch ||
nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) {
// check the topic
if (nsCRT::strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) {
return NS_ERROR_FAILURE;
}
@ -300,11 +304,6 @@ nsCookiePrefObserver::ReadPrefs()
{
nsresult rv, rv2 = NS_OK;
// check the prefservice is cached
if (!mPrefBranch) {
return NS_ERROR_FAILURE;
}
PRInt32 tempPrefValue;
#ifdef MOZ_PHOENIX
rv = mPrefBranch->GetBoolPref(kCookiesEnabled, &tempPrefValue);