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

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

Issue 1942723004: Change EventTarget callback APIs for add/RemoveEventListenerInternal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gypi Created 4 years, 7 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 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 document->cancelIdleCallback(id); 1290 document->cancelIdleCallback(id);
1291 } 1291 }
1292 1292
1293 CustomElementsRegistry* LocalDOMWindow::customElements() const 1293 CustomElementsRegistry* LocalDOMWindow::customElements() const
1294 { 1294 {
1295 if (!m_customElements) 1295 if (!m_customElements)
1296 m_customElements = CustomElementsRegistry::create(); 1296 m_customElements = CustomElementsRegistry::create();
1297 return m_customElements.get(); 1297 return m_customElements.get();
1298 } 1298 }
1299 1299
1300 bool LocalDOMWindow::addEventListenerInternal(const AtomicString& eventType, Eve ntListener* listener, const EventListenerOptions& options) 1300 void LocalDOMWindow::addedEventListener(const AtomicString& eventType, const Reg isteredEventListener& registeredListener)
1301 { 1301 {
1302 if (!EventTarget::addEventListenerInternal(eventType, listener, options)) 1302 DOMWindow::addedEventListener(eventType, registeredListener);
1303 return false; 1303 if (frame() && frame()->host())
1304 frame()->host()->eventHandlerRegistry().didAddEventHandler(*this, eventT ype, registeredListener.options());
1304 1305
1305 if (frame() && frame()->host()) 1306 if (Document* document = this->document())
1306 frame()->host()->eventHandlerRegistry().didAddEventHandler(*this, eventT ype, options);
1307
1308 if (Document* document = this->document()) {
1309 document->addListenerTypeIfNeeded(eventType); 1307 document->addListenerTypeIfNeeded(eventType);
1310 }
1311 1308
1312 notifyAddEventListener(this, eventType); 1309 notifyAddEventListener(this, eventType);
1313 1310
1314 if (eventType == EventTypeNames::unload) { 1311 if (eventType == EventTypeNames::unload) {
1315 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered); 1312 UseCounter::count(document(), UseCounter::DocumentUnloadRegistered);
1316 addUnloadEventListener(this); 1313 addUnloadEventListener(this);
1317 } else if (eventType == EventTypeNames::beforeunload) { 1314 } else if (eventType == EventTypeNames::beforeunload) {
1318 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered ); 1315 UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered );
1319 if (allowsBeforeUnloadListeners(this)) { 1316 if (allowsBeforeUnloadListeners(this)) {
1320 // This is confusingly named. It doesn't actually add the listener. It just increments a count 1317 // This is confusingly named. It doesn't actually add the listener. It just increments a count
1321 // so that we know we have listeners registered for the purposes of determining if we can 1318 // so that we know we have listeners registered for the purposes of determining if we can
1322 // fast terminate the renderer process. 1319 // fast terminate the renderer process.
1323 addBeforeUnloadEventListener(this); 1320 addBeforeUnloadEventListener(this);
1324 } else { 1321 } else {
1325 // Subframes return false from allowsBeforeUnloadListeners. 1322 // Subframes return false from allowsBeforeUnloadListeners.
1326 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegist ered); 1323 UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegist ered);
1327 } 1324 }
1328 } 1325 }
1329
1330 return true;
1331 } 1326 }
1332 1327
1333 bool LocalDOMWindow::removeEventListenerInternal(const AtomicString& eventType, EventListener* listener, const EventListenerOptions& options) 1328 void LocalDOMWindow::removedEventListener(const AtomicString& eventType, const R egisteredEventListener& registeredListener)
1334 { 1329 {
1335 if (!EventTarget::removeEventListenerInternal(eventType, listener, options)) 1330 DOMWindow::removedEventListener(eventType, registeredListener);
1336 return false;
1337
1338 if (frame() && frame()->host()) 1331 if (frame() && frame()->host())
1339 frame()->host()->eventHandlerRegistry().didRemoveEventHandler(*this, eve ntType, options); 1332 frame()->host()->eventHandlerRegistry().didRemoveEventHandler(*this, eve ntType, registeredListener.options());
1340 1333
1341 notifyRemoveEventListener(this, eventType); 1334 notifyRemoveEventListener(this, eventType);
1342 1335
1343 if (eventType == EventTypeNames::unload) { 1336 if (eventType == EventTypeNames::unload) {
1344 removeUnloadEventListener(this); 1337 removeUnloadEventListener(this);
1345 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi steners(this)) { 1338 } else if (eventType == EventTypeNames::beforeunload && allowsBeforeUnloadLi steners(this)) {
1346 removeBeforeUnloadEventListener(this); 1339 removeBeforeUnloadEventListener(this);
1347 } 1340 }
1348
1349 return true;
1350 } 1341 }
1351 1342
1352 void LocalDOMWindow::dispatchLoadEvent() 1343 void LocalDOMWindow::dispatchLoadEvent()
1353 { 1344 {
1354 Event* loadEvent(Event::create(EventTypeNames::load)); 1345 Event* loadEvent(Event::create(EventTypeNames::load));
1355 if (frame() && frame()->loader().documentLoader() && !frame()->loader().docu mentLoader()->timing().loadEventStart()) { 1346 if (frame() && frame()->loader().documentLoader() && !frame()->loader().docu mentLoader()->timing().loadEventStart()) {
1356 // The DocumentLoader (and thus its DocumentLoadTiming) might get destro yed while dispatching 1347 // The DocumentLoader (and thus its DocumentLoadTiming) might get destro yed while dispatching
1357 // the event, so protect it to prevent writing the end time into freed m emory. 1348 // the event, so protect it to prevent writing the end time into freed m emory.
1358 DocumentLoader* documentLoader = frame()->loader().documentLoader(); 1349 DocumentLoader* documentLoader = frame()->loader().documentLoader();
1359 DocumentLoadTiming& timing = documentLoader->timing(); 1350 DocumentLoadTiming& timing = documentLoader->timing();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 { 1496 {
1506 // If the LocalDOMWindow still has a frame reference, that frame must point 1497 // If the LocalDOMWindow still has a frame reference, that frame must point
1507 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation 1498 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation
1508 // where script execution leaks between different LocalDOMWindows. 1499 // where script execution leaks between different LocalDOMWindows.
1509 if (m_frameObserver->frame()) 1500 if (m_frameObserver->frame())
1510 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() = = this); 1501 ASSERT_WITH_SECURITY_IMPLICATION(m_frameObserver->frame()->domWindow() = = this);
1511 return m_frameObserver->frame(); 1502 return m_frameObserver->frame();
1512 } 1503 }
1513 1504
1514 } // namespace blink 1505 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698