| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 typedef HashCountedSet<LocalDOMWindow*> DOMWindowSet; | 107 typedef HashCountedSet<LocalDOMWindow*> DOMWindowSet; |
| 108 | 108 |
| 109 static DOMWindowSet& windowsWithUnloadEventListeners() | 109 static DOMWindowSet& windowsWithUnloadEventListeners() |
| 110 { | 110 { |
| 111 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithUnloadEventListeners, ()); | 111 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithUnloadEventListeners, ()); |
| 112 return windowsWithUnloadEventListeners; | 112 return windowsWithUnloadEventListeners; |
| 113 } | 113 } |
| 114 | 114 |
| 115 static DOMWindowSet& windowsWithBeforeUnloadEventListeners() | |
| 116 { | |
| 117 DEFINE_STATIC_LOCAL(DOMWindowSet, windowsWithBeforeUnloadEventListeners, ())
; | |
| 118 return windowsWithBeforeUnloadEventListeners; | |
| 119 } | |
| 120 | |
| 121 static void addUnloadEventListener(LocalDOMWindow* domWindow) | 115 static void addUnloadEventListener(LocalDOMWindow* domWindow) |
| 122 { | 116 { |
| 123 DOMWindowSet& set = windowsWithUnloadEventListeners(); | 117 DOMWindowSet& set = windowsWithUnloadEventListeners(); |
| 124 if (set.isEmpty()) | 118 if (set.isEmpty()) |
| 125 disableSuddenTermination(); | 119 disableSuddenTermination(); |
| 126 set.add(domWindow); | 120 set.add(domWindow); |
| 127 } | 121 } |
| 128 | 122 |
| 129 static void removeUnloadEventListener(LocalDOMWindow* domWindow) | 123 static void removeUnloadEventListener(LocalDOMWindow* domWindow) |
| 130 { | 124 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 141 { | 135 { |
| 142 DOMWindowSet& set = windowsWithUnloadEventListeners(); | 136 DOMWindowSet& set = windowsWithUnloadEventListeners(); |
| 143 DOMWindowSet::iterator it = set.find(domWindow); | 137 DOMWindowSet::iterator it = set.find(domWindow); |
| 144 if (it == set.end()) | 138 if (it == set.end()) |
| 145 return; | 139 return; |
| 146 set.removeAll(it); | 140 set.removeAll(it); |
| 147 if (set.isEmpty()) | 141 if (set.isEmpty()) |
| 148 enableSuddenTermination(); | 142 enableSuddenTermination(); |
| 149 } | 143 } |
| 150 | 144 |
| 151 static void addBeforeUnloadEventListener(LocalDOMWindow* domWindow) | |
| 152 { | |
| 153 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); | |
| 154 if (set.isEmpty()) | |
| 155 disableSuddenTermination(); | |
| 156 set.add(domWindow); | |
| 157 } | |
| 158 | |
| 159 static void removeBeforeUnloadEventListener(LocalDOMWindow* domWindow) | |
| 160 { | |
| 161 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); | |
| 162 DOMWindowSet::iterator it = set.find(domWindow); | |
| 163 if (it == set.end()) | |
| 164 return; | |
| 165 set.remove(it); | |
| 166 if (set.isEmpty()) | |
| 167 enableSuddenTermination(); | |
| 168 } | |
| 169 | |
| 170 static void removeAllBeforeUnloadEventListeners(LocalDOMWindow* domWindow) | |
| 171 { | |
| 172 DOMWindowSet& set = windowsWithBeforeUnloadEventListeners(); | |
| 173 DOMWindowSet::iterator it = set.find(domWindow); | |
| 174 if (it == set.end()) | |
| 175 return; | |
| 176 set.removeAll(it); | |
| 177 if (set.isEmpty()) | |
| 178 enableSuddenTermination(); | |
| 179 } | |
| 180 | |
| 181 static bool allowsBeforeUnloadListeners(LocalDOMWindow* window) | |
| 182 { | |
| 183 ASSERT_ARG(window, window); | |
| 184 return window->frame(); | |
| 185 } | |
| 186 | |
| 187 unsigned LocalDOMWindow::pendingUnloadEventListeners() const | 145 unsigned LocalDOMWindow::pendingUnloadEventListeners() const |
| 188 { | 146 { |
| 189 return windowsWithUnloadEventListeners().count(const_cast<LocalDOMWindow*>(t
his)); | 147 return windowsWithUnloadEventListeners().count(const_cast<LocalDOMWindow*>(t
his)); |
| 190 } | 148 } |
| 191 | 149 |
| 192 // This function: | 150 // This function: |
| 193 // 1) Validates the pending changes are not changing any value to NaN; in that c
ase keep original value. | 151 // 1) Validates the pending changes are not changing any value to NaN; in that c
ase keep original value. |
| 194 // 2) Constrains the window rect to the minimum window size and no bigger than t
he float rect's dimensions. | 152 // 2) Constrains the window rect to the minimum window size and no bigger than t
he float rect's dimensions. |
| 195 // 3) Constrains the window rect to within the top and left boundaries of the av
ailable screen rect. | 153 // 3) Constrains the window rect to within the top and left boundaries of the av
ailable screen rect. |
| 196 // 4) Constrains the window rect to within the bottom and right boundaries of th
e available screen rect. | 154 // 4) Constrains the window rect to within the bottom and right boundaries of th
e available screen rect. |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 m_frame->host()->eventHandlerRegistry().didAddEventHandler(*this, eventT
ype); | 806 m_frame->host()->eventHandlerRegistry().didAddEventHandler(*this, eventT
ype); |
| 849 | 807 |
| 850 if (Document* document = this->document()) | 808 if (Document* document = this->document()) |
| 851 document->addListenerTypeIfNeeded(eventType); | 809 document->addListenerTypeIfNeeded(eventType); |
| 852 | 810 |
| 853 lifecycleNotifier().notifyAddEventListener(this, eventType); | 811 lifecycleNotifier().notifyAddEventListener(this, eventType); |
| 854 | 812 |
| 855 if (eventType == EventTypeNames::unload) { | 813 if (eventType == EventTypeNames::unload) { |
| 856 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered); | 814 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered); |
| 857 addUnloadEventListener(this); | 815 addUnloadEventListener(this); |
| 858 } else if (eventType == EventTypeNames::beforeunload) { | |
| 859 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered
); | |
| 860 if (allowsBeforeUnloadListeners(this)) { | |
| 861 // This is confusingly named. It doesn't actually add the listener.
It just increments a count | |
| 862 // so that we know we have listeners registered for the purposes of
determining if we can | |
| 863 // fast terminate the renderer process. | |
| 864 addBeforeUnloadEventListener(this); | |
| 865 } else { | |
| 866 // Subframes return false from allowsBeforeUnloadListeners. | |
| 867 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegist
ered); | |
| 868 } | |
| 869 } | 816 } |
| 870 | |
| 871 return true; | 817 return true; |
| 872 } | 818 } |
| 873 | 819 |
| 874 bool LocalDOMWindow::removeEventListener(const AtomicString& eventType, PassRefP
tr<EventListener> listener, bool useCapture) | 820 bool LocalDOMWindow::removeEventListener(const AtomicString& eventType, PassRefP
tr<EventListener> listener, bool useCapture) |
| 875 { | 821 { |
| 876 if (!EventTarget::removeEventListener(eventType, listener, useCapture)) | 822 if (!EventTarget::removeEventListener(eventType, listener, useCapture)) |
| 877 return false; | 823 return false; |
| 878 | 824 |
| 879 if (m_frame && m_frame->host()) | 825 if (m_frame && m_frame->host()) |
| 880 m_frame->host()->eventHandlerRegistry().didRemoveEventHandler(*this, eve
ntType); | 826 m_frame->host()->eventHandlerRegistry().didRemoveEventHandler(*this, eve
ntType); |
| 881 | 827 |
| 882 lifecycleNotifier().notifyRemoveEventListener(this, eventType); | 828 lifecycleNotifier().notifyRemoveEventListener(this, eventType); |
| 883 | 829 |
| 884 if (eventType == EventTypeNames::unload) { | 830 if (eventType == EventTypeNames::unload) { |
| 885 removeUnloadEventListener(this); | 831 removeUnloadEventListener(this); |
| 886 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi
steners(this)) { | |
| 887 removeBeforeUnloadEventListener(this); | |
| 888 } | 832 } |
| 889 | 833 |
| 890 return true; | 834 return true; |
| 891 } | 835 } |
| 892 | 836 |
| 893 void LocalDOMWindow::dispatchLoadEvent() | 837 void LocalDOMWindow::dispatchLoadEvent() |
| 894 { | 838 { |
| 895 RefPtrWillBeRawPtr<Event> loadEvent(Event::create(EventTypeNames::load)); | 839 RefPtrWillBeRawPtr<Event> loadEvent(Event::create(EventTypeNames::load)); |
| 896 dispatchEvent(loadEvent, document()); | 840 dispatchEvent(loadEvent, document()); |
| 897 | 841 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 921 EventTarget::removeAllEventListeners(); | 865 EventTarget::removeAllEventListeners(); |
| 922 | 866 |
| 923 lifecycleNotifier().notifyRemoveAllEventListeners(this); | 867 lifecycleNotifier().notifyRemoveAllEventListeners(this); |
| 924 | 868 |
| 925 if (mode == DoBroadcastListenerRemoval) { | 869 if (mode == DoBroadcastListenerRemoval) { |
| 926 if (m_frame && m_frame->host()) | 870 if (m_frame && m_frame->host()) |
| 927 m_frame->host()->eventHandlerRegistry().didRemoveAllEventHandlers(*t
his); | 871 m_frame->host()->eventHandlerRegistry().didRemoveAllEventHandlers(*t
his); |
| 928 } | 872 } |
| 929 | 873 |
| 930 removeAllUnloadEventListeners(this); | 874 removeAllUnloadEventListeners(this); |
| 931 removeAllBeforeUnloadEventListeners(this); | |
| 932 } | 875 } |
| 933 | 876 |
| 934 void LocalDOMWindow::removeAllEventListeners() | 877 void LocalDOMWindow::removeAllEventListeners() |
| 935 { | 878 { |
| 936 removeAllEventListenersInternal(DoBroadcastListenerRemoval); | 879 removeAllEventListenersInternal(DoBroadcastListenerRemoval); |
| 937 } | 880 } |
| 938 | 881 |
| 939 void LocalDOMWindow::setLocation(const String& urlString, LocalDOMWindow* callin
gWindow, LocalDOMWindow* enteredWindow, SetLocationLocking locking) | 882 void LocalDOMWindow::setLocation(const String& urlString, LocalDOMWindow* callin
gWindow, LocalDOMWindow* enteredWindow, SetLocationLocking locking) |
| 940 { | 883 { |
| 941 // FIXME(sky): remove. | 884 // FIXME(sky): remove. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 visitor->trace(m_location); | 918 visitor->trace(m_location); |
| 976 visitor->trace(m_media); | 919 visitor->trace(m_media); |
| 977 visitor->trace(m_css); | 920 visitor->trace(m_css); |
| 978 visitor->trace(m_eventQueue); | 921 visitor->trace(m_eventQueue); |
| 979 WillBeHeapSupplementable<LocalDOMWindow>::trace(visitor); | 922 WillBeHeapSupplementable<LocalDOMWindow>::trace(visitor); |
| 980 EventTargetWithInlineData::trace(visitor); | 923 EventTargetWithInlineData::trace(visitor); |
| 981 LifecycleContext<LocalDOMWindow>::trace(visitor); | 924 LifecycleContext<LocalDOMWindow>::trace(visitor); |
| 982 } | 925 } |
| 983 | 926 |
| 984 } // namespace blink | 927 } // namespace blink |
| OLD | NEW |