DOMWindowExtension.cpp [plain text]
#include "config.h"
#include "DOMWindowExtension.h"
#include "DOMWindow.h"
#include "DOMWrapperWorld.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include <wtf/Ref.h>
namespace WebCore {
DOMWindowExtension::DOMWindowExtension(DOMWindow* window, DOMWrapperWorld& world)
: m_window(makeWeakPtr(window))
, m_world(world)
, m_wasDetached(false)
{
ASSERT(this->frame());
if (m_window)
m_window->registerObserver(*this);
}
DOMWindowExtension::~DOMWindowExtension()
{
if (m_window)
m_window->unregisterObserver(*this);
}
Frame* DOMWindowExtension::frame() const
{
return m_window ? m_window->frame() : nullptr;
}
void DOMWindowExtension::suspendForBackForwardCache()
{
Ref<DOMWindowExtension> protectedThis(*this);
auto frame = makeRef(*this->frame());
frame->loader().client().dispatchWillDisconnectDOMWindowExtensionFromGlobalObject(this);
m_disconnectedFrame = WTFMove(frame);
}
void DOMWindowExtension::resumeFromBackForwardCache()
{
ASSERT(frame());
ASSERT(m_disconnectedFrame == frame());
ASSERT(frame()->document()->domWindow() == m_window);
m_disconnectedFrame = nullptr;
frame()->loader().client().dispatchDidReconnectDOMWindowExtensionToGlobalObject(this);
}
void DOMWindowExtension::willDestroyGlobalObjectInCachedFrame()
{
ASSERT(m_disconnectedFrame);
Ref<DOMWindowExtension> protectedThis(*this);
if (m_disconnectedFrame)
m_disconnectedFrame->loader().client().dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
m_disconnectedFrame = nullptr;
ASSERT(m_window);
if (m_window)
m_window->unregisterObserver(*this);
m_window = nullptr;
}
void DOMWindowExtension::willDestroyGlobalObjectInFrame()
{
ASSERT(!m_disconnectedFrame);
Ref<DOMWindowExtension> protectedThis(*this);
if (!m_wasDetached) {
Frame* frame = this->frame();
ASSERT(frame);
frame->loader().client().dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
}
ASSERT(m_window);
if (m_window)
m_window->unregisterObserver(*this);
m_window = nullptr;
}
void DOMWindowExtension::willDetachGlobalObjectFromFrame()
{
ASSERT(!m_disconnectedFrame);
ASSERT(!m_wasDetached);
Ref<DOMWindowExtension> protectedThis(*this);
Frame* frame = this->frame();
ASSERT(frame);
frame->loader().client().dispatchWillDestroyGlobalObjectForDOMWindowExtension(this);
m_wasDetached = true;
}
}