Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 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 "config.h" |
| 32 | #include "WebDOMFileSystem.h" |
| 33 | |
| 34 | #include "V8DOMFileSystem.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 35 | #include "V8DirectoryEntry.h" |
| 36 | #include "V8FileEntry.h" |
| 37 | #include "WebFrameImpl.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 38 | #include "bindings/v8/WrapperTypeInfo.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 39 | #include "core/dom/Document.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 40 | #include "modules/filesystem/DOMFileSystem.h" |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 41 | #include "modules/filesystem/DirectoryEntry.h" |
| 42 | #include "modules/filesystem/FileEntry.h" |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 43 | #include <v8.h> |
| 44 | |
| 45 | using namespace WebCore; |
| 46 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 47 | namespace blink { |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 48 | |
| 49 | WebDOMFileSystem WebDOMFileSystem::fromV8Value(v8::Handle<v8::Value> value) |
| 50 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 51 | if (!V8DOMFileSystem::hasInstance(value, v8::Isolate::GetCurrent())) |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 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); |
| 57 | } |
| 58 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 59 | WebDOMFileSystem 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) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 73 | void WebDOMFileSystem::reset() |
| 74 | { |
| 75 | m_private.reset(); |
| 76 | } |
| 77 | |
| 78 | void WebDOMFileSystem::assign(const WebDOMFileSystem& other) |
| 79 | { |
| 80 | m_private = other.m_private; |
| 81 | } |
| 82 | |
| 83 | WebString WebDOMFileSystem::name() const |
| 84 | { |
| 85 | ASSERT(m_private.get()); |
| 86 | return m_private->name(); |
| 87 | } |
| 88 | |
| 89 | WebFileSystem::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 | |
| 107 | WebURL WebDOMFileSystem::rootURL() const |
| 108 | { |
| 109 | ASSERT(m_private.get()); |
| 110 | return m_private->rootURL(); |
| 111 | } |
| 112 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 113 | v8::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 | |
| 120 | v8::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 | |
| 132 | WebDOMFileSystem::WebDOMFileSystem(const PassRefPtrWillBeRawPtr<DOMFileSystem>& domFileSystem) |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 133 | : m_private(domFileSystem) |
| 134 | { |
| 135 | } |
| 136 | |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 137 | WebDOMFileSystem& WebDOMFileSystem::operator=(const PassRefPtrWillBeRawPtr<WebCore::DOMFileSystem>& domFileSystem) |
Torne (Richard Coles) | 1e20218 | 2013-10-18 15:46:42 +0100 | [diff] [blame] | 138 | { |
| 139 | m_private = domFileSystem; |
| 140 | return *this; |
| 141 | } |
| 142 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 143 | } // namespace blink |