1 /* 2 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 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 13 * distribution. 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. 17 * 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. 29 */ 30 31 #ifndef DOMFileSystemBase_h 32 #define DOMFileSystemBase_h 33 34 #include "modules/filesystem/FileSystemFlags.h" 35 #include "platform/FileSystemType.h" 36 #include "platform/weborigin/KURL.h" 37 #include "wtf/PassRefPtr.h" 38 #include "wtf/RefCounted.h" 39 #include "wtf/text/WTFString.h" 40 41 namespace blink { 42 class WebFileSystem; 43 } 44 45 namespace WebCore { 46 47 class DirectoryEntry; 48 class DirectoryReaderBase; 49 class EntriesCallback; 50 class EntryBase; 51 class EntryCallback; 52 class ErrorCallback; 53 class FileError; 54 class MetadataCallback; 55 class ExecutionContext; 56 class SecurityOrigin; 57 class VoidCallback; 58 59 // A common base class for DOMFileSystem and DOMFileSystemSync. 60 class DOMFileSystemBase : public RefCounted<DOMFileSystemBase> { 61 public: 62 enum SynchronousType { 63 Synchronous, 64 Asynchronous, 65 }; 66 67 // Path prefixes that are used in the filesystem URLs (that can be obtained by toURL()). 68 // http://www.w3.org/TR/file-system-api/#widl-Entry-toURL 69 static const char persistentPathPrefix[]; 70 static const char temporaryPathPrefix[]; 71 static const char isolatedPathPrefix[]; 72 static const char externalPathPrefix[]; 73 74 virtual ~DOMFileSystemBase(); 75 76 // These are called when a new callback is created and resolved in 77 // FileSystem API, so that subclasses can track the number of pending 78 // callbacks if necessary. 79 virtual void addPendingCallbacks() { } 80 virtual void removePendingCallbacks() { } 81 82 // Overridden by subclasses to handle sync vs async error-handling. 83 virtual void reportError(PassOwnPtr<ErrorCallback>, PassRefPtr<FileError>) = 0; 84 85 const String& name() const { return m_name; } 86 FileSystemType type() const { return m_type; } 87 KURL rootURL() const { return m_filesystemRootURL; } 88 blink::WebFileSystem* fileSystem() const; 89 SecurityOrigin* securityOrigin() const; 90 91 // The clonable flag is used in the structured clone algorithm to test 92 // whether the FileSystem API object is permitted to be cloned. It defaults 93 // to false, and must be explicitly set by internal code permit cloning. 94 void makeClonable() { m_clonable = true; } 95 bool clonable() const { return m_clonable; } 96 97 static bool isValidType(FileSystemType); 98 static bool crackFileSystemURL(const KURL&, FileSystemType&, String& filePath); 99 static KURL createFileSystemRootURL(const String& origin, FileSystemType); 100 bool supportsToURL() const; 101 KURL createFileSystemURL(const EntryBase*) const; 102 KURL createFileSystemURL(const String& fullPath) const; 103 static bool pathToAbsolutePath(FileSystemType, const EntryBase*, String path, String& absolutePath); 104 static bool pathPrefixToFileSystemType(const String& pathPrefix, FileSystemType&); 105 106 // Actual FileSystem API implementations. All the validity checks on virtual paths are done at this level. 107 void getMetadata(const EntryBase*, PassOwnPtr<MetadataCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 108 void move(const EntryBase* source, EntryBase* parent, const String& name, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 109 void copy(const EntryBase* source, EntryBase* parent, const String& name, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 110 void remove(const EntryBase*, PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 111 void removeRecursively(const EntryBase*, PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 112 void getParent(const EntryBase*, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>); 113 void getFile(const EntryBase*, const String& path, const FileSystemFlags&, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 114 void getDirectory(const EntryBase*, const String& path, const FileSystemFlags&, PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 115 bool readDirectory(PassRefPtr<DirectoryReaderBase>, const String& path, PassOwnPtr<EntriesCallback>, PassOwnPtr<ErrorCallback>, SynchronousType = Asynchronous); 116 117 protected: 118 DOMFileSystemBase(ExecutionContext*, const String& name, FileSystemType, const KURL& rootURL); 119 friend class DOMFileSystemSync; 120 121 ExecutionContext* m_context; 122 String m_name; 123 FileSystemType m_type; 124 KURL m_filesystemRootURL; 125 bool m_clonable; 126 }; 127 128 inline bool operator==(const DOMFileSystemBase& a, const DOMFileSystemBase& b) { return a.name() == b.name() && a.type() == b.type() && a.rootURL() == b.rootURL(); } 129 130 } // namespace WebCore 131 132 #endif // DOMFileSystemBase_h 133