Title: [211236] trunk/Source/WebCore
- Revision
- 211236
- Author
- aes...@apple.com
- Date
- 2017-01-26 15:50:28 -0800 (Thu, 26 Jan 2017)
Log 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.
2. 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().
3. Explicitly set the temporary directory's attributes with
-[NSFileManager setAttributes:ofItemAtPath:error:].
4. 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (211235 => 211236)
--- trunk/Source/WebCore/ChangeLog 2017-01-26 23:47:53 UTC (rev 211235)
+++ trunk/Source/WebCore/ChangeLog 2017-01-26 23:50:28 UTC (rev 211236)
@@ -1,3 +1,35 @@
+2017-01-26 Andy Estes <aes...@apple.com>
+
+ [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.
+ 2. 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().
+ 3. Explicitly set the temporary directory's attributes with
+ -[NSFileManager setAttributes:ofItemAtPath:error:].
+ 4. 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:
+
2017-01-26 Jeremy Jones <jere...@apple.com>
Pointer lock events should be delivered directly to the target element
Modified: trunk/Source/WebCore/loader/ios/QuickLook.h (211235 => 211236)
--- trunk/Source/WebCore/loader/ios/QuickLook.h 2017-01-26 23:47:53 UTC (rev 211235)
+++ trunk/Source/WebCore/loader/ios/QuickLook.h 2017-01-26 23:50:28 UTC (rev 211236)
@@ -52,10 +52,6 @@
WEBCORE_EXPORT NSSet *QLPreviewGetSupportedMIMETypesSet();
-// Used for setting the permissions on the saved QL content
-NSDictionary *QLFileAttributes();
-NSDictionary *QLDirectoryAttributes();
-
WEBCORE_EXPORT void addQLPreviewConverterWithFileForURL(NSURL *, id converter, NSString *fileName);
WEBCORE_EXPORT NSString *qlPreviewConverterFileNameForURL(NSURL *);
WEBCORE_EXPORT NSString *qlPreviewConverterUTIForURL(NSURL *);
Modified: trunk/Source/WebCore/loader/ios/QuickLook.mm (211235 => 211236)
--- trunk/Source/WebCore/loader/ios/QuickLook.mm 2017-01-26 23:47:53 UTC (rev 211235)
+++ trunk/Source/WebCore/loader/ios/QuickLook.mm 2017-01-26 23:50:28 UTC (rev 211236)
@@ -49,28 +49,6 @@
return set.get().get();
}
-NSDictionary *WebCore::QLFileAttributes()
-{
- // Set file perms to owner read/write only
- NSNumber *filePOSIXPermissions = [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE)];
- static NSDictionary *dictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:
- NSUserName(), NSFileOwnerAccountName,
- filePOSIXPermissions, NSFilePosixPermissions,
- nullptr]).leakRef();
- return dictionary;
-}
-
-NSDictionary *WebCore::QLDirectoryAttributes()
-{
- // Set file perms to owner read/write/execute only
- NSNumber *directoryPOSIXPermissions = [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE | WEB_UEXEC)];
- static NSDictionary *dictionary = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:
- NSUserName(), NSFileOwnerAccountName,
- directoryPOSIXPermissions, NSFilePosixPermissions,
- nullptr]).leakRef();
- return dictionary;
-}
-
static Lock& qlPreviewConverterDictionaryMutex()
{
static NeverDestroyed<Lock> mutex;
@@ -347,6 +325,25 @@
namespace WebCore {
+static NSDictionary *temporaryFileAttributes()
+{
+ static NSDictionary *attributes = [@{
+ NSFileOwnerAccountName : NSUserName(),
+ NSFilePosixPermissions : [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE)],
+ } retain];
+ return attributes;
+}
+
+static NSDictionary *temporaryDirectoryAttributes()
+{
+ static NSDictionary *attributes = [@{
+ NSFileOwnerAccountName : NSUserName(),
+ NSFilePosixPermissions : [NSNumber numberWithInteger:(WEB_UREAD | WEB_UWRITE | WEB_UEXEC)],
+ NSFileProtectionKey : NSFileProtectionCompleteUnlessOpen,
+ } retain];
+ return attributes;
+}
+
NSString *createTemporaryFileForQuickLook(NSString *fileName)
{
NSString *downloadDirectory = createTemporaryDirectory(@"QuickLookContent");
@@ -353,16 +350,21 @@
if (!downloadDirectory)
return nil;
- NSString *contentPath = [downloadDirectory stringByAppendingPathComponent:fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
- NSString *uniqueContentPath = [fileManager _web_pathWithUniqueFilenameForPath:contentPath];
- BOOL success = [fileManager _web_createFileAtPathWithIntermediateDirectories:uniqueContentPath
- contents:nil
- attributes:QLFileAttributes()
- directoryAttributes:QLDirectoryAttributes()];
+ NSError *error;
+ if (![fileManager setAttributes:temporaryDirectoryAttributes() ofItemAtPath:downloadDirectory error:&error]) {
+ LOG_ERROR("Failed to set attribute NSFileProtectionCompleteUnlessOpen on directory %@ with error: %@.", downloadDirectory, error.localizedDescription);
+ return nil;
+ }
- return success ? uniqueContentPath : nil;
+ NSString *contentPath = [downloadDirectory stringByAppendingPathComponent:fileName.lastPathComponent];
+ if (![fileManager _web_createFileAtPath:contentPath contents:nil attributes:temporaryFileAttributes()]) {
+ LOG_ERROR("Failed to create QuickLook temporary file at path %@.", contentPath);
+ return nil;
+ }
+
+ return contentPath;
}
QuickLookHandle::QuickLookHandle(ResourceLoader& loader, const ResourceResponse& response)
Modified: trunk/Source/WebCore/platform/spi/cocoa/NSFileManagerSPI.h (211235 => 211236)
--- trunk/Source/WebCore/platform/spi/cocoa/NSFileManagerSPI.h 2017-01-26 23:47:53 UTC (rev 211235)
+++ trunk/Source/WebCore/platform/spi/cocoa/NSFileManagerSPI.h 2017-01-26 23:50:28 UTC (rev 211236)
@@ -36,8 +36,7 @@
#define WEB_UEXEC (00100)
@interface NSFileManager ()
-- (BOOL)_web_createFileAtPathWithIntermediateDirectories:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes directoryAttributes:(NSDictionary *)directoryAttributes;
-- (NSString *)_web_pathWithUniqueFilenameForPath:(NSString *)path;
+- (BOOL)_web_createFileAtPath:(NSString *)path contents:(NSData *)contents attributes:(NSDictionary *)attributes;
- (BOOL)_web_removeFileOnlyAtPath:(NSString *)path;
@end
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes