1 | /* |
2 | * Copyright (C) 2014 Igalia S.L. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser 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 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #include "config.h" |
20 | #include "WebKitDOMDeprecated.h" |
21 | |
22 | #include "ConvertToUTF8String.h" |
23 | #include <WebCore/DOMException.h> |
24 | #include <WebCore/Document.h> |
25 | #include <WebCore/Element.h> |
26 | #include <WebCore/JSExecState.h> |
27 | #include <WebCore/HTMLCollection.h> |
28 | #include "WebKitDOMDocumentPrivate.h" |
29 | #include "WebKitDOMElementPrivate.h" |
30 | #include "WebKitDOMHTMLDocumentPrivate.h" |
31 | #include "WebKitDOMHTMLInputElementPrivate.h" |
32 | #include "WebKitDOMHTMLTitleElement.h" |
33 | #include "WebKitDOMNodeListPrivate.h" |
34 | #include "WebKitDOMNodePrivate.h" |
35 | #include "WebKitDOMPrivate.h" |
36 | #include "WebKitDOMTextPrivate.h" |
37 | #include <wtf/GetPtr.h> |
38 | #include <wtf/RefPtr.h> |
39 | #include <wtf/text/WTFString.h> |
40 | |
41 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
42 | |
43 | gchar* webkit_dom_html_element_get_inner_html(WebKitDOMHTMLElement* self) |
44 | { |
45 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self), nullptr); |
46 | return webkit_dom_element_get_inner_html(WEBKIT_DOM_ELEMENT(self)); |
47 | } |
48 | |
49 | void webkit_dom_html_element_set_inner_html(WebKitDOMHTMLElement* self, const gchar* contents, GError** error) |
50 | { |
51 | g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self)); |
52 | webkit_dom_element_set_inner_html(WEBKIT_DOM_ELEMENT(self), contents, error); |
53 | } |
54 | |
55 | gchar* webkit_dom_html_element_get_outer_html(WebKitDOMHTMLElement* self) |
56 | { |
57 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self), nullptr); |
58 | return webkit_dom_element_get_outer_html(WEBKIT_DOM_ELEMENT(self)); |
59 | } |
60 | |
61 | void webkit_dom_html_element_set_outer_html(WebKitDOMHTMLElement* self, const gchar* contents, GError** error) |
62 | { |
63 | g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self)); |
64 | webkit_dom_element_set_outer_html(WEBKIT_DOM_ELEMENT(self), contents, error); |
65 | } |
66 | |
67 | WebKitDOMHTMLCollection* webkit_dom_html_element_get_children(WebKitDOMHTMLElement* self) |
68 | { |
69 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self), nullptr); |
70 | return webkit_dom_element_get_children(WEBKIT_DOM_ELEMENT(self)); |
71 | } |
72 | |
73 | WebKitDOMNodeList* webkit_dom_document_get_elements_by_tag_name(WebKitDOMDocument* self, const gchar* tagName) |
74 | { |
75 | g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT(self), nullptr); |
76 | g_return_val_if_fail(tagName, nullptr); |
77 | |
78 | WebCore::JSMainThreadNullState state; |
79 | WebCore::Document* document = WebKit::core(self); |
80 | RefPtr<WebCore::NodeList> nodeList = WTF::getPtr(document->getElementsByTagName(String::fromUTF8(tagName))); |
81 | return WebKit::kit(nodeList.get()); |
82 | } |
83 | |
84 | WebKitDOMNodeList* webkit_dom_document_get_elements_by_tag_name_ns(WebKitDOMDocument* self, const gchar* namespaceURI, const gchar* tagName) |
85 | { |
86 | g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT(self), nullptr); |
87 | g_return_val_if_fail(namespaceURI, nullptr); |
88 | g_return_val_if_fail(tagName, nullptr); |
89 | |
90 | WebCore::JSMainThreadNullState state; |
91 | WebCore::Document* document = WebKit::core(self); |
92 | RefPtr<WebCore::NodeList> nodeList = WTF::getPtr(document->getElementsByTagNameNS(String::fromUTF8(namespaceURI), String::fromUTF8(tagName))); |
93 | return WebKit::kit(nodeList.get()); |
94 | } |
95 | |
96 | WebKitDOMNodeList* webkit_dom_document_get_elements_by_class_name(WebKitDOMDocument* self, const gchar* className) |
97 | { |
98 | g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT(self), nullptr); |
99 | g_return_val_if_fail(className, nullptr); |
100 | |
101 | WebCore::JSMainThreadNullState state; |
102 | WebCore::Document* document = WebKit::core(self); |
103 | RefPtr<WebCore::NodeList> nodeList = WTF::getPtr(document->getElementsByClassName(String::fromUTF8(className))); |
104 | return WebKit::kit(nodeList.get()); |
105 | } |
106 | |
107 | WebKitDOMNodeList* webkit_dom_element_get_elements_by_tag_name(WebKitDOMElement* self, const gchar* tagName) |
108 | { |
109 | g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), nullptr); |
110 | g_return_val_if_fail(tagName, nullptr); |
111 | |
112 | WebCore::JSMainThreadNullState state; |
113 | WebCore::Element* element = WebKit::core(self); |
114 | RefPtr<WebCore::NodeList> nodeList = WTF::getPtr(element->getElementsByTagName(String::fromUTF8(tagName))); |
115 | return WebKit::kit(nodeList.get()); |
116 | } |
117 | |
118 | WebKitDOMNodeList* webkit_dom_element_get_elements_by_tag_name_ns(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* tagName) |
119 | { |
120 | g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), nullptr); |
121 | g_return_val_if_fail(namespaceURI, nullptr); |
122 | g_return_val_if_fail(tagName, nullptr); |
123 | |
124 | WebCore::JSMainThreadNullState state; |
125 | WebCore::Element* element = WebKit::core(self); |
126 | RefPtr<WebCore::NodeList> nodeList = WTF::getPtr(element->getElementsByTagNameNS(String::fromUTF8(namespaceURI), String::fromUTF8(tagName))); |
127 | return WebKit::kit(nodeList.get()); |
128 | } |
129 | |
130 | WebKitDOMNodeList* webkit_dom_element_get_elements_by_class_name(WebKitDOMElement* self, const gchar* className) |
131 | { |
132 | g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), nullptr); |
133 | g_return_val_if_fail(className, nullptr); |
134 | |
135 | WebCore::JSMainThreadNullState state; |
136 | WebCore::Element* element = WebKit::core(self); |
137 | RefPtr<WebCore::NodeList> nodeList = WTF::getPtr(element->getElementsByClassName(String::fromUTF8(className))); |
138 | return WebKit::kit(nodeList.get()); |
139 | } |
140 | |
141 | WebKitDOMNode* webkit_dom_node_clone_node(WebKitDOMNode* self, gboolean deep) |
142 | { |
143 | return webkit_dom_node_clone_node_with_error(self, deep, nullptr); |
144 | } |
145 | |
146 | gchar* webkit_dom_document_get_default_charset(WebKitDOMDocument* self) |
147 | { |
148 | g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT(self), nullptr); |
149 | return convertToUTF8String(WebKit::core(self)->defaultCharsetForLegacyBindings()); |
150 | } |
151 | |
152 | WebKitDOMText* webkit_dom_text_replace_whole_text(WebKitDOMText* self, const gchar* content, GError** error) |
153 | { |
154 | g_return_val_if_fail(WEBKIT_DOM_IS_TEXT(self), nullptr); |
155 | g_return_val_if_fail(content, nullptr); |
156 | g_return_val_if_fail(!error || !*error, nullptr); |
157 | |
158 | WebCore::JSMainThreadNullState state; |
159 | return WebKit::kit(WebKit::core(self)->replaceWholeText(WTF::String::fromUTF8(content)).get()); |
160 | } |
161 | |
162 | gboolean webkit_dom_html_input_element_get_capture(WebKitDOMHTMLInputElement* self) |
163 | { |
164 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(self), FALSE); |
165 | |
166 | #if ENABLE(MEDIA_CAPTURE) |
167 | WebCore::JSMainThreadNullState state; |
168 | WebCore::HTMLInputElement* item = WebKit::core(self); |
169 | return item->mediaCaptureType() != WebCore::MediaCaptureTypeNone; |
170 | #else |
171 | UNUSED_PARAM(self); |
172 | WEBKIT_WARN_FEATURE_NOT_PRESENT("Media Capture" ) |
173 | return FALSE; |
174 | #endif /* ENABLE(MEDIA_CAPTURE) */ |
175 | } |
176 | |
177 | gchar* webkit_dom_html_document_get_design_mode(WebKitDOMHTMLDocument* self) |
178 | { |
179 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), nullptr); |
180 | return webkit_dom_document_get_design_mode(WEBKIT_DOM_DOCUMENT(self)); |
181 | } |
182 | |
183 | |
184 | void webkit_dom_html_document_set_design_mode(WebKitDOMHTMLDocument* self, const gchar* value) |
185 | { |
186 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
187 | webkit_dom_document_set_design_mode(WEBKIT_DOM_DOCUMENT(self), value); |
188 | } |
189 | |
190 | gchar* webkit_dom_html_document_get_compat_mode(WebKitDOMHTMLDocument* self) |
191 | { |
192 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), nullptr); |
193 | return webkit_dom_document_get_compat_mode(WEBKIT_DOM_DOCUMENT(self)); |
194 | } |
195 | |
196 | WebKitDOMHTMLCollection* webkit_dom_html_document_get_embeds(WebKitDOMHTMLDocument* self) |
197 | { |
198 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), nullptr); |
199 | return webkit_dom_document_get_embeds(WEBKIT_DOM_DOCUMENT(self)); |
200 | } |
201 | |
202 | WebKitDOMHTMLCollection* webkit_dom_html_document_get_plugins(WebKitDOMHTMLDocument* self) |
203 | { |
204 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), nullptr); |
205 | return webkit_dom_document_get_plugins(WEBKIT_DOM_DOCUMENT(self)); |
206 | } |
207 | |
208 | WebKitDOMHTMLCollection* webkit_dom_html_document_get_scripts(WebKitDOMHTMLDocument* self) |
209 | { |
210 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), nullptr); |
211 | return webkit_dom_document_get_scripts(WEBKIT_DOM_DOCUMENT(self)); |
212 | } |
213 | |
214 | gchar* webkit_dom_node_get_namespace_uri(WebKitDOMNode* self) |
215 | { |
216 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), nullptr); |
217 | |
218 | WebCore::JSMainThreadNullState state; |
219 | return convertToUTF8String(WebKit::core(self)->namespaceURI()); |
220 | } |
221 | |
222 | gchar* webkit_dom_node_get_prefix(WebKitDOMNode* self) |
223 | { |
224 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), nullptr); |
225 | WebCore::JSMainThreadNullState state; |
226 | return convertToUTF8String(WebKit::core(self)->prefix()); |
227 | } |
228 | |
229 | void webkit_dom_node_set_prefix(WebKitDOMNode* self, const gchar* value, GError** error) |
230 | { |
231 | g_return_if_fail(WEBKIT_DOM_IS_NODE(self)); |
232 | g_return_if_fail(value); |
233 | g_return_if_fail(!error || !*error); |
234 | |
235 | g_warning("%s: prefix is now a readonly property according to the DOM spec." , __func__); |
236 | |
237 | WebCore::JSMainThreadNullState state; |
238 | WebCore::Node* item = WebKit::core(self); |
239 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
240 | auto result = item->setPrefix(convertedValue); |
241 | if (result.hasException()) { |
242 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
243 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
244 | } |
245 | } |
246 | |
247 | gchar* webkit_dom_node_get_local_name(WebKitDOMNode* self) |
248 | { |
249 | g_return_val_if_fail(WEBKIT_DOM_IS_NODE(self), nullptr); |
250 | WebCore::JSMainThreadNullState state; |
251 | return convertToUTF8String(WebKit::core(self)->localName()); |
252 | } |
253 | |
254 | G_DEFINE_TYPE(WebKitDOMEntityReference, webkit_dom_entity_reference, WEBKIT_DOM_TYPE_NODE) |
255 | |
256 | static void webkit_dom_entity_reference_init(WebKitDOMEntityReference*) |
257 | { |
258 | } |
259 | |
260 | static void webkit_dom_entity_reference_class_init(WebKitDOMEntityReferenceClass*) |
261 | { |
262 | } |
263 | |
264 | gboolean webkit_dom_node_iterator_get_expand_entity_references(WebKitDOMNodeIterator*) |
265 | { |
266 | g_warning("%s: EntityReference has been removed from DOM spec, this function does nothing." , __func__); |
267 | return FALSE; |
268 | } |
269 | |
270 | gboolean webkit_dom_tree_walker_get_expand_entity_references(WebKitDOMTreeWalker*) |
271 | { |
272 | g_warning("%s: EntityReference has been removed from DOM spec, this function does nothing." , __func__); |
273 | return FALSE; |
274 | } |
275 | |
276 | WebKitDOMEntityReference* webkit_dom_document_create_entity_reference(WebKitDOMDocument*, const gchar*, GError**) |
277 | { |
278 | g_warning("%s: EntityReference has been removed from DOM spec, this function does nothing." , __func__); |
279 | return nullptr; |
280 | } |
281 | |
282 | G_DEFINE_TYPE(WebKitDOMHTMLBaseFontElement, webkit_dom_html_base_font_element, WEBKIT_DOM_TYPE_HTML_ELEMENT) |
283 | |
284 | static void webkit_dom_html_base_font_element_init(WebKitDOMHTMLBaseFontElement*) |
285 | { |
286 | } |
287 | |
288 | static void webkit_dom_html_base_font_element_class_init(WebKitDOMHTMLBaseFontElementClass*) |
289 | { |
290 | } |
291 | |
292 | gchar* webkit_dom_html_base_font_element_get_color(WebKitDOMHTMLBaseFontElement*) |
293 | { |
294 | g_warning("%s: HTMLBaseFont has been removed from DOM spec, this function does nothing." , __func__); |
295 | return nullptr; |
296 | } |
297 | |
298 | void webkit_dom_html_base_font_element_set_color(WebKitDOMHTMLBaseFontElement*, const gchar*) |
299 | { |
300 | g_warning("%s: HTMLBaseFont has been removed from DOM spec, this function does nothing." , __func__); |
301 | } |
302 | |
303 | gchar* webkit_dom_html_base_font_element_get_face(WebKitDOMHTMLBaseFontElement*) |
304 | { |
305 | g_warning("%s: HTMLBaseFont has been removed from DOM spec, this function does nothing." , __func__); |
306 | return nullptr; |
307 | } |
308 | |
309 | void webkit_dom_html_base_font_element_set_face(WebKitDOMHTMLBaseFontElement*, const gchar*) |
310 | { |
311 | g_warning("%s: HTMLBaseFont has been removed from DOM spec, this function does nothing." , __func__); |
312 | } |
313 | |
314 | glong webkit_dom_html_base_font_element_get_size(WebKitDOMHTMLBaseFontElement*) |
315 | { |
316 | g_warning("%s: HTMLBaseFont has been removed from DOM spec, this function does nothing." , __func__); |
317 | return 0; |
318 | } |
319 | |
320 | void webkit_dom_html_base_font_element_set_size(WebKitDOMHTMLBaseFontElement*, glong) |
321 | { |
322 | g_warning("%s: HTMLBaseFont has been removed from DOM spec, this function does nothing." , __func__); |
323 | } |
324 | |
325 | gchar* webkit_dom_element_get_webkit_region_overset(WebKitDOMElement*) |
326 | { |
327 | g_warning("%s: CSS Regions support has been removed, this function does nothing." , __func__); |
328 | return nullptr; |
329 | } |
330 | G_GNUC_END_IGNORE_DEPRECATIONS; |
331 | |