Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebDOMFileSystem.cpp
blobb811003a0a8020bc694688197b7d1abaee23a7ae
1 /*
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
6 * met:
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.
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 "config.h"
32 #include "public/web/WebDOMFileSystem.h"
34 #include "bindings/core/v8/WrapperTypeInfo.h"
35 #include "bindings/modules/v8/V8DOMFileSystem.h"
36 #include "bindings/modules/v8/V8DirectoryEntry.h"
37 #include "bindings/modules/v8/V8FileEntry.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"
43 #include <v8.h>
45 namespace blink {
47 WebDOMFileSystem WebDOMFileSystem::fromV8Value(v8::Local<v8::Value> value)
49 if (!V8DOMFileSystem::hasInstance(value, v8::Isolate::GetCurrent()))
50 return WebDOMFileSystem();
51 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
52 DOMFileSystem* domFileSystem = V8DOMFileSystem::toImpl(object);
53 ASSERT(domFileSystem);
54 return WebDOMFileSystem(domFileSystem);
57 WebURL WebDOMFileSystem::createFileSystemURL(v8::Local<v8::Value> value)
59 const Entry* const entry = V8Entry::toImplWithTypeCheck(v8::Isolate::GetCurrent(), value);
60 if (entry)
61 return entry->filesystem()->createFileSystemURL(entry);
62 return WebURL();
65 WebDOMFileSystem WebDOMFileSystem::create(
66 WebLocalFrame* frame,
67 WebFileSystemType type,
68 const WebString& name,
69 const WebURL& rootURL,
70 SerializableType serializableType)
72 ASSERT(frame && toWebLocalFrameImpl(frame)->frame());
73 DOMFileSystem* domFileSystem = DOMFileSystem::create(toWebLocalFrameImpl(frame)->frame()->document(), name, static_cast<FileSystemType>(type), rootURL);
74 if (serializableType == SerializableTypeSerializable)
75 domFileSystem->makeClonable();
76 return WebDOMFileSystem(domFileSystem);
79 void WebDOMFileSystem::reset()
81 m_private.reset();
84 void WebDOMFileSystem::assign(const WebDOMFileSystem& other)
86 m_private = other.m_private;
89 WebString WebDOMFileSystem::name() const
91 ASSERT(m_private.get());
92 return m_private->name();
95 WebFileSystem::Type WebDOMFileSystem::type() const
97 ASSERT(m_private.get());
98 switch (m_private->type()) {
99 case FileSystemTypeTemporary:
100 return WebFileSystem::TypeTemporary;
101 case FileSystemTypePersistent:
102 return WebFileSystem::TypePersistent;
103 case FileSystemTypeIsolated:
104 return WebFileSystem::TypeIsolated;
105 case FileSystemTypeExternal:
106 return WebFileSystem::TypeExternal;
107 default:
108 ASSERT_NOT_REACHED();
109 return WebFileSystem::TypeTemporary;
113 WebURL WebDOMFileSystem::rootURL() const
115 ASSERT(m_private.get());
116 return m_private->rootURL();
119 v8::Local<v8::Value> WebDOMFileSystem::toV8Value(v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
121 // We no longer use |creationContext| because it's often misused and points
122 // to a context faked by user script.
123 ASSERT(creationContext->CreationContext() == isolate->GetCurrentContext());
124 if (!m_private.get())
125 return v8::Local<v8::Value>();
126 return toV8(m_private.get(), isolate->GetCurrentContext()->Global(), isolate);
129 v8::Local<v8::Value> WebDOMFileSystem::createV8Entry(
130 const WebString& path,
131 EntryType entryType,
132 v8::Local<v8::Object> creationContext,
133 v8::Isolate* isolate)
135 // We no longer use |creationContext| because it's often misused and points
136 // to a context faked by user script.
137 ASSERT(creationContext->CreationContext() == isolate->GetCurrentContext());
138 if (!m_private.get())
139 return v8::Local<v8::Value>();
140 if (entryType == EntryTypeDirectory)
141 return toV8(DirectoryEntry::create(m_private.get(), path), isolate->GetCurrentContext()->Global(), isolate);
142 ASSERT(entryType == EntryTypeFile);
143 return toV8(FileEntry::create(m_private.get(), path), isolate->GetCurrentContext()->Global(), isolate);
146 WebDOMFileSystem::WebDOMFileSystem(DOMFileSystem* domFileSystem)
147 : m_private(domFileSystem)
151 WebDOMFileSystem& WebDOMFileSystem::operator=(DOMFileSystem* domFileSystem)
153 m_private = domFileSystem;
154 return *this;
157 } // namespace blink