Bug 65212 - profile support for kiosk mode. Also, removing profile change observer strings from header to cut dependencies. r=valeski@netscape.com, sr=alecf@netscape.com

This commit is contained in:
ccarlen%netscape.com 2001-03-11 22:12:21 +00:00
Родитель 9afeb09e55
Коммит 8d27bb9639
29 изменённых файлов: 495 добавлений и 186 удалений

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

@ -80,7 +80,6 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsIPref.h"
#include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h"
static char kChromePrefix[] = "chrome://";
static char kAllPackagesName[] = "all-packages.rdf";
@ -336,8 +335,10 @@ nsChromeRegistry::Init()
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (observerService)
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
if (observerService) {
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
}
CheckForNewChrome();
@ -3058,9 +3059,23 @@ nsChromeRegistry::GetProviderCount(const nsCString& aProviderType, nsIRDFDataSou
NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-before-change").get(), aTopic)) {
mChromeDataSource = nsnull;
mProfileInitialized = PR_FALSE;
if (!nsCRT::strcmp(PROFILE_DO_CHANGE_TOPIC, aTopic))
rv = LoadProfileDataSource();
if (!nsCRT::strcmp(NS_LITERAL_STRING("shutdown-cleanse").get(), someData)) {
nsCOMPtr<nsIFile> userChromeDir;
rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir));
if (NS_SUCCEEDED(rv) && userChromeDir)
rv = userChromeDir->Delete(PR_TRUE);
}
}
else if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-do-change").get(), aTopic)) {
if (!mProfileInitialized)
rv = LoadProfileDataSource();
}
return rv;
}

Двоичный файл не отображается.

Двоичный файл не отображается.

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

@ -63,7 +63,8 @@ enum {
// Alerts
enum {
alrt_ConfirmProfileSwitch = 1500
alrt_ConfirmProfileSwitch = 1500,
alrt_ConfirmLogout = 1501
};
// MENUs
@ -131,7 +132,8 @@ enum {
cmd_PrefillForm = 'PFFm',
cmd_ManageProfiles = 'MPrf'
cmd_ManageProfiles = 'MPrf',
cmd_Logout = 'LOut'
};
#endif // __ApplIDs__

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

@ -225,16 +225,17 @@ CBrowserApp::StartUp()
nsresult rv;
#if USE_PROFILES
CProfileManager *profileMgr = new CProfileManager;
profileMgr->StartUp();
AddAttachment(profileMgr);
// Register for profile changes
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
ThrowIfNil_(observerService);
observerService->AddObserver(this, PROFILE_APPROVE_CHANGE_TOPIC);
observerService->AddObserver(this, PROFILE_CHANGE_TEARDOWN_TOPIC);
observerService->AddObserver(this, PROFILE_AFTER_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-approve-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-change-teardown").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-after-change").get());
CProfileManager *profileMgr = new CProfileManager;
profileMgr->StartUp();
AddAttachment(profileMgr);
#else
@ -258,7 +259,6 @@ CBrowserApp::StartUp()
#endif
InitializePrefs();
ObeyCommand(PP_PowerPlant::cmd_New, nil); // EXAMPLE, create a new window
}
@ -628,7 +628,7 @@ NS_IMETHODIMP CBrowserApp::Observe(nsISupports *aSubject, const PRUnichar *aTopi
nsresult rv = NS_OK;
if (nsCRT::strcmp(aTopic, PROFILE_APPROVE_CHANGE_TOPIC) == 0)
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-approve-change").get()))
{
// Ask the user if they want to
DialogItemIndex item = UModalAlerts::StopAlert(alrt_ConfirmProfileSwitch);
@ -639,7 +639,7 @@ NS_IMETHODIMP CBrowserApp::Observe(nsISupports *aSubject, const PRUnichar *aTopi
status->VetoChange();
}
}
else if (nsCRT::strcmp(aTopic, PROFILE_CHANGE_TEARDOWN_TOPIC) == 0)
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-change-teardown").get()))
{
// Close all open windows. Alternatively, we could just call CBrowserWindow::Stop()
// on each. Either way, we have to stop all network activity on this phase.
@ -654,16 +654,28 @@ NS_IMETHODIMP CBrowserApp::Observe(nsISupports *aSubject, const PRUnichar *aTopi
delete browserWindow;
}
}
// Clear the cache(s) The cache mgr does not do this itself since an
// application may be using a global cache for all profiles so it would
// not know whether to respond to a profile change.
NS_WITH_SERVICE(nsINetDataCacheManager, cacheMgr, NS_NETWORK_CACHE_MANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
cacheMgr->Clear(nsINetDataCacheManager::MEM_CACHE);
{
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
cacheMgr->RemoveAll();
else
cacheMgr->Clear(nsINetDataCacheManager::MEM_CACHE);
}
}
else if (nsCRT::strcmp(aTopic, PROFILE_AFTER_CHANGE_TOPIC) == 0)
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-after-change").get()))
{
InitializePrefs(); // In case we have just switched to a newly created profile.
// Make a new default window
ObeyCommand(PP_PowerPlant::cmd_New, nil);
InitializePrefs();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("switch").get())) {
// Make a new default window
ObeyCommand(PP_PowerPlant::cmd_New, nil);
}
}
return rv;
}

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

@ -307,6 +307,33 @@ void CProfileManager::DoManageProfilesDialog()
}
}
void CProfileManager::DoLogout()
{
enum { iPersist = 1, iCancel, iCleanse };
nsresult rv;
NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv);
ThrowIfNil_(profileService);
nsXPIDLString currentProfile;
Str255 pStr;
profileService->GetCurrentProfile(getter_Copies(currentProfile));
CPlatformUCSConversion::GetInstance()->UCSToPlatform(nsLiteralString(currentProfile.get()), pStr);
::ParamText(pStr, "\p", "\p", "\p");
DialogItemIndex item = UModalAlerts::StopAlert(alrt_ConfirmLogout);
if (item == iCancel)
return;
rv = profileService->ShutDownCurrentProfile(item == iPersist ? nsIProfile::SHUTDOWN_PERSIST : nsIProfile::SHUTDOWN_CLEANSE);
if (NS_SUCCEEDED(rv)) {
// Just put this up modally until they pick a new profile
DoManageProfilesDialog();
}
}
/*
The following three methods have nothing to do with profile management per se.
They use the registry to store a flag which allows the user to choose whether
@ -415,9 +442,18 @@ void CProfileManager::ExecuteSelf(MessageT inMessage, void *ioParam)
*status->usesMark = false;
mExecuteHost = false; // we handled it
}
else if (status->command == cmd_Logout) {
*status->enabled = true;
*status->usesMark = false;
mExecuteHost = false; // we handled it
}
}
else if (inMessage == cmd_ManageProfiles) {
DoManageProfilesDialog();
mExecuteHost = false; // we handled it
}
else if (inMessage == cmd_Logout) {
DoLogout();
mExecuteHost = false; // we handled it
}
}

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

@ -41,6 +41,8 @@ class CProfileManager : public LAttachment
virtual void DoManageProfilesDialog();
virtual Boolean DoNewProfileDialog(char *outName, UInt32 bufSize);
virtual void DoLogout();
protected:
// LAttachment

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

@ -116,7 +116,6 @@ BOOL CMfcEmbedApp::InitInstance()
return FALSE;
}
InitializePrefs();
if(!CreateHiddenWindow())
{
@ -255,13 +254,13 @@ BOOL CMfcEmbedApp::InitializeProfiles()
if (!m_ProfileMgr)
return FALSE;
m_ProfileMgr->StartUp();
nsresult rv;
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
observerService->AddObserver(this, PROFILE_APPROVE_CHANGE_TOPIC);
observerService->AddObserver(this, PROFILE_CHANGE_TEARDOWN_TOPIC);
observerService->AddObserver(this, PROFILE_AFTER_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-approve-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-change-teardown").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-after-change").get());
m_ProfileMgr->StartUp();
return TRUE;
}
@ -388,7 +387,7 @@ NS_IMETHODIMP CMfcEmbedApp::Observe(nsISupports *aSubject, const PRUnichar *aTop
{
nsresult rv = NS_OK;
if (nsCRT::strcmp(aTopic, PROFILE_APPROVE_CHANGE_TOPIC) == 0)
if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-approve-change").get()) == 0)
{
// Ask the user if they want to
int result = MessageBox(NULL, "Do you want to close all windows in order to switch the profile?", "Confirm", MB_YESNO | MB_ICONQUESTION);
@ -399,7 +398,7 @@ NS_IMETHODIMP CMfcEmbedApp::Observe(nsISupports *aSubject, const PRUnichar *aTop
status->VetoChange();
}
}
else if (nsCRT::strcmp(aTopic, PROFILE_CHANGE_TEARDOWN_TOPIC) == 0)
else if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-change-teardown").get()) == 0)
{
// Close all open windows. Alternatively, we could just call CBrowserWindow::Stop()
// on each. Either way, we have to stop all network activity on this phase.
@ -424,11 +423,14 @@ NS_IMETHODIMP CMfcEmbedApp::Observe(nsISupports *aSubject, const PRUnichar *aTop
if (NS_SUCCEEDED(rv))
cacheMgr->Clear(nsINetDataCacheManager::MEM_CACHE);
}
else if (nsCRT::strcmp(aTopic, PROFILE_AFTER_CHANGE_TOPIC) == 0)
else if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-after-change").get()) == 0)
{
InitializePrefs(); // In case we have just switched to a newly created profile.
OnNewBrowser();
// Only make a new browser window on a switch. This also gets
// called at start up and we already make a window then.
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("switch").get()))
OnNewBrowser();
}
return rv;
}

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

@ -54,6 +54,9 @@ static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define MAX_HOST_NAME_LEN 64
#endif
static const char *kCookiesFileName = "cookies.txt";
static const char *kCookiesPermFileName = "cookperm.txt";
#define image_behaviorPref "network.image.imageBehavior"
#define image_warningPref "network.image.warnAboutImages"
#define cookie_behaviorPref "network.cookie.cookieBehavior"
@ -497,6 +500,28 @@ COOKIE_RemoveAllCookies()
}
}
PUBLIC void
COOKIE_DeletePersistentUserData(void)
{
nsresult res;
nsCOMPtr<nsIFile> cookiesFile;
res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(cookiesFile));
if (NS_SUCCEEDED(res)) {
res = cookiesFile->Append(kCookiesFileName);
if (NS_SUCCEEDED(res))
(void) cookiesFile->Delete(PR_FALSE);
}
nsCOMPtr<nsIFile> cookiesPermFile;
res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(cookiesPermFile));
if (NS_SUCCEEDED(res)) {
res = cookiesPermFile->Append(kCookiesPermFileName);
if (NS_SUCCEEDED(res))
(void) cookiesPermFile->Delete(PR_FALSE);
}
}
PRIVATE void
cookie_RemoveOldestCookie(void) {
cookie_CookieStruct * cookie_s;
@ -1883,7 +1908,7 @@ permission_Save() {
if (NS_FAILED(rval)) {
return;
}
nsOutputFileStream strm(dirSpec + "cookperm.txt");
nsOutputFileStream strm(dirSpec + kCookiesPermFileName);
if (!strm.is_open()) {
return;
}
@ -1949,7 +1974,7 @@ permission_Load() {
if (NS_FAILED(rv)) {
return;
}
nsInputFileStream strm(dirSpec + "cookperm.txt");
nsInputFileStream strm(dirSpec + kCookiesPermFileName);
if (!strm.is_open()) {
/* file doesn't exist -- that's not an error */
for (PRInt32 type=0; type<NUMBER_OF_PERMISSIONS; type++) {
@ -2056,7 +2081,7 @@ cookie_Save() {
if (NS_FAILED(rv)) {
return;
}
nsOutputFileStream strm(dirSpec + "cookies.txt");
nsOutputFileStream strm(dirSpec + kCookiesFileName);
if (!strm.is_open()) {
/* file doesn't exist -- that's not an error */
return;
@ -2128,7 +2153,7 @@ cookie_Load() {
if (NS_FAILED(rv)) {
return;
}
nsInputFileStream strm(dirSpec + "cookies.txt");
nsInputFileStream strm(dirSpec + kCookiesFileName);
if (!strm.is_open()) {
/* file doesn't exist -- that's not an error */
return;

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

@ -48,6 +48,7 @@ extern void COOKIE_SetCookieString(char * cur_url, nsIPrompt *aPrompter, char *
extern int COOKIE_ReadCookies();
extern void COOKIE_RegisterCookiePrefCallbacks(void);
extern void COOKIE_RemoveAllCookies(void);
extern void COOKIE_DeletePersistentUserData(void);
extern void COOKIE_SetCookieStringFromHttp(char * cur_url, char * first_url, nsIPrompt *aPRompter, char * set_cookie_header, char * server_date);
extern void COOKIE_GetCookieListForViewer (nsString& aCookieList);
extern void COOKIE_GetPermissionListForViewer (nsString& aPermissionList, PRInt32 type);

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

@ -31,7 +31,6 @@
#include "nsIDOMWindowInternal.h"
#include "nsIPrompt.h"
#include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h"
////////////////////////////////////////////////////////////////////////////////
@ -68,7 +67,8 @@ nsresult nsCookieService::Init()
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (observerService) {
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
}
mInitted = PR_TRUE;
@ -197,23 +197,25 @@ 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.
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
// The profile is about to change.
// 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
// cookie table. 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
// was accepted). If this condition ever changes, the cookie
// file would need to be updated here.
COOKIE_RemoveAllCookies();
// Now just read them from the new profile location
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
COOKIE_DeletePersistentUserData();
}
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get())) {
// The profile has aleady changed.
// Now just read them from the new profile location.
COOKIE_ReadCookies();
}

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

@ -65,7 +65,6 @@
#include "nsIDOMWindow.h"
#include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h"
#define PSM_VERSION_REG_KEY "/Netscape/Personal Security Manager"
@ -166,7 +165,7 @@ nsPSMComponent::RegisterProfileChangeObserver()
if (observerService) {
// Our refcnt must be > 0 when we call AddObserver or we'll get deleted.
++mRefCnt;
observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
--mRefCnt;
}
return rv;
@ -1228,7 +1227,7 @@ nsPSMComponent::RandomUpdate(void *entropy, PRInt32 bufLen)
NS_IMETHODIMP
nsPSMComponent::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
if (nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC) == 0) {
if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get()) == 0) {
// The profile is about to change - close our control connection if we have one.
// Next time PSM is needed, we'll make a new control connection which

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

@ -44,7 +44,6 @@
#include "nsIInterfaceRequestor.h"
#include "nsIPrompt.h"
#include "nsIChannel.h"
#include "nsIProfileChangeStatus.h"
// for making the leap from nsIDOMWindowInternal -> nsIPresShell
#include "nsIScriptGlobalObject.h"
@ -200,10 +199,13 @@ NS_IMETHODIMP nsWalletlibService::SI_SignonViewerReturn(nsAutoString results){
return NS_OK;
}
NS_IMETHODIMP nsWalletlibService::Observe(nsISupports*, const PRUnichar *aTopic, const PRUnichar*)
NS_IMETHODIMP nsWalletlibService::Observe(nsISupports*, const PRUnichar *aTopic, const PRUnichar *someData)
{
if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC)) {
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
WLLT_ClearUserData();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
WLLT_DeletePersistentUserData();
}
}
return NS_OK;
}
@ -228,7 +230,7 @@ nsresult nsWalletlibService::Init()
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);
svc->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
}
else
NS_ASSERTION(PR_FALSE, "Could not get nsIObserverService");
@ -482,7 +484,7 @@ nsSingleSignOnPrompt::Init()
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);
svc->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
}
else
NS_ASSERTION(PR_FALSE, "Could not get nsIObserverService");
@ -591,10 +593,13 @@ nsSingleSignOnPrompt::SetPromptDialogs(nsIPrompt* dialogs)
// nsIObserver methods:
NS_IMETHODIMP
nsSingleSignOnPrompt::Observe(nsISupports*, const PRUnichar *aTopic, const PRUnichar*)
nsSingleSignOnPrompt::Observe(nsISupports*, const PRUnichar *aTopic, const PRUnichar *someData)
{
if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC)) {
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
SI_ClearUserData();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
SI_DeletePersistentUserData();
}
}
return NS_OK;
}

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

@ -1230,6 +1230,20 @@ SI_ClearUserData() {
gLoadedUserData = PR_FALSE;
}
PUBLIC void
SI_DeletePersistentUserData() {
if (signonFileName && nsCRT::strlen(signonFileName)) {
nsFileSpec fileSpec;
nsresult rv = Wallet_ProfileDirectory(fileSpec);
if (NS_SUCCEEDED(rv)) {
fileSpec += signonFileName;
if (fileSpec.Valid() && fileSpec.IsFile())
fileSpec.Delete(PR_FALSE);
}
}
}
/****************************
* Managing the Reject List *
****************************/

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

@ -119,6 +119,9 @@ SI_DeleteAll();
extern void
SI_ClearUserData();
extern void
SI_DeletePersistentUserData();
extern PRBool
SINGSIGN_ReencryptAll();

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

@ -52,7 +52,6 @@
#include "nsIFileSpec.h"
#include "prmem.h"
#include "prprf.h"
#include "nsIProfile.h"
#include "nsIContent.h"
#include "nsISecurityManagerComponent.h"
@ -74,7 +73,6 @@ static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID);
static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
@ -3093,6 +3091,20 @@ WLLT_ClearUserData() {
wallet_URLListInitialized = PR_FALSE;
}
PUBLIC void
WLLT_DeletePersistentUserData() {
if (schemaValueFileName && nsCRT::strlen(schemaValueFileName)) {
nsFileSpec fileSpec;
nsresult rv = Wallet_ProfileDirectory(fileSpec);
if (NS_SUCCEEDED(rv)) {
fileSpec += schemaValueFileName;
if (fileSpec.Valid() && fileSpec.IsFile())
fileSpec.Delete(PR_FALSE);
}
}
}
MODULE_PRIVATE int PR_CALLBACK
wallet_ReencryptAll(const char * newpref, void* window) {
PRUnichar * message;

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

@ -54,6 +54,9 @@ WLLT_DeleteAll();
extern void
WLLT_ClearUserData();
extern void
WLLT_DeletePersistentUserData();
extern void
WLLT_PreEdit(nsString& walletList);

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

@ -61,8 +61,6 @@
#include "nsWeakReference.h"
#include "nsISupportsArray.h"
#include "nsIProfileChangeStatus.h"
#include "nsTextFormatter.h"
#include "plhash.h"
@ -235,8 +233,8 @@ nsPref::nsPref()
if (observerService) {
// Our refcnt must be > 0 when we call this, or we'll get deleted!
++mRefCnt;
rv = observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
rv = observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
rv = observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
rv = observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
--mRefCnt;
}
}
@ -1459,10 +1457,17 @@ NS_IMETHODIMP nsPref::Observe(nsISupports *aSubject, const PRUnichar *aTopic, co
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC)) {
rv = SavePrefFile();
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
if (mFileSpec) {
mFileSpec->Delete(PR_FALSE);
NS_RELEASE(mFileSpec);
}
}
else
rv = SavePrefFile();
}
else if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC)) {
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get())) {
PREF_ClearAllUserPrefs();
rv = ReadUserPrefs();
}

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

@ -52,7 +52,6 @@
#include "nsICategoryManager.h"
#include "nsISupportsPrimitives.h"
#include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h"
#if defined(DEBUG_dp) || defined(DEBUG_sspitzer) || defined(DEBUG_seth)
#define DEBUG_HTTP_STARTUP_CATEGORY 1
@ -838,7 +837,7 @@ nsHTTPHandler::Init()
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
return NS_OK;
}
@ -1595,7 +1594,7 @@ nsHTTPHandler::GetServerCapabilities (
NS_IMETHODIMP
nsHTTPHandler::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
if (!nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC)) {
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
nsAuthEngine *authEngine;
nsresult rv = GetAuthEngine(&authEngine);
if (NS_SUCCEEDED(rv) && authEngine)

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

@ -50,6 +50,11 @@ interface nsIProfile : nsISupports {
attribute wstring currentProfile;
const unsigned long SHUTDOWN_PERSIST = 0x00000001;
const unsigned long SHUTDOWN_CLEANSE = 0x00000002;
void shutDownCurrentProfile(in unsigned long shutDownType);
void createNewProfile(in wstring profileName,
in wstring nativeProfileDir,
in wstring langcode,

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

@ -25,47 +25,72 @@
%{C++
/**
* nsIObserver topics for profile changing. Profile changing happens in 5 phases
* nsIObserver topics for profile changing. Profile changing happens in phases
* in the order given below. An observer may register separately for each phase
* of the process depending on its needs. The subject passed to the observer's
* Observe() method can be QI'd to an nsIProfileChangeStatus.
*
* PROFILE_APPROVE_CHANGE_TOPIC
* Called before a profile switch is attempted. Typically,
* "profile-approve-change"
* Called before a profile change is attempted. Typically,
* the application level observer will ask the user if
* he/she wants to stop all network activity, close all open
* windows, etc. If the user says NO, the observer should
* call the subject's vetoChange(). If any observer does
* this, the profile will not be switched.
* this, the profile will not be changed.
*
* PROFILE_CHANGE_TEARDOWN_TOPIC
* "profile-change-teardown"
* All async activity must be stopped in this phase. Typically,
* the application level observer will close all open windows.
*
* PROFILE_BEFORE_CHANGE_TOPIC
* "profile-before-change"
* Called before the profile has changed. Use this notification
* to prepare for the profile being switched. If a component is
* to prepare for the profile going away. If a component is
* holding any state which needs to be flushed to a profile-relative
* location, it should be done here.
*
* PROFILE_DO_CHANGE_TOPIC
* "profile-do-change"
* Called after the profile has changed. Do the work to
* respond to having a new profile. Any change which
* affects others must be done in this phase.
*
* PROFILE_AFTER_CHANGE_TOPIC
* "profile-after-change"
* Called after the profile has changed. Use this notification
* to make changes that are dependent on what some other listener
* did during its PROFILE_DO_CHANGE. For example, to respond to
* did during its profile-do-change. For example, to respond to
* new preferences.
*/
#define PROFILE_APPROVE_CHANGE_TOPIC (NS_LITERAL_STRING("profile-approve-change").get())
#define PROFILE_CHANGE_TEARDOWN_TOPIC (NS_LITERAL_STRING("profile-change-teardown").get())
#define PROFILE_BEFORE_CHANGE_TOPIC (NS_LITERAL_STRING("profile-before-change").get())
#define PROFILE_DO_CHANGE_TOPIC (NS_LITERAL_STRING("profile-do-change").get())
#define PROFILE_AFTER_CHANGE_TOPIC (NS_LITERAL_STRING("profile-after-change").get())
*
*
* Contexts for profile changes. These are passed as the someData param to the
* observer's Observe() method.
* "startup"
* Going from no profile to a profile.
*
* The following topics happen in this context:
* profile-do-change
* profile-after-change
*
* "shutdown-persist"
* The user is logging out and whatever data the observer stores
* for the current profile should be released from memory and
* saved to disk.
*
* "shutdown-cleanse"
* The user is logging out and whatever data the observer stores
* for the current profile should be released from memory and
* deleted from disk.
*
* The following topics happen in both shutdown contexts:
* profile-approve-change
* profile-change-teardown
* profile-before-change
*
* "switch"
* Going from one profile to another.
*
* All of the above topics happen in a profile switch.
*
*/
%}

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

@ -19,7 +19,7 @@
*
* Contributor(s):
*/
#include "nsProfile.h"
#include "nsIPref.h"
@ -87,7 +87,7 @@
// A default profile name, in case automigration 4x profile fails
#define DEFAULT_PROFILE_NAME "default"
#define DEFAULT_PROFILE_NAME (NS_LITERAL_STRING("default").get())
#define PROFILE_SELECTION_URL "chrome://communicator/content/profile/profileSelection.xul"
#define PROFILE_SELECTION_CMD_LINE_ARG "-SelectProfile"
@ -123,7 +123,6 @@
// destructor at the right time (count == 0)
static nsProfileAccess* gProfileDataAccess = nsnull;
static PRInt32 gInstanceCount = 0;
static PRBool mCurrentProfileAvailable = PR_FALSE;
// Atoms for file locations
static nsIAtom* sApp_PrefsDirectory50 = nsnull;
@ -235,6 +234,7 @@ nsProfile::nsProfile()
mAutomigrate = PR_FALSE;
mOutofDiskSpace = PR_FALSE;
mDiskSpaceErrorQuitCalled = PR_FALSE;
mCurrentProfileAvailable = PR_FALSE;
if (gInstanceCount++ == 0) {
@ -383,24 +383,12 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
nsresult rv;
nsCOMPtr<nsIURI> profileURL;
PRInt32 numProfiles=0;
nsXPIDLString currentProfileStr;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
if (NS_FAILED(rv)) return rv;
GetProfileCount(&numProfiles);
/*
* Create the Application Shell instance...
*/
NS_WITH_SERVICE(nsIAppShellService, profAppShell,
kAppShellServiceCID, &rv);
if (NS_FAILED(rv))
return rv;
PRBool shrimpPrefEnabled = PR_FALSE;
prefs->GetBoolPref(SHRIMP_PREF, &shrimpPrefEnabled);
if (shrimpPrefEnabled)
profileURLStr = "";
if (profileURLStr.Length() == 0)
{
@ -411,25 +399,19 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
{
rv = CreateDefaultProfile();
if (NS_FAILED(rv)) return rv;
GetProfileCount(&numProfiles);
profileURLStr = "";
mCurrentProfileAvailable = PR_TRUE;
// Need to load new profile prefs.
rv = LoadNewProfilePrefs();
// Will get set in call to SetCurrentProfile() below
}
else if (numProfiles > 1)
profileURLStr = PROFILE_SELECTION_URL;
}
if ((profileURLStr.Length() != 0) && !(shrimpPrefEnabled))
if (profileURLStr.Length() != 0)
{
rv = NS_NewURI(getter_AddRefs(profileURL), (const char *)profileURLStr);
NS_WITH_SERVICE(nsIAppShellService, profAppShell, kAppShellServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
return rv;
}
rv = NS_NewURI(getter_AddRefs(profileURL), (const char *)profileURLStr);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIXULWindow> profWindow;
rv = profAppShell->CreateTopLevelWindow(nsnull, profileURL,
@ -440,9 +422,7 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
if (NS_FAILED(rv)) return rv;
/*
* Start up the main event loop...
*/
// Start an event loop for the modal dialog
rv = profAppShell->Run();
}
@ -473,17 +453,16 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
// if we get here, and we don't have a current profile,
// return a failure so we will exit
// this can happen, if the user hits Exit in the profile manager dialog
nsXPIDLString currentProfileStr;
rv = GetCurrentProfile(getter_Copies(currentProfileStr));
if (NS_FAILED(rv) || (*(const PRUnichar*)currentProfileStr == 0)) {
return NS_ERROR_FAILURE;
}
mCurrentProfileAvailable = PR_TRUE;
// Now we have the right profile, read the user-specific prefs.
rv = prefs->ReadUserPrefs();
if (NS_FAILED(rv)) return rv;
// if at this point we have a current profile but it is not set, set it
if (!mCurrentProfileAvailable) {
rv = SetCurrentProfile(currentProfileStr);
if (NS_FAILED(rv)) return rv;
}
NS_WITH_SERVICE(nsICategoryManager, catman, NS_CATEGORYMANAGER_CONTRACTID, &rv);
@ -523,7 +502,8 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
rv = pPrefConverter->ConvertPrefsToUTF8();
}
return rv;
return NS_OK;
}
nsresult
@ -965,28 +945,26 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile)
}
else
isSwitch = PR_FALSE;
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
NS_ENSURE_TRUE(directoryService, NS_ERROR_FAILURE);
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
NS_ENSURE_TRUE(observerService, NS_ERROR_FAILURE);
nsISupports *subject = (nsISupports *)((nsIProfile *)this);
nsLiteralString context(isSwitch ? (NS_LITERAL_STRING("switch")).get() : NS_LITERAL_STRING("startup").get());
if (isSwitch)
{
// Phase 1: See if anybody objects to the profile being changed.
mProfileChangeVetoed = PR_FALSE;
observerService->Notify(subject, PROFILE_APPROVE_CHANGE_TOPIC, nsnull);
observerService->Notify(subject, NS_LITERAL_STRING("profile-approve-change").get(), context.get());
if (mProfileChangeVetoed)
return NS_OK;
// Phase 2: Send the "teardown" notification
observerService->Notify(subject, PROFILE_CHANGE_TEARDOWN_TOPIC, nsnull);
observerService->Notify(subject, NS_LITERAL_STRING("profile-change-teardown").get(), context.get());
// Phase 3: Notify observers of a profile change
observerService->Notify(subject, PROFILE_BEFORE_CHANGE_TOPIC, nsnull);
observerService->Notify(subject, NS_LITERAL_STRING("profile-before-change").get(), context.get());
}
// Flush the stringbundle cache
@ -1006,29 +984,15 @@ nsProfile::SetCurrentProfile(const PRUnichar * aCurrentProfile)
if (isSwitch)
{
(void) directoryService->Undefine(NS_APP_PREFS_50_DIR);
(void) directoryService->Undefine(NS_APP_PREFS_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_PROFILE_50_DIR);
(void) directoryService->Undefine(NS_APP_USER_CHROME_DIR);
(void) directoryService->Undefine(NS_APP_LOCALSTORE_50_FILE);
(void) directoryService->Undefine(NS_APP_HISTORY_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_PANELS_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_MIMETYPES_50_FILE);
(void) directoryService->Undefine(NS_APP_BOOKMARKS_50_FILE);
(void) directoryService->Undefine(NS_APP_SEARCH_50_FILE);
(void) directoryService->Undefine(NS_APP_MAIL_50_DIR);
(void) directoryService->Undefine(NS_APP_IMAP_MAIL_50_DIR);
(void) directoryService->Undefine(NS_APP_NEWS_50_DIR);
(void) directoryService->Undefine(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR);
// Phase 4: Notify observers that the profile has changed - Here they respond to new profile
observerService->Notify(subject, PROFILE_DO_CHANGE_TOPIC, nsnull);
// Phase 5: Now observers can respond to something another observer did in phase 4
observerService->Notify(subject, PROFILE_AFTER_CHANGE_TOPIC, nsnull);
rv = UndefineFileLocations();
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not undefine file locations");
}
else
rv = LoadNewProfilePrefs();
// Phase 4: Notify observers that the profile has changed - Here they respond to new profile
observerService->Notify(subject, NS_LITERAL_STRING("profile-do-change").get(), context.get());
// Phase 5: Now observers can respond to something another observer did in phase 4
observerService->Notify(subject, NS_LITERAL_STRING("profile-after-change").get(), context.get());
// Now that a profile is established, set the profile defaults dir for the locale of this profile
rv = DefineLocaleDefaultsDir();
@ -1054,6 +1018,37 @@ NS_IMETHODIMP nsProfile::GetCurrentProfileDir(nsIFile **profileDir)
return NS_OK;
}
// Performs a "logout" by shutting down the current profile
NS_IMETHODIMP nsProfile::ShutDownCurrentProfile(PRUint32 shutDownType)
{
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
NS_ENSURE_TRUE(observerService, NS_ERROR_FAILURE);
nsISupports *subject = (nsISupports *)((nsIProfile *)this);
nsLiteralString context(shutDownType == SHUTDOWN_CLEANSE ? NS_LITERAL_STRING("shutdown-cleanse").get() : NS_LITERAL_STRING("shutdown-persist").get());
// Phase 1: See if anybody objects to the profile being changed.
mProfileChangeVetoed = PR_FALSE;
observerService->Notify(subject, NS_LITERAL_STRING("profile-approve-change").get(), context.get());
if (mProfileChangeVetoed)
return NS_OK;
// Phase 2: Send the "teardown" notification
observerService->Notify(subject, NS_LITERAL_STRING("profile-change-teardown").get(), context.get());
// Phase 3: Notify observers of a profile change
observerService->Notify(subject, NS_LITERAL_STRING("profile-before-change").get(), context.get());
rv = UndefineFileLocations();
NS_ASSERTION(NS_SUCCEEDED(rv), "Could not undefine file locations");
mCurrentProfileAvailable = PR_FALSE;
return NS_OK;
}
#define SALT_SIZE 8
#define TABLE_SIZE 36
#define SALT_EXTENSION ".slt"
@ -1493,6 +1488,7 @@ NS_IMETHODIMP nsProfile::ForgetCurrentProfile()
if (NS_FAILED(rv)) return rv;
gProfileDataAccess->mForgetProfileCalled = PR_TRUE;
mCurrentProfileAvailable = PR_FALSE;
return rv;
}
@ -1717,6 +1713,31 @@ nsProfile::DefineLocaleDefaultsDir()
return rv;
}
nsresult nsProfile::UndefineFileLocations()
{
nsresult rv;
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
NS_ENSURE_TRUE(directoryService, NS_ERROR_FAILURE);
(void) directoryService->Undefine(NS_APP_PREFS_50_DIR);
(void) directoryService->Undefine(NS_APP_PREFS_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_PROFILE_50_DIR);
(void) directoryService->Undefine(NS_APP_USER_CHROME_DIR);
(void) directoryService->Undefine(NS_APP_LOCALSTORE_50_FILE);
(void) directoryService->Undefine(NS_APP_HISTORY_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_PANELS_50_FILE);
(void) directoryService->Undefine(NS_APP_USER_MIMETYPES_50_FILE);
(void) directoryService->Undefine(NS_APP_BOOKMARKS_50_FILE);
(void) directoryService->Undefine(NS_APP_SEARCH_50_FILE);
(void) directoryService->Undefine(NS_APP_MAIL_50_DIR);
(void) directoryService->Undefine(NS_APP_IMAP_MAIL_50_DIR);
(void) directoryService->Undefine(NS_APP_NEWS_50_DIR);
(void) directoryService->Undefine(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR);
return NS_OK;
}
// Migrate a selected profile
// Set the profile to the current profile....debatable.
// Calls PrefMigration service to do the Copy and Diverge
@ -2093,8 +2114,7 @@ nsProfile::CreateDefaultProfile(void)
rv = profileRootDir->GetUnicodePath(getter_Copies(profilePath));
if (NS_FAILED(rv)) return rv;
nsAutoString defaultProfileName; defaultProfileName.AssignWithConversion(DEFAULT_PROFILE_NAME);
rv = CreateNewProfile(defaultProfileName.GetUnicode(), profilePath, nsnull, PR_TRUE);
rv = CreateNewProfile(DEFAULT_PROFILE_NAME, profilePath, nsnull, PR_TRUE);
return rv;
}

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

@ -65,12 +65,15 @@ private:
nsresult CloneProfileDirectorySpec(nsILocalFile **aLocalFile);
nsresult AddLevelOfIndirection(nsIFile *aDir);
nsresult DefineLocaleDefaultsDir();
nsresult UndefineFileLocations();
PRBool mAutomigrate;
PRBool mOutofDiskSpace;
PRBool mDiskSpaceErrorQuitCalled;
PRBool mProfileChangeVetoed;
PRBool mCurrentProfileAvailable;
public:
nsProfile();
virtual ~nsProfile();

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

@ -80,7 +80,6 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsIPref.h"
#include "nsIObserverService.h"
#include "nsIProfileChangeStatus.h"
static char kChromePrefix[] = "chrome://";
static char kAllPackagesName[] = "all-packages.rdf";
@ -336,8 +335,10 @@ nsChromeRegistry::Init()
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (observerService)
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
if (observerService) {
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
}
CheckForNewChrome();
@ -3058,9 +3059,23 @@ nsChromeRegistry::GetProviderCount(const nsCString& aProviderType, nsIRDFDataSou
NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-before-change").get(), aTopic)) {
mChromeDataSource = nsnull;
mProfileInitialized = PR_FALSE;
if (!nsCRT::strcmp(PROFILE_DO_CHANGE_TOPIC, aTopic))
rv = LoadProfileDataSource();
if (!nsCRT::strcmp(NS_LITERAL_STRING("shutdown-cleanse").get(), someData)) {
nsCOMPtr<nsIFile> userChromeDir;
rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir));
if (NS_SUCCEEDED(rv) && userChromeDir)
rv = userChromeDir->Delete(PR_TRUE);
}
}
else if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-do-change").get(), aTopic)) {
if (!mProfileInitialized)
rv = LoadProfileDataSource();
}
return rv;
}

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

@ -42,13 +42,16 @@
#include "nsCOMPtr.h"
#include "nsWeakPtr.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIObserverService.h"
#include "nsWeakReference.h"
////////////////////////////////////////////////////////////////////////
class LocalStoreImpl : public nsILocalStore,
public nsIRDFDataSource,
public nsIRDFRemoteDataSource
public nsIRDFRemoteDataSource,
public nsIObserver,
public nsSupportsWeakReference
{
protected:
nsCOMPtr<nsIRDFDataSource> mInner;
@ -198,6 +201,9 @@ public:
NS_IMETHOD Init(const char *uri);
NS_IMETHOD Flush();
NS_IMETHOD Refresh(PRBool sync);
// nsIObserver
NS_DECL_NSIOBSERVER
};
nsWeakPtr LocalStoreImpl::gRDF;
@ -250,6 +256,13 @@ NS_NewLocalStore(nsISupports* aOuter, REFNSIID aIID, void** aResult)
printf("\n\nRDF: NS_NewLocalStore::Refresh() failed.\n\n");
#endif
}
// Register as an observer of profile changes
NS_WITH_SERVICE(nsIObserverService, svc, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv) && svc) {
svc->AddObserver(impl, NS_LITERAL_STRING("profile-before-change").get());
svc->AddObserver(impl, NS_LITERAL_STRING("profile-do-change").get());
}
}
NS_RELEASE(impl);
@ -281,6 +294,12 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
else if (aIID.Equals(NS_GET_IID(nsIRDFRemoteDataSource))) {
*aResult = NS_STATIC_CAST(nsIRDFRemoteDataSource *, this);
}
else if (aIID.Equals(NS_GET_IID(nsIObserver))) {
*aResult = NS_STATIC_CAST(nsIObserver *, this);
}
else if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference))) {
*aResult = NS_STATIC_CAST(nsISupportsWeakReference *, this);
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
@ -393,7 +412,8 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
if (NS_FAILED(rv)) return rv;
// for later
gRDF = getter_AddRefs(NS_GetWeakReference(rdf));
if (!gRDF)
gRDF = getter_AddRefs(NS_GetWeakReference(rdf));
rv = rdf->RegisterDataSource(this, PR_FALSE);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register local store");
@ -454,3 +474,30 @@ LocalStoreImpl::DoCommand(nsISupportsArray* aSources,
// no-op
return NS_OK;
}
NS_IMETHODIMP
LocalStoreImpl::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get())) {
nsCOMPtr<nsIRDFService> rdf = do_QueryReferent(gRDF);
if (rdf)
rdf->UnregisterDataSource(this);
mInner = nsnull;
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
nsCOMPtr<nsIFile> aFile;
rv = NS_GetSpecialDirectory(NS_APP_LOCALSTORE_50_FILE, getter_AddRefs(aFile));
if (NS_SUCCEEDED(rv))
rv = aFile->Delete(PR_FALSE);
}
}
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get())) {
rv = Init();
if (NS_SUCCEEDED(rv))
rv = Refresh(PR_TRUE);
}
return rv;
}

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

@ -37,7 +37,6 @@
#include "nsFileStream.h"
#include "nsIComponentManager.h"
#include "nsIDOMWindowInternal.h"
#include "nsIProfileChangeStatus.h"
#include "nsIObserverService.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
@ -1682,8 +1681,8 @@ nsBookmarksService::Init()
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
NS_ASSERTION(observerService, "Could not get observer service.");
if (observerService) {
observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
}
// read in bookmarks AFTER trying to get string bundle
@ -2482,12 +2481,19 @@ NS_IMETHODIMP nsBookmarksService::Observe(nsISupports *aSubject, const PRUnichar
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, PROFILE_BEFORE_CHANGE_TOPIC))
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get()))
{
// The profile has not changed yet.
rv = Flush();
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
nsFileSpec bookmarksFile;
rv = GetBookmarksFile(&bookmarksFile);
if (NS_SUCCEEDED(rv) && bookmarksFile.IsFile())
bookmarksFile.Delete(PR_FALSE);
}
}
else if (!nsCRT::strcmp(aTopic, PROFILE_DO_CHANGE_TOPIC))
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get()))
{
// The profile has aleady changed.
rv = ReadBookmarks();

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

@ -60,7 +60,6 @@
#include "nsIMdbFactoryFactory.h"
#include "nsIPref.h"
#include "nsIProfileChangeStatus.h"
#include "nsIObserverService.h"
PRInt32 nsGlobalHistory::gRefCnt;
@ -2019,8 +2018,8 @@ nsGlobalHistory::Init()
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
NS_ASSERTION(observerService, "failed to get observer service");
if (observerService) {
observerService->AddObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
observerService->AddObserver(this, PROFILE_DO_CHANGE_TOPIC);
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
}
rv = OpenDB();
@ -2891,9 +2890,16 @@ nsGlobalHistory::Observe(nsISupports *aSubject, const PRUnichar *aTopic,
}
}
else if (aTopicString.Equals(PROFILE_BEFORE_CHANGE_TOPIC))
rv = CloseDB();
else if (aTopicString.Equals(PROFILE_DO_CHANGE_TOPIC))
else if (aTopicString.Equals(NS_LITERAL_STRING("profile-before-change"))) {
rv = CloseDB();
if (!nsCRT::strcmp(aSomeData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
nsCOMPtr <nsIFile> historyFile;
rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE, getter_AddRefs(historyFile));
if (NS_SUCCEEDED(rv))
rv = historyFile->Delete(PR_FALSE);
}
}
else if (aTopicString.Equals(NS_LITERAL_STRING("profile-do-change")))
rv = OpenDB();
return NS_OK;

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

@ -63,6 +63,8 @@
#include "nsIBookmarksService.h"
#include "nsIHTTPHeader.h"
#include "nsIStringBundle.h"
#include "nsIObserverService.h"
#include "nsIURL.h"
#ifdef XP_MAC
#include <Files.h>
@ -830,6 +832,7 @@ NS_INTERFACE_MAP_BEGIN(InternetSearchDataSource)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIInternetSearchService)
NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END
@ -875,6 +878,13 @@ InternetSearchDataSource::Init()
// we now build up the list of engines immediately,
// but still defer loading in of the contents until needed
DeferredInit();
// Register as a profile change obsevrer
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (observerService) {
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
observerService->AddObserver(this, NS_LITERAL_STRING("profile-do-change").get());
}
return(rv);
}
@ -1200,17 +1210,20 @@ InternetSearchDataSource::GetCategoryList()
// get search.rdf
nsCOMPtr<nsIFile> searchFile;
nsXPIDLCString filePath;
rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
if (NS_FAILED(rv)) return rv;
rv = searchFile->GetPath(getter_Copies(filePath));
if (NS_FAILED(rv)) return rv;
nsFileSpec fileSpec(filePath);
nsFileURL fileURL(fileSpec);
if (NS_FAILED(rv = remoteCategoryDataSource->Init(fileURL.GetURLString()))) return(rv);
nsCOMPtr<nsIFile> searchFile;
nsXPIDLCString searchFileURLSpec;
rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFileURL> searchFileURL(do_CreateInstance("@mozilla.org/network/standard-url;1", &rv));
if (NS_FAILED(rv)) return rv;
rv = searchFileURL->SetFile(searchFile);
if (NS_FAILED(rv)) return rv;
rv = searchFileURL->GetSpec(getter_Copies(searchFileURLSpec));
if (NS_FAILED(rv)) return rv;
rv = remoteCategoryDataSource->Init(searchFileURLSpec);
if (NS_FAILED(rv)) return rv;
// synchronous read
rv = remoteCategoryDataSource->Refresh(PR_TRUE);
if (NS_FAILED(rv)) return(rv);
@ -5721,3 +5734,32 @@ InternetSearchDataSource::ConvertEntities(nsString &nameStr, PRBool removeHTMLFl
return(NS_OK);
}
NS_IMETHODIMP
InternetSearchDataSource::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
nsresult rv = NS_OK;
if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-before-change").get()))
{
// The profile is about to change.
categoryDataSource = nsnull;
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get()))
{
// Delete search.rdf
nsCOMPtr<nsIFile> searchFile;
rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
if (NS_SUCCEEDED(rv))
rv = searchFile->Delete(PR_FALSE);
}
}
else if (!nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-do-change").get()))
{
// The profile has aleady changed.
if (!categoryDataSource)
GetCategoryList();
}
return rv;
}

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

@ -28,6 +28,7 @@
#include "nsISearchService.h"
#include "nsIRDFDataSource.h"
#include "nsIStreamListener.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsIRDFService.h"
#include "nsITimer.h"
@ -40,6 +41,7 @@
class InternetSearchDataSource : public nsIInternetSearchService,
public nsIRDFDataSource,
public nsIStreamListener,
public nsIObserver,
public nsSupportsWeakReference
{
private:
@ -158,6 +160,7 @@ public:
NS_DECL_NSISTREAMOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIRDFDATASOURCE
NS_DECL_NSIOBSERVER
InternetSearchDataSource(void);
virtual ~InternetSearchDataSource(void);