OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef DOMFileSystemBase_h | 31 #ifndef DOMFileSystemBase_h |
32 #define DOMFileSystemBase_h | 32 #define DOMFileSystemBase_h |
33 | 33 |
34 #include "core/platform/AsyncFileSystem.h" | |
35 #include "modules/filesystem/FileSystemFlags.h" | 34 #include "modules/filesystem/FileSystemFlags.h" |
36 #include "modules/filesystem/FileSystemType.h" | 35 #include "modules/filesystem/FileSystemType.h" |
37 #include "weborigin/KURL.h" | 36 #include "weborigin/KURL.h" |
38 #include "wtf/PassRefPtr.h" | 37 #include "wtf/PassRefPtr.h" |
39 #include "wtf/RefCounted.h" | 38 #include "wtf/RefCounted.h" |
40 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
41 | 40 |
| 41 namespace WebKit { |
| 42 class WebFileSystem; |
| 43 } |
| 44 |
42 namespace WebCore { | 45 namespace WebCore { |
43 | 46 |
44 class DirectoryEntry; | 47 class DirectoryEntry; |
45 class DirectoryReaderBase; | 48 class DirectoryReaderBase; |
46 class EntriesCallback; | 49 class EntriesCallback; |
47 class EntryBase; | 50 class EntryBase; |
48 class EntryCallback; | 51 class EntryCallback; |
49 class ErrorCallback; | 52 class ErrorCallback; |
50 class MetadataCallback; | 53 class MetadataCallback; |
51 class ScriptExecutionContext; | 54 class ScriptExecutionContext; |
52 class SecurityOrigin; | 55 class SecurityOrigin; |
53 class VoidCallback; | 56 class VoidCallback; |
54 | 57 |
55 // A common base class for DOMFileSystem and DOMFileSystemSync. | 58 // A common base class for DOMFileSystem and DOMFileSystemSync. |
56 class DOMFileSystemBase : public RefCounted<DOMFileSystemBase> { | 59 class DOMFileSystemBase : public RefCounted<DOMFileSystemBase> { |
57 public: | 60 public: |
58 enum SynchronousType { | 61 enum SynchronousType { |
59 Synchronous, | 62 Synchronous, |
60 Asynchronous, | 63 Asynchronous, |
61 }; | 64 }; |
62 | 65 |
63 // Path prefixes that are used in the filesystem URLs (that can be obtained
by toURL()). | 66 // Path prefixes that are used in the filesystem URLs (that can be obtained
by toURL()). |
64 // http://www.w3.org/TR/file-system-api/#widl-Entry-toURL | 67 // http://www.w3.org/TR/file-system-api/#widl-Entry-toURL |
65 static const char persistentPathPrefix[]; | 68 static const char persistentPathPrefix[]; |
66 static const char temporaryPathPrefix[]; | 69 static const char temporaryPathPrefix[]; |
67 static const char isolatedPathPrefix[]; | 70 static const char isolatedPathPrefix[]; |
68 static const char externalPathPrefix[]; | 71 static const char externalPathPrefix[]; |
69 | 72 |
70 static PassRefPtr<DOMFileSystemBase> create(ScriptExecutionContext* context,
const String& name, FileSystemType type, const KURL& rootURL, PassOwnPtr<AsyncF
ileSystem> asyncFileSystem) | 73 static PassRefPtr<DOMFileSystemBase> create(ScriptExecutionContext* context,
const String& name, FileSystemType type, const KURL& rootURL) |
71 { | 74 { |
72 return adoptRef(new DOMFileSystemBase(context, name, type, rootURL, asyn
cFileSystem)); | 75 return adoptRef(new DOMFileSystemBase(context, name, type, rootURL)); |
73 } | 76 } |
74 virtual ~DOMFileSystemBase(); | 77 virtual ~DOMFileSystemBase(); |
75 | 78 |
| 79 // These are called when a new callback is created and resolved in |
| 80 // FileSystem API, so that subclasses can track the number of pending |
| 81 // callbacks if necessary. |
| 82 virtual void addPendingCallbacks() { } |
| 83 virtual void removePendingCallbacks() { } |
| 84 |
76 const String& name() const { return m_name; } | 85 const String& name() const { return m_name; } |
77 FileSystemType type() const { return m_type; } | 86 FileSystemType type() const { return m_type; } |
78 KURL rootURL() const { return m_filesystemRootURL; } | 87 KURL rootURL() const { return m_filesystemRootURL; } |
79 AsyncFileSystem* asyncFileSystem() const { return m_asyncFileSystem.get(); } | 88 WebKit::WebFileSystem* fileSystem() const; |
80 SecurityOrigin* securityOrigin() const; | 89 SecurityOrigin* securityOrigin() const; |
81 | 90 |
82 // The clonable flag is used in the structured clone algorithm to test | 91 // The clonable flag is used in the structured clone algorithm to test |
83 // whether the FileSystem API object is permitted to be cloned. It defaults | 92 // whether the FileSystem API object is permitted to be cloned. It defaults |
84 // to false, and must be explicitly set by internal code permit cloning. | 93 // to false, and must be explicitly set by internal code permit cloning. |
85 void makeClonable() { m_clonable = true; } | 94 void makeClonable() { m_clonable = true; } |
86 bool clonable() const { return m_clonable; } | 95 bool clonable() const { return m_clonable; } |
87 | 96 |
88 static bool isValidType(FileSystemType); | 97 static bool isValidType(FileSystemType); |
89 static bool crackFileSystemURL(const KURL&, FileSystemType&, String& filePat
h); | 98 static bool crackFileSystemURL(const KURL&, FileSystemType&, String& filePat
h); |
90 bool supportsToURL() const; | 99 bool supportsToURL() const; |
91 KURL createFileSystemURL(const EntryBase*) const; | 100 KURL createFileSystemURL(const EntryBase*) const; |
92 KURL createFileSystemURL(const String& fullPath) const; | 101 KURL createFileSystemURL(const String& fullPath) const; |
93 | 102 |
94 // Actual FileSystem API implementations. All the validity checks on virtual
paths are done at this level. | 103 // Actual FileSystem API implementations. All the validity checks on virtual
paths are done at this level. |
95 // They return false for immediate errors that don't involve lower AsyncFile
System layer (e.g. for name validation errors). Otherwise they return true (but
later may call back with an runtime error). | 104 // They return false for immediate errors that don't involve lower WebFileSy
stem layer (e.g. for name validation errors). Otherwise they return true (but la
ter may call back with an runtime error). |
96 bool getMetadata(const EntryBase*, PassRefPtr<MetadataCallback>, PassRefPtr<
ErrorCallback>, SynchronousType = Asynchronous); | 105 bool getMetadata(const EntryBase*, PassRefPtr<MetadataCallback>, PassRefPtr<
ErrorCallback>, SynchronousType = Asynchronous); |
97 bool move(const EntryBase* source, EntryBase* parent, const String& name, Pa
ssRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchrono
us); | 106 bool move(const EntryBase* source, EntryBase* parent, const String& name, Pa
ssRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchrono
us); |
98 bool copy(const EntryBase* source, EntryBase* parent, const String& name, Pa
ssRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchrono
us); | 107 bool copy(const EntryBase* source, EntryBase* parent, const String& name, Pa
ssRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchrono
us); |
99 bool remove(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCall
back>, SynchronousType = Asynchronous); | 108 bool remove(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCall
back>, SynchronousType = Asynchronous); |
100 bool removeRecursively(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPt
r<ErrorCallback>, SynchronousType = Asynchronous); | 109 bool removeRecursively(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPt
r<ErrorCallback>, SynchronousType = Asynchronous); |
101 bool getParent(const EntryBase*, PassRefPtr<EntryCallback>, PassRefPtr<Error
Callback>); | 110 bool getParent(const EntryBase*, PassRefPtr<EntryCallback>, PassRefPtr<Error
Callback>); |
102 bool getFile(const EntryBase*, const String& path, const FileSystemFlags&, P
assRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchron
ous); | 111 bool getFile(const EntryBase*, const String& path, const FileSystemFlags&, P
assRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchron
ous); |
103 bool getDirectory(const EntryBase*, const String& path, const FileSystemFlag
s&, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asyn
chronous); | 112 bool getDirectory(const EntryBase*, const String& path, const FileSystemFlag
s&, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asyn
chronous); |
104 bool readDirectory(PassRefPtr<DirectoryReaderBase>, const String& path, Pass
RefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchrono
us); | 113 bool readDirectory(PassRefPtr<DirectoryReaderBase>, const String& path, Pass
RefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, SynchronousType = Asynchrono
us); |
105 | 114 |
106 protected: | 115 protected: |
107 DOMFileSystemBase(ScriptExecutionContext*, const String& name, FileSystemTyp
e, const KURL& rootURL, PassOwnPtr<AsyncFileSystem>); | 116 DOMFileSystemBase(ScriptExecutionContext*, const String& name, FileSystemTyp
e, const KURL& rootURL); |
108 friend class DOMFileSystemSync; | 117 friend class DOMFileSystemSync; |
109 | 118 |
110 ScriptExecutionContext* m_context; | 119 ScriptExecutionContext* m_context; |
111 String m_name; | 120 String m_name; |
112 FileSystemType m_type; | 121 FileSystemType m_type; |
113 KURL m_filesystemRootURL; | 122 KURL m_filesystemRootURL; |
114 bool m_clonable; | 123 bool m_clonable; |
115 | |
116 mutable OwnPtr<AsyncFileSystem> m_asyncFileSystem; | |
117 }; | 124 }; |
118 | 125 |
119 inline bool operator==(const DOMFileSystemBase& a, const DOMFileSystemBase& b) {
return a.name() == b.name() && a.type() == b.type() && a.rootURL() == b.rootURL
(); } | 126 inline bool operator==(const DOMFileSystemBase& a, const DOMFileSystemBase& b) {
return a.name() == b.name() && a.type() == b.type() && a.rootURL() == b.rootURL
(); } |
120 | 127 |
121 } // namespace WebCore | 128 } // namespace WebCore |
122 | 129 |
123 #endif // DOMFileSystemBase_h | 130 #endif // DOMFileSystemBase_h |
OLD | NEW |