Ignore:
Timestamp:
04/17/12 14:59:25 (2 years ago)
Author:
lforschler@apple.com
Message:

Merge 112023.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-534.57-branch/Source/WebCore/dom/XMLDocumentParser.cpp

    r91420 r114438  
    252252} 
    253253 
    254 static inline RefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages) 
    255 { 
    256     RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), false); 
    257     reportElement->setAttribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"); 
    258  
    259     ExceptionCode ec = 0; 
    260     RefPtr<Element> h3 = doc->createElement(h3Tag, false); 
    261     reportElement->appendChild(h3.get(), ec); 
    262     h3->appendChild(doc->createTextNode("This page contains the following errors:"), ec); 
    263  
    264     RefPtr<Element> fixed = doc->createElement(divTag, false); 
    265     reportElement->appendChild(fixed.get(), ec); 
    266     fixed->setAttribute(styleAttr, "font-family:monospace;font-size:12px"); 
    267     fixed->appendChild(doc->createTextNode(errorMessages), ec); 
    268  
    269     h3 = doc->createElement(h3Tag, false); 
    270     reportElement->appendChild(h3.get(), ec); 
    271     h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), ec); 
    272  
    273     return reportElement; 
     254static inline PassRefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages) 
     255{ 
     256    RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), true); 
     257 
     258    RefPtr<NamedNodeMap> reportAttributes = NamedNodeMap::create(); 
     259    reportAttributes->addAttribute(Attribute::createMapped(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black")); 
     260    reportElement->setAttributeMap(reportAttributes.release(), FragmentScriptingNotAllowed); 
     261 
     262    RefPtr<Element> h3 = doc->createElement(h3Tag, true); 
     263    reportElement->parserAddChild(h3.get()); 
     264    h3->parserAddChild(doc->createTextNode("This page contains the following errors:")); 
     265 
     266    RefPtr<Element> fixed = doc->createElement(divTag, true); 
     267    RefPtr<NamedNodeMap> fixedAttributes = NamedNodeMap::create(); 
     268    fixedAttributes->addAttribute(Attribute::createMapped(styleAttr, "font-family:monospace;font-size:12px")); 
     269    fixed->setAttributeMap(fixedAttributes.release(), FragmentScriptingNotAllowed); 
     270    reportElement->parserAddChild(fixed.get()); 
     271 
     272    fixed->parserAddChild(doc->createTextNode(errorMessages)); 
     273 
     274    h3 = doc->createElement(h3Tag, true); 
     275    reportElement->parserAddChild(h3.get()); 
     276    h3->parserAddChild(doc->createTextNode("Below is a rendering of the page up to the first error.")); 
     277 
     278    return reportElement.release(); 
    274279} 
    275280 
     
    285290 
    286291    // Create elements for display 
    287     ExceptionCode ec = 0; 
    288292    Document* document = this->document(); 
    289293    RefPtr<Element> documentElement = document->documentElement(); 
    290294    if (!documentElement) { 
    291         RefPtr<Element> rootElement = document->createElement(htmlTag, false); 
    292         document->appendChild(rootElement, ec); 
    293         RefPtr<Element> body = document->createElement(bodyTag, false); 
    294         rootElement->appendChild(body, ec); 
     295        RefPtr<Element> rootElement = document->createElement(htmlTag, true); 
     296        RefPtr<Element> body = document->createElement(bodyTag, true); 
     297        rootElement->parserAddChild(body); 
     298        document->parserAddChild(rootElement); 
     299        if (document->attached() && !rootElement->attached()) 
     300            rootElement->attach(); 
    295301        documentElement = body.get(); 
    296302    } 
    297303#if ENABLE(SVG) 
    298304    else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) { 
    299         RefPtr<Element> rootElement = document->createElement(htmlTag, false); 
    300         RefPtr<Element> body = document->createElement(bodyTag, false); 
    301         rootElement->appendChild(body, ec); 
    302         body->appendChild(documentElement, ec); 
    303         document->appendChild(rootElement.get(), ec); 
     305        RefPtr<Element> rootElement = document->createElement(htmlTag, true); 
     306        RefPtr<Element> body = document->createElement(bodyTag, true); 
     307        rootElement->parserAddChild(body); 
     308 
     309        documentElement->parentNode()->parserRemoveChild(documentElement.get()); 
     310        if (documentElement->attached()) 
     311            documentElement->detach(); 
     312 
     313        body->parserAddChild(documentElement); 
     314        document->parserAddChild(rootElement.get()); 
     315 
     316        if (document->attached()) { 
     317            // rootElement shouldn't be attached right now, but in some cases might be. 
     318            // See https://bugs.webkit.org/show_bug.cgi?id=81985 
     319            rootElement->reattach(); 
     320        } 
     321 
    304322        documentElement = body.get(); 
    305323    } 
    306324#endif 
     325 
    307326    RefPtr<Element> reportElement = createXHTMLParserErrorHeader(document, m_errorMessages); 
    308     documentElement->insertBefore(reportElement, documentElement->firstChild(), ec); 
     327 
    309328#if ENABLE(XSLT) 
    310329    if (document->transformSourceDocument()) { 
    311         RefPtr<Element> paragraph = document->createElement(pTag, false); 
    312         paragraph->setAttribute(styleAttr, "white-space: normal"); 
    313         paragraph->appendChild(document->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."), ec); 
    314         reportElement->appendChild(paragraph.release(), ec); 
    315     } 
    316 #endif 
     330        RefPtr<NamedNodeMap> attributes = NamedNodeMap::create(); 
     331        attributes->addAttribute(Attribute::createMapped(styleAttr, "white-space: normal")); 
     332        RefPtr<Element> paragraph = document->createElement(pTag, true); 
     333        paragraph->setAttributeMap(attributes.release(), FragmentScriptingNotAllowed); 
     334        paragraph->parserAddChild(document->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result.")); 
     335        reportElement->parserAddChild(paragraph.release()); 
     336    } 
     337#endif 
     338 
     339    Node* firstChild = documentElement->firstChild(); 
     340    if (firstChild) 
     341        documentElement->parserInsertBefore(reportElement, documentElement->firstChild()); 
     342    else 
     343        documentElement->parserAddChild(reportElement); 
     344 
     345    if (documentElement->attached() && !reportElement->attached()) 
     346        reportElement->attach(); 
     347 
    317348    document->updateStyleIfNeeded(); 
    318349} 
Note: See TracChangeset for help on using the changeset viewer.