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 #include "config.h"
31 #include "WebFileSystemCallbacksImpl.h"
32
33 #if ENABLE(FILE_SYSTEM)
34
35 #include "AsyncFileSystemCallbacks.h"
36 #include "AsyncFileSystemChromium.h"
37 #include "FileMetadata.h"
38 #include "ScriptExecutionContext.h"
39 #include "WebFileInfo.h"
40 #include "WebFileSystem.h"
41 #include "WebFileSystemEntry.h"
42 #include "WebString.h"
43 #include "WorkerAsyncFileSystemChromium.h"
44 #include <wtf/Vector.h>
45
46 using namespace WebCore;
47
48 namespace WebKit {
49
WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks,AsyncFileSystem::Type type,WebCore::ScriptExecutionContext * context,bool synchronous)50 WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks, AsyncFileSystem::Type type, WebCore::ScriptExecutionContext* context, bool synchronous)
51 : m_callbacks(callbacks)
52 , m_type(type)
53 , m_context(context)
54 , m_synchronous(synchronous)
55 {
56 ASSERT(m_callbacks);
57 }
58
~WebFileSystemCallbacksImpl()59 WebFileSystemCallbacksImpl::~WebFileSystemCallbacksImpl()
60 {
61 }
62
didSucceed()63 void WebFileSystemCallbacksImpl::didSucceed()
64 {
65 m_callbacks->didSucceed();
66 delete this;
67 }
68
didReadMetadata(const WebFileInfo & webFileInfo)69 void WebFileSystemCallbacksImpl::didReadMetadata(const WebFileInfo& webFileInfo)
70 {
71 FileMetadata fileMetadata;
72 fileMetadata.modificationTime = webFileInfo.modificationTime;
73 fileMetadata.length = webFileInfo.length;
74 fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type);
75 fileMetadata.platformPath = webFileInfo.platformPath;
76 m_callbacks->didReadMetadata(fileMetadata);
77 delete this;
78 }
79
didReadDirectory(const WebVector<WebFileSystemEntry> & entries,bool hasMore)80 void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
81 {
82 for (size_t i = 0; i < entries.size(); ++i)
83 m_callbacks->didReadDirectoryEntry(entries[i].name, entries[i].isDirectory);
84 m_callbacks->didReadDirectoryEntries(hasMore);
85 delete this;
86 }
87
didOpenFileSystem(const WebString & name,const WebString & path)88 void WebFileSystemCallbacksImpl::didOpenFileSystem(const WebString& name, const WebString& path)
89 {
90 if (m_context && m_context->isWorkerContext())
91 m_callbacks->didOpenFileSystem(name, WorkerAsyncFileSystemChromium::create(m_context, m_type, path, m_synchronous));
92 else
93 m_callbacks->didOpenFileSystem(name, AsyncFileSystemChromium::create(m_type, path));
94 delete this;
95 }
96
didFail(WebFileError error)97 void WebFileSystemCallbacksImpl::didFail(WebFileError error)
98 {
99 m_callbacks->didFail(error);
100 delete this;
101 }
102
103 } // namespace WebKit
104
105 #endif // ENABLE(FILE_SYSTEM)
106