1/*
2 * Copyright (C) 2008-2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#include "JSDOMConvertInterface.h"
32#include "JSDOMWindow.h"
33#include "WindowProxy.h"
34#include <JavaScriptCore/JSProxy.h>
35
36namespace JSC {
37class Debugger;
38}
39
40namespace WebCore {
41
42class AbstractDOMWindow;
43class AbstractFrame;
44
45class JSWindowProxy final : public JSC::JSProxy {
46 using Base = JSC::JSProxy;
47public:
48 static JSWindowProxy& create(JSC::VM&, AbstractDOMWindow&, DOMWrapperWorld&);
49 static void destroy(JSCell*);
50
51 DECLARE_INFO;
52
53 JSDOMGlobalObject* window() const { return static_cast<JSDOMGlobalObject*>(target()); }
54 void setWindow(JSC::VM&, JSDOMGlobalObject&);
55 void setWindow(AbstractDOMWindow&);
56
57 WindowProxy* windowProxy() const;
58
59 AbstractDOMWindow& wrapped() const;
60 static WEBCORE_EXPORT WindowProxy* toWrapped(JSC::VM&, JSC::JSValue);
61
62 DOMWrapperWorld& world() { return m_world; }
63
64 void attachDebugger(JSC::Debugger*);
65
66private:
67 JSWindowProxy(JSC::VM&, JSC::Structure&, DOMWrapperWorld&);
68 void finishCreation(JSC::VM&, AbstractDOMWindow&);
69
70 Ref<DOMWrapperWorld> m_world;
71};
72
73// JSWindowProxy is a little odd in that it's not a traditional wrapper and has no back pointer.
74// It is, however, strongly owned by AbstractFrame via its WindowProxy, so we can get one from a WindowProxy.
75WEBCORE_EXPORT JSC::JSValue toJS(JSC::ExecState*, WindowProxy&);
76inline JSC::JSValue toJS(JSC::ExecState* state, WindowProxy* windowProxy) { return windowProxy ? toJS(state, *windowProxy) : JSC::jsNull(); }
77inline JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject*, WindowProxy& windowProxy) { return toJS(state, windowProxy); }
78inline JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, WindowProxy* windowProxy) { return windowProxy ? toJS(state, globalObject, *windowProxy) : JSC::jsNull(); }
79
80JSWindowProxy* toJSWindowProxy(WindowProxy&, DOMWrapperWorld&);
81inline JSWindowProxy* toJSWindowProxy(WindowProxy* windowProxy, DOMWrapperWorld& world) { return windowProxy ? toJSWindowProxy(*windowProxy, world) : nullptr; }
82
83
84template<> struct JSDOMWrapperConverterTraits<WindowProxy> {
85 using WrapperClass = JSWindowProxy;
86 using ToWrappedReturnType = WindowProxy*;
87};
88
89} // namespace WebCore
90