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 "WebKitDOMProcessingInstruction.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 "WebKitDOMEventPrivate.h" |
30 | #include "WebKitDOMEventTarget.h" |
31 | #include "WebKitDOMNodePrivate.h" |
32 | #include "WebKitDOMPrivate.h" |
33 | #include "WebKitDOMProcessingInstructionPrivate.h" |
34 | #include "WebKitDOMStyleSheetPrivate.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 | WebKitDOMProcessingInstruction* kit(WebCore::ProcessingInstruction* obj) |
44 | { |
45 | return WEBKIT_DOM_PROCESSING_INSTRUCTION(kit(static_cast<WebCore::Node*>(obj))); |
46 | } |
47 | |
48 | WebCore::ProcessingInstruction* core(WebKitDOMProcessingInstruction* request) |
49 | { |
50 | return request ? static_cast<WebCore::ProcessingInstruction*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
51 | } |
52 | |
53 | WebKitDOMProcessingInstruction* wrapProcessingInstruction(WebCore::ProcessingInstruction* coreObject) |
54 | { |
55 | ASSERT(coreObject); |
56 | return WEBKIT_DOM_PROCESSING_INSTRUCTION(g_object_new(WEBKIT_DOM_TYPE_PROCESSING_INSTRUCTION, "core-object" , coreObject, nullptr)); |
57 | } |
58 | |
59 | } // namespace WebKit |
60 | |
61 | static gboolean webkit_dom_processing_instruction_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) |
62 | { |
63 | WebCore::Event* coreEvent = WebKit::core(event); |
64 | if (!coreEvent) |
65 | return false; |
66 | WebCore::ProcessingInstruction* coreTarget = static_cast<WebCore::ProcessingInstruction*>(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_processing_instruction_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
78 | { |
79 | WebCore::ProcessingInstruction* coreTarget = static_cast<WebCore::ProcessingInstruction*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
80 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
81 | } |
82 | |
83 | static gboolean webkit_dom_processing_instruction_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
84 | { |
85 | WebCore::ProcessingInstruction* coreTarget = static_cast<WebCore::ProcessingInstruction*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
86 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
87 | } |
88 | |
89 | static void webkit_dom_processing_instruction_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
90 | { |
91 | iface->dispatch_event = webkit_dom_processing_instruction_dispatch_event; |
92 | iface->add_event_listener = webkit_dom_processing_instruction_add_event_listener; |
93 | iface->remove_event_listener = webkit_dom_processing_instruction_remove_event_listener; |
94 | } |
95 | |
96 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMProcessingInstruction, webkit_dom_processing_instruction, WEBKIT_DOM_TYPE_CHARACTER_DATA, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_processing_instruction_dom_event_target_init)) |
97 | |
98 | enum { |
99 | DOM_PROCESSING_INSTRUCTION_PROP_0, |
100 | DOM_PROCESSING_INSTRUCTION_PROP_TARGET, |
101 | DOM_PROCESSING_INSTRUCTION_PROP_SHEET, |
102 | }; |
103 | |
104 | static void webkit_dom_processing_instruction_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
105 | { |
106 | WebKitDOMProcessingInstruction* self = WEBKIT_DOM_PROCESSING_INSTRUCTION(object); |
107 | |
108 | switch (propertyId) { |
109 | case DOM_PROCESSING_INSTRUCTION_PROP_TARGET: |
110 | g_value_take_string(value, webkit_dom_processing_instruction_get_target(self)); |
111 | break; |
112 | case DOM_PROCESSING_INSTRUCTION_PROP_SHEET: |
113 | g_value_set_object(value, webkit_dom_processing_instruction_get_sheet(self)); |
114 | break; |
115 | default: |
116 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
117 | break; |
118 | } |
119 | } |
120 | |
121 | static void webkit_dom_processing_instruction_class_init(WebKitDOMProcessingInstructionClass* requestClass) |
122 | { |
123 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
124 | gobjectClass->get_property = webkit_dom_processing_instruction_get_property; |
125 | |
126 | g_object_class_install_property( |
127 | gobjectClass, |
128 | DOM_PROCESSING_INSTRUCTION_PROP_TARGET, |
129 | g_param_spec_string( |
130 | "target" , |
131 | "ProcessingInstruction:target" , |
132 | "read-only gchar* ProcessingInstruction:target" , |
133 | "" , |
134 | WEBKIT_PARAM_READABLE)); |
135 | |
136 | g_object_class_install_property( |
137 | gobjectClass, |
138 | DOM_PROCESSING_INSTRUCTION_PROP_SHEET, |
139 | g_param_spec_object( |
140 | "sheet" , |
141 | "ProcessingInstruction:sheet" , |
142 | "read-only WebKitDOMStyleSheet* ProcessingInstruction:sheet" , |
143 | WEBKIT_DOM_TYPE_STYLE_SHEET, |
144 | WEBKIT_PARAM_READABLE)); |
145 | |
146 | } |
147 | |
148 | static void webkit_dom_processing_instruction_init(WebKitDOMProcessingInstruction* request) |
149 | { |
150 | UNUSED_PARAM(request); |
151 | } |
152 | |
153 | gchar* webkit_dom_processing_instruction_get_target(WebKitDOMProcessingInstruction* self) |
154 | { |
155 | WebCore::JSMainThreadNullState state; |
156 | g_return_val_if_fail(WEBKIT_DOM_IS_PROCESSING_INSTRUCTION(self), 0); |
157 | WebCore::ProcessingInstruction* item = WebKit::core(self); |
158 | gchar* result = convertToUTF8String(item->target()); |
159 | return result; |
160 | } |
161 | |
162 | WebKitDOMStyleSheet* webkit_dom_processing_instruction_get_sheet(WebKitDOMProcessingInstruction* self) |
163 | { |
164 | WebCore::JSMainThreadNullState state; |
165 | g_return_val_if_fail(WEBKIT_DOM_IS_PROCESSING_INSTRUCTION(self), 0); |
166 | WebCore::ProcessingInstruction* item = WebKit::core(self); |
167 | RefPtr<WebCore::StyleSheet> gobjectResult = WTF::getPtr(item->sheet()); |
168 | return WebKit::kit(gobjectResult.get()); |
169 | } |
170 | |
171 | G_GNUC_END_IGNORE_DEPRECATIONS; |
172 | |