ContextFeatures.cpp [plain text]
#include "config.h"
#include "ContextFeatures.h"
#include "Document.h"
#include "Page.h"
#include "RuntimeEnabledFeatures.h"
namespace WebCore {
ContextFeaturesClient* ContextFeaturesClient::empty()
{
DEFINE_STATIC_LOCAL(ContextFeaturesClient, empty, ());
return ∅
}
const char* ContextFeatures::supplementName()
{
return "ContextFeatures";
}
ContextFeatures* ContextFeatures::defaultSwitch()
{
DEFINE_STATIC_LOCAL(RefPtr<ContextFeatures>, instance, (ContextFeatures::create(ContextFeaturesClient::empty())));
return instance.get();
}
bool ContextFeatures::dialogElementEnabled(Document* document)
{
#if ENABLE(DIALOG_ELEMENT)
if (!document)
return RuntimeEnabledFeatures::dialogElementEnabled();
return document->contextFeatures()->isEnabled(document, DialogElement, RuntimeEnabledFeatures::dialogElementEnabled());
#else
UNUSED_PARAM(document);
return false;
#endif
}
bool ContextFeatures::styleScopedEnabled(Document* document)
{
#if ENABLE(STYLE_SCOPED)
if (!document)
return RuntimeEnabledFeatures::styleScopedEnabled();
return document->contextFeatures()->isEnabled(document, StyleScoped, RuntimeEnabledFeatures::styleScopedEnabled());
#else
UNUSED_PARAM(document);
return false;
#endif
}
bool ContextFeatures::htmlNotificationsEnabled(Document* document)
{
#if ENABLE(LEGACY_NOTIFICATIONS)
if (!document)
return false;
return document->contextFeatures()->isEnabled(document, HTMLNotifications, false);
#else
UNUSED_PARAM(document);
return false;
#endif
}
bool ContextFeatures::mutationEventsEnabled(Document* document)
{
ASSERT(document);
if (!document)
return true;
return document->contextFeatures()->isEnabled(document, MutationEvents, true);
}
bool ContextFeatures::pushStateEnabled(Document* document)
{
return document->contextFeatures()->isEnabled(document, PushState, true);
}
void provideContextFeaturesTo(Page* page, ContextFeaturesClient* client)
{
RefCountedSupplement<Page, ContextFeatures>::provideTo(page, ContextFeatures::supplementName(), ContextFeatures::create(client));
}
void provideContextFeaturesToDocumentFrom(Document* document, Page* page)
{
ContextFeatures* provided = static_cast<ContextFeatures*>(RefCountedSupplement<Page, ContextFeatures>::from(page, ContextFeatures::supplementName()));
if (!provided)
return;
document->setContextFeatures(provided);
}
}