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 "WebKitDOMHTMLBodyElement.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/HTMLNames.h>
29#include <WebCore/JSExecState.h>
30#include "WebKitDOMEventPrivate.h"
31#include "WebKitDOMEventTarget.h"
32#include "WebKitDOMHTMLBodyElementPrivate.h"
33#include "WebKitDOMNodePrivate.h"
34#include "WebKitDOMPrivate.h"
35#include "ConvertToUTF8String.h"
36#include <wtf/GetPtr.h>
37#include <wtf/RefPtr.h>
38
39G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
40
41namespace WebKit {
42
43WebKitDOMHTMLBodyElement* kit(WebCore::HTMLBodyElement* obj)
44{
45 return WEBKIT_DOM_HTML_BODY_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
46}
47
48WebCore::HTMLBodyElement* core(WebKitDOMHTMLBodyElement* request)
49{
50 return request ? static_cast<WebCore::HTMLBodyElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
51}
52
53WebKitDOMHTMLBodyElement* wrapHTMLBodyElement(WebCore::HTMLBodyElement* coreObject)
54{
55 ASSERT(coreObject);
56 return WEBKIT_DOM_HTML_BODY_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_BODY_ELEMENT, "core-object", coreObject, nullptr));
57}
58
59} // namespace WebKit
60
61static gboolean webkit_dom_html_body_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
62{
63 WebCore::Event* coreEvent = WebKit::core(event);
64 if (!coreEvent)
65 return false;
66 WebCore::HTMLBodyElement* coreTarget = static_cast<WebCore::HTMLBodyElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
67
68 auto result = coreTarget->dispatchEventForBindings(*coreEvent);
69 if (result.hasException()) {
70 auto description = WebCore::DOMException::description(result.releaseException().code());
71 g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
72 return false;
73 }
74 return result.releaseReturnValue();
75}
76
77static gboolean webkit_dom_html_body_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
78{
79 WebCore::HTMLBodyElement* coreTarget = static_cast<WebCore::HTMLBodyElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
80 return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
81}
82
83static gboolean webkit_dom_html_body_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
84{
85 WebCore::HTMLBodyElement* coreTarget = static_cast<WebCore::HTMLBodyElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
86 return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
87}
88
89static void webkit_dom_html_body_element_dom_event_target_init(WebKitDOMEventTargetIface* iface)
90{
91 iface->dispatch_event = webkit_dom_html_body_element_dispatch_event;
92 iface->add_event_listener = webkit_dom_html_body_element_add_event_listener;
93 iface->remove_event_listener = webkit_dom_html_body_element_remove_event_listener;
94}
95
96G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLBodyElement, webkit_dom_html_body_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_body_element_dom_event_target_init))
97
98enum {
99 DOM_HTML_BODY_ELEMENT_PROP_0,
100 DOM_HTML_BODY_ELEMENT_PROP_A_LINK,
101 DOM_HTML_BODY_ELEMENT_PROP_BACKGROUND,
102 DOM_HTML_BODY_ELEMENT_PROP_BG_COLOR,
103 DOM_HTML_BODY_ELEMENT_PROP_LINK,
104 DOM_HTML_BODY_ELEMENT_PROP_TEXT,
105 DOM_HTML_BODY_ELEMENT_PROP_V_LINK,
106};
107
108static void webkit_dom_html_body_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
109{
110 WebKitDOMHTMLBodyElement* self = WEBKIT_DOM_HTML_BODY_ELEMENT(object);
111
112 switch (propertyId) {
113 case DOM_HTML_BODY_ELEMENT_PROP_A_LINK:
114 webkit_dom_html_body_element_set_a_link(self, g_value_get_string(value));
115 break;
116 case DOM_HTML_BODY_ELEMENT_PROP_BACKGROUND:
117 webkit_dom_html_body_element_set_background(self, g_value_get_string(value));
118 break;
119 case DOM_HTML_BODY_ELEMENT_PROP_BG_COLOR:
120 webkit_dom_html_body_element_set_bg_color(self, g_value_get_string(value));
121 break;
122 case DOM_HTML_BODY_ELEMENT_PROP_LINK:
123 webkit_dom_html_body_element_set_link(self, g_value_get_string(value));
124 break;
125 case DOM_HTML_BODY_ELEMENT_PROP_TEXT:
126 webkit_dom_html_body_element_set_text(self, g_value_get_string(value));
127 break;
128 case DOM_HTML_BODY_ELEMENT_PROP_V_LINK:
129 webkit_dom_html_body_element_set_v_link(self, g_value_get_string(value));
130 break;
131 default:
132 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
133 break;
134 }
135}
136
137static void webkit_dom_html_body_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
138{
139 WebKitDOMHTMLBodyElement* self = WEBKIT_DOM_HTML_BODY_ELEMENT(object);
140
141 switch (propertyId) {
142 case DOM_HTML_BODY_ELEMENT_PROP_A_LINK:
143 g_value_take_string(value, webkit_dom_html_body_element_get_a_link(self));
144 break;
145 case DOM_HTML_BODY_ELEMENT_PROP_BACKGROUND:
146 g_value_take_string(value, webkit_dom_html_body_element_get_background(self));
147 break;
148 case DOM_HTML_BODY_ELEMENT_PROP_BG_COLOR:
149 g_value_take_string(value, webkit_dom_html_body_element_get_bg_color(self));
150 break;
151 case DOM_HTML_BODY_ELEMENT_PROP_LINK:
152 g_value_take_string(value, webkit_dom_html_body_element_get_link(self));
153 break;
154 case DOM_HTML_BODY_ELEMENT_PROP_TEXT:
155 g_value_take_string(value, webkit_dom_html_body_element_get_text(self));
156 break;
157 case DOM_HTML_BODY_ELEMENT_PROP_V_LINK:
158 g_value_take_string(value, webkit_dom_html_body_element_get_v_link(self));
159 break;
160 default:
161 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
162 break;
163 }
164}
165
166static void webkit_dom_html_body_element_class_init(WebKitDOMHTMLBodyElementClass* requestClass)
167{
168 GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
169 gobjectClass->set_property = webkit_dom_html_body_element_set_property;
170 gobjectClass->get_property = webkit_dom_html_body_element_get_property;
171
172 g_object_class_install_property(
173 gobjectClass,
174 DOM_HTML_BODY_ELEMENT_PROP_A_LINK,
175 g_param_spec_string(
176 "a-link",
177 "HTMLBodyElement:a-link",
178 "read-write gchar* HTMLBodyElement:a-link",
179 "",
180 WEBKIT_PARAM_READWRITE));
181
182 g_object_class_install_property(
183 gobjectClass,
184 DOM_HTML_BODY_ELEMENT_PROP_BACKGROUND,
185 g_param_spec_string(
186 "background",
187 "HTMLBodyElement:background",
188 "read-write gchar* HTMLBodyElement:background",
189 "",
190 WEBKIT_PARAM_READWRITE));
191
192 g_object_class_install_property(
193 gobjectClass,
194 DOM_HTML_BODY_ELEMENT_PROP_BG_COLOR,
195 g_param_spec_string(
196 "bg-color",
197 "HTMLBodyElement:bg-color",
198 "read-write gchar* HTMLBodyElement:bg-color",
199 "",
200 WEBKIT_PARAM_READWRITE));
201
202 g_object_class_install_property(
203 gobjectClass,
204 DOM_HTML_BODY_ELEMENT_PROP_LINK,
205 g_param_spec_string(
206 "link",
207 "HTMLBodyElement:link",
208 "read-write gchar* HTMLBodyElement:link",
209 "",
210 WEBKIT_PARAM_READWRITE));
211
212 g_object_class_install_property(
213 gobjectClass,
214 DOM_HTML_BODY_ELEMENT_PROP_TEXT,
215 g_param_spec_string(
216 "text",
217 "HTMLBodyElement:text",
218 "read-write gchar* HTMLBodyElement:text",
219 "",
220 WEBKIT_PARAM_READWRITE));
221
222 g_object_class_install_property(
223 gobjectClass,
224 DOM_HTML_BODY_ELEMENT_PROP_V_LINK,
225 g_param_spec_string(
226 "v-link",
227 "HTMLBodyElement:v-link",
228 "read-write gchar* HTMLBodyElement:v-link",
229 "",
230 WEBKIT_PARAM_READWRITE));
231
232}
233
234static void webkit_dom_html_body_element_init(WebKitDOMHTMLBodyElement* request)
235{
236 UNUSED_PARAM(request);
237}
238
239gchar* webkit_dom_html_body_element_get_a_link(WebKitDOMHTMLBodyElement* self)
240{
241 WebCore::JSMainThreadNullState state;
242 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self), 0);
243 WebCore::HTMLBodyElement* item = WebKit::core(self);
244 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alinkAttr));
245 return result;
246}
247
248void webkit_dom_html_body_element_set_a_link(WebKitDOMHTMLBodyElement* self, const gchar* value)
249{
250 WebCore::JSMainThreadNullState state;
251 g_return_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self));
252 g_return_if_fail(value);
253 WebCore::HTMLBodyElement* item = WebKit::core(self);
254 WTF::String convertedValue = WTF::String::fromUTF8(value);
255 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alinkAttr, convertedValue);
256}
257
258gchar* webkit_dom_html_body_element_get_background(WebKitDOMHTMLBodyElement* self)
259{
260 WebCore::JSMainThreadNullState state;
261 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self), 0);
262 WebCore::HTMLBodyElement* item = WebKit::core(self);
263 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::backgroundAttr));
264 return result;
265}
266
267void webkit_dom_html_body_element_set_background(WebKitDOMHTMLBodyElement* self, const gchar* value)
268{
269 WebCore::JSMainThreadNullState state;
270 g_return_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self));
271 g_return_if_fail(value);
272 WebCore::HTMLBodyElement* item = WebKit::core(self);
273 WTF::String convertedValue = WTF::String::fromUTF8(value);
274 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::backgroundAttr, convertedValue);
275}
276
277gchar* webkit_dom_html_body_element_get_bg_color(WebKitDOMHTMLBodyElement* self)
278{
279 WebCore::JSMainThreadNullState state;
280 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self), 0);
281 WebCore::HTMLBodyElement* item = WebKit::core(self);
282 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::bgcolorAttr));
283 return result;
284}
285
286void webkit_dom_html_body_element_set_bg_color(WebKitDOMHTMLBodyElement* self, const gchar* value)
287{
288 WebCore::JSMainThreadNullState state;
289 g_return_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self));
290 g_return_if_fail(value);
291 WebCore::HTMLBodyElement* item = WebKit::core(self);
292 WTF::String convertedValue = WTF::String::fromUTF8(value);
293 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::bgcolorAttr, convertedValue);
294}
295
296gchar* webkit_dom_html_body_element_get_link(WebKitDOMHTMLBodyElement* self)
297{
298 WebCore::JSMainThreadNullState state;
299 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self), 0);
300 WebCore::HTMLBodyElement* item = WebKit::core(self);
301 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::linkAttr));
302 return result;
303}
304
305void webkit_dom_html_body_element_set_link(WebKitDOMHTMLBodyElement* self, const gchar* value)
306{
307 WebCore::JSMainThreadNullState state;
308 g_return_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self));
309 g_return_if_fail(value);
310 WebCore::HTMLBodyElement* item = WebKit::core(self);
311 WTF::String convertedValue = WTF::String::fromUTF8(value);
312 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::linkAttr, convertedValue);
313}
314
315gchar* webkit_dom_html_body_element_get_text(WebKitDOMHTMLBodyElement* self)
316{
317 WebCore::JSMainThreadNullState state;
318 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self), 0);
319 WebCore::HTMLBodyElement* item = WebKit::core(self);
320 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::textAttr));
321 return result;
322}
323
324void webkit_dom_html_body_element_set_text(WebKitDOMHTMLBodyElement* self, const gchar* value)
325{
326 WebCore::JSMainThreadNullState state;
327 g_return_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self));
328 g_return_if_fail(value);
329 WebCore::HTMLBodyElement* item = WebKit::core(self);
330 WTF::String convertedValue = WTF::String::fromUTF8(value);
331 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::textAttr, convertedValue);
332}
333
334gchar* webkit_dom_html_body_element_get_v_link(WebKitDOMHTMLBodyElement* self)
335{
336 WebCore::JSMainThreadNullState state;
337 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self), 0);
338 WebCore::HTMLBodyElement* item = WebKit::core(self);
339 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::vlinkAttr));
340 return result;
341}
342
343void webkit_dom_html_body_element_set_v_link(WebKitDOMHTMLBodyElement* self, const gchar* value)
344{
345 WebCore::JSMainThreadNullState state;
346 g_return_if_fail(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(self));
347 g_return_if_fail(value);
348 WebCore::HTMLBodyElement* item = WebKit::core(self);
349 WTF::String convertedValue = WTF::String::fromUTF8(value);
350 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::vlinkAttr, convertedValue);
351}
352
353G_GNUC_END_IGNORE_DEPRECATIONS;
354