• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "PlatformString.h"
32 #include "RegisteredEventListener.h"
33 #include "SecurityOrigin.h"
34 #include <wtf/Forward.h>
35 #include <wtf/RefCounted.h>
36 #include <wtf/RefPtr.h>
37 
38 namespace WebCore {
39 
40     class BarInfo;
41     class BeforeUnloadEvent;
42     class CSSRuleList;
43     class CSSStyleDeclaration;
44     class Console;
45     class DOMSelection;
46     class Database;
47     class Document;
48     class Element;
49     class Event;
50     class EventListener;
51     class FloatRect;
52     class Frame;
53     class History;
54     class Location;
55     class Media;
56     class MessagePort;
57     class Navigator;
58     class Node;
59     class PostMessageTimer;
60     class ScheduledAction;
61     class Screen;
62     class WebKitPoint;
63 
64 #if ENABLE(DOM_STORAGE)
65     class Storage;
66 #endif
67 
68 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
69     class DOMApplicationCache;
70 #endif
71 
72     typedef int ExceptionCode;
73 
74     class DOMWindow : public RefCounted<DOMWindow>, public EventTarget {
75     public:
create(Frame * frame)76         static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
77         virtual ~DOMWindow();
78 
toDOMWindow()79         virtual DOMWindow* toDOMWindow() { return this; }
80         virtual ScriptExecutionContext* scriptExecutionContext() const;
81 
frame()82         Frame* frame() const { return m_frame; }
83         void disconnectFrame();
84 
85         void clear();
86 
setSecurityOrigin(SecurityOrigin * securityOrigin)87         void setSecurityOrigin(SecurityOrigin* securityOrigin) { m_securityOrigin = securityOrigin; }
securityOrigin()88         SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
89 
setURL(const KURL & url)90         void setURL(const KURL& url) { m_url = url; }
url()91         KURL url() const { return m_url; }
92 
93         unsigned pendingUnloadEventListeners() const;
94 
95         static bool dispatchAllPendingBeforeUnloadEvents();
96         static void dispatchAllPendingUnloadEvents();
97 
98         static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges);
99         static void parseModalDialogFeatures(const String& featuresArg, HashMap<String, String>& map);
100 
101         static bool allowPopUp(Frame* activeFrame);
102         static bool canShowModalDialog(const Frame*);
103         static bool canShowModalDialogNow(const Frame*);
104 
105         // DOM Level 0
106         Screen* screen() const;
107         History* history() const;
108         BarInfo* locationbar() const;
109         BarInfo* menubar() const;
110         BarInfo* personalbar() const;
111         BarInfo* scrollbars() const;
112         BarInfo* statusbar() const;
113         BarInfo* toolbar() const;
114         Navigator* navigator() const;
clientInformation()115         Navigator* clientInformation() const { return navigator(); }
116         Location* location() const;
117 
118         DOMSelection* getSelection();
119 
120         Element* frameElement() const;
121 
122         void focus();
123         void blur();
124         void close();
125         void print();
126         void stop();
127 
128         void alert(const String& message);
129         bool confirm(const String& message);
130         String prompt(const String& message, const String& defaultValue);
131 
132         bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
133 
134         bool offscreenBuffering() const;
135 
136         int outerHeight() const;
137         int outerWidth() const;
138         int innerHeight() const;
139         int innerWidth() const;
140         int screenX() const;
141         int screenY() const;
screenLeft()142         int screenLeft() const { return screenX(); }
screenTop()143         int screenTop() const { return screenY(); }
144         int scrollX() const;
145         int scrollY() const;
pageXOffset()146         int pageXOffset() const { return scrollX(); }
pageYOffset()147         int pageYOffset() const { return scrollY(); }
148 #ifdef ANDROID_ORIENTATION_SUPPORT
149         int orientation() const;
150 #endif
151 
152         bool closed() const;
153 
154         unsigned length() const;
155 
156         String name() const;
157         void setName(const String&);
158 
159         String status() const;
160         void setStatus(const String&);
161         String defaultStatus() const;
162         void setDefaultStatus(const String&);
163         // This attribute is an alias of defaultStatus and is necessary for legacy uses.
defaultstatus()164         String defaultstatus() const { return defaultStatus(); }
setDefaultstatus(const String & status)165         void setDefaultstatus(const String& status) { setDefaultStatus(status); }
166 
167         // Self referential attributes
168         DOMWindow* self() const;
window()169         DOMWindow* window() const { return self(); }
frames()170         DOMWindow* frames() const { return self(); }
171 
172         DOMWindow* opener() const;
173         DOMWindow* parent() const;
174         DOMWindow* top() const;
175 
176         // DOM Level 2 AbstractView Interface
177         Document* document() const;
178         // CSSOM View Module
179         PassRefPtr<Media> media() const;
180 
181         // DOM Level 2 Style Interface
182         PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
183 
184         // WebKit extensions
185         PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const;
186         double devicePixelRatio() const;
187 
188         PassRefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node* node, const WebKitPoint* p) const;
189         PassRefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const;
190 
191 #if ENABLE(DATABASE)
192         // HTML 5 client-side database
193         PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode&);
194 #endif
195 
196 #if ENABLE(DOM_STORAGE)
197         // HTML 5 key/value storage
198         Storage* sessionStorage() const;
199         Storage* localStorage() const;
200 #endif
201 
202         Console* console() const;
203 
204 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
205         DOMApplicationCache* applicationCache() const;
206 #endif
207 
208         void postMessage(const String& message, MessagePort*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
209         void postMessageTimerFired(PostMessageTimer*);
210 
211         void scrollBy(int x, int y) const;
212         void scrollTo(int x, int y) const;
scroll(int x,int y)213         void scroll(int x, int y) const { scrollTo(x, y); }
214 
215         void moveBy(float x, float y) const;
216         void moveTo(float x, float y) const;
217 
218         void resizeBy(float x, float y) const;
219         void resizeTo(float width, float height) const;
220 
221         // Timers
222         int setTimeout(ScheduledAction*, int timeout);
223         void clearTimeout(int timeoutId);
224         int setInterval(ScheduledAction*, int timeout);
225         void clearInterval(int timeoutId);
226 
227         // Events
228         // EventTarget API
229         virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
230         virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
231         virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&);
232 
233         void handleEvent(Event*, bool useCapture, RegisteredEventListenerVector* = 0);
234 
235         void dispatchEvent(const AtomicString& eventType, bool canBubble, bool cancelable);
236         void dispatchLoadEvent();
237         void dispatchUnloadEvent(RegisteredEventListenerVector* = 0);
238         PassRefPtr<BeforeUnloadEvent> dispatchBeforeUnloadEvent(RegisteredEventListenerVector* = 0);
239 
240         // Used for legacy "onEvent" property APIs.
241         void setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
242         void clearAttributeEventListener(const AtomicString& eventType);
243         EventListener* getAttributeEventListener(const AtomicString& eventType) const;
244 
eventListeners()245         const RegisteredEventListenerVector& eventListeners() const { return m_eventListeners; }
246         bool hasEventListener(const AtomicString& eventType);
247         void removeAllEventListeners();
248 
249         EventListener* onabort() const;
250         void setOnabort(PassRefPtr<EventListener>);
251         EventListener* onblur() const;
252         void setOnblur(PassRefPtr<EventListener>);
253         EventListener* onchange() const;
254         void setOnchange(PassRefPtr<EventListener>);
255         EventListener* onclick() const;
256         void setOnclick(PassRefPtr<EventListener>);
257         EventListener* ondblclick() const;
258         void setOndblclick(PassRefPtr<EventListener>);
259         EventListener* ondrag() const;
260         void setOndrag(PassRefPtr<EventListener>);
261         EventListener* ondragend() const;
262         void setOndragend(PassRefPtr<EventListener>);
263         EventListener* ondragenter() const;
264         void setOndragenter(PassRefPtr<EventListener>);
265         EventListener* ondragleave() const;
266         void setOndragleave(PassRefPtr<EventListener>);
267         EventListener* ondragover() const;
268         void setOndragover(PassRefPtr<EventListener>);
269         EventListener* ondragstart() const;
270         void setOndragstart(PassRefPtr<EventListener>);
271         EventListener* ondrop() const;
272         void setOndrop(PassRefPtr<EventListener>);
273         EventListener* onerror() const;
274         void setOnerror(PassRefPtr<EventListener>);
275         EventListener* onfocus() const;
276         void setOnfocus(PassRefPtr<EventListener>);
277         EventListener* onkeydown() const;
278         void setOnkeydown(PassRefPtr<EventListener>);
279         EventListener* onkeypress() const;
280         void setOnkeypress(PassRefPtr<EventListener>);
281         EventListener* onkeyup() const;
282         void setOnkeyup(PassRefPtr<EventListener>);
283         EventListener* onload() const;
284         void setOnload(PassRefPtr<EventListener>);
285         EventListener* onmousedown() const;
286         void setOnmousedown(PassRefPtr<EventListener>);
287         EventListener* onmousemove() const;
288         void setOnmousemove(PassRefPtr<EventListener>);
289         EventListener* onmouseout() const;
290         void setOnmouseout(PassRefPtr<EventListener>);
291         EventListener* onmouseover() const;
292         void setOnmouseover(PassRefPtr<EventListener>);
293         EventListener* onmouseup() const;
294         void setOnmouseup(PassRefPtr<EventListener>);
295         EventListener* onmousewheel() const;
296         void setOnmousewheel(PassRefPtr<EventListener>);
297         EventListener* onoffline() const;
298         void setOnoffline(PassRefPtr<EventListener>);
299         EventListener* ononline() const;
300         void setOnonline(PassRefPtr<EventListener>);
301         EventListener* onreset() const;
302         void setOnreset(PassRefPtr<EventListener>);
303         EventListener* onresize() const;
304         void setOnresize(PassRefPtr<EventListener>);
305         EventListener* onscroll() const;
306         void setOnscroll(PassRefPtr<EventListener>);
307         EventListener* onsearch() const;
308         void setOnsearch(PassRefPtr<EventListener>);
309         EventListener* onselect() const;
310         void setOnselect(PassRefPtr<EventListener>);
311         EventListener* onstorage() const;
312         void setOnstorage(PassRefPtr<EventListener>);
313         EventListener* onsubmit() const;
314         void setOnsubmit(PassRefPtr<EventListener>);
315         EventListener* onunload() const;
316         void setOnunload(PassRefPtr<EventListener>);
317         EventListener* onbeforeunload() const;
318         void setOnbeforeunload(PassRefPtr<EventListener>);
319         EventListener* onwebkitanimationstart() const;
320         void setOnwebkitanimationstart(PassRefPtr<EventListener>);
321         EventListener* onwebkitanimationiteration() const;
322         void setOnwebkitanimationiteration(PassRefPtr<EventListener>);
323         EventListener* onwebkitanimationend() const;
324         void setOnwebkitanimationend(PassRefPtr<EventListener>);
325         EventListener* onwebkittransitionend() const;
326         void setOnwebkittransitionend(PassRefPtr<EventListener>);
327 #if ENABLE(TOUCH_EVENTS) // Android
328         EventListener* ontouchstart() const;
329         void setOntouchstart(PassRefPtr<EventListener>);
330         EventListener* ontouchend() const;
331         void setOntouchend(PassRefPtr<EventListener>);
332         EventListener* ontouchmove() const;
333         void setOntouchmove(PassRefPtr<EventListener>);
334         EventListener* ontouchcancel() const;
335         void setOntouchcancel(PassRefPtr<EventListener>);
336 #endif
337 
338         EventListener* oncanplay() const;
339         void setOncanplay(PassRefPtr<EventListener>);
340         EventListener* oncanplaythrough() const;
341         void setOncanplaythrough(PassRefPtr<EventListener>);
342         EventListener* ondurationchange() const;
343         void setOndurationchange(PassRefPtr<EventListener>);
344         EventListener* onemptied() const;
345         void setOnemptied(PassRefPtr<EventListener>);
346         EventListener* onended() const;
347         void setOnended(PassRefPtr<EventListener>);
348         EventListener* onloadeddata() const;
349         void setOnloadeddata(PassRefPtr<EventListener>);
350         EventListener* onloadedmetadata() const;
351         void setOnloadedmetadata(PassRefPtr<EventListener>);
352         EventListener* onpause() const;
353         void setOnpause(PassRefPtr<EventListener>);
354         EventListener* onplay() const;
355         void setOnplay(PassRefPtr<EventListener>);
356         EventListener* onplaying() const;
357         void setOnplaying(PassRefPtr<EventListener>);
358         EventListener* onratechange() const;
359         void setOnratechange(PassRefPtr<EventListener>);
360         EventListener* onseeked() const;
361         void setOnseeked(PassRefPtr<EventListener>);
362         EventListener* onseeking() const;
363         void setOnseeking(PassRefPtr<EventListener>);
364         EventListener* ontimeupdate() const;
365         void setOntimeupdate(PassRefPtr<EventListener>);
366         EventListener* onvolumechange() const;
367         void setOnvolumechange(PassRefPtr<EventListener>);
368         EventListener* onwaiting() const;
369         void setOnwaiting(PassRefPtr<EventListener>);
370         EventListener* onloadstart() const;
371         void setOnloadstart(PassRefPtr<EventListener>);
372         EventListener* onprogress() const;
373         void setOnprogress(PassRefPtr<EventListener>);
374         EventListener* onstalled() const;
375         void setOnstalled(PassRefPtr<EventListener>);
376         EventListener* onsuspend() const;
377         void setOnsuspend(PassRefPtr<EventListener>);
378         EventListener* oninput() const;
379         void setOninput(PassRefPtr<EventListener>);
380         EventListener* onmessage() const;
381         void setOnmessage(PassRefPtr<EventListener>);
382         EventListener* oncontextmenu() const;
383         void setOncontextmenu(PassRefPtr<EventListener>);
384 
385         void captureEvents();
386         void releaseEvents();
387 
388         // These methods are used for GC marking. See JSDOMWindow::markChildren(MarkStack&) in
389         // JSDOMWindowCustom.cpp.
optionalScreen()390         Screen* optionalScreen() const { return m_screen.get(); }
optionalSelection()391         DOMSelection* optionalSelection() const { return m_selection.get(); }
optionalHistory()392         History* optionalHistory() const { return m_history.get(); }
optionalLocationbar()393         BarInfo* optionalLocationbar() const { return m_locationbar.get(); }
optionalMenubar()394         BarInfo* optionalMenubar() const { return m_menubar.get(); }
optionalPersonalbar()395         BarInfo* optionalPersonalbar() const { return m_personalbar.get(); }
optionalScrollbars()396         BarInfo* optionalScrollbars() const { return m_scrollbars.get(); }
optionalStatusbar()397         BarInfo* optionalStatusbar() const { return m_statusbar.get(); }
optionalToolbar()398         BarInfo* optionalToolbar() const { return m_toolbar.get(); }
optionalConsole()399         Console* optionalConsole() const { return m_console.get(); }
optionalNavigator()400         Navigator* optionalNavigator() const { return m_navigator.get(); }
optionalLocation()401         Location* optionalLocation() const { return m_location.get(); }
402 #if ENABLE(DOM_STORAGE)
optionalSessionStorage()403         Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
optionalLocalStorage()404         Storage* optionalLocalStorage() const { return m_localStorage.get(); }
405 #endif
406 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
optionalApplicationCache()407         DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
408 #endif
409 
410         using RefCounted<DOMWindow>::ref;
411         using RefCounted<DOMWindow>::deref;
412 
413     private:
414         DOMWindow(Frame*);
415 
refEventTarget()416         virtual void refEventTarget() { ref(); }
derefEventTarget()417         virtual void derefEventTarget() { deref(); }
418 
419         void dispatchEventWithDocumentAsTarget(PassRefPtr<Event>, RegisteredEventListenerVector* = 0);
420 
421         RefPtr<SecurityOrigin> m_securityOrigin;
422         KURL m_url;
423 
424         Frame* m_frame;
425         mutable RefPtr<Screen> m_screen;
426         mutable RefPtr<DOMSelection> m_selection;
427         mutable RefPtr<History> m_history;
428         mutable RefPtr<BarInfo> m_locationbar;
429         mutable RefPtr<BarInfo> m_menubar;
430         mutable RefPtr<BarInfo> m_personalbar;
431         mutable RefPtr<BarInfo> m_scrollbars;
432         mutable RefPtr<BarInfo> m_statusbar;
433         mutable RefPtr<BarInfo> m_toolbar;
434         mutable RefPtr<Console> m_console;
435         mutable RefPtr<Navigator> m_navigator;
436         mutable RefPtr<Location> m_location;
437 #if ENABLE(DOM_STORAGE)
438         mutable RefPtr<Storage> m_sessionStorage;
439         mutable RefPtr<Storage> m_localStorage;
440 #endif
441 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
442         mutable RefPtr<DOMApplicationCache> m_applicationCache;
443 #endif
444 
445         RegisteredEventListenerVector m_eventListeners;
446     };
447 
448 } // namespace WebCore
449 
450 #endif // DOMWindow_h
451