String WebFrameSerializerImpl::preActionBeforeSerializeOpenTag( const Element* element, SerializeDomParam* param, bool* needSkip) { StringBuilder result; *needSkip = false; if (param->isHTMLDocument) { // Skip the open tag of original META tag which declare charset since we // have overrided the META which have correct charset declaration after // serializing open tag of HEAD element. DCHECK(element); if (isHTMLMetaElement(element) && toHTMLMetaElement(element)->computeEncoding().isValid()) { // Found META tag declared charset, we need to skip it when // serializing DOM. param->skipMetaElement = element; *needSkip = true; } else if (isHTMLHtmlElement(*element)) { // Check something before processing the open tag of HEAD element. // First we add doc type declaration if original document has it. if (!param->haveSeenDocType) { param->haveSeenDocType = true; result.append(createMarkup(param->document->doctype())); } // Add MOTW declaration before html tag. // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx. result.append(WebFrameSerializer::generateMarkOfTheWebDeclaration(param->url)); } else if (isHTMLBaseElement(*element)) { // Comment the BASE tag when serializing dom. result.appendLiteral("<!--"); } } else { // Write XML declaration. if (!param->haveAddedXMLProcessingDirective) { param->haveAddedXMLProcessingDirective = true; // Get encoding info. String xmlEncoding = param->document->xmlEncoding(); if (xmlEncoding.isEmpty()) xmlEncoding = param->document->encodingName(); if (xmlEncoding.isEmpty()) xmlEncoding = UTF8Encoding().name(); result.appendLiteral("<?xml version=\""); result.append(param->document->xmlVersion()); result.appendLiteral("\" encoding=\""); result.append(xmlEncoding); if (param->document->xmlStandalone()) result.appendLiteral("\" standalone=\"yes"); result.appendLiteral("\"?>\n"); } // Add doc type declaration if original document has it. if (!param->haveSeenDocType) { param->haveSeenDocType = true; result.append(createMarkup(param->document->doctype())); } } return result.toString(); }
// After we finish serializing end tag of a element, we give the target // element a chance to do some post work to add some additional data. String WebPageSerializerImpl::postActionAfterSerializeEndTag( const Element* element, SerializeDomParam* param) { StringBuilder result; if (!param->isHTMLDocument) return result.toString(); // Comment the BASE tag when serializing DOM. if (isHTMLBaseElement(*element)) { result.append("-->"); // Append a new base tag declaration. result.append(WebPageSerializer::generateBaseTagDeclaration( param->document->baseTarget())); } return result.toString(); }