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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 DOMWindowSet::iterator it = set.find(domWindow); | 247 DOMWindowSet::iterator it = set.find(domWindow); |
248 if (it == set.end()) | 248 if (it == set.end()) |
249 return; | 249 return; |
250 set.removeAll(it); | 250 set.removeAll(it); |
251 if (set.isEmpty()) { | 251 if (set.isEmpty()) { |
252 updateSuddenTerminationStatus(domWindow, false, | 252 updateSuddenTerminationStatus(domWindow, false, |
253 LocalFrameClient::BeforeUnloadHandler); | 253 LocalFrameClient::BeforeUnloadHandler); |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
| 257 static bool allowsBeforeUnloadListeners(LocalDOMWindow* window) { |
| 258 DCHECK(window); |
| 259 LocalFrame* frame = window->frame(); |
| 260 if (!frame) |
| 261 return false; |
| 262 return frame->isMainFrame(); |
| 263 } |
| 264 |
257 unsigned LocalDOMWindow::pendingUnloadEventListeners() const { | 265 unsigned LocalDOMWindow::pendingUnloadEventListeners() const { |
258 return windowsWithUnloadEventListeners().count( | 266 return windowsWithUnloadEventListeners().count( |
259 const_cast<LocalDOMWindow*>(this)); | 267 const_cast<LocalDOMWindow*>(this)); |
260 } | 268 } |
261 | 269 |
262 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) { | 270 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) { |
263 if (UserGestureIndicator::utilizeUserGesture()) | 271 if (UserGestureIndicator::utilizeUserGesture()) |
264 return true; | 272 return true; |
265 | 273 |
266 Settings* settings = firstFrame.settings(); | 274 Settings* settings = firstFrame.settings(); |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 | 1426 |
1419 for (auto& it : m_eventListenerObservers) { | 1427 for (auto& it : m_eventListenerObservers) { |
1420 it->didAddEventListener(this, eventType); | 1428 it->didAddEventListener(this, eventType); |
1421 } | 1429 } |
1422 | 1430 |
1423 if (eventType == EventTypeNames::unload) { | 1431 if (eventType == EventTypeNames::unload) { |
1424 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered); | 1432 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered); |
1425 addUnloadEventListener(this); | 1433 addUnloadEventListener(this); |
1426 } else if (eventType == EventTypeNames::beforeunload) { | 1434 } else if (eventType == EventTypeNames::beforeunload) { |
1427 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered); | 1435 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered); |
1428 addBeforeUnloadEventListener(this); | 1436 if (allowsBeforeUnloadListeners(this)) { |
1429 if (frame() && !frame()->isMainFrame()) | 1437 // This is confusingly named. It doesn't actually add the listener. It |
| 1438 // just increments a count so that we know we have listeners registered |
| 1439 // for the purposes of determining if we can fast terminate the renderer |
| 1440 // process. |
| 1441 addBeforeUnloadEventListener(this); |
| 1442 } else { |
| 1443 // Subframes return false from allowsBeforeUnloadListeners. |
1430 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegistered); | 1444 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegistered); |
| 1445 } |
1431 } | 1446 } |
1432 } | 1447 } |
1433 | 1448 |
1434 void LocalDOMWindow::removedEventListener( | 1449 void LocalDOMWindow::removedEventListener( |
1435 const AtomicString& eventType, | 1450 const AtomicString& eventType, |
1436 const RegisteredEventListener& registeredListener) { | 1451 const RegisteredEventListener& registeredListener) { |
1437 DOMWindow::removedEventListener(eventType, registeredListener); | 1452 DOMWindow::removedEventListener(eventType, registeredListener); |
1438 if (frame() && frame()->page()) | 1453 if (frame() && frame()->page()) |
1439 frame()->page()->eventHandlerRegistry().didRemoveEventHandler( | 1454 frame()->page()->eventHandlerRegistry().didRemoveEventHandler( |
1440 *this, eventType, registeredListener.options()); | 1455 *this, eventType, registeredListener.options()); |
1441 | 1456 |
1442 for (auto& it : m_eventListenerObservers) { | 1457 for (auto& it : m_eventListenerObservers) { |
1443 it->didRemoveEventListener(this, eventType); | 1458 it->didRemoveEventListener(this, eventType); |
1444 } | 1459 } |
1445 | 1460 |
1446 if (eventType == EventTypeNames::unload) { | 1461 if (eventType == EventTypeNames::unload) { |
1447 removeUnloadEventListener(this); | 1462 removeUnloadEventListener(this); |
1448 } else if (eventType == EventTypeNames::beforeunload) { | 1463 } else if (eventType == EventTypeNames::beforeunload && |
| 1464 allowsBeforeUnloadListeners(this)) { |
1449 removeBeforeUnloadEventListener(this); | 1465 removeBeforeUnloadEventListener(this); |
1450 } | 1466 } |
1451 } | 1467 } |
1452 | 1468 |
1453 void LocalDOMWindow::warnUnusedPreloads(TimerBase* base) { | 1469 void LocalDOMWindow::warnUnusedPreloads(TimerBase* base) { |
1454 if (frame() && frame()->loader().documentLoader()) { | 1470 if (frame() && frame()->loader().documentLoader()) { |
1455 ResourceFetcher* fetcher = frame()->loader().documentLoader()->fetcher(); | 1471 ResourceFetcher* fetcher = frame()->loader().documentLoader()->fetcher(); |
1456 DCHECK(fetcher); | 1472 DCHECK(fetcher); |
1457 if (fetcher->countPreloads()) | 1473 if (fetcher->countPreloads()) |
1458 fetcher->warnUnusedPreloads(); | 1474 fetcher->warnUnusedPreloads(); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 DOMWindow::trace(visitor); | 1659 DOMWindow::trace(visitor); |
1644 Supplementable<LocalDOMWindow>::trace(visitor); | 1660 Supplementable<LocalDOMWindow>::trace(visitor); |
1645 } | 1661 } |
1646 | 1662 |
1647 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { | 1663 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { |
1648 visitor->traceWrappers(m_customElements); | 1664 visitor->traceWrappers(m_customElements); |
1649 DOMWindow::traceWrappers(visitor); | 1665 DOMWindow::traceWrappers(visitor); |
1650 } | 1666 } |
1651 | 1667 |
1652 } // namespace blink | 1668 } // namespace blink |
OLD | NEW |