| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 String WebPageSerializerImpl::preActionBeforeSerializeOpenTag( | 125 String WebPageSerializerImpl::preActionBeforeSerializeOpenTag( |
| 126 const Element* element, SerializeDomParam* param, bool* needSkip) | 126 const Element* element, SerializeDomParam* param, bool* needSkip) |
| 127 { | 127 { |
| 128 StringBuilder result; | 128 StringBuilder result; |
| 129 | 129 |
| 130 *needSkip = false; | 130 *needSkip = false; |
| 131 if (param->isHTMLDocument) { | 131 if (param->isHTMLDocument) { |
| 132 // Skip the open tag of original META tag which declare charset since we | 132 // Skip the open tag of original META tag which declare charset since we |
| 133 // have overrided the META which have correct charset declaration after | 133 // have overrided the META which have correct charset declaration after |
| 134 // serializing open tag of HEAD element. | 134 // serializing open tag of HEAD element. |
| 135 if (element->hasTagName(HTMLNames::metaTag)) { | 135 ASSERT(element); |
| 136 const HTMLMetaElement* meta = toHTMLMetaElement(element); | 136 if (isHTMLMetaElement(*element)) { |
| 137 const HTMLMetaElement& meta = toHTMLMetaElement(*element); |
| 137 // Check whether the META tag has declared charset or not. | 138 // Check whether the META tag has declared charset or not. |
| 138 String equiv = meta->httpEquiv(); | 139 String equiv = meta.httpEquiv(); |
| 139 if (equalIgnoringCase(equiv, "content-type")) { | 140 if (equalIgnoringCase(equiv, "content-type")) { |
| 140 String content = meta->content(); | 141 String content = meta.content(); |
| 141 if (content.length() && content.contains("charset", false)) { | 142 if (content.length() && content.contains("charset", false)) { |
| 142 // Find META tag declared charset, we need to skip it when | 143 // Find META tag declared charset, we need to skip it when |
| 143 // serializing DOM. | 144 // serializing DOM. |
| 144 param->skipMetaElement = element; | 145 param->skipMetaElement = element; |
| 145 *needSkip = true; | 146 *needSkip = true; |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 } else if (element->hasTagName(HTMLNames::htmlTag)) { | 149 } else if (isHTMLHtmlElement(*element)) { |
| 149 // Check something before processing the open tag of HEAD element. | 150 // Check something before processing the open tag of HEAD element. |
| 150 // First we add doc type declaration if original document has it. | 151 // First we add doc type declaration if original document has it. |
| 151 if (!param->haveSeenDocType) { | 152 if (!param->haveSeenDocType) { |
| 152 param->haveSeenDocType = true; | 153 param->haveSeenDocType = true; |
| 153 result.append(createMarkup(param->document->doctype())); | 154 result.append(createMarkup(param->document->doctype())); |
| 154 } | 155 } |
| 155 | 156 |
| 156 // Add MOTW declaration before html tag. | 157 // Add MOTW declaration before html tag. |
| 157 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx
. | 158 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx
. |
| 158 result.append(WebPageSerializer::generateMarkOfTheWebDeclaration(par
am->url)); | 159 result.append(WebPageSerializer::generateMarkOfTheWebDeclaration(par
am->url)); |
| 159 } else if (element->hasTagName(HTMLNames::baseTag)) { | 160 } else if (isHTMLBaseElement(*element)) { |
| 160 // Comment the BASE tag when serializing dom. | 161 // Comment the BASE tag when serializing dom. |
| 161 result.append("<!--"); | 162 result.append("<!--"); |
| 162 } | 163 } |
| 163 } else { | 164 } else { |
| 164 // Write XML declaration. | 165 // Write XML declaration. |
| 165 if (!param->haveAddedXMLProcessingDirective) { | 166 if (!param->haveAddedXMLProcessingDirective) { |
| 166 param->haveAddedXMLProcessingDirective = true; | 167 param->haveAddedXMLProcessingDirective = true; |
| 167 // Get encoding info. | 168 // Get encoding info. |
| 168 String xmlEncoding = param->document->xmlEncoding(); | 169 String xmlEncoding = param->document->xmlEncoding(); |
| 169 if (xmlEncoding.isEmpty()) | 170 if (xmlEncoding.isEmpty()) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 190 String WebPageSerializerImpl::postActionAfterSerializeOpenTag( | 191 String WebPageSerializerImpl::postActionAfterSerializeOpenTag( |
| 191 const Element* element, SerializeDomParam* param) | 192 const Element* element, SerializeDomParam* param) |
| 192 { | 193 { |
| 193 StringBuilder result; | 194 StringBuilder result; |
| 194 | 195 |
| 195 param->haveAddedContentsBeforeEnd = false; | 196 param->haveAddedContentsBeforeEnd = false; |
| 196 if (!param->isHTMLDocument) | 197 if (!param->isHTMLDocument) |
| 197 return result.toString(); | 198 return result.toString(); |
| 198 // Check after processing the open tag of HEAD element | 199 // Check after processing the open tag of HEAD element |
| 199 if (!param->haveAddedCharsetDeclaration | 200 if (!param->haveAddedCharsetDeclaration |
| 200 && element->hasTagName(HTMLNames::headTag)) { | 201 && isHTMLHeadElement(*element)) { |
| 201 param->haveAddedCharsetDeclaration = true; | 202 param->haveAddedCharsetDeclaration = true; |
| 202 // Check meta element. WebKit only pre-parse the first 512 bytes | 203 // Check meta element. WebKit only pre-parse the first 512 bytes |
| 203 // of the document. If the whole <HEAD> is larger and meta is the | 204 // of the document. If the whole <HEAD> is larger and meta is the |
| 204 // end of head part, then this kind of pages aren't decoded correctly | 205 // end of head part, then this kind of pages aren't decoded correctly |
| 205 // because of this issue. So when we serialize the DOM, we need to | 206 // because of this issue. So when we serialize the DOM, we need to |
| 206 // make sure the meta will in first child of head tag. | 207 // make sure the meta will in first child of head tag. |
| 207 // See http://bugs.webkit.org/show_bug.cgi?id=16621. | 208 // See http://bugs.webkit.org/show_bug.cgi?id=16621. |
| 208 // First we generate new content for writing correct META element. | 209 // First we generate new content for writing correct META element. |
| 209 result.append(WebPageSerializer::generateMetaCharsetDeclaration( | 210 result.append(WebPageSerializer::generateMetaCharsetDeclaration( |
| 210 String(param->textEncoding.name()))); | 211 String(param->textEncoding.name()))); |
| 211 | 212 |
| 212 param->haveAddedContentsBeforeEnd = true; | 213 param->haveAddedContentsBeforeEnd = true; |
| 213 // Will search each META which has charset declaration, and skip them al
l | 214 // Will search each META which has charset declaration, and skip them al
l |
| 214 // in PreActionBeforeSerializeOpenTag. | 215 // in PreActionBeforeSerializeOpenTag. |
| 215 } else if (element->hasTagName(HTMLNames::scriptTag) | 216 } else if (isHTMLScriptElement(*element) || isHTMLScriptElement(*element)) { |
| 216 || element->hasTagName(HTMLNames::styleTag)) { | |
| 217 param->isInScriptOrStyleTag = true; | 217 param->isInScriptOrStyleTag = true; |
| 218 } | 218 } |
| 219 | 219 |
| 220 return result.toString(); | 220 return result.toString(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 String WebPageSerializerImpl::preActionBeforeSerializeEndTag( | 223 String WebPageSerializerImpl::preActionBeforeSerializeEndTag( |
| 224 const Element* element, SerializeDomParam* param, bool* needSkip) | 224 const Element* element, SerializeDomParam* param, bool* needSkip) |
| 225 { | 225 { |
| 226 String result; | 226 String result; |
| 227 | 227 |
| 228 *needSkip = false; | 228 *needSkip = false; |
| 229 if (!param->isHTMLDocument) | 229 if (!param->isHTMLDocument) |
| 230 return result; | 230 return result; |
| 231 // Skip the end tag of original META tag which declare charset. | 231 // Skip the end tag of original META tag which declare charset. |
| 232 // Need not to check whether it's META tag since we guarantee | 232 // Need not to check whether it's META tag since we guarantee |
| 233 // skipMetaElement is definitely META tag if it's not 0. | 233 // skipMetaElement is definitely META tag if it's not 0. |
| 234 if (param->skipMetaElement == element) | 234 if (param->skipMetaElement == element) { |
| 235 *needSkip = true; | 235 *needSkip = true; |
| 236 else if (element->hasTagName(HTMLNames::scriptTag) | 236 } else if (isHTMLScriptElement(*element) || isHTMLScriptElement(*element)) { |
| 237 || element->hasTagName(HTMLNames::styleTag)) { | |
| 238 ASSERT(param->isInScriptOrStyleTag); | 237 ASSERT(param->isInScriptOrStyleTag); |
| 239 param->isInScriptOrStyleTag = false; | 238 param->isInScriptOrStyleTag = false; |
| 240 } | 239 } |
| 241 | 240 |
| 242 return result; | 241 return result; |
| 243 } | 242 } |
| 244 | 243 |
| 245 // After we finish serializing end tag of a element, we give the target | 244 // After we finish serializing end tag of a element, we give the target |
| 246 // element a chance to do some post work to add some additional data. | 245 // element a chance to do some post work to add some additional data. |
| 247 String WebPageSerializerImpl::postActionAfterSerializeEndTag( | 246 String WebPageSerializerImpl::postActionAfterSerializeEndTag( |
| 248 const Element* element, SerializeDomParam* param) | 247 const Element* element, SerializeDomParam* param) |
| 249 { | 248 { |
| 250 StringBuilder result; | 249 StringBuilder result; |
| 251 | 250 |
| 252 if (!param->isHTMLDocument) | 251 if (!param->isHTMLDocument) |
| 253 return result.toString(); | 252 return result.toString(); |
| 254 // Comment the BASE tag when serializing DOM. | 253 // Comment the BASE tag when serializing DOM. |
| 255 if (element->hasTagName(HTMLNames::baseTag)) { | 254 if (isHTMLBaseElement(*element)) { |
| 256 result.append("-->"); | 255 result.append("-->"); |
| 257 // Append a new base tag declaration. | 256 // Append a new base tag declaration. |
| 258 result.append(WebPageSerializer::generateBaseTagDeclaration( | 257 result.append(WebPageSerializer::generateBaseTagDeclaration( |
| 259 param->document->baseTarget())); | 258 param->document->baseTarget())); |
| 260 } | 259 } |
| 261 | 260 |
| 262 return result.toString(); | 261 return result.toString(); |
| 263 } | 262 } |
| 264 | 263 |
| 265 void WebPageSerializerImpl::saveHTMLContentToBuffer( | 264 void WebPageSerializerImpl::saveHTMLContentToBuffer( |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 516 |
| 518 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); | 517 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); |
| 519 } | 518 } |
| 520 | 519 |
| 521 ASSERT(m_dataBuffer.isEmpty()); | 520 ASSERT(m_dataBuffer.isEmpty()); |
| 522 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali
zerClient::AllFramesAreFinished); | 521 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali
zerClient::AllFramesAreFinished); |
| 523 return didSerialization; | 522 return didSerialization; |
| 524 } | 523 } |
| 525 | 524 |
| 526 } // namespace blink | 525 } // namespace blink |
| OLD | NEW |