OSDN Git Service

am 68b5dbab: (-s ours) am 7d1dae3f: am 58348114: Merge "DO NOT MERGE cursor ring...
[android-x86/external-webkit.git] / Source / WebCore / platform / FileSystem.h
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(QT)
34 #include <QFile>
35 #include <QLibrary>
36 #if defined(Q_OS_WIN32)
37 #include <windows.h>
38 #endif
39 #endif
40
41 #if PLATFORM(CF) || (PLATFORM(QT) && defined(Q_WS_MAC))
42 #include <CoreFoundation/CFBundle.h>
43 #endif
44
45 #include "PlatformString.h"
46 #include <time.h>
47 #include <wtf/Forward.h>
48 #include <wtf/Vector.h>
49
50 typedef const struct __CFData* CFDataRef;
51
52 #if OS(WINDOWS)
53 // These are to avoid including <winbase.h> in a header for Chromium
54 typedef void *HANDLE;
55 // Assuming STRICT
56 typedef struct HINSTANCE__* HINSTANCE;
57 typedef HINSTANCE HMODULE;
58 #endif
59
60 #if PLATFORM(BREWMP)
61 typedef struct _IFile IFile;
62 #endif
63
64 #if PLATFORM(GTK)
65 typedef struct _GFileIOStream GFileIOStream;
66 typedef struct _GModule GModule;
67 #endif
68
69 namespace WebCore {
70
71 // PlatformModule
72 #if OS(WINDOWS)
73 typedef HMODULE PlatformModule;
74 #elif PLATFORM(QT)
75 #if defined(Q_WS_MAC)
76 typedef CFBundleRef PlatformModule;
77 #elif !defined(QT_NO_LIBRARY)
78 typedef QLibrary* PlatformModule;
79 #else
80 typedef void* PlatformModule;
81 #endif
82 #elif PLATFORM(GTK)
83 typedef GModule* PlatformModule;
84 #elif PLATFORM(CF)
85 typedef CFBundleRef PlatformModule;
86 #else
87 typedef void* PlatformModule;
88 #endif
89
90 // PlatformModuleVersion
91 #if OS(WINDOWS)
92 struct PlatformModuleVersion {
93     unsigned leastSig;
94     unsigned mostSig;
95
96     PlatformModuleVersion(unsigned)
97         : leastSig(0)
98         , mostSig(0)
99     {
100     }
101
102     PlatformModuleVersion(unsigned lsb, unsigned msb)
103         : leastSig(lsb)
104         , mostSig(msb)
105     {
106     }
107
108 };
109 #else
110 typedef unsigned PlatformModuleVersion;
111 #endif
112
113 // PlatformFileHandle
114 #if PLATFORM(QT)
115 typedef QFile* PlatformFileHandle;
116 const PlatformFileHandle invalidPlatformFileHandle = 0;
117 #elif OS(WINDOWS)
118 typedef HANDLE PlatformFileHandle;
119 // FIXME: -1 is INVALID_HANDLE_VALUE, defined in <winbase.h>. Chromium tries to
120 // avoid using Windows headers in headers.  We'd rather move this into the .cpp.
121 const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
122 #elif PLATFORM(BREWMP)
123 typedef IFile* PlatformFileHandle;
124 const PlatformFileHandle invalidPlatformFileHandle = 0;
125 typedef void* PlatformModule;
126 typedef unsigned PlatformModuleVersion;
127 #elif PLATFORM(GTK)
128 typedef GFileIOStream* PlatformFileHandle;
129 const PlatformFileHandle invalidPlatformFileHandle = 0;
130 #else
131 typedef int PlatformFileHandle;
132 const PlatformFileHandle invalidPlatformFileHandle = -1;
133 #endif
134
135 enum FileOpenMode {
136     OpenForRead = 0,
137     OpenForWrite
138 };
139
140 enum FileSeekOrigin {
141     SeekFromBeginning = 0,
142     SeekFromCurrent,
143     SeekFromEnd
144 };
145
146 #if OS(WINDOWS)
147 static const char PlatformFilePathSeparator = '\\';
148 #else
149 static const char PlatformFilePathSeparator = '/';
150 #endif
151
152 void revealFolderInOS(const String&);
153 bool fileExists(const String&);
154 bool deleteFile(const String&);
155 bool deleteEmptyDirectory(const String&);
156 bool getFileSize(const String&, long long& result);
157 bool getFileModificationTime(const String&, time_t& result);
158 String pathByAppendingComponent(const String& path, const String& component);
159 bool makeAllDirectories(const String& path);
160 String homeDirectoryPath();
161 String pathGetFileName(const String&);
162 String directoryName(const String&);
163
164 Vector<String> listDirectory(const String& path, const String& filter = String());
165
166 CString fileSystemRepresentation(const String&);
167
168 inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
169
170 // Prefix is what the filename should be prefixed with, not the full path.
171 CString openTemporaryFile(const char* prefix, PlatformFileHandle&);
172 PlatformFileHandle openFile(const String& path, FileOpenMode);
173 void closeFile(PlatformFileHandle&);
174 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise.
175 long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
176 bool truncateFile(PlatformFileHandle, long long offset);
177 // Returns number of bytes actually read if successful, -1 otherwise.
178 int writeToFile(PlatformFileHandle, const char* data, int length);
179 // Returns number of bytes actually written if successful, -1 otherwise.
180 int readFromFile(PlatformFileHandle, char* data, int length);
181
182 // Methods for dealing with loadable modules
183 bool unloadModule(PlatformModule);
184
185 // Encode a string for use within a file name.
186 String encodeForFileName(const String&);
187
188 #if PLATFORM(WIN)
189 String localUserSpecificStorageDirectory();
190 String roamingUserSpecificStorageDirectory();
191
192 bool safeCreateFile(const String&, CFDataRef);
193 #endif
194
195 #if PLATFORM(GTK)
196 String filenameToString(const char*);
197 String filenameForDisplay(const String&);
198 #endif
199
200 #if PLATFORM(CHROMIUM)
201 String pathGetDisplayFileName(const String&);
202 #endif
203
204 } // namespace WebCore
205
206 #endif // FileSystem_h