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/JSExecState.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
38G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
39
40namespace WebKit {
41
42WebKitDOMCDATASection* kit(WebCore::CDATASection* obj)
43{
44 return WEBKIT_DOM_CDATA_SECTION(kit(static_cast<WebCore::Node*>(obj)));
45}
46
47WebCore::CDATASection* core(WebKitDOMCDATASection* request)
48{
49 return request ? static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
50}
51
52WebKitDOMCDATASection* wrapCDATASection(WebCore::CDATASection* coreObject)
53{
54 ASSERT(coreObject);
55 return WEBKIT_DOM_CDATA_SECTION(g_object_new(WEBKIT_DOM_TYPE_CDATA_SECTION, "core-object", coreObject, nullptr));
56}
57
58} // namespace WebKit
59
60static gboolean webkit_dom_cdata_section_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
61{
62 WebCore::Event* coreEvent = WebKit::core(event);
63 if (!coreEvent)
64 return false;
65 WebCore::CDATASection* coreTarget = static_cast<WebCore::CDATASection*>(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
76static gboolean webkit_dom_cdata_section_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
77{
78 WebCore::CDATASection* coreTarget = static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(target)->coreObject);
79 return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
80}
81
82static gboolean webkit_dom_cdata_section_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
83{
84 WebCore::CDATASection* coreTarget = static_cast<WebCore::CDATASection*>(WEBKIT_DOM_OBJECT(target)->coreObject);
85 return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
86}
87
88static void webkit_dom_cdata_section_dom_event_target_init(WebKitDOMEventTargetIface* iface)
89{
90 iface->dispatch_event = webkit_dom_cdata_section_dispatch_event;
91 iface->add_event_listener = webkit_dom_cdata_section_add_event_listener;
92 iface->remove_event_listener = webkit_dom_cdata_section_remove_event_listener;
93}
94
95G_DEFINE_TYPE_WITH_CODE(WebKitDOMCDATASection, webkit_dom_cdata_section, WEBKIT_DOM_TYPE_TEXT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_cdata_section_dom_event_target_init))
96
97static void webkit_dom_cdata_section_class_init(WebKitDOMCDATASectionClass* requestClass)
98{
99 UNUSED_PARAM(requestClass);
100}
101
102static void webkit_dom_cdata_section_init(WebKitDOMCDATASection* request)
103{
104 UNUSED_PARAM(request);
105}
106
107G_GNUC_END_IGNORE_DEPRECATIONS;
108