Bug 1752159 - check if target is executable before offering always opening, r=mhowell,mtigley

Depends on D137152

Differential Revision: https://phabricator.services.mozilla.com/D137153
This commit is contained in:
Gijs Kruitbosch 2022-01-27 23:49:38 +00:00
parent 9f3032dc53
commit 377caf35ba
3 changed files with 21 additions and 0 deletions

View File

@ -325,6 +325,9 @@ var DownloadsViewUI = {
mimeInfo.type === "application/octet-stream" ||
mimeInfo.type === "application/x-msdownload" ||
mimeInfo.type === "application/x-msdos-program" ||
gReputationService.isExecutable(
PathUtils.filename(download.target.path)
) ||
(mimeInfo.type === "text/plain" &&
gReputationService.isBinary(download.target.path));

View File

@ -1971,3 +1971,10 @@ nsresult ApplicationReputationService::IsBinary(const nsACString& aFileName,
*aBinary = ::IsBinary(aFileName);
return NS_OK;
}
nsresult ApplicationReputationService::IsExecutable(const nsACString& aFileName,
bool* aExecutable) {
*aExecutable =
::IsFileType(aFileName, sExecutableExts, ArrayLength(sExecutableExts));
return NS_OK;
}

View File

@ -60,6 +60,17 @@ interface nsIApplicationReputationService : nsISupports {
* The filename to check.
*/
bool isBinary(in AUTF8String aFilename);
/**
* Check if a file with this name should be treated as an executable,
* and should not be opened without caution.
* Will return true if the filename's extension is in sExecutableExts
* in nsLocalFileCommon.h.
*
* @param aFilename
* The filename to check.
*/
bool isExecutable(in AUTF8String aFilename);
};
/**