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; }
49        ScriptExecutionContext* scriptExecutionContext() const;
50
51        // Called just before removing this window from the JSDOMWindowShell.
52        void willRemoveFromWindowShell();
53
54        DECLARE_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), 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 shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*);
67        static bool javaScriptExperimentsEnabled(const JSC::JSGlobalObject*);
68        static void queueTaskToEventLoop(const JSC::JSGlobalObject*, PassRefPtr<JSC::Microtask>);
69
70        void printErrorMessage(const String&) const;
71
72        JSDOMWindowShell* shell() const;
73
74        static JSC::VM& commonVM();
75        static void fireFrameClearedWatchpointsForWindow(DOMWindow*);
76
77    protected:
78        JSC::WatchpointSet m_windowCloseWatchpoints;
79
80    private:
81        RefPtr<DOMWindow> m_impl;
82        JSDOMWindowShell* m_shell;
83    };
84
85    // Returns a JSDOMWindow or jsNull()
86    // JSDOMGlobalObject* is ignored, accessing a window in any context will
87    // use that DOMWindow's prototype chain.
88    JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, DOMWindow*);
89    JSC::JSValue toJS(JSC::ExecState*, DOMWindow*);
90
91    // Returns JSDOMWindow or 0
92    JSDOMWindow* toJSDOMWindow(Frame*, DOMWrapperWorld&);
93    JSDOMWindow* toJSDOMWindow(JSC::JSValue);
94
95} // namespace WebCore
96
97#endif // JSDOMWindowBase_h
98