| Index: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
|
| diff --git a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
|
| index b4fd3fe539ce39913ff720a61d538780bdbdfdfb..222a4e02ce27fb3d427ec684553fc1c35090b7b8 100644
|
| --- a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
|
| +++ b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
|
| @@ -254,6 +254,14 @@
|
| }
|
| }
|
|
|
| +static bool allowsBeforeUnloadListeners(LocalDOMWindow* window) {
|
| + DCHECK(window);
|
| + LocalFrame* frame = window->frame();
|
| + if (!frame)
|
| + return false;
|
| + return frame->isMainFrame();
|
| +}
|
| +
|
| unsigned LocalDOMWindow::pendingUnloadEventListeners() const {
|
| return windowsWithUnloadEventListeners().count(
|
| const_cast<LocalDOMWindow*>(this));
|
| @@ -1425,9 +1433,16 @@
|
| addUnloadEventListener(this);
|
| } else if (eventType == EventTypeNames::beforeunload) {
|
| UseCounter::count(document(), UseCounter::DocumentBeforeUnloadRegistered);
|
| - addBeforeUnloadEventListener(this);
|
| - if (frame() && !frame()->isMainFrame())
|
| + if (allowsBeforeUnloadListeners(this)) {
|
| + // This is confusingly named. It doesn't actually add the listener. It
|
| + // just increments a count so that we know we have listeners registered
|
| + // for the purposes of determining if we can fast terminate the renderer
|
| + // process.
|
| + addBeforeUnloadEventListener(this);
|
| + } else {
|
| + // Subframes return false from allowsBeforeUnloadListeners.
|
| UseCounter::count(document(), UseCounter::SubFrameBeforeUnloadRegistered);
|
| + }
|
| }
|
| }
|
|
|
| @@ -1445,7 +1460,8 @@
|
|
|
| if (eventType == EventTypeNames::unload) {
|
| removeUnloadEventListener(this);
|
| - } else if (eventType == EventTypeNames::beforeunload) {
|
| + } else if (eventType == EventTypeNames::beforeunload &&
|
| + allowsBeforeUnloadListeners(this)) {
|
| removeBeforeUnloadEventListener(this);
|
| }
|
| }
|
|
|