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