#ifndef ContextFeatures_h
#define ContextFeatures_h
#include "platform/RefCountedSupplement.h"
namespace WebCore {
class ContextFeaturesClient;
class Document;
class Page;
class ContextFeatures : public RefCountedSupplement<Page, ContextFeatures> {
public:
enum FeatureType {
DialogElement = 0,
StyleScoped,
PagePopup,
MutationEvents,
PushState,
FeatureTypeSize
};
static const char* supplementName();
static ContextFeatures* defaultSwitch();
static PassRefPtr<ContextFeatures> create(ContextFeaturesClient*);
static bool dialogElementEnabled(Document*);
static bool styleScopedEnabled(Document*);
static bool pagePopupEnabled(Document*);
static bool mutationEventsEnabled(Document*);
static bool pushStateEnabled(Document*);
bool isEnabled(Document*, FeatureType, bool) const;
void urlDidChange(Document*);
private:
explicit ContextFeatures(ContextFeaturesClient* client)
: m_client(client)
{ }
virtual void hostDestroyed() OVERRIDE;
ContextFeaturesClient* m_client;
};
inline void ContextFeatures::hostDestroyed()
{
m_client = 0;
}
class ContextFeaturesClient {
WTF_MAKE_FAST_ALLOCATED;
public:
static ContextFeaturesClient* empty();
virtual ~ContextFeaturesClient() { }
virtual bool isEnabled(Document*, ContextFeatures::FeatureType, bool defaultValue) { return defaultValue; }
virtual void urlDidChange(Document*) { }
};
void provideContextFeaturesTo(Page&, ContextFeaturesClient*);
void provideContextFeaturesToDocumentFrom(Document&, Page&);
inline PassRefPtr<ContextFeatures> ContextFeatures::create(ContextFeaturesClient* client)
{
return adoptRef(new ContextFeatures(client));
}
inline bool ContextFeatures::isEnabled(Document* document, FeatureType type, bool defaultValue) const
{
if (!m_client)
return defaultValue;
return m_client->isEnabled(document, type, defaultValue);
}
inline void ContextFeatures::urlDidChange(Document* document)
{
}
}
#endif