2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 #ifndef DOMFileSystemBase_h
32 #define DOMFileSystemBase_h
34 #include "modules/filesystem/FileSystemFlags.h"
35 #include "platform/FileSystemType.h"
36 #include "platform/heap/Handle.h"
37 #include "platform/weborigin/KURL.h"
38 #include "wtf/text/WTFString.h"
47 class DirectoryReaderBase;
48 class EntriesCallback;
53 class MetadataCallback;
54 class ExecutionContext;
58 // A common base class for DOMFileSystem and DOMFileSystemSync.
59 class DOMFileSystemBase : public GarbageCollectedFinalized<DOMFileSystemBase> {
61 enum SynchronousType {
66 // Path prefixes that are used in the filesystem URLs (that can be obtained by toURL()).
67 // http://www.w3.org/TR/file-system-api/#widl-Entry-toURL
68 static const char persistentPathPrefix[];
69 static const char temporaryPathPrefix[];
70 static const char isolatedPathPrefix[];
71 static const char externalPathPrefix[];
73 virtual ~DOMFileSystemBase();
75 // These are called when a new callback is created and resolved in
76 // FileSystem API, so that subclasses can track the number of pending
77 // callbacks if necessary.
78 virtual void addPendingCallbacks() { }
79 virtual void removePendingCallbacks() { }
81 // Overridden by subclasses to handle sync vs async error-handling.
82 virtual void reportError(PassOwnPtr<ErrorCallback>, PassRefPtrWillBeRawPtr<FileError>) = 0;
84 const String& name() const { return m_name; }
85 FileSystemType type() const { return m_type; }
86 KURL rootURL() const { return m_filesystemRootURL; }
87 blink::WebFileSystem* fileSystem() const;
88 SecurityOrigin* securityOrigin() const;
90 // The clonable flag is used in the structured clone algorithm to test
91 // whether the FileSystem API object is permitted to be cloned. It defaults
92 // to false, and must be explicitly set by internal code permit cloning.
93 void makeClonable() { m_clonable = true; }
94 bool clonable() const { return m_clonable; }
96 static bool isValidType(FileSystemType);
97 static bool crackFileSystemURL(const KURL&, FileSystemType&, String& filePath);
98 static KURL createFileSystemRootURL(const String& origin, FileSystemType);
99 bool supportsToURL() const;
100 KURL createFileSystemURL(const EntryBase*) const;
101 KURL createFileSystemURL(const String& fullPath) const;
102 static bool pathToAbsolutePath(FileSystemType, const EntryBase*, String path, String& absolutePath);
103 static bool pathPrefixToFileSystemType(const String& pathPrefix, FileSystemType&);
105 // Actual FileSystem API implementations. All the validity checks on virtual paths are done at this level.
106 void getMetadata(const EntryBase*, PassOwnPtr<MetadataCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
107 void move(const EntryBase* source, EntryBase* parent, const String& name, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
108 void copy(const EntryBase* source, EntryBase* parent, const String& name, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
109 void remove(const EntryBase*, PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
110 void removeRecursively(const EntryBase*, PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
111 void getParent(const EntryBase*, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>);
112 void getFile(const EntryBase*, const String& path, const FileSystemFlags&, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
113 void getDirectory(const EntryBase*, const String& path, const FileSystemFlags&, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
114 int readDirectory(DirectoryReaderBase*, const String& path, PassOwnPtr<EntriesCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous);
115 bool waitForAdditionalResult(int callbacksId);
117 virtual void trace(Visitor*) { }
120 DOMFileSystemBase(ExecutionContext*, const String& name, FileSystemType, const KURL& rootURL);
121 friend class DOMFileSystemSync;
123 ExecutionContext* m_context;
125 FileSystemType m_type;
126 KURL m_filesystemRootURL;
130 inline bool operator==(const DOMFileSystemBase& a, const DOMFileSystemBase& b) { return a.name() == b.name() && a.type() == b.type() && a.rootURL() == b.rootURL(); }
134 #endif // DOMFileSystemBase_h