0be678aa03fc2100e542ffdb83edc013a3428b14
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMDocumentType.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 "WebKitDOMDocumentType.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/Document.h>
26 #include <WebCore/ExceptionCode.h>
27 #include <WebCore/ExceptionCodeDescription.h>
28 #include "GObjectEventListener.h"
29 #include <WebCore/JSMainThreadExecState.h>
30 #include "WebKitDOMDocumentTypePrivate.h"
31 #include "WebKitDOMEventPrivate.h"
32 #include "WebKitDOMEventTarget.h"
33 #include "WebKitDOMNamedNodeMapPrivate.h"
34 #include "WebKitDOMNodePrivate.h"
35 #include "WebKitDOMPrivate.h"
36 #include "ConvertToUTF8String.h"
37 #include <wtf/GetPtr.h>
38 #include <wtf/RefPtr.h>
39
40 namespace WebKit {
41
42 WebKitDOMDocumentType* kit(WebCore::DocumentType* obj)
43 {
44     return WEBKIT_DOM_DOCUMENT_TYPE(kit(static_cast<WebCore::Node*>(obj)));
45 }
46
47 WebCore::DocumentType* core(WebKitDOMDocumentType* request)
48 {
49     return request ? static_cast<WebCore::DocumentType*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
50 }
51
52 WebKitDOMDocumentType* wrapDocumentType(WebCore::DocumentType* coreObject)
53 {
54     ASSERT(coreObject);
55     return WEBKIT_DOM_DOCUMENT_TYPE(g_object_new(WEBKIT_DOM_TYPE_DOCUMENT_TYPE, "core-object", coreObject, nullptr));
56 }
57
58 } // namespace WebKit
59
60 static gboolean webkit_dom_document_type_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
61 {
62     WebCore::Event* coreEvent = WebKit::core(event);
63     if (!coreEvent)
64         return false;
65     WebCore::DocumentType* coreTarget = static_cast<WebCore::DocumentType*>(WEBKIT_DOM_OBJECT(target)->coreObject);
66
67     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
68     if (result.hasException()) {
69         WebCore::ExceptionCodeDescription description(result.releaseException().code());
70         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.code, description.name);
71         return false;
72     }
73     return result.releaseReturnValue();
74 }
75
76 static gboolean webkit_dom_document_type_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
77 {
78     WebCore::DocumentType* coreTarget = static_cast<WebCore::DocumentType*>(WEBKIT_DOM_OBJECT(target)->coreObject);
79     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
80 }
81
82 static gboolean webkit_dom_document_type_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
83 {
84     WebCore::DocumentType* coreTarget = static_cast<WebCore::DocumentType*>(WEBKIT_DOM_OBJECT(target)->coreObject);
85     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
86 }
87
88 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
89 {
90     iface->dispatch_event = webkit_dom_document_type_dispatch_event;
91     iface->add_event_listener = webkit_dom_document_type_add_event_listener;
92     iface->remove_event_listener = webkit_dom_document_type_remove_event_listener;
93 }
94
95 G_DEFINE_TYPE_WITH_CODE(WebKitDOMDocumentType, webkit_dom_document_type, WEBKIT_DOM_TYPE_NODE, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
96
97 enum {
98     PROP_0,
99     PROP_NAME,
100     PROP_ENTITIES,
101     PROP_NOTATIONS,
102     PROP_INTERNAL_SUBSET,
103     PROP_PUBLIC_ID,
104     PROP_SYSTEM_ID,
105 };
106
107 static void webkit_dom_document_type_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
108 {
109     WebKitDOMDocumentType* self = WEBKIT_DOM_DOCUMENT_TYPE(object);
110
111     switch (propertyId) {
112     case PROP_NAME:
113         g_value_take_string(value, webkit_dom_document_type_get_name(self));
114         break;
115     case PROP_ENTITIES:
116         g_value_set_object(value, webkit_dom_document_type_get_entities(self));
117         break;
118     case PROP_NOTATIONS:
119         g_value_set_object(value, webkit_dom_document_type_get_notations(self));
120         break;
121     case PROP_INTERNAL_SUBSET:
122         g_value_take_string(value, webkit_dom_document_type_get_internal_subset(self));
123         break;
124     case PROP_PUBLIC_ID:
125         g_value_take_string(value, webkit_dom_document_type_get_public_id(self));
126         break;
127     case PROP_SYSTEM_ID:
128         g_value_take_string(value, webkit_dom_document_type_get_system_id(self));
129         break;
130     default:
131         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
132         break;
133     }
134 }
135
136 static void webkit_dom_document_type_class_init(WebKitDOMDocumentTypeClass* requestClass)
137 {
138     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
139     gobjectClass->get_property = webkit_dom_document_type_get_property;
140
141     g_object_class_install_property(
142         gobjectClass,
143         PROP_NAME,
144         g_param_spec_string(
145             "name",
146             "DocumentType:name",
147             "read-only gchar* DocumentType:name",
148             "",
149             WEBKIT_PARAM_READABLE));
150
151     g_object_class_install_property(
152         gobjectClass,
153         PROP_ENTITIES,
154         g_param_spec_object(
155             "entities",
156             "DocumentType:entities",
157             "read-only WebKitDOMNamedNodeMap* DocumentType:entities",
158             WEBKIT_DOM_TYPE_NAMED_NODE_MAP,
159             WEBKIT_PARAM_READABLE));
160
161     g_object_class_install_property(
162         gobjectClass,
163         PROP_NOTATIONS,
164         g_param_spec_object(
165             "notations",
166             "DocumentType:notations",
167             "read-only WebKitDOMNamedNodeMap* DocumentType:notations",
168             WEBKIT_DOM_TYPE_NAMED_NODE_MAP,
169             WEBKIT_PARAM_READABLE));
170
171     g_object_class_install_property(
172         gobjectClass,
173         PROP_INTERNAL_SUBSET,
174         g_param_spec_string(
175             "internal-subset",
176             "DocumentType:internal-subset",
177             "read-only gchar* DocumentType:internal-subset",
178             "",
179             WEBKIT_PARAM_READABLE));
180
181     g_object_class_install_property(
182         gobjectClass,
183         PROP_PUBLIC_ID,
184         g_param_spec_string(
185             "public-id",
186             "DocumentType:public-id",
187             "read-only gchar* DocumentType:public-id",
188             "",
189             WEBKIT_PARAM_READABLE));
190
191     g_object_class_install_property(
192         gobjectClass,
193         PROP_SYSTEM_ID,
194         g_param_spec_string(
195             "system-id",
196             "DocumentType:system-id",
197             "read-only gchar* DocumentType:system-id",
198             "",
199             WEBKIT_PARAM_READABLE));
200
201 }
202
203 static void webkit_dom_document_type_init(WebKitDOMDocumentType* request)
204 {
205     UNUSED_PARAM(request);
206 }
207
208 gchar* webkit_dom_document_type_get_name(WebKitDOMDocumentType* self)
209 {
210     WebCore::JSMainThreadNullState state;
211     g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT_TYPE(self), 0);
212     WebCore::DocumentType* item = WebKit::core(self);
213     gchar* result = convertToUTF8String(item->name());
214     return result;
215 }
216
217 WebKitDOMNamedNodeMap* webkit_dom_document_type_get_entities(WebKitDOMDocumentType* self)
218 {
219     g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT_TYPE(self), nullptr);
220     return nullptr;
221 }
222
223 WebKitDOMNamedNodeMap* webkit_dom_document_type_get_notations(WebKitDOMDocumentType* self)
224 {
225     g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT_TYPE(self), nullptr);
226     return nullptr;
227 }
228
229 gchar* webkit_dom_document_type_get_internal_subset(WebKitDOMDocumentType* self)
230 {
231     g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT_TYPE(self), nullptr);
232     return nullptr;
233 }
234
235 gchar* webkit_dom_document_type_get_public_id(WebKitDOMDocumentType* self)
236 {
237     WebCore::JSMainThreadNullState state;
238     g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT_TYPE(self), 0);
239     WebCore::DocumentType* item = WebKit::core(self);
240     gchar* result = convertToUTF8String(item->publicId());
241     return result;
242 }
243
244 gchar* webkit_dom_document_type_get_system_id(WebKitDOMDocumentType* self)
245 {
246     WebCore::JSMainThreadNullState state;
247     g_return_val_if_fail(WEBKIT_DOM_IS_DOCUMENT_TYPE(self), 0);
248     WebCore::DocumentType* item = WebKit::core(self);
249     gchar* result = convertToUTF8String(item->systemId());
250     return result;
251 }
252