2 * This file is part of the WebKit open source project.
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.
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.
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.
21 #include "WebKitDOMBlob.h"
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/Document.h>
26 #include <WebCore/JSMainThreadExecState.h>
27 #include "WebKitDOMBlobPrivate.h"
28 #include "WebKitDOMPrivate.h"
29 #include "ConvertToUTF8String.h"
30 #include <wtf/GetPtr.h>
31 #include <wtf/RefPtr.h>
33 #define WEBKIT_DOM_BLOB_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_BLOB, WebKitDOMBlobPrivate)
35 typedef struct _WebKitDOMBlobPrivate {
36 RefPtr<WebCore::Blob> coreObject;
37 } WebKitDOMBlobPrivate;
41 WebKitDOMBlob* kit(WebCore::Blob* obj)
46 if (gpointer ret = DOMObjectCache::get(obj))
47 return WEBKIT_DOM_BLOB(ret);
52 WebCore::Blob* core(WebKitDOMBlob* request)
54 return request ? static_cast<WebCore::Blob*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
57 WebKitDOMBlob* wrapBlob(WebCore::Blob* coreObject)
60 return WEBKIT_DOM_BLOB(g_object_new(WEBKIT_DOM_TYPE_BLOB, "core-object", coreObject, nullptr));
65 G_DEFINE_TYPE(WebKitDOMBlob, webkit_dom_blob, WEBKIT_DOM_TYPE_OBJECT)
72 static void webkit_dom_blob_finalize(GObject* object)
74 WebKitDOMBlobPrivate* priv = WEBKIT_DOM_BLOB_GET_PRIVATE(object);
76 WebKit::DOMObjectCache::forget(priv->coreObject.get());
78 priv->~WebKitDOMBlobPrivate();
79 G_OBJECT_CLASS(webkit_dom_blob_parent_class)->finalize(object);
82 static void webkit_dom_blob_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
84 WebKitDOMBlob* self = WEBKIT_DOM_BLOB(object);
88 g_value_set_uint64(value, webkit_dom_blob_get_size(self));
91 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
96 static GObject* webkit_dom_blob_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
98 GObject* object = G_OBJECT_CLASS(webkit_dom_blob_parent_class)->constructor(type, constructPropertiesCount, constructProperties);
100 WebKitDOMBlobPrivate* priv = WEBKIT_DOM_BLOB_GET_PRIVATE(object);
101 priv->coreObject = static_cast<WebCore::Blob*>(WEBKIT_DOM_OBJECT(object)->coreObject);
102 WebKit::DOMObjectCache::put(priv->coreObject.get(), object);
107 static void webkit_dom_blob_class_init(WebKitDOMBlobClass* requestClass)
109 GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
110 g_type_class_add_private(gobjectClass, sizeof(WebKitDOMBlobPrivate));
111 gobjectClass->constructor = webkit_dom_blob_constructor;
112 gobjectClass->finalize = webkit_dom_blob_finalize;
113 gobjectClass->get_property = webkit_dom_blob_get_property;
115 g_object_class_install_property(
121 "read-only guint64 Blob:size",
123 WEBKIT_PARAM_READABLE));
126 static void webkit_dom_blob_init(WebKitDOMBlob* request)
128 WebKitDOMBlobPrivate* priv = WEBKIT_DOM_BLOB_GET_PRIVATE(request);
129 new (priv) WebKitDOMBlobPrivate();
132 guint64 webkit_dom_blob_get_size(WebKitDOMBlob* self)
134 WebCore::JSMainThreadNullState state;
135 g_return_val_if_fail(WEBKIT_DOM_IS_BLOB(self), 0);
136 WebCore::Blob* item = WebKit::core(self);
137 guint64 result = item->size();