Bug 460609 - Temporary files for helper applications are not deleted when leaving Private Browsing mode; r,sr=bzbarsky a=blocking1.9.1
This commit is contained in:
Родитель
1326fc3ac8
Коммит
55ebbf5e5f
|
@ -26,6 +26,7 @@
|
|||
* Christian Biesinger <cbiesinger@web.de>
|
||||
* Dan Mosedale <dmose@mozilla.org>
|
||||
* Myk Melez <myk@mozilla.org>
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
|
@ -124,6 +125,8 @@
|
|||
#include "plbase64.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsIPrivateBrowsingService.h"
|
||||
|
||||
// Buffer file writes in 32kb chunks
|
||||
#define BUFFERED_OUTPUT_SIZE (1024 * 32)
|
||||
|
||||
|
@ -564,12 +567,19 @@ NS_IMPL_ISUPPORTS6(
|
|||
nsIObserver,
|
||||
nsISupportsWeakReference)
|
||||
|
||||
nsExternalHelperAppService::nsExternalHelperAppService()
|
||||
nsExternalHelperAppService::nsExternalHelperAppService() :
|
||||
mInPrivateBrowsing(PR_FALSE)
|
||||
{
|
||||
gExtProtSvc = this;
|
||||
}
|
||||
nsresult nsExternalHelperAppService::Init()
|
||||
{
|
||||
nsCOMPtr<nsIPrivateBrowsingService> pbs =
|
||||
do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
|
||||
if (pbs) {
|
||||
pbs->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
|
||||
}
|
||||
|
||||
// Add an observer for profile change
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIObserverService> obs = do_GetService("@mozilla.org/observer-service;1", &rv);
|
||||
|
@ -583,7 +593,9 @@ nsresult nsExternalHelperAppService::Init()
|
|||
}
|
||||
#endif
|
||||
|
||||
return obs->AddObserver(this, "profile-before-change", PR_TRUE);
|
||||
rv = obs->AddObserver(this, "profile-before-change", PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return obs->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
|
||||
}
|
||||
|
||||
nsExternalHelperAppService::~nsExternalHelperAppService()
|
||||
|
@ -927,7 +939,10 @@ NS_IMETHODIMP nsExternalHelperAppService::DeleteTemporaryFileOnExit(nsIFile * aT
|
|||
localFile->IsFile(&isFile);
|
||||
if (!isFile) return NS_OK;
|
||||
|
||||
mTemporaryFilesList.AppendObject(localFile);
|
||||
if (mInPrivateBrowsing)
|
||||
mTemporaryPrivateFilesList.AppendObject(localFile);
|
||||
else
|
||||
mTemporaryFilesList.AppendObject(localFile);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -937,13 +952,13 @@ void nsExternalHelperAppService::FixFilePermissions(nsILocalFile* aFile)
|
|||
// This space intentionally left blank
|
||||
}
|
||||
|
||||
nsresult nsExternalHelperAppService::ExpungeTemporaryFiles()
|
||||
void nsExternalHelperAppService::ExpungeTemporaryFilesHelper(nsCOMArray<nsILocalFile> &fileList)
|
||||
{
|
||||
PRInt32 numEntries = mTemporaryFilesList.Count();
|
||||
PRInt32 numEntries = fileList.Count();
|
||||
nsILocalFile* localFile;
|
||||
for (PRInt32 index = 0; index < numEntries; index++)
|
||||
{
|
||||
localFile = mTemporaryFilesList[index];
|
||||
localFile = fileList[index];
|
||||
if (localFile) {
|
||||
// First make the file writable, since the temp file is probably readonly.
|
||||
localFile->SetPermissions(0600);
|
||||
|
@ -951,9 +966,17 @@ nsresult nsExternalHelperAppService::ExpungeTemporaryFiles()
|
|||
}
|
||||
}
|
||||
|
||||
mTemporaryFilesList.Clear();
|
||||
fileList.Clear();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
void nsExternalHelperAppService::ExpungeTemporaryFiles()
|
||||
{
|
||||
ExpungeTemporaryFilesHelper(mTemporaryFilesList);
|
||||
}
|
||||
|
||||
void nsExternalHelperAppService::ExpungeTemporaryPrivateFiles()
|
||||
{
|
||||
ExpungeTemporaryFilesHelper(mTemporaryPrivateFilesList);
|
||||
}
|
||||
|
||||
static const char kExternalWarningPrefPrefix[] =
|
||||
|
@ -1042,6 +1065,13 @@ nsExternalHelperAppService::Observe(nsISupports *aSubject, const char *aTopic, c
|
|||
{
|
||||
if (!strcmp(aTopic, "profile-before-change")) {
|
||||
ExpungeTemporaryFiles();
|
||||
} else if (!strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC)) {
|
||||
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).Equals(someData))
|
||||
mInPrivateBrowsing = PR_TRUE;
|
||||
else if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(someData)) {
|
||||
mInPrivateBrowsing = PR_FALSE;
|
||||
ExpungeTemporaryPrivateFiles();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
* Christian Biesinger <cbiesinger@web.de>
|
||||
* Dan Mosedale <dmose@mozilla.org>
|
||||
* Myk Melez <myk@mozilla.org>
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
|
@ -200,15 +201,34 @@ protected:
|
|||
friend class nsExternalAppHandler;
|
||||
friend class nsExternalLoadRequest;
|
||||
|
||||
/**
|
||||
* Helper function for ExpungeTemporaryFiles and ExpungeTemporaryPrivateFiles
|
||||
*/
|
||||
static void ExpungeTemporaryFilesHelper(nsCOMArray<nsILocalFile> &fileList);
|
||||
/**
|
||||
* Functions related to the tempory file cleanup service provided by
|
||||
* nsExternalHelperAppService
|
||||
*/
|
||||
NS_HIDDEN_(nsresult) ExpungeTemporaryFiles();
|
||||
void ExpungeTemporaryFiles();
|
||||
/**
|
||||
* Functions related to the tempory file cleanup service provided by
|
||||
* nsExternalHelperAppService (for the temporary files added during
|
||||
* the private browsing mode)
|
||||
*/
|
||||
void ExpungeTemporaryPrivateFiles();
|
||||
/**
|
||||
* Array for the files that should be deleted
|
||||
*/
|
||||
nsCOMArray<nsILocalFile> mTemporaryFilesList;
|
||||
/**
|
||||
* Array for the files that should be deleted (for the temporary files
|
||||
* added during the private browsing mode)
|
||||
*/
|
||||
nsCOMArray<nsILocalFile> mTemporaryPrivateFilesList;
|
||||
/**
|
||||
* Whether we are in private browsing mode
|
||||
*/
|
||||
PRBool mInPrivateBrowsing;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче