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