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 #include "WebFileSystemCallbacksImpl.h"
33 #if ENABLE(FILE_SYSTEM)
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>
46 using namespace WebCore;
50 WebFileSystemCallbacksImpl::WebFileSystemCallbacksImpl(PassOwnPtr<AsyncFileSystemCallbacks> callbacks, AsyncFileSystem::Type type, WebCore::ScriptExecutionContext* context, bool synchronous)
51 : m_callbacks(callbacks)
54 , m_synchronous(synchronous)
59 WebFileSystemCallbacksImpl::~WebFileSystemCallbacksImpl()
63 void WebFileSystemCallbacksImpl::didSucceed()
65 m_callbacks->didSucceed();
69 void WebFileSystemCallbacksImpl::didReadMetadata(const WebFileInfo& webFileInfo)
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);
80 void WebFileSystemCallbacksImpl::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
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);
88 void WebFileSystemCallbacksImpl::didOpenFileSystem(const WebString& name, const WebURL& rootURL)
90 // This object is intended to delete itself on exit.
91 OwnPtr<WebFileSystemCallbacksImpl> callbacks = adoptPtr(this);
94 if (m_context && m_context->isWorkerContext()) {
95 m_callbacks->didOpenFileSystem(name, WorkerAsyncFileSystemChromium::create(m_context, m_type, rootURL, m_synchronous));
99 m_callbacks->didOpenFileSystem(name, AsyncFileSystemChromium::create(m_type, rootURL));
102 void WebFileSystemCallbacksImpl::didFail(WebFileError error)
104 m_callbacks->didFail(error);
108 } // namespace WebKit
110 #endif // ENABLE(FILE_SYSTEM)