Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / 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 "EventTarget.h"
31 #include "FrameDestructionObserver.h"
32 #include "KURL.h"
33 #include "Supplementable.h"
34
35 namespace WebCore {
36
37     class BarInfo;
38     class CSSRuleList;
39     class CSSStyleDeclaration;
40     class Console;
41     class Crypto;
42     class DOMApplicationCache;
43     class DOMSelection;
44     class DOMURL;
45     class DOMWindowProperty;
46     class Database;
47     class DatabaseCallback;
48     class Document;
49     class Element;
50     class EventListener;
51     class FloatRect;
52     class Frame;
53     class History;
54     class IDBFactory;
55     class Location;
56     class MediaQueryList;
57     class MessageEvent;
58     class Navigator;
59     class Node;
60     class Page;
61     class Performance;
62     class PostMessageTimer;
63     class ScheduledAction;
64     class Screen;
65     class ScriptCallStack;
66     class SecurityOrigin;
67     class SerializedScriptValue;
68     class Storage;
69     class StyleMedia;
70     class WebKitPoint;
71
72 #if ENABLE(REQUEST_ANIMATION_FRAME)
73     class RequestAnimationFrameCallback;
74 #endif
75
76 #if ENABLE(TIZEN_SEARCH_PROVIDER)
77     class External;
78 #endif
79
80     struct WindowFeatures;
81
82     typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
83
84     typedef int ExceptionCode;
85
86     enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
87
88     class DOMWindow : public RefCounted<DOMWindow>, public EventTarget, public FrameDestructionObserver, public Supplementable<DOMWindow> {
89     public:
90         static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); }
91         virtual ~DOMWindow();
92
93         virtual const AtomicString& interfaceName() const;
94         virtual ScriptExecutionContext* scriptExecutionContext() const;
95
96         virtual DOMWindow* toDOMWindow();
97
98         void registerProperty(DOMWindowProperty*);
99         void unregisterProperty(DOMWindowProperty*);
100
101         void clear();
102         void suspendForPageCache();
103         void resumeFromPageCache();
104
105         PassRefPtr<MediaQueryList> matchMedia(const String&);
106
107         void setSecurityOrigin(SecurityOrigin*);
108         SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
109
110         void setURL(const KURL& url) { m_url = url; }
111         KURL url() const { return m_url; }
112
113         unsigned pendingUnloadEventListeners() const;
114
115         static bool dispatchAllPendingBeforeUnloadEvents();
116         static void dispatchAllPendingUnloadEvents();
117
118         static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges);
119
120         // FIXME: We can remove this function once V8 showModalDialog is changed to use DOMWindow.
121         static void parseModalDialogFeatures(const String&, HashMap<String, String>&);
122
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*);
127
128         // DOM Level 0
129
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(); }
141
142         Location* location() const;
143         void setLocation(const String& location, DOMWindow* activeWindow, DOMWindow* firstWindow,
144             SetLocationLocking = LockHistoryBasedOnGestureState);
145
146         DOMSelection* getSelection();
147
148         Element* frameElement() const;
149
150         void focus(ScriptExecutionContext* = 0);
151         void blur();
152         void close(ScriptExecutionContext* = 0);
153         void print();
154         void stop();
155
156         PassRefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
157             DOMWindow* activeWindow, DOMWindow* firstWindow);
158
159         typedef void (*PrepareDialogFunction)(DOMWindow*, void* context);
160         void showModalDialog(const String& urlString, const String& dialogFeaturesString,
161             DOMWindow* activeWindow, DOMWindow* firstWindow, PrepareDialogFunction, void* functionContext);
162
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&);
168
169         bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
170
171         bool offscreenBuffering() const;
172
173         int outerHeight() const;
174         int outerWidth() const;
175         int innerHeight() const;
176         int innerWidth() const;
177         int screenX() const;
178         int screenY() const;
179         int screenLeft() const { return screenX(); }
180         int screenTop() const { return screenY(); }
181         int scrollX() const;
182         int scrollY() const;
183         int pageXOffset() const { return scrollX(); }
184         int pageYOffset() const { return scrollY(); }
185
186         bool closed() const;
187
188         unsigned length() const;
189
190         String name() const;
191         void setName(const String&);
192
193         String status() const;
194         void setStatus(const String&);
195         String defaultStatus() const;
196         void setDefaultStatus(const String&);
197
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); }
201
202         // Self-referential attributes
203
204         DOMWindow* self() const;
205         DOMWindow* window() const { return self(); }
206         DOMWindow* frames() const { return self(); }
207
208         DOMWindow* opener() const;
209         DOMWindow* parent() const;
210         DOMWindow* top() const;
211
212         // DOM Level 2 AbstractView Interface
213
214         Document* document() const;
215
216         // CSSOM View Module
217
218         PassRefPtr<StyleMedia> styleMedia() const;
219
220         // DOM Level 2 Style Interface
221
222         PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
223
224         // WebKit extensions
225
226         PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const;
227         double devicePixelRatio() const;
228
229         PassRefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node*, const WebKitPoint*) const;
230         PassRefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node*, const WebKitPoint*) const;        
231
232         Console* console() const;
233
234         void printErrorMessage(const String&);
235         String crossDomainAccessErrorMessage(DOMWindow* activeWindow);
236
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>);
242
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); }
246
247         void moveBy(float x, float y) const;
248         void moveTo(float x, float y) const;
249
250         void resizeBy(float x, float y) const;
251         void resizeTo(float width, float height) const;
252
253         // Timers
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);
258
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); }
264 #endif
265
266         // Events
267         // EventTarget API
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();
271
272         using EventTarget::dispatchEvent;
273         bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget);
274         void dispatchLoadEvent();
275
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);
341
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);
346
347         void captureEvents();
348         void releaseEvents();
349
350         void finishedLoading();
351
352         using RefCounted<DOMWindow>::ref;
353         using RefCounted<DOMWindow>::deref;
354
355 #if ENABLE(DEVICE_ORIENTATION)
356         DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion);
357         DEFINE_ATTRIBUTE_EVENT_LISTENER(deviceorientation);
358 #endif
359
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(); }
365
366         DOMApplicationCache* applicationCache() const;
367         DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
368
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;
374
375         DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange);
376 #endif
377
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);
383 #endif
384
385 #if ENABLE(WEB_TIMING)
386         Performance* performance() const;
387 #endif
388
389 #if ENABLE(TIZEN_SEARCH_PROVIDER)
390         External* external() const;
391 #endif
392
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;
398
399         void willDetachDocumentFromFrame();
400         void willDestroyCachedFrame();
401
402     private:
403         explicit DOMWindow(Frame*);
404
405         Page* page();
406
407         virtual void frameDestroyed() OVERRIDE;
408         virtual void willDetachPage() OVERRIDE;
409
410         virtual void refEventTarget() { ref(); }
411         virtual void derefEventTarget() { deref(); }
412         virtual EventTargetData* eventTargetData();
413         virtual EventTargetData* ensureEventTargetData();
414
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);
419
420         void clearDOMWindowProperties();
421         void disconnectDOMWindowProperties();
422         void reconnectDOMWindowProperties();
423         void willDestroyDocumentInFrame();
424
425         RefPtr<SecurityOrigin> m_securityOrigin;
426         KURL m_url;
427
428         bool m_shouldPrintWhenFinishedLoading;
429         bool m_suspendedForPageCache;
430
431         HashSet<DOMWindowProperty*> m_properties;
432
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;
446
447         EventTargetData m_eventTargetData;
448
449         String m_status;
450         String m_defaultStatus;
451
452         mutable RefPtr<Storage> m_sessionStorage;
453         mutable RefPtr<Storage> m_localStorage;
454         mutable RefPtr<DOMApplicationCache> m_applicationCache;
455
456 #if ENABLE(WEB_TIMING)
457         mutable RefPtr<Performance> m_performance;
458 #endif
459
460 #if ENABLE(BLOB)
461         mutable RefPtr<DOMURL> m_domURL;
462 #endif
463 #if ENABLE(TIZEN_SEARCH_PROVIDER)
464         mutable RefPtr<External> m_external;
465 #endif
466     };
467
468     inline String DOMWindow::status() const
469     {
470         return m_status;
471     }
472
473     inline String DOMWindow::defaultStatus() const
474     {
475         return m_defaultStatus;
476     } 
477
478 } // namespace WebCore
479
480 #endif // DOMWindow_h