This source file includes following definitions.
- m_wentAway
- registrationContextWentAway
- documentWasDisposed
- registerElement
- find
#include "config.h"
#include "core/dom/custom/CustomElementRegistry.h"
#include "HTMLNames.h"
#include "SVGNames.h"
#include "bindings/v8/CustomElementConstructorBuilder.h"
#include "core/dom/DocumentLifecycleObserver.h"
#include "core/dom/custom/CustomElementException.h"
#include "core/dom/custom/CustomElementRegistrationContext.h"
namespace WebCore {
class RegistrationContextObserver : public DocumentLifecycleObserver {
public:
explicit RegistrationContextObserver(Document* document)
: DocumentLifecycleObserver(document)
, m_wentAway(!document)
{
}
bool registrationContextWentAway() { return m_wentAway; }
private:
virtual void documentWasDisposed() OVERRIDE { m_wentAway = true; }
bool m_wentAway;
};
CustomElementDefinition* CustomElementRegistry::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& userSuppliedName, CustomElement::NameSet validNames, ExceptionState& exceptionState)
{
RegistrationContextObserver observer(document);
AtomicString type = userSuppliedName.lower();
if (!constructorBuilder->isFeatureAllowed()) {
CustomElementException::throwException(CustomElementException::CannotRegisterFromExtension, type, exceptionState);
return 0;
}
if (!CustomElement::isValidName(type, validNames)) {
CustomElementException::throwException(CustomElementException::InvalidName, type, exceptionState);
return 0;
}
QualifiedName tagName = nullQName();
if (!constructorBuilder->validateOptions(type, tagName, exceptionState))
return 0;
ASSERT(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.namespaceURI() == SVGNames::svgNamespaceURI);
if (m_registeredTypeNames.contains(type)) {
CustomElementException::throwException(CustomElementException::TypeAlreadyRegistered, type, exceptionState);
return 0;
}
ASSERT(!observer.registrationContextWentAway());
RefPtr<CustomElementLifecycleCallbacks> lifecycleCallbacks = constructorBuilder->createCallbacks();
if (observer.registrationContextWentAway()) {
CustomElementException::throwException(CustomElementException::ContextDestroyedCreatingCallbacks, type, exceptionState);
return 0;
}
const CustomElementDescriptor descriptor(type, tagName.namespaceURI(), tagName.localName());
RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create(descriptor, lifecycleCallbacks);
if (!constructorBuilder->createConstructor(document, definition.get(), exceptionState))
return 0;
m_definitions.add(descriptor, definition);
m_registeredTypeNames.add(descriptor.type());
if (!constructorBuilder->didRegisterDefinition(definition.get())) {
CustomElementException::throwException(CustomElementException::ContextDestroyedRegisteringDefinition, type, exceptionState);
return 0;
}
return definition.get();
}
CustomElementDefinition* CustomElementRegistry::find(const CustomElementDescriptor& descriptor) const
{
return m_definitions.get(descriptor);
}
}