blob: 406e4de06ef798a0cbc966557313825d1084c928 [file] [log] [blame]
Torne (Richard Coles)1e202182013-10-18 15:46:42 +01001/*
2 * Copyright (C) 2013 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#include "config.h"
32#include "WebDOMFileSystem.h"
33
34#include "V8DOMFileSystem.h"
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000035#include "V8DirectoryEntry.h"
36#include "V8FileEntry.h"
37#include "WebFrameImpl.h"
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010038#include "bindings/v8/WrapperTypeInfo.h"
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000039#include "core/dom/Document.h"
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010040#include "modules/filesystem/DOMFileSystem.h"
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000041#include "modules/filesystem/DirectoryEntry.h"
42#include "modules/filesystem/FileEntry.h"
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010043#include <v8.h>
44
45using namespace WebCore;
46
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000047namespace blink {
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010048
49WebDOMFileSystem WebDOMFileSystem::fromV8Value(v8::Handle<v8::Value> value)
50{
Torne (Richard Coles)09380292014-02-21 12:17:33 +000051 if (!V8DOMFileSystem::hasInstance(value, v8::Isolate::GetCurrent()))
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010052 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);
57}
58
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +000059WebDOMFileSystem WebDOMFileSystem::create(
60 WebFrame* frame,
61 WebFileSystemType type,
62 const WebString& name,
63 const WebURL& rootURL,
64 SerializableType serializableType)
65{
66 ASSERT(frame && toWebFrameImpl(frame)->frame());
67 RefPtrWillBeRawPtr<DOMFileSystem> domFileSystem = DOMFileSystem::create(toWebFrameImpl(frame)->frame()->document(), name, static_cast<WebCore::FileSystemType>(type), rootURL);
68 if (serializableType == SerializableTypeSerializable)
69 domFileSystem->makeClonable();
70 return WebDOMFileSystem(domFileSystem);
71}
72
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010073void WebDOMFileSystem::reset()
74{
75 m_private.reset();
76}
77
78void WebDOMFileSystem::assign(const WebDOMFileSystem& other)
79{
80 m_private = other.m_private;
81}
82
83WebString WebDOMFileSystem::name() const
84{
85 ASSERT(m_private.get());
86 return m_private->name();
87}
88
89WebFileSystem::Type WebDOMFileSystem::type() const
90{
91 ASSERT(m_private.get());
92 switch (m_private->type()) {
93 case FileSystemTypeTemporary:
94 return WebFileSystem::TypeTemporary;
95 case FileSystemTypePersistent:
96 return WebFileSystem::TypePersistent;
97 case FileSystemTypeIsolated:
98 return WebFileSystem::TypeIsolated;
99 case FileSystemTypeExternal:
100 return WebFileSystem::TypeExternal;
101 default:
102 ASSERT_NOT_REACHED();
103 return WebFileSystem::TypeTemporary;
104 }
105}
106
107WebURL WebDOMFileSystem::rootURL() const
108{
109 ASSERT(m_private.get());
110 return m_private->rootURL();
111}
112
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000113v8::Handle<v8::Value> WebDOMFileSystem::toV8Value()
114{
115 if (!m_private.get())
116 return v8::Handle<v8::Value>();
117 return toV8(m_private.get(), v8::Handle<v8::Object>(), toIsolate(m_private->executionContext()));
118}
119
120v8::Handle<v8::Value> WebDOMFileSystem::createV8Entry(
121 const WebString& path,
122 EntryType entryType)
123{
124 if (!m_private.get())
125 return v8::Handle<v8::Value>();
126 if (entryType == EntryTypeDirectory)
127 return toV8(DirectoryEntry::create(m_private.get(), path), v8::Handle<v8::Object>(), toIsolate(m_private->executionContext()));
128 ASSERT(entryType == EntryTypeFile);
129 return toV8(FileEntry::create(m_private.get(), path), v8::Handle<v8::Object>(), toIsolate(m_private->executionContext()));
130}
131
132WebDOMFileSystem::WebDOMFileSystem(const PassRefPtrWillBeRawPtr<DOMFileSystem>& domFileSystem)
Torne (Richard Coles)1e202182013-10-18 15:46:42 +0100133 : m_private(domFileSystem)
134{
135}
136
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000137WebDOMFileSystem& WebDOMFileSystem::operator=(const PassRefPtrWillBeRawPtr<WebCore::DOMFileSystem>& domFileSystem)
Torne (Richard Coles)1e202182013-10-18 15:46:42 +0100138{
139 m_private = domFileSystem;
140 return *this;
141}
142
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000143} // namespace blink