Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMCSSRuleList.cpp
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 "WebKitDOMCSSRuleList.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/Document.h>
26 #include <WebCore/JSMainThreadExecState.h>
27 #include "WebKitDOMCSSRuleListPrivate.h"
28 #include "WebKitDOMCSSRulePrivate.h"
29 #include "WebKitDOMPrivate.h"
30 #include "ConvertToUTF8String.h"
31 #include <wtf/GetPtr.h>
32 #include <wtf/RefPtr.h>
33
34 #define WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_CSS_RULE_LIST, WebKitDOMCSSRuleListPrivate)
35
36 typedef struct _WebKitDOMCSSRuleListPrivate {
37     RefPtr<WebCore::CSSRuleList> coreObject;
38 } WebKitDOMCSSRuleListPrivate;
39
40 namespace WebKit {
41
42 WebKitDOMCSSRuleList* kit(WebCore::CSSRuleList* obj)
43 {
44     if (!obj)
45         return 0;
46
47     if (gpointer ret = DOMObjectCache::get(obj))
48         return WEBKIT_DOM_CSS_RULE_LIST(ret);
49
50     return wrapCSSRuleList(obj);
51 }
52
53 WebCore::CSSRuleList* core(WebKitDOMCSSRuleList* request)
54 {
55     return request ? static_cast<WebCore::CSSRuleList*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
56 }
57
58 WebKitDOMCSSRuleList* wrapCSSRuleList(WebCore::CSSRuleList* coreObject)
59 {
60     ASSERT(coreObject);
61     return WEBKIT_DOM_CSS_RULE_LIST(g_object_new(WEBKIT_DOM_TYPE_CSS_RULE_LIST, "core-object", coreObject, nullptr));
62 }
63
64 } // namespace WebKit
65
66 G_DEFINE_TYPE(WebKitDOMCSSRuleList, webkit_dom_css_rule_list, WEBKIT_DOM_TYPE_OBJECT)
67
68 enum {
69     PROP_0,
70     PROP_LENGTH,
71 };
72
73 static void webkit_dom_css_rule_list_finalize(GObject* object)
74 {
75     WebKitDOMCSSRuleListPrivate* priv = WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(object);
76
77     WebKit::DOMObjectCache::forget(priv->coreObject.get());
78
79     priv->~WebKitDOMCSSRuleListPrivate();
80     G_OBJECT_CLASS(webkit_dom_css_rule_list_parent_class)->finalize(object);
81 }
82
83 static void webkit_dom_css_rule_list_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
84 {
85     WebKitDOMCSSRuleList* self = WEBKIT_DOM_CSS_RULE_LIST(object);
86
87     switch (propertyId) {
88     case PROP_LENGTH:
89         g_value_set_ulong(value, webkit_dom_css_rule_list_get_length(self));
90         break;
91     default:
92         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
93         break;
94     }
95 }
96
97 static GObject* webkit_dom_css_rule_list_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
98 {
99     GObject* object = G_OBJECT_CLASS(webkit_dom_css_rule_list_parent_class)->constructor(type, constructPropertiesCount, constructProperties);
100
101     WebKitDOMCSSRuleListPrivate* priv = WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(object);
102     priv->coreObject = static_cast<WebCore::CSSRuleList*>(WEBKIT_DOM_OBJECT(object)->coreObject);
103     WebKit::DOMObjectCache::put(priv->coreObject.get(), object);
104
105     return object;
106 }
107
108 static void webkit_dom_css_rule_list_class_init(WebKitDOMCSSRuleListClass* requestClass)
109 {
110     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
111     g_type_class_add_private(gobjectClass, sizeof(WebKitDOMCSSRuleListPrivate));
112     gobjectClass->constructor = webkit_dom_css_rule_list_constructor;
113     gobjectClass->finalize = webkit_dom_css_rule_list_finalize;
114     gobjectClass->get_property = webkit_dom_css_rule_list_get_property;
115
116     g_object_class_install_property(
117         gobjectClass,
118         PROP_LENGTH,
119         g_param_spec_ulong(
120             "length",
121             "CSSRuleList:length",
122             "read-only gulong CSSRuleList:length",
123             0, G_MAXULONG, 0,
124             WEBKIT_PARAM_READABLE));
125
126 }
127
128 static void webkit_dom_css_rule_list_init(WebKitDOMCSSRuleList* request)
129 {
130     WebKitDOMCSSRuleListPrivate* priv = WEBKIT_DOM_CSS_RULE_LIST_GET_PRIVATE(request);
131     new (priv) WebKitDOMCSSRuleListPrivate();
132 }
133
134 WebKitDOMCSSRule* webkit_dom_css_rule_list_item(WebKitDOMCSSRuleList* self, gulong index)
135 {
136     WebCore::JSMainThreadNullState state;
137     g_return_val_if_fail(WEBKIT_DOM_IS_CSS_RULE_LIST(self), 0);
138     WebCore::CSSRuleList* item = WebKit::core(self);
139     RefPtr<WebCore::CSSRule> gobjectResult = WTF::getPtr(item->item(index));
140     return WebKit::kit(gobjectResult.get());
141 }
142
143 gulong webkit_dom_css_rule_list_get_length(WebKitDOMCSSRuleList* self)
144 {
145     WebCore::JSMainThreadNullState state;
146     g_return_val_if_fail(WEBKIT_DOM_IS_CSS_RULE_LIST(self), 0);
147     WebCore::CSSRuleList* item = WebKit::core(self);
148     gulong result = item->length();
149     return result;
150 }
151