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 "WebKitDOMDOMWindow.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 <WebCore/SerializedScriptValue.h>
30#include <WebCore/UserMessageHandlersNamespace.h>
31#include <WebCore/WebKitNamespace.h>
32#include <WebCore/WindowProxy.h>
33#include "WebKitDOMCSSStyleDeclarationPrivate.h"
34#include "WebKitDOMDOMSelectionPrivate.h"
35#include "WebKitDOMDOMWindowPrivate.h"
36#include "WebKitDOMDocumentPrivate.h"
37#include "WebKitDOMElementPrivate.h"
38#include "WebKitDOMEventPrivate.h"
39#include "WebKitDOMEventTarget.h"
40#include "WebKitDOMNodePrivate.h"
41#include "WebKitDOMPrivate.h"
42#include "ConvertToUTF8String.h"
43#include <wtf/GetPtr.h>
44#include <wtf/RefPtr.h>
45
46#define WEBKIT_DOM_DOM_WINDOW_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_DOM_WINDOW, WebKitDOMDOMWindowPrivate)
47
48typedef struct _WebKitDOMDOMWindowPrivate {
49 RefPtr<WebCore::DOMWindow> coreObject;
50} WebKitDOMDOMWindowPrivate;
51
52G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
53
54namespace WebKit {
55
56WebKitDOMDOMWindow* kit(WebCore::DOMWindow* obj)
57{
58 if (!obj)
59 return 0;
60
61 if (gpointer ret = DOMObjectCache::get(obj))
62 return WEBKIT_DOM_DOM_WINDOW(ret);
63
64 return wrapDOMWindow(obj);
65}
66
67WebKitDOMDOMWindow* kit(WebCore::WindowProxy* windowProxy)
68{
69 if (!windowProxy || !is<WebCore::DOMWindow>(windowProxy->window()))
70 return nullptr;
71
72 return kit(downcast<WebCore::DOMWindow>(windowProxy->window()));
73}
74
75WebCore::WindowProxy* toWindowProxy(WebKitDOMDOMWindow* view)
76{
77 auto* window = core(view);
78 if (!window || !window->frame())
79 return nullptr;
80 return &window->frame()->windowProxy();
81}
82
83WebCore::DOMWindow* core(WebKitDOMDOMWindow* request)
84{
85 return request ? static_cast<WebCore::DOMWindow*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
86}
87
88WebKitDOMDOMWindow* wrapDOMWindow(WebCore::DOMWindow* coreObject)
89{
90 ASSERT(coreObject);
91 return WEBKIT_DOM_DOM_WINDOW(g_object_new(WEBKIT_DOM_TYPE_DOM_WINDOW, "core-object", coreObject, nullptr));
92}
93
94} // namespace WebKit
95
96static gboolean webkit_dom_dom_window_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
97{
98 WebCore::Event* coreEvent = WebKit::core(event);
99 if (!coreEvent)
100 return false;
101 WebCore::DOMWindow* coreTarget = static_cast<WebCore::DOMWindow*>(WEBKIT_DOM_OBJECT(target)->coreObject);
102
103 auto result = coreTarget->dispatchEventForBindings(*coreEvent);
104 if (result.hasException()) {
105 auto description = WebCore::DOMException::description(result.releaseException().code());
106 g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
107 return false;
108 }
109 return result.releaseReturnValue();
110}
111
112static gboolean webkit_dom_dom_window_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
113{
114 WebCore::DOMWindow* coreTarget = static_cast<WebCore::DOMWindow*>(WEBKIT_DOM_OBJECT(target)->coreObject);
115 return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
116}
117
118static gboolean webkit_dom_dom_window_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
119{
120 WebCore::DOMWindow* coreTarget = static_cast<WebCore::DOMWindow*>(WEBKIT_DOM_OBJECT(target)->coreObject);
121 return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
122}
123
124static void webkit_dom_dom_window_dom_event_target_init(WebKitDOMEventTargetIface* iface)
125{
126 iface->dispatch_event = webkit_dom_dom_window_dispatch_event;
127 iface->add_event_listener = webkit_dom_dom_window_add_event_listener;
128 iface->remove_event_listener = webkit_dom_dom_window_remove_event_listener;
129}
130
131G_DEFINE_TYPE_WITH_CODE(WebKitDOMDOMWindow, webkit_dom_dom_window, WEBKIT_DOM_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_dom_window_dom_event_target_init))
132
133enum {
134 DOM_WINDOW_PROP_0,
135 DOM_WINDOW_PROP_FRAME_ELEMENT,
136 DOM_WINDOW_PROP_OFFSCREEN_BUFFERING,
137 DOM_WINDOW_PROP_OUTER_HEIGHT,
138 DOM_WINDOW_PROP_OUTER_WIDTH,
139 DOM_WINDOW_PROP_INNER_HEIGHT,
140 DOM_WINDOW_PROP_INNER_WIDTH,
141 DOM_WINDOW_PROP_SCREEN_X,
142 DOM_WINDOW_PROP_SCREEN_Y,
143 DOM_WINDOW_PROP_SCREEN_LEFT,
144 DOM_WINDOW_PROP_SCREEN_TOP,
145 DOM_WINDOW_PROP_SCROLL_X,
146 DOM_WINDOW_PROP_SCROLL_Y,
147 DOM_WINDOW_PROP_PAGE_X_OFFSET,
148 DOM_WINDOW_PROP_PAGE_Y_OFFSET,
149 DOM_WINDOW_PROP_CLOSED,
150 DOM_WINDOW_PROP_LENGTH,
151 DOM_WINDOW_PROP_NAME,
152 DOM_WINDOW_PROP_STATUS,
153 DOM_WINDOW_PROP_DEFAULT_STATUS,
154 DOM_WINDOW_PROP_SELF,
155 DOM_WINDOW_PROP_WINDOW,
156 DOM_WINDOW_PROP_FRAMES,
157 DOM_WINDOW_PROP_OPENER,
158 DOM_WINDOW_PROP_PARENT,
159 DOM_WINDOW_PROP_TOP,
160 DOM_WINDOW_PROP_DOCUMENT,
161 DOM_WINDOW_PROP_DEVICE_PIXEL_RATIO,
162 DOM_WINDOW_PROP_ORIENTATION,
163};
164
165static void webkit_dom_dom_window_finalize(GObject* object)
166{
167 WebKitDOMDOMWindowPrivate* priv = WEBKIT_DOM_DOM_WINDOW_GET_PRIVATE(object);
168
169 WebKit::DOMObjectCache::forget(priv->coreObject.get());
170
171 priv->~WebKitDOMDOMWindowPrivate();
172 G_OBJECT_CLASS(webkit_dom_dom_window_parent_class)->finalize(object);
173}
174
175static void webkit_dom_dom_window_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
176{
177 WebKitDOMDOMWindow* self = WEBKIT_DOM_DOM_WINDOW(object);
178
179 switch (propertyId) {
180 case DOM_WINDOW_PROP_NAME:
181 webkit_dom_dom_window_set_name(self, g_value_get_string(value));
182 break;
183 case DOM_WINDOW_PROP_STATUS:
184 webkit_dom_dom_window_set_status(self, g_value_get_string(value));
185 break;
186 case DOM_WINDOW_PROP_DEFAULT_STATUS:
187 webkit_dom_dom_window_set_default_status(self, g_value_get_string(value));
188 break;
189 default:
190 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
191 break;
192 }
193}
194
195static void webkit_dom_dom_window_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
196{
197 WebKitDOMDOMWindow* self = WEBKIT_DOM_DOM_WINDOW(object);
198
199 switch (propertyId) {
200 case DOM_WINDOW_PROP_FRAME_ELEMENT:
201 g_value_set_object(value, webkit_dom_dom_window_get_frame_element(self));
202 break;
203 case DOM_WINDOW_PROP_OFFSCREEN_BUFFERING:
204 g_value_set_boolean(value, webkit_dom_dom_window_get_offscreen_buffering(self));
205 break;
206 case DOM_WINDOW_PROP_OUTER_HEIGHT:
207 g_value_set_long(value, webkit_dom_dom_window_get_outer_height(self));
208 break;
209 case DOM_WINDOW_PROP_OUTER_WIDTH:
210 g_value_set_long(value, webkit_dom_dom_window_get_outer_width(self));
211 break;
212 case DOM_WINDOW_PROP_INNER_HEIGHT:
213 g_value_set_long(value, webkit_dom_dom_window_get_inner_height(self));
214 break;
215 case DOM_WINDOW_PROP_INNER_WIDTH:
216 g_value_set_long(value, webkit_dom_dom_window_get_inner_width(self));
217 break;
218 case DOM_WINDOW_PROP_SCREEN_X:
219 g_value_set_long(value, webkit_dom_dom_window_get_screen_x(self));
220 break;
221 case DOM_WINDOW_PROP_SCREEN_Y:
222 g_value_set_long(value, webkit_dom_dom_window_get_screen_y(self));
223 break;
224 case DOM_WINDOW_PROP_SCREEN_LEFT:
225 g_value_set_long(value, webkit_dom_dom_window_get_screen_left(self));
226 break;
227 case DOM_WINDOW_PROP_SCREEN_TOP:
228 g_value_set_long(value, webkit_dom_dom_window_get_screen_top(self));
229 break;
230 case DOM_WINDOW_PROP_SCROLL_X:
231 g_value_set_long(value, webkit_dom_dom_window_get_scroll_x(self));
232 break;
233 case DOM_WINDOW_PROP_SCROLL_Y:
234 g_value_set_long(value, webkit_dom_dom_window_get_scroll_y(self));
235 break;
236 case DOM_WINDOW_PROP_PAGE_X_OFFSET:
237 g_value_set_long(value, webkit_dom_dom_window_get_page_x_offset(self));
238 break;
239 case DOM_WINDOW_PROP_PAGE_Y_OFFSET:
240 g_value_set_long(value, webkit_dom_dom_window_get_page_y_offset(self));
241 break;
242 case DOM_WINDOW_PROP_CLOSED:
243 g_value_set_boolean(value, webkit_dom_dom_window_get_closed(self));
244 break;
245 case DOM_WINDOW_PROP_LENGTH:
246 g_value_set_ulong(value, webkit_dom_dom_window_get_length(self));
247 break;
248 case DOM_WINDOW_PROP_NAME:
249 g_value_take_string(value, webkit_dom_dom_window_get_name(self));
250 break;
251 case DOM_WINDOW_PROP_STATUS:
252 g_value_take_string(value, webkit_dom_dom_window_get_status(self));
253 break;
254 case DOM_WINDOW_PROP_DEFAULT_STATUS:
255 g_value_take_string(value, webkit_dom_dom_window_get_default_status(self));
256 break;
257 case DOM_WINDOW_PROP_SELF:
258 g_value_set_object(value, webkit_dom_dom_window_get_self(self));
259 break;
260 case DOM_WINDOW_PROP_WINDOW:
261 g_value_set_object(value, webkit_dom_dom_window_get_window(self));
262 break;
263 case DOM_WINDOW_PROP_FRAMES:
264 g_value_set_object(value, webkit_dom_dom_window_get_frames(self));
265 break;
266 case DOM_WINDOW_PROP_OPENER:
267 g_value_set_object(value, webkit_dom_dom_window_get_opener(self));
268 break;
269 case DOM_WINDOW_PROP_PARENT:
270 g_value_set_object(value, webkit_dom_dom_window_get_parent(self));
271 break;
272 case DOM_WINDOW_PROP_TOP:
273 g_value_set_object(value, webkit_dom_dom_window_get_top(self));
274 break;
275 case DOM_WINDOW_PROP_DOCUMENT:
276 g_value_set_object(value, webkit_dom_dom_window_get_document(self));
277 break;
278 case DOM_WINDOW_PROP_DEVICE_PIXEL_RATIO:
279 g_value_set_double(value, webkit_dom_dom_window_get_device_pixel_ratio(self));
280 break;
281 case DOM_WINDOW_PROP_ORIENTATION:
282 g_value_set_long(value, webkit_dom_dom_window_get_orientation(self));
283 break;
284 default:
285 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
286 break;
287 }
288}
289
290static GObject* webkit_dom_dom_window_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties)
291{
292 GObject* object = G_OBJECT_CLASS(webkit_dom_dom_window_parent_class)->constructor(type, constructPropertiesCount, constructProperties);
293
294 WebKitDOMDOMWindowPrivate* priv = WEBKIT_DOM_DOM_WINDOW_GET_PRIVATE(object);
295 priv->coreObject = static_cast<WebCore::DOMWindow*>(WEBKIT_DOM_OBJECT(object)->coreObject);
296 WebKit::DOMObjectCache::put(priv->coreObject.get(), object);
297
298 return object;
299}
300
301static void webkit_dom_dom_window_class_init(WebKitDOMDOMWindowClass* requestClass)
302{
303 GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
304 g_type_class_add_private(gobjectClass, sizeof(WebKitDOMDOMWindowPrivate));
305 gobjectClass->constructor = webkit_dom_dom_window_constructor;
306 gobjectClass->finalize = webkit_dom_dom_window_finalize;
307 gobjectClass->set_property = webkit_dom_dom_window_set_property;
308 gobjectClass->get_property = webkit_dom_dom_window_get_property;
309
310 g_object_class_install_property(
311 gobjectClass,
312 DOM_WINDOW_PROP_FRAME_ELEMENT,
313 g_param_spec_object(
314 "frame-element",
315 "DOMWindow:frame-element",
316 "read-only WebKitDOMElement* DOMWindow:frame-element",
317 WEBKIT_DOM_TYPE_ELEMENT,
318 WEBKIT_PARAM_READABLE));
319
320 g_object_class_install_property(
321 gobjectClass,
322 DOM_WINDOW_PROP_OFFSCREEN_BUFFERING,
323 g_param_spec_boolean(
324 "offscreen-buffering",
325 "DOMWindow:offscreen-buffering",
326 "read-only gboolean DOMWindow:offscreen-buffering",
327 FALSE,
328 WEBKIT_PARAM_READABLE));
329
330 g_object_class_install_property(
331 gobjectClass,
332 DOM_WINDOW_PROP_OUTER_HEIGHT,
333 g_param_spec_long(
334 "outer-height",
335 "DOMWindow:outer-height",
336 "read-only glong DOMWindow:outer-height",
337 G_MINLONG, G_MAXLONG, 0,
338 WEBKIT_PARAM_READABLE));
339
340 g_object_class_install_property(
341 gobjectClass,
342 DOM_WINDOW_PROP_OUTER_WIDTH,
343 g_param_spec_long(
344 "outer-width",
345 "DOMWindow:outer-width",
346 "read-only glong DOMWindow:outer-width",
347 G_MINLONG, G_MAXLONG, 0,
348 WEBKIT_PARAM_READABLE));
349
350 g_object_class_install_property(
351 gobjectClass,
352 DOM_WINDOW_PROP_INNER_HEIGHT,
353 g_param_spec_long(
354 "inner-height",
355 "DOMWindow:inner-height",
356 "read-only glong DOMWindow:inner-height",
357 G_MINLONG, G_MAXLONG, 0,
358 WEBKIT_PARAM_READABLE));
359
360 g_object_class_install_property(
361 gobjectClass,
362 DOM_WINDOW_PROP_INNER_WIDTH,
363 g_param_spec_long(
364 "inner-width",
365 "DOMWindow:inner-width",
366 "read-only glong DOMWindow:inner-width",
367 G_MINLONG, G_MAXLONG, 0,
368 WEBKIT_PARAM_READABLE));
369
370 g_object_class_install_property(
371 gobjectClass,
372 DOM_WINDOW_PROP_SCREEN_X,
373 g_param_spec_long(
374 "screen-x",
375 "DOMWindow:screen-x",
376 "read-only glong DOMWindow:screen-x",
377 G_MINLONG, G_MAXLONG, 0,
378 WEBKIT_PARAM_READABLE));
379
380 g_object_class_install_property(
381 gobjectClass,
382 DOM_WINDOW_PROP_SCREEN_Y,
383 g_param_spec_long(
384 "screen-y",
385 "DOMWindow:screen-y",
386 "read-only glong DOMWindow:screen-y",
387 G_MINLONG, G_MAXLONG, 0,
388 WEBKIT_PARAM_READABLE));
389
390 g_object_class_install_property(
391 gobjectClass,
392 DOM_WINDOW_PROP_SCREEN_LEFT,
393 g_param_spec_long(
394 "screen-left",
395 "DOMWindow:screen-left",
396 "read-only glong DOMWindow:screen-left",
397 G_MINLONG, G_MAXLONG, 0,
398 WEBKIT_PARAM_READABLE));
399
400 g_object_class_install_property(
401 gobjectClass,
402 DOM_WINDOW_PROP_SCREEN_TOP,
403 g_param_spec_long(
404 "screen-top",
405 "DOMWindow:screen-top",
406 "read-only glong DOMWindow:screen-top",
407 G_MINLONG, G_MAXLONG, 0,
408 WEBKIT_PARAM_READABLE));
409
410 g_object_class_install_property(
411 gobjectClass,
412 DOM_WINDOW_PROP_SCROLL_X,
413 g_param_spec_long(
414 "scroll-x",
415 "DOMWindow:scroll-x",
416 "read-only glong DOMWindow:scroll-x",
417 G_MINLONG, G_MAXLONG, 0,
418 WEBKIT_PARAM_READABLE));
419
420 g_object_class_install_property(
421 gobjectClass,
422 DOM_WINDOW_PROP_SCROLL_Y,
423 g_param_spec_long(
424 "scroll-y",
425 "DOMWindow:scroll-y",
426 "read-only glong DOMWindow:scroll-y",
427 G_MINLONG, G_MAXLONG, 0,
428 WEBKIT_PARAM_READABLE));
429
430 g_object_class_install_property(
431 gobjectClass,
432 DOM_WINDOW_PROP_PAGE_X_OFFSET,
433 g_param_spec_long(
434 "page-x-offset",
435 "DOMWindow:page-x-offset",
436 "read-only glong DOMWindow:page-x-offset",
437 G_MINLONG, G_MAXLONG, 0,
438 WEBKIT_PARAM_READABLE));
439
440 g_object_class_install_property(
441 gobjectClass,
442 DOM_WINDOW_PROP_PAGE_Y_OFFSET,
443 g_param_spec_long(
444 "page-y-offset",
445 "DOMWindow:page-y-offset",
446 "read-only glong DOMWindow:page-y-offset",
447 G_MINLONG, G_MAXLONG, 0,
448 WEBKIT_PARAM_READABLE));
449
450 g_object_class_install_property(
451 gobjectClass,
452 DOM_WINDOW_PROP_CLOSED,
453 g_param_spec_boolean(
454 "closed",
455 "DOMWindow:closed",
456 "read-only gboolean DOMWindow:closed",
457 FALSE,
458 WEBKIT_PARAM_READABLE));
459
460 g_object_class_install_property(
461 gobjectClass,
462 DOM_WINDOW_PROP_LENGTH,
463 g_param_spec_ulong(
464 "length",
465 "DOMWindow:length",
466 "read-only gulong DOMWindow:length",
467 0, G_MAXULONG, 0,
468 WEBKIT_PARAM_READABLE));
469
470 g_object_class_install_property(
471 gobjectClass,
472 DOM_WINDOW_PROP_NAME,
473 g_param_spec_string(
474 "name",
475 "DOMWindow:name",
476 "read-write gchar* DOMWindow:name",
477 "",
478 WEBKIT_PARAM_READWRITE));
479
480 g_object_class_install_property(
481 gobjectClass,
482 DOM_WINDOW_PROP_STATUS,
483 g_param_spec_string(
484 "status",
485 "DOMWindow:status",
486 "read-write gchar* DOMWindow:status",
487 "",
488 WEBKIT_PARAM_READWRITE));
489
490 g_object_class_install_property(
491 gobjectClass,
492 DOM_WINDOW_PROP_DEFAULT_STATUS,
493 g_param_spec_string(
494 "default-status",
495 "DOMWindow:default-status",
496 "read-write gchar* DOMWindow:default-status",
497 "",
498 WEBKIT_PARAM_READWRITE));
499
500 g_object_class_install_property(
501 gobjectClass,
502 DOM_WINDOW_PROP_SELF,
503 g_param_spec_object(
504 "self",
505 "DOMWindow:self",
506 "read-only WebKitDOMDOMWindow* DOMWindow:self",
507 WEBKIT_DOM_TYPE_DOM_WINDOW,
508 WEBKIT_PARAM_READABLE));
509
510 g_object_class_install_property(
511 gobjectClass,
512 DOM_WINDOW_PROP_WINDOW,
513 g_param_spec_object(
514 "window",
515 "DOMWindow:window",
516 "read-only WebKitDOMDOMWindow* DOMWindow:window",
517 WEBKIT_DOM_TYPE_DOM_WINDOW,
518 WEBKIT_PARAM_READABLE));
519
520 g_object_class_install_property(
521 gobjectClass,
522 DOM_WINDOW_PROP_FRAMES,
523 g_param_spec_object(
524 "frames",
525 "DOMWindow:frames",
526 "read-only WebKitDOMDOMWindow* DOMWindow:frames",
527 WEBKIT_DOM_TYPE_DOM_WINDOW,
528 WEBKIT_PARAM_READABLE));
529
530 g_object_class_install_property(
531 gobjectClass,
532 DOM_WINDOW_PROP_OPENER,
533 g_param_spec_object(
534 "opener",
535 "DOMWindow:opener",
536 "read-only WebKitDOMDOMWindow* DOMWindow:opener",
537 WEBKIT_DOM_TYPE_DOM_WINDOW,
538 WEBKIT_PARAM_READABLE));
539
540 g_object_class_install_property(
541 gobjectClass,
542 DOM_WINDOW_PROP_PARENT,
543 g_param_spec_object(
544 "parent",
545 "DOMWindow:parent",
546 "read-only WebKitDOMDOMWindow* DOMWindow:parent",
547 WEBKIT_DOM_TYPE_DOM_WINDOW,
548 WEBKIT_PARAM_READABLE));
549
550 g_object_class_install_property(
551 gobjectClass,
552 DOM_WINDOW_PROP_TOP,
553 g_param_spec_object(
554 "top",
555 "DOMWindow:top",
556 "read-only WebKitDOMDOMWindow* DOMWindow:top",
557 WEBKIT_DOM_TYPE_DOM_WINDOW,
558 WEBKIT_PARAM_READABLE));
559
560 g_object_class_install_property(
561 gobjectClass,
562 DOM_WINDOW_PROP_DOCUMENT,
563 g_param_spec_object(
564 "document",
565 "DOMWindow:document",
566 "read-only WebKitDOMDocument* DOMWindow:document",
567 WEBKIT_DOM_TYPE_DOCUMENT,
568 WEBKIT_PARAM_READABLE));
569
570 g_object_class_install_property(
571 gobjectClass,
572 DOM_WINDOW_PROP_DEVICE_PIXEL_RATIO,
573 g_param_spec_double(
574 "device-pixel-ratio",
575 "DOMWindow:device-pixel-ratio",
576 "read-only gdouble DOMWindow:device-pixel-ratio",
577 -G_MAXDOUBLE, G_MAXDOUBLE, 0,
578 WEBKIT_PARAM_READABLE));
579
580 g_object_class_install_property(
581 gobjectClass,
582 DOM_WINDOW_PROP_ORIENTATION,
583 g_param_spec_long(
584 "orientation",
585 "DOMWindow:orientation",
586 "read-only glong DOMWindow:orientation",
587 G_MINLONG, G_MAXLONG, 0,
588 WEBKIT_PARAM_READABLE));
589}
590
591static void webkit_dom_dom_window_init(WebKitDOMDOMWindow* request)
592{
593 WebKitDOMDOMWindowPrivate* priv = WEBKIT_DOM_DOM_WINDOW_GET_PRIVATE(request);
594 new (priv) WebKitDOMDOMWindowPrivate();
595}
596
597WebKitDOMDOMSelection* webkit_dom_dom_window_get_selection(WebKitDOMDOMWindow* self)
598{
599 WebCore::JSMainThreadNullState state;
600 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
601 WebCore::DOMWindow* item = WebKit::core(self);
602 RefPtr<WebCore::DOMSelection> gobjectResult = WTF::getPtr(item->getSelection());
603 return WebKit::kit(gobjectResult.get());
604}
605
606void webkit_dom_dom_window_focus(WebKitDOMDOMWindow* self)
607{
608 WebCore::JSMainThreadNullState state;
609 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
610 WebCore::DOMWindow* item = WebKit::core(self);
611 item->focus();
612}
613
614void webkit_dom_dom_window_blur(WebKitDOMDOMWindow* self)
615{
616 WebCore::JSMainThreadNullState state;
617 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
618 WebCore::DOMWindow* item = WebKit::core(self);
619 item->blur();
620}
621
622void webkit_dom_dom_window_close(WebKitDOMDOMWindow* self)
623{
624 WebCore::JSMainThreadNullState state;
625 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
626 WebCore::DOMWindow* item = WebKit::core(self);
627 item->close();
628}
629
630void webkit_dom_dom_window_print(WebKitDOMDOMWindow* self)
631{
632 WebCore::JSMainThreadNullState state;
633 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
634 WebCore::DOMWindow* item = WebKit::core(self);
635 item->print();
636}
637
638void webkit_dom_dom_window_stop(WebKitDOMDOMWindow* self)
639{
640 WebCore::JSMainThreadNullState state;
641 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
642 WebCore::DOMWindow* item = WebKit::core(self);
643 item->stop();
644}
645
646void webkit_dom_dom_window_alert(WebKitDOMDOMWindow* self, const gchar* message)
647{
648 WebCore::JSMainThreadNullState state;
649 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
650 g_return_if_fail(message);
651 WebCore::DOMWindow* item = WebKit::core(self);
652 WTF::String convertedMessage = WTF::String::fromUTF8(message);
653 item->alert(convertedMessage);
654}
655
656gboolean webkit_dom_dom_window_confirm(WebKitDOMDOMWindow* self, const gchar* message)
657{
658 WebCore::JSMainThreadNullState state;
659 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), FALSE);
660 g_return_val_if_fail(message, FALSE);
661 WebCore::DOMWindow* item = WebKit::core(self);
662 WTF::String convertedMessage = WTF::String::fromUTF8(message);
663 gboolean result = item->confirm(convertedMessage);
664 return result;
665}
666
667gchar* webkit_dom_dom_window_prompt(WebKitDOMDOMWindow* self, const gchar* message, const gchar* defaultValue)
668{
669 WebCore::JSMainThreadNullState state;
670 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
671 g_return_val_if_fail(message, 0);
672 g_return_val_if_fail(defaultValue, 0);
673 WebCore::DOMWindow* item = WebKit::core(self);
674 WTF::String convertedMessage = WTF::String::fromUTF8(message);
675 WTF::String convertedDefaultValue = WTF::String::fromUTF8(defaultValue);
676 gchar* result = convertToUTF8String(item->prompt(convertedMessage, convertedDefaultValue));
677 return result;
678}
679
680gboolean webkit_dom_dom_window_find(WebKitDOMDOMWindow* self, const gchar* string, gboolean caseSensitive, gboolean backwards, gboolean wrap, gboolean wholeWord, gboolean searchInFrames, gboolean showDialog)
681{
682 WebCore::JSMainThreadNullState state;
683 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), FALSE);
684 g_return_val_if_fail(string, FALSE);
685 WebCore::DOMWindow* item = WebKit::core(self);
686 WTF::String convertedString = WTF::String::fromUTF8(string);
687 gboolean result = item->find(convertedString, caseSensitive, backwards, wrap, wholeWord, searchInFrames, showDialog);
688 return result;
689}
690
691void webkit_dom_dom_window_scroll_by(WebKitDOMDOMWindow* self, gdouble x, gdouble y)
692{
693 WebCore::JSMainThreadNullState state;
694 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
695 WebCore::DOMWindow* item = WebKit::core(self);
696 item->scrollBy(x, y);
697}
698
699void webkit_dom_dom_window_scroll_to(WebKitDOMDOMWindow* self, gdouble x, gdouble y)
700{
701 WebCore::JSMainThreadNullState state;
702 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
703 WebCore::DOMWindow* item = WebKit::core(self);
704 item->scrollTo(x, y);
705}
706
707void webkit_dom_dom_window_move_by(WebKitDOMDOMWindow* self, gfloat x, gfloat y)
708{
709 WebCore::JSMainThreadNullState state;
710 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
711 WebCore::DOMWindow* item = WebKit::core(self);
712 item->moveBy(x, y);
713}
714
715void webkit_dom_dom_window_move_to(WebKitDOMDOMWindow* self, gfloat x, gfloat y)
716{
717 WebCore::JSMainThreadNullState state;
718 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
719 WebCore::DOMWindow* item = WebKit::core(self);
720 item->moveTo(x, y);
721}
722
723void webkit_dom_dom_window_resize_by(WebKitDOMDOMWindow* self, gfloat x, gfloat y)
724{
725 WebCore::JSMainThreadNullState state;
726 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
727 WebCore::DOMWindow* item = WebKit::core(self);
728 item->resizeBy(x, y);
729}
730
731void webkit_dom_dom_window_resize_to(WebKitDOMDOMWindow* self, gfloat width, gfloat height)
732{
733 WebCore::JSMainThreadNullState state;
734 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
735 WebCore::DOMWindow* item = WebKit::core(self);
736 item->resizeTo(width, height);
737}
738
739WebKitDOMCSSStyleDeclaration* webkit_dom_dom_window_get_computed_style(WebKitDOMDOMWindow* self, WebKitDOMElement* element, const gchar* pseudoElement)
740{
741 WebCore::JSMainThreadNullState state;
742 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
743 g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(element), 0);
744 WebCore::DOMWindow* item = WebKit::core(self);
745 WebCore::Element* convertedElement = WebKit::core(element);
746 WTF::String convertedPseudoElement = WTF::String::fromUTF8(pseudoElement);
747 RefPtr<WebCore::CSSStyleDeclaration> gobjectResult = WTF::getPtr(item->getComputedStyle(*convertedElement, convertedPseudoElement));
748 return WebKit::kit(gobjectResult.get());
749}
750
751void webkit_dom_dom_window_capture_events(WebKitDOMDOMWindow* self)
752{
753 WebCore::JSMainThreadNullState state;
754 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
755 WebCore::DOMWindow* item = WebKit::core(self);
756 item->captureEvents();
757}
758
759void webkit_dom_dom_window_release_events(WebKitDOMDOMWindow* self)
760{
761 WebCore::JSMainThreadNullState state;
762 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
763 WebCore::DOMWindow* item = WebKit::core(self);
764 item->releaseEvents();
765}
766
767WebKitDOMElement* webkit_dom_dom_window_get_frame_element(WebKitDOMDOMWindow* self)
768{
769 WebCore::JSMainThreadNullState state;
770 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
771 WebCore::DOMWindow* item = WebKit::core(self);
772 RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->frameElement());
773 return WebKit::kit(gobjectResult.get());
774}
775
776gboolean webkit_dom_dom_window_get_offscreen_buffering(WebKitDOMDOMWindow* self)
777{
778 WebCore::JSMainThreadNullState state;
779 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), FALSE);
780 WebCore::DOMWindow* item = WebKit::core(self);
781 gboolean result = item->offscreenBuffering();
782 return result;
783}
784
785glong webkit_dom_dom_window_get_outer_height(WebKitDOMDOMWindow* self)
786{
787 WebCore::JSMainThreadNullState state;
788 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
789 WebCore::DOMWindow* item = WebKit::core(self);
790 glong result = item->outerHeight();
791 return result;
792}
793
794glong webkit_dom_dom_window_get_outer_width(WebKitDOMDOMWindow* self)
795{
796 WebCore::JSMainThreadNullState state;
797 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
798 WebCore::DOMWindow* item = WebKit::core(self);
799 glong result = item->outerWidth();
800 return result;
801}
802
803glong webkit_dom_dom_window_get_inner_height(WebKitDOMDOMWindow* self)
804{
805 WebCore::JSMainThreadNullState state;
806 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
807 WebCore::DOMWindow* item = WebKit::core(self);
808 glong result = item->innerHeight();
809 return result;
810}
811
812glong webkit_dom_dom_window_get_inner_width(WebKitDOMDOMWindow* self)
813{
814 WebCore::JSMainThreadNullState state;
815 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
816 WebCore::DOMWindow* item = WebKit::core(self);
817 glong result = item->innerWidth();
818 return result;
819}
820
821glong webkit_dom_dom_window_get_screen_x(WebKitDOMDOMWindow* self)
822{
823 WebCore::JSMainThreadNullState state;
824 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
825 WebCore::DOMWindow* item = WebKit::core(self);
826 glong result = item->screenX();
827 return result;
828}
829
830glong webkit_dom_dom_window_get_screen_y(WebKitDOMDOMWindow* self)
831{
832 WebCore::JSMainThreadNullState state;
833 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
834 WebCore::DOMWindow* item = WebKit::core(self);
835 glong result = item->screenY();
836 return result;
837}
838
839glong webkit_dom_dom_window_get_screen_left(WebKitDOMDOMWindow* self)
840{
841 WebCore::JSMainThreadNullState state;
842 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
843 WebCore::DOMWindow* item = WebKit::core(self);
844 glong result = item->screenLeft();
845 return result;
846}
847
848glong webkit_dom_dom_window_get_screen_top(WebKitDOMDOMWindow* self)
849{
850 WebCore::JSMainThreadNullState state;
851 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
852 WebCore::DOMWindow* item = WebKit::core(self);
853 glong result = item->screenTop();
854 return result;
855}
856
857glong webkit_dom_dom_window_get_scroll_x(WebKitDOMDOMWindow* self)
858{
859 WebCore::JSMainThreadNullState state;
860 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
861 WebCore::DOMWindow* item = WebKit::core(self);
862 glong result = item->scrollX();
863 return result;
864}
865
866glong webkit_dom_dom_window_get_scroll_y(WebKitDOMDOMWindow* self)
867{
868 WebCore::JSMainThreadNullState state;
869 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
870 WebCore::DOMWindow* item = WebKit::core(self);
871 glong result = item->scrollY();
872 return result;
873}
874
875glong webkit_dom_dom_window_get_page_x_offset(WebKitDOMDOMWindow* self)
876{
877 WebCore::JSMainThreadNullState state;
878 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
879 WebCore::DOMWindow* item = WebKit::core(self);
880 glong result = item->scrollX();
881 return result;
882}
883
884glong webkit_dom_dom_window_get_page_y_offset(WebKitDOMDOMWindow* self)
885{
886 WebCore::JSMainThreadNullState state;
887 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
888 WebCore::DOMWindow* item = WebKit::core(self);
889 glong result = item->scrollY();
890 return result;
891}
892
893gboolean webkit_dom_dom_window_get_closed(WebKitDOMDOMWindow* self)
894{
895 WebCore::JSMainThreadNullState state;
896 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), FALSE);
897 WebCore::DOMWindow* item = WebKit::core(self);
898 gboolean result = item->closed();
899 return result;
900}
901
902gulong webkit_dom_dom_window_get_length(WebKitDOMDOMWindow* self)
903{
904 WebCore::JSMainThreadNullState state;
905 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
906 WebCore::DOMWindow* item = WebKit::core(self);
907 gulong result = item->length();
908 return result;
909}
910
911gchar* webkit_dom_dom_window_get_name(WebKitDOMDOMWindow* self)
912{
913 WebCore::JSMainThreadNullState state;
914 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
915 WebCore::DOMWindow* item = WebKit::core(self);
916 gchar* result = convertToUTF8String(item->name());
917 return result;
918}
919
920void webkit_dom_dom_window_set_name(WebKitDOMDOMWindow* self, const gchar* value)
921{
922 WebCore::JSMainThreadNullState state;
923 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
924 g_return_if_fail(value);
925 WebCore::DOMWindow* item = WebKit::core(self);
926 WTF::String convertedValue = WTF::String::fromUTF8(value);
927 item->setName(convertedValue);
928}
929
930gchar* webkit_dom_dom_window_get_status(WebKitDOMDOMWindow* self)
931{
932 WebCore::JSMainThreadNullState state;
933 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
934 WebCore::DOMWindow* item = WebKit::core(self);
935 gchar* result = convertToUTF8String(item->status());
936 return result;
937}
938
939void webkit_dom_dom_window_set_status(WebKitDOMDOMWindow* self, const gchar* value)
940{
941 WebCore::JSMainThreadNullState state;
942 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
943 g_return_if_fail(value);
944 WebCore::DOMWindow* item = WebKit::core(self);
945 WTF::String convertedValue = WTF::String::fromUTF8(value);
946 item->setStatus(convertedValue);
947}
948
949gchar* webkit_dom_dom_window_get_default_status(WebKitDOMDOMWindow* self)
950{
951 WebCore::JSMainThreadNullState state;
952 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
953 WebCore::DOMWindow* item = WebKit::core(self);
954 gchar* result = convertToUTF8String(item->defaultStatus());
955 return result;
956}
957
958void webkit_dom_dom_window_set_default_status(WebKitDOMDOMWindow* self, const gchar* value)
959{
960 WebCore::JSMainThreadNullState state;
961 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self));
962 g_return_if_fail(value);
963 WebCore::DOMWindow* item = WebKit::core(self);
964 WTF::String convertedValue = WTF::String::fromUTF8(value);
965 item->setDefaultStatus(convertedValue);
966}
967
968WebKitDOMDOMWindow* webkit_dom_dom_window_get_self(WebKitDOMDOMWindow* self)
969{
970 WebCore::JSMainThreadNullState state;
971 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
972 WebCore::DOMWindow* item = WebKit::core(self);
973 return WebKit::kit(item);
974}
975
976WebKitDOMDOMWindow* webkit_dom_dom_window_get_window(WebKitDOMDOMWindow* self)
977{
978 WebCore::JSMainThreadNullState state;
979 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
980 WebCore::DOMWindow* item = WebKit::core(self);
981 return WebKit::kit(item);
982}
983
984WebKitDOMDOMWindow* webkit_dom_dom_window_get_frames(WebKitDOMDOMWindow* self)
985{
986 WebCore::JSMainThreadNullState state;
987 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
988 WebCore::DOMWindow* item = WebKit::core(self);
989 return WebKit::kit(item);
990}
991
992WebKitDOMDOMWindow* webkit_dom_dom_window_get_opener(WebKitDOMDOMWindow* self)
993{
994 WebCore::JSMainThreadNullState state;
995 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
996 WebCore::DOMWindow* item = WebKit::core(self);
997 auto* openerWindowProxy = item->opener();
998 RefPtr<WebCore::DOMWindow> gobjectResult = downcast<WebCore::DOMWindow>(openerWindowProxy->window());
999 return WebKit::kit(gobjectResult.get());
1000}
1001
1002WebKitDOMDOMWindow* webkit_dom_dom_window_get_parent(WebKitDOMDOMWindow* self)
1003{
1004 WebCore::JSMainThreadNullState state;
1005 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
1006 WebCore::DOMWindow* item = WebKit::core(self);
1007 auto* parentWindowProxy = item->parent();
1008 RefPtr<WebCore::DOMWindow> gobjectResult = downcast<WebCore::DOMWindow>(parentWindowProxy->window());
1009 return WebKit::kit(gobjectResult.get());
1010}
1011
1012WebKitDOMDOMWindow* webkit_dom_dom_window_get_top(WebKitDOMDOMWindow* self)
1013{
1014 WebCore::JSMainThreadNullState state;
1015 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
1016 WebCore::DOMWindow* item = WebKit::core(self);
1017 auto* topWindowProxy = item->top();
1018 RefPtr<WebCore::DOMWindow> gobjectResult = downcast<WebCore::DOMWindow>(topWindowProxy->window());
1019 return WebKit::kit(gobjectResult.get());
1020}
1021
1022WebKitDOMDocument* webkit_dom_dom_window_get_document(WebKitDOMDOMWindow* self)
1023{
1024 WebCore::JSMainThreadNullState state;
1025 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
1026 WebCore::DOMWindow* item = WebKit::core(self);
1027 RefPtr<WebCore::Document> gobjectResult = WTF::getPtr(item->document());
1028 return WebKit::kit(gobjectResult.get());
1029}
1030
1031gdouble webkit_dom_dom_window_get_device_pixel_ratio(WebKitDOMDOMWindow* self)
1032{
1033 WebCore::JSMainThreadNullState state;
1034 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
1035 WebCore::DOMWindow* item = WebKit::core(self);
1036 gdouble result = item->devicePixelRatio();
1037 return result;
1038}
1039
1040glong webkit_dom_dom_window_get_orientation(WebKitDOMDOMWindow* self)
1041{
1042#if ENABLE(ORIENTATION_EVENTS)
1043 WebCore::JSMainThreadNullState state;
1044 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(self), 0);
1045 WebCore::DOMWindow* item = WebKit::core(self);
1046 glong result = item->orientation();
1047 return result;
1048#else
1049 UNUSED_PARAM(self);
1050 WEBKIT_WARN_FEATURE_NOT_PRESENT("Orientation Events")
1051 return static_cast<glong>(0);
1052#endif /* ENABLE(ORIENTATION_EVENTS) */
1053}
1054
1055gboolean webkit_dom_dom_window_webkit_message_handlers_post_message(WebKitDOMDOMWindow* window, const gchar* handlerName, const gchar* message)
1056{
1057 g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(window), FALSE);
1058 g_return_val_if_fail(handlerName, FALSE);
1059 g_return_val_if_fail(message, FALSE);
1060
1061 WebCore::DOMWindow* domWindow = WebKit::core(window);
1062 if (!domWindow->shouldHaveWebKitNamespaceForWorld(WebCore::mainThreadNormalWorld()))
1063 return FALSE;
1064
1065 auto webkitNamespace = domWindow->webkitNamespace();
1066 if (!webkitNamespace)
1067 return FALSE;
1068
1069 auto handler = webkitNamespace->messageHandlers()->namedItem(WebCore::mainThreadNormalWorld(), String::fromUTF8(handlerName));
1070 if (!handler)
1071 return FALSE;
1072
1073 auto result = handler->postMessage(WebCore::SerializedScriptValue::create(String::fromUTF8(message)));
1074 if (result.hasException())
1075 return FALSE;
1076
1077 return TRUE;
1078}
1079G_GNUC_END_IGNORE_DEPRECATIONS;
1080