void XMLDocumentParser::parseEndElement() { exitText(); RefPtr<ContainerNode> n = m_currentNode; n->finishParsingChildren(); if (!scriptingContentIsAllowed(m_scriptingPermission) && n->isElementNode() && toScriptElement(static_cast<Element*>(n.get()))) { popCurrentNode(); ExceptionCode ec; n->remove(ec); return; } if (!n->isElementNode() || !m_view) { if (!m_currentNodeStack.isEmpty()) popCurrentNode(); return; } Element* element = static_cast<Element*>(n.get()); // The element's parent may have already been removed from document. // Parsing continues in this case, but scripts aren't executed. if (!element->inDocument()) { popCurrentNode(); return; } ScriptElement* scriptElement = toScriptElement(element); if (!scriptElement) { popCurrentNode(); return; } // don't load external scripts for standalone documents (for now) ASSERT(!m_pendingScript); m_requestingScript = true; if (scriptElement->prepareScript(m_scriptStartPosition, ScriptElement::AllowLegacyTypeInTypeAttribute)) { if (scriptElement->readyToBeParserExecuted()) scriptElement->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition)); else if (scriptElement->willBeParserExecuted()) { m_pendingScript = scriptElement->cachedScript(); m_scriptElement = element; m_pendingScript->addClient(this); // m_pendingScript will be 0 if script was already loaded and addClient() executed it. if (m_pendingScript) pauseParsing(); } else m_scriptElement = 0; } m_requestingScript = false; popCurrentNode(); }
void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) { ActionLogScope log_scope("script runner timer"); ASSERT_UNUSED(timer, timer == &m_timer); RefPtr<Document> protect(m_document); Vector<PendingScript> scripts; scripts.swap(m_scriptsToExecuteSoon); size_t numInOrderScriptsToExecute = 0; for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute].cachedScript()->isLoaded(); ++numInOrderScriptsToExecute) scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); if (numInOrderScriptsToExecute) m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); size_t size = scripts.size(); for (size_t i = 0; i < size; ++i) { CachedScript* cachedScript = scripts[i].cachedScript(); RefPtr<Element> element = scripts[i].releaseElementAndClear(); ScriptElement* script = toScriptElement(element.get()); ActionLogFormat(ActionLog::READ_MEMORY, "ScriptRunner-%p-%p", static_cast<void*>(this), static_cast<void*>(script)); script->execute(cachedScript); m_document->decrementLoadEventDelayCount(); } }
void XMLTokenizer::notifyFinished(CachedResource* unusedResource) { ASSERT_UNUSED(unusedResource, unusedResource == m_pendingScript); ASSERT(m_pendingScript->accessCount() > 0); ScriptSourceCode sourceCode(m_pendingScript.get()); bool errorOccurred = m_pendingScript->errorOccurred(); m_pendingScript->removeClient(this); m_pendingScript = 0; RefPtr<Element> e = m_scriptElement; m_scriptElement = 0; ScriptElement* scriptElement = toScriptElement(e.get()); ASSERT(scriptElement); if (errorOccurred) scriptElement->dispatchErrorEvent(); else { m_view->frame()->loader()->executeScript(sourceCode); scriptElement->dispatchLoadEvent(); } m_scriptElement = 0; if (!m_requestingScript) resumeParsing(); }
void XMLDocumentParser::parseStartElement() { if (!m_sawFirstElement && m_parsingFragment) { // skip dummy element for fragments m_sawFirstElement = true; return; } exitText(); String localName = m_stream.name(); String uri = m_stream.namespaceUri(); String prefix = prefixFromQName(m_stream.qualifiedName().toString()); if (m_parsingFragment && uri.isNull()) { Q_ASSERT(prefix.isNull()); uri = m_defaultNamespaceURI; } QualifiedName qName(prefix, localName, uri); RefPtr<Element> newElement = document()->createElement(qName, true); if (!newElement) { stopParsing(); return; } bool isFirstElement = !m_sawFirstElement; m_sawFirstElement = true; ExceptionCode ec = 0; handleElementNamespaces(newElement.get(), m_stream.namespaceDeclarations(), ec, m_scriptingPermission); if (ec) { stopParsing(); return; } handleElementAttributes(newElement.get(), m_stream.attributes(), ec, m_scriptingPermission); if (ec) { stopParsing(); return; } ScriptElement* scriptElement = toScriptElement(newElement.get()); if (scriptElement) m_scriptStartPosition = textPosition(); m_currentNode->parserAddChild(newElement.get()); pushCurrentNode(newElement.get()); if (m_view && !newElement->attached()) newElement->attach(); if (newElement->hasTagName(HTMLNames::htmlTag)) static_cast<HTMLHtmlElement*>(newElement.get())->insertedByParser(); if (isFirstElement && document()->frame()) document()->frame()->loader()->dispatchDocumentElementAvailable(); }
void XMLTreeBuilder::closeElement(PassRefPtr<Element> element) { element->finishParsingChildren(); ScriptElement* scriptElement = toScriptElement(element.get()); if (scriptElement) m_parser->processScript(scriptElement); popCurrentNode(); }
String HTMLOptionElement::collectOptionInnerText() const { StringBuilder text; for (Node* node = firstChild(); node; ) { if (node->isTextNode()) text.append(node->nodeValue()); // Text nodes inside script elements are not part of the option text. if (node->isElementNode() && toScriptElement(toElement(node))) node = node->traverseNextSibling(this); else node = node->traverseNextNode(this); } return text.toString(); }
String OptionElement::collectOptionInnerText(const Element* element) { String text; Node* n = element->firstChild(); while (n) { if (n->nodeType() == Node::TEXT_NODE || n->nodeType() == Node::CDATA_SECTION_NODE) text += n->nodeValue(); // skip script content if (n->isElementNode() && toScriptElement(static_cast<Element*>(n))) n = n->traverseNextSibling(element); else n = n->traverseNextNode(element); } return text; }
void AsyncScriptRunner::timerFired(Timer<AsyncScriptRunner>* timer) { ASSERT_UNUSED(timer, timer == &m_timer); RefPtr<Document> protect(m_document); Vector<PendingScript> scripts; scripts.swap(m_scriptsToExecuteSoon); size_t size = scripts.size(); for (size_t i = 0; i < size; ++i) { CachedScript* cachedScript = scripts[i].cachedScript(); RefPtr<Element> element = scripts[i].releaseElementAndClear(); toScriptElement(element.get())->execute(cachedScript); m_document->decrementLoadEventDelayCount(); } }
void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) { ASSERT_UNUSED(timer, timer == &m_timer); RefPtr<Document> protect(m_document); Vector<PendingScript> scripts; scripts.swap(m_scriptsToExecuteSoon); size_t numInOrderScriptsToExecute = 0; for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute].cachedScript()->isLoaded(); ++numInOrderScriptsToExecute) scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); if (numInOrderScriptsToExecute) m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); size_t size = scripts.size(); for (size_t i = 0; i < size; ++i) { CachedScript* cachedScript = scripts[i].cachedScript(); RefPtr<Element> element = scripts[i].releaseElementAndClear(); toScriptElement(element.get())->execute(cachedScript); m_document->decrementLoadEventDelayCount(); } }
void XMLDocumentParser::parseStartElement() { if (!m_sawFirstElement && m_parsingFragment) { // skip dummy element for fragments m_sawFirstElement = true; return; } exitText(); String localName = m_stream.name(); String uri = m_stream.namespaceUri(); String prefix = prefixFromQName(m_stream.qualifiedName().toString()); if (m_parsingFragment && uri.isNull()) { Q_ASSERT(prefix.isNull()); uri = m_defaultNamespaceURI; } QualifiedName qName(prefix, localName, uri); RefPtr<Element> newElement = document()->createElement(qName, true); if (!newElement) { stopParsing(); return; } #if ENABLE(XHTMLMP) if (!m_sawFirstElement && isXHTMLMPDocument()) { // As per 7.1 section of OMA-WAP-XHTMLMP-V1_1-20061020-A.pdf, // we should make sure that the root element MUST be 'html' and // ensure the name of the default namespace on the root elment 'html' // MUST be 'http://www.w3.org/1999/xhtml' if (localName != HTMLNames::htmlTag.localName()) { handleError(fatal, "XHTMLMP document expects 'html' as root element.", lineNumber(), columnNumber()); return; } if (uri.isNull()) { m_defaultNamespaceURI = HTMLNames::xhtmlNamespaceURI; uri = m_defaultNamespaceURI; m_stream.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration(prefix, HTMLNames::xhtmlNamespaceURI)); } } #endif bool isFirstElement = !m_sawFirstElement; m_sawFirstElement = true; ExceptionCode ec = 0; handleElementNamespaces(newElement.get(), m_stream.namespaceDeclarations(), ec, m_scriptingPermission); if (ec) { stopParsing(); return; } handleElementAttributes(newElement.get(), m_stream.attributes(), ec, m_scriptingPermission); if (ec) { stopParsing(); return; } ScriptElement* scriptElement = toScriptElement(newElement.get()); if (scriptElement) m_scriptStartPosition = textPositionOneBased(); m_currentNode->deprecatedParserAddChild(newElement.get()); pushCurrentNode(newElement.get()); if (m_view && !newElement->attached()) newElement->attach(); #if ENABLE(OFFLINE_WEB_APPLICATIONS) if (newElement->hasTagName(HTMLNames::htmlTag)) static_cast<HTMLHtmlElement*>(newElement.get())->insertedByParser(); #endif if (isFirstElement && document()->frame()) document()->frame()->loader()->dispatchDocumentElementAvailable(); }