зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1684897: Ensure that xpcom/io/CocoaFileUtils.mm uses NSAutoReleasePools. r=mac-reviewers,mstange
Differential Revision: https://phabricator.services.mozilla.com/D197607
This commit is contained in:
Родитель
c5c0e87897
Коммит
41a9498074
|
@ -10,6 +10,7 @@
|
|||
#ifndef CocoaFileUtils_h_
|
||||
#define CocoaFileUtils_h_
|
||||
|
||||
#include "CFTypeRefPtr.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
@ -37,9 +38,9 @@ void AddQuarantineMetadataToFile(const CFStringRef filePath,
|
|||
void CopyQuarantineReferrerUrl(const CFStringRef aFilePath,
|
||||
nsAString& aReferrer);
|
||||
|
||||
CFURLRef GetTemporaryFolderCFURLRef();
|
||||
CFTypeRefPtr<CFURLRef> GetTemporaryFolder();
|
||||
|
||||
CFURLRef GetProductDirectoryCFURLRef(bool aLocal);
|
||||
CFTypeRefPtr<CFURLRef> GetProductDirectory(bool aLocal);
|
||||
|
||||
} // namespace CocoaFileUtils
|
||||
|
||||
|
|
|
@ -17,12 +17,14 @@ namespace CocoaFileUtils {
|
|||
nsresult RevealFileInFinder(CFURLRef url) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (NS_WARN_IF(!url)) return NS_ERROR_INVALID_ARG;
|
||||
if (NS_WARN_IF(!url)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
BOOL success = [[NSWorkspace sharedWorkspace] selectFile:[(NSURL*)url path]
|
||||
inFileViewerRootedAtPath:@""];
|
||||
[ap release];
|
||||
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -32,11 +34,13 @@ nsresult RevealFileInFinder(CFURLRef url) {
|
|||
nsresult OpenURL(CFURLRef url) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (NS_WARN_IF(!url)) return NS_ERROR_INVALID_ARG;
|
||||
if (NS_WARN_IF(!url)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
BOOL success = [[NSWorkspace sharedWorkspace] openURL:(NSURL*)url];
|
||||
[ap release];
|
||||
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -46,7 +50,9 @@ nsresult OpenURL(CFURLRef url) {
|
|||
nsresult GetFileCreatorCode(CFURLRef url, OSType* creatorCode) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (NS_WARN_IF(!url) || NS_WARN_IF(!creatorCode)) return NS_ERROR_INVALID_ARG;
|
||||
if (NS_WARN_IF(!url) || NS_WARN_IF(!creatorCode)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
|
@ -76,9 +82,12 @@ nsresult GetFileCreatorCode(CFURLRef url, OSType* creatorCode) {
|
|||
nsresult SetFileCreatorCode(CFURLRef url, OSType creatorCode) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (NS_WARN_IF(!url)) return NS_ERROR_INVALID_ARG;
|
||||
if (NS_WARN_IF(!url)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
NSDictionary* dict = [NSDictionary
|
||||
dictionaryWithObject:[NSNumber numberWithUnsignedLong:creatorCode]
|
||||
forKey:NSFileHFSCreatorCode];
|
||||
|
@ -86,7 +95,7 @@ nsresult SetFileCreatorCode(CFURLRef url, OSType creatorCode) {
|
|||
[[NSFileManager defaultManager] setAttributes:dict
|
||||
ofItemAtPath:[(NSURL*)url path]
|
||||
error:nil];
|
||||
[ap release];
|
||||
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
|
||||
|
@ -95,7 +104,9 @@ nsresult SetFileCreatorCode(CFURLRef url, OSType creatorCode) {
|
|||
nsresult GetFileTypeCode(CFURLRef url, OSType* typeCode) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (NS_WARN_IF(!url) || NS_WARN_IF(!typeCode)) return NS_ERROR_INVALID_ARG;
|
||||
if (NS_WARN_IF(!url) || NS_WARN_IF(!typeCode)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
|
@ -125,9 +136,12 @@ nsresult GetFileTypeCode(CFURLRef url, OSType* typeCode) {
|
|||
nsresult SetFileTypeCode(CFURLRef url, OSType typeCode) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (NS_WARN_IF(!url)) return NS_ERROR_INVALID_ARG;
|
||||
if (NS_WARN_IF(!url)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
NSAutoreleasePool* ap = [[NSAutoreleasePool alloc] init];
|
||||
NSDictionary* dict = [NSDictionary
|
||||
dictionaryWithObject:[NSNumber numberWithUnsignedLong:typeCode]
|
||||
forKey:NSFileHFSTypeCode];
|
||||
|
@ -135,7 +149,7 @@ nsresult SetFileTypeCode(CFURLRef url, OSType typeCode) {
|
|||
[[NSFileManager defaultManager] setAttributes:dict
|
||||
ofItemAtPath:[(NSURL*)url path]
|
||||
error:nil];
|
||||
[ap release];
|
||||
|
||||
return (success ? NS_OK : NS_ERROR_FAILURE);
|
||||
|
||||
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
|
||||
|
@ -145,6 +159,8 @@ nsresult SetFileTypeCode(CFURLRef url, OSType typeCode) {
|
|||
void AddOriginMetadataToFile(const CFStringRef filePath,
|
||||
const CFURLRef sourceURL,
|
||||
const CFURLRef referrerURL) {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
typedef OSStatus (*MDItemSetAttribute_type)(MDItemRef, CFStringRef,
|
||||
CFTypeRef);
|
||||
static MDItemSetAttribute_type mdItemSetAttributeFunc = NULL;
|
||||
|
@ -197,6 +213,8 @@ void AddOriginMetadataToFile(const CFStringRef filePath,
|
|||
// Can be called off of the main thread.
|
||||
static CFMutableDictionaryRef CreateQuarantineDictionary(
|
||||
const CFURLRef aFileURL, const bool aCreateProps) {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
CFDictionaryRef quarantineProps = NULL;
|
||||
if (aCreateProps) {
|
||||
quarantineProps = ::CFDictionaryCreate(NULL, NULL, NULL, 0,
|
||||
|
@ -232,6 +250,8 @@ void AddQuarantineMetadataToFile(const CFStringRef filePath,
|
|||
const CFURLRef referrerURL,
|
||||
const bool isFromWeb,
|
||||
const bool createProps /* = false */) {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
CFURLRef fileURL = ::CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault, filePath, kCFURLPOSIXPathStyle, false);
|
||||
|
||||
|
@ -273,6 +293,8 @@ void AddQuarantineMetadataToFile(const CFStringRef filePath,
|
|||
// Can be called off of the main thread.
|
||||
void CopyQuarantineReferrerUrl(const CFStringRef aFilePath,
|
||||
nsAString& aReferrer) {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
CFURLRef fileURL = ::CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault, aFilePath, kCFURLPOSIXPathStyle, false);
|
||||
|
||||
|
@ -295,20 +317,25 @@ void CopyQuarantineReferrerUrl(const CFStringRef aFilePath,
|
|||
::CFRelease(mutQuarantineProps);
|
||||
}
|
||||
|
||||
CFURLRef GetTemporaryFolderCFURLRef() {
|
||||
CFTypeRefPtr<CFURLRef> GetTemporaryFolder() {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
NSString* tempDir = ::NSTemporaryDirectory();
|
||||
return tempDir == nil
|
||||
? NULL
|
||||
: (CFURLRef)[NSURL fileURLWithPath:tempDir isDirectory:YES];
|
||||
return tempDir == nil ? NULL
|
||||
: CFTypeRefPtr<CFURLRef>::WrapUnderGetRule(
|
||||
(__bridge CFURLRef)[NSURL fileURLWithPath:tempDir
|
||||
isDirectory:YES]);
|
||||
}
|
||||
|
||||
CFURLRef GetProductDirectoryCFURLRef(bool aLocal) {
|
||||
CFTypeRefPtr<CFURLRef> GetProductDirectory(bool aLocal) {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
NSSearchPathDirectory folderType =
|
||||
aLocal ? NSCachesDirectory : NSLibraryDirectory;
|
||||
NSFileManager* manager = [NSFileManager defaultManager];
|
||||
return static_cast<CFURLRef>(
|
||||
[[manager URLsForDirectory:folderType
|
||||
inDomains:NSUserDomainMask] firstObject]);
|
||||
return CFTypeRefPtr<CFURLRef>::WrapUnderGetRule((__bridge CFURLRef)[[manager
|
||||
URLsForDirectory:folderType
|
||||
inDomains:NSUserDomainMask] firstObject]);
|
||||
}
|
||||
|
||||
} // namespace CocoaFileUtils
|
||||
|
|
|
@ -710,7 +710,7 @@ nsresult GetOSXFolderType(short aDomain, OSType aFolderType,
|
|||
nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*aLocalFile));
|
||||
if (localMacFile) {
|
||||
rv = localMacFile->InitWithCFURL(
|
||||
CocoaFileUtils::GetTemporaryFolderCFURLRef());
|
||||
CocoaFileUtils::GetTemporaryFolder().get());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ nsresult nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
|
|||
nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
|
||||
|
||||
rv = localDirMac->InitWithCFURL(
|
||||
CocoaFileUtils::GetProductDirectoryCFURLRef(aLocal));
|
||||
CocoaFileUtils::GetProductDirectory(aLocal).get());
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче