| OLD | NEW |
| (Empty) |
| 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/DOMWindowBase64.h" | |
| 34 #include "core/frame/FrameDestructionObserver.h" | |
| 35 #include "platform/LifecycleContext.h" | |
| 36 #include "platform/Supplementable.h" | |
| 37 #include "platform/heap/Handle.h" | |
| 38 | |
| 39 #include "wtf/Forward.h" | |
| 40 | |
| 41 namespace WebCore { | |
| 42 class ApplicationCache; | |
| 43 class BarProp; | |
| 44 class CSSRuleList; | |
| 45 class CSSStyleDeclaration; | |
| 46 class Console; | |
| 47 class DOMPoint; | |
| 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 Vector<RefPtr<MessagePort>, 1> MessagePortArray; | |
| 87 | |
| 88 enum PageshowEventPersistence { | |
| 89 PageshowEventNotPersisted = 0, | |
| 90 PageshowEventPersisted = 1 | |
| 91 }; | |
| 92 | |
| 93 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBack
ForwardList }; | |
| 94 | |
| 95 class DOMWindow FINAL : public RefCountedWillBeRefCountedGarbageCollected<DO
MWindow>, public ScriptWrappable, public EventTargetWithInlineData, public DOMWi
ndowBase64, public FrameDestructionObserver, public WillBeHeapSupplementable<DOM
Window>, public LifecycleContext<DOMWindow> { | |
| 96 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(DOMWindow); | |
| 97 REFCOUNTED_EVENT_TARGET(DOMWindow); | |
| 98 public: | |
| 99 static PassRefPtrWillBeRawPtr<Document> createDocument(const String& mim
eType, const DocumentInit&, bool forceXHTML); | |
| 100 static PassRefPtrWillBeRawPtr<DOMWindow> create(LocalFrame& frame) | |
| 101 { | |
| 102 return adoptRefWillBeRefCountedGarbageCollected(new DOMWindow(frame)
); | |
| 103 } | |
| 104 virtual ~DOMWindow(); | |
| 105 | |
| 106 PassRefPtrWillBeRawPtr<Document> installNewDocument(const String& mimeTy
pe, const DocumentInit&, bool forceXHTML = false); | |
| 107 | |
| 108 virtual const AtomicString& interfaceName() const OVERRIDE; | |
| 109 virtual ExecutionContext* executionContext() const OVERRIDE; | |
| 110 | |
| 111 virtual DOMWindow* 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& pendingC
hanges); | |
| 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, DOMWindow* callingWindow, DOMWi
ndow* 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<DOMWindow> open(const String& urlString, const At
omicString& frameName, const String& windowFeaturesString, | |
| 156 DOMWindow* callingWindow, DOMWindow* enteredWindow); | |
| 157 | |
| 158 typedef void (*PrepareDialogFunction)(DOMWindow*, void* context); | |
| 159 void showModalDialog(const String& urlString, const String& dialogFeatur
esString, | |
| 160 DOMWindow* callingWindow, DOMWindow* enteredWindow, PrepareDialogFun
ction, 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 DOMWindow* self() const; | |
| 198 DOMWindow* window() const { return self(); } | |
| 199 DOMWindow* frames() const { return self(); } | |
| 200 | |
| 201 DOMWindow* opener() const; | |
| 202 DOMWindow* parent() const; | |
| 203 DOMWindow* 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*, c
onst String& pseudoElt) const; | |
| 216 | |
| 217 // WebKit extensions | |
| 218 | |
| 219 PassRefPtrWillBeRawPtr<CSSRuleList> getMatchedCSSRules(Element*, const S
tring& pseudoElt) const; | |
| 220 double devicePixelRatio() const; | |
| 221 | |
| 222 PassRefPtrWillBeRawPtr<DOMPoint> webkitConvertPointFromPageToNode(Node*,
const DOMPoint*) const; | |
| 223 PassRefPtrWillBeRawPtr<DOMPoint> webkitConvertPointFromNodeToPage(Node*,
const DOMPoint*) const; | |
| 224 | |
| 225 Console& console() const; | |
| 226 FrameConsole* frameConsole() const; | |
| 227 | |
| 228 void printErrorMessage(const String&); | |
| 229 String crossDomainAccessErrorMessage(DOMWindow* callingWindow); | |
| 230 String sanitizedCrossDomainAccessErrorMessage(DOMWindow* callingWindow); | |
| 231 | |
| 232 void postMessage(PassRefPtr<SerializedScriptValue> message, const Messag
ePortArray*, const String& targetOrigin, DOMWindow* source, ExceptionState&); | |
| 233 void postMessageTimerFired(PassOwnPtr<PostMessageTimer>); | |
| 234 void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetO
rigin, PassRefPtrWillBeRawPtr<Event>, PassRefPtrWillBeRawPtr<ScriptCallStack>); | |
| 235 | |
| 236 void scrollBy(int x, int y) const; | |
| 237 void scrollBy(int x, int y, const Dictionary& scrollOptions, ExceptionSt
ate&) const; | |
| 238 void scrollTo(int x, int y) const; | |
| 239 void scrollTo(int x, int y, const Dictionary& scrollOptions, ExceptionSt
ate&) const; | |
| 240 void scroll(int x, int y) const { scrollTo(x, y); } | |
| 241 void scroll(int x, int y, const Dictionary& scrollOptions, ExceptionStat
e& 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, EventLis
tener*, bool useCapture = false) OVERRIDE; | |
| 260 virtual void removeAllEventListeners() OVERRIDE; | |
| 261 | |
| 262 using EventTarget::dispatchEvent; | |
| 263 bool dispatchEvent(PassRefPtrWillBeRawPtr<Event> prpEvent, PassRefPtrWil
lBeRawPtr<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, webkitAnima
tionStart); | |
| 275 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitA
nimationIteration); | |
| 276 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimati
onEnd); | |
| 277 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransi
tionEnd); | |
| 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_applicatio
nCache.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 DOMWindow is no longer the active DOMWindow (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 DOMWindow* anonymousIndexedGetter(uint32_t); | |
| 314 | |
| 315 bool isInsecureScriptAccess(DOMWindow& callingWindow, const String& urlS
tring); | |
| 316 | |
| 317 PassOwnPtr<LifecycleNotifier<DOMWindow> > 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 DOMWindow becomes ExecutionConte
xt. | |
| 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 DOMWindow(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 ASSERT_ENABLED | |
| 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 | |
| 400 inline String DOMWindow::status() const | |
| 401 { | |
| 402 return m_status; | |
| 403 } | |
| 404 | |
| 405 inline String DOMWindow::defaultStatus() const | |
| 406 { | |
| 407 return m_defaultStatus; | |
| 408 } | |
| 409 | |
| 410 } // namespace WebCore | |
| 411 | |
| 412 #endif // DOMWindow_h | |
| OLD | NEW |