• 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 "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 IndexedDatabaseRequest;
56     class InspectorTimelineAgent;
57     class Location;
58     class Media;
59     class Navigator;
60     class Node;
61     class NotificationCenter;
62     class PostMessageTimer;
63     class ScheduledAction;
64     class SerializedScriptValue;
65     class Screen;
66     class WebKitPoint;
67 
68 #if ENABLE(DOM_STORAGE)
69     class Storage;
70 #endif
71 
72 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
73     class DOMApplicationCache;
74 #endif
75 
76     typedef int ExceptionCode;
77 
78     class DOMWindow : public RefCounted<DOMWindow>, public EventTarget {
79     public:
create(Frame * frame)80         static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
81         virtual ~DOMWindow();
82 
toDOMWindow()83         virtual DOMWindow* toDOMWindow() { return this; }
84         virtual ScriptExecutionContext* scriptExecutionContext() const;
85 
frame()86         Frame* frame() const { return m_frame; }
87         void disconnectFrame();
88 
89         void clear();
90 
91 #if ENABLE(ORIENTATION_EVENTS)
92         // This is the interface orientation in degrees. Some examples are:
93         //  0 is straight up; -90 is when the device is rotated 90 clockwise;
94         //  90 is when rotated counter clockwise.
95         int orientation() const;
96 #endif
97 
setSecurityOrigin(SecurityOrigin * securityOrigin)98         void setSecurityOrigin(SecurityOrigin* securityOrigin) { m_securityOrigin = securityOrigin; }
securityOrigin()99         SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
100 
setURL(const KURL & url)101         void setURL(const KURL& url) { m_url = url; }
url()102         KURL url() const { return m_url; }
103 
104         unsigned pendingUnloadEventListeners() const;
105 
106         static bool dispatchAllPendingBeforeUnloadEvents();
107         static void dispatchAllPendingUnloadEvents();
108 
109         static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges);
110         static void parseModalDialogFeatures(const String& featuresArg, HashMap<String, String>& map);
111 
112         static bool allowPopUp(Frame* activeFrame);
113         static bool canShowModalDialog(const Frame*);
114         static bool canShowModalDialogNow(const Frame*);
115 
116         // DOM Level 0
117         Screen* screen() const;
118         History* history() const;
119         BarInfo* locationbar() const;
120         BarInfo* menubar() const;
121         BarInfo* personalbar() const;
122         BarInfo* scrollbars() const;
123         BarInfo* statusbar() const;
124         BarInfo* toolbar() const;
125         Navigator* navigator() const;
clientInformation()126         Navigator* clientInformation() const { return navigator(); }
127         Location* location() const;
128 
129         DOMSelection* getSelection();
130 
131         Element* frameElement() const;
132 
133         void focus();
134         void blur();
135         void close();
136         void print();
137         void stop();
138 
139         void alert(const String& message);
140         bool confirm(const String& message);
141         String prompt(const String& message, const String& defaultValue);
142 
143         bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
144 
145         bool offscreenBuffering() const;
146 
147         int outerHeight() const;
148         int outerWidth() const;
149         int innerHeight() const;
150         int innerWidth() const;
151         int screenX() const;
152         int screenY() const;
screenLeft()153         int screenLeft() const { return screenX(); }
screenTop()154         int screenTop() const { return screenY(); }
155         int scrollX() const;
156         int scrollY() const;
pageXOffset()157         int pageXOffset() const { return scrollX(); }
pageYOffset()158         int pageYOffset() const { return scrollY(); }
159 
160         bool closed() const;
161 
162         unsigned length() const;
163 
164         String name() const;
165         void setName(const String&);
166 
167         String status() const;
168         void setStatus(const String&);
169         String defaultStatus() const;
170         void setDefaultStatus(const String&);
171         // This attribute is an alias of defaultStatus and is necessary for legacy uses.
defaultstatus()172         String defaultstatus() const { return defaultStatus(); }
setDefaultstatus(const String & status)173         void setDefaultstatus(const String& status) { setDefaultStatus(status); }
174 
175         // Self referential attributes
176         DOMWindow* self() const;
window()177         DOMWindow* window() const { return self(); }
frames()178         DOMWindow* frames() const { return self(); }
179 
180         DOMWindow* opener() const;
181         DOMWindow* parent() const;
182         DOMWindow* top() const;
183 
184         // DOM Level 2 AbstractView Interface
185         Document* document() const;
186         // CSSOM View Module
187         PassRefPtr<Media> media() const;
188 
189         // DOM Level 2 Style Interface
190         PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
191 
192         // WebKit extensions
193         PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const;
194         double devicePixelRatio() const;
195 
196         PassRefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node* node, const WebKitPoint* p) const;
197         PassRefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const;
198 
199 #if ENABLE(DATABASE)
200         // HTML 5 client-side database
201         PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode&);
202 #endif
203 
204 #if ENABLE(DOM_STORAGE)
205         // HTML 5 key/value storage
206         Storage* sessionStorage() const;
207         Storage* localStorage() const;
208 #ifdef ANDROID
209         void clearDOMStorage();
210 #endif
211 #endif
212 
213         Console* console() const;
214 
215 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
216         DOMApplicationCache* applicationCache() const;
217 #endif
218 
219 #if ENABLE(NOTIFICATIONS)
220         NotificationCenter* webkitNotifications() const;
221 #endif
222 
223 #if ENABLE(INDEXED_DATABASE)
224         IndexedDatabaseRequest* indexedDB() const;
225 #endif
226 
227         void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
228         // FIXME: remove this when we update the ObjC bindings (bug #28774).
229         void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
230         void postMessageTimerFired(PostMessageTimer*);
231 
232         void scrollBy(int x, int y) const;
233         void scrollTo(int x, int y) const;
scroll(int x,int y)234         void scroll(int x, int y) const { scrollTo(x, y); }
235 
236         void moveBy(float x, float y) const;
237         void moveTo(float x, float y) const;
238 
239         void resizeBy(float x, float y) const;
240         void resizeTo(float width, float height) const;
241 
242         // Timers
243         int setTimeout(ScheduledAction*, int timeout, ExceptionCode&);
244         void clearTimeout(int timeoutId);
245         int setInterval(ScheduledAction*, int timeout, ExceptionCode&);
246         void clearInterval(int timeoutId);
247 
248         // Events
249         // EventTarget API
250         virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
251         virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
252         virtual void removeAllEventListeners();
253 
254         using EventTarget::dispatchEvent;
255         bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
256         void dispatchLoadEvent();
257 
258         DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
259         DEFINE_ATTRIBUTE_EVENT_LISTENER(beforeunload);
260         DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
261         DEFINE_ATTRIBUTE_EVENT_LISTENER(canplay);
262         DEFINE_ATTRIBUTE_EVENT_LISTENER(canplaythrough);
263         DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
264         DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
265         DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
266         DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
267         DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
268         DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
269         DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
270         DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
271         DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
272         DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
273         DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
274         DEFINE_ATTRIBUTE_EVENT_LISTENER(durationchange);
275         DEFINE_ATTRIBUTE_EVENT_LISTENER(emptied);
276         DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
277         DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
278         DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
279         DEFINE_ATTRIBUTE_EVENT_LISTENER(hashchange);
280         DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
281         DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
282         DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
283         DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
284         DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
285         DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
286         DEFINE_ATTRIBUTE_EVENT_LISTENER(loadeddata);
287         DEFINE_ATTRIBUTE_EVENT_LISTENER(loadedmetadata);
288         DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
289         DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
290         DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
291         DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
292         DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
293         DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
294         DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
295         DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
296         DEFINE_ATTRIBUTE_EVENT_LISTENER(offline);
297         DEFINE_ATTRIBUTE_EVENT_LISTENER(online);
298         DEFINE_ATTRIBUTE_EVENT_LISTENER(pagehide);
299         DEFINE_ATTRIBUTE_EVENT_LISTENER(pageshow);
300         DEFINE_ATTRIBUTE_EVENT_LISTENER(pause);
301         DEFINE_ATTRIBUTE_EVENT_LISTENER(play);
302         DEFINE_ATTRIBUTE_EVENT_LISTENER(playing);
303         DEFINE_ATTRIBUTE_EVENT_LISTENER(popstate);
304         DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
305         DEFINE_ATTRIBUTE_EVENT_LISTENER(ratechange);
306         DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
307         DEFINE_ATTRIBUTE_EVENT_LISTENER(resize);
308         DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
309         DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
310         DEFINE_ATTRIBUTE_EVENT_LISTENER(seeked);
311         DEFINE_ATTRIBUTE_EVENT_LISTENER(seeking);
312         DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
313         DEFINE_ATTRIBUTE_EVENT_LISTENER(stalled);
314         DEFINE_ATTRIBUTE_EVENT_LISTENER(storage);
315         DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
316         DEFINE_ATTRIBUTE_EVENT_LISTENER(suspend);
317         DEFINE_ATTRIBUTE_EVENT_LISTENER(timeupdate);
318         DEFINE_ATTRIBUTE_EVENT_LISTENER(unload);
319         DEFINE_ATTRIBUTE_EVENT_LISTENER(volumechange);
320         DEFINE_ATTRIBUTE_EVENT_LISTENER(waiting);
321         DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitbeginfullscreen);
322         DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitendfullscreen);
323 
324 #if ENABLE(ORIENTATION_EVENTS)
325         DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange);
326 #endif
327 
328         DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationstart, webkitAnimationStart);
329         DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitAnimationIteration);
330         DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimationEnd);
331         DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransitionEnd);
332 
333 #if ENABLE(TOUCH_EVENTS)
334         DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
335         DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
336         DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
337         DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
338 #endif
339         void captureEvents();
340         void releaseEvents();
341 
342         // These methods are used for GC marking. See JSDOMWindow::markChildren(MarkStack&) in
343         // JSDOMWindowCustom.cpp.
optionalScreen()344         Screen* optionalScreen() const { return m_screen.get(); }
optionalSelection()345         DOMSelection* optionalSelection() const { return m_selection.get(); }
optionalHistory()346         History* optionalHistory() const { return m_history.get(); }
optionalLocationbar()347         BarInfo* optionalLocationbar() const { return m_locationbar.get(); }
optionalMenubar()348         BarInfo* optionalMenubar() const { return m_menubar.get(); }
optionalPersonalbar()349         BarInfo* optionalPersonalbar() const { return m_personalbar.get(); }
optionalScrollbars()350         BarInfo* optionalScrollbars() const { return m_scrollbars.get(); }
optionalStatusbar()351         BarInfo* optionalStatusbar() const { return m_statusbar.get(); }
optionalToolbar()352         BarInfo* optionalToolbar() const { return m_toolbar.get(); }
optionalConsole()353         Console* optionalConsole() const { return m_console.get(); }
optionalNavigator()354         Navigator* optionalNavigator() const { return m_navigator.get(); }
optionalLocation()355         Location* optionalLocation() const { return m_location.get(); }
optionalMedia()356         Media* optionalMedia() const { return m_media.get(); }
357 #if ENABLE(DOM_STORAGE)
optionalSessionStorage()358         Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
optionalLocalStorage()359         Storage* optionalLocalStorage() const { return m_localStorage.get(); }
360 #endif
361 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
optionalApplicationCache()362         DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
363 #endif
364 
365         using RefCounted<DOMWindow>::ref;
366         using RefCounted<DOMWindow>::deref;
367 
368     private:
369         DOMWindow(Frame*);
370 
refEventTarget()371         virtual void refEventTarget() { ref(); }
derefEventTarget()372         virtual void derefEventTarget() { deref(); }
373         virtual EventTargetData* eventTargetData();
374         virtual EventTargetData* ensureEventTargetData();
375         InspectorTimelineAgent* inspectorTimelineAgent();
376 
377         RefPtr<SecurityOrigin> m_securityOrigin;
378         KURL m_url;
379 
380         Frame* m_frame;
381         mutable RefPtr<Screen> m_screen;
382         mutable RefPtr<DOMSelection> m_selection;
383         mutable RefPtr<History> m_history;
384         mutable RefPtr<BarInfo> m_locationbar;
385         mutable RefPtr<BarInfo> m_menubar;
386         mutable RefPtr<BarInfo> m_personalbar;
387         mutable RefPtr<BarInfo> m_scrollbars;
388         mutable RefPtr<BarInfo> m_statusbar;
389         mutable RefPtr<BarInfo> m_toolbar;
390         mutable RefPtr<Console> m_console;
391         mutable RefPtr<Navigator> m_navigator;
392         mutable RefPtr<Location> m_location;
393         mutable RefPtr<Media> m_media;
394 #if ENABLE(DOM_STORAGE)
395         mutable RefPtr<Storage> m_sessionStorage;
396         mutable RefPtr<Storage> m_localStorage;
397 #endif
398 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
399         mutable RefPtr<DOMApplicationCache> m_applicationCache;
400 #endif
401 #if ENABLE(NOTIFICATIONS)
402         mutable RefPtr<NotificationCenter> m_notifications;
403 #endif
404 
405         EventTargetData m_eventTargetData;
406     };
407 
408 } // namespace WebCore
409 
410 #endif // DOMWindow_h
411