| 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 "WebKitDOMStyleSheetList.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 "WebKitDOMPrivate.h" |
| 29 | #include "WebKitDOMStyleSheetListPrivate.h" |
| 30 | #include "WebKitDOMStyleSheetPrivate.h" |
| 31 | #include "ConvertToUTF8String.h" |
| 32 | #include <wtf/GetPtr.h> |
| 33 | #include <wtf/RefPtr.h> |
| 34 | |
| 35 | #define WEBKIT_DOM_STYLE_SHEET_LIST_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_STYLE_SHEET_LIST, WebKitDOMStyleSheetListPrivate) |
| 36 | |
| 37 | typedef struct _WebKitDOMStyleSheetListPrivate { |
| 38 | RefPtr<WebCore::StyleSheetList> coreObject; |
| 39 | } WebKitDOMStyleSheetListPrivate; |
| 40 | |
| 41 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 42 | |
| 43 | namespace WebKit { |
| 44 | |
| 45 | WebKitDOMStyleSheetList* kit(WebCore::StyleSheetList* obj) |
| 46 | { |
| 47 | if (!obj) |
| 48 | return 0; |
| 49 | |
| 50 | if (gpointer ret = DOMObjectCache::get(obj)) |
| 51 | return WEBKIT_DOM_STYLE_SHEET_LIST(ret); |
| 52 | |
| 53 | return wrapStyleSheetList(obj); |
| 54 | } |
| 55 | |
| 56 | WebCore::StyleSheetList* core(WebKitDOMStyleSheetList* request) |
| 57 | { |
| 58 | return request ? static_cast<WebCore::StyleSheetList*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
| 59 | } |
| 60 | |
| 61 | WebKitDOMStyleSheetList* wrapStyleSheetList(WebCore::StyleSheetList* coreObject) |
| 62 | { |
| 63 | ASSERT(coreObject); |
| 64 | return WEBKIT_DOM_STYLE_SHEET_LIST(g_object_new(WEBKIT_DOM_TYPE_STYLE_SHEET_LIST, "core-object" , coreObject, nullptr)); |
| 65 | } |
| 66 | |
| 67 | } // namespace WebKit |
| 68 | |
| 69 | G_DEFINE_TYPE(WebKitDOMStyleSheetList, webkit_dom_style_sheet_list, WEBKIT_DOM_TYPE_OBJECT) |
| 70 | |
| 71 | enum { |
| 72 | DOM_STYLE_SHEET_LIST_PROP_0, |
| 73 | DOM_STYLE_SHEET_LIST_PROP_LENGTH, |
| 74 | }; |
| 75 | |
| 76 | static void webkit_dom_style_sheet_list_finalize(GObject* object) |
| 77 | { |
| 78 | WebKitDOMStyleSheetListPrivate* priv = WEBKIT_DOM_STYLE_SHEET_LIST_GET_PRIVATE(object); |
| 79 | |
| 80 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
| 81 | |
| 82 | priv->~WebKitDOMStyleSheetListPrivate(); |
| 83 | G_OBJECT_CLASS(webkit_dom_style_sheet_list_parent_class)->finalize(object); |
| 84 | } |
| 85 | |
| 86 | static void webkit_dom_style_sheet_list_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
| 87 | { |
| 88 | WebKitDOMStyleSheetList* self = WEBKIT_DOM_STYLE_SHEET_LIST(object); |
| 89 | |
| 90 | switch (propertyId) { |
| 91 | case DOM_STYLE_SHEET_LIST_PROP_LENGTH: |
| 92 | g_value_set_ulong(value, webkit_dom_style_sheet_list_get_length(self)); |
| 93 | break; |
| 94 | default: |
| 95 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static GObject* webkit_dom_style_sheet_list_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) |
| 101 | { |
| 102 | GObject* object = G_OBJECT_CLASS(webkit_dom_style_sheet_list_parent_class)->constructor(type, constructPropertiesCount, constructProperties); |
| 103 | |
| 104 | WebKitDOMStyleSheetListPrivate* priv = WEBKIT_DOM_STYLE_SHEET_LIST_GET_PRIVATE(object); |
| 105 | priv->coreObject = static_cast<WebCore::StyleSheetList*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
| 106 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
| 107 | |
| 108 | return object; |
| 109 | } |
| 110 | |
| 111 | static void webkit_dom_style_sheet_list_class_init(WebKitDOMStyleSheetListClass* requestClass) |
| 112 | { |
| 113 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| 114 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMStyleSheetListPrivate)); |
| 115 | gobjectClass->constructor = webkit_dom_style_sheet_list_constructor; |
| 116 | gobjectClass->finalize = webkit_dom_style_sheet_list_finalize; |
| 117 | gobjectClass->get_property = webkit_dom_style_sheet_list_get_property; |
| 118 | |
| 119 | g_object_class_install_property( |
| 120 | gobjectClass, |
| 121 | DOM_STYLE_SHEET_LIST_PROP_LENGTH, |
| 122 | g_param_spec_ulong( |
| 123 | "length" , |
| 124 | "StyleSheetList:length" , |
| 125 | "read-only gulong StyleSheetList:length" , |
| 126 | 0, G_MAXULONG, 0, |
| 127 | WEBKIT_PARAM_READABLE)); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | static void webkit_dom_style_sheet_list_init(WebKitDOMStyleSheetList* request) |
| 132 | { |
| 133 | WebKitDOMStyleSheetListPrivate* priv = WEBKIT_DOM_STYLE_SHEET_LIST_GET_PRIVATE(request); |
| 134 | new (priv) WebKitDOMStyleSheetListPrivate(); |
| 135 | } |
| 136 | |
| 137 | WebKitDOMStyleSheet* webkit_dom_style_sheet_list_item(WebKitDOMStyleSheetList* self, gulong index) |
| 138 | { |
| 139 | WebCore::JSMainThreadNullState state; |
| 140 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET_LIST(self), 0); |
| 141 | WebCore::StyleSheetList* item = WebKit::core(self); |
| 142 | RefPtr<WebCore::StyleSheet> gobjectResult = WTF::getPtr(item->item(index)); |
| 143 | return WebKit::kit(gobjectResult.get()); |
| 144 | } |
| 145 | |
| 146 | gulong webkit_dom_style_sheet_list_get_length(WebKitDOMStyleSheetList* self) |
| 147 | { |
| 148 | WebCore::JSMainThreadNullState state; |
| 149 | g_return_val_if_fail(WEBKIT_DOM_IS_STYLE_SHEET_LIST(self), 0); |
| 150 | WebCore::StyleSheetList* item = WebKit::core(self); |
| 151 | gulong result = item->length(); |
| 152 | return result; |
| 153 | } |
| 154 | |
| 155 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 156 | |