• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006, 2007, 2008 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 #include "config.h"
27 #include "DOMWindow.h"
28 
29 #include "BarInfo.h"
30 #include "BeforeUnloadEvent.h"
31 #include "CSSComputedStyleDeclaration.h"
32 #include "CSSRuleList.h"
33 #include "CSSStyleSelector.h"
34 #include "CString.h"
35 #include "Chrome.h"
36 #include "Console.h"
37 #include "DOMSelection.h"
38 #include "DOMTimer.h"
39 #include "Document.h"
40 #include "Element.h"
41 #include "EventException.h"
42 #include "EventListener.h"
43 #include "EventNames.h"
44 #include "ExceptionCode.h"
45 #include "FloatRect.h"
46 #include "Frame.h"
47 #include "FrameLoader.h"
48 #include "FrameTree.h"
49 #include "FrameView.h"
50 #include "HTMLFrameOwnerElement.h"
51 #include "History.h"
52 #include "InspectorController.h"
53 #include "Location.h"
54 #include "Media.h"
55 #include "MessageEvent.h"
56 #include "Navigator.h"
57 #include "Page.h"
58 #include "PageGroup.h"
59 #include "PlatformScreen.h"
60 #include "PlatformString.h"
61 #include "Screen.h"
62 #include "SecurityOrigin.h"
63 #include "Settings.h"
64 #include "SuddenTermination.h"
65 #include "WebKitPoint.h"
66 #include <algorithm>
67 #include <wtf/MathExtras.h>
68 
69 #if ENABLE(DATABASE)
70 #include "Database.h"
71 #endif
72 
73 #if ENABLE(DOM_STORAGE)
74 #include "Storage.h"
75 #include "StorageArea.h"
76 #include "StorageNamespace.h"
77 #endif
78 
79 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
80 #include "DOMApplicationCache.h"
81 #endif
82 
83 using std::min;
84 using std::max;
85 
86 namespace WebCore {
87 
88 class PostMessageTimer : public TimerBase {
89 public:
PostMessageTimer(DOMWindow * window,const String & message,const String & sourceOrigin,PassRefPtr<DOMWindow> source,PassOwnPtr<MessagePortChannel> channel,SecurityOrigin * targetOrigin)90     PostMessageTimer(DOMWindow* window, const String& message, const String& sourceOrigin, PassRefPtr<DOMWindow> source, PassOwnPtr<MessagePortChannel> channel, SecurityOrigin* targetOrigin)
91         : m_window(window)
92         , m_message(message)
93         , m_origin(sourceOrigin)
94         , m_source(source)
95         , m_channel(channel)
96         , m_targetOrigin(targetOrigin)
97     {
98     }
99 
event(ScriptExecutionContext * context)100     PassRefPtr<MessageEvent> event(ScriptExecutionContext* context)
101     {
102         RefPtr<MessagePort> messagePort;
103         if (m_channel) {
104             messagePort = MessagePort::create(*context);
105             messagePort->entangle(m_channel.release());
106         }
107         return MessageEvent::create(m_message, m_origin, "", m_source, messagePort.release());
108     }
targetOrigin() const109     SecurityOrigin* targetOrigin() const { return m_targetOrigin.get(); }
110 
111 private:
fired()112     virtual void fired()
113     {
114         m_window->postMessageTimerFired(this);
115     }
116 
117     RefPtr<DOMWindow> m_window;
118     String m_message;
119     String m_origin;
120     RefPtr<DOMWindow> m_source;
121     OwnPtr<MessagePortChannel> m_channel;
122     RefPtr<SecurityOrigin> m_targetOrigin;
123 };
124 
125 typedef HashMap<DOMWindow*, RegisteredEventListenerVector*> DOMWindowRegisteredEventListenerMap;
126 
pendingUnloadEventListenerMap()127 static DOMWindowRegisteredEventListenerMap& pendingUnloadEventListenerMap()
128 {
129     DEFINE_STATIC_LOCAL(DOMWindowRegisteredEventListenerMap, eventListenerMap, ());
130     return eventListenerMap;
131 }
132 
pendingBeforeUnloadEventListenerMap()133 static DOMWindowRegisteredEventListenerMap& pendingBeforeUnloadEventListenerMap()
134 {
135     DEFINE_STATIC_LOCAL(DOMWindowRegisteredEventListenerMap, eventListenerMap, ());
136     return eventListenerMap;
137 }
138 
allowsPendingBeforeUnloadListeners(DOMWindow * window)139 static bool allowsPendingBeforeUnloadListeners(DOMWindow* window)
140 {
141     ASSERT_ARG(window, window);
142     Frame* frame = window->frame();
143     Page* page = frame->page();
144     return page && frame == page->mainFrame();
145 }
146 
addPendingEventListener(DOMWindowRegisteredEventListenerMap & map,DOMWindow * window,RegisteredEventListener * listener)147 static void addPendingEventListener(DOMWindowRegisteredEventListenerMap& map, DOMWindow* window, RegisteredEventListener* listener)
148 {
149     ASSERT_ARG(window, window);
150     ASSERT_ARG(listener, listener);
151 
152     if (map.isEmpty())
153         disableSuddenTermination();
154 
155     pair<DOMWindowRegisteredEventListenerMap::iterator, bool> result = map.add(window, 0);
156     if (result.second)
157         result.first->second = new RegisteredEventListenerVector;
158     result.first->second->append(listener);
159 }
160 
removePendingEventListener(DOMWindowRegisteredEventListenerMap & map,DOMWindow * window,RegisteredEventListener * listener)161 static void removePendingEventListener(DOMWindowRegisteredEventListenerMap& map, DOMWindow* window, RegisteredEventListener* listener)
162 {
163     ASSERT_ARG(window, window);
164     ASSERT_ARG(listener, listener);
165 
166     DOMWindowRegisteredEventListenerMap::iterator it = map.find(window);
167     ASSERT(it != map.end());
168 
169     RegisteredEventListenerVector* listeners = it->second;
170     size_t index = listeners->find(listener);
171     ASSERT(index != WTF::notFound);
172     listeners->remove(index);
173 
174     if (!listeners->isEmpty())
175         return;
176 
177     map.remove(it);
178     delete listeners;
179 
180     if (map.isEmpty())
181         enableSuddenTermination();
182 }
183 
removePendingEventListeners(DOMWindowRegisteredEventListenerMap & map,DOMWindow * window)184 static void removePendingEventListeners(DOMWindowRegisteredEventListenerMap& map, DOMWindow* window)
185 {
186     ASSERT_ARG(window, window);
187 
188     RegisteredEventListenerVector* listeners = map.take(window);
189     if (!listeners)
190         return;
191 
192     delete listeners;
193 
194     if (map.isEmpty())
195         enableSuddenTermination();
196 }
197 
dispatchAllPendingBeforeUnloadEvents()198 bool DOMWindow::dispatchAllPendingBeforeUnloadEvents()
199 {
200     DOMWindowRegisteredEventListenerMap& map = pendingBeforeUnloadEventListenerMap();
201     if (map.isEmpty())
202         return true;
203 
204     static bool alreadyDispatched = false;
205     ASSERT(!alreadyDispatched);
206     if (alreadyDispatched)
207         return true;
208 
209     Vector<RefPtr<DOMWindow> > windows;
210     DOMWindowRegisteredEventListenerMap::iterator mapEnd = map.end();
211     for (DOMWindowRegisteredEventListenerMap::iterator it = map.begin(); it != mapEnd; ++it)
212         windows.append(it->first);
213 
214     size_t size = windows.size();
215     for (size_t i = 0; i < size; ++i) {
216         DOMWindow* window = windows[i].get();
217         RegisteredEventListenerVector* listeners = map.get(window);
218         if (!listeners)
219             continue;
220 
221         RegisteredEventListenerVector listenersCopy = *listeners;
222         Frame* frame = window->frame();
223         if (!frame->shouldClose(&listenersCopy))
224             return false;
225     }
226 
227     enableSuddenTermination();
228 
229     alreadyDispatched = true;
230 
231     return true;
232 }
233 
pendingUnloadEventListeners() const234 unsigned DOMWindow::pendingUnloadEventListeners() const
235 {
236     RegisteredEventListenerVector* listeners = pendingUnloadEventListenerMap().get(const_cast<DOMWindow*>(this));
237     return listeners ? listeners->size() : 0;
238 }
239 
dispatchAllPendingUnloadEvents()240 void DOMWindow::dispatchAllPendingUnloadEvents()
241 {
242     DOMWindowRegisteredEventListenerMap& map = pendingUnloadEventListenerMap();
243     if (map.isEmpty())
244         return;
245 
246     static bool alreadyDispatched = false;
247     ASSERT(!alreadyDispatched);
248     if (alreadyDispatched)
249         return;
250 
251     Vector<RefPtr<DOMWindow> > windows;
252     DOMWindowRegisteredEventListenerMap::iterator mapEnd = map.end();
253     for (DOMWindowRegisteredEventListenerMap::iterator it = map.begin(); it != mapEnd; ++it)
254         windows.append(it->first);
255 
256     size_t size = windows.size();
257     for (size_t i = 0; i < size; ++i) {
258         DOMWindow* window = windows[i].get();
259         RegisteredEventListenerVector* listeners = map.get(window);
260         if (!listeners)
261             continue;
262         RegisteredEventListenerVector listenersCopy = *listeners;
263         window->dispatchUnloadEvent(&listenersCopy);
264     }
265 
266     enableSuddenTermination();
267 
268     alreadyDispatched = true;
269 }
270 
271 // This function:
272 // 1) Validates the pending changes are not changing to NaN
273 // 2) Constrains the window rect to no smaller than 100 in each dimension and no
274 //    bigger than the the float rect's dimensions.
275 // 3) Constrain window rect to within the top and left boundaries of the screen rect
276 // 4) Constraint the window rect to within the bottom and right boundaries of the
277 //    screen rect.
278 // 5) Translate the window rect coordinates to be within the coordinate space of
279 //    the screen rect.
adjustWindowRect(const FloatRect & screen,FloatRect & window,const FloatRect & pendingChanges)280 void DOMWindow::adjustWindowRect(const FloatRect& screen, FloatRect& window, const FloatRect& pendingChanges)
281 {
282     // Make sure we're in a valid state before adjusting dimensions.
283     ASSERT(isfinite(screen.x()));
284     ASSERT(isfinite(screen.y()));
285     ASSERT(isfinite(screen.width()));
286     ASSERT(isfinite(screen.height()));
287     ASSERT(isfinite(window.x()));
288     ASSERT(isfinite(window.y()));
289     ASSERT(isfinite(window.width()));
290     ASSERT(isfinite(window.height()));
291 
292     // Update window values if new requested values are not NaN.
293     if (!isnan(pendingChanges.x()))
294         window.setX(pendingChanges.x());
295     if (!isnan(pendingChanges.y()))
296         window.setY(pendingChanges.y());
297     if (!isnan(pendingChanges.width()))
298         window.setWidth(pendingChanges.width());
299     if (!isnan(pendingChanges.height()))
300         window.setHeight(pendingChanges.height());
301 
302     // Resize the window to between 100 and the screen width and height.
303     window.setWidth(min(max(100.0f, window.width()), screen.width()));
304     window.setHeight(min(max(100.0f, window.height()), screen.height()));
305 
306     // Constrain the window position to the screen.
307     window.setX(max(screen.x(), min(window.x(), screen.right() - window.width())));
308     window.setY(max(screen.y(), min(window.y(), screen.bottom() - window.height())));
309 }
310 
parseModalDialogFeatures(const String & featuresArg,HashMap<String,String> & map)311 void DOMWindow::parseModalDialogFeatures(const String& featuresArg, HashMap<String, String>& map)
312 {
313     Vector<String> features;
314     featuresArg.split(';', features);
315     Vector<String>::const_iterator end = features.end();
316     for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) {
317         String s = *it;
318         int pos = s.find('=');
319         int colonPos = s.find(':');
320         if (pos >= 0 && colonPos >= 0)
321             continue; // ignore any strings that have both = and :
322         if (pos < 0)
323             pos = colonPos;
324         if (pos < 0) {
325             // null string for value means key without value
326             map.set(s.stripWhiteSpace().lower(), String());
327         } else {
328             String key = s.left(pos).stripWhiteSpace().lower();
329             String val = s.substring(pos + 1).stripWhiteSpace().lower();
330             int spacePos = val.find(' ');
331             if (spacePos != -1)
332                 val = val.left(spacePos);
333             map.set(key, val);
334         }
335     }
336 }
337 
allowPopUp(Frame * activeFrame)338 bool DOMWindow::allowPopUp(Frame* activeFrame)
339 {
340     ASSERT(activeFrame);
341     if (activeFrame->script()->processingUserGesture())
342         return true;
343     Settings* settings = activeFrame->settings();
344     return settings && settings->javaScriptCanOpenWindowsAutomatically();
345 }
346 
canShowModalDialog(const Frame * frame)347 bool DOMWindow::canShowModalDialog(const Frame* frame)
348 {
349     if (!frame)
350         return false;
351     Page* page = frame->page();
352     if (!page)
353         return false;
354     return page->chrome()->canRunModal();
355 }
356 
canShowModalDialogNow(const Frame * frame)357 bool DOMWindow::canShowModalDialogNow(const Frame* frame)
358 {
359     if (!frame)
360         return false;
361     Page* page = frame->page();
362     if (!page)
363         return false;
364     return page->chrome()->canRunModalNow();
365 }
366 
DOMWindow(Frame * frame)367 DOMWindow::DOMWindow(Frame* frame)
368     : m_frame(frame)
369 {
370 }
371 
~DOMWindow()372 DOMWindow::~DOMWindow()
373 {
374     if (m_frame)
375         m_frame->clearFormerDOMWindow(this);
376 
377     removePendingEventListeners(pendingUnloadEventListenerMap(), this);
378     removePendingEventListeners(pendingBeforeUnloadEventListenerMap(), this);
379 }
380 
scriptExecutionContext() const381 ScriptExecutionContext* DOMWindow::scriptExecutionContext() const
382 {
383     return document();
384 }
385 
disconnectFrame()386 void DOMWindow::disconnectFrame()
387 {
388     m_frame = 0;
389     clear();
390 }
391 
clear()392 void DOMWindow::clear()
393 {
394     if (m_screen)
395         m_screen->disconnectFrame();
396     m_screen = 0;
397 
398     if (m_selection)
399         m_selection->disconnectFrame();
400     m_selection = 0;
401 
402     if (m_history)
403         m_history->disconnectFrame();
404     m_history = 0;
405 
406     if (m_locationbar)
407         m_locationbar->disconnectFrame();
408     m_locationbar = 0;
409 
410     if (m_menubar)
411         m_menubar->disconnectFrame();
412     m_menubar = 0;
413 
414     if (m_personalbar)
415         m_personalbar->disconnectFrame();
416     m_personalbar = 0;
417 
418     if (m_scrollbars)
419         m_scrollbars->disconnectFrame();
420     m_scrollbars = 0;
421 
422     if (m_statusbar)
423         m_statusbar->disconnectFrame();
424     m_statusbar = 0;
425 
426     if (m_toolbar)
427         m_toolbar->disconnectFrame();
428     m_toolbar = 0;
429 
430     if (m_console)
431         m_console->disconnectFrame();
432     m_console = 0;
433 
434     if (m_navigator)
435         m_navigator->disconnectFrame();
436     m_navigator = 0;
437 
438     if (m_location)
439         m_location->disconnectFrame();
440     m_location = 0;
441 
442 #if ENABLE(DOM_STORAGE)
443     if (m_sessionStorage)
444         m_sessionStorage->disconnectFrame();
445     m_sessionStorage = 0;
446 
447     if (m_localStorage)
448         m_localStorage->disconnectFrame();
449     m_localStorage = 0;
450 #endif
451 
452 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
453     if (m_applicationCache)
454         m_applicationCache->disconnectFrame();
455     m_applicationCache = 0;
456 #endif
457 }
458 
screen() const459 Screen* DOMWindow::screen() const
460 {
461     if (!m_screen)
462         m_screen = Screen::create(m_frame);
463     return m_screen.get();
464 }
465 
history() const466 History* DOMWindow::history() const
467 {
468     if (!m_history)
469         m_history = History::create(m_frame);
470     return m_history.get();
471 }
472 
locationbar() const473 BarInfo* DOMWindow::locationbar() const
474 {
475     if (!m_locationbar)
476         m_locationbar = BarInfo::create(m_frame, BarInfo::Locationbar);
477     return m_locationbar.get();
478 }
479 
menubar() const480 BarInfo* DOMWindow::menubar() const
481 {
482     if (!m_menubar)
483         m_menubar = BarInfo::create(m_frame, BarInfo::Menubar);
484     return m_menubar.get();
485 }
486 
personalbar() const487 BarInfo* DOMWindow::personalbar() const
488 {
489     if (!m_personalbar)
490         m_personalbar = BarInfo::create(m_frame, BarInfo::Personalbar);
491     return m_personalbar.get();
492 }
493 
scrollbars() const494 BarInfo* DOMWindow::scrollbars() const
495 {
496     if (!m_scrollbars)
497         m_scrollbars = BarInfo::create(m_frame, BarInfo::Scrollbars);
498     return m_scrollbars.get();
499 }
500 
statusbar() const501 BarInfo* DOMWindow::statusbar() const
502 {
503     if (!m_statusbar)
504         m_statusbar = BarInfo::create(m_frame, BarInfo::Statusbar);
505     return m_statusbar.get();
506 }
507 
toolbar() const508 BarInfo* DOMWindow::toolbar() const
509 {
510     if (!m_toolbar)
511         m_toolbar = BarInfo::create(m_frame, BarInfo::Toolbar);
512     return m_toolbar.get();
513 }
514 
console() const515 Console* DOMWindow::console() const
516 {
517     if (!m_console)
518         m_console = Console::create(m_frame);
519     return m_console.get();
520 }
521 
522 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
applicationCache() const523 DOMApplicationCache* DOMWindow::applicationCache() const
524 {
525     if (!m_applicationCache && m_frame && m_frame->settings() && m_frame->settings()->offlineWebApplicationCacheEnabled())
526         m_applicationCache = DOMApplicationCache::create(m_frame);
527     return m_applicationCache.get();
528 }
529 #endif
530 
navigator() const531 Navigator* DOMWindow::navigator() const
532 {
533     if (!m_navigator)
534         m_navigator = Navigator::create(m_frame);
535     return m_navigator.get();
536 }
537 
location() const538 Location* DOMWindow::location() const
539 {
540     if (!m_location)
541         m_location = Location::create(m_frame);
542     return m_location.get();
543 }
544 
545 #if ENABLE(DOM_STORAGE)
sessionStorage() const546 Storage* DOMWindow::sessionStorage() const
547 {
548     if (m_sessionStorage)
549         return m_sessionStorage.get();
550 
551     Document* document = this->document();
552     if (!document)
553         return 0;
554 
555     Page* page = document->page();
556     if (!page)
557         return 0;
558 
559     if (!page->settings()->sessionStorageEnabled())
560         return 0;
561 
562     RefPtr<StorageArea> storageArea = page->sessionStorage()->storageArea(document->securityOrigin());
563     page->inspectorController()->didUseDOMStorage(storageArea.get(), false, m_frame);
564 
565     m_sessionStorage = Storage::create(m_frame, storageArea.release());
566     return m_sessionStorage.get();
567 }
568 
localStorage() const569 Storage* DOMWindow::localStorage() const
570 {
571     if (m_localStorage)
572         return m_localStorage.get();
573 
574     Document* document = this->document();
575     if (!document)
576         return 0;
577 
578     Page* page = document->page();
579     if (!page)
580         return 0;
581 
582     if (!page->settings()->localStorageEnabled())
583         return 0;
584 
585     StorageNamespace* localStorage = page->group().localStorage();
586     RefPtr<StorageArea> storageArea = localStorage ? localStorage->storageArea(document->securityOrigin()) : 0;
587     if (storageArea) {
588         page->inspectorController()->didUseDOMStorage(storageArea.get(), true, m_frame);
589         m_localStorage = Storage::create(m_frame, storageArea.release());
590     }
591 
592     return m_localStorage.get();
593 }
594 #endif
595 
postMessage(const String & message,MessagePort * messagePort,const String & targetOrigin,DOMWindow * source,ExceptionCode & ec)596 void DOMWindow::postMessage(const String& message, MessagePort* messagePort, const String& targetOrigin, DOMWindow* source, ExceptionCode& ec)
597 {
598     if (!m_frame)
599         return;
600 
601     // Compute the target origin.  We need to do this synchronously in order
602     // to generate the SYNTAX_ERR exception correctly.
603     RefPtr<SecurityOrigin> target;
604     if (targetOrigin != "*") {
605         target = SecurityOrigin::createFromString(targetOrigin);
606         if (target->isEmpty()) {
607             ec = SYNTAX_ERR;
608             return;
609         }
610     }
611 
612     OwnPtr<MessagePortChannel> channel;
613     if (messagePort)
614         channel = messagePort->disentangle(ec);
615     if (ec)
616         return;
617 
618     // Capture the source of the message.  We need to do this synchronously
619     // in order to capture the source of the message correctly.
620     Document* sourceDocument = source->document();
621     if (!sourceDocument)
622         return;
623     String sourceOrigin = sourceDocument->securityOrigin()->toString();
624 
625     // Schedule the message.
626     PostMessageTimer* timer = new PostMessageTimer(this, message, sourceOrigin, source, channel.release(), target.get());
627     timer->startOneShot(0);
628 }
629 
postMessageTimerFired(PostMessageTimer * t)630 void DOMWindow::postMessageTimerFired(PostMessageTimer* t)
631 {
632     OwnPtr<PostMessageTimer> timer(t);
633 
634     if (!document())
635         return;
636 
637     if (timer->targetOrigin()) {
638         // Check target origin now since the target document may have changed since the simer was scheduled.
639         if (!timer->targetOrigin()->isSameSchemeHostPort(document()->securityOrigin())) {
640             String message = String::format("Unable to post message to %s. Recipient has origin %s.\n",
641                 timer->targetOrigin()->toString().utf8().data(), document()->securityOrigin()->toString().utf8().data());
642             console()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, 0, String());
643             return;
644         }
645     }
646 
647     ExceptionCode ec = 0;
648     dispatchEvent(timer->event(document()), ec);
649 }
650 
getSelection()651 DOMSelection* DOMWindow::getSelection()
652 {
653     if (!m_selection)
654         m_selection = DOMSelection::create(m_frame);
655     return m_selection.get();
656 }
657 
frameElement() const658 Element* DOMWindow::frameElement() const
659 {
660     if (!m_frame)
661         return 0;
662 
663     return m_frame->ownerElement();
664 }
665 
focus()666 void DOMWindow::focus()
667 {
668     if (!m_frame)
669         return;
670 
671     m_frame->focusWindow();
672 }
673 
blur()674 void DOMWindow::blur()
675 {
676     if (!m_frame)
677         return;
678 
679     m_frame->unfocusWindow();
680 }
681 
close()682 void DOMWindow::close()
683 {
684     if (!m_frame)
685         return;
686 
687     Page* page = m_frame->page();
688     if (!page)
689         return;
690 
691     if (m_frame != page->mainFrame())
692         return;
693 
694     Settings* settings = m_frame->settings();
695     bool allowScriptsToCloseWindows =
696         settings && settings->allowScriptsToCloseWindows();
697 
698     if (m_frame->loader()->openedByDOM()
699         || m_frame->loader()->getHistoryLength() <= 1
700         || allowScriptsToCloseWindows)
701         m_frame->scheduleClose();
702 }
703 
print()704 void DOMWindow::print()
705 {
706     if (!m_frame)
707         return;
708 
709     Page* page = m_frame->page();
710     if (!page)
711         return;
712 
713     page->chrome()->print(m_frame);
714 }
715 
stop()716 void DOMWindow::stop()
717 {
718     if (!m_frame)
719         return;
720 
721     // We must check whether the load is complete asynchronously, because we might still be parsing
722     // the document until the callstack unwinds.
723     m_frame->loader()->stopForUserCancel(true);
724 }
725 
alert(const String & message)726 void DOMWindow::alert(const String& message)
727 {
728     if (!m_frame)
729         return;
730 
731     m_frame->document()->updateStyleIfNeeded();
732 
733     Page* page = m_frame->page();
734     if (!page)
735         return;
736 
737     page->chrome()->runJavaScriptAlert(m_frame, message);
738 }
739 
confirm(const String & message)740 bool DOMWindow::confirm(const String& message)
741 {
742     if (!m_frame)
743         return false;
744 
745     m_frame->document()->updateStyleIfNeeded();
746 
747     Page* page = m_frame->page();
748     if (!page)
749         return false;
750 
751     return page->chrome()->runJavaScriptConfirm(m_frame, message);
752 }
753 
prompt(const String & message,const String & defaultValue)754 String DOMWindow::prompt(const String& message, const String& defaultValue)
755 {
756     if (!m_frame)
757         return String();
758 
759     m_frame->document()->updateStyleIfNeeded();
760 
761     Page* page = m_frame->page();
762     if (!page)
763         return String();
764 
765     String returnValue;
766     if (page->chrome()->runJavaScriptPrompt(m_frame, message, defaultValue, returnValue))
767         return returnValue;
768 
769     return String();
770 }
771 
find(const String & string,bool caseSensitive,bool backwards,bool wrap,bool,bool,bool) const772 bool DOMWindow::find(const String& string, bool caseSensitive, bool backwards, bool wrap, bool /*wholeWord*/, bool /*searchInFrames*/, bool /*showDialog*/) const
773 {
774     if (!m_frame)
775         return false;
776 
777     // FIXME (13016): Support wholeWord, searchInFrames and showDialog
778     return m_frame->findString(string, !backwards, caseSensitive, wrap, false);
779 }
780 
offscreenBuffering() const781 bool DOMWindow::offscreenBuffering() const
782 {
783     return true;
784 }
785 
outerHeight() const786 int DOMWindow::outerHeight() const
787 {
788     if (!m_frame)
789         return 0;
790 
791     Page* page = m_frame->page();
792     if (!page)
793         return 0;
794 
795     return static_cast<int>(page->chrome()->windowRect().height());
796 }
797 
outerWidth() const798 int DOMWindow::outerWidth() const
799 {
800     if (!m_frame)
801         return 0;
802 
803     Page* page = m_frame->page();
804     if (!page)
805         return 0;
806 
807     return static_cast<int>(page->chrome()->windowRect().width());
808 }
809 
innerHeight() const810 int DOMWindow::innerHeight() const
811 {
812     if (!m_frame)
813         return 0;
814 
815     FrameView* view = m_frame->view();
816     if (!view)
817         return 0;
818 
819     return static_cast<int>(view->height() / m_frame->pageZoomFactor());
820 }
821 
innerWidth() const822 int DOMWindow::innerWidth() const
823 {
824     if (!m_frame)
825         return 0;
826 
827     FrameView* view = m_frame->view();
828     if (!view)
829         return 0;
830 
831     return static_cast<int>(view->width() / m_frame->pageZoomFactor());
832 }
833 
screenX() const834 int DOMWindow::screenX() const
835 {
836     if (!m_frame)
837         return 0;
838 
839     Page* page = m_frame->page();
840     if (!page)
841         return 0;
842 
843     return static_cast<int>(page->chrome()->windowRect().x());
844 }
845 
screenY() const846 int DOMWindow::screenY() const
847 {
848     if (!m_frame)
849         return 0;
850 
851     Page* page = m_frame->page();
852     if (!page)
853         return 0;
854 
855     return static_cast<int>(page->chrome()->windowRect().y());
856 }
857 
scrollX() const858 int DOMWindow::scrollX() const
859 {
860     if (!m_frame)
861         return 0;
862 
863     FrameView* view = m_frame->view();
864     if (!view)
865         return 0;
866 
867     m_frame->document()->updateLayoutIgnorePendingStylesheets();
868 
869     return static_cast<int>(view->scrollX() / m_frame->pageZoomFactor());
870 }
871 
872 #ifdef ANDROID_ORIENTATION_SUPPORT
orientation() const873 int DOMWindow::orientation() const
874 {
875     return screen()->orientation();
876 }
877 #endif
878 
scrollY() const879 int DOMWindow::scrollY() const
880 {
881     if (!m_frame)
882         return 0;
883 
884     FrameView* view = m_frame->view();
885     if (!view)
886         return 0;
887 
888     m_frame->document()->updateLayoutIgnorePendingStylesheets();
889 
890     return static_cast<int>(view->scrollY() / m_frame->pageZoomFactor());
891 }
892 
closed() const893 bool DOMWindow::closed() const
894 {
895     return !m_frame;
896 }
897 
length() const898 unsigned DOMWindow::length() const
899 {
900     if (!m_frame)
901         return 0;
902 
903     return m_frame->tree()->childCount();
904 }
905 
name() const906 String DOMWindow::name() const
907 {
908     if (!m_frame)
909         return String();
910 
911     return m_frame->tree()->name();
912 }
913 
setName(const String & string)914 void DOMWindow::setName(const String& string)
915 {
916     if (!m_frame)
917         return;
918 
919     m_frame->tree()->setName(string);
920 }
921 
status() const922 String DOMWindow::status() const
923 {
924     if (!m_frame)
925         return String();
926 
927     return m_frame->jsStatusBarText();
928 }
929 
setStatus(const String & string)930 void DOMWindow::setStatus(const String& string)
931 {
932     if (!m_frame)
933         return;
934 
935     m_frame->setJSStatusBarText(string);
936 }
937 
defaultStatus() const938 String DOMWindow::defaultStatus() const
939 {
940     if (!m_frame)
941         return String();
942 
943     return m_frame->jsDefaultStatusBarText();
944 }
945 
setDefaultStatus(const String & string)946 void DOMWindow::setDefaultStatus(const String& string)
947 {
948     if (!m_frame)
949         return;
950 
951     m_frame->setJSDefaultStatusBarText(string);
952 }
953 
self() const954 DOMWindow* DOMWindow::self() const
955 {
956     if (!m_frame)
957         return 0;
958 
959     return m_frame->domWindow();
960 }
961 
opener() const962 DOMWindow* DOMWindow::opener() const
963 {
964     if (!m_frame)
965         return 0;
966 
967     Frame* opener = m_frame->loader()->opener();
968     if (!opener)
969         return 0;
970 
971     return opener->domWindow();
972 }
973 
parent() const974 DOMWindow* DOMWindow::parent() const
975 {
976     if (!m_frame)
977         return 0;
978 
979     Frame* parent = m_frame->tree()->parent(true);
980     if (parent)
981         return parent->domWindow();
982 
983     return m_frame->domWindow();
984 }
985 
top() const986 DOMWindow* DOMWindow::top() const
987 {
988     if (!m_frame)
989         return 0;
990 
991     Page* page = m_frame->page();
992     if (!page)
993         return 0;
994 
995     return m_frame->tree()->top(true)->domWindow();
996 }
997 
document() const998 Document* DOMWindow::document() const
999 {
1000     // FIXME: This function shouldn't need a frame to work.
1001     if (!m_frame)
1002         return 0;
1003 
1004     // The m_frame pointer is not zeroed out when the window is put into b/f cache, so it can hold an unrelated document/window pair.
1005     // FIXME: We should always zero out the frame pointer on navigation to avoid accidentally accessing the new frame content.
1006     if (m_frame->domWindow() != this)
1007         return 0;
1008 
1009     ASSERT(m_frame->document());
1010     return m_frame->document();
1011 }
1012 
media() const1013 PassRefPtr<Media> DOMWindow::media() const
1014 {
1015     return Media::create(const_cast<DOMWindow*>(this));
1016 }
1017 
getComputedStyle(Element * elt,const String &) const1018 PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String&) const
1019 {
1020     if (!elt)
1021         return 0;
1022 
1023     // FIXME: This needs take pseudo elements into account.
1024     return computedStyle(elt);
1025 }
1026 
getMatchedCSSRules(Element * elt,const String & pseudoElt,bool authorOnly) const1027 PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* elt, const String& pseudoElt, bool authorOnly) const
1028 {
1029     if (!m_frame)
1030         return 0;
1031 
1032     Document* doc = m_frame->document();
1033 
1034     if (!pseudoElt.isEmpty())
1035         return doc->styleSelector()->pseudoStyleRulesForElement(elt, pseudoElt, authorOnly);
1036     return doc->styleSelector()->styleRulesForElement(elt, authorOnly);
1037 }
1038 
webkitConvertPointFromNodeToPage(Node * node,const WebKitPoint * p) const1039 PassRefPtr<WebKitPoint> DOMWindow::webkitConvertPointFromNodeToPage(Node* node, const WebKitPoint* p) const
1040 {
1041     if (!node || !p)
1042         return 0;
1043 
1044     FloatPoint pagePoint(p->x(), p->y());
1045     pagePoint = node->convertToPage(pagePoint);
1046     return WebKitPoint::create(pagePoint.x(), pagePoint.y());
1047 }
1048 
webkitConvertPointFromPageToNode(Node * node,const WebKitPoint * p) const1049 PassRefPtr<WebKitPoint> DOMWindow::webkitConvertPointFromPageToNode(Node* node, const WebKitPoint* p) const
1050 {
1051     if (!node || !p)
1052         return 0;
1053 
1054     FloatPoint nodePoint(p->x(), p->y());
1055     nodePoint = node->convertFromPage(nodePoint);
1056     return WebKitPoint::create(nodePoint.x(), nodePoint.y());
1057 }
1058 
devicePixelRatio() const1059 double DOMWindow::devicePixelRatio() const
1060 {
1061     if (!m_frame)
1062         return 0.0;
1063 
1064     Page* page = m_frame->page();
1065     if (!page)
1066         return 0.0;
1067 
1068     return page->chrome()->scaleFactor();
1069 }
1070 
1071 #if ENABLE(DATABASE)
openDatabase(const String & name,const String & version,const String & displayName,unsigned long estimatedSize,ExceptionCode & ec)1072 PassRefPtr<Database> DOMWindow::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, ExceptionCode& ec)
1073 {
1074     if (!m_frame)
1075         return 0;
1076 
1077     Document* doc = m_frame->document();
1078 
1079     Settings* settings = m_frame->settings();
1080     if (!settings || !settings->databasesEnabled())
1081         return 0;
1082 
1083     return Database::openDatabase(doc, name, version, displayName, estimatedSize, ec);
1084 }
1085 #endif
1086 
scrollBy(int x,int y) const1087 void DOMWindow::scrollBy(int x, int y) const
1088 {
1089     if (!m_frame)
1090         return;
1091 
1092     m_frame->document()->updateLayoutIgnorePendingStylesheets();
1093 
1094     FrameView* view = m_frame->view();
1095     if (!view)
1096         return;
1097 
1098     view->scrollBy(IntSize(x, y));
1099 }
1100 
scrollTo(int x,int y) const1101 void DOMWindow::scrollTo(int x, int y) const
1102 {
1103     if (!m_frame)
1104         return;
1105 
1106     m_frame->document()->updateLayoutIgnorePendingStylesheets();
1107 
1108     FrameView* view = m_frame->view();
1109     if (!view)
1110         return;
1111 
1112     int zoomedX = static_cast<int>(x * m_frame->pageZoomFactor());
1113     int zoomedY = static_cast<int>(y * m_frame->pageZoomFactor());
1114     view->setScrollPosition(IntPoint(zoomedX, zoomedY));
1115 }
1116 
moveBy(float x,float y) const1117 void DOMWindow::moveBy(float x, float y) const
1118 {
1119     if (!m_frame)
1120         return;
1121 
1122     Page* page = m_frame->page();
1123     if (!page)
1124         return;
1125 
1126     if (m_frame != page->mainFrame())
1127         return;
1128 
1129     FloatRect fr = page->chrome()->windowRect();
1130     FloatRect update = fr;
1131     update.move(x, y);
1132     // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1133     adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), fr, update);
1134     page->chrome()->setWindowRect(fr);
1135 }
1136 
moveTo(float x,float y) const1137 void DOMWindow::moveTo(float x, float y) const
1138 {
1139     if (!m_frame)
1140         return;
1141 
1142     Page* page = m_frame->page();
1143     if (!page)
1144         return;
1145 
1146     if (m_frame != page->mainFrame())
1147         return;
1148 
1149     FloatRect fr = page->chrome()->windowRect();
1150     FloatRect sr = screenAvailableRect(page->mainFrame()->view());
1151     fr.setLocation(sr.location());
1152     FloatRect update = fr;
1153     update.move(x, y);
1154     // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1155     adjustWindowRect(sr, fr, update);
1156     page->chrome()->setWindowRect(fr);
1157 }
1158 
resizeBy(float x,float y) const1159 void DOMWindow::resizeBy(float x, float y) const
1160 {
1161     if (!m_frame)
1162         return;
1163 
1164     Page* page = m_frame->page();
1165     if (!page)
1166         return;
1167 
1168     if (m_frame != page->mainFrame())
1169         return;
1170 
1171     FloatRect fr = page->chrome()->windowRect();
1172     FloatSize dest = fr.size() + FloatSize(x, y);
1173     FloatRect update(fr.location(), dest);
1174     adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), fr, update);
1175     page->chrome()->setWindowRect(fr);
1176 }
1177 
resizeTo(float width,float height) const1178 void DOMWindow::resizeTo(float width, float height) const
1179 {
1180     if (!m_frame)
1181         return;
1182 
1183     Page* page = m_frame->page();
1184     if (!page)
1185         return;
1186 
1187     if (m_frame != page->mainFrame())
1188         return;
1189 
1190     FloatRect fr = page->chrome()->windowRect();
1191     FloatSize dest = FloatSize(width, height);
1192     FloatRect update(fr.location(), dest);
1193     adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), fr, update);
1194     page->chrome()->setWindowRect(fr);
1195 }
1196 
setTimeout(ScheduledAction * action,int timeout)1197 int DOMWindow::setTimeout(ScheduledAction* action, int timeout)
1198 {
1199     return DOMTimer::install(scriptExecutionContext(), action, timeout, true);
1200 }
1201 
clearTimeout(int timeoutId)1202 void DOMWindow::clearTimeout(int timeoutId)
1203 {
1204     DOMTimer::removeById(scriptExecutionContext(), timeoutId);
1205 }
1206 
setInterval(ScheduledAction * action,int timeout)1207 int DOMWindow::setInterval(ScheduledAction* action, int timeout)
1208 {
1209     return DOMTimer::install(scriptExecutionContext(), action, timeout, false);
1210 }
1211 
clearInterval(int timeoutId)1212 void DOMWindow::clearInterval(int timeoutId)
1213 {
1214     DOMTimer::removeById(scriptExecutionContext(), timeoutId);
1215 }
1216 
handleEvent(Event * event,bool useCapture,RegisteredEventListenerVector * alternateListeners)1217 void DOMWindow::handleEvent(Event* event, bool useCapture, RegisteredEventListenerVector* alternateListeners)
1218 {
1219     RegisteredEventListenerVector& listeners = (alternateListeners ? *alternateListeners : m_eventListeners);
1220     if (listeners.isEmpty())
1221         return;
1222 
1223     // If any HTML event listeners are registered on the window, dispatch them here.
1224     RegisteredEventListenerVector listenersCopy = listeners;
1225     size_t size = listenersCopy.size();
1226     for (size_t i = 0; i < size; ++i) {
1227         RegisteredEventListener& r = *listenersCopy[i];
1228         if (r.eventType() == event->type() && r.useCapture() == useCapture && !r.removed())
1229             r.listener()->handleEvent(event, true);
1230     }
1231 }
1232 
addEventListener(const AtomicString & eventType,PassRefPtr<EventListener> listener,bool useCapture)1233 void DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
1234 {
1235     // Remove existing identical listener set with identical arguments.
1236     // The DOM 2 spec says that "duplicate instances are discarded" in this case.
1237     removeEventListener(eventType, listener.get(), useCapture);
1238     if (Document* document = this->document())
1239         document->addListenerTypeIfNeeded(eventType);
1240 
1241     RefPtr<RegisteredEventListener> registeredListener = RegisteredEventListener::create(eventType, listener, useCapture);
1242     m_eventListeners.append(registeredListener);
1243 
1244     if (eventType == eventNames().unloadEvent)
1245         addPendingEventListener(pendingUnloadEventListenerMap(), this, registeredListener.get());
1246     else if (eventType == eventNames().beforeunloadEvent && allowsPendingBeforeUnloadListeners(this))
1247         addPendingEventListener(pendingBeforeUnloadEventListenerMap(), this, registeredListener.get());
1248 }
1249 
removeEventListener(const AtomicString & eventType,EventListener * listener,bool useCapture)1250 void DOMWindow::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
1251 {
1252     size_t size = m_eventListeners.size();
1253     for (size_t i = 0; i < size; ++i) {
1254         RegisteredEventListener& r = *m_eventListeners[i];
1255         if (r.eventType() == eventType && r.listener() == listener && r.useCapture() == useCapture) {
1256             if (eventType == eventNames().unloadEvent)
1257                 removePendingEventListener(pendingUnloadEventListenerMap(), this, &r);
1258             else if (eventType == eventNames().beforeunloadEvent && allowsPendingBeforeUnloadListeners(this))
1259                 removePendingEventListener(pendingBeforeUnloadEventListenerMap(), this, &r);
1260             r.setRemoved(true);
1261             m_eventListeners.remove(i);
1262             return;
1263         }
1264     }
1265 }
1266 
dispatchEvent(PassRefPtr<Event> e,ExceptionCode & ec)1267 bool DOMWindow::dispatchEvent(PassRefPtr<Event> e, ExceptionCode& ec)
1268 {
1269     ASSERT(!eventDispatchForbidden());
1270 
1271     RefPtr<Event> event = e;
1272     if (!event || event->type().isEmpty()) {
1273         ec = EventException::UNSPECIFIED_EVENT_TYPE_ERR;
1274         return true;
1275     }
1276 
1277     RefPtr<DOMWindow> protect(this);
1278 
1279     event->setTarget(this);
1280     event->setCurrentTarget(this);
1281 
1282     handleEvent(event.get(), true);
1283     handleEvent(event.get(), false);
1284 
1285     return !event->defaultPrevented();
1286 }
1287 
dispatchEvent(const AtomicString & eventType,bool canBubble,bool cancelable)1288 void DOMWindow::dispatchEvent(const AtomicString& eventType, bool canBubble, bool cancelable)
1289 {
1290     ASSERT(!eventDispatchForbidden());
1291     ExceptionCode ec = 0;
1292     dispatchEvent(Event::create(eventType, canBubble, cancelable), ec);
1293 }
1294 
1295 // This function accommodates the Firefox quirk of dispatching the load, unload and
1296 // beforeunload events on the window, but setting event.target to be the Document.
dispatchEventWithDocumentAsTarget(PassRefPtr<Event> e,RegisteredEventListenerVector * alternateEventListeners)1297 inline void DOMWindow::dispatchEventWithDocumentAsTarget(PassRefPtr<Event> e, RegisteredEventListenerVector* alternateEventListeners)
1298 {
1299     ASSERT(!eventDispatchForbidden());
1300 
1301     RefPtr<Event> event = e;
1302     RefPtr<DOMWindow> protect(this);
1303     RefPtr<Document> document = this->document();
1304 
1305     event->setTarget(document);
1306     event->setCurrentTarget(this);
1307 
1308     handleEvent(event.get(), true, alternateEventListeners);
1309     handleEvent(event.get(), false, alternateEventListeners);
1310 }
1311 
dispatchLoadEvent()1312 void DOMWindow::dispatchLoadEvent()
1313 {
1314     dispatchEventWithDocumentAsTarget(Event::create(eventNames().loadEvent, false, false));
1315 
1316     // For load events, send a separate load event to the enclosing frame only.
1317     // This is a DOM extension and is independent of bubbling/capturing rules of
1318     // the DOM.
1319     Element* ownerElement = document()->ownerElement();
1320     if (ownerElement) {
1321         RefPtr<Event> ownerEvent = Event::create(eventNames().loadEvent, false, false);
1322         ownerEvent->setTarget(ownerElement);
1323         ownerElement->dispatchGenericEvent(ownerEvent.release());
1324     }
1325 }
1326 
dispatchUnloadEvent(RegisteredEventListenerVector * alternateEventListeners)1327 void DOMWindow::dispatchUnloadEvent(RegisteredEventListenerVector* alternateEventListeners)
1328 {
1329     dispatchEventWithDocumentAsTarget(Event::create(eventNames().unloadEvent, false, false), alternateEventListeners);
1330 }
1331 
dispatchBeforeUnloadEvent(RegisteredEventListenerVector * alternateEventListeners)1332 PassRefPtr<BeforeUnloadEvent> DOMWindow::dispatchBeforeUnloadEvent(RegisteredEventListenerVector* alternateEventListeners)
1333 {
1334     RefPtr<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create();
1335     dispatchEventWithDocumentAsTarget(beforeUnloadEvent.get(), alternateEventListeners);
1336     return beforeUnloadEvent.release();
1337 }
1338 
removeAllEventListeners()1339 void DOMWindow::removeAllEventListeners()
1340 {
1341     size_t size = m_eventListeners.size();
1342     for (size_t i = 0; i < size; ++i)
1343         m_eventListeners[i]->setRemoved(true);
1344     m_eventListeners.clear();
1345 
1346     removePendingEventListeners(pendingUnloadEventListenerMap(), this);
1347     removePendingEventListeners(pendingBeforeUnloadEventListenerMap(), this);
1348 }
1349 
hasEventListener(const AtomicString & eventType)1350 bool DOMWindow::hasEventListener(const AtomicString& eventType)
1351 {
1352     size_t size = m_eventListeners.size();
1353     for (size_t i = 0; i < size; ++i) {
1354         if (m_eventListeners[i]->eventType() == eventType)
1355             return true;
1356     }
1357     return false;
1358 }
1359 
setAttributeEventListener(const AtomicString & eventType,PassRefPtr<EventListener> listener)1360 void DOMWindow::setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener)
1361 {
1362     clearAttributeEventListener(eventType);
1363     if (listener)
1364         addEventListener(eventType, listener, false);
1365 }
1366 
clearAttributeEventListener(const AtomicString & eventType)1367 void DOMWindow::clearAttributeEventListener(const AtomicString& eventType)
1368 {
1369     size_t size = m_eventListeners.size();
1370     for (size_t i = 0; i < size; ++i) {
1371         RegisteredEventListener& r = *m_eventListeners[i];
1372         if (r.eventType() == eventType && r.listener()->isAttribute()) {
1373             if (eventType == eventNames().unloadEvent)
1374                 removePendingEventListener(pendingUnloadEventListenerMap(), this, &r);
1375             else if (eventType == eventNames().beforeunloadEvent && allowsPendingBeforeUnloadListeners(this))
1376                 removePendingEventListener(pendingBeforeUnloadEventListenerMap(), this, &r);
1377             r.setRemoved(true);
1378             m_eventListeners.remove(i);
1379             return;
1380         }
1381     }
1382 }
1383 
getAttributeEventListener(const AtomicString & eventType) const1384 EventListener* DOMWindow::getAttributeEventListener(const AtomicString& eventType) const
1385 {
1386     size_t size = m_eventListeners.size();
1387     for (size_t i = 0; i < size; ++i) {
1388         RegisteredEventListener& r = *m_eventListeners[i];
1389         if (r.eventType() == eventType && r.listener()->isAttribute())
1390             return r.listener();
1391     }
1392     return 0;
1393 }
1394 
onabort() const1395 EventListener* DOMWindow::onabort() const
1396 {
1397     return getAttributeEventListener(eventNames().abortEvent);
1398 }
1399 
setOnabort(PassRefPtr<EventListener> eventListener)1400 void DOMWindow::setOnabort(PassRefPtr<EventListener> eventListener)
1401 {
1402     setAttributeEventListener(eventNames().abortEvent, eventListener);
1403 }
1404 
onblur() const1405 EventListener* DOMWindow::onblur() const
1406 {
1407     return getAttributeEventListener(eventNames().blurEvent);
1408 }
1409 
setOnblur(PassRefPtr<EventListener> eventListener)1410 void DOMWindow::setOnblur(PassRefPtr<EventListener> eventListener)
1411 {
1412     setAttributeEventListener(eventNames().blurEvent, eventListener);
1413 }
1414 
onchange() const1415 EventListener* DOMWindow::onchange() const
1416 {
1417     return getAttributeEventListener(eventNames().changeEvent);
1418 }
1419 
setOnchange(PassRefPtr<EventListener> eventListener)1420 void DOMWindow::setOnchange(PassRefPtr<EventListener> eventListener)
1421 {
1422     setAttributeEventListener(eventNames().changeEvent, eventListener);
1423 }
1424 
onclick() const1425 EventListener* DOMWindow::onclick() const
1426 {
1427     return getAttributeEventListener(eventNames().clickEvent);
1428 }
1429 
setOnclick(PassRefPtr<EventListener> eventListener)1430 void DOMWindow::setOnclick(PassRefPtr<EventListener> eventListener)
1431 {
1432     setAttributeEventListener(eventNames().clickEvent, eventListener);
1433 }
1434 
ondblclick() const1435 EventListener* DOMWindow::ondblclick() const
1436 {
1437     return getAttributeEventListener(eventNames().dblclickEvent);
1438 }
1439 
setOndblclick(PassRefPtr<EventListener> eventListener)1440 void DOMWindow::setOndblclick(PassRefPtr<EventListener> eventListener)
1441 {
1442     setAttributeEventListener(eventNames().dblclickEvent, eventListener);
1443 }
1444 
ondrag() const1445 EventListener* DOMWindow::ondrag() const
1446 {
1447     return getAttributeEventListener(eventNames().dragEvent);
1448 }
1449 
setOndrag(PassRefPtr<EventListener> eventListener)1450 void DOMWindow::setOndrag(PassRefPtr<EventListener> eventListener)
1451 {
1452     setAttributeEventListener(eventNames().dragEvent, eventListener);
1453 }
1454 
ondragend() const1455 EventListener* DOMWindow::ondragend() const
1456 {
1457     return getAttributeEventListener(eventNames().dragendEvent);
1458 }
1459 
setOndragend(PassRefPtr<EventListener> eventListener)1460 void DOMWindow::setOndragend(PassRefPtr<EventListener> eventListener)
1461 {
1462     setAttributeEventListener(eventNames().dragendEvent, eventListener);
1463 }
1464 
ondragenter() const1465 EventListener* DOMWindow::ondragenter() const
1466 {
1467     return getAttributeEventListener(eventNames().dragenterEvent);
1468 }
1469 
setOndragenter(PassRefPtr<EventListener> eventListener)1470 void DOMWindow::setOndragenter(PassRefPtr<EventListener> eventListener)
1471 {
1472     setAttributeEventListener(eventNames().dragenterEvent, eventListener);
1473 }
1474 
ondragleave() const1475 EventListener* DOMWindow::ondragleave() const
1476 {
1477     return getAttributeEventListener(eventNames().dragleaveEvent);
1478 }
1479 
setOndragleave(PassRefPtr<EventListener> eventListener)1480 void DOMWindow::setOndragleave(PassRefPtr<EventListener> eventListener)
1481 {
1482     setAttributeEventListener(eventNames().dragleaveEvent, eventListener);
1483 }
1484 
ondragover() const1485 EventListener* DOMWindow::ondragover() const
1486 {
1487     return getAttributeEventListener(eventNames().dragoverEvent);
1488 }
1489 
setOndragover(PassRefPtr<EventListener> eventListener)1490 void DOMWindow::setOndragover(PassRefPtr<EventListener> eventListener)
1491 {
1492     setAttributeEventListener(eventNames().dragoverEvent, eventListener);
1493 }
1494 
ondragstart() const1495 EventListener* DOMWindow::ondragstart() const
1496 {
1497     return getAttributeEventListener(eventNames().dragstartEvent);
1498 }
1499 
setOndragstart(PassRefPtr<EventListener> eventListener)1500 void DOMWindow::setOndragstart(PassRefPtr<EventListener> eventListener)
1501 {
1502     setAttributeEventListener(eventNames().dragstartEvent, eventListener);
1503 }
1504 
ondrop() const1505 EventListener* DOMWindow::ondrop() const
1506 {
1507     return getAttributeEventListener(eventNames().dropEvent);
1508 }
1509 
setOndrop(PassRefPtr<EventListener> eventListener)1510 void DOMWindow::setOndrop(PassRefPtr<EventListener> eventListener)
1511 {
1512     setAttributeEventListener(eventNames().dropEvent, eventListener);
1513 }
1514 
onerror() const1515 EventListener* DOMWindow::onerror() const
1516 {
1517     return getAttributeEventListener(eventNames().errorEvent);
1518 }
1519 
setOnerror(PassRefPtr<EventListener> eventListener)1520 void DOMWindow::setOnerror(PassRefPtr<EventListener> eventListener)
1521 {
1522     setAttributeEventListener(eventNames().errorEvent, eventListener);
1523 }
1524 
onfocus() const1525 EventListener* DOMWindow::onfocus() const
1526 {
1527     return getAttributeEventListener(eventNames().focusEvent);
1528 }
1529 
setOnfocus(PassRefPtr<EventListener> eventListener)1530 void DOMWindow::setOnfocus(PassRefPtr<EventListener> eventListener)
1531 {
1532     setAttributeEventListener(eventNames().focusEvent, eventListener);
1533 }
1534 
onkeydown() const1535 EventListener* DOMWindow::onkeydown() const
1536 {
1537     return getAttributeEventListener(eventNames().keydownEvent);
1538 }
1539 
setOnkeydown(PassRefPtr<EventListener> eventListener)1540 void DOMWindow::setOnkeydown(PassRefPtr<EventListener> eventListener)
1541 {
1542     setAttributeEventListener(eventNames().keydownEvent, eventListener);
1543 }
1544 
onkeypress() const1545 EventListener* DOMWindow::onkeypress() const
1546 {
1547     return getAttributeEventListener(eventNames().keypressEvent);
1548 }
1549 
setOnkeypress(PassRefPtr<EventListener> eventListener)1550 void DOMWindow::setOnkeypress(PassRefPtr<EventListener> eventListener)
1551 {
1552     setAttributeEventListener(eventNames().keypressEvent, eventListener);
1553 }
1554 
onkeyup() const1555 EventListener* DOMWindow::onkeyup() const
1556 {
1557     return getAttributeEventListener(eventNames().keyupEvent);
1558 }
1559 
setOnkeyup(PassRefPtr<EventListener> eventListener)1560 void DOMWindow::setOnkeyup(PassRefPtr<EventListener> eventListener)
1561 {
1562     setAttributeEventListener(eventNames().keyupEvent, eventListener);
1563 }
1564 
onload() const1565 EventListener* DOMWindow::onload() const
1566 {
1567     return getAttributeEventListener(eventNames().loadEvent);
1568 }
1569 
setOnload(PassRefPtr<EventListener> eventListener)1570 void DOMWindow::setOnload(PassRefPtr<EventListener> eventListener)
1571 {
1572     setAttributeEventListener(eventNames().loadEvent, eventListener);
1573 }
1574 
onmousedown() const1575 EventListener* DOMWindow::onmousedown() const
1576 {
1577     return getAttributeEventListener(eventNames().mousedownEvent);
1578 }
1579 
setOnmousedown(PassRefPtr<EventListener> eventListener)1580 void DOMWindow::setOnmousedown(PassRefPtr<EventListener> eventListener)
1581 {
1582     setAttributeEventListener(eventNames().mousedownEvent, eventListener);
1583 }
1584 
onmousemove() const1585 EventListener* DOMWindow::onmousemove() const
1586 {
1587     return getAttributeEventListener(eventNames().mousemoveEvent);
1588 }
1589 
setOnmousemove(PassRefPtr<EventListener> eventListener)1590 void DOMWindow::setOnmousemove(PassRefPtr<EventListener> eventListener)
1591 {
1592     setAttributeEventListener(eventNames().mousemoveEvent, eventListener);
1593 }
1594 
onmouseout() const1595 EventListener* DOMWindow::onmouseout() const
1596 {
1597     return getAttributeEventListener(eventNames().mouseoutEvent);
1598 }
1599 
setOnmouseout(PassRefPtr<EventListener> eventListener)1600 void DOMWindow::setOnmouseout(PassRefPtr<EventListener> eventListener)
1601 {
1602     setAttributeEventListener(eventNames().mouseoutEvent, eventListener);
1603 }
1604 
onmouseover() const1605 EventListener* DOMWindow::onmouseover() const
1606 {
1607     return getAttributeEventListener(eventNames().mouseoverEvent);
1608 }
1609 
setOnmouseover(PassRefPtr<EventListener> eventListener)1610 void DOMWindow::setOnmouseover(PassRefPtr<EventListener> eventListener)
1611 {
1612     setAttributeEventListener(eventNames().mouseoverEvent, eventListener);
1613 }
1614 
onmouseup() const1615 EventListener* DOMWindow::onmouseup() const
1616 {
1617     return getAttributeEventListener(eventNames().mouseupEvent);
1618 }
1619 
setOnmouseup(PassRefPtr<EventListener> eventListener)1620 void DOMWindow::setOnmouseup(PassRefPtr<EventListener> eventListener)
1621 {
1622     setAttributeEventListener(eventNames().mouseupEvent, eventListener);
1623 }
1624 
onmousewheel() const1625 EventListener* DOMWindow::onmousewheel() const
1626 {
1627     return getAttributeEventListener(eventNames().mousewheelEvent);
1628 }
1629 
setOnmousewheel(PassRefPtr<EventListener> eventListener)1630 void DOMWindow::setOnmousewheel(PassRefPtr<EventListener> eventListener)
1631 {
1632     setAttributeEventListener(eventNames().mousewheelEvent, eventListener);
1633 }
1634 
onoffline() const1635 EventListener* DOMWindow::onoffline() const
1636 {
1637     return getAttributeEventListener(eventNames().offlineEvent);
1638 }
1639 
setOnoffline(PassRefPtr<EventListener> eventListener)1640 void DOMWindow::setOnoffline(PassRefPtr<EventListener> eventListener)
1641 {
1642     setAttributeEventListener(eventNames().offlineEvent, eventListener);
1643 }
1644 
ononline() const1645 EventListener* DOMWindow::ononline() const
1646 {
1647     return getAttributeEventListener(eventNames().onlineEvent);
1648 }
1649 
setOnonline(PassRefPtr<EventListener> eventListener)1650 void DOMWindow::setOnonline(PassRefPtr<EventListener> eventListener)
1651 {
1652     setAttributeEventListener(eventNames().onlineEvent, eventListener);
1653 }
1654 
onreset() const1655 EventListener* DOMWindow::onreset() const
1656 {
1657     return getAttributeEventListener(eventNames().resetEvent);
1658 }
1659 
setOnreset(PassRefPtr<EventListener> eventListener)1660 void DOMWindow::setOnreset(PassRefPtr<EventListener> eventListener)
1661 {
1662     setAttributeEventListener(eventNames().resetEvent, eventListener);
1663 }
1664 
onresize() const1665 EventListener* DOMWindow::onresize() const
1666 {
1667     return getAttributeEventListener(eventNames().resizeEvent);
1668 }
1669 
setOnresize(PassRefPtr<EventListener> eventListener)1670 void DOMWindow::setOnresize(PassRefPtr<EventListener> eventListener)
1671 {
1672     setAttributeEventListener(eventNames().resizeEvent, eventListener);
1673 }
1674 
onscroll() const1675 EventListener* DOMWindow::onscroll() const
1676 {
1677     return getAttributeEventListener(eventNames().scrollEvent);
1678 }
1679 
setOnscroll(PassRefPtr<EventListener> eventListener)1680 void DOMWindow::setOnscroll(PassRefPtr<EventListener> eventListener)
1681 {
1682     setAttributeEventListener(eventNames().scrollEvent, eventListener);
1683 }
1684 
onsearch() const1685 EventListener* DOMWindow::onsearch() const
1686 {
1687     return getAttributeEventListener(eventNames().searchEvent);
1688 }
1689 
setOnsearch(PassRefPtr<EventListener> eventListener)1690 void DOMWindow::setOnsearch(PassRefPtr<EventListener> eventListener)
1691 {
1692     setAttributeEventListener(eventNames().searchEvent, eventListener);
1693 }
1694 
onselect() const1695 EventListener* DOMWindow::onselect() const
1696 {
1697     return getAttributeEventListener(eventNames().selectEvent);
1698 }
1699 
setOnselect(PassRefPtr<EventListener> eventListener)1700 void DOMWindow::setOnselect(PassRefPtr<EventListener> eventListener)
1701 {
1702     setAttributeEventListener(eventNames().selectEvent, eventListener);
1703 }
1704 
onstorage() const1705 EventListener* DOMWindow::onstorage() const
1706 {
1707     return getAttributeEventListener(eventNames().storageEvent);
1708 }
1709 
setOnstorage(PassRefPtr<EventListener> eventListener)1710 void DOMWindow::setOnstorage(PassRefPtr<EventListener> eventListener)
1711 {
1712     setAttributeEventListener(eventNames().storageEvent, eventListener);
1713 }
1714 
onsubmit() const1715 EventListener* DOMWindow::onsubmit() const
1716 {
1717     return getAttributeEventListener(eventNames().submitEvent);
1718 }
1719 
setOnsubmit(PassRefPtr<EventListener> eventListener)1720 void DOMWindow::setOnsubmit(PassRefPtr<EventListener> eventListener)
1721 {
1722     setAttributeEventListener(eventNames().submitEvent, eventListener);
1723 }
1724 
onunload() const1725 EventListener* DOMWindow::onunload() const
1726 {
1727     return getAttributeEventListener(eventNames().unloadEvent);
1728 }
1729 
setOnunload(PassRefPtr<EventListener> eventListener)1730 void DOMWindow::setOnunload(PassRefPtr<EventListener> eventListener)
1731 {
1732     setAttributeEventListener(eventNames().unloadEvent, eventListener);
1733 }
1734 
onbeforeunload() const1735 EventListener* DOMWindow::onbeforeunload() const
1736 {
1737     return getAttributeEventListener(eventNames().beforeunloadEvent);
1738 }
1739 
setOnbeforeunload(PassRefPtr<EventListener> eventListener)1740 void DOMWindow::setOnbeforeunload(PassRefPtr<EventListener> eventListener)
1741 {
1742     setAttributeEventListener(eventNames().beforeunloadEvent, eventListener);
1743 }
1744 
onwebkitanimationstart() const1745 EventListener* DOMWindow::onwebkitanimationstart() const
1746 {
1747     return getAttributeEventListener(eventNames().webkitAnimationStartEvent);
1748 }
1749 
setOnwebkitanimationstart(PassRefPtr<EventListener> eventListener)1750 void DOMWindow::setOnwebkitanimationstart(PassRefPtr<EventListener> eventListener)
1751 {
1752     setAttributeEventListener(eventNames().webkitAnimationStartEvent, eventListener);
1753 }
1754 
onwebkitanimationiteration() const1755 EventListener* DOMWindow::onwebkitanimationiteration() const
1756 {
1757     return getAttributeEventListener(eventNames().webkitAnimationIterationEvent);
1758 }
1759 
setOnwebkitanimationiteration(PassRefPtr<EventListener> eventListener)1760 void DOMWindow::setOnwebkitanimationiteration(PassRefPtr<EventListener> eventListener)
1761 {
1762     setAttributeEventListener(eventNames().webkitAnimationIterationEvent, eventListener);
1763 }
1764 
onwebkitanimationend() const1765 EventListener* DOMWindow::onwebkitanimationend() const
1766 {
1767     return getAttributeEventListener(eventNames().webkitAnimationEndEvent);
1768 }
1769 
setOnwebkitanimationend(PassRefPtr<EventListener> eventListener)1770 void DOMWindow::setOnwebkitanimationend(PassRefPtr<EventListener> eventListener)
1771 {
1772     setAttributeEventListener(eventNames().webkitAnimationEndEvent, eventListener);
1773 }
1774 
onwebkittransitionend() const1775 EventListener* DOMWindow::onwebkittransitionend() const
1776 {
1777     return getAttributeEventListener(eventNames().webkitTransitionEndEvent);
1778 }
1779 
setOnwebkittransitionend(PassRefPtr<EventListener> eventListener)1780 void DOMWindow::setOnwebkittransitionend(PassRefPtr<EventListener> eventListener)
1781 {
1782     setAttributeEventListener(eventNames().webkitTransitionEndEvent, eventListener);
1783 }
1784 
oncanplay() const1785 EventListener* DOMWindow::oncanplay() const
1786 {
1787     return getAttributeEventListener(eventNames().canplayEvent);
1788 }
1789 
setOncanplay(PassRefPtr<EventListener> eventListener)1790 void DOMWindow::setOncanplay(PassRefPtr<EventListener> eventListener)
1791 {
1792     setAttributeEventListener(eventNames().canplayEvent, eventListener);
1793 }
1794 
oncanplaythrough() const1795 EventListener* DOMWindow::oncanplaythrough() const
1796 {
1797     return getAttributeEventListener(eventNames().canplaythroughEvent);
1798 }
1799 
setOncanplaythrough(PassRefPtr<EventListener> eventListener)1800 void DOMWindow::setOncanplaythrough(PassRefPtr<EventListener> eventListener)
1801 {
1802     setAttributeEventListener(eventNames().canplaythroughEvent, eventListener);
1803 }
1804 
ondurationchange() const1805 EventListener* DOMWindow::ondurationchange() const
1806 {
1807     return getAttributeEventListener(eventNames().durationchangeEvent);
1808 }
1809 
setOndurationchange(PassRefPtr<EventListener> eventListener)1810 void DOMWindow::setOndurationchange(PassRefPtr<EventListener> eventListener)
1811 {
1812     setAttributeEventListener(eventNames().durationchangeEvent, eventListener);
1813 }
1814 
onemptied() const1815 EventListener* DOMWindow::onemptied() const
1816 {
1817     return getAttributeEventListener(eventNames().emptiedEvent);
1818 }
1819 
setOnemptied(PassRefPtr<EventListener> eventListener)1820 void DOMWindow::setOnemptied(PassRefPtr<EventListener> eventListener)
1821 {
1822     setAttributeEventListener(eventNames().emptiedEvent, eventListener);
1823 }
1824 
onended() const1825 EventListener* DOMWindow::onended() const
1826 {
1827     return getAttributeEventListener(eventNames().endedEvent);
1828 }
1829 
setOnended(PassRefPtr<EventListener> eventListener)1830 void DOMWindow::setOnended(PassRefPtr<EventListener> eventListener)
1831 {
1832     setAttributeEventListener(eventNames().endedEvent, eventListener);
1833 }
1834 
onloadeddata() const1835 EventListener* DOMWindow::onloadeddata() const
1836 {
1837     return getAttributeEventListener(eventNames().loadeddataEvent);
1838 }
1839 
setOnloadeddata(PassRefPtr<EventListener> eventListener)1840 void DOMWindow::setOnloadeddata(PassRefPtr<EventListener> eventListener)
1841 {
1842     setAttributeEventListener(eventNames().loadeddataEvent, eventListener);
1843 }
1844 
onloadedmetadata() const1845 EventListener* DOMWindow::onloadedmetadata() const
1846 {
1847     return getAttributeEventListener(eventNames().loadedmetadataEvent);
1848 }
1849 
setOnloadedmetadata(PassRefPtr<EventListener> eventListener)1850 void DOMWindow::setOnloadedmetadata(PassRefPtr<EventListener> eventListener)
1851 {
1852     setAttributeEventListener(eventNames().loadedmetadataEvent, eventListener);
1853 }
1854 
onpause() const1855 EventListener* DOMWindow::onpause() const
1856 {
1857     return getAttributeEventListener(eventNames().pauseEvent);
1858 }
1859 
setOnpause(PassRefPtr<EventListener> eventListener)1860 void DOMWindow::setOnpause(PassRefPtr<EventListener> eventListener)
1861 {
1862     setAttributeEventListener(eventNames().pauseEvent, eventListener);
1863 }
1864 
onplay() const1865 EventListener* DOMWindow::onplay() const
1866 {
1867     return getAttributeEventListener(eventNames().playEvent);
1868 }
1869 
setOnplay(PassRefPtr<EventListener> eventListener)1870 void DOMWindow::setOnplay(PassRefPtr<EventListener> eventListener)
1871 {
1872     setAttributeEventListener(eventNames().playEvent, eventListener);
1873 }
1874 
onplaying() const1875 EventListener* DOMWindow::onplaying() const
1876 {
1877     return getAttributeEventListener(eventNames().playingEvent);
1878 }
1879 
setOnplaying(PassRefPtr<EventListener> eventListener)1880 void DOMWindow::setOnplaying(PassRefPtr<EventListener> eventListener)
1881 {
1882     setAttributeEventListener(eventNames().playingEvent, eventListener);
1883 }
1884 
onratechange() const1885 EventListener* DOMWindow::onratechange() const
1886 {
1887     return getAttributeEventListener(eventNames().ratechangeEvent);
1888 }
1889 
setOnratechange(PassRefPtr<EventListener> eventListener)1890 void DOMWindow::setOnratechange(PassRefPtr<EventListener> eventListener)
1891 {
1892     setAttributeEventListener(eventNames().ratechangeEvent, eventListener);
1893 }
1894 
onseeked() const1895 EventListener* DOMWindow::onseeked() const
1896 {
1897     return getAttributeEventListener(eventNames().seekedEvent);
1898 }
1899 
setOnseeked(PassRefPtr<EventListener> eventListener)1900 void DOMWindow::setOnseeked(PassRefPtr<EventListener> eventListener)
1901 {
1902     setAttributeEventListener(eventNames().seekedEvent, eventListener);
1903 }
1904 
onseeking() const1905 EventListener* DOMWindow::onseeking() const
1906 {
1907     return getAttributeEventListener(eventNames().seekingEvent);
1908 }
1909 
setOnseeking(PassRefPtr<EventListener> eventListener)1910 void DOMWindow::setOnseeking(PassRefPtr<EventListener> eventListener)
1911 {
1912     setAttributeEventListener(eventNames().seekingEvent, eventListener);
1913 }
1914 
ontimeupdate() const1915 EventListener* DOMWindow::ontimeupdate() const
1916 {
1917     return getAttributeEventListener(eventNames().timeupdateEvent);
1918 }
1919 
setOntimeupdate(PassRefPtr<EventListener> eventListener)1920 void DOMWindow::setOntimeupdate(PassRefPtr<EventListener> eventListener)
1921 {
1922     setAttributeEventListener(eventNames().timeupdateEvent, eventListener);
1923 }
1924 
onvolumechange() const1925 EventListener* DOMWindow::onvolumechange() const
1926 {
1927     return getAttributeEventListener(eventNames().volumechangeEvent);
1928 }
1929 
setOnvolumechange(PassRefPtr<EventListener> eventListener)1930 void DOMWindow::setOnvolumechange(PassRefPtr<EventListener> eventListener)
1931 {
1932     setAttributeEventListener(eventNames().volumechangeEvent, eventListener);
1933 }
1934 
onwaiting() const1935 EventListener* DOMWindow::onwaiting() const
1936 {
1937     return getAttributeEventListener(eventNames().waitingEvent);
1938 }
1939 
setOnwaiting(PassRefPtr<EventListener> eventListener)1940 void DOMWindow::setOnwaiting(PassRefPtr<EventListener> eventListener)
1941 {
1942     setAttributeEventListener(eventNames().waitingEvent, eventListener);
1943 }
1944 
onloadstart() const1945 EventListener* DOMWindow::onloadstart() const
1946 {
1947     return getAttributeEventListener(eventNames().loadstartEvent);
1948 }
1949 
setOnloadstart(PassRefPtr<EventListener> eventListener)1950 void DOMWindow::setOnloadstart(PassRefPtr<EventListener> eventListener)
1951 {
1952     setAttributeEventListener(eventNames().loadstartEvent, eventListener);
1953 }
1954 
onprogress() const1955 EventListener* DOMWindow::onprogress() const
1956 {
1957     return getAttributeEventListener(eventNames().progressEvent);
1958 }
1959 
setOnprogress(PassRefPtr<EventListener> eventListener)1960 void DOMWindow::setOnprogress(PassRefPtr<EventListener> eventListener)
1961 {
1962     setAttributeEventListener(eventNames().progressEvent, eventListener);
1963 }
1964 
onstalled() const1965 EventListener* DOMWindow::onstalled() const
1966 {
1967     return getAttributeEventListener(eventNames().stalledEvent);
1968 }
1969 
setOnstalled(PassRefPtr<EventListener> eventListener)1970 void DOMWindow::setOnstalled(PassRefPtr<EventListener> eventListener)
1971 {
1972     setAttributeEventListener(eventNames().stalledEvent, eventListener);
1973 }
1974 
onsuspend() const1975 EventListener* DOMWindow::onsuspend() const
1976 {
1977     return getAttributeEventListener(eventNames().suspendEvent);
1978 }
1979 
setOnsuspend(PassRefPtr<EventListener> eventListener)1980 void DOMWindow::setOnsuspend(PassRefPtr<EventListener> eventListener)
1981 {
1982     setAttributeEventListener(eventNames().suspendEvent, eventListener);
1983 }
1984 
oninput() const1985 EventListener* DOMWindow::oninput() const
1986 {
1987     return getAttributeEventListener(eventNames().inputEvent);
1988 }
1989 
setOninput(PassRefPtr<EventListener> eventListener)1990 void DOMWindow::setOninput(PassRefPtr<EventListener> eventListener)
1991 {
1992     setAttributeEventListener(eventNames().inputEvent, eventListener);
1993 }
1994 
onmessage() const1995 EventListener* DOMWindow::onmessage() const
1996 {
1997     return getAttributeEventListener(eventNames().messageEvent);
1998 }
1999 
setOnmessage(PassRefPtr<EventListener> eventListener)2000 void DOMWindow::setOnmessage(PassRefPtr<EventListener> eventListener)
2001 {
2002     setAttributeEventListener(eventNames().messageEvent, eventListener);
2003 }
2004 
oncontextmenu() const2005 EventListener* DOMWindow::oncontextmenu() const
2006 {
2007     return getAttributeEventListener(eventNames().contextmenuEvent);
2008 }
2009 
setOncontextmenu(PassRefPtr<EventListener> eventListener)2010 void DOMWindow::setOncontextmenu(PassRefPtr<EventListener> eventListener)
2011 {
2012     setAttributeEventListener(eventNames().contextmenuEvent, eventListener);
2013 }
2014 
captureEvents()2015 void DOMWindow::captureEvents()
2016 {
2017     // Not implemented.
2018 }
2019 
releaseEvents()2020 void DOMWindow::releaseEvents()
2021 {
2022     // Not implemented.
2023 }
2024 
2025 #if ENABLE(TOUCH_EVENTS) // Android
ontouchstart() const2026 EventListener* DOMWindow::ontouchstart() const
2027 {
2028     return getAttributeEventListener(eventNames().touchstartEvent);
2029 }
2030 
setOntouchstart(PassRefPtr<EventListener> eventListener)2031 void DOMWindow::setOntouchstart(PassRefPtr<EventListener> eventListener)
2032 {
2033     setAttributeEventListener(eventNames().touchstartEvent, eventListener);
2034 }
2035 
ontouchend() const2036 EventListener* DOMWindow::ontouchend() const
2037 {
2038     return getAttributeEventListener(eventNames().touchendEvent);
2039 }
2040 
setOntouchend(PassRefPtr<EventListener> eventListener)2041 void DOMWindow::setOntouchend(PassRefPtr<EventListener> eventListener)
2042 {
2043     setAttributeEventListener(eventNames().touchendEvent, eventListener);
2044 }
2045 
ontouchmove() const2046 EventListener* DOMWindow::ontouchmove() const
2047 {
2048     return getAttributeEventListener(eventNames().touchmoveEvent);
2049 }
2050 
setOntouchmove(PassRefPtr<EventListener> eventListener)2051 void DOMWindow::setOntouchmove(PassRefPtr<EventListener> eventListener)
2052 {
2053     setAttributeEventListener(eventNames().touchmoveEvent, eventListener);
2054 }
2055 
ontouchcancel() const2056 EventListener* DOMWindow::ontouchcancel() const
2057 {
2058     return getAttributeEventListener(eventNames().touchcancelEvent);
2059 }
2060 
setOntouchcancel(PassRefPtr<EventListener> eventListener)2061 void DOMWindow::setOntouchcancel(PassRefPtr<EventListener> eventListener)
2062 {
2063     setAttributeEventListener(eventNames().touchcancelEvent, eventListener);
2064 }
2065 #endif
2066 
2067 } // namespace WebCore
2068