Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / DOMWindow.h
1 /*
2  * Copyright (C) 2006, 2007, 2009, 2010 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
25  */
26
27 #ifndef DOMWindow_h
28 #define DOMWindow_h
29
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"
36
37 #include "wtf/Forward.h"
38
39 namespace WebCore {
40     class ApplicationCache;
41     class BarProp;
42     class CSSRuleList;
43     class CSSStyleDeclaration;
44     class Console;
45     class DOMPoint;
46     class DOMSelection;
47     class DOMURL;
48     class DOMWindowProperty;
49     class Database;
50     class DatabaseCallback;
51     class Document;
52     class DocumentInit;
53     class DOMWindowEventQueue;
54     class DOMWindowLifecycleNotifier;
55     class Element;
56     class EventListener;
57     class EventQueue;
58     class ExceptionState;
59     class FloatRect;
60     class Frame;
61     class History;
62     class IDBFactory;
63     class Location;
64     class MediaQueryList;
65     class MessageEvent;
66     class Navigator;
67     class Node;
68     class Page;
69     class PageConsole;
70     class Performance;
71     class PostMessageTimer;
72     class RequestAnimationFrameCallback;
73     class ScheduledAction;
74     class Screen;
75     class ScriptCallStack;
76     class SecurityOrigin;
77     class SerializedScriptValue;
78     class Storage;
79     class StyleMedia;
80     class DOMWindowCSS;
81
82     struct WindowFeatures;
83
84     typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
85
86 enum PageshowEventPersistence {
87     PageshowEventNotPersisted = 0,
88     PageshowEventPersisted = 1
89 };
90
91     enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
92
93     class DOMWindow FINAL : public RefCounted<DOMWindow>, public ScriptWrappable, public EventTargetWithInlineData, public FrameDestructionObserver, public Supplementable<DOMWindow>, public LifecycleContext<DOMWindow> {
94         REFCOUNTED_EVENT_TARGET(DOMWindow);
95     public:
96         static PassRefPtr<Document> createDocument(const String& mimeType, const DocumentInit&, bool forceXHTML);
97         static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
98         virtual ~DOMWindow();
99
100         PassRefPtr<Document> installNewDocument(const String& mimeType, const DocumentInit&, bool forceXHTML = false);
101
102         virtual const AtomicString& interfaceName() const OVERRIDE;
103         virtual ExecutionContext* executionContext() const OVERRIDE;
104
105         virtual DOMWindow* toDOMWindow() OVERRIDE;
106
107         void registerProperty(DOMWindowProperty*);
108         void unregisterProperty(DOMWindowProperty*);
109
110         void reset();
111
112         PassRefPtr<MediaQueryList> matchMedia(const String&);
113
114         unsigned pendingUnloadEventListeners() const;
115
116         static FloatRect adjustWindowRect(Frame*, const FloatRect& pendingChanges);
117
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*);
122
123         // DOM Level 0
124
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(); }
135
136         Location* location() const;
137         void setLocation(const String& location, DOMWindow* activeWindow, DOMWindow* firstWindow,
138             SetLocationLocking = LockHistoryBasedOnGestureState);
139
140         DOMSelection* getSelection();
141
142         Element* frameElement() const;
143
144         void focus(ExecutionContext* = 0);
145         void blur();
146         void close(ExecutionContext* = 0);
147         void print();
148         void stop();
149
150         PassRefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
151             DOMWindow* activeWindow, DOMWindow* firstWindow);
152
153         typedef void (*PrepareDialogFunction)(DOMWindow*, void* context);
154         void showModalDialog(const String& urlString, const String& dialogFeaturesString,
155             DOMWindow* activeWindow, DOMWindow* firstWindow, PrepareDialogFunction, void* functionContext);
156
157         void alert(const String& message);
158         bool confirm(const String& message);
159         String prompt(const String& message, const String& defaultValue);
160
161         bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
162
163         bool offscreenBuffering() const;
164
165         int outerHeight() const;
166         int outerWidth() const;
167         int innerHeight() const;
168         int innerWidth() const;
169         int screenX() const;
170         int screenY() const;
171         int screenLeft() const { return screenX(); }
172         int screenTop() const { return screenY(); }
173         int scrollX() const;
174         int scrollY() const;
175         int pageXOffset() const { return scrollX(); }
176         int pageYOffset() const { return scrollY(); }
177
178         bool closed() const;
179
180         unsigned length() const;
181
182         const AtomicString& name() const;
183         void setName(const AtomicString&);
184
185         String status() const;
186         void setStatus(const String&);
187         String defaultStatus() const;
188         void setDefaultStatus(const String&);
189
190         // Self-referential attributes
191
192         DOMWindow* self() const;
193         DOMWindow* window() const { return self(); }
194         DOMWindow* frames() const { return self(); }
195
196         DOMWindow* opener() const;
197         DOMWindow* parent() const;
198         DOMWindow* top() const;
199
200         // DOM Level 2 AbstractView Interface
201
202         Document* document() const;
203
204         // CSSOM View Module
205
206         PassRefPtr<StyleMedia> styleMedia() const;
207
208         // DOM Level 2 Style Interface
209
210         PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
211
212         // WebKit extensions
213
214         PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt) const;
215         double devicePixelRatio() const;
216
217         PassRefPtr<DOMPoint> webkitConvertPointFromPageToNode(Node*, const DOMPoint*) const;
218         PassRefPtr<DOMPoint> webkitConvertPointFromNodeToPage(Node*, const DOMPoint*) const;
219
220         Console* console() const;
221         PageConsole* pageConsole() const;
222
223         void printErrorMessage(const String&);
224         String crossDomainAccessErrorMessage(DOMWindow* activeWindow);
225         String sanitizedCrossDomainAccessErrorMessage(DOMWindow* activeWindow);
226
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>);
230
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); }
234
235         void moveBy(float x, float y) const;
236         void moveTo(float x, float y) const;
237
238         void resizeBy(float x, float y) const;
239         void resizeTo(float width, float height) const;
240
241         // WebKit animation extensions
242         int requestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
243         int webkitRequestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
244         void cancelAnimationFrame(int id);
245
246         DOMWindowCSS* css();
247
248         // Events
249         // EventTarget API
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;
253
254         using EventTarget::dispatchEvent;
255         bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
256
257         void dispatchLoadEvent();
258
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);
265
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);
270
271         void captureEvents() { }
272         void releaseEvents() { }
273
274         void finishedLoading();
275
276         DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion);
277         DEFINE_ATTRIBUTE_EVENT_LISTENER(deviceorientation);
278
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(); }
284
285         ApplicationCache* applicationCache() const;
286         ApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
287
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;
292
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);
298
299         Performance* performance() const;
300
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;
306
307         void willDetachDocumentFromFrame();
308         DOMWindow* anonymousIndexedGetter(uint32_t);
309
310         bool isInsecureScriptAccess(DOMWindow* activeWindow, const String& urlString);
311
312         PassOwnPtr<LifecycleNotifier<DOMWindow> > createLifecycleNotifier();
313
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>);
323
324         // FIXME: This shouldn't be public once DOMWindow becomes ExecutionContext.
325         void clearEventQueue();
326
327     protected:
328         DOMWindowLifecycleNotifier& lifecycleNotifier();
329
330     private:
331         explicit DOMWindow(Frame*);
332
333         Page* page();
334
335         virtual void frameDestroyed() OVERRIDE;
336         virtual void willDetachFrameHost() OVERRIDE;
337
338         void clearDocument();
339         void resetDOMWindowProperties();
340         void willDestroyDocumentInFrame();
341
342         RefPtr<Document> m_document;
343
344         bool m_shouldPrintWhenFinishedLoading;
345
346         HashSet<DOMWindowProperty*> m_properties;
347
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;
360
361         String m_status;
362         String m_defaultStatus;
363
364         mutable RefPtrWillBePersistent<Storage> m_sessionStorage;
365         mutable RefPtrWillBePersistent<Storage> m_localStorage;
366         mutable RefPtr<ApplicationCache> m_applicationCache;
367
368         mutable RefPtr<Performance> m_performance;
369
370         mutable RefPtr<DOMWindowCSS> m_css;
371
372         RefPtr<DOMWindowEventQueue> m_eventQueue;
373         RefPtr<SerializedScriptValue> m_pendingStateObject;
374     };
375
376     inline String DOMWindow::status() const
377     {
378         return m_status;
379     }
380
381     inline String DOMWindow::defaultStatus() const
382     {
383         return m_defaultStatus;
384     }
385
386 } // namespace WebCore
387
388 #endif // DOMWindow_h