Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMNode.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 "WebKitDOMNode.h"
22
23 #include "ConvertToUTF8String.h"
24 #include "DOMObjectCache.h"
25 #include "GObjectEventListener.h"
26 #include "WebKitDOMDocumentPrivate.h"
27 #include "WebKitDOMElementPrivate.h"
28 #include "WebKitDOMEventPrivate.h"
29 #include "WebKitDOMEventTarget.h"
30 #include "WebKitDOMNodeListPrivate.h"
31 #include "WebKitDOMNodePrivate.h"
32 #include "WebKitDOMPrivate.h"
33 #include <WebCore/CSSImportRule.h>
34 #include <WebCore/DOMException.h>
35 #include <WebCore/Document.h>
36 #include <WebCore/JSMainThreadExecState.h>
37 #include <WebCore/SVGTests.h>
38 #include <wtf/GetPtr.h>
39 #include <wtf/RefPtr.h>
40
41 #define WEBKIT_DOM_NODE_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_NODE, WebKitDOMNodePrivate)
42
43 typedef struct _WebKitDOMNodePrivate {
44     RefPtr<WebCore::Node> coreObject;
45 } WebKitDOMNodePrivate;
46
47 namespace WebKit {
48
49 WebKitDOMNode* kit(WebCore::Node* obj)
50 {
51     if (!obj)
52         return 0;
53
54     if (gpointer ret = DOMObjectCache::get(obj))
55         return WEBKIT_DOM_NODE(ret);
56
57     return wrap(obj);
58 }
59
60 WebCore::Node* core(WebKitDOMNode* request)
61 {
62     return request ? static_cast<WebCore::Node*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
63 }
64
65 WebKitDOMNode* wrapNode(WebCore::Node* coreObject)
66 {
67     ASSERT(coreObject);
68     return WEBKIT_DOM_NODE(g_object_new(WEBKIT_DOM_TYPE_NODE, "core-object", coreObject, nullptr));
69 }
70
71 }
72
73 static gboolean webkit_dom_node_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
74 {
75     WebCore::Event* coreEvent = WebKit::core(event);
76     if (!coreEvent)
77         return false;
78     WebCore::Node* coreTarget = static_cast<WebCore::Node*>(WEBKIT_DOM_OBJECT(target)->coreObject);
79
80     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
81     if (result.hasException()) {
82         auto description = WebCore::DOMException::description(result.releaseException().code());
83         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
84         return false;
85     }
86     return result.releaseReturnValue();
87 }
88
89 static gboolean webkit_dom_node_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
90 {
91     WebCore::Node* coreTarget = static_cast<WebCore::Node*>(WEBKIT_DOM_OBJECT(target)->coreObject);
92     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
93 }
94
95 static gboolean webkit_dom_node_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
96 {
97     WebCore::Node* coreTarget = static_cast<WebCore::Node*>(WEBKIT_DOM_OBJECT(target)->coreObject);
98     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
99 }
100
101 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
102 {
103     iface->dispatch_event = webkit_dom_node_dispatch_event;
104     iface->add_event_listener = webkit_dom_node_add_event_listener;
105     iface->remove_event_listener = webkit_dom_node_remove_event_listener;
106 }
107
108 G_DEFINE_TYPE_WITH_CODE(WebKitDOMNode, webkit_dom_node, WEBKIT_DOM_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
109
110 enum {
111     PROP_0,
112     PROP_NODE_NAME,
113     PROP_NODE_VALUE,
114     PROP_NODE_TYPE,
115     PROP_PARENT_NODE,
116     PROP_CHILD_NODES,
117     PROP_FIRST_CHILD,
118     PROP_LAST_CHILD,
119     PROP_PREVIOUS_SIBLING,
120     PROP_NEXT_SIBLING,
121     PROP_OWNER_DOCUMENT,
122     PROP_BASE_URI,
123     PROP_TEXT_CONTENT,
124     PROP_PARENT_ELEMENT,
125 };
126
127 static void webkit_dom_node_finalize(GObject* object)
128 {
129     WebKitDOMNodePrivate* priv = WEBKIT_DOM_NODE_GET_PRIVATE(object);
130
131     WebKit::DOMObjectCache::forget(priv->coreObject.get());
132
133     priv->~WebKitDOMNodePrivate();
134     G_OBJECT_CLASS(webkit_dom_node_parent_class)->finalize(object);
135 }
136
137 static void webkit_dom_node_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
138 {
139     WebKitDOMNode* self = WEBKIT_DOM_NODE(object);
140
141     switch (propertyId) {
142     case PROP_NODE_VALUE:
143         webkit_dom_node_set_node_value(self, g_value_get_string(value), nullptr);
144         break;
145     case PROP_TEXT_CONTENT:
146         webkit_dom_node_set_text_content(self, g_value_get_string(value), nullptr);
147         break;
148     default:
149         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
150         break;
151     }
152 }
153
154 static void webkit_dom_node_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
155 {
156     WebKitDOMNode* self = WEBKIT_DOM_NODE(object);
157
158     switch (propertyId) {
159     case PROP_NODE_NAME:
160         g_value_take_string(value, webkit_dom_node_get_node_name(self));
161         break;
162     case PROP_NODE_VALUE:
163         g_value_take_string(value, webkit_dom_node_get_node_value(self));
164         break;
165     case PROP_NODE_TYPE:
166         g_value_set_uint(value, webkit_dom_node_get_node_type(self));
167         break;
168     case PROP_PARENT_NODE:
169         g_value_set_object(value, webkit_dom_node_get_parent_node(self));
170         break;
171     case PROP_CHILD_NODES:
172         g_value_set_object(value, webkit_dom_node_get_child_nodes(self));
173         break;
174     case PROP_FIRST_CHILD:
175         g_value_set_object(value, webkit_dom_node_get_first_child(self));
176         break;
177     case PROP_LAST_CHILD:
178         g_value_set_object(value, webkit_dom_node_get_last_child(self));
179         break;
180     case PROP_PREVIOUS_SIBLING:
181         g_value_set_object(value, webkit_dom_node_get_previous_sibling(self));
182         break;
183     case PROP_NEXT_SIBLING:
184         g_value_set_object(value, webkit_dom_node_get_next_sibling(self));
185         break;
186     case PROP_OWNER_DOCUMENT:
187         g_value_set_object(value, webkit_dom_node_get_owner_document(self));
188         break;
189     case PROP_BASE_URI:
190         g_value_take_string(value, webkit_dom_node_get_base_uri(self));
191         break;
192     case PROP_TEXT_CONTENT:
193         g_value_take_string(value, webkit_dom_node_get_text_content(self));
194         break;
195     case PROP_PARENT_ELEMENT:
196         g_value_set_object(value, webkit_dom_node_get_parent_element(self));
197         break;
198     default:
199         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
200         break;
201     }
202 }
203
204 static GObject* webkit_dom_node_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
205 {
206     GObject* object = G_OBJECT_CLASS(webkit_dom_node_parent_class)->constructor(type, constructPropertiesCount, constructProperties);
207
208     WebKitDOMNodePrivate* priv = WEBKIT_DOM_NODE_GET_PRIVATE(object);
209     priv->coreObject = static_cast<WebCore::Node*>(WEBKIT_DOM_OBJECT(object)->coreObject);
210     WebKit::DOMObjectCache::put(priv->coreObject.get(), object);
211
212     return object;
213 }
214
215 static void webkit_dom_node_class_init(WebKitDOMNodeClass* requestClass)
216 {
217     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
218     g_type_class_add_private(gobjectClass, sizeof(WebKitDOMNodePrivate));
219     gobjectClass->constructor = webkit_dom_node_constructor;
220     gobjectClass->finalize = webkit_dom_node_finalize;
221     gobjectClass->set_property = webkit_dom_node_set_property;
222     gobjectClass->get_property = webkit_dom_node_get_property;
223
224     g_object_class_install_property(
225         gobjectClass,
226         PROP_NODE_NAME,
227         g_param_spec_string(
228             "node-name",
229             "Node:node-name",
230             "read-only gchar* Node:node-name",
231             "",
232             WEBKIT_PARAM_READABLE));
233
234     g_object_class_install_property(
235         gobjectClass,
236         PROP_NODE_VALUE,
237         g_param_spec_string(
238             "node-value",
239             "Node:node-value",
240             "read-write gchar* Node:node-value",
241             "",
242             WEBKIT_PARAM_READWRITE));
243
244     g_object_class_install_property(
245         gobjectClass,
246         PROP_NODE_TYPE,
247         g_param_spec_uint(
248             "node-type",
249             "Node:node-type",
250             "read-only gushort Node:node-type",
251             0, G_MAXUINT, 0,
252             WEBKIT_PARAM_READABLE));
253
254     g_object_class_install_property(
255         gobjectClass,
256         PROP_PARENT_NODE,
257         g_param_spec_object(
258             "parent-node",
259             "Node:parent-node",
260             "read-only WebKitDOMNode* Node:parent-node",
261             WEBKIT_DOM_TYPE_NODE,
262             WEBKIT_PARAM_READABLE));
263
264     g_object_class_install_property(
265         gobjectClass,
266         PROP_CHILD_NODES,
267         g_param_spec_object(
268             "child-nodes",
269             "Node:child-nodes",
270             "read-only WebKitDOMNodeList* Node:child-nodes",
271             WEBKIT_DOM_TYPE_NODE_LIST,
272             WEBKIT_PARAM_READABLE));
273
274     g_object_class_install_property(
275         gobjectClass,
276         PROP_FIRST_CHILD,
277         g_param_spec_object(
278             "first-child",
279             "Node:first-child",
280             "read-only WebKitDOMNode* Node:first-child",
281             WEBKIT_DOM_TYPE_NODE,
282             WEBKIT_PARAM_READABLE));
283
284     g_object_class_install_property(
285         gobjectClass,
286         PROP_LAST_CHILD,
287         g_param_spec_object(
288             "last-child",
289             "Node:last-child",
290             "read-only WebKitDOMNode* Node:last-child",
291             WEBKIT_DOM_TYPE_NODE,
292             WEBKIT_PARAM_READABLE));
293
294     g_object_class_install_property(
295         gobjectClass,
296         PROP_PREVIOUS_SIBLING,
297         g_param_spec_object(
298             "previous-sibling",
299             "Node:previous-sibling",
300             "read-only WebKitDOMNode* Node:previous-sibling",
301             WEBKIT_DOM_TYPE_NODE,
302             WEBKIT_PARAM_READABLE));
303
304     g_object_class_install_property(
305         gobjectClass,
306         PROP_NEXT_SIBLING,
307         g_param_spec_object(
308             "next-sibling",
309             "Node:next-sibling",
310             "read-only WebKitDOMNode* Node:next-sibling",
311             WEBKIT_DOM_TYPE_NODE,
312             WEBKIT_PARAM_READABLE));
313
314     g_object_class_install_property(
315         gobjectClass,
316         PROP_OWNER_DOCUMENT,
317         g_param_spec_object(
318             "owner-document",
319             "Node:owner-document",
320             "read-only WebKitDOMDocument* Node:owner-document",
321             WEBKIT_DOM_TYPE_DOCUMENT,
322             WEBKIT_PARAM_READABLE));
323
324     g_object_class_install_property(
325         gobjectClass,
326         PROP_BASE_URI,
327         g_param_spec_string(
328             "base-uri",
329             "Node:base-uri",
330             "read-only gchar* Node:base-uri",
331             "",
332             WEBKIT_PARAM_READABLE));
333
334     g_object_class_install_property(
335         gobjectClass,
336         PROP_TEXT_CONTENT,
337         g_param_spec_string(
338             "text-content",
339             "Node:text-content",
340             "read-write gchar* Node:text-content",
341             "",
342             WEBKIT_PARAM_READWRITE));
343
344     g_object_class_install_property(
345         gobjectClass,
346         PROP_PARENT_ELEMENT,
347         g_param_spec_object(
348             "parent-element",
349             "Node:parent-element",
350             "read-only WebKitDOMElement* Node:parent-element",
351             WEBKIT_DOM_TYPE_ELEMENT,
352             WEBKIT_PARAM_READABLE));
353
354 }
355
356 static void webkit_dom_node_init(WebKitDOMNode* request)
357 {
358     WebKitDOMNodePrivate* priv = WEBKIT_DOM_NODE_GET_PRIVATE(request);
359     new (priv) WebKitDOMNodePrivate();
360 }
361
362 WebKitDOMNode* webkit_dom_node_insert_before(WebKitDOMNode* self, WebKitDOMNode* newChild, WebKitDOMNode* refChild, GError** error)
363 {
364     WebCore::JSMainThreadNullState state;
365     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
366     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(newChild), 0);
367     g_return_val_if_fail(!refChild || WEBKIT_DOM_IS_NODE(refChild), 0);
368     g_return_val_if_fail(!error || !*error, 0);
369     WebCore::Node* item = WebKit::core(self);
370     WebCore::Node* convertedNewChild = WebKit::core(newChild);
371     WebCore::Node* convertedRefChild = WebKit::core(refChild);
372     auto result = item->insertBefore(*convertedNewChild, convertedRefChild);
373     if (result.hasException()) {
374         auto description = WebCore::DOMException::description(result.releaseException().code());
375         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
376         return nullptr;
377     }
378     return newChild;
379 }
380
381 WebKitDOMNode* webkit_dom_node_replace_child(WebKitDOMNode* self, WebKitDOMNode* newChild, WebKitDOMNode* oldChild, GError** error)
382 {
383     WebCore::JSMainThreadNullState state;
384     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
385     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(newChild), 0);
386     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(oldChild), 0);
387     g_return_val_if_fail(!error || !*error, 0);
388     WebCore::Node* item = WebKit::core(self);
389     WebCore::Node* convertedNewChild = WebKit::core(newChild);
390     WebCore::Node* convertedOldChild = WebKit::core(oldChild);
391     auto result = item->replaceChild(*convertedNewChild, *convertedOldChild);
392     if (result.hasException()) {
393         auto description = WebCore::DOMException::description(result.releaseException().code());
394         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
395         return nullptr;
396     }
397     return oldChild;
398 }
399
400 WebKitDOMNode* webkit_dom_node_remove_child(WebKitDOMNode* self, WebKitDOMNode* oldChild, GError** error)
401 {
402     WebCore::JSMainThreadNullState state;
403     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
404     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(oldChild), 0);
405     g_return_val_if_fail(!error || !*error, 0);
406     WebCore::Node* item = WebKit::core(self);
407     WebCore::Node* convertedOldChild = WebKit::core(oldChild);
408     auto result = item->removeChild(*convertedOldChild);
409     if (result.hasException()) {
410         auto description = WebCore::DOMException::description(result.releaseException().code());
411         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
412         return nullptr;
413     }
414     return oldChild;
415 }
416
417 WebKitDOMNode* webkit_dom_node_append_child(WebKitDOMNode* self, WebKitDOMNode* newChild, GError** error)
418 {
419     WebCore::JSMainThreadNullState state;
420     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
421     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(newChild), 0);
422     g_return_val_if_fail(!error || !*error, 0);
423     WebCore::Node* item = WebKit::core(self);
424     WebCore::Node* convertedNewChild = WebKit::core(newChild);
425     auto result = item->appendChild(*convertedNewChild);
426     if (result.hasException()) {
427         auto description = WebCore::DOMException::description(result.releaseException().code());
428         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
429         return nullptr;
430     }
431     return newChild;
432 }
433
434 gboolean webkit_dom_node_has_child_nodes(WebKitDOMNode* self)
435 {
436     WebCore::JSMainThreadNullState state;
437     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), FALSE);
438     WebCore::Node* item = WebKit::core(self);
439     gboolean result = item->hasChildNodes();
440     return result;
441 }
442
443 WebKitDOMNode* webkit_dom_node_clone_node_with_error(WebKitDOMNode* self, gboolean deep, GError** error)
444 {
445     WebCore::JSMainThreadNullState state;
446     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
447     g_return_val_if_fail(!error || !*error, 0);
448     WebCore::Node* item = WebKit::core(self);
449     auto result = item->cloneNodeForBindings(deep);
450     if (result.hasException()) {
451         auto description = WebCore::DOMException::description(result.releaseException().code());
452         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
453         return nullptr;
454     }
455     return WebKit::kit(result.releaseReturnValue().ptr());
456 }
457
458 void webkit_dom_node_normalize(WebKitDOMNode* self)
459 {
460     WebCore::JSMainThreadNullState state;
461     g_return_if_fail(WEBKIT_DOM_IS_NODE(self));
462     WebCore::Node* item = WebKit::core(self);
463     item->normalize();
464 }
465
466 gboolean webkit_dom_node_is_supported(WebKitDOMNode* self, const gchar* feature, const gchar* version)
467 {
468     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), FALSE);
469     g_return_val_if_fail(feature, FALSE);
470     g_return_val_if_fail(version, FALSE);
471     WTF::String convertedFeature = WTF::String::fromUTF8(feature);
472     WTF::String convertedVersion = WTF::String::fromUTF8(version);
473     return WebCore::SVGTests::hasFeatureForLegacyBindings(convertedFeature, convertedVersion);
474 }
475
476 gboolean webkit_dom_node_is_same_node(WebKitDOMNode* self, WebKitDOMNode* other)
477 {
478     WebCore::JSMainThreadNullState state;
479     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), FALSE);
480     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(other), FALSE);
481     WebCore::Node* item = WebKit::core(self);
482     WebCore::Node* convertedOther = WebKit::core(other);
483     gboolean result = item->isSameNode(convertedOther);
484     return result;
485 }
486
487 gboolean webkit_dom_node_is_equal_node(WebKitDOMNode* self, WebKitDOMNode* other)
488 {
489     WebCore::JSMainThreadNullState state;
490     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), FALSE);
491     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(other), FALSE);
492     WebCore::Node* item = WebKit::core(self);
493     WebCore::Node* convertedOther = WebKit::core(other);
494     gboolean result = item->isEqualNode(convertedOther);
495     return result;
496 }
497
498 gchar* webkit_dom_node_lookup_prefix(WebKitDOMNode* self, const gchar* namespaceURI)
499 {
500     WebCore::JSMainThreadNullState state;
501     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
502     g_return_val_if_fail(namespaceURI, 0);
503     WebCore::Node* item = WebKit::core(self);
504     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
505     gchar* result = convertToUTF8String(item->lookupPrefix(convertedNamespaceURI));
506     return result;
507 }
508
509 gchar* webkit_dom_node_lookup_namespace_uri(WebKitDOMNode* self, const gchar* prefix)
510 {
511     WebCore::JSMainThreadNullState state;
512     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
513     g_return_val_if_fail(prefix, 0);
514     WebCore::Node* item = WebKit::core(self);
515     WTF::String convertedPrefix = WTF::String::fromUTF8(prefix);
516     gchar* result = convertToUTF8String(item->lookupNamespaceURI(convertedPrefix));
517     return result;
518 }
519
520 gboolean webkit_dom_node_is_default_namespace(WebKitDOMNode* self, const gchar* namespaceURI)
521 {
522     WebCore::JSMainThreadNullState state;
523     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), FALSE);
524     g_return_val_if_fail(namespaceURI, FALSE);
525     WebCore::Node* item = WebKit::core(self);
526     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
527     gboolean result = item->isDefaultNamespace(convertedNamespaceURI);
528     return result;
529 }
530
531 gushort webkit_dom_node_compare_document_position(WebKitDOMNode* self, WebKitDOMNode* other)
532 {
533     WebCore::JSMainThreadNullState state;
534     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
535     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(other), 0);
536     WebCore::Node* item = WebKit::core(self);
537     WebCore::Node* convertedOther = WebKit::core(other);
538     gushort result = item->compareDocumentPosition(*convertedOther);
539     return result;
540 }
541
542 gboolean webkit_dom_node_contains(WebKitDOMNode* self, WebKitDOMNode* other)
543 {
544     WebCore::JSMainThreadNullState state;
545     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), FALSE);
546     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(other), FALSE);
547     WebCore::Node* item = WebKit::core(self);
548     WebCore::Node* convertedOther = WebKit::core(other);
549     gboolean result = item->contains(convertedOther);
550     return result;
551 }
552
553 gchar* webkit_dom_node_get_node_name(WebKitDOMNode* self)
554 {
555     WebCore::JSMainThreadNullState state;
556     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
557     WebCore::Node* item = WebKit::core(self);
558     gchar* result = convertToUTF8String(item->nodeName());
559     return result;
560 }
561
562 gchar* webkit_dom_node_get_node_value(WebKitDOMNode* self)
563 {
564     WebCore::JSMainThreadNullState state;
565     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
566     WebCore::Node* item = WebKit::core(self);
567     gchar* result = convertToUTF8String(item->nodeValue());
568     return result;
569 }
570
571 void webkit_dom_node_set_node_value(WebKitDOMNode* self, const gchar* value, GError** error)
572 {
573     WebCore::JSMainThreadNullState state;
574     g_return_if_fail(WEBKIT_DOM_IS_NODE(self));
575     g_return_if_fail(value);
576     g_return_if_fail(!error || !*error);
577     WebCore::Node* item = WebKit::core(self);
578     WTF::String convertedValue = WTF::String::fromUTF8(value);
579     auto result = item->setNodeValue(convertedValue);
580     if (result.hasException()) {
581         auto description = WebCore::DOMException::description(result.releaseException().code());
582         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
583     }
584 }
585
586 gushort webkit_dom_node_get_node_type(WebKitDOMNode* self)
587 {
588     WebCore::JSMainThreadNullState state;
589     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
590     WebCore::Node* item = WebKit::core(self);
591     gushort result = item->nodeType();
592     return result;
593 }
594
595 WebKitDOMNode* webkit_dom_node_get_parent_node(WebKitDOMNode* self)
596 {
597     WebCore::JSMainThreadNullState state;
598     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
599     WebCore::Node* item = WebKit::core(self);
600     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->parentNode());
601     return WebKit::kit(gobjectResult.get());
602 }
603
604 WebKitDOMNodeList* webkit_dom_node_get_child_nodes(WebKitDOMNode* self)
605 {
606     WebCore::JSMainThreadNullState state;
607     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
608     WebCore::Node* item = WebKit::core(self);
609     RefPtr<WebCore::NodeList> gobjectResult = WTF::getPtr(item->childNodes());
610     return WebKit::kit(gobjectResult.get());
611 }
612
613 WebKitDOMNode* webkit_dom_node_get_first_child(WebKitDOMNode* self)
614 {
615     WebCore::JSMainThreadNullState state;
616     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
617     WebCore::Node* item = WebKit::core(self);
618     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->firstChild());
619     return WebKit::kit(gobjectResult.get());
620 }
621
622 WebKitDOMNode* webkit_dom_node_get_last_child(WebKitDOMNode* self)
623 {
624     WebCore::JSMainThreadNullState state;
625     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
626     WebCore::Node* item = WebKit::core(self);
627     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->lastChild());
628     return WebKit::kit(gobjectResult.get());
629 }
630
631 WebKitDOMNode* webkit_dom_node_get_previous_sibling(WebKitDOMNode* self)
632 {
633     WebCore::JSMainThreadNullState state;
634     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
635     WebCore::Node* item = WebKit::core(self);
636     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->previousSibling());
637     return WebKit::kit(gobjectResult.get());
638 }
639
640 WebKitDOMNode* webkit_dom_node_get_next_sibling(WebKitDOMNode* self)
641 {
642     WebCore::JSMainThreadNullState state;
643     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
644     WebCore::Node* item = WebKit::core(self);
645     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->nextSibling());
646     return WebKit::kit(gobjectResult.get());
647 }
648
649 WebKitDOMDocument* webkit_dom_node_get_owner_document(WebKitDOMNode* self)
650 {
651     WebCore::JSMainThreadNullState state;
652     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
653     WebCore::Node* item = WebKit::core(self);
654     RefPtr<WebCore::Document> gobjectResult = WTF::getPtr(item->ownerDocument());
655     return WebKit::kit(gobjectResult.get());
656 }
657
658 gchar* webkit_dom_node_get_base_uri(WebKitDOMNode* self)
659 {
660     WebCore::JSMainThreadNullState state;
661     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
662     WebCore::Node* item = WebKit::core(self);
663     gchar* result = convertToUTF8String(item->baseURI());
664     return result;
665 }
666
667 gchar* webkit_dom_node_get_text_content(WebKitDOMNode* self)
668 {
669     WebCore::JSMainThreadNullState state;
670     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
671     WebCore::Node* item = WebKit::core(self);
672     gchar* result = convertToUTF8String(item->textContent());
673     return result;
674 }
675
676 void webkit_dom_node_set_text_content(WebKitDOMNode* self, const gchar* value, GError** error)
677 {
678     WebCore::JSMainThreadNullState state;
679     g_return_if_fail(WEBKIT_DOM_IS_NODE(self));
680     g_return_if_fail(value);
681     g_return_if_fail(!error || !*error);
682     WebCore::Node* item = WebKit::core(self);
683     WTF::String convertedValue = WTF::String::fromUTF8(value);
684     auto result = item->setTextContent(convertedValue);
685     if (result.hasException()) {
686         auto description = WebCore::DOMException::description(result.releaseException().code());
687         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
688     }
689 }
690
691 WebKitDOMElement* webkit_dom_node_get_parent_element(WebKitDOMNode* self)
692 {
693     WebCore::JSMainThreadNullState state;
694     g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), 0);
695     WebCore::Node* item = WebKit::core(self);
696     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->parentElement());
697     return WebKit::kit(gobjectResult.get());
698 }
699