Title: [102517] trunk/Source/WebCore
Revision
102517
Author
[email protected]
Date
2011-12-09 21:34:02 -0800 (Fri, 09 Dec 2011)

Log Message

Add the FileSystem functions of iOS
https://bugs.webkit.org/show_bug.cgi?id=74164

Patch by Benjamin Poulain <[email protected]> on 2011-12-09
Reviewed by David Kilzer.

Two functions are needed on iOS for temporary files and directories.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* platform/ios/FileSystemIOS.h: Added.
* platform/ios/FileSystemIOS.mm: Added.
(WebCore::createTemporaryDirectory):
(WebCore::createTemporaryFile):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (102516 => 102517)


--- trunk/Source/WebCore/ChangeLog	2011-12-10 05:18:40 UTC (rev 102516)
+++ trunk/Source/WebCore/ChangeLog	2011-12-10 05:34:02 UTC (rev 102517)
@@ -1,3 +1,19 @@
+2011-12-09  Benjamin Poulain  <[email protected]>
+
+        Add the FileSystem functions of iOS
+        https://bugs.webkit.org/show_bug.cgi?id=74164
+
+        Reviewed by David Kilzer.
+
+        Two functions are needed on iOS for temporary files and directories.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/ios/FileSystemIOS.h: Added.
+        * platform/ios/FileSystemIOS.mm: Added.
+        (WebCore::createTemporaryDirectory):
+        (WebCore::createTemporaryFile):
+
 2011-12-09  Jacky Jiang  <[email protected]>
 
         Remove ResourceHandle::bufferedData() from ResourceHandleBlackBerry.cpp

Modified: trunk/Source/WebCore/WebCore.exp.in (102516 => 102517)


--- trunk/Source/WebCore/WebCore.exp.in	2011-12-10 05:18:40 UTC (rev 102516)
+++ trunk/Source/WebCore/WebCore.exp.in	2011-12-10 05:34:02 UTC (rev 102517)
@@ -1560,6 +1560,10 @@
 _wkGetMacOSXVersionString
 #endif
 
+#if PLATFORM(IOS)
+__ZN7WebCore24createTemporaryDirectoryEP8NSString
+#endif
+
 _wkUnregisterUniqueIdForElement
 _wkAccessibilityHandleFocusChanged
 _wkGetAXTextMarkerTypeID

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (102516 => 102517)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-12-10 05:18:40 UTC (rev 102516)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-12-10 05:34:02 UTC (rev 102517)
@@ -680,6 +680,8 @@
 		265541391489811C000DFC5D /* KeyEventCodesIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 265541371489811C000DFC5D /* KeyEventCodesIOS.h */; };
 		2655413A1489811C000DFC5D /* KeyEventIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 265541381489811C000DFC5D /* KeyEventIOS.mm */; };
 		265541521489B233000DFC5D /* CursorIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2655414B1489AA2B000DFC5D /* CursorIOS.cpp */; };
+		26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 26C17A3C1491D2D400D12BA2 /* FileSystemIOS.h */; };
+		26C17A3F1491D2D400D12BA2 /* FileSystemIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26C17A3D1491D2D400D12BA2 /* FileSystemIOS.mm */; };
 		26E98A10130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 26E98A0F130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h */; };
 		26F40D4A14904A6300CA67C4 /* EventLoopIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 26F40D4914904A6300CA67C4 /* EventLoopIOS.mm */; };
 		2917B5611473496C0052C9D0 /* LayerFlushScheduler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2917B55E1473496C0052C9D0 /* LayerFlushScheduler.cpp */; };
@@ -7791,6 +7793,8 @@
 		265541371489811C000DFC5D /* KeyEventCodesIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KeyEventCodesIOS.h; path = ios/KeyEventCodesIOS.h; sourceTree = "<group>"; };
 		265541381489811C000DFC5D /* KeyEventIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = KeyEventIOS.mm; path = ios/KeyEventIOS.mm; sourceTree = "<group>"; };
 		2655414B1489AA2B000DFC5D /* CursorIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CursorIOS.cpp; path = ios/CursorIOS.cpp; sourceTree = "<group>"; };
+		26C17A3C1491D2D400D12BA2 /* FileSystemIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileSystemIOS.h; path = ios/FileSystemIOS.h; sourceTree = "<group>"; };
+		26C17A3D1491D2D400D12BA2 /* FileSystemIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FileSystemIOS.mm; path = ios/FileSystemIOS.mm; sourceTree = "<group>"; };
 		26E98A0F130A9FCA008EB7B2 /* TextCodecASCIIFastPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCodecASCIIFastPath.h; sourceTree = "<group>"; };
 		26F40D4914904A6300CA67C4 /* EventLoopIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = EventLoopIOS.mm; path = ios/EventLoopIOS.mm; sourceTree = "<group>"; };
 		2917B55E1473496C0052C9D0 /* LayerFlushScheduler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LayerFlushScheduler.cpp; path = ca/LayerFlushScheduler.cpp; sourceTree = "<group>"; };
@@ -17633,6 +17637,8 @@
 			isa = PBXGroup;
 			children = (
 				26F40D4914904A6300CA67C4 /* EventLoopIOS.mm */,
+				26C17A3C1491D2D400D12BA2 /* FileSystemIOS.h */,
+				26C17A3D1491D2D400D12BA2 /* FileSystemIOS.mm */,
 				2655414B1489AA2B000DFC5D /* CursorIOS.cpp */,
 				265541371489811C000DFC5D /* KeyEventCodesIOS.h */,
 				265541381489811C000DFC5D /* KeyEventIOS.mm */,
@@ -24789,6 +24795,7 @@
 				265541391489811C000DFC5D /* KeyEventCodesIOS.h in Headers */,
 				8A195932147EA16E00D1EA61 /* DOMWebKitNamedFlow.h in Headers */,
 				8A195934147EA16E00D1EA61 /* DOMWebKitNamedFlowInternal.h in Headers */,
+				26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -27671,6 +27678,7 @@
 				D7613A501474F13F00DB8606 /* WebKitNamedFlow.cpp in Sources */,
 				D7613AC414753E5600DB8606 /* JSWebKitNamedFlow.cpp in Sources */,
 				8A195933147EA16E00D1EA61 /* DOMWebKitNamedFlow.mm in Sources */,
+				26C17A3F1491D2D400D12BA2 /* FileSystemIOS.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Source/WebCore/platform/ios/FileSystemIOS.h (0 => 102517)


--- trunk/Source/WebCore/platform/ios/FileSystemIOS.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/FileSystemIOS.h	2011-12-10 05:34:02 UTC (rev 102517)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FileSystemIOS_h
+#define FileSystemIOS_h
+
+@class NSString;
+
+namespace WebCore {
+
+NSString *createTemporaryDirectory(NSString *directoryPrefix);
+NSString *createTemporaryFile(NSString *directoryPath, NSString *filePrefix);
+
+} // namespace WebCore
+
+#endif // FileSystemIOS_h

Added: trunk/Source/WebCore/platform/ios/FileSystemIOS.mm (0 => 102517)


--- trunk/Source/WebCore/platform/ios/FileSystemIOS.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/FileSystemIOS.mm	2011-12-10 05:34:02 UTC (rev 102517)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "FileSystemIOS.h"
+
+#import "FileSystem.h"
+
+namespace WebCore {
+
+NSString *createTemporaryDirectory(NSString *directoryPrefix)
+{
+    NSString *tempDirectory = NSTemporaryDirectory();
+    if (!tempDirectory || ![tempDirectory length])
+        return nil;
+
+    if (!directoryPrefix || ![directoryPrefix length])
+        return nil;
+
+    NSString *tempDirectoryComponent = [directoryPrefix stringByAppendingString:@"-XXXXXXXX"];
+    const char* tempDirectoryCString = [[tempDirectory stringByAppendingPathComponent:tempDirectoryComponent] fileSystemRepresentation];
+    if (!tempDirectoryCString)
+        return nil;
+
+    const size_t length = strlen(tempDirectoryCString);
+    ASSERT(length <= MAXPATHLEN);
+    if (length > MAXPATHLEN)
+        return nil;
+
+    const size_t lengthPlusNullTerminator = length + 1;
+    Vector<char, MAXPATHLEN + 1> path(lengthPlusNullTerminator);
+    memcpy(path.data(), tempDirectoryCString, lengthPlusNullTerminator);
+
+    if (!mkdtemp(path.data()))
+        return nil;
+
+    return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path.data() length:length];
+}
+
+NSString *createTemporaryFile(NSString *directoryPath, NSString *filePrefix)
+{
+    if (!directoryPath || ![directoryPath length] || !filePrefix || ![filePrefix length])
+        return nil;
+
+    NSString *tempFileComponent = [filePrefix stringByAppendingString:@"-XXXXXXXX"];
+    const char* templatePathCString = [[directoryPath stringByAppendingPathComponent:tempFileComponent] fileSystemRepresentation];
+    if (!templatePathCString)
+        return nil;
+
+    const size_t length = strlen(templatePathCString);
+    ASSERT(length <= MAXPATHLEN);
+    if (length > MAXPATHLEN)
+        return nil;
+
+    const size_t lengthPlusNullTerminator = length + 1;
+    Vector<char, MAXPATHLEN + 1> path(lengthPlusNullTerminator);
+    memcpy(path.data(), templatePathCString, lengthPlusNullTerminator);
+
+    int fd = mkstemp(path.data());
+    if (fd < 0)
+        return nil;
+
+    int err = fchmod(fd, S_IRUSR | S_IWUSR);
+    if (err < 0) {
+        close(fd);
+        unlink(path.data());
+        return nil;
+    }
+
+    close(fd);
+    return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path.data() length:length];
+}
+
+} // namespace WebCore
+
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to