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/DOMWindowBase64.h"
34 #include "core/frame/FrameDestructionObserver.h"
35 #include "platform/LifecycleContext.h"
36 #include "platform/Supplementable.h"
37 #include "platform/heap/Handle.h"
39 #include "wtf/Forward.h"
42 class ApplicationCache;
45 class CSSStyleDeclaration;
50 class DOMWindowProperty;
52 class DatabaseCallback;
55 class DOMWindowEventQueue;
56 class DOMWindowLifecycleNotifier;
73 class PostMessageTimer;
74 class RequestAnimationFrameCallback;
75 class ScheduledAction;
77 class ScriptCallStack;
79 class SerializedScriptValue;
84 struct WindowFeatures;
86 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
88 enum PageshowEventPersistence {
89 PageshowEventNotPersisted = 0,
90 PageshowEventPersisted = 1
93 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
95 class LocalDOMWindow FINAL : public RefCountedWillBeRefCountedGarbageCollected<LocalDOMWindow>, public ScriptWrappable, public EventTargetWithInlineData, public DOMWindowBase64, public FrameDestructionObserver, public WillBeHeapSupplementable<LocalDOMWindow>, public LifecycleContext<LocalDOMWindow> {
96 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(LocalDOMWindow);
97 REFCOUNTED_EVENT_TARGET(LocalDOMWindow);
99 static PassRefPtrWillBeRawPtr<Document> createDocument(const String& mimeType, const DocumentInit&, bool forceXHTML);
100 static PassRefPtrWillBeRawPtr<LocalDOMWindow> create(LocalFrame& frame)
102 return adoptRefWillBeRefCountedGarbageCollected(new LocalDOMWindow(frame));
104 virtual ~LocalDOMWindow();
106 PassRefPtrWillBeRawPtr<Document> installNewDocument(const String& mimeType, const DocumentInit&, bool forceXHTML = false);
108 virtual const AtomicString& interfaceName() const OVERRIDE;
109 virtual ExecutionContext* executionContext() const OVERRIDE;
111 virtual LocalDOMWindow* toDOMWindow() OVERRIDE;
113 void registerProperty(DOMWindowProperty*);
114 void unregisterProperty(DOMWindowProperty*);
118 PassRefPtrWillBeRawPtr<MediaQueryList> matchMedia(const String&);
120 unsigned pendingUnloadEventListeners() const;
122 static FloatRect adjustWindowRect(LocalFrame&, const FloatRect& pendingChanges);
124 bool allowPopUp(); // Call on first window, not target window.
125 static bool allowPopUp(LocalFrame& firstFrame);
126 static bool canShowModalDialogNow(const LocalFrame*);
130 Screen& screen() const;
131 History& history() const;
132 BarProp& locationbar() const;
133 BarProp& menubar() const;
134 BarProp& personalbar() const;
135 BarProp& scrollbars() const;
136 BarProp& statusbar() const;
137 BarProp& toolbar() const;
138 Navigator& navigator() const;
139 Navigator& clientInformation() const { return navigator(); }
141 Location& location() const;
142 void setLocation(const String& location, LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow,
143 SetLocationLocking = LockHistoryBasedOnGestureState);
145 DOMSelection* getSelection();
147 Element* frameElement() const;
149 void focus(ExecutionContext* = 0);
151 void close(ExecutionContext* = 0);
155 PassRefPtrWillBeRawPtr<LocalDOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
156 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow);
158 typedef void (*PrepareDialogFunction)(LocalDOMWindow*, void* context);
159 void showModalDialog(const String& urlString, const String& dialogFeaturesString,
160 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow, PrepareDialogFunction, void* functionContext);
162 void alert(const String& message = String());
163 bool confirm(const String& message);
164 String prompt(const String& message, const String& defaultValue);
166 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
168 bool offscreenBuffering() const;
170 int outerHeight() const;
171 int outerWidth() const;
172 int innerHeight() const;
173 int innerWidth() const;
176 int screenLeft() const { return screenX(); }
177 int screenTop() const { return screenY(); }
180 int pageXOffset() const { return scrollX(); }
181 int pageYOffset() const { return scrollY(); }
185 unsigned length() const;
187 const AtomicString& name() const;
188 void setName(const AtomicString&);
190 String status() const;
191 void setStatus(const String&);
192 String defaultStatus() const;
193 void setDefaultStatus(const String&);
195 // Self-referential attributes
197 LocalDOMWindow* self() const;
198 LocalDOMWindow* window() const { return self(); }
199 LocalDOMWindow* frames() const { return self(); }
201 LocalDOMWindow* opener() const;
202 LocalDOMWindow* parent() const;
203 LocalDOMWindow* top() const;
205 // DOM Level 2 AbstractView Interface
207 Document* document() const;
211 StyleMedia& styleMedia() const;
213 // DOM Level 2 Style Interface
215 PassRefPtrWillBeRawPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
219 PassRefPtrWillBeRawPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt) const;
220 double devicePixelRatio() const;
222 PassRefPtrWillBeRawPtr<DOMPoint> webkitConvertPointFromPageToNode(Node*, const DOMPoint*) const;
223 PassRefPtrWillBeRawPtr<DOMPoint> webkitConvertPointFromNodeToPage(Node*, const DOMPoint*) const;
225 Console& console() const;
226 FrameConsole* frameConsole() const;
228 void printErrorMessage(const String&);
229 String crossDomainAccessErrorMessage(LocalDOMWindow* callingWindow);
230 String sanitizedCrossDomainAccessErrorMessage(LocalDOMWindow* callingWindow);
232 void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, const String& targetOrigin, LocalDOMWindow* source, ExceptionState&);
233 void postMessageTimerFired(PostMessageTimer*);
234 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, PassRefPtrWillBeRawPtr<Event>, PassRefPtrWillBeRawPtr<ScriptCallStack>);
236 void scrollBy(int x, int y) const;
237 void scrollBy(int x, int y, const Dictionary& scrollOptions, ExceptionState&) const;
238 void scrollTo(int x, int y) const;
239 void scrollTo(int x, int y, const Dictionary& scrollOptions, ExceptionState&) const;
240 void scroll(int x, int y) const { scrollTo(x, y); }
241 void scroll(int x, int y, const Dictionary& scrollOptions, ExceptionState& exceptionState) const { scrollTo(x, y, scrollOptions, exceptionState); }
243 void moveBy(float x, float y) const;
244 void moveTo(float x, float y) const;
246 void resizeBy(float x, float y) const;
247 void resizeTo(float width, float height) const;
249 // WebKit animation extensions
250 int requestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
251 int webkitRequestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
252 void cancelAnimationFrame(int id);
254 DOMWindowCSS& css() const;
258 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture = false) OVERRIDE;
259 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture = false) OVERRIDE;
260 virtual void removeAllEventListeners() OVERRIDE;
262 using EventTarget::dispatchEvent;
263 bool dispatchEvent(PassRefPtrWillBeRawPtr<Event> prpEvent, PassRefPtrWillBeRawPtr<EventTarget> prpTarget);
265 void dispatchLoadEvent();
267 DEFINE_ATTRIBUTE_EVENT_LISTENER(animationend);
268 DEFINE_ATTRIBUTE_EVENT_LISTENER(animationiteration);
269 DEFINE_ATTRIBUTE_EVENT_LISTENER(animationstart);
270 DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
271 DEFINE_ATTRIBUTE_EVENT_LISTENER(transitionend);
272 DEFINE_ATTRIBUTE_EVENT_LISTENER(wheel);
274 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationstart, webkitAnimationStart);
275 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitAnimationIteration);
276 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimationEnd);
277 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransitionEnd);
279 void captureEvents() { }
280 void releaseEvents() { }
282 void finishedLoading();
284 // HTML 5 key/value storage
285 Storage* sessionStorage(ExceptionState&) const;
286 Storage* localStorage(ExceptionState&) const;
287 Storage* optionalSessionStorage() const { return m_sessionStorage.get(); }
288 Storage* optionalLocalStorage() const { return m_localStorage.get(); }
290 ApplicationCache* applicationCache() const;
291 ApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
293 // This is the interface orientation in degrees. Some examples are:
294 // 0 is straight up; -90 is when the device is rotated 90 clockwise;
295 // 90 is when rotated counter clockwise.
296 int orientation() const;
298 DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange);
299 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
300 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
301 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
302 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
304 Performance& performance() const;
306 // FIXME: When this LocalDOMWindow is no longer the active LocalDOMWindow (i.e.,
307 // when its document is no longer the document that is displayed in its
308 // frame), we would like to zero out m_frame to avoid being confused
309 // by the document that is currently active in m_frame.
310 bool isCurrentlyDisplayedInFrame() const;
312 void willDetachDocumentFromFrame();
313 LocalDOMWindow* anonymousIndexedGetter(uint32_t);
315 bool isInsecureScriptAccess(LocalDOMWindow& callingWindow, const String& urlString);
317 PassOwnPtr<LifecycleNotifier<LocalDOMWindow> > createLifecycleNotifier();
319 EventQueue* eventQueue() const;
320 void enqueueWindowEvent(PassRefPtrWillBeRawPtr<Event>);
321 void enqueueDocumentEvent(PassRefPtrWillBeRawPtr<Event>);
322 void enqueuePageshowEvent(PageshowEventPersistence);
323 void enqueueHashchangeEvent(const String& oldURL, const String& newURL);
324 void enqueuePopstateEvent(PassRefPtr<SerializedScriptValue>);
325 void dispatchWindowLoadEvent();
326 void documentWasClosed();
327 void statePopped(PassRefPtr<SerializedScriptValue>);
329 // FIXME: This shouldn't be public once LocalDOMWindow becomes ExecutionContext.
330 void clearEventQueue();
332 void acceptLanguagesChanged();
334 virtual void trace(Visitor*) OVERRIDE;
337 DOMWindowLifecycleNotifier& lifecycleNotifier();
340 explicit LocalDOMWindow(LocalFrame&);
344 virtual void frameDestroyed() OVERRIDE;
345 virtual void willDetachFrameHost() OVERRIDE;
347 void clearDocument();
348 void resetDOMWindowProperties();
349 void willDestroyDocumentInFrame();
351 // FIXME: Oilpan: the need for this internal method will fall
352 // away when EventTargets are no longer using refcounts and
353 // window properties are also on the heap. Inline the minimal
354 // do-not-broadcast handling then and remove the enum +
355 // removeAllEventListenersInternal().
356 enum BroadcastListenerRemoval {
357 DoNotBroadcastListenerRemoval,
358 DoBroadcastListenerRemoval
361 void removeAllEventListenersInternal(BroadcastListenerRemoval);
363 RefPtrWillBeMember<Document> m_document;
365 bool m_shouldPrintWhenFinishedLoading;
370 HashSet<DOMWindowProperty*> m_properties;
372 mutable RefPtrWillBeMember<Screen> m_screen;
373 mutable RefPtrWillBeMember<History> m_history;
374 mutable RefPtrWillBeMember<BarProp> m_locationbar;
375 mutable RefPtrWillBeMember<BarProp> m_menubar;
376 mutable RefPtrWillBeMember<BarProp> m_personalbar;
377 mutable RefPtrWillBeMember<BarProp> m_scrollbars;
378 mutable RefPtrWillBeMember<BarProp> m_statusbar;
379 mutable RefPtrWillBeMember<BarProp> m_toolbar;
380 mutable RefPtrWillBeMember<Console> m_console;
381 mutable RefPtrWillBeMember<Navigator> m_navigator;
382 mutable RefPtrWillBeMember<Location> m_location;
383 mutable RefPtrWillBeMember<StyleMedia> m_media;
386 String m_defaultStatus;
388 mutable RefPtrWillBeMember<Storage> m_sessionStorage;
389 mutable RefPtrWillBeMember<Storage> m_localStorage;
390 mutable RefPtrWillBeMember<ApplicationCache> m_applicationCache;
392 mutable RefPtrWillBeMember<Performance> m_performance;
394 mutable RefPtrWillBeMember<DOMWindowCSS> m_css;
396 RefPtrWillBeMember<DOMWindowEventQueue> m_eventQueue;
397 RefPtr<SerializedScriptValue> m_pendingStateObject;
399 HashSet<OwnPtr<PostMessageTimer> > m_postMessageTimers;
402 inline String LocalDOMWindow::status() const
407 inline String LocalDOMWindow::defaultStatus() const
409 return m_defaultStatus;
412 } // namespace WebCore
414 #endif // DOMWindow_h