0
|
1 |
/*
|
|
2 |
* Copyright (C) 2006, 2007, 2009 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 |
* 1. Redistributions of source code must retain the above copyright
|
|
8 |
* notice, this list of conditions and the following disclaimer.
|
|
9 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
10 |
* notice, this list of conditions and the following disclaimer in the
|
|
11 |
* documentation and/or other materials provided with the distribution.
|
|
12 |
*
|
|
13 |
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
|
14 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
15 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
|
17 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
18 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
19 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
20 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
21 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
22 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
23 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#ifndef DOMWindow_h
|
|
27 |
#define DOMWindow_h
|
|
28 |
|
|
29 |
#include "EventTarget.h"
|
|
30 |
#include "KURL.h"
|
|
31 |
#include "MessagePort.h"
|
|
32 |
#include "PlatformString.h"
|
|
33 |
#include "RegisteredEventListener.h"
|
|
34 |
#include "SecurityOrigin.h"
|
|
35 |
#include <wtf/Forward.h>
|
|
36 |
#include <wtf/RefCounted.h>
|
|
37 |
#include <wtf/RefPtr.h>
|
|
38 |
|
|
39 |
namespace WebCore {
|
|
40 |
|
|
41 |
class BarInfo;
|
|
42 |
class BeforeUnloadEvent;
|
|
43 |
class CSSRuleList;
|
|
44 |
class CSSStyleDeclaration;
|
|
45 |
class Console;
|
|
46 |
class DOMSelection;
|
|
47 |
class Database;
|
|
48 |
class Document;
|
|
49 |
class Element;
|
|
50 |
class Event;
|
|
51 |
class EventListener;
|
|
52 |
class FloatRect;
|
|
53 |
class Frame;
|
|
54 |
class History;
|
|
55 |
class Location;
|
|
56 |
class Media;
|
|
57 |
class Navigator;
|
|
58 |
class Node;
|
|
59 |
class NotificationCenter;
|
|
60 |
class PostMessageTimer;
|
|
61 |
class ScheduledAction;
|
|
62 |
class SerializedScriptValue;
|
|
63 |
class Screen;
|
|
64 |
class WebKitPoint;
|
|
65 |
|
|
66 |
#if ENABLE(DOM_STORAGE)
|
|
67 |
class Storage;
|
|
68 |
#endif
|
|
69 |
|
|
70 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
|
|
71 |
class DOMApplicationCache;
|
|
72 |
#endif
|
|
73 |
|
|
74 |
typedef int ExceptionCode;
|
|
75 |
|
|
76 |
class DOMWindow : public RefCounted<DOMWindow>, public EventTarget {
|
|
77 |
public:
|
|
78 |
static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
|
|
79 |
virtual ~DOMWindow();
|
|
80 |
|
|
81 |
virtual DOMWindow* toDOMWindow() { return this; }
|
|
82 |
virtual ScriptExecutionContext* scriptExecutionContext() const;
|
|
83 |
|
|
84 |
Frame* frame() const { return m_frame; }
|
|
85 |
void disconnectFrame();
|
|
86 |
|
|
87 |
void clear();
|
|
88 |
|
|
89 |
#if ENABLE(ORIENTATION_EVENTS)
|
|
90 |
// This is the interface orientation in degrees. Some examples are:
|
|
91 |
// 0 is straight up; -90 is when the device is rotated 90 clockwise;
|
|
92 |
// 90 is when rotated counter clockwise.
|
|
93 |
int orientation() const;
|
|
94 |
#endif
|
|
95 |
|
|
96 |
void setSecurityOrigin(SecurityOrigin* securityOrigin) { m_securityOrigin = securityOrigin; }
|
|
97 |
SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
|
|
98 |
|
|
99 |
void setURL(const KURL& url) { m_url = url; }
|
|
100 |
KURL url() const { return m_url; }
|
|
101 |
|
|
102 |
unsigned pendingUnloadEventListeners() const;
|
|
103 |
|
|
104 |
static bool dispatchAllPendingBeforeUnloadEvents();
|
|
105 |
static void dispatchAllPendingUnloadEvents();
|
|
106 |
|
|
107 |
static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges);
|
|
108 |
static void parseModalDialogFeatures(const String& featuresArg, HashMap<String, String>& map);
|
|
109 |
|
|
110 |
static bool allowPopUp(Frame* activeFrame);
|
|
111 |
static bool canShowModalDialog(const Frame*);
|
|
112 |
static bool canShowModalDialogNow(const Frame*);
|
|
113 |
|
|
114 |
// DOM Level 0
|
|
115 |
Screen* screen() const;
|
|
116 |
History* history() const;
|
|
117 |
BarInfo* locationbar() const;
|
|
118 |
BarInfo* menubar() const;
|
|
119 |
BarInfo* personalbar() const;
|
|
120 |
BarInfo* scrollbars() const;
|
|
121 |
BarInfo* statusbar() const;
|
|
122 |
BarInfo* toolbar() const;
|
|
123 |
Navigator* navigator() const;
|
|
124 |
Navigator* clientInformation() const { return navigator(); }
|
|
125 |
Location* location() const;
|
|
126 |
|
|
127 |
DOMSelection* getSelection();
|
|
128 |
|
|
129 |
Element* frameElement() const;
|
|
130 |
|
|
131 |
void focus();
|
|
132 |
void blur();
|
|
133 |
void close();
|
|
134 |
void print();
|
|
135 |
void stop();
|
|
136 |
|
|
137 |
void alert(const String& message);
|
|
138 |
bool confirm(const String& message);
|
|
139 |
String prompt(const String& message, const String& defaultValue);
|
|
140 |
|
|
141 |
bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
|
|
142 |
|
|
143 |
bool offscreenBuffering() const;
|
|
144 |
|
|
145 |
int outerHeight() const;
|
|
146 |
int outerWidth() const;
|
|
147 |
int innerHeight() const;
|
|
148 |
int innerWidth() const;
|
|
149 |
int screenX() const;
|
|
150 |
int screenY() const;
|
|
151 |
int screenLeft() const { return screenX(); }
|
|
152 |
int screenTop() const { return screenY(); }
|
|
153 |
int scrollX() const;
|
|
154 |
int scrollY() const;
|
|
155 |
int pageXOffset() const { return scrollX(); }
|
|
156 |
int pageYOffset() const { return scrollY(); }
|
|
157 |
|
|
158 |
bool closed() const;
|
|
159 |
|
|
160 |
unsigned length() const;
|
|
161 |
|
|
162 |
String name() const;
|
|
163 |
void setName(const String&);
|
|
164 |
|
|
165 |
String status() const;
|
|
166 |
void setStatus(const String&);
|
|
167 |
String defaultStatus() const;
|
|
168 |
void setDefaultStatus(const String&);
|
|
169 |
// This attribute is an alias of defaultStatus and is necessary for legacy uses.
|
|
170 |
String defaultstatus() const { return defaultStatus(); }
|
|
171 |
void setDefaultstatus(const String& status) { setDefaultStatus(status); }
|
|
172 |
|
|
173 |
// Self referential attributes
|
|
174 |
DOMWindow* self() const;
|
|
175 |
DOMWindow* window() const { return self(); }
|
|
176 |
DOMWindow* frames() const { return self(); }
|
|
177 |
|
|
178 |
DOMWindow* opener() const;
|
|
179 |
DOMWindow* parent() const;
|
|
180 |
DOMWindow* top() const;
|
|
181 |
|
|
182 |
// DOM Level 2 AbstractView Interface
|
|
183 |
Document* document() const;
|
|
184 |
// CSSOM View Module
|
|
185 |
PassRefPtr<Media> media() const;
|
|
186 |
|
|
187 |
// DOM Level 2 Style Interface
|
|
188 |
PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
|
|
189 |
|
|
190 |
// WebKit extensions
|
|
191 |
PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const;
|
|
192 |
double devicePixelRatio() const;
|
|
193 |
|
|
194 |
PassRefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node* node, const WebKitPoint* p) const;
|
|
195 |
PassRefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const;
|
|
196 |
|
|
197 |
#if ENABLE(DATABASE)
|
|
198 |
// HTML 5 client-side database
|
|
199 |
PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode&);
|
|
200 |
#endif
|
|
201 |
|
|
202 |
#if ENABLE(DOM_STORAGE)
|
|
203 |
// HTML 5 key/value storage
|
|
204 |
Storage* sessionStorage() const;
|
|
205 |
Storage* localStorage() const;
|
|
206 |
#endif
|
|
207 |
|
|
208 |
Console* console() const;
|
|
209 |
|
|
210 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
|
|
211 |
DOMApplicationCache* applicationCache() const;
|
|
212 |
#endif
|
|
213 |
|
|
214 |
#if ENABLE(NOTIFICATIONS)
|
|
215 |
NotificationCenter* webkitNotifications() const;
|
|
216 |
#endif
|
|
217 |
|
|
218 |
void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
|
|
219 |
// FIXME: remove this when we update the ObjC bindings (bug #28774).
|
|
220 |
void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
|
|
221 |
void postMessageTimerFired(PostMessageTimer*);
|
|
222 |
|
|
223 |
void scrollBy(int x, int y) const;
|
|
224 |
void scrollTo(int x, int y) const;
|
|
225 |
void scroll(int x, int y) const { scrollTo(x, y); }
|
|
226 |
|
|
227 |
void moveBy(float x, float y) const;
|
|
228 |
void moveTo(float x, float y) const;
|
|
229 |
|
|
230 |
void resizeBy(float x, float y) const;
|
|
231 |
void resizeTo(float width, float height) const;
|
|
232 |
|
|
233 |
// Timers
|
|
234 |
int setTimeout(ScheduledAction*, int timeout);
|
|
235 |
void clearTimeout(int timeoutId);
|
|
236 |
int setInterval(ScheduledAction*, int timeout);
|
|
237 |
void clearInterval(int timeoutId);
|
|
238 |
|
|
239 |
// Events
|
|
240 |
// EventTarget API
|
|
241 |
virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
|
|
242 |
virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
|
|
243 |
virtual void removeAllEventListeners();
|
|
244 |
|
|
245 |
using EventTarget::dispatchEvent;
|
|
246 |
bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
|
|
247 |
void dispatchLoadEvent();
|
|
248 |
|
|
249 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
|
|
250 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
|
|
251 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
|
|
252 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
|
|
253 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
|
|
254 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
|
|
255 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
|
|
256 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
|
|
257 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
|
|
258 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
|
|
259 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
|
|
260 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
|
|
261 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
|
|
262 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
|
|
263 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(hashchange);
|
|
264 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
|
|
265 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
|
|
266 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
|
|
267 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
|
|
268 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
|
|
269 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
|
|
270 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
|
|
271 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
|
|
272 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
|
|
273 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
|
|
274 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(offline);
|
|
275 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(online);
|
|
276 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(pagehide);
|
|
277 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(pageshow);
|
|
278 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
|
|
279 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(resize);
|
|
280 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
|
|
281 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
|
|
282 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
|
|
283 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(storage);
|
|
284 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
|
|
285 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(unload);
|
|
286 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(beforeunload);
|
|
287 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(canplay);
|
|
288 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(canplaythrough);
|
|
289 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(durationchange);
|
|
290 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(emptied);
|
|
291 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
|
|
292 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(loadeddata);
|
|
293 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(loadedmetadata);
|
|
294 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(pause);
|
|
295 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(play);
|
|
296 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(playing);
|
|
297 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(ratechange);
|
|
298 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(seeked);
|
|
299 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(seeking);
|
|
300 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(timeupdate);
|
|
301 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(volumechange);
|
|
302 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(waiting);
|
|
303 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
|
|
304 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
|
|
305 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(stalled);
|
|
306 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(suspend);
|
|
307 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
|
|
308 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
|
|
309 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
|
|
310 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
|
|
311 |
#if ENABLE(ORIENTATION_EVENTS)
|
|
312 |
DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange);
|
|
313 |
#endif
|
|
314 |
|
|
315 |
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationstart, webkitAnimationStart);
|
|
316 |
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitAnimationIteration);
|
|
317 |
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimationEnd);
|
|
318 |
DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransitionEnd);
|
|
319 |
|
|
320 |
void captureEvents();
|
|
321 |
void releaseEvents();
|
|
322 |
|
|
323 |
// These methods are used for GC marking. See JSDOMWindow::markChildren(MarkStack&) in
|
|
324 |
// JSDOMWindowCustom.cpp.
|
|
325 |
Screen* optionalScreen() const { return m_screen.get(); }
|
|
326 |
DOMSelection* optionalSelection() const { return m_selection.get(); }
|
|
327 |
History* optionalHistory() const { return m_history.get(); }
|
|
328 |
BarInfo* optionalLocationbar() const { return m_locationbar.get(); }
|
|
329 |
BarInfo* optionalMenubar() const { return m_menubar.get(); }
|
|
330 |
BarInfo* optionalPersonalbar() const { return m_personalbar.get(); }
|
|
331 |
BarInfo* optionalScrollbars() const { return m_scrollbars.get(); }
|
|
332 |
BarInfo* optionalStatusbar() const { return m_statusbar.get(); }
|
|
333 |
BarInfo* optionalToolbar() const { return m_toolbar.get(); }
|
|
334 |
Console* optionalConsole() const { return m_console.get(); }
|
|
335 |
Navigator* optionalNavigator() const { return m_navigator.get(); }
|
|
336 |
Location* optionalLocation() const { return m_location.get(); }
|
|
337 |
#if ENABLE(DOM_STORAGE)
|
|
338 |
Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
|
|
339 |
Storage* optionalLocalStorage() const { return m_localStorage.get(); }
|
|
340 |
#endif
|
|
341 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
|
|
342 |
DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
|
|
343 |
#endif
|
|
344 |
|
|
345 |
using RefCounted<DOMWindow>::ref;
|
|
346 |
using RefCounted<DOMWindow>::deref;
|
|
347 |
|
|
348 |
private:
|
|
349 |
DOMWindow(Frame*);
|
|
350 |
|
|
351 |
virtual void refEventTarget() { ref(); }
|
|
352 |
virtual void derefEventTarget() { deref(); }
|
|
353 |
virtual EventTargetData* eventTargetData();
|
|
354 |
virtual EventTargetData* ensureEventTargetData();
|
|
355 |
|
|
356 |
RefPtr<SecurityOrigin> m_securityOrigin;
|
|
357 |
KURL m_url;
|
|
358 |
|
|
359 |
Frame* m_frame;
|
|
360 |
mutable RefPtr<Screen> m_screen;
|
|
361 |
mutable RefPtr<DOMSelection> m_selection;
|
|
362 |
mutable RefPtr<History> m_history;
|
|
363 |
mutable RefPtr<BarInfo> m_locationbar;
|
|
364 |
mutable RefPtr<BarInfo> m_menubar;
|
|
365 |
mutable RefPtr<BarInfo> m_personalbar;
|
|
366 |
mutable RefPtr<BarInfo> m_scrollbars;
|
|
367 |
mutable RefPtr<BarInfo> m_statusbar;
|
|
368 |
mutable RefPtr<BarInfo> m_toolbar;
|
|
369 |
mutable RefPtr<Console> m_console;
|
|
370 |
mutable RefPtr<Navigator> m_navigator;
|
|
371 |
mutable RefPtr<Location> m_location;
|
|
372 |
#if ENABLE(DOM_STORAGE)
|
|
373 |
mutable RefPtr<Storage> m_sessionStorage;
|
|
374 |
mutable RefPtr<Storage> m_localStorage;
|
|
375 |
#endif
|
|
376 |
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
|
|
377 |
mutable RefPtr<DOMApplicationCache> m_applicationCache;
|
|
378 |
#endif
|
|
379 |
#if ENABLE(NOTIFICATIONS)
|
|
380 |
mutable RefPtr<NotificationCenter> m_notifications;
|
|
381 |
#endif
|
|
382 |
|
|
383 |
EventTargetData m_eventTargetData;
|
|
384 |
};
|
|
385 |
|
|
386 |
} // namespace WebCore
|
|
387 |
|
|
388 |
#endif // DOMWindow_h
|