CachedPage.cpp 3.51 KB
Newer Older
darin's avatar
darin committed
1
/*
ggaren@apple.com's avatar
ggaren@apple.com committed
2
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
darin's avatar
darin committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#include "config.h"
beidson's avatar
beidson committed
27
#include "CachedPage.h"
darin's avatar
darin committed
28

29
#include "CSSStyleSelector.h"
30 31
#include "Document.h"
#include "Element.h"
adele's avatar
adele committed
32
#include "FocusController.h"
darin's avatar
darin committed
33
#include "Frame.h"
34
#include "FrameView.h"
35
#include "Node.h"
darin's avatar
darin committed
36
#include "Page.h"
ap@webkit.org's avatar
ap@webkit.org committed
37
#include <wtf/CurrentTime.h>
38
#include <wtf/RefCountedLeakCounter.h>
darin's avatar
darin committed
39

40
using namespace JSC;
darin's avatar
darin committed
41 42 43

namespace WebCore {

ggaren's avatar
ggaren committed
44
#ifndef NDEBUG
45
static WTF::RefCountedLeakCounter cachedPageCounter("CachedPage");
ggaren's avatar
ggaren committed
46 47
#endif

beidson's avatar
beidson committed
48
PassRefPtr<CachedPage> CachedPage::create(Page* page)
darin's avatar
darin committed
49
{
50
    return adoptRef(new CachedPage(page));
darin's avatar
darin committed
51 52
}

beidson's avatar
beidson committed
53
CachedPage::CachedPage(Page* page)
54
    : m_timeStamp(currentTime())
55
    , m_cachedMainFrame(CachedFrame::create(page->mainFrame()))
56
    , m_needStyleRecalcForVisitedLinks(false)
darin's avatar
darin committed
57
{
ggaren's avatar
ggaren committed
58
#ifndef NDEBUG
59
    cachedPageCounter.increment();
ggaren's avatar
ggaren committed
60
#endif
darin's avatar
darin committed
61 62
}

beidson's avatar
beidson committed
63
CachedPage::~CachedPage()
darin's avatar
darin committed
64
{
ggaren's avatar
ggaren committed
65
#ifndef NDEBUG
66
    cachedPageCounter.decrement();
ggaren's avatar
ggaren committed
67 68
#endif

69 70
    destroy();
    ASSERT(!m_cachedMainFrame);
darin's avatar
darin committed
71 72
}

beidson's avatar
beidson committed
73
void CachedPage::restore(Page* page)
darin's avatar
darin committed
74
{
75
    ASSERT(m_cachedMainFrame);
76
    ASSERT(page && page->mainFrame() && page->mainFrame() == m_cachedMainFrame->view()->frame());
ap@apple.com's avatar
ap@apple.com committed
77
    ASSERT(!page->frameCount());
darin's avatar
darin committed
78

79
    m_cachedMainFrame->open();
80
    
adele's avatar
adele committed
81 82 83 84 85 86 87
    // Restore the focus appearance for the focused element.
    // FIXME: Right now we don't support pages w/ frames in the b/f cache.  This may need to be tweaked when we add support for that.
    Document* focusedDocument = page->focusController()->focusedOrMainFrame()->document();
    if (Node* node = focusedDocument->focusedNode()) {
        if (node->isElementNode())
            static_cast<Element*>(node)->updateFocusAppearance(true);
    }
88 89 90 91 92 93 94 95

    if (m_needStyleRecalcForVisitedLinks) {
        for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
            if (CSSStyleSelector* styleSelector = frame->document()->styleSelector())
                styleSelector->allVisitedStateChanged();
        }
    }

96
    clear();
darin's avatar
darin committed
97 98
}

beidson's avatar
beidson committed
99
void CachedPage::clear()
darin's avatar
darin committed
100
{
101 102 103
    ASSERT(m_cachedMainFrame);
    m_cachedMainFrame->clear();
    m_cachedMainFrame = 0;
104
    m_needStyleRecalcForVisitedLinks = false;
105 106 107 108 109 110 111 112
}

void CachedPage::destroy()
{
    if (m_cachedMainFrame)
        m_cachedMainFrame->destroy();

    m_cachedMainFrame = 0;
beidson's avatar
beidson committed
113 114 115
}

} // namespace WebCore