1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef DOMWindow_h 27 #define DOMWindow_h 28 29 #include "KURL.h" 30 #include "PlatformString.h" 31 #include "SecurityOrigin.h" 32 #include <wtf/Forward.h> 33 #include <wtf/RefCounted.h> 34 #include <wtf/RefPtr.h> 35 36 namespace WebCore { 37 38 class BarInfo; 39 class CSSRuleList; 40 class CSSStyleDeclaration; 41 class Console; 42 class DOMSelection; 43 class Database; 44 class Document; 45 class Element; 46 class EventListener; 47 class FloatRect; 48 class Frame; 49 class History; 50 class Location; 51 class MessagePort; 52 class Navigator; 53 class PostMessageTimer; 54 class Screen; 55 56 #if ENABLE(DOM_STORAGE) 57 class SessionStorage; 58 class Storage; 59 #endif 60 61 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 62 class DOMApplicationCache; 63 #endif 64 65 typedef int ExceptionCode; 66 67 class DOMWindow : public RefCounted<DOMWindow> { 68 public: create(Frame * frame)69 static PassRefPtr<DOMWindow> create(Frame* frame) { return adoptRef(new DOMWindow(frame)); } 70 virtual ~DOMWindow(); 71 frame()72 Frame* frame() { return m_frame; } 73 void disconnectFrame(); 74 75 void clear(); 76 setSecurityOrigin(SecurityOrigin * securityOrigin)77 void setSecurityOrigin(SecurityOrigin* securityOrigin) { m_securityOrigin = securityOrigin; } securityOrigin()78 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } 79 setURL(const KURL & url)80 void setURL(const KURL& url) { m_url = url; } url()81 KURL url() const { return m_url; } 82 83 static void adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges); 84 85 // DOM Level 0 86 Screen* screen() const; 87 History* history() const; 88 BarInfo* locationbar() const; 89 BarInfo* menubar() const; 90 BarInfo* personalbar() const; 91 BarInfo* scrollbars() const; 92 BarInfo* statusbar() const; 93 BarInfo* toolbar() const; 94 Navigator* navigator() const; clientInformation()95 Navigator* clientInformation() const { return navigator(); } 96 Location* location() const; 97 98 DOMSelection* getSelection(); 99 100 Element* frameElement() const; 101 102 void focus(); 103 void blur(); 104 void close(); 105 void print(); 106 void stop(); 107 108 void alert(const String& message); 109 bool confirm(const String& message); 110 String prompt(const String& message, const String& defaultValue); 111 112 bool find(const String&, bool caseSensitive, bool backwards, bool wrap, bool wholeWord, bool searchInFrames, bool showDialog) const; 113 114 bool offscreenBuffering() const; 115 116 int outerHeight() const; 117 int outerWidth() const; 118 int innerHeight() const; 119 int innerWidth() const; 120 int screenX() const; 121 int screenY() const; screenLeft()122 int screenLeft() const { return screenX(); } screenTop()123 int screenTop() const { return screenY(); } 124 int scrollX() const; 125 int scrollY() const; pageXOffset()126 int pageXOffset() const { return scrollX(); } pageYOffset()127 int pageYOffset() const { return scrollY(); } 128 #ifdef ANDROID_ORIENTATION_SUPPORT 129 int orientation() const; 130 #endif 131 132 bool closed() const; 133 134 unsigned length() const; 135 136 String name() const; 137 void setName(const String&); 138 139 String status() const; 140 void setStatus(const String&); 141 String defaultStatus() const; 142 void setDefaultStatus(const String&); 143 // This attribute is an alias of defaultStatus and is necessary for legacy uses. defaultstatus()144 String defaultstatus() const { return defaultStatus(); } setDefaultstatus(const String & status)145 void setDefaultstatus(const String& status) { setDefaultStatus(status); } 146 147 // Self referential attributes 148 DOMWindow* self() const; window()149 DOMWindow* window() const { return self(); } frames()150 DOMWindow* frames() const { return self(); } 151 152 DOMWindow* opener() const; 153 DOMWindow* parent() const; 154 DOMWindow* top() const; 155 156 // DOM Level 2 AbstractView Interface 157 Document* document() const; 158 159 // DOM Level 2 Style Interface 160 PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const; 161 162 // WebKit extensions 163 PassRefPtr<CSSRuleList> getMatchedCSSRules(Element*, const String& pseudoElt, bool authorOnly = true) const; 164 double devicePixelRatio() const; 165 166 #if ENABLE(DATABASE) 167 // HTML 5 client-side database 168 PassRefPtr<Database> openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode&); 169 #endif 170 171 #if ENABLE(DOM_STORAGE) 172 // HTML 5 key/value storage 173 Storage* sessionStorage() const; 174 Storage* localStorage() const; 175 #endif 176 177 Console* console() const; 178 179 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 180 DOMApplicationCache* applicationCache() const; 181 #endif 182 183 void postMessage(const String& message, MessagePort*, const String& targetOrigin, DOMWindow* source, ExceptionCode&); 184 void postMessageTimerFired(PostMessageTimer*); 185 186 void scrollBy(int x, int y) const; 187 void scrollTo(int x, int y) const; scroll(int x,int y)188 void scroll(int x, int y) const { scrollTo(x, y); } 189 190 void moveBy(float x, float y) const; 191 void moveTo(float x, float y) const; 192 193 void resizeBy(float x, float y) const; 194 void resizeTo(float width, float height) const; 195 196 EventListener* onabort() const; 197 void setOnabort(PassRefPtr<EventListener>); 198 EventListener* onblur() const; 199 void setOnblur(PassRefPtr<EventListener>); 200 EventListener* onchange() const; 201 void setOnchange(PassRefPtr<EventListener>); 202 EventListener* onclick() const; 203 void setOnclick(PassRefPtr<EventListener>); 204 EventListener* ondblclick() const; 205 void setOndblclick(PassRefPtr<EventListener>); 206 EventListener* onerror() const; 207 void setOnerror(PassRefPtr<EventListener>); 208 EventListener* onfocus() const; 209 void setOnfocus(PassRefPtr<EventListener>); 210 EventListener* onkeydown() const; 211 void setOnkeydown(PassRefPtr<EventListener>); 212 EventListener* onkeypress() const; 213 void setOnkeypress(PassRefPtr<EventListener>); 214 EventListener* onkeyup() const; 215 void setOnkeyup(PassRefPtr<EventListener>); 216 EventListener* onload() const; 217 void setOnload(PassRefPtr<EventListener>); 218 EventListener* onmousedown() const; 219 void setOnmousedown(PassRefPtr<EventListener>); 220 EventListener* onmousemove() const; 221 void setOnmousemove(PassRefPtr<EventListener>); 222 EventListener* onmouseout() const; 223 void setOnmouseout(PassRefPtr<EventListener>); 224 EventListener* onmouseover() const; 225 void setOnmouseover(PassRefPtr<EventListener>); 226 EventListener* onmouseup() const; 227 void setOnmouseup(PassRefPtr<EventListener>); 228 EventListener* onmousewheel() const; 229 void setOnmousewheel(PassRefPtr<EventListener>); 230 EventListener* onreset() const; 231 void setOnreset(PassRefPtr<EventListener>); 232 EventListener* onresize() const; 233 void setOnresize(PassRefPtr<EventListener>); 234 EventListener* onscroll() const; 235 void setOnscroll(PassRefPtr<EventListener>); 236 EventListener* onsearch() const; 237 void setOnsearch(PassRefPtr<EventListener>); 238 EventListener* onselect() const; 239 void setOnselect(PassRefPtr<EventListener>); 240 EventListener* onsubmit() const; 241 void setOnsubmit(PassRefPtr<EventListener>); 242 EventListener* onunload() const; 243 void setOnunload(PassRefPtr<EventListener>); 244 EventListener* onbeforeunload() const; 245 void setOnbeforeunload(PassRefPtr<EventListener>); 246 EventListener* onwebkitanimationstart() const; 247 void setOnwebkitanimationstart(PassRefPtr<EventListener>); 248 EventListener* onwebkitanimationiteration() const; 249 void setOnwebkitanimationiteration(PassRefPtr<EventListener>); 250 EventListener* onwebkitanimationend() const; 251 void setOnwebkitanimationend(PassRefPtr<EventListener>); 252 EventListener* onwebkittransitionend() const; 253 void setOnwebkittransitionend(PassRefPtr<EventListener>); 254 #if ENABLE(TOUCH_EVENTS) // Android 255 EventListener* ontouchstart() const; 256 void setOntouchstart(PassRefPtr<EventListener>); 257 EventListener* ontouchend() const; 258 void setOntouchend(PassRefPtr<EventListener>); 259 EventListener* ontouchmove() const; 260 void setOntouchmove(PassRefPtr<EventListener>); 261 EventListener* ontouchcancel() const; 262 void setOntouchcancel(PassRefPtr<EventListener>); 263 #endif 264 265 // These methods are used for GC marking. See JSDOMWindow::mark() in 266 // JSDOMWindowCustom.cpp. optionalScreen()267 Screen* optionalScreen() const { return m_screen.get(); } optionalSelection()268 DOMSelection* optionalSelection() const { return m_selection.get(); } optionalHistory()269 History* optionalHistory() const { return m_history.get(); } optionalLocationbar()270 BarInfo* optionalLocationbar() const { return m_locationbar.get(); } optionalMenubar()271 BarInfo* optionalMenubar() const { return m_menubar.get(); } optionalPersonalbar()272 BarInfo* optionalPersonalbar() const { return m_personalbar.get(); } optionalScrollbars()273 BarInfo* optionalScrollbars() const { return m_scrollbars.get(); } optionalStatusbar()274 BarInfo* optionalStatusbar() const { return m_statusbar.get(); } optionalToolbar()275 BarInfo* optionalToolbar() const { return m_toolbar.get(); } optionalConsole()276 Console* optionalConsole() const { return m_console.get(); } optionalNavigator()277 Navigator* optionalNavigator() const { return m_navigator.get(); } optionalLocation()278 Location* optionalLocation() const { return m_location.get(); } 279 #if ENABLE(DOM_STORAGE) optionalSessionStorage()280 Storage* optionalSessionStorage() const { return m_sessionStorage.get(); } optionalLocalStorage()281 Storage* optionalLocalStorage() const { return m_sessionStorage.get(); } 282 #endif 283 #if ENABLE(OFFLINE_WEB_APPLICATIONS) optionalApplicationCache()284 DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); } 285 #endif 286 287 private: 288 DOMWindow(Frame*); 289 290 void setInlineEventListenerForType(const AtomicString& eventType, PassRefPtr<EventListener>); 291 EventListener* inlineEventListenerForType(const AtomicString& eventType) const; 292 293 RefPtr<SecurityOrigin> m_securityOrigin; 294 KURL m_url; 295 296 Frame* m_frame; 297 mutable RefPtr<Screen> m_screen; 298 mutable RefPtr<DOMSelection> m_selection; 299 mutable RefPtr<History> m_history; 300 mutable RefPtr<BarInfo> m_locationbar; 301 mutable RefPtr<BarInfo> m_menubar; 302 mutable RefPtr<BarInfo> m_personalbar; 303 mutable RefPtr<BarInfo> m_scrollbars; 304 mutable RefPtr<BarInfo> m_statusbar; 305 mutable RefPtr<BarInfo> m_toolbar; 306 mutable RefPtr<Console> m_console; 307 mutable RefPtr<Navigator> m_navigator; 308 mutable RefPtr<Location> m_location; 309 #if ENABLE(DOM_STORAGE) 310 mutable RefPtr<Storage> m_sessionStorage; 311 mutable RefPtr<Storage> m_localStorage; 312 #endif 313 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 314 mutable RefPtr<DOMApplicationCache> m_applicationCache; 315 #endif 316 }; 317 318 } // namespace WebCore 319 320 #endif 321