2 * Copyright (C) 2013 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.
32 #include "public/web/WebDOMFileSystem.h"
34 #include "V8DOMFileSystem.h"
35 #include "V8DirectoryEntry.h"
36 #include "V8FileEntry.h"
37 #include "bindings/v8/WrapperTypeInfo.h"
38 #include "core/dom/Document.h"
39 #include "modules/filesystem/DOMFileSystem.h"
40 #include "modules/filesystem/DirectoryEntry.h"
41 #include "modules/filesystem/FileEntry.h"
42 #include "web/WebLocalFrameImpl.h"
45 using namespace WebCore;
49 WebDOMFileSystem WebDOMFileSystem::fromV8Value(v8::Handle<v8::Value> value)
51 if (!V8DOMFileSystem::hasInstance(value, v8::Isolate::GetCurrent()))
52 return WebDOMFileSystem();
53 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value);
54 DOMFileSystem* domFileSystem = V8DOMFileSystem::toNative(object);
55 ASSERT(domFileSystem);
56 return WebDOMFileSystem(domFileSystem);
59 WebURL WebDOMFileSystem::createFileSystemURL(v8::Handle<v8::Value> value)
61 const FileEntry* const entry = V8FileEntry::toNativeWithTypeCheck(v8::Isolate::GetCurrent(), value);
63 return entry->filesystem()->createFileSystemURL(entry);
67 WebDOMFileSystem WebDOMFileSystem::create(
69 WebFileSystemType type,
70 const WebString& name,
71 const WebURL& rootURL,
72 SerializableType serializableType)
74 ASSERT(frame && toWebLocalFrameImpl(frame)->frame());
75 DOMFileSystem* domFileSystem = DOMFileSystem::create(toWebLocalFrameImpl(frame)->frame()->document(), name, static_cast<WebCore::FileSystemType>(type), rootURL);
76 if (serializableType == SerializableTypeSerializable)
77 domFileSystem->makeClonable();
78 return WebDOMFileSystem(domFileSystem);
81 void WebDOMFileSystem::reset()
86 void WebDOMFileSystem::assign(const WebDOMFileSystem& other)
88 m_private = other.m_private;
91 WebString WebDOMFileSystem::name() const
93 ASSERT(m_private.get());
94 return m_private->name();
97 WebFileSystem::Type WebDOMFileSystem::type() const
99 ASSERT(m_private.get());
100 switch (m_private->type()) {
101 case FileSystemTypeTemporary:
102 return WebFileSystem::TypeTemporary;
103 case FileSystemTypePersistent:
104 return WebFileSystem::TypePersistent;
105 case FileSystemTypeIsolated:
106 return WebFileSystem::TypeIsolated;
107 case FileSystemTypeExternal:
108 return WebFileSystem::TypeExternal;
110 ASSERT_NOT_REACHED();
111 return WebFileSystem::TypeTemporary;
115 WebURL WebDOMFileSystem::rootURL() const
117 ASSERT(m_private.get());
118 return m_private->rootURL();
121 v8::Handle<v8::Value> WebDOMFileSystem::toV8Value(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
123 if (!m_private.get())
124 return v8::Handle<v8::Value>();
125 return toV8(m_private.get(), creationContext, isolate);
128 v8::Handle<v8::Value> WebDOMFileSystem::createV8Entry(
129 const WebString& path,
131 v8::Handle<v8::Object> creationContext,
132 v8::Isolate* isolate)
134 if (!m_private.get())
135 return v8::Handle<v8::Value>();
136 if (entryType == EntryTypeDirectory)
137 return toV8(DirectoryEntry::create(m_private.get(), path), creationContext, isolate);
138 ASSERT(entryType == EntryTypeFile);
139 return toV8(FileEntry::create(m_private.get(), path), creationContext, isolate);
142 WebDOMFileSystem::WebDOMFileSystem(DOMFileSystem* domFileSystem)
143 : m_private(domFileSystem)
147 WebDOMFileSystem& WebDOMFileSystem::operator=(WebCore::DOMFileSystem* domFileSystem)
149 m_private = domFileSystem;