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 "bindings/v8/Dictionary.h"
31 #include "bindings/v8/ScriptWrappable.h"
32 #include "core/events/EventTarget.h"
33 #include "core/frame/FrameDestructionObserver.h"
34 #include "platform/LifecycleContext.h"
35 #include "platform/Supplementable.h"
37 #include "wtf/Forward.h"
40 class ApplicationCache;
43 class CSSStyleDeclaration;
48 class DOMWindowProperty;
50 class DatabaseCallback;
53 class DOMWindowEventQueue;
54 class DOMWindowLifecycleNotifier;
71 class PostMessageTimer;
72 class RequestAnimationFrameCallback;
73 class ScheduledAction;
75 class ScriptCallStack;
77 class SerializedScriptValue;
82 struct WindowFeatures;
84 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
86 enum PageshowEventPersistence {
87 PageshowEventNotPersisted = 0,
88 PageshowEventPersisted = 1
91 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
93 class DOMWindow FINAL : public RefCounted<DOMWindow>, public ScriptWrappable, public EventTargetWithInlineData, public FrameDestructionObserver, public Supplementable<DOMWindow>, public LifecycleContext<DOMWindow> {
94 REFCOUNTED_EVENT_TARGET(DOMWindow);
96 static PassRefPtr<Document> createDocument(const String& mimeType, const DocumentInit&, bool forceXHTML);
97 static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
100 PassRefPtr<Document> installNewDocument(const String& mimeType, const DocumentInit&, bool forceXHTML = false);
102 virtual const AtomicString& interfaceName() const OVERRIDE;
103 virtual ExecutionContext* executionContext() const OVERRIDE;
105 virtual DOMWindow* toDOMWindow() OVERRIDE;
107 void registerProperty(DOMWindowProperty*);
108 void unregisterProperty(DOMWindowProperty*);
112 PassRefPtr<MediaQueryList> matchMedia(const String&);
114 unsigned pendingUnloadEventListeners() const;
116 static FloatRect adjustWindowRect(Frame*, const FloatRect& pendingChanges);
118 bool allowPopUp(); // Call on first window, not target window.
119 static bool allowPopUp(Frame* firstFrame);
120 static bool canShowModalDialog(const Frame*);
121 static bool canShowModalDialogNow(const Frame*);
125 Screen* screen() const;
126 History* history() const;
127 BarProp* locationbar() const;
128 BarProp* menubar() const;
129 BarProp* personalbar() const;
130 BarProp* scrollbars() const;
131 BarProp* statusbar() const;
132 BarProp* toolbar() const;
133 Navigator* navigator() const;
134 Navigator* clientInformation() const { return navigator(); }
136 Location* location() const;
137 void setLocation(const String& location, DOMWindow* activeWindow, DOMWindow* firstWindow,
138 SetLocationLocking = LockHistoryBasedOnGestureState);
140 DOMSelection* getSelection();
142 Element* frameElement() const;
144 void focus(ExecutionContext* = 0);
146 void close(ExecutionContext* = 0);
150 PassRefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
151 DOMWindow* activeWindow, DOMWindow* firstWindow);
153 typedef void (*PrepareDialogFunction)(DOMWindow*, void* context);
154 void showModalDialog(const String& urlString, const String& dialogFeaturesString,
155 DOMWindow* activeWindow, DOMWindow* firstWindow, PrepareDialogFunction, void* functionContext);
157 void alert(const String& message);
158 bool confirm(const String& message);
159 String prompt(const String& message, const String& defaultValue);
161 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
163 bool offscreenBuffering() const;
165 int outerHeight() const;
166 int outerWidth() const;
167 int innerHeight() const;
168 int innerWidth() const;
171 int screenLeft() const { return screenX(); }
172 int screenTop() const { return screenY(); }
175 int pageXOffset() const { return scrollX(); }
176 int pageYOffset() const { return scrollY(); }
180 unsigned length() const;
182 const AtomicString& name() const;
183 void setName(const AtomicString&);
185 String status() const;
186 void setStatus(const String&);
187 String defaultStatus() const;
188 void setDefaultStatus(const String&);
190 // Self-referential attributes
192 DOMWindow* self() const;
193 DOMWindow* window() const { return self(); }
194 DOMWindow* frames() const { return self(); }
196 DOMWindow* opener() const;
197 DOMWindow* parent() const;
198 DOMWindow* top() const;
200 // DOM Level 2 AbstractView Interface
202 Document* document() const;
206 PassRefPtr<StyleMedia> styleMedia() const;
208 // DOM Level 2 Style Interface
210 PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
214 PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt) const;
215 double devicePixelRatio() const;
217 PassRefPtr<DOMPoint> webkitConvertPointFromPageToNode(Node*, const DOMPoint*) const;
218 PassRefPtr<DOMPoint> webkitConvertPointFromNodeToPage(Node*, const DOMPoint*) const;
220 Console* console() const;
221 PageConsole* pageConsole() const;
223 void printErrorMessage(const String&);
224 String crossDomainAccessErrorMessage(DOMWindow* activeWindow);
225 String sanitizedCrossDomainAccessErrorMessage(DOMWindow* activeWindow);
227 void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, const String& targetOrigin, DOMWindow* source, ExceptionState&);
228 void postMessageTimerFired(PassOwnPtr<PostMessageTimer>);
229 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, PassRefPtr<Event>, PassRefPtr<ScriptCallStack>);
231 void scrollBy(int x, int y, const Dictionary& scrollOptions, ExceptionState&) const;
232 void scrollTo(int x, int y, const Dictionary& scrollOptions, ExceptionState&) const;
233 void scroll(int x, int y, const Dictionary& scrollOptions, ExceptionState& exceptionState) const { scrollTo(x, y, scrollOptions, exceptionState); }
235 void moveBy(float x, float y) const;
236 void moveTo(float x, float y) const;
238 void resizeBy(float x, float y) const;
239 void resizeTo(float width, float height) const;
241 // WebKit animation extensions
242 int requestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
243 int webkitRequestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
244 void cancelAnimationFrame(int id);
250 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) OVERRIDE;
251 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) OVERRIDE;
252 virtual void removeAllEventListeners() OVERRIDE;
254 using EventTarget::dispatchEvent;
255 bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
257 void dispatchLoadEvent();
259 DEFINE_ATTRIBUTE_EVENT_LISTENER(animationend);
260 DEFINE_ATTRIBUTE_EVENT_LISTENER(animationiteration);
261 DEFINE_ATTRIBUTE_EVENT_LISTENER(animationstart);
262 DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
263 DEFINE_ATTRIBUTE_EVENT_LISTENER(transitionend);
264 DEFINE_ATTRIBUTE_EVENT_LISTENER(wheel);
266 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationstart, webkitAnimationStart);
267 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitAnimationIteration);
268 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimationEnd);
269 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransitionEnd);
271 void captureEvents() { }
272 void releaseEvents() { }
274 void finishedLoading();
276 DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion);
277 DEFINE_ATTRIBUTE_EVENT_LISTENER(deviceorientation);
279 // HTML 5 key/value storage
280 Storage* sessionStorage(ExceptionState&) const;
281 Storage* localStorage(ExceptionState&) const;
282 Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
283 Storage* optionalLocalStorage() const { return m_localStorage.get(); }
285 ApplicationCache* applicationCache() const;
286 ApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
288 // This is the interface orientation in degrees. Some examples are:
289 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
290 // 90 is when rotated counter clockwise.
291 int orientation() const;
293 DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange);
294 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
295 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
296 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
297 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
299 Performance* performance() const;
301 // FIXME: When this DOMWindow is no longer the active DOMWindow (i.e.,
302 // when its document is no longer the document that is displayed in its
303 // frame), we would like to zero out m_frame to avoid being confused
304 // by the document that is currently active in m_frame.
305 bool isCurrentlyDisplayedInFrame() const;
307 void willDetachDocumentFromFrame();
308 DOMWindow* anonymousIndexedGetter(uint32_t);
310 bool isInsecureScriptAccess(DOMWindow* activeWindow, const String& urlString);
312 PassOwnPtr<LifecycleNotifier<DOMWindow> > createLifecycleNotifier();
314 EventQueue* eventQueue() const;
315 void enqueueWindowEvent(PassRefPtr<Event>);
316 void enqueueDocumentEvent(PassRefPtr<Event>);
317 void enqueuePageshowEvent(PageshowEventPersistence);
318 void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
319 void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue>);
320 void dispatchWindowLoadEvent();
321 void documentWasClosed();
322 void statePopped(PassRefPtr<SerializedScriptValue>);
324 // FIXME: This shouldn't be public once DOMWindow becomes ExecutionContext.
325 void clearEventQueue();
328 DOMWindowLifecycleNotifier& lifecycleNotifier();
331 explicit DOMWindow(Frame*);
335 virtual void frameDestroyed() OVERRIDE;
336 virtual void willDetachFrameHost() OVERRIDE;
338 void clearDocument();
339 void resetDOMWindowProperties();
340 void willDestroyDocumentInFrame();
342 RefPtr<Document> m_document;
344 bool m_shouldPrintWhenFinishedLoading;
346 HashSet<DOMWindowProperty*> m_properties;
348 mutable RefPtr<Screen> m_screen;
349 mutable RefPtr<History> m_history;
350 mutable RefPtr<BarProp> m_locationbar;
351 mutable RefPtr<BarProp> m_menubar;
352 mutable RefPtr<BarProp> m_personalbar;
353 mutable RefPtr<BarProp> m_scrollbars;
354 mutable RefPtr<BarProp> m_statusbar;
355 mutable RefPtr<BarProp> m_toolbar;
356 mutable RefPtr<Console> m_console;
357 mutable RefPtr<Navigator> m_navigator;
358 mutable RefPtr<Location> m_location;
359 mutable RefPtr<StyleMedia> m_media;
362 String m_defaultStatus;
364 mutable RefPtrWillBePersistent<Storage> m_sessionStorage;
365 mutable RefPtrWillBePersistent<Storage> m_localStorage;
366 mutable RefPtr<ApplicationCache> m_applicationCache;
368 mutable RefPtr<Performance> m_performance;
370 mutable RefPtr<DOMWindowCSS> m_css;
372 RefPtr<DOMWindowEventQueue> m_eventQueue;
373 RefPtr<SerializedScriptValue> m_pendingStateObject;
376 inline String DOMWindow::status() const
381 inline String DOMWindow::defaultStatus() const
383 return m_defaultStatus;
386 } // namespace WebCore
388 #endif // DOMWindow_h