| 1 | /* |
| 2 | * This file is part of the WebKit open source project. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | #include "WebKitDOMFile.h" |
| 22 | |
| 23 | #include <WebCore/CSSImportRule.h> |
| 24 | #include "DOMObjectCache.h" |
| 25 | #include <WebCore/Document.h> |
| 26 | #include <WebCore/ExceptionCode.h> |
| 27 | #include <WebCore/JSExecState.h> |
| 28 | #include "WebKitDOMBlobPrivate.h" |
| 29 | #include "WebKitDOMFilePrivate.h" |
| 30 | #include "WebKitDOMPrivate.h" |
| 31 | #include "ConvertToUTF8String.h" |
| 32 | #include <wtf/GetPtr.h> |
| 33 | #include <wtf/RefPtr.h> |
| 34 | |
| 35 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 36 | |
| 37 | namespace WebKit { |
| 38 | |
| 39 | WebKitDOMFile* kit(WebCore::File* obj) |
| 40 | { |
| 41 | return WEBKIT_DOM_FILE(kit(static_cast<WebCore::Blob*>(obj))); |
| 42 | } |
| 43 | |
| 44 | WebCore::File* core(WebKitDOMFile* request) |
| 45 | { |
| 46 | return request ? static_cast<WebCore::File*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
| 47 | } |
| 48 | |
| 49 | WebKitDOMFile* wrapFile(WebCore::File* coreObject) |
| 50 | { |
| 51 | ASSERT(coreObject); |
| 52 | return WEBKIT_DOM_FILE(g_object_new(WEBKIT_DOM_TYPE_FILE, "core-object" , coreObject, nullptr)); |
| 53 | } |
| 54 | |
| 55 | } // namespace WebKit |
| 56 | |
| 57 | G_DEFINE_TYPE(WebKitDOMFile, webkit_dom_file, WEBKIT_DOM_TYPE_BLOB) |
| 58 | |
| 59 | enum { |
| 60 | DOM_FILE_PROP_0, |
| 61 | DOM_FILE_PROP_NAME, |
| 62 | }; |
| 63 | |
| 64 | static void webkit_dom_file_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
| 65 | { |
| 66 | WebKitDOMFile* self = WEBKIT_DOM_FILE(object); |
| 67 | |
| 68 | switch (propertyId) { |
| 69 | case DOM_FILE_PROP_NAME: |
| 70 | g_value_take_string(value, webkit_dom_file_get_name(self)); |
| 71 | break; |
| 72 | default: |
| 73 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | static void webkit_dom_file_class_init(WebKitDOMFileClass* requestClass) |
| 79 | { |
| 80 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| 81 | gobjectClass->get_property = webkit_dom_file_get_property; |
| 82 | |
| 83 | g_object_class_install_property( |
| 84 | gobjectClass, |
| 85 | DOM_FILE_PROP_NAME, |
| 86 | g_param_spec_string( |
| 87 | "name" , |
| 88 | "File:name" , |
| 89 | "read-only gchar* File:name" , |
| 90 | "" , |
| 91 | WEBKIT_PARAM_READABLE)); |
| 92 | } |
| 93 | |
| 94 | static void webkit_dom_file_init(WebKitDOMFile* request) |
| 95 | { |
| 96 | UNUSED_PARAM(request); |
| 97 | } |
| 98 | |
| 99 | gchar* webkit_dom_file_get_name(WebKitDOMFile* self) |
| 100 | { |
| 101 | WebCore::JSMainThreadNullState state; |
| 102 | g_return_val_if_fail(WEBKIT_DOM_IS_FILE(self), 0); |
| 103 | WebCore::File* item = WebKit::core(self); |
| 104 | gchar* result = convertToUTF8String(item->name()); |
| 105 | return result; |
| 106 | } |
| 107 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 108 | |