void PageCache::addIfCacheable(HistoryItem& item, Page* page)
{
    if (item.isInPageCache())
        return;

    if (!page || !canCache(*page))
        return;

    // Make sure all the documents know they are being added to the PageCache.
    setInPageCache(*page, true);

    // Focus the main frame, defocusing a focused subframe (if we have one). We do this here,
    // before the page enters the page cache, while we still can dispatch DOM blur/focus events.
    if (page->focusController().focusedFrame())
        page->focusController().setFocusedFrame(&page->mainFrame());

    // Fire the pagehide event in all frames.
    firePageHideEventRecursively(page->mainFrame());

    // Check that the page is still page-cacheable after firing the pagehide event. The JS event handlers
    // could have altered the page in a way that could prevent caching.
    if (!canCache(*page)) {
        setInPageCache(*page, false);
        return;
    }

    // Make sure we no longer fire any JS events past this point.
    NoEventDispatchAssertion assertNoEventDispatch;

    item.m_cachedPage = std::make_unique<CachedPage>(*page);
    item.m_pruningReason = PruningReason::None;
    m_items.add(&item);
    
    prune(PruningReason::ReachedMaxSize);
}
Exemple #2
0
void PageCache::add(HistoryItem& item, Page& page)
{
    ASSERT(canCache(&page));

    // Remove stale cache entry if necessary.
    remove(item);

    item.m_cachedPage = std::make_unique<CachedPage>(page);
    item.m_pruningReason = PruningReason::None;
    m_items.add(&item);
    
    prune(PruningReason::ReachedMaxSize);
}
void PageCache::add(PassRefPtr<HistoryItem> prpItem, Page& page)
{
    ASSERT(prpItem);
    ASSERT(canCache(&page));
    
    HistoryItem* item = prpItem.leakRef(); // Balanced in remove().

    // Remove stale cache entry if necessary.
    if (item->m_cachedPage)
        remove(item);

    item->m_cachedPage = std::make_unique<CachedPage>(page);
    addToLRUList(item);
    ++m_size;
    
    prune();
}