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 "KURL.h" 32 33 namespace WebCore { 34 35 class BarInfo; 36 class CSSRuleList; 37 class CSSStyleDeclaration; 38 class Console; 39 class Crypto; 40 class DOMApplicationCache; 41 class DOMSelection; 42 class DOMURL; 43 class Database; 44 class DatabaseCallback; 45 class Document; 46 class Element; 47 class EntryCallback; 48 class ErrorCallback; 49 class EventListener; 50 class FileSystemCallback; 51 class FloatRect; 52 class Frame; 53 class History; 54 class IDBFactory; 55 class Location; 56 class MediaQueryList; 57 class Navigator; 58 class Node; 59 class NotificationCenter; 60 class Performance; 61 class PostMessageTimer; 62 class ScheduledAction; 63 class Screen; 64 class SecurityOrigin; 65 class SerializedScriptValue; 66 class Storage; 67 class StorageInfo; 68 class StyleMedia; 69 class WebKitPoint; 70 71 #if ENABLE(REQUEST_ANIMATION_FRAME) 72 class RequestAnimationFrameCallback; 73 #endif 74 75 struct WindowFeatures; 76 77 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; 78 79 typedef int ExceptionCode; 80 81 enum SetLocationLocking { LockHistoryBasedOnGestureState, LockHistoryAndBackForwardList }; 82 83 class DOMWindow : public RefCounted<DOMWindow>, public EventTarget { 84 public: create(Frame * frame)85 static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); } 86 virtual ~DOMWindow(); 87 toDOMWindow()88 virtual DOMWindow* toDOMWindow() { return this; } 89 virtual ScriptExecutionContext* scriptExecutionContext() const; 90 frame()91 Frame* frame() const { return m_frame; } 92 void disconnectFrame(); 93 94 void clear(); 95 96 PassRefPtr<MediaQueryList> matchMedia(const String&); 97 98 void setSecurityOrigin(SecurityOrigin*); securityOrigin()99 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } 100 setURL(const KURL & url)101 void setURL(const KURL& url) { m_url = url; } url()102 KURL url() const { return m_url; } 103 104 unsigned pendingUnloadEventListeners() const; 105 106 static bool dispatchAllPendingBeforeUnloadEvents(); 107 static void dispatchAllPendingUnloadEvents(); 108 109 static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges); 110 111 // FIXME: We can remove this function once V8 showModalDialog is changed to use DOMWindow. 112 static void parseModalDialogFeatures(const String&, HashMap<String, String>&); 113 114 bool allowPopUp(); // Call on first window, not target window. 115 static bool allowPopUp(Frame* firstFrame); 116 static bool canShowModalDialog(const Frame*); 117 static bool canShowModalDialogNow(const Frame*); 118 119 // DOM Level 0 120 121 Screen* screen() const; 122 History* history() const; 123 Crypto* crypto() const; 124 BarInfo* locationbar() const; 125 BarInfo* menubar() const; 126 BarInfo* personalbar() const; 127 BarInfo* scrollbars() const; 128 BarInfo* statusbar() const; 129 BarInfo* toolbar() const; 130 Navigator* navigator() const; clientInformation()131 Navigator* clientInformation() const { return navigator(); } 132 133 Location* location() const; 134 void setLocation(const String& location, DOMWindow* activeWindow, DOMWindow* firstWindow, 135 SetLocationLocking = LockHistoryBasedOnGestureState); 136 137 DOMSelection* getSelection(); 138 139 Element* frameElement() const; 140 141 void focus(); 142 void blur(); 143 void close(ScriptExecutionContext* = 0); 144 void print(); 145 void stop(); 146 147 PassRefPtr<DOMWindow> open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString, 148 DOMWindow* activeWindow, DOMWindow* firstWindow); 149 150 typedef void (*PrepareDialogFunction)(DOMWindow*, void* context); 151 void showModalDialog(const String& urlString, const String& dialogFeaturesString, 152 DOMWindow* activeWindow, DOMWindow* firstWindow, PrepareDialogFunction, void* functionContext); 153 154 void alert(const String& message); 155 bool confirm(const String& message); 156 String prompt(const String& message, const String& defaultValue); 157 String btoa(const String& stringToEncode, ExceptionCode&); 158 String atob(const String& encodedString, ExceptionCode&); 159 160 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const; 161 162 bool offscreenBuffering() const; 163 164 int outerHeight() const; 165 int outerWidth() const; 166 int innerHeight() const; 167 int innerWidth() const; 168 int screenX() const; 169 int screenY() const; screenLeft()170 int screenLeft() const { return screenX(); } screenTop()171 int screenTop() const { return screenY(); } 172 int scrollX() const; 173 int scrollY() const; pageXOffset()174 int pageXOffset() const { return scrollX(); } pageYOffset()175 int pageYOffset() const { return scrollY(); } 176 177 bool closed() const; 178 179 unsigned length() const; 180 181 String name() const; 182 void setName(const String&); 183 184 String status() const; 185 void setStatus(const String&); 186 String defaultStatus() const; 187 void setDefaultStatus(const String&); 188 189 // This attribute is an alias of defaultStatus and is necessary for legacy uses. defaultstatus()190 String defaultstatus() const { return defaultStatus(); } setDefaultstatus(const String & status)191 void setDefaultstatus(const String& status) { setDefaultStatus(status); } 192 193 // Self-referential attributes 194 195 DOMWindow* self() const; window()196 DOMWindow* window() const { return self(); } frames()197 DOMWindow* frames() const { return self(); } 198 199 DOMWindow* opener() const; 200 DOMWindow* parent() const; 201 DOMWindow* top() const; 202 203 // DOM Level 2 AbstractView Interface 204 205 Document* document() const; 206 207 // CSSOM View Module 208 209 PassRefPtr<StyleMedia> styleMedia() const; 210 211 // DOM Level 2 Style Interface 212 213 PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const; 214 215 // WebKit extensions 216 217 PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const; 218 double devicePixelRatio() const; 219 220 PassRefPtr<WebKitPoint> webkitConvertPointFromPageToNode(Node*, const WebKitPoint*) const; 221 PassRefPtr<WebKitPoint> webkitConvertPointFromNodeToPage(Node*, const WebKitPoint*) const; 222 223 Console* console() const; 224 225 void printErrorMessage(const String&); 226 String crossDomainAccessErrorMessage(DOMWindow* activeWindow); 227 228 void pageDestroyed(); 229 void resetGeolocation(); 230 231 void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, const String& targetOrigin, DOMWindow* source, ExceptionCode&); 232 // FIXME: remove this when we update the ObjC bindings (bug #28774). 233 void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, const String& targetOrigin, DOMWindow* source, ExceptionCode&); 234 void postMessageTimerFired(PassOwnPtr<PostMessageTimer>); 235 236 void scrollBy(int x, int y) const; 237 void scrollTo(int x, int y) const; scroll(int x,int y)238 void scroll(int x, int y) const { scrollTo(x, y); } 239 240 void moveBy(float x, float y) const; 241 void moveTo(float x, float y) const; 242 243 void resizeBy(float x, float y) const; 244 void resizeTo(float width, float height) const; 245 246 // Timers 247 int setTimeout(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&); 248 void clearTimeout(int timeoutId); 249 int setInterval(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&); 250 void clearInterval(int timeoutId); 251 252 // WebKit animation extensions 253 #if ENABLE(REQUEST_ANIMATION_FRAME) 254 int webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback>, Element*); 255 void webkitCancelRequestAnimationFrame(int id); 256 #endif 257 258 // Events 259 // EventTarget API 260 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture); 261 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture); 262 virtual void removeAllEventListeners(); 263 264 using EventTarget::dispatchEvent; 265 bool dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget); 266 void dispatchLoadEvent(); 267 void dispatchTimedEvent(PassRefPtr<Event> event, Document* target, double* startTime, double* endTime); 268 269 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); 270 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforeunload); 271 DEFINE_ATTRIBUTE_EVENT_LISTENER(blur); 272 DEFINE_ATTRIBUTE_EVENT_LISTENER(canplay); 273 DEFINE_ATTRIBUTE_EVENT_LISTENER(canplaythrough); 274 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); 275 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); 276 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu); 277 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick); 278 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag); 279 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend); 280 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter); 281 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave); 282 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover); 283 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart); 284 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop); 285 DEFINE_ATTRIBUTE_EVENT_LISTENER(durationchange); 286 DEFINE_ATTRIBUTE_EVENT_LISTENER(emptied); 287 DEFINE_ATTRIBUTE_EVENT_LISTENER(ended); 288 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 289 DEFINE_ATTRIBUTE_EVENT_LISTENER(focus); 290 DEFINE_ATTRIBUTE_EVENT_LISTENER(hashchange); 291 DEFINE_ATTRIBUTE_EVENT_LISTENER(input); 292 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid); 293 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown); 294 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress); 295 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup); 296 DEFINE_ATTRIBUTE_EVENT_LISTENER(load); 297 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadeddata); 298 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadedmetadata); 299 DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart); 300 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); 301 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown); 302 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove); 303 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout); 304 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover); 305 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup); 306 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel); 307 DEFINE_ATTRIBUTE_EVENT_LISTENER(offline); 308 DEFINE_ATTRIBUTE_EVENT_LISTENER(online); 309 DEFINE_ATTRIBUTE_EVENT_LISTENER(pagehide); 310 DEFINE_ATTRIBUTE_EVENT_LISTENER(pageshow); 311 DEFINE_ATTRIBUTE_EVENT_LISTENER(pause); 312 DEFINE_ATTRIBUTE_EVENT_LISTENER(play); 313 DEFINE_ATTRIBUTE_EVENT_LISTENER(playing); 314 DEFINE_ATTRIBUTE_EVENT_LISTENER(popstate); 315 DEFINE_ATTRIBUTE_EVENT_LISTENER(progress); 316 DEFINE_ATTRIBUTE_EVENT_LISTENER(ratechange); 317 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset); 318 DEFINE_ATTRIBUTE_EVENT_LISTENER(resize); 319 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll); 320 DEFINE_ATTRIBUTE_EVENT_LISTENER(search); 321 DEFINE_ATTRIBUTE_EVENT_LISTENER(seeked); 322 DEFINE_ATTRIBUTE_EVENT_LISTENER(seeking); 323 DEFINE_ATTRIBUTE_EVENT_LISTENER(select); 324 DEFINE_ATTRIBUTE_EVENT_LISTENER(stalled); 325 DEFINE_ATTRIBUTE_EVENT_LISTENER(storage); 326 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit); 327 DEFINE_ATTRIBUTE_EVENT_LISTENER(suspend); 328 DEFINE_ATTRIBUTE_EVENT_LISTENER(timeupdate); 329 DEFINE_ATTRIBUTE_EVENT_LISTENER(unload); 330 DEFINE_ATTRIBUTE_EVENT_LISTENER(volumechange); 331 DEFINE_ATTRIBUTE_EVENT_LISTENER(waiting); 332 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitbeginfullscreen); 333 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitendfullscreen); 334 335 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationstart, webkitAnimationStart); 336 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationiteration, webkitAnimationIteration); 337 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkitanimationend, webkitAnimationEnd); 338 DEFINE_MAPPED_ATTRIBUTE_EVENT_LISTENER(webkittransitionend, webkitTransitionEnd); 339 340 void captureEvents(); 341 void releaseEvents(); 342 343 void finishedLoading(); 344 345 using RefCounted<DOMWindow>::ref; 346 using RefCounted<DOMWindow>::deref; 347 348 #if ENABLE(BLOB) 349 DOMURL* webkitURL() const; 350 #endif 351 352 #if ENABLE(DATABASE) 353 // HTML 5 client-side database 354 PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode&); 355 #endif 356 357 #if ENABLE(DEVICE_ORIENTATION) 358 DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion); 359 DEFINE_ATTRIBUTE_EVENT_LISTENER(deviceorientation); 360 #endif 361 362 #if ENABLE(DOM_STORAGE) 363 // HTML 5 key/value storage 364 Storage* sessionStorage(ExceptionCode&) const; 365 Storage* localStorage(ExceptionCode&) const; 366 #endif 367 368 #if ENABLE(FILE_SYSTEM) 369 // They are placed here and in all capital letters so they can be checked against the constants in the 370 // IDL at compile time. 371 enum FileSystemType { 372 TEMPORARY, 373 PERSISTENT, 374 EXTERNAL, 375 }; 376 void webkitRequestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>); 377 void webkitResolveLocalFileSystemURL(const String&, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>); 378 #endif 379 380 #if ENABLE(INDEXED_DATABASE) 381 IDBFactory* webkitIndexedDB() const; 382 #endif 383 384 #if ENABLE(NOTIFICATIONS) 385 NotificationCenter* webkitNotifications() const; 386 #endif 387 388 #if ENABLE(QUOTA) 389 StorageInfo* webkitStorageInfo() const; 390 #endif 391 392 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 393 DOMApplicationCache* applicationCache() const; optionalApplicationCache()394 DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); } 395 #endif 396 397 #if ENABLE(ORIENTATION_EVENTS) 398 // This is the interface orientation in degrees. Some examples are: 399 // 0 is straight up; -90 is when the device is rotated 90 clockwise; 400 // 90 is when rotated counter clockwise. 401 int orientation() const; 402 403 DEFINE_ATTRIBUTE_EVENT_LISTENER(orientationchange); 404 #endif 405 406 #if ENABLE(TOUCH_EVENTS) 407 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart); 408 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove); 409 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend); 410 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel); 411 #endif 412 413 #if ENABLE(WEB_TIMING) 414 Performance* performance() const; 415 #endif 416 417 private: 418 DOMWindow(Frame*); 419 refEventTarget()420 virtual void refEventTarget() { ref(); } derefEventTarget()421 virtual void derefEventTarget() { deref(); } 422 virtual EventTargetData* eventTargetData(); 423 virtual EventTargetData* ensureEventTargetData(); 424 425 static Frame* createWindow(const String& urlString, const AtomicString& frameName, const WindowFeatures&, 426 DOMWindow* activeWindow, Frame* firstFrame, Frame* openerFrame, 427 PrepareDialogFunction = 0, void* functionContext = 0); 428 bool isInsecureScriptAccess(DOMWindow* activeWindow, const String& urlString); 429 430 RefPtr<SecurityOrigin> m_securityOrigin; 431 KURL m_url; 432 433 bool m_shouldPrintWhenFinishedLoading; 434 Frame* m_frame; 435 mutable RefPtr<Screen> m_screen; 436 mutable RefPtr<DOMSelection> m_selection; 437 mutable RefPtr<History> m_history; 438 mutable RefPtr<Crypto> m_crypto; 439 mutable RefPtr<BarInfo> m_locationbar; 440 mutable RefPtr<BarInfo> m_menubar; 441 mutable RefPtr<BarInfo> m_personalbar; 442 mutable RefPtr<BarInfo> m_scrollbars; 443 mutable RefPtr<BarInfo> m_statusbar; 444 mutable RefPtr<BarInfo> m_toolbar; 445 mutable RefPtr<Console> m_console; 446 mutable RefPtr<Navigator> m_navigator; 447 mutable RefPtr<Location> m_location; 448 mutable RefPtr<StyleMedia> m_media; 449 450 EventTargetData m_eventTargetData; 451 452 String m_status; 453 String m_defaultStatus; 454 455 #if ENABLE(DOM_STORAGE) 456 mutable RefPtr<Storage> m_sessionStorage; 457 mutable RefPtr<Storage> m_localStorage; 458 #endif 459 460 #if ENABLE(INDEXED_DATABASE) 461 mutable RefPtr<IDBFactory> m_idbFactory; 462 #endif 463 464 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 465 mutable RefPtr<DOMApplicationCache> m_applicationCache; 466 #endif 467 468 #if ENABLE(NOTIFICATIONS) 469 mutable RefPtr<NotificationCenter> m_notifications; 470 #endif 471 472 #if ENABLE(WEB_TIMING) 473 mutable RefPtr<Performance> m_performance; 474 #endif 475 476 #if ENABLE(BLOB) 477 mutable RefPtr<DOMURL> m_domURL; 478 #endif 479 480 #if ENABLE(QUOTA) 481 mutable RefPtr<StorageInfo> m_storageInfo; 482 #endif 483 }; 484 status()485 inline String DOMWindow::status() const 486 { 487 return m_status; 488 } 489 defaultStatus()490 inline String DOMWindow::defaultStatus() const 491 { 492 return m_defaultStatus; 493 } 494 495 } // namespace WebCore 496 497 #endif // DOMWindow_h 498