StorageEventDispatcher.cpp [plain text]
#include "config.h"
#include "StorageEventDispatcher.h"
#if ENABLE(DOM_STORAGE)
#include "DOMWindow.h"
#include "EventNames.h"
#include "Frame.h"
#include "Page.h"
#include "PageGroup.h"
#include "SecurityOrigin.h"
#include "StorageEvent.h"
namespace WebCore {
void StorageEventDispatcher::dispatch(const String& key, const String& oldValue, const String& newValue, StorageType storageType, SecurityOrigin* securityOrigin, Frame* sourceFrame)
{
Page* page = sourceFrame->page();
if (!page)
return;
Vector<RefPtr<Frame> > frames;
if (storageType == SessionStorage) {
for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
if (sourceFrame != frame && frame->document()->securityOrigin()->equal(securityOrigin))
frames.append(frame);
}
for (unsigned i = 0; i < frames.size(); ++i) {
ExceptionCode ec = 0;
Storage* storage = frames[i]->domWindow()->sessionStorage(ec);
if (!ec)
frames[i]->document()->enqueueEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), storage));
}
} else {
const HashSet<Page*>& pages = page->group().pages();
HashSet<Page*>::const_iterator end = pages.end();
for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) {
for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
if (sourceFrame != frame && frame->document()->securityOrigin()->equal(securityOrigin))
frames.append(frame);
}
}
for (unsigned i = 0; i < frames.size(); ++i) {
ExceptionCode ec = 0;
Storage* storage = frames[i]->domWindow()->localStorage(ec);
if (!ec)
frames[i]->document()->enqueueEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), storage));
}
}
}
}
#endif // ENABLE(DOM_STORAGE)