Changeset 211236 in webkit
- Timestamp:
- Jan 26, 2017 3:50:28 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r211235 r211236 1 2017-01-26 Andy Estes <aestes@apple.com> 2 3 [QuickLook] Create temporary files with NSFileProtectionCompleteUnlessOpen 4 https://bugs.webkit.org/show_bug.cgi?id=167455 5 <rdar://problem/12499118> 6 7 Reviewed by David Kilzer. 8 9 Add the NSFileProtectionKey attribute with value NSFileProtectionCompleteUnlessOpen to 10 temporary directories created for QuickLook files. Also: 11 12 1. Stop calling -[NSFileManager _web_pathWithUniqueFilenameForPath:], since the temporary 13 directory is already unique and only one file will be placed inside it. 14 2. Create the temporary file with -[NSFileManager _web_createFileAtPath:contents:attributes:] 15 instead of with -[NSFileManager _web_createFileAtPathWithIntermediateDirectories:contents:attributes:directoryAttributes:], 16 since the intermediate directories were already created by createTemporaryDirectory(). 17 3. Explicitly set the temporary directory's attributes with 18 -[NSFileManager setAttributes:ofItemAtPath:error:]. 19 4. Append the lastPathComponent of fileName to downloadDirectory to ensure fileName isn't 20 really a relative path. 21 22 * loader/ios/QuickLook.h: Stopped declaring QLFileAttributes() and QLDirectoryAttributes(). 23 * loader/ios/QuickLook.mm: 24 (WebCore::temporaryFileAttributes): Renamed from QLFileAttributes(). 25 (WebCore::temporaryDirectoryAttributes): Renamed from QLDirectoryAttributes(). 26 (WebCore::createTemporaryFileForQuickLook): 27 (WebCore::QLFileAttributes): Deleted. 28 (WebCore::QLDirectoryAttributes): Deleted. 29 * platform/spi/cocoa/NSFileManagerSPI.h: Declared -_web_createFileAtPath:contents:attributes: 30 and removed declarations for -_web_createFileAtPathWithIntermediateDirectories:contents:attributes:directoryAttributes: 31 and -_web_pathWithUniqueFilenameForPath: 32 1 33 2017-01-26 Jeremy Jones <jeremyj@apple.com> 2 34 -
trunk/Source/WebCore/loader/ios/QuickLook.h
r210864 r211236 53 53 WEBCORE_EXPORT NSSet *QLPreviewGetSupportedMIMETypesSet(); 54 54 55 // Used for setting the permissions on the saved QL content56 NSDictionary *QLFileAttributes();57 NSDictionary *QLDirectoryAttributes();58 59 55 WEBCORE_EXPORT void addQLPreviewConverterWithFileForURL(NSURL *, id converter, NSString *fileName); 60 56 WEBCORE_EXPORT NSString *qlPreviewConverterFileNameForURL(NSURL *); -
trunk/Source/WebCore/loader/ios/QuickLook.mm
r210864 r211236 50 50 } 51 51 52 NSDictionary *WebCore::QLFileAttributes()53 {54 // Set file perms to owner read/write only55 NSNumber *filePOSIXPermissions = [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE)];56 static NSDictionary *dictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:57 NSUserName(), NSFileOwnerAccountName,58 filePOSIXPermissions, NSFilePosixPermissions,59 nullptr]).leakRef();60 return dictionary;61 }62 63 NSDictionary *WebCore::QLDirectoryAttributes()64 {65 // Set file perms to owner read/write/execute only66 NSNumber *directoryPOSIXPermissions = [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE | WEB_UEXEC)];67 static NSDictionary *dictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:68 NSUserName(), NSFileOwnerAccountName,69 directoryPOSIXPermissions, NSFilePosixPermissions,70 nullptr]).leakRef();71 return dictionary;72 }73 74 52 static Lock& qlPreviewConverterDictionaryMutex() 75 53 { … … 348 326 namespace WebCore { 349 327 328 static NSDictionary *temporaryFileAttributes() 329 { 330 static NSDictionary *attributes = [@{ 331 NSFileOwnerAccountName : NSUserName(), 332 NSFilePosixPermissions : [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE)], 333 } retain]; 334 return attributes; 335 } 336 337 static NSDictionary *temporaryDirectoryAttributes() 338 { 339 static NSDictionary *attributes = [@{ 340 NSFileOwnerAccountName : NSUserName(), 341 NSFilePosixPermissions : [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE | WEB_UEXEC)], 342 NSFileProtectionKey : NSFileProtectionCompleteUnlessOpen, 343 } retain]; 344 return attributes; 345 } 346 350 347 NSString *createTemporaryFileForQuickLook(NSString *fileName) 351 348 { … … 354 351 return nil; 355 352 356 NSString *contentPath = [downloadDirectory stringByAppendingPathComponent:fileName];357 353 NSFileManager *fileManager = [NSFileManager defaultManager]; 358 NSString *uniqueContentPath = [fileManager _web_pathWithUniqueFilenameForPath:contentPath]; 359 360 BOOL success = [fileManager _web_createFileAtPathWithIntermediateDirectories:uniqueContentPath 361 contents:nil 362 attributes:QLFileAttributes() 363 directoryAttributes:QLDirectoryAttributes()]; 364 365 return success ? uniqueContentPath : nil; 354 355 NSError *error; 356 if (![fileManager setAttributes:temporaryDirectoryAttributes() ofItemAtPath:downloadDirectory error:&error]) { 357 LOG_ERROR("Failed to set attribute NSFileProtectionCompleteUnlessOpen on directory %@ with error: %@.", downloadDirectory, error.localizedDescription); 358 return nil; 359 } 360 361 NSString *contentPath = [downloadDirectory stringByAppendingPathComponent:fileName.lastPathComponent]; 362 if (![fileManager _web_createFileAtPath:contentPath contents:nil attributes:temporaryFileAttributes()]) { 363 LOG_ERROR("Failed to create QuickLook temporary file at path %@.", contentPath); 364 return nil; 365 } 366 367 return contentPath; 366 368 } 367 369 -
trunk/Source/WebCore/platform/spi/cocoa/NSFileManagerSPI.h
r187609 r211236 37 37 38 38 @interface NSFileManager () 39 - (BOOL)_web_createFileAtPathWithIntermediateDirectories:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes directoryAttributes:(NSDictionary *)directoryAttributes; 40 - (NSString *)_web_pathWithUniqueFilenameForPath:(NSString *)path; 39 - (BOOL)_web_createFileAtPath:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes; 41 40 - (BOOL)_web_removeFileOnlyAtPath:(NSString *)path; 42 41 @end
Note: See TracChangeset
for help on using the changeset viewer.