SessionStorageArea.cpp [plain text]
#include "config.h"
#include "SessionStorageArea.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameTree.h"
#include "Page.h"
#include "PlatformString.h"
#include "SecurityOrigin.h"
#include "StorageMap.h"
namespace WebCore {
PassRefPtr<SessionStorageArea> SessionStorageArea::copy(SecurityOrigin* origin, Page* page)
{
return adoptRef(new SessionStorageArea(origin, page, this));
}
SessionStorageArea::SessionStorageArea(SecurityOrigin* origin, Page* page)
: StorageArea(origin)
, m_page(page)
{
ASSERT(page);
}
SessionStorageArea::SessionStorageArea(SecurityOrigin* origin, Page* page, SessionStorageArea* area)
: StorageArea(origin, area)
, m_page(page)
{
ASSERT(page);
}
void SessionStorageArea::itemChanged(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame)
{
dispatchStorageEvent(key, oldValue, newValue, sourceFrame);
}
void SessionStorageArea::itemRemoved(const String& key, const String& oldValue, Frame* sourceFrame)
{
dispatchStorageEvent(key, oldValue, String(), sourceFrame);
}
void SessionStorageArea::areaCleared(Frame* sourceFrame)
{
dispatchStorageEvent(String(), String(), String(), sourceFrame);
}
void SessionStorageArea::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame)
{
Vector<RefPtr<Frame> > frames;
for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
if (Document* document = frame->document())
if (document->securityOrigin()->equal(securityOrigin()))
frames.append(frame);
}
for (unsigned i = 0; i < frames.size(); ++i) {
if (HTMLElement* body = frames[i]->document()->body())
body->dispatchStorageEvent(eventNames().storageEvent, key, oldValue, newValue, sourceFrame);
}
}
}