1/*
2 *  Copyright (C) 2000 Harri Porten (porten@kde.org)
3 *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
4 *
5 *  This library is free software; you can redistribute it and/or
6 *  modify it under the terms of the GNU Lesser General Public
7 *  License as published by the Free Software Foundation; either
8 *  version 2 of the License, or (at your option) any later version.
9 *
10 *  This library is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *  Lesser General Public License for more details.
14 *
15 *  You should have received a copy of the GNU Lesser General Public
16 *  License along with this library; if not, write to the Free Software
17 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#ifndef JSDOMWindowBase_h
21#define JSDOMWindowBase_h
22
23#include "JSDOMBinding.h"
24#include "JSDOMGlobalObject.h"
25#include <wtf/Forward.h>
26
27namespace WebCore {
28
29    class DOMWindow;
30    class Frame;
31    class DOMWrapperWorld;
32    class JSDOMWindow;
33    class JSDOMWindowShell;
34
35    class JSDOMWindowBasePrivate;
36
37    class JSDOMWindowBase : public JSDOMGlobalObject {
38        typedef JSDOMGlobalObject Base;
39    protected:
40        JSDOMWindowBase(JSC::VM&, JSC::Structure*, PassRefPtr<DOMWindow>, JSDOMWindowShell*);
41        void finishCreation(JSC::VM&, JSDOMWindowShell*);
42
43        static void destroy(JSCell*);
44
45    public:
46        void updateDocument();
47
48        DOMWindow* impl() const { return m_impl.get(); }
49        ScriptExecutionContext* scriptExecutionContext() const;
50
51        // Called just before removing this window from the JSDOMWindowShell.
52        void willRemoveFromWindowShell();
53
54        static const JSC::ClassInfo s_info;
55
56        static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSValue prototype)
57        {
58            return JSC::Structure::create(vm, 0, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), &s_info);
59        }
60
61        static const JSC::GlobalObjectMethodTable s_globalObjectMethodTable;
62
63        static bool supportsProfiling(const JSC::JSGlobalObject*);
64        static bool supportsRichSourceInfo(const JSC::JSGlobalObject*);
65        static bool shouldInterruptScript(const JSC::JSGlobalObject*);
66        static bool javaScriptExperimentsEnabled(const JSC::JSGlobalObject*);
67        void printErrorMessage(const String&) const;
68
69        JSDOMWindowShell* shell() const;
70
71        static JSC::VM* commonVM();
72
73    private:
74        RefPtr<DOMWindow> m_impl;
75        JSDOMWindowShell* m_shell;
76    };
77
78    // Returns a JSDOMWindow or jsNull()
79    // JSDOMGlobalObject* is ignored, accessing a window in any context will
80    // use that DOMWindow's prototype chain.
81    JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, DOMWindow*);
82    JSC::JSValue toJS(JSC::ExecState*, DOMWindow*);
83
84    // Returns JSDOMWindow or 0
85    JSDOMWindow* toJSDOMWindow(Frame*, DOMWrapperWorld*);
86    JSDOMWindow* toJSDOMWindow(JSC::JSValue);
87
88} // namespace WebCore
89
90#endif // JSDOMWindowBase_h
91