Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp

Issue 2783723002: Keep track in the browser of which frames have onunload and onbeforeunload handlers. (Closed)
Patch Set: fix content_browsertests with plznavigate and also remove now unnecessary unloadcontroller change Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
265 unsigned LocalDOMWindow::pendingUnloadEventListeners() const { 257 unsigned LocalDOMWindow::pendingUnloadEventListeners() const {
266 return windowsWithUnloadEventListeners().count( 258 return windowsWithUnloadEventListeners().count(
267 const_cast<LocalDOMWindow*>(this)); 259 const_cast<LocalDOMWindow*>(this));
268 } 260 }
269 261
270 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) { 262 bool LocalDOMWindow::allowPopUp(LocalFrame& firstFrame) {
271 if (UserGestureIndicator::utilizeUserGesture()) 263 if (UserGestureIndicator::utilizeUserGesture())
272 return true; 264 return true;
273 265
274 Settings* settings = firstFrame.settings(); 266 Settings* settings = firstFrame.settings();
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 1418
1427 for (auto& it : m_eventListenerObservers) { 1419 for (auto& it : m_eventListenerObservers) {
1428 it->didAddEventListener(this, eventType); 1420 it->didAddEventListener(this, eventType);
1429 } 1421 }
1430 1422
1431 if (eventType == EventTypeNames::unload) { 1423 if (eventType == EventTypeNames::unload) {
1432 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered); 1424 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered);
1433 addUnloadEventListener(this); 1425 addUnloadEventListener(this);
1434 } else if (eventType == EventTypeNames::beforeunload) { 1426 } else if (eventType == EventTypeNames::beforeunload) {
1435 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered); 1427 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered);
1436 if (allowsBeforeUnloadListeners(this)) { 1428 addBeforeUnloadEventListener(this);
1437 // This is confusingly named. It doesn't actually add the listener. It 1429 if (frame() && !frame()->isMainFrame())
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.
dcheng 2017/03/29 23:03:46 Nit: please keep this comment.
jam 2017/03/30 14:53:23 Done.
1441 addBeforeUnloadEventListener(this);
1442 } else {
1443 // Subframes return false from allowsBeforeUnloadListeners.
1444 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegistered); 1430 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegistered);
1445 }
1446 } 1431 }
1447 } 1432 }
1448 1433
1449 void LocalDOMWindow::removedEventListener( 1434 void LocalDOMWindow::removedEventListener(
1450 const AtomicString& eventType, 1435 const AtomicString& eventType,
1451 const RegisteredEventListener& registeredListener) { 1436 const RegisteredEventListener& registeredListener) {
1452 DOMWindow::removedEventListener(eventType, registeredListener); 1437 DOMWindow::removedEventListener(eventType, registeredListener);
1453 if (frame() && frame()->page()) 1438 if (frame() && frame()->page())
1454 frame()->page()->eventHandlerRegistry().didRemoveEventHandler( 1439 frame()->page()->eventHandlerRegistry().didRemoveEventHandler(
1455 *this, eventType, registeredListener.options()); 1440 *this, eventType, registeredListener.options());
1456 1441
1457 for (auto& it : m_eventListenerObservers) { 1442 for (auto& it : m_eventListenerObservers) {
1458 it->didRemoveEventListener(this, eventType); 1443 it->didRemoveEventListener(this, eventType);
1459 } 1444 }
1460 1445
1461 if (eventType == EventTypeNames::unload) { 1446 if (eventType == EventTypeNames::unload) {
1462 removeUnloadEventListener(this); 1447 removeUnloadEventListener(this);
1463 } else if (eventType == EventTypeNames::beforeunload && 1448 } else if (eventType == EventTypeNames::beforeunload) {
1464 allowsBeforeUnloadListeners(this)) {
1465 removeBeforeUnloadEventListener(this); 1449 removeBeforeUnloadEventListener(this);
dcheng 2017/03/29 23:03:46 This would ideally be commented too.
jam 2017/03/30 14:53:23 all 4 would need comment, to be consistent, or per
1466 } 1450 }
1467 } 1451 }
1468 1452
1469 void LocalDOMWindow::warnUnusedPreloads(TimerBase* base) { 1453 void LocalDOMWindow::warnUnusedPreloads(TimerBase* base) {
1470 if (frame() && frame()->loader().documentLoader()) { 1454 if (frame() && frame()->loader().documentLoader()) {
1471 ResourceFetcher* fetcher = frame()->loader().documentLoader()->fetcher(); 1455 ResourceFetcher* fetcher = frame()->loader().documentLoader()->fetcher();
1472 DCHECK(fetcher); 1456 DCHECK(fetcher);
1473 if (fetcher->countPreloads()) 1457 if (fetcher->countPreloads())
1474 fetcher->warnUnusedPreloads(); 1458 fetcher->warnUnusedPreloads();
1475 } 1459 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 DOMWindow::trace(visitor); 1643 DOMWindow::trace(visitor);
1660 Supplementable<LocalDOMWindow>::trace(visitor); 1644 Supplementable<LocalDOMWindow>::trace(visitor);
1661 } 1645 }
1662 1646
1663 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) { 1647 DEFINE_TRACE_WRAPPERS(LocalDOMWindow) {
1664 visitor->traceWrappers(m_customElements); 1648 visitor->traceWrappers(m_customElements);
1665 DOMWindow::traceWrappers(visitor); 1649 DOMWindow::traceWrappers(visitor);
1666 } 1650 }
1667 1651
1668 } // namespace blink 1652 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698