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 "WebKitDOMHTMLDocument.h" |
22 | |
23 | #include <WebCore/CSSImportRule.h> |
24 | #include "DOMObjectCache.h" |
25 | #include <WebCore/DOMException.h> |
26 | #include <WebCore/Document.h> |
27 | #include "GObjectEventListener.h" |
28 | #include <WebCore/JSExecState.h> |
29 | #include "WebKitDOMEventPrivate.h" |
30 | #include "WebKitDOMEventTarget.h" |
31 | #include "WebKitDOMHTMLDocumentPrivate.h" |
32 | #include "WebKitDOMNodePrivate.h" |
33 | #include "WebKitDOMPrivate.h" |
34 | #include "ConvertToUTF8String.h" |
35 | #include <wtf/GetPtr.h> |
36 | #include <wtf/RefPtr.h> |
37 | |
38 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
39 | |
40 | namespace WebKit { |
41 | |
42 | WebKitDOMHTMLDocument* kit(WebCore::HTMLDocument* obj) |
43 | { |
44 | return WEBKIT_DOM_HTML_DOCUMENT(kit(static_cast<WebCore::Node*>(obj))); |
45 | } |
46 | |
47 | WebCore::HTMLDocument* core(WebKitDOMHTMLDocument* request) |
48 | { |
49 | return request ? static_cast<WebCore::HTMLDocument*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
50 | } |
51 | |
52 | WebKitDOMHTMLDocument* wrapHTMLDocument(WebCore::HTMLDocument* coreObject) |
53 | { |
54 | ASSERT(coreObject); |
55 | return WEBKIT_DOM_HTML_DOCUMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_DOCUMENT, "core-object" , coreObject, nullptr)); |
56 | } |
57 | |
58 | } // namespace WebKit |
59 | |
60 | static gboolean webkit_dom_html_document_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) |
61 | { |
62 | WebCore::Event* coreEvent = WebKit::core(event); |
63 | if (!coreEvent) |
64 | return false; |
65 | WebCore::HTMLDocument* coreTarget = static_cast<WebCore::HTMLDocument*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
66 | |
67 | auto result = coreTarget->dispatchEventForBindings(*coreEvent); |
68 | if (result.hasException()) { |
69 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
70 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
71 | return false; |
72 | } |
73 | return result.releaseReturnValue(); |
74 | } |
75 | |
76 | static gboolean webkit_dom_html_document_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
77 | { |
78 | WebCore::HTMLDocument* coreTarget = static_cast<WebCore::HTMLDocument*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
79 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
80 | } |
81 | |
82 | static gboolean webkit_dom_html_document_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
83 | { |
84 | WebCore::HTMLDocument* coreTarget = static_cast<WebCore::HTMLDocument*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
85 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
86 | } |
87 | |
88 | static void webkit_dom_html_document_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
89 | { |
90 | iface->dispatch_event = webkit_dom_html_document_dispatch_event; |
91 | iface->add_event_listener = webkit_dom_html_document_add_event_listener; |
92 | iface->remove_event_listener = webkit_dom_html_document_remove_event_listener; |
93 | } |
94 | |
95 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLDocument, webkit_dom_html_document, WEBKIT_DOM_TYPE_DOCUMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_document_dom_event_target_init)) |
96 | |
97 | enum { |
98 | DOM_HTML_DOCUMENT_PROP_0, |
99 | DOM_HTML_DOCUMENT_PROP_WIDTH, |
100 | DOM_HTML_DOCUMENT_PROP_HEIGHT, |
101 | DOM_HTML_DOCUMENT_PROP_DIR, |
102 | DOM_HTML_DOCUMENT_PROP_BG_COLOR, |
103 | DOM_HTML_DOCUMENT_PROP_FG_COLOR, |
104 | DOM_HTML_DOCUMENT_PROP_ALINK_COLOR, |
105 | DOM_HTML_DOCUMENT_PROP_LINK_COLOR, |
106 | DOM_HTML_DOCUMENT_PROP_VLINK_COLOR, |
107 | }; |
108 | |
109 | static void webkit_dom_html_document_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
110 | { |
111 | WebKitDOMHTMLDocument* self = WEBKIT_DOM_HTML_DOCUMENT(object); |
112 | |
113 | switch (propertyId) { |
114 | case DOM_HTML_DOCUMENT_PROP_DIR: |
115 | webkit_dom_html_document_set_dir(self, g_value_get_string(value)); |
116 | break; |
117 | case DOM_HTML_DOCUMENT_PROP_BG_COLOR: |
118 | webkit_dom_html_document_set_bg_color(self, g_value_get_string(value)); |
119 | break; |
120 | case DOM_HTML_DOCUMENT_PROP_FG_COLOR: |
121 | webkit_dom_html_document_set_fg_color(self, g_value_get_string(value)); |
122 | break; |
123 | case DOM_HTML_DOCUMENT_PROP_ALINK_COLOR: |
124 | webkit_dom_html_document_set_alink_color(self, g_value_get_string(value)); |
125 | break; |
126 | case DOM_HTML_DOCUMENT_PROP_LINK_COLOR: |
127 | webkit_dom_html_document_set_link_color(self, g_value_get_string(value)); |
128 | break; |
129 | case DOM_HTML_DOCUMENT_PROP_VLINK_COLOR: |
130 | webkit_dom_html_document_set_vlink_color(self, g_value_get_string(value)); |
131 | break; |
132 | default: |
133 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
134 | break; |
135 | } |
136 | } |
137 | |
138 | static void webkit_dom_html_document_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
139 | { |
140 | WebKitDOMHTMLDocument* self = WEBKIT_DOM_HTML_DOCUMENT(object); |
141 | |
142 | switch (propertyId) { |
143 | case DOM_HTML_DOCUMENT_PROP_WIDTH: |
144 | g_value_set_long(value, webkit_dom_html_document_get_width(self)); |
145 | break; |
146 | case DOM_HTML_DOCUMENT_PROP_HEIGHT: |
147 | g_value_set_long(value, webkit_dom_html_document_get_height(self)); |
148 | break; |
149 | case DOM_HTML_DOCUMENT_PROP_DIR: |
150 | g_value_take_string(value, webkit_dom_html_document_get_dir(self)); |
151 | break; |
152 | case DOM_HTML_DOCUMENT_PROP_BG_COLOR: |
153 | g_value_take_string(value, webkit_dom_html_document_get_bg_color(self)); |
154 | break; |
155 | case DOM_HTML_DOCUMENT_PROP_FG_COLOR: |
156 | g_value_take_string(value, webkit_dom_html_document_get_fg_color(self)); |
157 | break; |
158 | case DOM_HTML_DOCUMENT_PROP_ALINK_COLOR: |
159 | g_value_take_string(value, webkit_dom_html_document_get_alink_color(self)); |
160 | break; |
161 | case DOM_HTML_DOCUMENT_PROP_LINK_COLOR: |
162 | g_value_take_string(value, webkit_dom_html_document_get_link_color(self)); |
163 | break; |
164 | case DOM_HTML_DOCUMENT_PROP_VLINK_COLOR: |
165 | g_value_take_string(value, webkit_dom_html_document_get_vlink_color(self)); |
166 | break; |
167 | default: |
168 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
169 | break; |
170 | } |
171 | } |
172 | |
173 | static void webkit_dom_html_document_class_init(WebKitDOMHTMLDocumentClass* requestClass) |
174 | { |
175 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
176 | gobjectClass->set_property = webkit_dom_html_document_set_property; |
177 | gobjectClass->get_property = webkit_dom_html_document_get_property; |
178 | |
179 | g_object_class_install_property( |
180 | gobjectClass, |
181 | DOM_HTML_DOCUMENT_PROP_WIDTH, |
182 | g_param_spec_long( |
183 | "width" , |
184 | "HTMLDocument:width" , |
185 | "read-only glong HTMLDocument:width" , |
186 | G_MINLONG, G_MAXLONG, 0, |
187 | WEBKIT_PARAM_READABLE)); |
188 | |
189 | g_object_class_install_property( |
190 | gobjectClass, |
191 | DOM_HTML_DOCUMENT_PROP_HEIGHT, |
192 | g_param_spec_long( |
193 | "height" , |
194 | "HTMLDocument:height" , |
195 | "read-only glong HTMLDocument:height" , |
196 | G_MINLONG, G_MAXLONG, 0, |
197 | WEBKIT_PARAM_READABLE)); |
198 | |
199 | g_object_class_install_property( |
200 | gobjectClass, |
201 | DOM_HTML_DOCUMENT_PROP_DIR, |
202 | g_param_spec_string( |
203 | "dir" , |
204 | "HTMLDocument:dir" , |
205 | "read-write gchar* HTMLDocument:dir" , |
206 | "" , |
207 | WEBKIT_PARAM_READWRITE)); |
208 | |
209 | g_object_class_install_property( |
210 | gobjectClass, |
211 | DOM_HTML_DOCUMENT_PROP_BG_COLOR, |
212 | g_param_spec_string( |
213 | "bg-color" , |
214 | "HTMLDocument:bg-color" , |
215 | "read-write gchar* HTMLDocument:bg-color" , |
216 | "" , |
217 | WEBKIT_PARAM_READWRITE)); |
218 | |
219 | g_object_class_install_property( |
220 | gobjectClass, |
221 | DOM_HTML_DOCUMENT_PROP_FG_COLOR, |
222 | g_param_spec_string( |
223 | "fg-color" , |
224 | "HTMLDocument:fg-color" , |
225 | "read-write gchar* HTMLDocument:fg-color" , |
226 | "" , |
227 | WEBKIT_PARAM_READWRITE)); |
228 | |
229 | g_object_class_install_property( |
230 | gobjectClass, |
231 | DOM_HTML_DOCUMENT_PROP_ALINK_COLOR, |
232 | g_param_spec_string( |
233 | "alink-color" , |
234 | "HTMLDocument:alink-color" , |
235 | "read-write gchar* HTMLDocument:alink-color" , |
236 | "" , |
237 | WEBKIT_PARAM_READWRITE)); |
238 | |
239 | g_object_class_install_property( |
240 | gobjectClass, |
241 | DOM_HTML_DOCUMENT_PROP_LINK_COLOR, |
242 | g_param_spec_string( |
243 | "link-color" , |
244 | "HTMLDocument:link-color" , |
245 | "read-write gchar* HTMLDocument:link-color" , |
246 | "" , |
247 | WEBKIT_PARAM_READWRITE)); |
248 | |
249 | g_object_class_install_property( |
250 | gobjectClass, |
251 | DOM_HTML_DOCUMENT_PROP_VLINK_COLOR, |
252 | g_param_spec_string( |
253 | "vlink-color" , |
254 | "HTMLDocument:vlink-color" , |
255 | "read-write gchar* HTMLDocument:vlink-color" , |
256 | "" , |
257 | WEBKIT_PARAM_READWRITE)); |
258 | |
259 | } |
260 | |
261 | static void webkit_dom_html_document_init(WebKitDOMHTMLDocument* request) |
262 | { |
263 | UNUSED_PARAM(request); |
264 | } |
265 | |
266 | void webkit_dom_html_document_close(WebKitDOMHTMLDocument* self) |
267 | { |
268 | WebCore::JSMainThreadNullState state; |
269 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
270 | WebCore::HTMLDocument* item = WebKit::core(self); |
271 | item->close(); |
272 | } |
273 | |
274 | void webkit_dom_html_document_clear(WebKitDOMHTMLDocument* self) |
275 | { |
276 | WebCore::JSMainThreadNullState state; |
277 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
278 | WebCore::HTMLDocument* item = WebKit::core(self); |
279 | item->clear(); |
280 | } |
281 | |
282 | void webkit_dom_html_document_capture_events(WebKitDOMHTMLDocument* self) |
283 | { |
284 | WebCore::JSMainThreadNullState state; |
285 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
286 | WebCore::HTMLDocument* item = WebKit::core(self); |
287 | item->captureEvents(); |
288 | } |
289 | |
290 | void webkit_dom_html_document_release_events(WebKitDOMHTMLDocument* self) |
291 | { |
292 | WebCore::JSMainThreadNullState state; |
293 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
294 | WebCore::HTMLDocument* item = WebKit::core(self); |
295 | item->releaseEvents(); |
296 | } |
297 | |
298 | glong webkit_dom_html_document_get_width(WebKitDOMHTMLDocument* self) |
299 | { |
300 | WebCore::JSMainThreadNullState state; |
301 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
302 | WebCore::HTMLDocument* item = WebKit::core(self); |
303 | glong result = item->width(); |
304 | return result; |
305 | } |
306 | |
307 | glong webkit_dom_html_document_get_height(WebKitDOMHTMLDocument* self) |
308 | { |
309 | WebCore::JSMainThreadNullState state; |
310 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
311 | WebCore::HTMLDocument* item = WebKit::core(self); |
312 | glong result = item->height(); |
313 | return result; |
314 | } |
315 | |
316 | gchar* webkit_dom_html_document_get_dir(WebKitDOMHTMLDocument* self) |
317 | { |
318 | WebCore::JSMainThreadNullState state; |
319 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
320 | WebCore::HTMLDocument* item = WebKit::core(self); |
321 | gchar* result = convertToUTF8String(item->dir()); |
322 | return result; |
323 | } |
324 | |
325 | void webkit_dom_html_document_set_dir(WebKitDOMHTMLDocument* self, const gchar* value) |
326 | { |
327 | WebCore::JSMainThreadNullState state; |
328 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
329 | g_return_if_fail(value); |
330 | WebCore::HTMLDocument* item = WebKit::core(self); |
331 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
332 | item->setDir(convertedValue); |
333 | } |
334 | |
335 | gchar* webkit_dom_html_document_get_bg_color(WebKitDOMHTMLDocument* self) |
336 | { |
337 | WebCore::JSMainThreadNullState state; |
338 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
339 | WebCore::HTMLDocument* item = WebKit::core(self); |
340 | gchar* result = convertToUTF8String(item->bgColor()); |
341 | return result; |
342 | } |
343 | |
344 | void webkit_dom_html_document_set_bg_color(WebKitDOMHTMLDocument* self, const gchar* value) |
345 | { |
346 | WebCore::JSMainThreadNullState state; |
347 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
348 | g_return_if_fail(value); |
349 | WebCore::HTMLDocument* item = WebKit::core(self); |
350 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
351 | item->setBgColor(convertedValue); |
352 | } |
353 | |
354 | gchar* webkit_dom_html_document_get_fg_color(WebKitDOMHTMLDocument* self) |
355 | { |
356 | WebCore::JSMainThreadNullState state; |
357 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
358 | WebCore::HTMLDocument* item = WebKit::core(self); |
359 | gchar* result = convertToUTF8String(item->fgColor()); |
360 | return result; |
361 | } |
362 | |
363 | void webkit_dom_html_document_set_fg_color(WebKitDOMHTMLDocument* self, const gchar* value) |
364 | { |
365 | WebCore::JSMainThreadNullState state; |
366 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
367 | g_return_if_fail(value); |
368 | WebCore::HTMLDocument* item = WebKit::core(self); |
369 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
370 | item->setFgColor(convertedValue); |
371 | } |
372 | |
373 | gchar* webkit_dom_html_document_get_alink_color(WebKitDOMHTMLDocument* self) |
374 | { |
375 | WebCore::JSMainThreadNullState state; |
376 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
377 | WebCore::HTMLDocument* item = WebKit::core(self); |
378 | gchar* result = convertToUTF8String(item->alinkColor()); |
379 | return result; |
380 | } |
381 | |
382 | void webkit_dom_html_document_set_alink_color(WebKitDOMHTMLDocument* self, const gchar* value) |
383 | { |
384 | WebCore::JSMainThreadNullState state; |
385 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
386 | g_return_if_fail(value); |
387 | WebCore::HTMLDocument* item = WebKit::core(self); |
388 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
389 | item->setAlinkColor(convertedValue); |
390 | } |
391 | |
392 | gchar* webkit_dom_html_document_get_link_color(WebKitDOMHTMLDocument* self) |
393 | { |
394 | WebCore::JSMainThreadNullState state; |
395 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
396 | WebCore::HTMLDocument* item = WebKit::core(self); |
397 | gchar* result = convertToUTF8String(item->linkColorForBindings()); |
398 | return result; |
399 | } |
400 | |
401 | void webkit_dom_html_document_set_link_color(WebKitDOMHTMLDocument* self, const gchar* value) |
402 | { |
403 | WebCore::JSMainThreadNullState state; |
404 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
405 | g_return_if_fail(value); |
406 | WebCore::HTMLDocument* item = WebKit::core(self); |
407 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
408 | item->setLinkColorForBindings(convertedValue); |
409 | } |
410 | |
411 | gchar* webkit_dom_html_document_get_vlink_color(WebKitDOMHTMLDocument* self) |
412 | { |
413 | WebCore::JSMainThreadNullState state; |
414 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self), 0); |
415 | WebCore::HTMLDocument* item = WebKit::core(self); |
416 | gchar* result = convertToUTF8String(item->vlinkColor()); |
417 | return result; |
418 | } |
419 | |
420 | void webkit_dom_html_document_set_vlink_color(WebKitDOMHTMLDocument* self, const gchar* value) |
421 | { |
422 | WebCore::JSMainThreadNullState state; |
423 | g_return_if_fail(WEBKIT_DOM_IS_HTML_DOCUMENT(self)); |
424 | g_return_if_fail(value); |
425 | WebCore::HTMLDocument* item = WebKit::core(self); |
426 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
427 | item->setVlinkColor(convertedValue); |
428 | } |
429 | |
430 | G_GNUC_END_IGNORE_DEPRECATIONS; |
431 | |