ScriptCachedFrameData.cpp [plain text]
#include "config.h"
#include "ScriptCachedFrameData.h"
#include "Frame.h"
#include "GCController.h"
#include "Page.h"
#include "PageGroup.h"
#include <heap/StrongInlines.h>
#include <runtime/JSLock.h>
#include "ScriptController.h"
using namespace JSC;
namespace WebCore {
ScriptCachedFrameData::ScriptCachedFrameData(Frame* frame)
{
JSLockHolder lock(JSDOMWindowBase::commonJSGlobalData());
ScriptController* scriptController = frame->script();
ScriptController::ShellMap& windowShells = scriptController->m_windowShells;
ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end();
for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) {
JSDOMWindow* window = iter->second->window();
m_windows.add(iter->first.get(), Strong<JSDOMWindow>(window->globalData(), window));
}
scriptController->attachDebugger(0);
}
ScriptCachedFrameData::~ScriptCachedFrameData()
{
clear();
}
void ScriptCachedFrameData::restore(Frame* frame)
{
JSLockHolder lock(JSDOMWindowBase::commonJSGlobalData());
ScriptController* scriptController = frame->script();
ScriptController::ShellMap& windowShells = scriptController->m_windowShells;
ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end();
for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) {
DOMWrapperWorld* world = iter->first.get();
JSDOMWindowShell* windowShell = iter->second.get();
if (JSDOMWindow* window = m_windows.get(world).get())
windowShell->setWindow(window->globalData(), window);
else {
windowShell->setWindow(frame->domWindow());
if (Page* page = frame->page()) {
scriptController->attachDebugger(windowShell, page->debugger());
windowShell->window()->setProfileGroup(page->group().identifier());
}
}
}
}
void ScriptCachedFrameData::clear()
{
if (m_windows.isEmpty())
return;
JSLockHolder lock(JSDOMWindowBase::commonJSGlobalData());
m_windows.clear();
gcController().garbageCollectSoon();
}
}