This source file includes following definitions.
- m_loader
- create
- isURLAttribute
- hasLegalLinkAttribute
- subResourceAttributeName
- childrenChanged
- parseAttribute
- insertedInto
- didNotifySubtreeInsertionsToDocument
- setText
- setAsync
- async
- src
- sourceAttributeValue
- charsetAttributeValue
- typeAttributeValue
- languageAttributeValue
- forAttributeValue
- eventAttributeValue
- asyncAttributeValue
- deferAttributeValue
- hasSourceAttribute
- dispatchLoadEvent
- cloneElementWithoutAttributesAndChildren
#include "config.h"
#include "core/html/HTMLScriptElement.h"
#include "HTMLNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "bindings/v8/ScriptEventListener.h"
#include "core/dom/Attribute.h"
#include "core/dom/Document.h"
#include "core/dom/ScriptLoader.h"
#include "core/dom/Text.h"
#include "core/events/Event.h"
namespace WebCore {
using namespace HTMLNames;
inline HTMLScriptElement::HTMLScriptElement(Document& document, bool wasInsertedByParser, bool alreadyStarted)
: HTMLElement(scriptTag, document)
, m_loader(ScriptLoader::create(this, wasInsertedByParser, alreadyStarted))
{
ScriptWrappable::init(this);
}
PassRefPtr<HTMLScriptElement> HTMLScriptElement::create(Document& document, bool wasInsertedByParser, bool alreadyStarted)
{
return adoptRef(new HTMLScriptElement(document, wasInsertedByParser, alreadyStarted));
}
bool HTMLScriptElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute);
}
bool HTMLScriptElement::hasLegalLinkAttribute(const QualifiedName& name) const
{
return name == srcAttr || HTMLElement::hasLegalLinkAttribute(name);
}
const QualifiedName& HTMLScriptElement::subResourceAttributeName() const
{
return srcAttr;
}
void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
m_loader->childrenChanged();
}
void HTMLScriptElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == srcAttr)
m_loader->handleSourceAttribute(value);
else if (name == asyncAttr)
m_loader->handleAsyncAttribute();
else
HTMLElement::parseAttribute(name, value);
}
Node::InsertionNotificationRequest HTMLScriptElement::insertedInto(ContainerNode* insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
return InsertionShouldCallDidNotifySubtreeInsertions;
}
void HTMLScriptElement::didNotifySubtreeInsertionsToDocument()
{
m_loader->didNotifySubtreeInsertionsToDocument();
}
void HTMLScriptElement::setText(const String &value)
{
RefPtr<Node> protectFromMutationEvents(this);
if (hasOneTextChild()) {
toText(firstChild())->setData(value);
return;
}
removeChildren();
appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION);
}
void HTMLScriptElement::setAsync(bool async)
{
setBooleanAttribute(asyncAttr, async);
m_loader->handleAsyncAttribute();
}
bool HTMLScriptElement::async() const
{
return fastHasAttribute(asyncAttr) || (m_loader->forceAsync());
}
KURL HTMLScriptElement::src() const
{
return document().completeURL(sourceAttributeValue());
}
String HTMLScriptElement::sourceAttributeValue() const
{
return getAttribute(srcAttr).string();
}
String HTMLScriptElement::charsetAttributeValue() const
{
return getAttribute(charsetAttr).string();
}
String HTMLScriptElement::typeAttributeValue() const
{
return getAttribute(typeAttr).string();
}
String HTMLScriptElement::languageAttributeValue() const
{
return getAttribute(languageAttr).string();
}
String HTMLScriptElement::forAttributeValue() const
{
return getAttribute(forAttr).string();
}
String HTMLScriptElement::eventAttributeValue() const
{
return getAttribute(eventAttr).string();
}
bool HTMLScriptElement::asyncAttributeValue() const
{
return fastHasAttribute(asyncAttr);
}
bool HTMLScriptElement::deferAttributeValue() const
{
return fastHasAttribute(deferAttr);
}
bool HTMLScriptElement::hasSourceAttribute() const
{
return fastHasAttribute(srcAttr);
}
void HTMLScriptElement::dispatchLoadEvent()
{
ASSERT(!m_loader->haveFiredLoadEvent());
dispatchEvent(Event::create(EventTypeNames::load));
}
PassRefPtr<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren()
{
return adoptRef(new HTMLScriptElement(document(), false, m_loader->alreadyStarted()));
}
}