| Index: Source/core/frame/LocalFrame.cpp
 | 
| diff --git a/Source/core/frame/LocalFrame.cpp b/Source/core/frame/LocalFrame.cpp
 | 
| index 14c5bd1102963df17813ca6523fb5cdffd14eff3..34698bdd1486c398a563d46c2803a8c97185bd94 100644
 | 
| --- a/Source/core/frame/LocalFrame.cpp
 | 
| +++ b/Source/core/frame/LocalFrame.cpp
 | 
| @@ -174,16 +174,7 @@
 | 
|      // will trigger the unload event handlers of any child frames, and those event
 | 
|      // handlers might start a new subresource load in this frame.
 | 
|      m_loader.stopAllLoaders();
 | 
| -    if (!client())
 | 
| -        return;
 | 
| -    m_loader.detach();
 | 
| -    setView(nullptr);
 | 
| -    willDetachFrameHost();
 | 
| -    // Notify ScriptController that the frame is closing, since its cleanup ends up calling
 | 
| -    // back to FrameLoaderClient via WindowProxy.
 | 
| -    script().clearForClose();
 | 
| -    InspectorInstrumentation::frameDetachedFromParent(this);
 | 
| -    Frame::detach();
 | 
| +    m_loader.detachFromParent();
 | 
|  }
 | 
|  
 | 
|  bool LocalFrame::inScope(TreeScope* scope) const
 | 
| @@ -324,6 +315,12 @@
 | 
|  
 | 
|  void LocalFrame::willDetachFrameHost()
 | 
|  {
 | 
| +    // We should never be detatching the page during a Layout.
 | 
| +    RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
 | 
| +
 | 
| +    Frame* parent = tree().parent();
 | 
| +    if (parent && parent->isLocalFrame())
 | 
| +        toLocalFrame(parent)->loader().checkLoadComplete();
 | 
|  
 | 
|      WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> >::iterator stop = m_destructionObservers.end();
 | 
|      for (WillBeHeapHashSet<RawPtrWillBeWeakMember<FrameDestructionObserver> >::iterator it = m_destructionObservers.begin(); it != stop; ++it)
 | 
| @@ -338,6 +335,13 @@
 | 
|  
 | 
|      if (page() && page()->scrollingCoordinator() && m_view)
 | 
|          page()->scrollingCoordinator()->willDestroyScrollableArea(m_view.get());
 | 
| +}
 | 
| +
 | 
| +void LocalFrame::detachFromFrameHost()
 | 
| +{
 | 
| +    // We should never be detaching the page during a Layout.
 | 
| +    RELEASE_ASSERT(!m_view || !m_view->isInPerformLayout());
 | 
| +    m_host = nullptr;
 | 
|  }
 | 
|  
 | 
|  String LocalFrame::documentTypeString() const
 | 
| @@ -576,7 +580,7 @@
 | 
|  {
 | 
|      // We allow one level of self-reference because some sites depend on that,
 | 
|      // but we don't allow more than one.
 | 
| -    if (host()->frameCount() >= FrameHost::maxNumberOfFrames)
 | 
| +    if (page()->subframeCount() >= Page::maxNumberOfFrames)
 | 
|          return false;
 | 
|      bool foundSelfReference = false;
 | 
|      for (const Frame* frame = this; frame; frame = frame->tree().parent()) {
 | 
| 
 |