Changeset 211236 in webkit


Ignore:
Timestamp:
Jan 26, 2017 3:50:28 PM (7 years ago)
Author:
aestes@apple.com
Message:

[QuickLook] Create temporary files with NSFileProtectionCompleteUnlessOpen
https://bugs.webkit.org/show_bug.cgi?id=167455
<rdar://problem/12499118>

Reviewed by David Kilzer.

Add the NSFileProtectionKey attribute with value NSFileProtectionCompleteUnlessOpen to
temporary directories created for QuickLook files. Also:

  1. Stop calling -[NSFileManager _web_pathWithUniqueFilenameForPath:], since the temporary

directory is already unique and only one file will be placed inside it.

  1. Create the temporary file with -[NSFileManager _web_createFileAtPath:contents:attributes:]

instead of with -[NSFileManager _web_createFileAtPathWithIntermediateDirectories:contents:attributes:directoryAttributes:],
since the intermediate directories were already created by createTemporaryDirectory().

  1. Explicitly set the temporary directory's attributes with

-[NSFileManager setAttributes:ofItemAtPath:error:].

  1. Append the lastPathComponent of fileName to downloadDirectory to ensure fileName isn't

really a relative path.

  • loader/ios/QuickLook.h: Stopped declaring QLFileAttributes() and QLDirectoryAttributes().
  • loader/ios/QuickLook.mm:

(WebCore::temporaryFileAttributes): Renamed from QLFileAttributes().
(WebCore::temporaryDirectoryAttributes): Renamed from QLDirectoryAttributes().
(WebCore::createTemporaryFileForQuickLook):
(WebCore::QLFileAttributes): Deleted.
(WebCore::QLDirectoryAttributes): Deleted.

  • platform/spi/cocoa/NSFileManagerSPI.h: Declared -_web_createFileAtPath:contents:attributes:

and removed declarations for -_web_createFileAtPathWithIntermediateDirectories:contents:attributes:directoryAttributes:
and -_web_pathWithUniqueFilenameForPath:

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211235 r211236  
     12017-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
    1332017-01-26  Jeremy Jones  <jeremyj@apple.com>
    234
  • trunk/Source/WebCore/loader/ios/QuickLook.h

    r210864 r211236  
    5353WEBCORE_EXPORT NSSet *QLPreviewGetSupportedMIMETypesSet();
    5454
    55 // Used for setting the permissions on the saved QL content
    56 NSDictionary *QLFileAttributes();
    57 NSDictionary *QLDirectoryAttributes();
    58 
    5955WEBCORE_EXPORT void addQLPreviewConverterWithFileForURL(NSURL *, id converter, NSString *fileName);
    6056WEBCORE_EXPORT NSString *qlPreviewConverterFileNameForURL(NSURL *);
  • trunk/Source/WebCore/loader/ios/QuickLook.mm

    r210864 r211236  
    5050}
    5151
    52 NSDictionary *WebCore::QLFileAttributes()
    53 {
    54     // Set file perms to owner read/write only
    55     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 only
    66     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 
    7452static Lock& qlPreviewConverterDictionaryMutex()
    7553{
     
    348326namespace WebCore {
    349327
     328static 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
     337static 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
    350347NSString *createTemporaryFileForQuickLook(NSString *fileName)
    351348{
     
    354351        return nil;
    355352
    356     NSString *contentPath = [downloadDirectory stringByAppendingPathComponent:fileName];
    357353    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;
    366368}
    367369
  • trunk/Source/WebCore/platform/spi/cocoa/NSFileManagerSPI.h

    r187609 r211236  
    3737
    3838@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;
    4140- (BOOL)_web_removeFileOnlyAtPath:(NSString *)path;
    4241@end
Note: See TracChangeset for help on using the changeset viewer.