зеркало из https://github.com/mozilla/gecko-dev.git
Bug 124307, respect umask for downloaded files.
r=bzbarsky sr=darin
This commit is contained in:
Родитель
2785900fde
Коммит
d0fdabc0c9
|
@ -108,6 +108,11 @@ static const char NEVER_ASK_FOR_OPEN_FILE_PREF[] = "openFile";
|
|||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
||||
|
||||
/**
|
||||
* Contains a pointer to the helper app service, set in its constructor
|
||||
*/
|
||||
static nsExternalHelperAppService* sSrv;
|
||||
|
||||
// Helper functions for Content-Disposition headers
|
||||
|
||||
/** Gets the content-disposition header from a channel, using nsIHttpChannel
|
||||
|
@ -398,6 +403,7 @@ NS_IMPL_ISUPPORTS6(
|
|||
nsExternalHelperAppService::nsExternalHelperAppService()
|
||||
: mDataSourceInitialized(PR_FALSE)
|
||||
{
|
||||
sSrv = this;
|
||||
}
|
||||
nsresult nsExternalHelperAppService::Init()
|
||||
{
|
||||
|
@ -419,6 +425,7 @@ nsresult nsExternalHelperAppService::Init()
|
|||
|
||||
nsExternalHelperAppService::~nsExternalHelperAppService()
|
||||
{
|
||||
sSrv = nsnull;
|
||||
}
|
||||
|
||||
nsresult nsExternalHelperAppService::InitDataSource()
|
||||
|
@ -620,7 +627,7 @@ nsExternalAppHandler * nsExternalHelperAppService::CreateNewExternalHandler(nsIM
|
|||
// add any XP intialization code for an external handler that we may need here...
|
||||
// right now we don't have any but i bet we will before we are done.
|
||||
|
||||
handler->Init(aMIMEInfo, aTempFileExtension, aWindowContext, aFileName, aIsAttachment, this);
|
||||
handler->Init(aMIMEInfo, aTempFileExtension, aWindowContext, aFileName, aIsAttachment);
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
@ -988,6 +995,11 @@ NS_IMETHODIMP nsExternalHelperAppService::DeleteTemporaryFileOnExit(nsIFile * aT
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsExternalHelperAppService::FixFilePermissions(nsILocalFile* aFile)
|
||||
{
|
||||
// This space intentionally left blank
|
||||
}
|
||||
|
||||
nsresult nsExternalHelperAppService::ExpungeTemporaryFiles()
|
||||
{
|
||||
PRInt32 numEntries = mTemporaryFilesList.Count();
|
||||
|
@ -1043,13 +1055,11 @@ nsExternalAppHandler::nsExternalAppHandler()
|
|||
mProgressListenerInitialized = PR_FALSE;
|
||||
mContentLength = -1;
|
||||
mProgress = 0;
|
||||
mHelperAppService = nsnull;
|
||||
mRequest = nsnull;
|
||||
}
|
||||
|
||||
nsExternalAppHandler::~nsExternalAppHandler()
|
||||
{
|
||||
NS_IF_RELEASE(mHelperAppService);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExternalAppHandler::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData )
|
||||
|
@ -1334,10 +1344,10 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
|
|||
rv = encEnum->GetNext(encType);
|
||||
if (NS_SUCCEEDED(rv) && !encType.IsEmpty())
|
||||
{
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized");
|
||||
mHelperAppService->ApplyDecodingForExtension(extension.get(),
|
||||
encType.get(),
|
||||
&applyConversion);
|
||||
NS_ASSERTION(sSrv, "Where did the service go?");
|
||||
sSrv->ApplyDecodingForExtension(extension.get(),
|
||||
encType.get(),
|
||||
&applyConversion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1366,8 +1376,8 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
|
|||
// at some point in the distant past that they don't
|
||||
// want to be asked. The latter fact would have been
|
||||
// stored in pref strings back in the old days.
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized properly");
|
||||
if (!mHelperAppService->MIMETypeIsInDataSource(MIMEType.get()))
|
||||
NS_ASSERTION(sSrv, "Service gone away!?");
|
||||
if (!sSrv->MIMETypeIsInDataSource(MIMEType.get()))
|
||||
{
|
||||
if (!GetNeverAskFlagFromPref(NEVER_ASK_FOR_SAVE_TO_DISK_PREF, MIMEType.get()))
|
||||
{
|
||||
|
@ -1727,8 +1737,7 @@ nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo,
|
|||
const char * aTempFileExtension,
|
||||
nsISupports * aWindowContext,
|
||||
const nsAString& aSuggestedFilename,
|
||||
PRBool aIsAttachment,
|
||||
nsExternalHelperAppService *aHelperAppService)
|
||||
PRBool aIsAttachment)
|
||||
{
|
||||
mWindowContext = aWindowContext;
|
||||
mMimeInfo = aMIMEInfo;
|
||||
|
@ -1748,9 +1757,6 @@ nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo,
|
|||
// Make sure extension is correct.
|
||||
EnsureSuggestedFileName();
|
||||
|
||||
mHelperAppService = aHelperAppService;
|
||||
NS_IF_ADDREF(mHelperAppService);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1873,6 +1879,7 @@ nsresult nsExternalAppHandler::MoveFile(nsIFile * aNewFileLocation)
|
|||
if (directoryLocation)
|
||||
{
|
||||
rv = mTempFile->MoveToNative(directoryLocation, fileName);
|
||||
sSrv->FixFilePermissions(fileToUse);
|
||||
}
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
|
@ -2004,10 +2011,11 @@ nsresult nsExternalAppHandler::OpenWithApplication()
|
|||
else
|
||||
{
|
||||
#if !defined(XP_MAC) && !defined (XP_MACOSX)
|
||||
NS_ASSERTION(mHelperAppService, "Not initialized");
|
||||
NS_ASSERTION(sSrv, "Service gone away!?");
|
||||
// Mac users have been very verbal about temp files being deleted on app exit - they
|
||||
// don't like it - but we'll continue to do this on other platforms for now
|
||||
mHelperAppService->DeleteTemporaryFileOnExit(mFinalFileDestination);
|
||||
rv = sSrv->LaunchAppWithTempFile(mMimeInfo, mFinalFileDestination);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,6 +234,13 @@ protected:
|
|||
nsresult GetMIMEInfoForExtensionFromExtras(const char * aExtension,
|
||||
nsIMIMEInfo * aMIMEInfo);
|
||||
|
||||
/**
|
||||
* Fixes the file permissions to be correct. Base class has a no-op
|
||||
* implementation, subclasses can use this to correctly inherit ACLs from the
|
||||
* parent directory, to make the permissions obey the umask, etc.
|
||||
*/
|
||||
virtual void FixFilePermissions(nsILocalFile* aFile);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
/**
|
||||
* NSPR Logging Module. Usage: set NSPR_LOG_MODULES=HelperAppService:level,
|
||||
|
@ -242,9 +249,9 @@ protected:
|
|||
*/
|
||||
static PRLogModuleInfo* mLog;
|
||||
|
||||
// friend, so that it can access the nspr log module
|
||||
friend class nsExternalAppHandler;
|
||||
#endif
|
||||
// friend, so that it can access the nspr log module and FixFilePermissions
|
||||
friend class nsExternalAppHandler;
|
||||
|
||||
/**
|
||||
* Functions related to the tempory file cleanup service provided by
|
||||
|
@ -289,8 +296,7 @@ public:
|
|||
nsresult Init(nsIMIMEInfo * aMIMEInfo, const char * aFileExtension,
|
||||
nsISupports * aWindowContext,
|
||||
const nsAString& aFilename,
|
||||
PRBool aIsAttachment,
|
||||
nsExternalHelperAppService *aHelperAppService);
|
||||
PRBool aIsAttachment);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mTempFile;
|
||||
|
@ -405,7 +411,6 @@ protected:
|
|||
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
|
||||
nsCOMPtr<nsIChannel> mOriginalChannel; /**< in the case of a redirect, this will be the pre-redirect channel. */
|
||||
nsCOMPtr<nsIHelperAppLauncherDialog> mDialog;
|
||||
nsExternalHelperAppService *mHelperAppService;
|
||||
|
||||
/**
|
||||
* The request that's being loaded. Not used after OnStopRequest, so a weak
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
* Boris Zbarsky <bzbarsky@mit.edu> (Added mailcap and mime.types support)
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "nsOSHelperAppService.h"
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "nsGNOMERegistry.h"
|
||||
|
@ -70,6 +73,10 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
|
|||
#ifdef MOZ_WIDGET_GTK2
|
||||
nsGNOMERegistry::Startup();
|
||||
#endif
|
||||
|
||||
mode_t mask = umask(0777);
|
||||
umask(mask);
|
||||
mPermissions = 0666 & ~mask;
|
||||
}
|
||||
|
||||
nsOSHelperAppService::~nsOSHelperAppService()
|
||||
|
@ -1607,3 +1614,9 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
|
|||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
nsOSHelperAppService::FixFilePermissions(nsILocalFile* aFile)
|
||||
{
|
||||
aFile->SetPermissions(mPermissions);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,10 @@ protected:
|
|||
already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMimeType);
|
||||
already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
|
||||
|
||||
virtual void FixFilePermissions(nsILocalFile* aFile);
|
||||
private:
|
||||
PRUint32 mPermissions;
|
||||
|
||||
// Helper methods which have to access static members
|
||||
static nsresult UnescapeCommand(const nsAString& aEscapedCommand,
|
||||
const nsAString& aMajorType,
|
||||
|
|
Загрузка…
Ссылка в новой задаче