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 "WebKitDOMHTMLEmbedElement.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 "WebKitDOMHTMLEmbedElementPrivate.h" |
33 | #include "WebKitDOMNodePrivate.h" |
34 | #include "WebKitDOMPrivate.h" |
35 | #include "ConvertToUTF8String.h" |
36 | #include <wtf/GetPtr.h> |
37 | #include <wtf/RefPtr.h> |
38 | |
39 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
40 | |
41 | namespace WebKit { |
42 | |
43 | WebKitDOMHTMLEmbedElement* kit(WebCore::HTMLEmbedElement* obj) |
44 | { |
45 | return WEBKIT_DOM_HTML_EMBED_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
46 | } |
47 | |
48 | WebCore::HTMLEmbedElement* core(WebKitDOMHTMLEmbedElement* request) |
49 | { |
50 | return request ? static_cast<WebCore::HTMLEmbedElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
51 | } |
52 | |
53 | WebKitDOMHTMLEmbedElement* wrapHTMLEmbedElement(WebCore::HTMLEmbedElement* coreObject) |
54 | { |
55 | ASSERT(coreObject); |
56 | return WEBKIT_DOM_HTML_EMBED_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_EMBED_ELEMENT, "core-object" , coreObject, nullptr)); |
57 | } |
58 | |
59 | } // namespace WebKit |
60 | |
61 | static gboolean webkit_dom_html_embed_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::HTMLEmbedElement* coreTarget = static_cast<WebCore::HTMLEmbedElement*>(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 | |
77 | static gboolean webkit_dom_html_embed_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
78 | { |
79 | WebCore::HTMLEmbedElement* coreTarget = static_cast<WebCore::HTMLEmbedElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
80 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
81 | } |
82 | |
83 | static gboolean webkit_dom_html_embed_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
84 | { |
85 | WebCore::HTMLEmbedElement* coreTarget = static_cast<WebCore::HTMLEmbedElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
86 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
87 | } |
88 | |
89 | static void webkit_dom_html_embed_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
90 | { |
91 | iface->dispatch_event = webkit_dom_html_embed_element_dispatch_event; |
92 | iface->add_event_listener = webkit_dom_html_embed_element_add_event_listener; |
93 | iface->remove_event_listener = webkit_dom_html_embed_element_remove_event_listener; |
94 | } |
95 | |
96 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLEmbedElement, webkit_dom_html_embed_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_embed_element_dom_event_target_init)) |
97 | |
98 | enum { |
99 | DOM_HTML_EMBED_ELEMENT_PROP_0, |
100 | DOM_HTML_EMBED_ELEMENT_PROP_ALIGN, |
101 | DOM_HTML_EMBED_ELEMENT_PROP_HEIGHT, |
102 | DOM_HTML_EMBED_ELEMENT_PROP_NAME, |
103 | DOM_HTML_EMBED_ELEMENT_PROP_SRC, |
104 | DOM_HTML_EMBED_ELEMENT_PROP_TYPE, |
105 | DOM_HTML_EMBED_ELEMENT_PROP_WIDTH, |
106 | }; |
107 | |
108 | static void webkit_dom_html_embed_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
109 | { |
110 | WebKitDOMHTMLEmbedElement* self = WEBKIT_DOM_HTML_EMBED_ELEMENT(object); |
111 | |
112 | switch (propertyId) { |
113 | case DOM_HTML_EMBED_ELEMENT_PROP_ALIGN: |
114 | webkit_dom_html_embed_element_set_align(self, g_value_get_string(value)); |
115 | break; |
116 | case DOM_HTML_EMBED_ELEMENT_PROP_HEIGHT: |
117 | webkit_dom_html_embed_element_set_height(self, g_value_get_long(value)); |
118 | break; |
119 | case DOM_HTML_EMBED_ELEMENT_PROP_NAME: |
120 | webkit_dom_html_embed_element_set_name(self, g_value_get_string(value)); |
121 | break; |
122 | case DOM_HTML_EMBED_ELEMENT_PROP_SRC: |
123 | webkit_dom_html_embed_element_set_src(self, g_value_get_string(value)); |
124 | break; |
125 | case DOM_HTML_EMBED_ELEMENT_PROP_TYPE: |
126 | webkit_dom_html_embed_element_set_type_attr(self, g_value_get_string(value)); |
127 | break; |
128 | case DOM_HTML_EMBED_ELEMENT_PROP_WIDTH: |
129 | webkit_dom_html_embed_element_set_width(self, g_value_get_long(value)); |
130 | break; |
131 | default: |
132 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
133 | break; |
134 | } |
135 | } |
136 | |
137 | static void webkit_dom_html_embed_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
138 | { |
139 | WebKitDOMHTMLEmbedElement* self = WEBKIT_DOM_HTML_EMBED_ELEMENT(object); |
140 | |
141 | switch (propertyId) { |
142 | case DOM_HTML_EMBED_ELEMENT_PROP_ALIGN: |
143 | g_value_take_string(value, webkit_dom_html_embed_element_get_align(self)); |
144 | break; |
145 | case DOM_HTML_EMBED_ELEMENT_PROP_HEIGHT: |
146 | g_value_set_long(value, webkit_dom_html_embed_element_get_height(self)); |
147 | break; |
148 | case DOM_HTML_EMBED_ELEMENT_PROP_NAME: |
149 | g_value_take_string(value, webkit_dom_html_embed_element_get_name(self)); |
150 | break; |
151 | case DOM_HTML_EMBED_ELEMENT_PROP_SRC: |
152 | g_value_take_string(value, webkit_dom_html_embed_element_get_src(self)); |
153 | break; |
154 | case DOM_HTML_EMBED_ELEMENT_PROP_TYPE: |
155 | g_value_take_string(value, webkit_dom_html_embed_element_get_type_attr(self)); |
156 | break; |
157 | case DOM_HTML_EMBED_ELEMENT_PROP_WIDTH: |
158 | g_value_set_long(value, webkit_dom_html_embed_element_get_width(self)); |
159 | break; |
160 | default: |
161 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
162 | break; |
163 | } |
164 | } |
165 | |
166 | static void webkit_dom_html_embed_element_class_init(WebKitDOMHTMLEmbedElementClass* requestClass) |
167 | { |
168 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
169 | gobjectClass->set_property = webkit_dom_html_embed_element_set_property; |
170 | gobjectClass->get_property = webkit_dom_html_embed_element_get_property; |
171 | |
172 | g_object_class_install_property( |
173 | gobjectClass, |
174 | DOM_HTML_EMBED_ELEMENT_PROP_ALIGN, |
175 | g_param_spec_string( |
176 | "align" , |
177 | "HTMLEmbedElement:align" , |
178 | "read-write gchar* HTMLEmbedElement:align" , |
179 | "" , |
180 | WEBKIT_PARAM_READWRITE)); |
181 | |
182 | g_object_class_install_property( |
183 | gobjectClass, |
184 | DOM_HTML_EMBED_ELEMENT_PROP_HEIGHT, |
185 | g_param_spec_long( |
186 | "height" , |
187 | "HTMLEmbedElement:height" , |
188 | "read-write glong HTMLEmbedElement:height" , |
189 | G_MINLONG, G_MAXLONG, 0, |
190 | WEBKIT_PARAM_READWRITE)); |
191 | |
192 | g_object_class_install_property( |
193 | gobjectClass, |
194 | DOM_HTML_EMBED_ELEMENT_PROP_NAME, |
195 | g_param_spec_string( |
196 | "name" , |
197 | "HTMLEmbedElement:name" , |
198 | "read-write gchar* HTMLEmbedElement:name" , |
199 | "" , |
200 | WEBKIT_PARAM_READWRITE)); |
201 | |
202 | g_object_class_install_property( |
203 | gobjectClass, |
204 | DOM_HTML_EMBED_ELEMENT_PROP_SRC, |
205 | g_param_spec_string( |
206 | "src" , |
207 | "HTMLEmbedElement:src" , |
208 | "read-write gchar* HTMLEmbedElement:src" , |
209 | "" , |
210 | WEBKIT_PARAM_READWRITE)); |
211 | |
212 | g_object_class_install_property( |
213 | gobjectClass, |
214 | DOM_HTML_EMBED_ELEMENT_PROP_TYPE, |
215 | g_param_spec_string( |
216 | "type" , |
217 | "HTMLEmbedElement:type" , |
218 | "read-write gchar* HTMLEmbedElement:type" , |
219 | "" , |
220 | WEBKIT_PARAM_READWRITE)); |
221 | |
222 | g_object_class_install_property( |
223 | gobjectClass, |
224 | DOM_HTML_EMBED_ELEMENT_PROP_WIDTH, |
225 | g_param_spec_long( |
226 | "width" , |
227 | "HTMLEmbedElement:width" , |
228 | "read-write glong HTMLEmbedElement:width" , |
229 | G_MINLONG, G_MAXLONG, 0, |
230 | WEBKIT_PARAM_READWRITE)); |
231 | |
232 | } |
233 | |
234 | static void webkit_dom_html_embed_element_init(WebKitDOMHTMLEmbedElement* request) |
235 | { |
236 | UNUSED_PARAM(request); |
237 | } |
238 | |
239 | gchar* webkit_dom_html_embed_element_get_align(WebKitDOMHTMLEmbedElement* self) |
240 | { |
241 | WebCore::JSMainThreadNullState state; |
242 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self), 0); |
243 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
244 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alignAttr)); |
245 | return result; |
246 | } |
247 | |
248 | void webkit_dom_html_embed_element_set_align(WebKitDOMHTMLEmbedElement* self, const gchar* value) |
249 | { |
250 | WebCore::JSMainThreadNullState state; |
251 | g_return_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self)); |
252 | g_return_if_fail(value); |
253 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
254 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
255 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alignAttr, convertedValue); |
256 | } |
257 | |
258 | glong webkit_dom_html_embed_element_get_height(WebKitDOMHTMLEmbedElement* self) |
259 | { |
260 | WebCore::JSMainThreadNullState state; |
261 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self), 0); |
262 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
263 | glong result = item->getIntegralAttribute(WebCore::HTMLNames::heightAttr); |
264 | return result; |
265 | } |
266 | |
267 | void webkit_dom_html_embed_element_set_height(WebKitDOMHTMLEmbedElement* self, glong value) |
268 | { |
269 | WebCore::JSMainThreadNullState state; |
270 | g_return_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self)); |
271 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
272 | item->setIntegralAttribute(WebCore::HTMLNames::heightAttr, value); |
273 | } |
274 | |
275 | gchar* webkit_dom_html_embed_element_get_name(WebKitDOMHTMLEmbedElement* self) |
276 | { |
277 | WebCore::JSMainThreadNullState state; |
278 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self), 0); |
279 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
280 | gchar* result = convertToUTF8String(item->getNameAttribute()); |
281 | return result; |
282 | } |
283 | |
284 | void webkit_dom_html_embed_element_set_name(WebKitDOMHTMLEmbedElement* self, const gchar* value) |
285 | { |
286 | WebCore::JSMainThreadNullState state; |
287 | g_return_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self)); |
288 | g_return_if_fail(value); |
289 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
290 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
291 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::nameAttr, convertedValue); |
292 | } |
293 | |
294 | gchar* webkit_dom_html_embed_element_get_src(WebKitDOMHTMLEmbedElement* self) |
295 | { |
296 | WebCore::JSMainThreadNullState state; |
297 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self), 0); |
298 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
299 | gchar* result = convertToUTF8String(item->getURLAttribute(WebCore::HTMLNames::srcAttr)); |
300 | return result; |
301 | } |
302 | |
303 | void webkit_dom_html_embed_element_set_src(WebKitDOMHTMLEmbedElement* self, const gchar* value) |
304 | { |
305 | WebCore::JSMainThreadNullState state; |
306 | g_return_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self)); |
307 | g_return_if_fail(value); |
308 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
309 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
310 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::srcAttr, convertedValue); |
311 | } |
312 | |
313 | gchar* webkit_dom_html_embed_element_get_type_attr(WebKitDOMHTMLEmbedElement* self) |
314 | { |
315 | WebCore::JSMainThreadNullState state; |
316 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self), 0); |
317 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
318 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::typeAttr)); |
319 | return result; |
320 | } |
321 | |
322 | void webkit_dom_html_embed_element_set_type_attr(WebKitDOMHTMLEmbedElement* self, const gchar* value) |
323 | { |
324 | WebCore::JSMainThreadNullState state; |
325 | g_return_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self)); |
326 | g_return_if_fail(value); |
327 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
328 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
329 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::typeAttr, convertedValue); |
330 | } |
331 | |
332 | glong webkit_dom_html_embed_element_get_width(WebKitDOMHTMLEmbedElement* self) |
333 | { |
334 | WebCore::JSMainThreadNullState state; |
335 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self), 0); |
336 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
337 | glong result = item->getIntegralAttribute(WebCore::HTMLNames::widthAttr); |
338 | return result; |
339 | } |
340 | |
341 | void webkit_dom_html_embed_element_set_width(WebKitDOMHTMLEmbedElement* self, glong value) |
342 | { |
343 | WebCore::JSMainThreadNullState state; |
344 | g_return_if_fail(WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(self)); |
345 | WebCore::HTMLEmbedElement* item = WebKit::core(self); |
346 | item->setIntegralAttribute(WebCore::HTMLNames::widthAttr, value); |
347 | } |
348 | |
349 | G_GNUC_END_IGNORE_DEPRECATIONS; |
350 | |