OLD | NEW |
| (Empty) |
1 /* | |
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 "public/web/WebDOMFileSystem.h" | |
32 | |
33 #include "bindings/modules/v8/V8DOMFileSystem.h" | |
34 #include "bindings/modules/v8/V8DirectoryEntry.h" | |
35 #include "bindings/modules/v8/V8FileEntry.h" | |
36 #include "core/dom/Document.h" | |
37 #include "core/frame/LocalFrame.h" | |
38 #include "core/frame/WebLocalFrameBase.h" | |
39 #include "modules/filesystem/DOMFileSystem.h" | |
40 #include "modules/filesystem/DirectoryEntry.h" | |
41 #include "modules/filesystem/FileEntry.h" | |
42 #include "platform/bindings/WrapperTypeInfo.h" | |
43 #include "v8/include/v8.h" | |
44 | |
45 namespace blink { | |
46 | |
47 WebDOMFileSystem WebDOMFileSystem::FromV8Value(v8::Local<v8::Value> value) { | |
48 if (!V8DOMFileSystem::hasInstance(value, v8::Isolate::GetCurrent())) | |
49 return WebDOMFileSystem(); | |
50 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | |
51 DOMFileSystem* dom_file_system = V8DOMFileSystem::toImpl(object); | |
52 DCHECK(dom_file_system); | |
53 return WebDOMFileSystem(dom_file_system); | |
54 } | |
55 | |
56 WebURL WebDOMFileSystem::CreateFileSystemURL(v8::Local<v8::Value> value) { | |
57 const Entry* const entry = | |
58 V8Entry::toImplWithTypeCheck(v8::Isolate::GetCurrent(), value); | |
59 if (entry) | |
60 return entry->filesystem()->CreateFileSystemURL(entry); | |
61 return WebURL(); | |
62 } | |
63 | |
64 WebDOMFileSystem WebDOMFileSystem::Create(WebLocalFrame* frame, | |
65 WebFileSystemType type, | |
66 const WebString& name, | |
67 const WebURL& root_url, | |
68 SerializableType serializable_type) { | |
69 DCHECK(frame); | |
70 DCHECK(ToWebLocalFrameBase(frame)->GetFrame()); | |
71 DOMFileSystem* dom_file_system = DOMFileSystem::Create( | |
72 ToWebLocalFrameBase(frame)->GetFrame()->GetDocument(), name, | |
73 static_cast<FileSystemType>(type), root_url); | |
74 if (serializable_type == kSerializableTypeSerializable) | |
75 dom_file_system->MakeClonable(); | |
76 return WebDOMFileSystem(dom_file_system); | |
77 } | |
78 | |
79 void WebDOMFileSystem::Reset() { | |
80 private_.Reset(); | |
81 } | |
82 | |
83 void WebDOMFileSystem::Assign(const WebDOMFileSystem& other) { | |
84 private_ = other.private_; | |
85 } | |
86 | |
87 WebString WebDOMFileSystem::GetName() const { | |
88 DCHECK(private_.Get()); | |
89 return private_->name(); | |
90 } | |
91 | |
92 WebFileSystem::Type WebDOMFileSystem::GetType() const { | |
93 DCHECK(private_.Get()); | |
94 switch (private_->GetType()) { | |
95 case kFileSystemTypeTemporary: | |
96 return WebFileSystem::kTypeTemporary; | |
97 case kFileSystemTypePersistent: | |
98 return WebFileSystem::kTypePersistent; | |
99 case kFileSystemTypeIsolated: | |
100 return WebFileSystem::kTypeIsolated; | |
101 case kFileSystemTypeExternal: | |
102 return WebFileSystem::kTypeExternal; | |
103 default: | |
104 NOTREACHED(); | |
105 return WebFileSystem::kTypeTemporary; | |
106 } | |
107 } | |
108 | |
109 WebURL WebDOMFileSystem::RootURL() const { | |
110 DCHECK(private_.Get()); | |
111 return private_->RootURL(); | |
112 } | |
113 | |
114 v8::Local<v8::Value> WebDOMFileSystem::ToV8Value( | |
115 v8::Local<v8::Object> creation_context, | |
116 v8::Isolate* isolate) { | |
117 // We no longer use |creationContext| because it's often misused and points | |
118 // to a context faked by user script. | |
119 DCHECK(creation_context->CreationContext() == isolate->GetCurrentContext()); | |
120 if (!private_.Get()) | |
121 return v8::Local<v8::Value>(); | |
122 return ToV8(private_.Get(), isolate->GetCurrentContext()->Global(), isolate); | |
123 } | |
124 | |
125 v8::Local<v8::Value> WebDOMFileSystem::CreateV8Entry( | |
126 const WebString& path, | |
127 EntryType entry_type, | |
128 v8::Local<v8::Object> creation_context, | |
129 v8::Isolate* isolate) { | |
130 // We no longer use |creationContext| because it's often misused and points | |
131 // to a context faked by user script. | |
132 DCHECK(creation_context->CreationContext() == isolate->GetCurrentContext()); | |
133 if (!private_.Get()) | |
134 return v8::Local<v8::Value>(); | |
135 if (entry_type == kEntryTypeDirectory) | |
136 return ToV8(DirectoryEntry::Create(private_.Get(), path), | |
137 isolate->GetCurrentContext()->Global(), isolate); | |
138 DCHECK_EQ(entry_type, kEntryTypeFile); | |
139 return ToV8(FileEntry::Create(private_.Get(), path), | |
140 isolate->GetCurrentContext()->Global(), isolate); | |
141 } | |
142 | |
143 WebDOMFileSystem::WebDOMFileSystem(DOMFileSystem* dom_file_system) | |
144 : private_(dom_file_system) {} | |
145 | |
146 WebDOMFileSystem& WebDOMFileSystem::operator=(DOMFileSystem* dom_file_system) { | |
147 private_ = dom_file_system; | |
148 return *this; | |
149 } | |
150 | |
151 } // namespace blink | |
OLD | NEW |