378 } else |
378 } else |
379 return false; |
379 return false; |
380 } |
380 } |
381 } else if (h->hasLocalName(htmlTag)) { |
381 } else if (h->hasLocalName(htmlTag)) { |
382 if (!current->isDocumentNode() ) { |
382 if (!current->isDocumentNode() ) { |
383 if (document->documentElement()->hasTagName(htmlTag) && !m_isParsingFragment) { |
383 if (document->documentElement()->hasTagName(htmlTag)) { |
384 reportError(RedundantHTMLBodyError, &localName); |
384 reportError(RedundantHTMLBodyError, &localName); |
385 // we have another <HTML> element.... apply attributes to existing one |
385 // we have another <HTML> element.... apply attributes to existing one |
386 // make sure we don't overwrite already existing attributes |
386 // make sure we don't overwrite already existing attributes |
387 NamedAttrMap* map = static_cast<Element*>(n)->attributes(true); |
387 NamedAttrMap* map = static_cast<Element*>(n)->attributes(true); |
388 Element* existingHTML = static_cast<Element*>(document->documentElement()); |
388 Element* existingHTML = static_cast<Element*>(document->documentElement()); |
420 if (inBody) { |
420 if (inBody) { |
421 setSkipMode(h->tagQName()); |
421 setSkipMode(h->tagQName()); |
422 return false; |
422 return false; |
423 } |
423 } |
424 } else if (h->hasLocalName(bodyTag)) { |
424 } else if (h->hasLocalName(bodyTag)) { |
425 if (inBody && document->body() && !m_isParsingFragment) { |
425 if (inBody && document->body()) { |
426 // we have another <BODY> element.... apply attributes to existing one |
426 // we have another <BODY> element.... apply attributes to existing one |
427 // make sure we don't overwrite already existing attributes |
427 // make sure we don't overwrite already existing attributes |
428 // some sites use <body bgcolor=rightcolor>...<body bgcolor=wrongcolor> |
428 // some sites use <body bgcolor=rightcolor>...<body bgcolor=wrongcolor> |
429 reportError(RedundantHTMLBodyError, &localName); |
429 reportError(RedundantHTMLBodyError, &localName); |
430 NamedAttrMap* map = static_cast<Element*>(n)->attributes(true); |
430 NamedAttrMap* map = static_cast<Element*>(n)->attributes(true); |
675 popBlock(bodyTag); |
675 popBlock(bodyTag); |
676 // ### actually for IE document.body returns the now hidden "body" element |
676 // ### actually for IE document.body returns the now hidden "body" element |
677 // we can't implement that behaviour now because it could cause too many |
677 // we can't implement that behaviour now because it could cause too many |
678 // regressions and the headaches are not worth the work as long as there is |
678 // regressions and the headaches are not worth the work as long as there is |
679 // no site actually relying on that detail (Dirk) |
679 // no site actually relying on that detail (Dirk) |
680 if (document->body() && !m_isParsingFragment) |
680 if (document->body()) |
681 document->body()->setAttribute(styleAttr, "display:none"); |
681 document->body()->setAttribute(styleAttr, "display:none"); |
682 inBody = false; |
682 inBody = false; |
683 } |
683 } |
684 if ((haveContent || haveFrameSet) && current->localName() == htmlTag) |
684 if ((haveContent || haveFrameSet) && current->localName() == htmlTag) |
685 return false; |
685 return false; |
813 gFunctionMap.set(bigTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
813 gFunctionMap.set(bigTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
814 gFunctionMap.set(bodyTag.localName().impl(), &HTMLParser::bodyCreateErrorCheck); |
814 gFunctionMap.set(bodyTag.localName().impl(), &HTMLParser::bodyCreateErrorCheck); |
815 gFunctionMap.set(buttonTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); |
815 gFunctionMap.set(buttonTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); |
816 gFunctionMap.set(commentAtom.impl(), &HTMLParser::commentCreateErrorCheck); |
816 gFunctionMap.set(commentAtom.impl(), &HTMLParser::commentCreateErrorCheck); |
817 gFunctionMap.set(ddTag.localName().impl(), &HTMLParser::ddCreateErrorCheck); |
817 gFunctionMap.set(ddTag.localName().impl(), &HTMLParser::ddCreateErrorCheck); |
818 gFunctionMap.set(divTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
|
819 gFunctionMap.set(dtTag.localName().impl(), &HTMLParser::dtCreateErrorCheck); |
818 gFunctionMap.set(dtTag.localName().impl(), &HTMLParser::dtCreateErrorCheck); |
820 gFunctionMap.set(formTag.localName().impl(), &HTMLParser::formCreateErrorCheck); |
819 gFunctionMap.set(formTag.localName().impl(), &HTMLParser::formCreateErrorCheck); |
821 gFunctionMap.set(framesetTag.localName().impl(), &HTMLParser::framesetCreateErrorCheck); |
820 gFunctionMap.set(framesetTag.localName().impl(), &HTMLParser::framesetCreateErrorCheck); |
822 gFunctionMap.set(headTag.localName().impl(), &HTMLParser::headCreateErrorCheck); |
821 gFunctionMap.set(headTag.localName().impl(), &HTMLParser::headCreateErrorCheck); |
823 gFunctionMap.set(iTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
822 gFunctionMap.set(iTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
827 gFunctionMap.set(mapTag.localName().impl(), &HTMLParser::mapCreateErrorCheck); |
826 gFunctionMap.set(mapTag.localName().impl(), &HTMLParser::mapCreateErrorCheck); |
828 gFunctionMap.set(nobrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); |
827 gFunctionMap.set(nobrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); |
829 gFunctionMap.set(noembedTag.localName().impl(), &HTMLParser::noembedCreateErrorCheck); |
828 gFunctionMap.set(noembedTag.localName().impl(), &HTMLParser::noembedCreateErrorCheck); |
830 gFunctionMap.set(noframesTag.localName().impl(), &HTMLParser::noframesCreateErrorCheck); |
829 gFunctionMap.set(noframesTag.localName().impl(), &HTMLParser::noframesCreateErrorCheck); |
831 gFunctionMap.set(noscriptTag.localName().impl(), &HTMLParser::noscriptCreateErrorCheck); |
830 gFunctionMap.set(noscriptTag.localName().impl(), &HTMLParser::noscriptCreateErrorCheck); |
832 gFunctionMap.set(qTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
|
833 gFunctionMap.set(sTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
831 gFunctionMap.set(sTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
834 gFunctionMap.set(selectTag.localName().impl(), &HTMLParser::selectCreateErrorCheck); |
832 gFunctionMap.set(selectTag.localName().impl(), &HTMLParser::selectCreateErrorCheck); |
835 gFunctionMap.set(smallTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
833 gFunctionMap.set(smallTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
836 gFunctionMap.set(strikeTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
834 gFunctionMap.set(strikeTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
837 gFunctionMap.set(tbodyTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); |
835 gFunctionMap.set(tbodyTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); |
841 gFunctionMap.set(thTag.localName().impl(), &HTMLParser::tableCellCreateErrorCheck); |
839 gFunctionMap.set(thTag.localName().impl(), &HTMLParser::tableCellCreateErrorCheck); |
842 gFunctionMap.set(theadTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); |
840 gFunctionMap.set(theadTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); |
843 gFunctionMap.set(trTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); |
841 gFunctionMap.set(trTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); |
844 gFunctionMap.set(ttTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
842 gFunctionMap.set(ttTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
845 gFunctionMap.set(uTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
843 gFunctionMap.set(uTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
846 gFunctionMap.set(ulTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); |
|
847 } |
844 } |
848 |
845 |
849 bool proceed = true; |
846 bool proceed = true; |
850 RefPtr<Node> result; |
847 RefPtr<Node> result; |
851 if (CreateErrorCheckFunc errorCheckFunc = gFunctionMap.get(t->tagName.impl())) |
848 if (CreateErrorCheckFunc errorCheckFunc = gFunctionMap.get(t->tagName.impl())) |
859 { |
856 { |
860 // www.liceo.edu.mx is an example of a site that achieves a level of nesting of |
857 // www.liceo.edu.mx is an example of a site that achieves a level of nesting of |
861 // about 1500 tags, all from a bunch of <b>s. We will only allow at most 20 |
858 // about 1500 tags, all from a bunch of <b>s. We will only allow at most 20 |
862 // nested tags of the same type before just ignoring them all together. |
859 // nested tags of the same type before just ignoring them all together. |
863 unsigned i = 0; |
860 unsigned i = 0; |
864 for (HTMLStackElem* curr = blockStack; i < cMaxRedundantTagDepth && curr; curr = curr->next) { |
861 for (HTMLStackElem* curr = blockStack; |
865 if (curr->tagName == tagName) |
862 i < cMaxRedundantTagDepth && curr && curr->tagName == tagName; |
866 i++; |
863 curr = curr->next, i++); |
867 } |
|
868 return i != cMaxRedundantTagDepth; |
864 return i != cMaxRedundantTagDepth; |
869 } |
865 } |
870 |
866 |
871 void HTMLParser::processCloseTag(Token* t) |
867 void HTMLParser::processCloseTag(Token* t) |
872 { |
868 { |
1160 elem->node = prevMaxElem->node; |
1156 elem->node = prevMaxElem->node; |
1161 elem->didRefNode = prevMaxElem->didRefNode; |
1157 elem->didRefNode = prevMaxElem->didRefNode; |
1162 prevMaxElem->next = elem; |
1158 prevMaxElem->next = elem; |
1163 ASSERT(newNodePtr); |
1159 ASSERT(newNodePtr); |
1164 prevMaxElem->node = newNodePtr; |
1160 prevMaxElem->node = newNodePtr; |
1165 newNodePtr->ref(); |
1161 prevMaxElem->didRefNode = false; |
1166 prevMaxElem->didRefNode = true; |
|
1167 } else |
1162 } else |
1168 delete elem; |
1163 delete elem; |
1169 } |
1164 } |
1170 |
1165 |
1171 // Step 7: Reopen intermediate inlines, e.g., <b><p><i>Foo</b>Goo</p>. |
1166 // Step 7: Reopen intermediate inlines, e.g., <b><p><i>Foo</b>Goo</p>. |
1391 { |
1386 { |
1392 if (head || !document->documentElement()) |
1387 if (head || !document->documentElement()) |
1393 return; |
1388 return; |
1394 |
1389 |
1395 head = new HTMLHeadElement(document); |
1390 head = new HTMLHeadElement(document); |
1396 |
|
1397 if (m_isParsingFragment) |
|
1398 return; |
|
1399 |
|
1400 HTMLElement* body = document->body(); |
1391 HTMLElement* body = document->body(); |
1401 ExceptionCode ec = 0; |
1392 ExceptionCode ec = 0; |
1402 document->documentElement()->insertBefore(head, body, ec); |
1393 document->documentElement()->insertBefore(head, body, ec); |
1403 if (ec) |
1394 if (ec) |
1404 head = 0; |
1395 head = 0; |