Show
Ignore:
Timestamp:
08/15/08 13:25:16 (5 months ago)
Author:
mbensi
Message:

merge with webkit revision 35774

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/WebCore/dom/XMLTokenizer.cpp

    r396 r437  
    4343#include "HTMLTokenizer.h" 
    4444#include "ScriptController.h" 
     45#include "ScriptElement.h" 
    4546#include "ProcessingInstruction.h" 
    4647#include "ResourceError.h" 
     
    6667#if ENABLE(SVG) 
    6768#include "SVGNames.h" 
     69#include "SVGScriptElement.h" 
    6870#include "SVGStyleElement.h" 
    69 #include "XLinkNames.h" 
    7071#endif 
    7172 
     
    7576 
    7677using namespace EventNames; 
    77 using namespace HTMLNames; 
    7878 
    7979const int maxErrors = 25; 
     
    543543 
    544544// -------------------------------- 
     545 
     546inline bool isScriptElement(Element* element) 
     547{ 
     548    return element->hasTagName(HTMLNames::scriptTag) 
     549#if ENABLE(SVG) 
     550        || element->hasTagName(SVGNames::scriptTag) 
     551#endif 
     552        ; 
     553} 
     554 
     555inline ScriptElement* castToScriptElement(Element* element) 
     556{ 
     557    ASSERT(isScriptElement(element)); 
     558 
     559    if (element->hasTagName(HTMLNames::scriptTag)) 
     560        return static_cast<HTMLScriptElement*>(element); 
     561 
     562#if ENABLE(SVG) 
     563    if (element->hasTagName(SVGNames::scriptTag)) 
     564        return static_cast<SVGScriptElement*>(element); 
     565#endif 
     566 
     567    ASSERT_NOT_REACHED(); 
     568    return 0; 
     569} 
    545570 
    546571XMLTokenizer::XMLTokenizer(Document* _doc, FrameView* _view) 
     
    751776    return false; 
    752777} 
     778 
     779static void eventuallyMarkAsParserCreated(Element* element) 
     780{ 
     781    if (element->hasTagName(HTMLNames::scriptTag)) 
     782        static_cast<HTMLScriptElement*>(element)->setCreatedByParser(true); 
     783#if ENABLE(SVG) 
     784    else if (element->hasTagName(SVGNames::scriptTag)) 
     785        static_cast<SVGScriptElement*>(element)->setCreatedByParser(true); 
     786#endif 
     787    else if (element->hasTagName(HTMLNames::styleTag)) 
     788        static_cast<HTMLStyleElement*>(element)->setCreatedByParser(true); 
     789#if ENABLE(SVG) 
     790    else if (element->hasTagName(SVGNames::styleTag)) 
     791        static_cast<SVGStyleElement*>(element)->setCreatedByParser(true); 
     792#endif 
     793    else if (element->hasTagName(HTMLNames::linkTag)) 
     794        static_cast<HTMLLinkElement*>(element)->setCreatedByParser(true); 
     795} 
     796 
    753797#ifndef USE_QXMLSTREAM 
    754798static inline String toString(const xmlChar* str, unsigned len) 
     
    866910 
    867911    newElement->beginParsingChildren(); 
    868  
    869     if (newElement->hasTagName(scriptTag)) 
    870         static_cast<HTMLScriptElement*>(newElement.get())->setCreatedByParser(true); 
    871     else if (newElement->hasTagName(HTMLNames::styleTag)) 
    872         static_cast<HTMLStyleElement*>(newElement.get())->setCreatedByParser(true); 
    873 #if ENABLE(SVG) 
    874     else if (newElement->hasTagName(SVGNames::styleTag)) 
    875         static_cast<SVGStyleElement*>(newElement.get())->setCreatedByParser(true); 
    876 #endif 
    877     else if (newElement->hasTagName(HTMLNames::linkTag)) 
    878         static_cast<HTMLLinkElement*>(newElement.get())->setCreatedByParser(true); 
    879  
    880     if (newElement->hasTagName(HTMLNames::scriptTag) 
    881 #if ENABLE(SVG) 
    882         || newElement->hasTagName(SVGNames::scriptTag) 
    883 #endif 
    884         ) 
     912    eventuallyMarkAsParserCreated(newElement.get()); 
     913 
     914    if (isScriptElement(newElement.get())) 
    885915        m_scriptStartLine = lineNumber(); 
    886      
     916 
    887917    if (!m_currentNode->addChild(newElement.get())) { 
    888918        stopParsing(); 
    889919        return; 
    890920    } 
    891      
     921 
    892922    setCurrentNode(newElement.get()); 
    893923    if (m_view && !newElement->attached()) 
     
    912942     
    913943    // don't load external scripts for standalone documents (for now) 
    914     if (n->isElementNode() && m_view && (static_cast<Element*>(n)->hasTagName(scriptTag)  
    915 #if ENABLE(SVG) 
    916                                          || static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag) 
    917 #endif 
    918                                          )) { 
    919  
    920                                           
     944    if (n->isElementNode() && m_view && isScriptElement(static_cast<Element*>(n))) { 
    921945        ASSERT(!m_pendingScript); 
    922          
    923946        m_requestingScript = true; 
    924          
    925         Element* scriptElement = static_cast<Element*>(n);         
    926         String scriptHref; 
    927          
    928         if (static_cast<Element*>(n)->hasTagName(scriptTag)) 
    929             scriptHref = scriptElement->getAttribute(srcAttr); 
    930 #if ENABLE(SVG) 
    931         else if (static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag)) 
    932             scriptHref = scriptElement->getAttribute(XLinkNames::hrefAttr); 
    933 #endif 
    934          
     947 
     948        Element* element = static_cast<Element*>(n);  
     949        ScriptElement* scriptElement = castToScriptElement(element); 
     950 
     951        String scriptHref = scriptElement->sourceAttributeValue(); 
    935952        if (!scriptHref.isEmpty()) { 
    936953            // we have a src attribute  
    937             const AtomicString& charset = scriptElement->getAttribute(charsetAttr); 
    938             if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, charset))) { 
    939                 m_scriptElement = scriptElement; 
     954            String scriptCharset = scriptElement->charsetAttributeValue(); 
     955            if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) { 
     956                m_scriptElement = element; 
    940957                m_pendingScript->addClient(this); 
    941                      
     958 
    942959                // m_pendingScript will be 0 if script was already loaded and ref() executed it 
    943960                if (m_pendingScript) 
     
    947964 
    948965        } else { 
    949             String scriptCode = ""; 
    950             for (Node* child = scriptElement->firstChild(); child; child = child->nextSibling()) { 
    951                 if (child->isTextNode() || child->nodeType() == Node::CDATA_SECTION_NODE) 
    952                     scriptCode += static_cast<CharacterData*>(child)->data(); 
    953             } 
     966            String scriptCode = scriptElement->scriptContent(); 
    954967            m_view->frame()->loader()->executeScript(m_doc->url().string(), m_scriptStartLine, scriptCode); 
    955968        } 
    956          
     969 
    957970        m_requestingScript = false; 
    958971    } 
     
    14321445{ 
    14331446    ExceptionCode ec = 0; 
    1434     RefPtr<Element> reportElement = doc->createElementNS(xhtmlNamespaceURI, "parsererror", ec); 
    1435     reportElement->setAttribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"); 
    1436      
    1437     RefPtr<Element> h3 = doc->createElementNS(xhtmlNamespaceURI, "h3", ec); 
     1447    RefPtr<Element> reportElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "parsererror", ec); 
     1448    reportElement->setAttribute(HTMLNames::styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"); 
     1449     
     1450    RefPtr<Element> h3 = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "h3", ec); 
    14381451    reportElement->appendChild(h3.get(), ec); 
    14391452    h3->appendChild(doc->createTextNode("This page contains the following errors:"), ec); 
    14401453     
    1441     RefPtr<Element> fixed = doc->createElementNS(xhtmlNamespaceURI, "div", ec); 
     1454    RefPtr<Element> fixed = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "div", ec); 
    14421455    reportElement->appendChild(fixed.get(), ec); 
    1443     fixed->setAttribute(styleAttr, "font-family:monospace;font-size:12px"); 
     1456    fixed->setAttribute(HTMLNames::styleAttr, "font-family:monospace;font-size:12px"); 
    14441457    fixed->appendChild(doc->createTextNode(errorMessages), ec); 
    14451458     
    1446     h3 = doc->createElementNS(xhtmlNamespaceURI, "h3", ec); 
     1459    h3 = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "h3", ec); 
    14471460    reportElement->appendChild(h3.get(), ec); 
    14481461    h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), ec); 
     
    14661479    Node* documentElement = doc->documentElement(); 
    14671480    if (!documentElement) { 
    1468         RefPtr<Node> rootElement = doc->createElementNS(xhtmlNamespaceURI, "html", ec); 
     1481        RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec); 
    14691482        doc->appendChild(rootElement, ec); 
    1470         RefPtr<Node> body = doc->createElementNS(xhtmlNamespaceURI, "body", ec); 
     1483        RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec); 
    14711484        rootElement->appendChild(body, ec); 
    14721485        documentElement = body.get(); 
     
    14771490        // wrap the erroneous SVG document in an xhtml document and render 
    14781491        // the combined document with error messages. 
    1479         RefPtr<Node> rootElement = doc->createElementNS(xhtmlNamespaceURI, "html", ec); 
    1480         RefPtr<Node> body = doc->createElementNS(xhtmlNamespaceURI, "body", ec); 
     1492        RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec); 
     1493        RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec); 
    14811494        rootElement->appendChild(body, ec); 
    14821495        body->appendChild(documentElement, ec); 
     
    14901503#if ENABLE(XSLT) 
    14911504    if (doc->transformSourceDocument()) { 
    1492         RefPtr<Element> par = doc->createElementNS(xhtmlNamespaceURI, "p", ec); 
     1505        RefPtr<Element> par = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "p", ec); 
    14931506        reportElement->appendChild(par, ec); 
    1494         par->setAttribute(styleAttr, "white-space: normal"); 
     1507        par->setAttribute(HTMLNames::styleAttr, "white-space: normal"); 
    14951508        par->appendChild(doc->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."), ec); 
    14961509    } 
     
    19131926    } 
    19141927 
    1915     if (newElement->hasTagName(scriptTag)) 
    1916         static_cast<HTMLScriptElement*>(newElement.get())->setCreatedByParser(true); 
    1917  
    1918     if (newElement->hasTagName(HTMLNames::scriptTag) 
    1919 #if ENABLE(SVG) 
    1920         || newElement->hasTagName(SVGNames::scriptTag) 
    1921 #endif 
    1922         ) 
     1928    eventuallyMarkAsParserCreated(newElement.get()); 
     1929 
     1930    if (isScriptElement(newElement.get())) 
    19231931        m_scriptStartLine = lineNumber(); 
    19241932 
     
    19381946 
    19391947    Node* n = m_currentNode; 
    1940  
    1941     // skip end of dummy element 
    1942 //     if (m_parsingFragment & n->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) 
    1943 //         return; 
    1944      
    19451948    RefPtr<Node> parent = n->parentNode(); 
    19461949    n->finishParsingChildren(); 
    19471950 
    19481951    // don't load external scripts for standalone documents (for now) 
    1949     if (n->isElementNode() && m_view && (static_cast<Element*>(n)->hasTagName(scriptTag)  
    1950 #if ENABLE(SVG) 
    1951                                          || static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag) 
    1952 #endif 
    1953                                          )) { 
    1954  
    1955  
     1952    if (n->isElementNode() && m_view && isScriptElement(static_cast<Element*>(n))) { 
    19561953        ASSERT(!m_pendingScript); 
    1957  
    19581954        m_requestingScript = true; 
    19591955 
    1960         Element* scriptElement = static_cast<Element*>(n); 
    1961         String scriptHref; 
    1962  
    1963         if (static_cast<Element*>(n)->hasTagName(scriptTag)) 
    1964             scriptHref = scriptElement->getAttribute(srcAttr); 
    1965 #if ENABLE(SVG) 
    1966         else if (static_cast<Element*>(n)->hasTagName(SVGNames::scriptTag)) 
    1967             scriptHref = scriptElement->getAttribute(XLinkNames::hrefAttr); 
    1968 #endif 
     1956        Element* element = static_cast<Element*>(n);  
     1957        ScriptElement* scriptElement = castToScriptElement(element); 
     1958 
     1959        String scriptHref = scriptElement->sourceAttributeValue(); 
    19691960        if (!scriptHref.isEmpty()) { 
    19701961            // we have a src attribute 
    1971             const AtomicString& charset = scriptElement->getAttribute(charsetAttr); 
    1972             if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, charset))) { 
    1973                 m_scriptElement = scriptElement; 
     1962            String scriptCharset = scriptElement->charsetAttributeValue(); 
     1963            if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) { 
     1964                m_scriptElement = element; 
    19741965                m_pendingScript->addClient(this); 
    19751966 
     
    19811972 
    19821973        } else { 
    1983             String scriptCode = ""; 
    1984             for (Node* child = scriptElement->firstChild(); child; child = child->nextSibling()) { 
    1985                 if (child->isTextNode() || child->nodeType() == Node::CDATA_SECTION_NODE) 
    1986                     scriptCode += static_cast<CharacterData*>(child)->data(); 
    1987             } 
     1974            String scriptCode = scriptElement->scriptContent(); 
    19881975            m_view->frame()->loader()->executeScript(m_doc->url().string(), m_scriptStartLine, scriptCode); 
    19891976        } 
     1977 
    19901978        m_requestingScript = false; 
    19911979    }