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 #if ENABLE(FILE_SYSTEM) 35 36 #include "AsyncFileSystem.h" 37 #include "WebKitFlags.h" 38 #include "PlatformString.h" 39 #include <wtf/PassRefPtr.h> 40 #include <wtf/RefCounted.h> 41 42 namespace WebCore { 43 44 class DirectoryEntry; 45 class DirectoryReaderBase; 46 class EntriesCallback; 47 class EntryBase; 48 class EntryCallback; 49 class ErrorCallback; 50 class KURL; 51 class MetadataCallback; 52 class ScriptExecutionContext; 53 class SecurityOrigin; 54 class VoidCallback; 55 56 // A common base class for DOMFileSystem and DOMFileSystemSync. 57 class DOMFileSystemBase : public RefCounted<DOMFileSystemBase> { 58 public: create(ScriptExecutionContext * context,const String & name,PassOwnPtr<AsyncFileSystem> asyncFileSystem)59 static PassRefPtr<DOMFileSystemBase> create(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem) 60 { 61 return adoptRef(new DOMFileSystemBase(context, name, asyncFileSystem)); 62 } 63 virtual ~DOMFileSystemBase(); 64 65 static const char kPersistentPathPrefix[]; 66 static const size_t kPersistentPathPrefixLength; 67 static const char kTemporaryPathPrefix[]; 68 static const size_t kTemporaryPathPrefixLength; 69 static const char kExternalPathPrefix[]; 70 static const size_t kExternalPathPrefixLength; 71 static bool crackFileSystemURL(const KURL&, AsyncFileSystem::Type&, String& filePath); 72 name()73 const String& name() const { return m_name; } asyncFileSystem()74 AsyncFileSystem* asyncFileSystem() const { return m_asyncFileSystem.get(); } 75 SecurityOrigin* securityOrigin() const; 76 77 // Actual FileSystem API implementations. All the validity checks on virtual paths are done at this level. 78 // They return false for immediate errors that don't involve lower AsyncFileSystem layer (e.g. for name validation errors). Otherwise they return true (but later may call back with an runtime error). 79 bool getMetadata(const EntryBase*, PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>); 80 bool move(const EntryBase* source, EntryBase* parent, const String& name, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); 81 bool copy(const EntryBase* source, EntryBase* parent, const String& name, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); 82 bool remove(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>); 83 bool removeRecursively(const EntryBase*, PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>); 84 bool getParent(const EntryBase*, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); 85 bool getFile(const EntryBase*, const String& path, PassRefPtr<WebKitFlags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); 86 bool getDirectory(const EntryBase*, const String& path, PassRefPtr<WebKitFlags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); 87 bool readDirectory(PassRefPtr<DirectoryReaderBase>, const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>); 88 89 protected: 90 DOMFileSystemBase(ScriptExecutionContext*, const String& name, PassOwnPtr<AsyncFileSystem>); 91 friend class DOMFileSystemSync; 92 93 ScriptExecutionContext* m_context; 94 String m_name; 95 mutable OwnPtr<AsyncFileSystem> m_asyncFileSystem; 96 }; 97 98 } // namespace WebCore 99 100 #endif // ENABLE(FILE_SYSTEM) 101 102 #endif // DOMFileSystemBase_h 103