#ifndef PageLifecycleNotifier_h
#define PageLifecycleNotifier_h
#include "core/page/PageLifecycleObserver.h"
#include "platform/LifecycleNotifier.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/TemporaryChange.h"
namespace WebCore {
class Page;
class LocalFrame;
class PageLifecycleNotifier FINAL : public LifecycleNotifier<Page> {
public:
static PassOwnPtr<PageLifecycleNotifier> create(Page*);
void notifyPageVisibilityChanged();
void notifyDidCommitLoad(LocalFrame*);
virtual void addObserver(Observer*) OVERRIDE;
virtual void removeObserver(Observer*) OVERRIDE;
private:
explicit PageLifecycleNotifier(Page*);
typedef HashSet<PageLifecycleObserver*> PageObserverSet;
PageObserverSet m_pageObservers;
};
inline PassOwnPtr<PageLifecycleNotifier> PageLifecycleNotifier::create(Page* context)
{
return adoptPtr(new PageLifecycleNotifier(context));
}
inline void PageLifecycleNotifier::notifyPageVisibilityChanged()
{
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverPageObservers);
for (PageObserverSet::iterator it = m_pageObservers.begin(); it != m_pageObservers.end(); ++it)
(*it)->pageVisibilityChanged();
}
inline void PageLifecycleNotifier::notifyDidCommitLoad(LocalFrame* frame)
{
TemporaryChange<IterationType> scope(this->m_iterating, IteratingOverPageObservers);
for (PageObserverSet::iterator it = m_pageObservers.begin(); it != m_pageObservers.end(); ++it)
(*it)->didCommitLoad(frame);
}
}
#endif