2 * Copyright (C) 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "EventTarget.h"
31 #include "FrameDestructionObserver.h"
33 #include "Supplementable.h"
39 class CSSStyleDeclaration;
42 class DOMApplicationCache;
45 class DOMWindowProperty;
47 class DatabaseCallback;
62 class PostMessageTimer;
63 class ScheduledAction;
65 class ScriptCallStack;
67 class SerializedScriptValue;
72 #if ENABLE(REQUEST_ANIMATION_FRAME)
73 class RequestAnimationFrameCallback;
76 #if ENABLE(TIZEN_SEARCH_PROVIDER)
80 struct WindowFeatures;
82 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
84 typedef int ExceptionCode;
86 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
88 class DOMWindow : public RefCounted<DOMWindow>, public EventTarget, public FrameDestructionObserver, public Supplementable<DOMWindow> {
90 static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
93 virtual const AtomicString& interfaceName() const;
94 virtual ScriptExecutionContext* scriptExecutionContext() const;
96 virtual DOMWindow* toDOMWindow();
98 void registerProperty(DOMWindowProperty*);
99 void unregisterProperty(DOMWindowProperty*);
102 void suspendForPageCache();
103 void resumeFromPageCache();
105 PassRefPtr<MediaQueryList> matchMedia(const String&);
107 void setSecurityOrigin(SecurityOrigin*);
108 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
110 void setURL(const KURL& url) { m_url = url; }
111 KURL url() const { return m_url; }
113 unsigned pendingUnloadEventListeners() const;
115 static bool dispatchAllPendingBeforeUnloadEvents();
116 static void dispatchAllPendingUnloadEvents();
118 static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges);
120 // FIXME: We can remove this function once V8 showModalDialog is changed to use DOMWindow.
121 static void parseModalDialogFeatures(const String&, HashMap<String, String>&);
123 bool allowPopUp(); // Call on first window, not target window.
124 static bool allowPopUp(Frame* firstFrame);
125 static bool canShowModalDialog(const Frame*);
126 static bool canShowModalDialogNow(const Frame*);
130 Screen* screen() const;
131 History* history() const;
132 Crypto* crypto() const;
133 BarInfo* locationbar() const;
134 BarInfo* menubar() const;
135 BarInfo* personalbar() const;
136 BarInfo* scrollbars() const;
137 BarInfo* statusbar() const;
138 BarInfo* toolbar() const;
139 Navigator* navigator() const;
140 Navigator* clientInformation() const { return navigator(); }
142 Location* location() const;
143 void setLocation(const String& location, DOMWindow* activeWindow, DOMWindow* firstWindow,
144 SetLocationLocking = LockHistoryBasedOnGestureState);
146 DOMSelection* getSelection();
148 Element* frameElement() const;
150 void focus(ScriptExecutionContext* = 0);
152 void close(ScriptExecutionContext* = 0);
156 PassRefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
157 DOMWindow* activeWindow, DOMWindow* firstWindow);
159 typedef void (*PrepareDialogFunction)(DOMWindow*, void* context);
160 void showModalDialog(const String& urlString, const String& dialogFeaturesString,
161 DOMWindow* activeWindow, DOMWindow* firstWindow, PrepareDialogFunction, void* functionContext);
163 void alert(const String& message);
164 bool confirm(const String& message);
165 String prompt(const String& message, const String& defaultValue);
166 String btoa(const String& stringToEncode, ExceptionCode&);
167 String atob(const String& encodedString, ExceptionCode&);
169 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
171 bool offscreenBuffering() const;
173 int outerHeight() const;
174 int outerWidth() const;
175 int innerHeight() const;
176 int innerWidth() const;
179 int screenLeft() const { return screenX(); }
180 int screenTop() const { return screenY(); }
183 int pageXOffset() const { return scrollX(); }
184 int pageYOffset() const { return scrollY(); }
188 unsigned length() const;
191 void setName(const String&);
193 String status() const;
194 void setStatus(const String&);
195 String defaultStatus() const;
196 void setDefaultStatus(const String&);
198 // This attribute is an alias of defaultStatus and is necessary for legacy uses.
199 String defaultstatus() const { return defaultStatus(); }
200 void setDefaultstatus(const String& status) { setDefaultStatus(status); }
202 // Self-referential attributes
204 DOMWindow* self() const;
205 DOMWindow* window() const { return self(); }
206 DOMWindow* frames() const { return self(); }
208 DOMWindow* opener() const;
209 DOMWindow* parent() const;
210 DOMWindow* top() const;
212 // DOM Level 2 AbstractView Interface
214 Document* document() const;
218 PassRefPtr<StyleMedia> styleMedia() const;
220 // DOM Level 2 Style Interface
222 PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
226 PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const;
227 double devicePixelRatio() const;
229 PassRefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node*, const WebKitPoint*) const;
230 PassRefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node*, const WebKitPoint*) const;
232 Console* console() const;
234 void printErrorMessage(const String&);
235 String crossDomainAccessErrorMessage(DOMWindow* activeWindow);
237 void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
238 // FIXME: remove this when we update the ObjC bindings (bug #28774).
239 void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, const String& targetOrigin, DOMWindow* source, ExceptionCode&);
240 void postMessageTimerFired(PassOwnPtr<PostMessageTimer>);
241 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, PassRefPtr<Event>, PassRefPtr<ScriptCallStack>);
243 void scrollBy(int x, int y) const;
244 void scrollTo(int x, int y) const;
245 void scroll(int x, int y) const { scrollTo(x, y); }
247 void moveBy(float x, float y) const;
248 void moveTo(float x, float y) const;
250 void resizeBy(float x, float y) const;
251 void resizeTo(float width, float height) const;
254 int setTimeout(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&);
255 void clearTimeout(int timeoutId);
256 int setInterval(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&);
257 void clearInterval(int timeoutId);
259 // WebKit animation extensions
260 #if ENABLE(REQUEST_ANIMATION_FRAME)
261 int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>);
262 void webkitCancelAnimationFrame(int id);
263 void webkitCancelRequestAnimationFrame(int id) { webkitCancelAnimationFrame(id); }
268 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
269 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
270 virtual void removeAllEventListeners();
272 using EventTarget::dispatchEvent;
273 bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
274 void dispatchLoadEvent();
276 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
277 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforeunload);
278 DEFINE_ATTRIBUTE_EVENT_LISTENER(blur);
279 DEFINE_ATTRIBUTE_EVENT_LISTENER(canplay);
280 DEFINE_ATTRIBUTE_EVENT_LISTENER(canplaythrough);
281 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
282 DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
283 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
284 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
285 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
286 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
287 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
288 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
289 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
290 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
291 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
292 DEFINE_ATTRIBUTE_EVENT_LISTENER(durationchange);
293 DEFINE_ATTRIBUTE_EVENT_LISTENER(emptied);
294 DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
295 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
296 DEFINE_ATTRIBUTE_EVENT_LISTENER(focus);
297 DEFINE_ATTRIBUTE_EVENT_LISTENER(hashchange);
298 DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
299 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
300 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
301 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
302 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
303 DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
304 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadeddata);
305 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadedmetadata);
306 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
307 DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
308 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
309 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
310 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
311 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
312 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
313 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
314 DEFINE_ATTRIBUTE_EVENT_LISTENER(offline);
315 DEFINE_ATTRIBUTE_EVENT_LISTENER(online);
316 DEFINE_ATTRIBUTE_EVENT_LISTENER(pagehide);
317 DEFINE_ATTRIBUTE_EVENT_LISTENER(pageshow);
318 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause);
319 DEFINE_ATTRIBUTE_EVENT_LISTENER(play);
320 DEFINE_ATTRIBUTE_EVENT_LISTENER(playing);
321 DEFINE_ATTRIBUTE_EVENT_LISTENER(popstate);
322 DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
323 DEFINE_ATTRIBUTE_EVENT_LISTENER(ratechange);
324 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
325 DEFINE_ATTRIBUTE_EVENT_LISTENER(resize);
326 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
327 DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
328 DEFINE_ATTRIBUTE_EVENT_LISTENER(seeked);
329 DEFINE_ATTRIBUTE_EVENT_LISTENER(seeking);
330 DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
331 DEFINE_ATTRIBUTE_EVENT_LISTENER(stalled);
332 DEFINE_ATTRIBUTE_EVENT_LISTENER(storage);
333 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
334 DEFINE_ATTRIBUTE_EVENT_LISTENER(suspend);
335 DEFINE_ATTRIBUTE_EVENT_LISTENER(timeupdate);
336 DEFINE_ATTRIBUTE_EVENT_LISTENER(unload);
337 DEFINE_ATTRIBUTE_EVENT_LISTENER(volumechange);
338 DEFINE_ATTRIBUTE_EVENT_LISTENER(waiting);
339 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitbeginfullscreen);
340 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitendfullscreen);
342 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationstart, webkitAnimationStart);
343 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitAnimationIteration);
344 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimationEnd);
345 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransitionEnd);
347 void captureEvents();
348 void releaseEvents();
350 void finishedLoading();
352 using RefCounted<DOMWindow>::ref;
353 using RefCounted<DOMWindow>::deref;
355 #if ENABLE(DEVICE_ORIENTATION)
356 DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion);
357 DEFINE_ATTRIBUTE_EVENT_LISTENER(deviceorientation);
360 // HTML 5 key/value storage
361 Storage* sessionStorage(ExceptionCode&) const;
362 Storage* localStorage(ExceptionCode&) const;
363 Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
364 Storage* optionalLocalStorage() const { return m_localStorage.get(); }
366 DOMApplicationCache* applicationCache() const;
367 DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
369 #if ENABLE(ORIENTATION_EVENTS)
370 // This is the interface orientation in degrees. Some examples are:
371 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
372 // 90 is when rotated counter clockwise.
373 int orientation() const;
375 DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange);
378 #if ENABLE(TOUCH_EVENTS)
379 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
380 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
381 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
382 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
385 #if ENABLE(WEB_TIMING)
386 Performance* performance() const;
389 #if ENABLE(TIZEN_SEARCH_PROVIDER)
390 External* external() const;
393 // FIXME: When this DOMWindow is no longer the active DOMWindow (i.e.,
394 // when its document is no longer the document that is displayed in its
395 // frame), we would like to zero out m_frame to avoid being confused
396 // by the document that is currently active in m_frame.
397 bool isCurrentlyDisplayedInFrame() const;
399 void willDetachDocumentFromFrame();
400 void willDestroyCachedFrame();
403 explicit DOMWindow(Frame*);
407 virtual void frameDestroyed() OVERRIDE;
408 virtual void willDetachPage() OVERRIDE;
410 virtual void refEventTarget() { ref(); }
411 virtual void derefEventTarget() { deref(); }
412 virtual EventTargetData* eventTargetData();
413 virtual EventTargetData* ensureEventTargetData();
415 static Frame* createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures&,
416 DOMWindow* activeWindow, Frame* firstFrame, Frame* openerFrame,
417 PrepareDialogFunction = 0, void* functionContext = 0);
418 bool isInsecureScriptAccess(DOMWindow* activeWindow, const String& urlString);
420 void clearDOMWindowProperties();
421 void disconnectDOMWindowProperties();
422 void reconnectDOMWindowProperties();
423 void willDestroyDocumentInFrame();
425 RefPtr<SecurityOrigin> m_securityOrigin;
428 bool m_shouldPrintWhenFinishedLoading;
429 bool m_suspendedForPageCache;
431 HashSet<DOMWindowProperty*> m_properties;
433 mutable RefPtr<Screen> m_screen;
434 mutable RefPtr<History> m_history;
435 mutable RefPtr<Crypto> m_crypto;
436 mutable RefPtr<BarInfo> m_locationbar;
437 mutable RefPtr<BarInfo> m_menubar;
438 mutable RefPtr<BarInfo> m_personalbar;
439 mutable RefPtr<BarInfo> m_scrollbars;
440 mutable RefPtr<BarInfo> m_statusbar;
441 mutable RefPtr<BarInfo> m_toolbar;
442 mutable RefPtr<Console> m_console;
443 mutable RefPtr<Navigator> m_navigator;
444 mutable RefPtr<Location> m_location;
445 mutable RefPtr<StyleMedia> m_media;
447 EventTargetData m_eventTargetData;
450 String m_defaultStatus;
452 mutable RefPtr<Storage> m_sessionStorage;
453 mutable RefPtr<Storage> m_localStorage;
454 mutable RefPtr<DOMApplicationCache> m_applicationCache;
456 #if ENABLE(WEB_TIMING)
457 mutable RefPtr<Performance> m_performance;
461 mutable RefPtr<DOMURL> m_domURL;
463 #if ENABLE(TIZEN_SEARCH_PROVIDER)
464 mutable RefPtr<External> m_external;
468 inline String DOMWindow::status() const
473 inline String DOMWindow::defaultStatus() const
475 return m_defaultStatus;
478 } // namespace WebCore
480 #endif // DOMWindow_h