1/* 2 * Copyright (C) 2007, 2011 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#import "config.h" 30#import "FileSystem.h" 31 32#import "WebCoreNSURLExtras.h" 33#import "WebCoreSystemInterface.h" 34#import <wtf/RetainPtr.h> 35#import <wtf/text/CString.h> 36#import <wtf/text/WTFString.h> 37 38namespace WebCore { 39 40String homeDirectoryPath() 41{ 42 return NSHomeDirectory(); 43} 44 45String openTemporaryFile(const String& prefix, PlatformFileHandle& platformFileHandle) 46{ 47 platformFileHandle = invalidPlatformFileHandle; 48 49 Vector<char> temporaryFilePath(PATH_MAX); 50 if (!confstr(_CS_DARWIN_USER_TEMP_DIR, temporaryFilePath.data(), temporaryFilePath.size())) 51 return String(); 52 53 // Shrink the vector. 54 temporaryFilePath.shrink(strlen(temporaryFilePath.data())); 55 ASSERT(temporaryFilePath.last() == '/'); 56 57 // Append the file name. 58 CString prefixUtf8 = prefix.utf8(); 59 temporaryFilePath.append(prefixUtf8.data(), prefixUtf8.length()); 60 temporaryFilePath.append("XXXXXX", 6); 61 temporaryFilePath.append('\0'); 62 63 platformFileHandle = mkstemp(temporaryFilePath.data()); 64 if (platformFileHandle == invalidPlatformFileHandle) 65 return String(); 66 67 return String::fromUTF8(temporaryFilePath.data()); 68} 69 70#if !PLATFORM(IOS) 71 72void setMetadataURL(String& URLString, const String& referrer, const String& path) 73{ 74 NSURL *URL = URLWithUserTypedString(URLString, nil); 75 if (URL) 76 URLString = userVisibleString(URLByRemovingUserInfo(URL)); 77 78 // Call WKSetMetadataURL on a background queue because it can take some time. 79 NSString *URLStringCopy = URLString; 80 NSString *referrerCopy = referrer; 81 NSString *pathCopy = path; 82 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 83 wkSetMetadataURL(URLStringCopy, referrerCopy, [NSString stringWithUTF8String:[pathCopy fileSystemRepresentation]]); 84 }); 85} 86 87bool canExcludeFromBackup() 88{ 89 return true; 90} 91 92bool excludeFromBackup(const String& path) 93{ 94 // It is critical to pass FALSE for excludeByPath because excluding by path requires root privileges. 95 CSBackupSetItemExcluded(pathAsURL(path).get(), TRUE, FALSE); 96 return true; 97} 98 99#endif 100 101} // namespace WebCore 102