#include "config.h"
#include "MainFrame.h"
#include "Element.h"
#include "EmptyClients.h"
#include "PageConfiguration.h"
#include "PageOverlayController.h"
#include "PaymentCoordinator.h"
#include "PerformanceLogging.h"
#include "ScrollLatchingState.h"
#include "WheelEventDeltaFilter.h"
#include <wtf/NeverDestroyed.h>
#if PLATFORM(MAC)
#include "ServicesOverlayController.h"
#endif
namespace WebCore {
inline MainFrame::MainFrame(Page& page, PageConfiguration& configuration)
: Frame(page, nullptr, *configuration.loaderClientForMainFrame)
, m_selfOnlyRefCount(0)
#if PLATFORM(MAC) && (ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION))
, m_servicesOverlayController(std::make_unique<ServicesOverlayController>(*this))
#endif
, m_recentWheelEventDeltaFilter(WheelEventDeltaFilter::create())
, m_pageOverlayController(std::make_unique<PageOverlayController>(*this))
#if ENABLE(APPLE_PAY)
, m_paymentCoordinator(std::make_unique<PaymentCoordinator>(*configuration.paymentCoordinatorClient))
#endif
, m_performanceLogging(std::make_unique<PerformanceLogging>(*this))
{
}
MainFrame::~MainFrame()
{
m_recentWheelEventDeltaFilter = nullptr;
m_eventHandler = nullptr;
setMainFrameWasDestroyed();
}
Ref<MainFrame> MainFrame::create(Page& page, PageConfiguration& configuration)
{
return adoptRef(*new MainFrame(page, configuration));
}
void MainFrame::selfOnlyRef()
{
if (m_selfOnlyRefCount++)
return;
ref();
}
void MainFrame::selfOnlyDeref()
{
ASSERT(m_selfOnlyRefCount);
if (--m_selfOnlyRefCount)
return;
if (hasOneRef())
dropChildren();
deref();
}
void MainFrame::dropChildren()
{
while (Frame* child = tree().firstChild())
tree().removeChild(child);
}
void MainFrame::didCompleteLoad()
{
m_timeOfLastCompletedLoad = MonotonicTime::now();
performanceLogging().didReachPointOfInterest(PerformanceLogging::MainFrameLoadCompleted);
}
#if PLATFORM(MAC)
ScrollLatchingState* MainFrame::latchingState()
{
if (m_latchingState.isEmpty())
return nullptr;
return &m_latchingState.last();
}
void MainFrame::pushNewLatchingState()
{
m_latchingState.append(ScrollLatchingState());
}
void MainFrame::resetLatchingState()
{
m_latchingState.clear();
}
void MainFrame::popLatchingState()
{
m_latchingState.removeLast();
}
void MainFrame::removeLatchingStateForTarget(Element& targetNode)
{
if (m_latchingState.isEmpty())
return;
m_latchingState.removeAllMatching([&targetNode] (ScrollLatchingState& state) {
auto* wheelElement = state.wheelEventElement();
if (!wheelElement)
return false;
return targetNode.isEqualNode(wheelElement);
});
}
#endif
}