• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1.  Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  * 2.  Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15  *     its contributors may be used to endorse or promote products derived
16  *     from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef FileSystem_h
31 #define FileSystem_h
32 
33 #if PLATFORM(GTK)
34 #include <gmodule.h>
35 #endif
36 #if PLATFORM(QT)
37 #include <QFile>
38 #include <QLibrary>
39 #if defined(Q_OS_WIN32)
40 #include <windows.h>
41 #endif
42 #if defined(Q_WS_MAC)
43 #include <CoreFoundation/CFBundle.h>
44 #endif
45 #endif
46 
47 #include <time.h>
48 
49 #include <wtf/Platform.h>
50 #include <wtf/Vector.h>
51 
52 #include "PlatformString.h"
53 
54 typedef const struct __CFData* CFDataRef;
55 
56 #if PLATFORM(WIN_OS)
57 // These are to avoid including <winbase.h> in a header for Chromium
58 typedef void *HANDLE;
59 // Assuming STRICT
60 typedef struct HINSTANCE__* HINSTANCE;
61 typedef HINSTANCE HMODULE;
62 #endif
63 
64 namespace WebCore {
65 
66 class CString;
67 
68 #if PLATFORM(QT)
69 
70 typedef QFile* PlatformFileHandle;
71 const PlatformFileHandle invalidPlatformFileHandle = 0;
72 #if defined(Q_WS_MAC)
73 typedef CFBundleRef PlatformModule;
74 typedef unsigned PlatformModuleVersion;
75 #elif defined(Q_OS_WIN)
76 typedef HMODULE PlatformModule;
77 struct PlatformModuleVersion {
78     unsigned leastSig;
79     unsigned mostSig;
80 
PlatformModuleVersionPlatformModuleVersion81     PlatformModuleVersion(unsigned)
82         : leastSig(0)
83         , mostSig(0)
84     {
85     }
86 
PlatformModuleVersionPlatformModuleVersion87     PlatformModuleVersion(unsigned lsb, unsigned msb)
88         : leastSig(lsb)
89         , mostSig(msb)
90     {
91     }
92 
93 };
94 #else
95 typedef QLibrary* PlatformModule;
96 typedef unsigned PlatformModuleVersion;
97 #endif
98 
99 #elif PLATFORM(WIN_OS)
100 typedef HANDLE PlatformFileHandle;
101 typedef HMODULE PlatformModule;
102 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
103 // avoid using Windows headers in headers.  We'd rather move this into the .cpp.
104 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
105 
106 struct PlatformModuleVersion {
107     unsigned leastSig;
108     unsigned mostSig;
109 
PlatformModuleVersionPlatformModuleVersion110     PlatformModuleVersion(unsigned)
111         : leastSig(0)
112         , mostSig(0)
113     {
114     }
115 
PlatformModuleVersionPlatformModuleVersion116     PlatformModuleVersion(unsigned lsb, unsigned msb)
117         : leastSig(lsb)
118         , mostSig(msb)
119     {
120     }
121 
122 };
123 #else
124 typedef int PlatformFileHandle;
125 #if PLATFORM(GTK)
126 typedef GModule* PlatformModule;
127 #else
128 typedef void* PlatformModule;
129 #endif
130 const PlatformFileHandle invalidPlatformFileHandle = -1;
131 
132 typedef unsigned PlatformModuleVersion;
133 #endif
134 
135 bool fileExists(const String&);
136 bool deleteFile(const String&);
137 bool deleteEmptyDirectory(const String&);
138 bool getFileSize(const String&, long long& result);
139 bool getFileModificationTime(const String&, time_t& result);
140 String pathByAppendingComponent(const String& path, const String& component);
141 bool makeAllDirectories(const String& path);
142 String homeDirectoryPath();
143 String pathGetFileName(const String&);
144 String directoryName(const String&);
145 
146 Vector<String> listDirectory(const String& path, const String& filter = String());
147 
148 CString fileSystemRepresentation(const String&);
149 
isHandleValid(const PlatformFileHandle & handle)150 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
151 
152 // Prefix is what the filename should be prefixed with, not the full path.
153 CString openTemporaryFile(const char* prefix, PlatformFileHandle&);
154 void closeFile(PlatformFileHandle&);
155 int writeToFile(PlatformFileHandle, const char* data, int length);
156 
157 // Methods for dealing with loadable modules
158 bool unloadModule(PlatformModule);
159 
160 #if PLATFORM(WIN)
161 String localUserSpecificStorageDirectory();
162 String roamingUserSpecificStorageDirectory();
163 
164 bool safeCreateFile(const String&, CFDataRef);
165 #endif
166 
167 #if PLATFORM(GTK)
168 String filenameToString(const char*);
169 char* filenameFromString(const String&);
170 String filenameForDisplay(const String&);
171 #endif
172 
173 } // namespace WebCore
174 
175 #endif // FileSystem_h
176