Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / LocalDOMWindow.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/core/v8/Dictionary.h"
31 #include "core/events/EventTarget.h"
32 #include "core/frame/DOMWindowBase64.h"
33 #include "core/frame/FrameDestructionObserver.h"
34 #include "platform/LifecycleContext.h"
35 #include "platform/Supplementable.h"
36 #include "platform/heap/Handle.h"
37 #include "platform/scroll/ScrollableArea.h"
38
39 #include "wtf/Forward.h"
40
41 namespace blink {
42     class ApplicationCache;
43     class BarProp;
44     class CSSRuleList;
45     class CSSStyleDeclaration;
46     class Console;
47     class WebKitPoint;
48     class DOMSelection;
49     class DOMURL;
50     class DOMWindowProperty;
51     class Database;
52     class DatabaseCallback;
53     class Document;
54     class DocumentInit;
55     class DOMWindowEventQueue;
56     class DOMWindowLifecycleNotifier;
57     class Element;
58     class EventListener;
59     class EventQueue;
60     class ExceptionState;
61     class FloatRect;
62     class FrameConsole;
63     class History;
64     class IDBFactory;
65     class LocalFrame;
66     class Location;
67     class MediaQueryList;
68     class MessageEvent;
69     class Navigator;
70     class Node;
71     class Page;
72     class Performance;
73     class PostMessageTimer;
74     class RequestAnimationFrameCallback;
75     class ScheduledAction;
76     class Screen;
77     class ScriptCallStack;
78     class SecurityOrigin;
79     class SerializedScriptValue;
80     class Storage;
81     class StyleMedia;
82     class DOMWindowCSS;
83
84     struct WindowFeatures;
85
86     typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray;
87
88 enum PageshowEventPersistence {
89     PageshowEventNotPersisted = 0,
90     PageshowEventPersisted = 1
91 };
92
93     enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList };
94
95     class LocalDOMWindow FINAL : public RefCountedWillBeGarbageCollectedFinalized<LocalDOMWindow>, public EventTargetWithInlineData, public DOMWindowBase64, public FrameDestructionObserver, public WillBeHeapSupplementable<LocalDOMWindow>, public LifecycleContext<LocalDOMWindow> {
96         WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(LocalDOMWindow);
97         DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCounted<LocalDOMWindow>);
98     public:
99         static PassRefPtrWillBeRawPtr<Document> createDocument(const String& mimeType, const DocumentInit&, bool forceXHTML);
100         static PassRefPtrWillBeRawPtr<LocalDOMWindow> create(LocalFrame& frame)
101         {
102             return adoptRefWillBeNoop(new LocalDOMWindow(frame));
103         }
104         virtual ~LocalDOMWindow();
105
106         PassRefPtrWillBeRawPtr<Document> installNewDocument(const String& mimeType, const DocumentInit&, bool forceXHTML = false);
107
108         virtual const AtomicString& interfaceName() const OVERRIDE;
109         virtual ExecutionContext* executionContext() const OVERRIDE;
110
111         virtual LocalDOMWindow* toDOMWindow() OVERRIDE;
112
113         void registerProperty(DOMWindowProperty*);
114         void unregisterProperty(DOMWindowProperty*);
115
116         void reset();
117
118         PassRefPtrWillBeRawPtr<MediaQueryList> matchMedia(const String&);
119
120         unsigned pendingUnloadEventListeners() const;
121
122         static FloatRect adjustWindowRect(LocalFrame&, const FloatRect& pendingChanges);
123
124         bool allowPopUp(); // Call on first window, not target window.
125         static bool allowPopUp(LocalFrame& firstFrame);
126         static bool canShowModalDialogNow(const LocalFrame*);
127
128         // DOM Level 0
129
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(); }
140
141         Location& location() const;
142         void setLocation(const String& location, LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow,
143             SetLocationLocking = LockHistoryBasedOnGestureState);
144
145         DOMSelection* getSelection();
146
147         Element* frameElement() const;
148
149         void focus(ExecutionContext* = 0);
150         void blur();
151         void close(ExecutionContext* = 0);
152         void print();
153         void stop();
154
155         PassRefPtrWillBeRawPtr<LocalDOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
156             LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow);
157
158         typedef void (*PrepareDialogFunction)(LocalDOMWindow*, void* context);
159         void showModalDialog(const String& urlString, const String& dialogFeaturesString,
160             LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow, PrepareDialogFunction, void* functionContext);
161
162         void alert(const String& message = String());
163         bool confirm(const String& message);
164         String prompt(const String& message, const String& defaultValue);
165
166         bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const;
167
168         bool offscreenBuffering() const;
169
170         int outerHeight() const;
171         int outerWidth() const;
172         int innerHeight() const;
173         int innerWidth() const;
174         int screenX() const;
175         int screenY() const;
176         int screenLeft() const { return screenX(); }
177         int screenTop() const { return screenY(); }
178         int scrollX() const;
179         int scrollY() const;
180         int pageXOffset() const { return scrollX(); }
181         int pageYOffset() const { return scrollY(); }
182
183         bool closed() const;
184
185         unsigned length() const;
186
187         const AtomicString& name() const;
188         void setName(const AtomicString&);
189
190         String status() const;
191         void setStatus(const String&);
192         String defaultStatus() const;
193         void setDefaultStatus(const String&);
194
195         // Self-referential attributes
196
197         LocalDOMWindow* self() const;
198         LocalDOMWindow* window() const { return self(); }
199         LocalDOMWindow* frames() const { return self(); }
200
201         LocalDOMWindow* opener() const;
202         LocalDOMWindow* parent() const;
203         LocalDOMWindow* top() const;
204
205         // DOM Level 2 AbstractView Interface
206
207         Document* document() const;
208
209         // CSSOM View Module
210
211         StyleMedia& styleMedia() const;
212
213         // DOM Level 2 Style Interface
214
215         PassRefPtrWillBeRawPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
216
217         // WebKit extensions
218
219         PassRefPtrWillBeRawPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt) const;
220         double devicePixelRatio() const;
221
222         PassRefPtrWillBeRawPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node*, const WebKitPoint*) const;
223         PassRefPtrWillBeRawPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node*, const WebKitPoint*) const;
224
225         Console& console() const;
226         FrameConsole* frameConsole() const;
227
228         void printErrorMessage(const String&);
229         String crossDomainAccessErrorMessage(LocalDOMWindow* callingWindow);
230         String sanitizedCrossDomainAccessErrorMessage(LocalDOMWindow* callingWindow);
231
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>);
235
236         void scrollBy(int x, int y, ScrollBehavior = ScrollBehaviorAuto) const;
237         void scrollBy(int x, int y, const Dictionary& scrollOptions, ExceptionState&) const;
238         void scrollTo(int x, int y, ScrollBehavior = ScrollBehaviorAuto) 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); }
242
243         void moveBy(float x, float y) const;
244         void moveTo(float x, float y) const;
245
246         void resizeBy(float x, float y) const;
247         void resizeTo(float width, float height) const;
248
249         // WebKit animation extensions
250         int requestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
251         int webkitRequestAnimationFrame(PassOwnPtr<RequestAnimationFrameCallback>);
252         void cancelAnimationFrame(int id);
253
254         DOMWindowCSS& css() const;
255
256         // Events
257         // EventTarget API
258         virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture = false) OVERRIDE;
259         virtual bool removeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture = false) OVERRIDE;
260         virtual void removeAllEventListeners() OVERRIDE;
261
262         using EventTarget::dispatchEvent;
263         bool dispatchEvent(PassRefPtrWillBeRawPtr<Event> prpEvent, PassRefPtrWillBeRawPtr<EventTarget> prpTarget);
264
265         void dispatchLoadEvent();
266
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);
273
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);
278
279         void captureEvents() { }
280         void releaseEvents() { }
281
282         void finishedLoading();
283
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(); }
289
290         ApplicationCache* applicationCache() const;
291         ApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
292
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;
297
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);
303
304         Performance& performance() const;
305
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;
311
312         void willDetachDocumentFromFrame();
313         LocalDOMWindow* anonymousIndexedGetter(uint32_t);
314
315         bool isInsecureScriptAccess(LocalDOMWindow& callingWindow, const String& urlString);
316
317         PassOwnPtr<LifecycleNotifier<LocalDOMWindow> > createLifecycleNotifier();
318
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>);
328
329         // FIXME: This shouldn't be public once LocalDOMWindow becomes ExecutionContext.
330         void clearEventQueue();
331
332         void acceptLanguagesChanged();
333
334         virtual void trace(Visitor*) OVERRIDE;
335
336     protected:
337         DOMWindowLifecycleNotifier& lifecycleNotifier();
338
339     private:
340         explicit LocalDOMWindow(LocalFrame&);
341
342         Page* page();
343
344         virtual void frameDestroyed() OVERRIDE;
345         virtual void willDetachFrameHost() OVERRIDE;
346
347         void clearDocument();
348         void resetDOMWindowProperties();
349         void willDestroyDocumentInFrame();
350
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
359         };
360
361         void removeAllEventListenersInternal(BroadcastListenerRemoval);
362
363         RefPtrWillBeMember<Document> m_document;
364
365         bool m_shouldPrintWhenFinishedLoading;
366 #if ENABLE(ASSERT)
367         bool m_hasBeenReset;
368 #endif
369
370         HashSet<DOMWindowProperty*> m_properties;
371
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;
384
385         String m_status;
386         String m_defaultStatus;
387
388         mutable RefPtrWillBeMember<Storage> m_sessionStorage;
389         mutable RefPtrWillBeMember<Storage> m_localStorage;
390         mutable RefPtrWillBeMember<ApplicationCache> m_applicationCache;
391
392         mutable RefPtrWillBeMember<Performance> m_performance;
393
394         mutable RefPtrWillBeMember<DOMWindowCSS> m_css;
395
396         RefPtrWillBeMember<DOMWindowEventQueue> m_eventQueue;
397         RefPtr<SerializedScriptValue> m_pendingStateObject;
398
399         HashSet<OwnPtr<PostMessageTimer> > m_postMessageTimers;
400     };
401
402     inline String LocalDOMWindow::status() const
403     {
404         return m_status;
405     }
406
407     inline String LocalDOMWindow::defaultStatus() const
408     {
409         return m_defaultStatus;
410     }
411
412 } // namespace blink
413
414 #endif // DOMWindow_h