OSDN Git Service

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