2
* Copyright (C) 2000 Harri Porten (porten@kde.org)
3
* Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include "PlatformString.h"
24
#include "kjs_binding.h"
25
#include <wtf/HashMap.h>
26
#include <wtf/OwnPtr.h>
34
class JSEventListener;
35
class JSUnprotectedEventListener;
43
class ScheduledAction;
47
class PausedTimeouts {
49
PausedTimeouts(PausedTimeout *a, size_t length) : m_array(a), m_length(length) { }
52
size_t numTimeouts() const { return m_length; }
53
PausedTimeout *takeTimeouts()
54
{ PausedTimeout *a = m_array; m_array = 0; return a; }
57
PausedTimeout *m_array;
60
PausedTimeouts(const PausedTimeouts&);
61
PausedTimeouts& operator=(const PausedTimeouts&);
68
class Window : public DOMObject {
69
friend class Location;
70
friend class WindowFunc;
71
friend class ScheduledAction;
73
Window(WebCore::DOMWindow*);
76
WebCore::DOMWindow* impl() const { return m_impl.get(); }
77
void disconnectFrame();
79
* Returns and registers a window object. In case there's already a Window
80
* for the specified frame p this will be returned in order to have unique
83
static JSValue* retrieve(WebCore::Frame*);
85
* Returns the Window object for a given HTML frame
87
static Window* retrieveWindow(WebCore::Frame*);
89
* returns a pointer to the Window object this javascript interpreting instance
92
static Window* retrieveActive(ExecState*);
94
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
95
JSValue *getValueProperty(ExecState *exec, int token) const;
96
virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
98
int installTimeout(const UString& handler, int t, bool singleShot);
99
int installTimeout(JSValue* function, const List& args, int t, bool singleShot);
100
void clearTimeout(int timerId, bool delAction = true);
101
PausedTimeouts* pauseTimeouts();
102
void resumeTimeouts(PausedTimeouts*);
104
void timerFired(DOMWindowTimer*);
106
KJS::ScriptInterpreter *interpreter() const;
108
bool isSafeScript(ExecState*) const;
109
static bool isSafeScript(const ScriptInterpreter *origin, const ScriptInterpreter *target);
111
Location* location() const;
113
// Finds a wrapper of a JS EventListener, returns 0 if no existing one.
114
WebCore::JSEventListener* findJSEventListener(JSValue*, bool html = false);
116
// Finds or creates a wrapper of a JS EventListener. JS EventListener object is GC-protected.
117
WebCore::JSEventListener *findOrCreateJSEventListener(JSValue*, bool html = false);
119
// Finds a wrapper of a GC-unprotected JS EventListener, returns 0 if no existing one.
120
WebCore::JSUnprotectedEventListener* findJSUnprotectedEventListener(JSValue*, bool html = false);
122
// Finds or creates a wrapper of a JS EventListener. JS EventListener object is *NOT* GC-protected.
123
WebCore::JSUnprotectedEventListener *findOrCreateJSUnprotectedEventListener(JSValue*, bool html = false);
127
// Set the current "event" object
128
void setCurrentEvent(WebCore::Event*);
130
// Set a place to put a dialog return value when the window is cleared.
131
void setReturnValueSlot(JSValue **slot);
133
typedef HashMap<JSObject*, WebCore::JSEventListener*> ListenersMap;
134
typedef HashMap<JSObject*, WebCore::JSUnprotectedEventListener*> UnprotectedListenersMap;
136
ListenersMap& jsEventListeners();
137
ListenersMap& jsHTMLEventListeners();
138
UnprotectedListenersMap& jsUnprotectedEventListeners();
139
UnprotectedListenersMap& jsUnprotectedHTMLEventListeners();
141
virtual const ClassInfo* classInfo() const { return &info; }
142
static const ClassInfo info;
146
AToB, BToA, Open, SetTimeout,
147
ClearTimeout, SetInterval, ClearInterval, CaptureEvents,
148
ReleaseEvents, AddEventListener, RemoveEventListener, Scroll,
149
ScrollBy, ScrollTo, MoveBy, MoveTo,
150
ResizeBy, ResizeTo, ShowModalDialog,
153
Crypto, Event_, Location_, Navigator_,
157
Onabort, Onblur, Onchange, Onclick,
158
Ondblclick, Onerror, Onfocus, Onkeydown,
159
Onkeypress, Onkeyup, Onload, Onmousedown,
160
Onmousemove, Onmouseout, Onmouseover, Onmouseup,
161
OnWindowMouseWheel, Onreset, Onresize, Onscroll,
162
Onsearch, Onselect, Onsubmit, Onunload,
166
DOMException, Image, Option, XMLHttpRequest,
171
JSValue* getListener(ExecState*, const WebCore::AtomicString& eventType) const;
172
void setListener(ExecState*, const WebCore::AtomicString& eventType, JSValue* func);
174
static JSValue *childFrameGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
175
static JSValue *namedFrameGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
176
static JSValue *indexGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
177
static JSValue *namedItemGetter(ExecState *exec, JSObject *, const Identifier&, const PropertySlot& slot);
179
void updateLayout() const;
181
void clearHelperObjectProperties();
182
void clearAllTimeouts();
183
int installTimeout(ScheduledAction*, int interval, bool singleShot);
185
RefPtr<WebCore::DOMWindow> m_impl;
186
OwnPtr<WindowPrivate> d;
189
KJS_IMPLEMENT_PROTOTYPE_FUNCTION(WindowFunc)
192
* An action (either function or string) to be executed after a specified
193
* time interval, either once or repeatedly. Used for window.setTimeout()
194
* and window.setInterval()
196
class ScheduledAction {
198
ScheduledAction(JSValue *func, const List& args)
199
: m_func(func), m_args(args) { }
200
ScheduledAction(const WebCore::String& code)
202
void execute(Window *);
205
ProtectedPtr<JSValue> m_func;
207
WebCore::String m_code;
210
class Location : public DOMObject {
212
virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
213
JSValue *getValueProperty(ExecState *exec, int token) const;
214
virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
215
enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search,
216
Replace, Reload, ToString, Assign };
217
WebCore::Frame* frame() const { return m_frame; }
218
virtual const ClassInfo* classInfo() const { return &info; }
219
static const ClassInfo info;
222
Location(WebCore::Frame*);
223
WebCore::Frame* m_frame;
229
KJS::JSValue* toJS(KJS::ExecState*, DOMWindow*);
230
} // namespace WebCore