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" 35 #include "bindings/v8/WrapperTypeInfo.h" 36 #include "modules/filesystem/DOMFileSystem.h" 37 #include <v8.h> 38 39 using namespace WebCore; 40 41 namespace blink { 42 43 WebDOMFileSystem WebDOMFileSystem::fromV8Value(v8::Handle<v8::Value> value) 44 { 45 if (!V8DOMFileSystem::hasInstanceInAnyWorld(value, v8::Isolate::GetCurrent())) 46 return WebDOMFileSystem(); 47 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); 48 DOMFileSystem* domFileSystem = V8DOMFileSystem::toNative(object); 49 ASSERT(domFileSystem); 50 return WebDOMFileSystem(domFileSystem); 51 } 52 53 void WebDOMFileSystem::reset() 54 { 55 m_private.reset(); 56 } 57 58 void WebDOMFileSystem::assign(const WebDOMFileSystem& other) 59 { 60 m_private = other.m_private; 61 } 62 63 WebString WebDOMFileSystem::name() const 64 { 65 ASSERT(m_private.get()); 66 return m_private->name(); 67 } 68 69 WebFileSystem::Type WebDOMFileSystem::type() const 70 { 71 ASSERT(m_private.get()); 72 switch (m_private->type()) { 73 case FileSystemTypeTemporary: 74 return WebFileSystem::TypeTemporary; 75 case FileSystemTypePersistent: 76 return WebFileSystem::TypePersistent; 77 case FileSystemTypeIsolated: 78 return WebFileSystem::TypeIsolated; 79 case FileSystemTypeExternal: 80 return WebFileSystem::TypeExternal; 81 default: 82 ASSERT_NOT_REACHED(); 83 return WebFileSystem::TypeTemporary; 84 } 85 } 86 87 WebURL WebDOMFileSystem::rootURL() const 88 { 89 ASSERT(m_private.get()); 90 return m_private->rootURL(); 91 } 92 93 WebDOMFileSystem::WebDOMFileSystem(const WTF::PassRefPtr<DOMFileSystem>& domFileSystem) 94 : m_private(domFileSystem) 95 { 96 } 97 98 WebDOMFileSystem& WebDOMFileSystem::operator=(const WTF::PassRefPtr<WebCore::DOMFileSystem>& domFileSystem) 99 { 100 m_private = domFileSystem; 101 return *this; 102 } 103 104 WebDOMFileSystem::operator WTF::PassRefPtr<WebCore::DOMFileSystem>() const 105 { 106 return m_private.get(); 107 } 108 109 } // namespace blink 110