Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLParamElement.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 "WebKitDOMHTMLParamElement.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/DOMException.h>
26 #include <WebCore/Document.h>
27 #include "GObjectEventListener.h"
28 #include <WebCore/HTMLNames.h>
29 #include <WebCore/JSMainThreadExecState.h>
30 #include "WebKitDOMEventPrivate.h"
31 #include "WebKitDOMEventTarget.h"
32 #include "WebKitDOMHTMLParamElementPrivate.h"
33 #include "WebKitDOMNodePrivate.h"
34 #include "WebKitDOMPrivate.h"
35 #include "ConvertToUTF8String.h"
36 #include <wtf/GetPtr.h>
37 #include <wtf/RefPtr.h>
38
39 namespace WebKit {
40
41 WebKitDOMHTMLParamElement* kit(WebCore::HTMLParamElement* obj)
42 {
43     return WEBKIT_DOM_HTML_PARAM_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
44 }
45
46 WebCore::HTMLParamElement* core(WebKitDOMHTMLParamElement* request)
47 {
48     return request ? static_cast<WebCore::HTMLParamElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
49 }
50
51 WebKitDOMHTMLParamElement* wrapHTMLParamElement(WebCore::HTMLParamElement* coreObject)
52 {
53     ASSERT(coreObject);
54     return WEBKIT_DOM_HTML_PARAM_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_PARAM_ELEMENT, "core-object", coreObject, nullptr));
55 }
56
57 } // namespace WebKit
58
59 static gboolean webkit_dom_html_param_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
60 {
61     WebCore::Event* coreEvent = WebKit::core(event);
62     if (!coreEvent)
63         return false;
64     WebCore::HTMLParamElement* coreTarget = static_cast<WebCore::HTMLParamElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
65
66     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
67     if (result.hasException()) {
68         auto description = WebCore::DOMException::description(result.releaseException().code());
69         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
70         return false;
71     }
72     return result.releaseReturnValue();
73 }
74
75 static gboolean webkit_dom_html_param_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
76 {
77     WebCore::HTMLParamElement* coreTarget = static_cast<WebCore::HTMLParamElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
78     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
79 }
80
81 static gboolean webkit_dom_html_param_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
82 {
83     WebCore::HTMLParamElement* coreTarget = static_cast<WebCore::HTMLParamElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
84     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
85 }
86
87 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
88 {
89     iface->dispatch_event = webkit_dom_html_param_element_dispatch_event;
90     iface->add_event_listener = webkit_dom_html_param_element_add_event_listener;
91     iface->remove_event_listener = webkit_dom_html_param_element_remove_event_listener;
92 }
93
94 G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLParamElement, webkit_dom_html_param_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
95
96 enum {
97     PROP_0,
98     PROP_NAME,
99     PROP_TYPE,
100     PROP_VALUE,
101     PROP_VALUE_TYPE,
102 };
103
104 static void webkit_dom_html_param_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
105 {
106     WebKitDOMHTMLParamElement* self = WEBKIT_DOM_HTML_PARAM_ELEMENT(object);
107
108     switch (propertyId) {
109     case PROP_NAME:
110         webkit_dom_html_param_element_set_name(self, g_value_get_string(value));
111         break;
112     case PROP_TYPE:
113         webkit_dom_html_param_element_set_type_attr(self, g_value_get_string(value));
114         break;
115     case PROP_VALUE:
116         webkit_dom_html_param_element_set_value(self, g_value_get_string(value));
117         break;
118     case PROP_VALUE_TYPE:
119         webkit_dom_html_param_element_set_value_type(self, g_value_get_string(value));
120         break;
121     default:
122         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
123         break;
124     }
125 }
126
127 static void webkit_dom_html_param_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
128 {
129     WebKitDOMHTMLParamElement* self = WEBKIT_DOM_HTML_PARAM_ELEMENT(object);
130
131     switch (propertyId) {
132     case PROP_NAME:
133         g_value_take_string(value, webkit_dom_html_param_element_get_name(self));
134         break;
135     case PROP_TYPE:
136         g_value_take_string(value, webkit_dom_html_param_element_get_type_attr(self));
137         break;
138     case PROP_VALUE:
139         g_value_take_string(value, webkit_dom_html_param_element_get_value(self));
140         break;
141     case PROP_VALUE_TYPE:
142         g_value_take_string(value, webkit_dom_html_param_element_get_value_type(self));
143         break;
144     default:
145         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
146         break;
147     }
148 }
149
150 static void webkit_dom_html_param_element_class_init(WebKitDOMHTMLParamElementClass* requestClass)
151 {
152     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
153     gobjectClass->set_property = webkit_dom_html_param_element_set_property;
154     gobjectClass->get_property = webkit_dom_html_param_element_get_property;
155
156     g_object_class_install_property(
157         gobjectClass,
158         PROP_NAME,
159         g_param_spec_string(
160             "name",
161             "HTMLParamElement:name",
162             "read-write gchar* HTMLParamElement:name",
163             "",
164             WEBKIT_PARAM_READWRITE));
165
166     g_object_class_install_property(
167         gobjectClass,
168         PROP_TYPE,
169         g_param_spec_string(
170             "type",
171             "HTMLParamElement:type",
172             "read-write gchar* HTMLParamElement:type",
173             "",
174             WEBKIT_PARAM_READWRITE));
175
176     g_object_class_install_property(
177         gobjectClass,
178         PROP_VALUE,
179         g_param_spec_string(
180             "value",
181             "HTMLParamElement:value",
182             "read-write gchar* HTMLParamElement:value",
183             "",
184             WEBKIT_PARAM_READWRITE));
185
186     g_object_class_install_property(
187         gobjectClass,
188         PROP_VALUE_TYPE,
189         g_param_spec_string(
190             "value-type",
191             "HTMLParamElement:value-type",
192             "read-write gchar* HTMLParamElement:value-type",
193             "",
194             WEBKIT_PARAM_READWRITE));
195
196 }
197
198 static void webkit_dom_html_param_element_init(WebKitDOMHTMLParamElement* request)
199 {
200     UNUSED_PARAM(request);
201 }
202
203 gchar* webkit_dom_html_param_element_get_name(WebKitDOMHTMLParamElement* self)
204 {
205     WebCore::JSMainThreadNullState state;
206     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self), 0);
207     WebCore::HTMLParamElement* item = WebKit::core(self);
208     gchar* result = convertToUTF8String(item->getNameAttribute());
209     return result;
210 }
211
212 void webkit_dom_html_param_element_set_name(WebKitDOMHTMLParamElement* self, const gchar* value)
213 {
214     WebCore::JSMainThreadNullState state;
215     g_return_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self));
216     g_return_if_fail(value);
217     WebCore::HTMLParamElement* item = WebKit::core(self);
218     WTF::String convertedValue = WTF::String::fromUTF8(value);
219     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::nameAttr, convertedValue);
220 }
221
222 gchar* webkit_dom_html_param_element_get_type_attr(WebKitDOMHTMLParamElement* self)
223 {
224     WebCore::JSMainThreadNullState state;
225     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self), 0);
226     WebCore::HTMLParamElement* item = WebKit::core(self);
227     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::typeAttr));
228     return result;
229 }
230
231 void webkit_dom_html_param_element_set_type_attr(WebKitDOMHTMLParamElement* self, const gchar* value)
232 {
233     WebCore::JSMainThreadNullState state;
234     g_return_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self));
235     g_return_if_fail(value);
236     WebCore::HTMLParamElement* item = WebKit::core(self);
237     WTF::String convertedValue = WTF::String::fromUTF8(value);
238     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::typeAttr, convertedValue);
239 }
240
241 gchar* webkit_dom_html_param_element_get_value(WebKitDOMHTMLParamElement* self)
242 {
243     WebCore::JSMainThreadNullState state;
244     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self), 0);
245     WebCore::HTMLParamElement* item = WebKit::core(self);
246     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::valueAttr));
247     return result;
248 }
249
250 void webkit_dom_html_param_element_set_value(WebKitDOMHTMLParamElement* self, const gchar* value)
251 {
252     WebCore::JSMainThreadNullState state;
253     g_return_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self));
254     g_return_if_fail(value);
255     WebCore::HTMLParamElement* item = WebKit::core(self);
256     WTF::String convertedValue = WTF::String::fromUTF8(value);
257     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::valueAttr, convertedValue);
258 }
259
260 gchar* webkit_dom_html_param_element_get_value_type(WebKitDOMHTMLParamElement* self)
261 {
262     WebCore::JSMainThreadNullState state;
263     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self), 0);
264     WebCore::HTMLParamElement* item = WebKit::core(self);
265     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::valuetypeAttr));
266     return result;
267 }
268
269 void webkit_dom_html_param_element_set_value_type(WebKitDOMHTMLParamElement* self, const gchar* value)
270 {
271     WebCore::JSMainThreadNullState state;
272     g_return_if_fail(WEBKIT_DOM_IS_HTML_PARAM_ELEMENT(self));
273     g_return_if_fail(value);
274     WebCore::HTMLParamElement* item = WebKit::core(self);
275     WTF::String convertedValue = WTF::String::fromUTF8(value);
276     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::valuetypeAttr, convertedValue);
277 }
278