2
* Copyright (C) 2009 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#include "CachedPage.h"
29
#include "CachedFramePlatformData.h"
31
#include "DocumentLoader.h"
32
#include "ExceptionCode.h"
33
#include "EventNames.h"
35
#include "FrameLoaderClient.h"
36
#include "FrameView.h"
38
#include "PageTransitionEvent.h"
39
#include <wtf/RefCountedLeakCounter.h>
42
#include "SVGDocumentExtensions.h"
48
static WTF::RefCountedLeakCounter& cachedFrameCounter()
50
DEFINE_STATIC_LOCAL(WTF::RefCountedLeakCounter, counter, ("CachedFrame"));
55
CachedFrameBase::CachedFrameBase(Frame* frame)
56
: m_document(frame->document())
57
, m_documentLoader(frame->loader()->documentLoader())
58
, m_view(frame->view())
59
, m_mousePressNode(frame->eventHandler()->mousePressNode())
60
, m_url(frame->loader()->url())
61
, m_isMainFrame(!frame->tree()->parent())
65
CachedFrameBase::~CachedFrameBase()
68
cachedFrameCounter().decrement();
70
// CachedFrames should always have had destroy() called by their parent CachedPage
74
void CachedFrameBase::restore()
76
ASSERT(m_document->view() == m_view);
78
Frame* frame = m_view->frame();
79
m_cachedFrameScriptData->restore(frame);
82
if (m_document->svgExtensions())
83
m_document->accessSVGExtensions()->unpauseAnimations();
86
frame->animation()->resumeAnimations(m_document.get());
87
frame->eventHandler()->setMousePressNode(m_mousePressNode.get());
88
m_document->resumeActiveDOMObjects();
90
// It is necessary to update any platform script objects after restoring the
92
frame->script()->updatePlatformScriptObjects();
94
// Reconstruct the FrameTree
95
for (unsigned i = 0; i < m_childFrames.size(); ++i)
96
frame->tree()->appendChild(m_childFrames[i]->view()->frame());
98
// Open the child CachedFrames in their respective FrameLoaders.
99
for (unsigned i = 0; i < m_childFrames.size(); ++i)
100
m_childFrames[i]->open();
102
m_document->dispatchWindowEvent(PageTransitionEvent::create(EventNames().pageshowEvent, true), m_document);
105
CachedFrame::CachedFrame(Frame* frame)
106
: CachedFrameBase(frame)
109
cachedFrameCounter().increment();
112
ASSERT(m_documentLoader);
115
// Active DOM objects must be suspended before we cached the frame script data
116
m_document->suspendActiveDOMObjects();
117
m_cachedFrameScriptData.set(new ScriptCachedFrameData(frame));
119
// Custom scrollbar renderers will get reattached when the document comes out of the page cache
120
m_view->detachCustomScrollbars();
122
m_document->documentWillBecomeInactive();
123
frame->clearTimers();
124
m_document->setInPageCache(true);
126
frame->loader()->client()->savePlatformDataToCachedFrame(this);
128
// Create the CachedFrames for all Frames in the FrameTree.
129
for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling())
130
m_childFrames.append(CachedFrame::create(child));
132
// Deconstruct the FrameTree, to restore it later.
133
// We do this for two reasons:
134
// 1 - We reuse the main frame, so when it navigates to a new page load it needs to start with a blank FrameTree.
135
// 2 - It's much easier to destroy a CachedFrame while it resides in the PageCache if it is disconnected from its parent.
136
for (unsigned i = 0; i < m_childFrames.size(); ++i)
137
frame->tree()->removeChild(m_childFrames[i]->view()->frame());
141
LOG(PageCache, "Finished creating CachedFrame for main frame url '%s' and DocumentLoader %p\n", m_url.string().utf8().data(), m_documentLoader.get());
143
LOG(PageCache, "Finished creating CachedFrame for child frame with url '%s' and DocumentLoader %p\n", m_url.string().utf8().data(), m_documentLoader.get());
147
void CachedFrame::open()
150
m_view->frame()->loader()->open(*this);
153
void CachedFrame::clear()
158
// clear() should only be called for Frames representing documents that are no longer in the page cache.
159
// This means the CachedFrame has been:
160
// 1 - Successfully restore()'d by going back/forward.
161
// 2 - destroy()'ed because the PageCache is pruning or the WebView was closed.
162
ASSERT(!m_document->inPageCache());
164
ASSERT(m_document->frame() == m_view->frame());
166
for (int i = m_childFrames.size() - 1; i >= 0; --i)
167
m_childFrames[i]->clear();
171
m_mousePressNode = 0;
174
m_cachedFramePlatformData.clear();
175
m_cachedFrameScriptData.clear();
178
void CachedFrame::destroy()
183
// Only CachedFrames that are still in the PageCache should be destroyed in this manner
184
ASSERT(m_document->inPageCache());
186
ASSERT(m_document->frame() == m_view->frame());
188
if (!m_isMainFrame) {
189
m_view->frame()->detachFromPage();
190
m_view->frame()->loader()->detachViewsAndDocumentLoader();
193
for (int i = m_childFrames.size() - 1; i >= 0; --i)
194
m_childFrames[i]->destroy();
196
if (m_cachedFramePlatformData)
197
m_cachedFramePlatformData->clear();
199
Frame::clearTimers(m_view.get(), m_document.get());
201
// FIXME: Why do we need to call removeAllEventListeners here? When the document is in page cache, this method won't work
202
// fully anyway, because the document won't be able to access its DOMWindow object (due to being frameless).
203
m_document->removeAllEventListeners();
205
m_document->setInPageCache(false);
206
// FIXME: We don't call willRemove here. Why is that OK?
207
m_document->detach();
208
m_view->clearFrame();
213
void CachedFrame::setCachedFramePlatformData(CachedFramePlatformData* data)
215
m_cachedFramePlatformData.set(data);
218
CachedFramePlatformData* CachedFrame::cachedFramePlatformData()
220
return m_cachedFramePlatformData.get();
223
int CachedFrame::descendantFrameCount() const
225
int count = m_childFrames.size();
226
for (size_t i = 0; i < m_childFrames.size(); ++i)
227
count += m_childFrames[i]->descendantFrameCount();
232
} // namespace WebCore