#ifndef DocumentLifecycleNotifier_h
#define DocumentLifecycleNotifier_h
#include "core/dom/DocumentLifecycleObserver.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/TemporaryChange.h"
namespace WebCore {
class Document;
class DocumentLifecycleNotifier : public LifecycleNotifier<Document> {
public:
static PassOwnPtr<DocumentLifecycleNotifier> create(Document*);
void notifyDocumentWasDetached();
void notifyDocumentWasDisposed();
virtual void addObserver(Observer*) OVERRIDE FINAL;
virtual void removeObserver(Observer*) OVERRIDE FINAL;
private:
explicit DocumentLifecycleNotifier(Document*);
typedef HashSet<DocumentLifecycleObserver*> DocumentObserverSet;
DocumentObserverSet m_documentObservers;
};
inline PassOwnPtr<DocumentLifecycleNotifier> DocumentLifecycleNotifier::create(Document* document)
{
return adoptPtr(new DocumentLifecycleNotifier(document));
}
inline void DocumentLifecycleNotifier::notifyDocumentWasDetached()
{
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverDocumentObservers);
for (DocumentObserverSet::iterator i = m_documentObservers.begin(); i != m_documentObservers.end(); ++i)
(*i)->documentWasDetached();
}
inline void DocumentLifecycleNotifier::notifyDocumentWasDisposed()
{
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverDocumentObservers);
for (DocumentObserverSet::iterator i = m_documentObservers.begin(); i != m_documentObservers.end(); ++i)
(*i)->documentWasDisposed();
}
}
#endif