Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLFrameElement.cpp
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 "WebKitDOMHTMLFrameElement.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/JSMainThreadExecState.h>
30 #include "WebKitDOMDOMWindowPrivate.h"
31 #include "WebKitDOMDocumentPrivate.h"
32 #include "WebKitDOMEventPrivate.h"
33 #include "WebKitDOMEventTarget.h"
34 #include "WebKitDOMHTMLFrameElementPrivate.h"
35 #include "WebKitDOMNodePrivate.h"
36 #include "WebKitDOMPrivate.h"
37 #include "ConvertToUTF8String.h"
38 #include <wtf/GetPtr.h>
39 #include <wtf/RefPtr.h>
40
41 namespace WebKit {
42
43 WebKitDOMHTMLFrameElement* kit(WebCore::HTMLFrameElement* obj)
44 {
45     return WEBKIT_DOM_HTML_FRAME_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
46 }
47
48 WebCore::HTMLFrameElement* core(WebKitDOMHTMLFrameElement* request)
49 {
50     return request ? static_cast<WebCore::HTMLFrameElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
51 }
52
53 WebKitDOMHTMLFrameElement* wrapHTMLFrameElement(WebCore::HTMLFrameElement* coreObject)
54 {
55     ASSERT(coreObject);
56     return WEBKIT_DOM_HTML_FRAME_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_FRAME_ELEMENT, "core-object", coreObject, nullptr));
57 }
58
59 } // namespace WebKit
60
61 static gboolean webkit_dom_html_frame_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::HTMLFrameElement* coreTarget = static_cast<WebCore::HTMLFrameElement*>(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_frame_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
78 {
79     WebCore::HTMLFrameElement* coreTarget = static_cast<WebCore::HTMLFrameElement*>(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_frame_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
84 {
85     WebCore::HTMLFrameElement* coreTarget = static_cast<WebCore::HTMLFrameElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
86     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
87 }
88
89 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
90 {
91     iface->dispatch_event = webkit_dom_html_frame_element_dispatch_event;
92     iface->add_event_listener = webkit_dom_html_frame_element_add_event_listener;
93     iface->remove_event_listener = webkit_dom_html_frame_element_remove_event_listener;
94 }
95
96 G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLFrameElement, webkit_dom_html_frame_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
97
98 enum {
99     PROP_0,
100     PROP_FRAME_BORDER,
101     PROP_LONG_DESC,
102     PROP_MARGIN_HEIGHT,
103     PROP_MARGIN_WIDTH,
104     PROP_NAME,
105     PROP_NO_RESIZE,
106     PROP_SCROLLING,
107     PROP_SRC,
108     PROP_CONTENT_DOCUMENT,
109     PROP_CONTENT_WINDOW,
110     PROP_WIDTH,
111     PROP_HEIGHT,
112 };
113
114 static void webkit_dom_html_frame_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
115 {
116     WebKitDOMHTMLFrameElement* self = WEBKIT_DOM_HTML_FRAME_ELEMENT(object);
117
118     switch (propertyId) {
119     case PROP_FRAME_BORDER:
120         webkit_dom_html_frame_element_set_frame_border(self, g_value_get_string(value));
121         break;
122     case PROP_LONG_DESC:
123         webkit_dom_html_frame_element_set_long_desc(self, g_value_get_string(value));
124         break;
125     case PROP_MARGIN_HEIGHT:
126         webkit_dom_html_frame_element_set_margin_height(self, g_value_get_string(value));
127         break;
128     case PROP_MARGIN_WIDTH:
129         webkit_dom_html_frame_element_set_margin_width(self, g_value_get_string(value));
130         break;
131     case PROP_NAME:
132         webkit_dom_html_frame_element_set_name(self, g_value_get_string(value));
133         break;
134     case PROP_NO_RESIZE:
135         webkit_dom_html_frame_element_set_no_resize(self, g_value_get_boolean(value));
136         break;
137     case PROP_SCROLLING:
138         webkit_dom_html_frame_element_set_scrolling(self, g_value_get_string(value));
139         break;
140     case PROP_SRC:
141         webkit_dom_html_frame_element_set_src(self, g_value_get_string(value));
142         break;
143     default:
144         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
145         break;
146     }
147 }
148
149 static void webkit_dom_html_frame_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
150 {
151     WebKitDOMHTMLFrameElement* self = WEBKIT_DOM_HTML_FRAME_ELEMENT(object);
152
153     switch (propertyId) {
154     case PROP_FRAME_BORDER:
155         g_value_take_string(value, webkit_dom_html_frame_element_get_frame_border(self));
156         break;
157     case PROP_LONG_DESC:
158         g_value_take_string(value, webkit_dom_html_frame_element_get_long_desc(self));
159         break;
160     case PROP_MARGIN_HEIGHT:
161         g_value_take_string(value, webkit_dom_html_frame_element_get_margin_height(self));
162         break;
163     case PROP_MARGIN_WIDTH:
164         g_value_take_string(value, webkit_dom_html_frame_element_get_margin_width(self));
165         break;
166     case PROP_NAME:
167         g_value_take_string(value, webkit_dom_html_frame_element_get_name(self));
168         break;
169     case PROP_NO_RESIZE:
170         g_value_set_boolean(value, webkit_dom_html_frame_element_get_no_resize(self));
171         break;
172     case PROP_SCROLLING:
173         g_value_take_string(value, webkit_dom_html_frame_element_get_scrolling(self));
174         break;
175     case PROP_SRC:
176         g_value_take_string(value, webkit_dom_html_frame_element_get_src(self));
177         break;
178     case PROP_CONTENT_DOCUMENT:
179         g_value_set_object(value, webkit_dom_html_frame_element_get_content_document(self));
180         break;
181     case PROP_CONTENT_WINDOW:
182         g_value_set_object(value, webkit_dom_html_frame_element_get_content_window(self));
183         break;
184     case PROP_WIDTH:
185         g_value_set_long(value, webkit_dom_html_frame_element_get_width(self));
186         break;
187     case PROP_HEIGHT:
188         g_value_set_long(value, webkit_dom_html_frame_element_get_height(self));
189         break;
190     default:
191         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
192         break;
193     }
194 }
195
196 static void webkit_dom_html_frame_element_class_init(WebKitDOMHTMLFrameElementClass* requestClass)
197 {
198     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
199     gobjectClass->set_property = webkit_dom_html_frame_element_set_property;
200     gobjectClass->get_property = webkit_dom_html_frame_element_get_property;
201
202     g_object_class_install_property(
203         gobjectClass,
204         PROP_FRAME_BORDER,
205         g_param_spec_string(
206             "frame-border",
207             "HTMLFrameElement:frame-border",
208             "read-write gchar* HTMLFrameElement:frame-border",
209             "",
210             WEBKIT_PARAM_READWRITE));
211
212     g_object_class_install_property(
213         gobjectClass,
214         PROP_LONG_DESC,
215         g_param_spec_string(
216             "long-desc",
217             "HTMLFrameElement:long-desc",
218             "read-write gchar* HTMLFrameElement:long-desc",
219             "",
220             WEBKIT_PARAM_READWRITE));
221
222     g_object_class_install_property(
223         gobjectClass,
224         PROP_MARGIN_HEIGHT,
225         g_param_spec_string(
226             "margin-height",
227             "HTMLFrameElement:margin-height",
228             "read-write gchar* HTMLFrameElement:margin-height",
229             "",
230             WEBKIT_PARAM_READWRITE));
231
232     g_object_class_install_property(
233         gobjectClass,
234         PROP_MARGIN_WIDTH,
235         g_param_spec_string(
236             "margin-width",
237             "HTMLFrameElement:margin-width",
238             "read-write gchar* HTMLFrameElement:margin-width",
239             "",
240             WEBKIT_PARAM_READWRITE));
241
242     g_object_class_install_property(
243         gobjectClass,
244         PROP_NAME,
245         g_param_spec_string(
246             "name",
247             "HTMLFrameElement:name",
248             "read-write gchar* HTMLFrameElement:name",
249             "",
250             WEBKIT_PARAM_READWRITE));
251
252     g_object_class_install_property(
253         gobjectClass,
254         PROP_NO_RESIZE,
255         g_param_spec_boolean(
256             "no-resize",
257             "HTMLFrameElement:no-resize",
258             "read-write gboolean HTMLFrameElement:no-resize",
259             FALSE,
260             WEBKIT_PARAM_READWRITE));
261
262     g_object_class_install_property(
263         gobjectClass,
264         PROP_SCROLLING,
265         g_param_spec_string(
266             "scrolling",
267             "HTMLFrameElement:scrolling",
268             "read-write gchar* HTMLFrameElement:scrolling",
269             "",
270             WEBKIT_PARAM_READWRITE));
271
272     g_object_class_install_property(
273         gobjectClass,
274         PROP_SRC,
275         g_param_spec_string(
276             "src",
277             "HTMLFrameElement:src",
278             "read-write gchar* HTMLFrameElement:src",
279             "",
280             WEBKIT_PARAM_READWRITE));
281
282     g_object_class_install_property(
283         gobjectClass,
284         PROP_CONTENT_DOCUMENT,
285         g_param_spec_object(
286             "content-document",
287             "HTMLFrameElement:content-document",
288             "read-only WebKitDOMDocument* HTMLFrameElement:content-document",
289             WEBKIT_DOM_TYPE_DOCUMENT,
290             WEBKIT_PARAM_READABLE));
291
292     g_object_class_install_property(
293         gobjectClass,
294         PROP_CONTENT_WINDOW,
295         g_param_spec_object(
296             "content-window",
297             "HTMLFrameElement:content-window",
298             "read-only WebKitDOMDOMWindow* HTMLFrameElement:content-window",
299             WEBKIT_DOM_TYPE_DOM_WINDOW,
300             WEBKIT_PARAM_READABLE));
301
302     g_object_class_install_property(
303         gobjectClass,
304         PROP_WIDTH,
305         g_param_spec_long(
306             "width",
307             "HTMLFrameElement:width",
308             "read-only glong HTMLFrameElement:width",
309             G_MINLONG, G_MAXLONG, 0,
310             WEBKIT_PARAM_READABLE));
311
312     g_object_class_install_property(
313         gobjectClass,
314         PROP_HEIGHT,
315         g_param_spec_long(
316             "height",
317             "HTMLFrameElement:height",
318             "read-only glong HTMLFrameElement:height",
319             G_MINLONG, G_MAXLONG, 0,
320             WEBKIT_PARAM_READABLE));
321
322 }
323
324 static void webkit_dom_html_frame_element_init(WebKitDOMHTMLFrameElement* request)
325 {
326     UNUSED_PARAM(request);
327 }
328
329 gchar* webkit_dom_html_frame_element_get_frame_border(WebKitDOMHTMLFrameElement* self)
330 {
331     WebCore::JSMainThreadNullState state;
332     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
333     WebCore::HTMLFrameElement* item = WebKit::core(self);
334     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::frameborderAttr));
335     return result;
336 }
337
338 void webkit_dom_html_frame_element_set_frame_border(WebKitDOMHTMLFrameElement* self, const gchar* value)
339 {
340     WebCore::JSMainThreadNullState state;
341     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
342     g_return_if_fail(value);
343     WebCore::HTMLFrameElement* item = WebKit::core(self);
344     WTF::String convertedValue = WTF::String::fromUTF8(value);
345     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::frameborderAttr, convertedValue);
346 }
347
348 gchar* webkit_dom_html_frame_element_get_long_desc(WebKitDOMHTMLFrameElement* self)
349 {
350     WebCore::JSMainThreadNullState state;
351     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
352     WebCore::HTMLFrameElement* item = WebKit::core(self);
353     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::longdescAttr));
354     return result;
355 }
356
357 void webkit_dom_html_frame_element_set_long_desc(WebKitDOMHTMLFrameElement* self, const gchar* value)
358 {
359     WebCore::JSMainThreadNullState state;
360     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
361     g_return_if_fail(value);
362     WebCore::HTMLFrameElement* item = WebKit::core(self);
363     WTF::String convertedValue = WTF::String::fromUTF8(value);
364     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::longdescAttr, convertedValue);
365 }
366
367 gchar* webkit_dom_html_frame_element_get_margin_height(WebKitDOMHTMLFrameElement* self)
368 {
369     WebCore::JSMainThreadNullState state;
370     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
371     WebCore::HTMLFrameElement* item = WebKit::core(self);
372     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::marginheightAttr));
373     return result;
374 }
375
376 void webkit_dom_html_frame_element_set_margin_height(WebKitDOMHTMLFrameElement* self, const gchar* value)
377 {
378     WebCore::JSMainThreadNullState state;
379     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
380     g_return_if_fail(value);
381     WebCore::HTMLFrameElement* item = WebKit::core(self);
382     WTF::String convertedValue = WTF::String::fromUTF8(value);
383     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::marginheightAttr, convertedValue);
384 }
385
386 gchar* webkit_dom_html_frame_element_get_margin_width(WebKitDOMHTMLFrameElement* self)
387 {
388     WebCore::JSMainThreadNullState state;
389     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
390     WebCore::HTMLFrameElement* item = WebKit::core(self);
391     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::marginwidthAttr));
392     return result;
393 }
394
395 void webkit_dom_html_frame_element_set_margin_width(WebKitDOMHTMLFrameElement* self, const gchar* value)
396 {
397     WebCore::JSMainThreadNullState state;
398     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
399     g_return_if_fail(value);
400     WebCore::HTMLFrameElement* item = WebKit::core(self);
401     WTF::String convertedValue = WTF::String::fromUTF8(value);
402     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::marginwidthAttr, convertedValue);
403 }
404
405 gchar* webkit_dom_html_frame_element_get_name(WebKitDOMHTMLFrameElement* self)
406 {
407     WebCore::JSMainThreadNullState state;
408     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
409     WebCore::HTMLFrameElement* item = WebKit::core(self);
410     gchar* result = convertToUTF8String(item->getNameAttribute());
411     return result;
412 }
413
414 void webkit_dom_html_frame_element_set_name(WebKitDOMHTMLFrameElement* self, const gchar* value)
415 {
416     WebCore::JSMainThreadNullState state;
417     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
418     g_return_if_fail(value);
419     WebCore::HTMLFrameElement* item = WebKit::core(self);
420     WTF::String convertedValue = WTF::String::fromUTF8(value);
421     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::nameAttr, convertedValue);
422 }
423
424 gboolean webkit_dom_html_frame_element_get_no_resize(WebKitDOMHTMLFrameElement* self)
425 {
426     WebCore::JSMainThreadNullState state;
427     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), FALSE);
428     WebCore::HTMLFrameElement* item = WebKit::core(self);
429     gboolean result = item->hasAttributeWithoutSynchronization(WebCore::HTMLNames::noresizeAttr);
430     return result;
431 }
432
433 void webkit_dom_html_frame_element_set_no_resize(WebKitDOMHTMLFrameElement* self, gboolean value)
434 {
435     WebCore::JSMainThreadNullState state;
436     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
437     WebCore::HTMLFrameElement* item = WebKit::core(self);
438     item->setBooleanAttribute(WebCore::HTMLNames::noresizeAttr, value);
439 }
440
441 gchar* webkit_dom_html_frame_element_get_scrolling(WebKitDOMHTMLFrameElement* self)
442 {
443     WebCore::JSMainThreadNullState state;
444     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
445     WebCore::HTMLFrameElement* item = WebKit::core(self);
446     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::scrollingAttr));
447     return result;
448 }
449
450 void webkit_dom_html_frame_element_set_scrolling(WebKitDOMHTMLFrameElement* self, const gchar* value)
451 {
452     WebCore::JSMainThreadNullState state;
453     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
454     g_return_if_fail(value);
455     WebCore::HTMLFrameElement* item = WebKit::core(self);
456     WTF::String convertedValue = WTF::String::fromUTF8(value);
457     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::scrollingAttr, convertedValue);
458 }
459
460 gchar* webkit_dom_html_frame_element_get_src(WebKitDOMHTMLFrameElement* self)
461 {
462     WebCore::JSMainThreadNullState state;
463     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
464     WebCore::HTMLFrameElement* item = WebKit::core(self);
465     gchar* result = convertToUTF8String(item->getURLAttribute(WebCore::HTMLNames::srcAttr));
466     return result;
467 }
468
469 void webkit_dom_html_frame_element_set_src(WebKitDOMHTMLFrameElement* self, const gchar* value)
470 {
471     WebCore::JSMainThreadNullState state;
472     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self));
473     g_return_if_fail(value);
474     WebCore::HTMLFrameElement* item = WebKit::core(self);
475     WTF::String convertedValue = WTF::String::fromUTF8(value);
476     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::srcAttr, convertedValue);
477 }
478
479 WebKitDOMDocument* webkit_dom_html_frame_element_get_content_document(WebKitDOMHTMLFrameElement* self)
480 {
481     WebCore::JSMainThreadNullState state;
482     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
483     WebCore::HTMLFrameElement* item = WebKit::core(self);
484     RefPtr<WebCore::Document> gobjectResult = WTF::getPtr(item->contentDocument());
485     return WebKit::kit(gobjectResult.get());
486 }
487
488 WebKitDOMDOMWindow* webkit_dom_html_frame_element_get_content_window(WebKitDOMHTMLFrameElement* self)
489 {
490     WebCore::JSMainThreadNullState state;
491     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
492     WebCore::HTMLFrameElement* item = WebKit::core(self);
493     RefPtr<WebCore::DOMWindow> gobjectResult = WTF::getPtr(item->contentWindow());
494     return WebKit::kit(gobjectResult.get());
495 }
496
497 glong webkit_dom_html_frame_element_get_width(WebKitDOMHTMLFrameElement* self)
498 {
499     WebCore::JSMainThreadNullState state;
500     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
501     WebCore::HTMLFrameElement* item = WebKit::core(self);
502     glong result = item->width();
503     return result;
504 }
505
506 glong webkit_dom_html_frame_element_get_height(WebKitDOMHTMLFrameElement* self)
507 {
508     WebCore::JSMainThreadNullState state;
509     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(self), 0);
510     WebCore::HTMLFrameElement* item = WebKit::core(self);
511     glong result = item->height();
512     return result;
513 }
514