Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMCDATASection.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 "WebKitDOMCDATASection.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/JSMainThreadExecState.h>
29 #include "WebKitDOMCDATASectionPrivate.h"
30 #include "WebKitDOMEventPrivate.h"
31 #include "WebKitDOMEventTarget.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 namespace WebKit {
39
40 WebKitDOMCDATASection* kit(WebCore::CDATASection* obj)
41 {
42     return WEBKIT_DOM_CDATA_SECTION(kit(static_cast<WebCore::Node*>(obj)));
43 }
44
45 WebCore::CDATASection* core(WebKitDOMCDATASection* request)
46 {
47     return request ? static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
48 }
49
50 WebKitDOMCDATASection* wrapCDATASection(WebCore::CDATASection* coreObject)
51 {
52     ASSERT(coreObject);
53     return WEBKIT_DOM_CDATA_SECTION(g_object_new(WEBKIT_DOM_TYPE_CDATA_SECTION, "core-object", coreObject, nullptr));
54 }
55
56 } // namespace WebKit
57
58 static gboolean webkit_dom_cdata_section_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
59 {
60     WebCore::Event* coreEvent = WebKit::core(event);
61     if (!coreEvent)
62         return false;
63     WebCore::CDATASection* coreTarget = static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(target)->coreObject);
64
65     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
66     if (result.hasException()) {
67         auto description = WebCore::DOMException::description(result.releaseException().code());
68         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
69         return false;
70     }
71     return result.releaseReturnValue();
72 }
73
74 static gboolean webkit_dom_cdata_section_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
75 {
76     WebCore::CDATASection* coreTarget = static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(target)->coreObject);
77     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
78 }
79
80 static gboolean webkit_dom_cdata_section_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
81 {
82     WebCore::CDATASection* coreTarget = static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(target)->coreObject);
83     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
84 }
85
86 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
87 {
88     iface->dispatch_event = webkit_dom_cdata_section_dispatch_event;
89     iface->add_event_listener = webkit_dom_cdata_section_add_event_listener;
90     iface->remove_event_listener = webkit_dom_cdata_section_remove_event_listener;
91 }
92
93 G_DEFINE_TYPE_WITH_CODE(WebKitDOMCDATASection, webkit_dom_cdata_section, WEBKIT_DOM_TYPE_TEXT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
94
95 static void webkit_dom_cdata_section_class_init(WebKitDOMCDATASectionClass* requestClass)
96 {
97     UNUSED_PARAM(requestClass);
98 }
99
100 static void webkit_dom_cdata_section_init(WebKitDOMCDATASection* request)
101 {
102     UNUSED_PARAM(request);
103 }
104