| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (!param->haveSeenDocType) { | 142 if (!param->haveSeenDocType) { |
| 143 param->haveSeenDocType = true; | 143 param->haveSeenDocType = true; |
| 144 result.append(createMarkup(param->document->doctype())); | 144 result.append(createMarkup(param->document->doctype())); |
| 145 } | 145 } |
| 146 | 146 |
| 147 // Add MOTW declaration before html tag. | 147 // Add MOTW declaration before html tag. |
| 148 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx
. | 148 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx
. |
| 149 result.append(WebFrameSerializer::generateMarkOfTheWebDeclaration(pa
ram->url)); | 149 result.append(WebFrameSerializer::generateMarkOfTheWebDeclaration(pa
ram->url)); |
| 150 } else if (isHTMLBaseElement(*element)) { | 150 } else if (isHTMLBaseElement(*element)) { |
| 151 // Comment the BASE tag when serializing dom. | 151 // Comment the BASE tag when serializing dom. |
| 152 result.append("<!--"); | 152 result.appendLiteral("<!--"); |
| 153 } | 153 } |
| 154 } else { | 154 } else { |
| 155 // Write XML declaration. | 155 // Write XML declaration. |
| 156 if (!param->haveAddedXMLProcessingDirective) { | 156 if (!param->haveAddedXMLProcessingDirective) { |
| 157 param->haveAddedXMLProcessingDirective = true; | 157 param->haveAddedXMLProcessingDirective = true; |
| 158 // Get encoding info. | 158 // Get encoding info. |
| 159 String xmlEncoding = param->document->xmlEncoding(); | 159 String xmlEncoding = param->document->xmlEncoding(); |
| 160 if (xmlEncoding.isEmpty()) | 160 if (xmlEncoding.isEmpty()) |
| 161 xmlEncoding = param->document->encodingName(); | 161 xmlEncoding = param->document->encodingName(); |
| 162 if (xmlEncoding.isEmpty()) | 162 if (xmlEncoding.isEmpty()) |
| 163 xmlEncoding = UTF8Encoding().name(); | 163 xmlEncoding = UTF8Encoding().name(); |
| 164 result.append("<?xml version=\""); | 164 result.appendLiteral("<?xml version=\""); |
| 165 result.append(param->document->xmlVersion()); | 165 result.append(param->document->xmlVersion()); |
| 166 result.append("\" encoding=\""); | 166 result.appendLiteral("\" encoding=\""); |
| 167 result.append(xmlEncoding); | 167 result.append(xmlEncoding); |
| 168 if (param->document->xmlStandalone()) | 168 if (param->document->xmlStandalone()) |
| 169 result.append("\" standalone=\"yes"); | 169 result.appendLiteral("\" standalone=\"yes"); |
| 170 result.append("\"?>\n"); | 170 result.appendLiteral("\"?>\n"); |
| 171 } | 171 } |
| 172 // Add doc type declaration if original document has it. | 172 // Add doc type declaration if original document has it. |
| 173 if (!param->haveSeenDocType) { | 173 if (!param->haveSeenDocType) { |
| 174 param->haveSeenDocType = true; | 174 param->haveSeenDocType = true; |
| 175 result.append(createMarkup(param->document->doctype())); | 175 result.append(createMarkup(param->document->doctype())); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 return result.toString(); | 178 return result.toString(); |
| 179 } | 179 } |
| 180 | 180 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // element a chance to do some post work to add some additional data. | 230 // element a chance to do some post work to add some additional data. |
| 231 String WebFrameSerializerImpl::postActionAfterSerializeEndTag( | 231 String WebFrameSerializerImpl::postActionAfterSerializeEndTag( |
| 232 const Element* element, SerializeDomParam* param) | 232 const Element* element, SerializeDomParam* param) |
| 233 { | 233 { |
| 234 StringBuilder result; | 234 StringBuilder result; |
| 235 | 235 |
| 236 if (!param->isHTMLDocument) | 236 if (!param->isHTMLDocument) |
| 237 return result.toString(); | 237 return result.toString(); |
| 238 // Comment the BASE tag when serializing DOM. | 238 // Comment the BASE tag when serializing DOM. |
| 239 if (isHTMLBaseElement(*element)) { | 239 if (isHTMLBaseElement(*element)) { |
| 240 result.append("-->"); | 240 result.appendLiteral("-->"); |
| 241 // Append a new base tag declaration. | 241 // Append a new base tag declaration. |
| 242 result.append(WebFrameSerializer::generateBaseTagDeclaration( | 242 result.append(WebFrameSerializer::generateBaseTagDeclaration( |
| 243 param->document->baseTarget())); | 243 param->document->baseTarget())); |
| 244 } | 244 } |
| 245 | 245 |
| 246 return result.toString(); | 246 return result.toString(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void WebFrameSerializerImpl::saveHTMLContentToBuffer( | 249 void WebFrameSerializerImpl::saveHTMLContentToBuffer( |
| 250 const String& result, SerializeDomParam* param) | 250 const String& result, SerializeDomParam* param) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 277 // TODO(yosin): We should utilize |MarkupFormatter| here to share code, | 277 // TODO(yosin): We should utilize |MarkupFormatter| here to share code, |
| 278 // especially escaping attribute values, done by |WebEntities| |m_htmlEntities| | 278 // especially escaping attribute values, done by |WebEntities| |m_htmlEntities| |
| 279 // and |m_xmlEntities|. | 279 // and |m_xmlEntities|. |
| 280 void WebFrameSerializerImpl::appendAttribute( | 280 void WebFrameSerializerImpl::appendAttribute( |
| 281 StringBuilder& result, | 281 StringBuilder& result, |
| 282 bool isHTMLDocument, | 282 bool isHTMLDocument, |
| 283 const String& attrName, | 283 const String& attrName, |
| 284 const String& attrValue) { | 284 const String& attrValue) { |
| 285 result.append(' '); | 285 result.append(' '); |
| 286 result.append(attrName); | 286 result.append(attrName); |
| 287 result.append("=\""); | 287 result.appendLiteral("=\""); |
| 288 if (isHTMLDocument) | 288 if (isHTMLDocument) |
| 289 result.append(m_htmlEntities.convertEntitiesInString(attrValue)); | 289 result.append(m_htmlEntities.convertEntitiesInString(attrValue)); |
| 290 else | 290 else |
| 291 result.append(m_xmlEntities.convertEntitiesInString(attrValue)); | 291 result.append(m_xmlEntities.convertEntitiesInString(attrValue)); |
| 292 result.append('\"'); | 292 result.append('\"'); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void WebFrameSerializerImpl::openTagToString( | 295 void WebFrameSerializerImpl::openTagToString( |
| 296 Element* element, | 296 Element* element, |
| 297 SerializeDomParam* param) | 297 SerializeDomParam* param) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 SerializeDomParam* param) | 374 SerializeDomParam* param) |
| 375 { | 375 { |
| 376 bool needSkip; | 376 bool needSkip; |
| 377 StringBuilder result; | 377 StringBuilder result; |
| 378 // Do pre action for end tag. | 378 // Do pre action for end tag. |
| 379 result.append(preActionBeforeSerializeEndTag(element, param, &needSkip)); | 379 result.append(preActionBeforeSerializeEndTag(element, param, &needSkip)); |
| 380 if (needSkip) | 380 if (needSkip) |
| 381 return; | 381 return; |
| 382 // Write end tag when element has child/children. | 382 // Write end tag when element has child/children. |
| 383 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) { | 383 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) { |
| 384 result.append("</"); | 384 result.appendLiteral("</"); |
| 385 result.append(element->nodeName().lower()); | 385 result.append(element->nodeName().lower()); |
| 386 result.append('>'); | 386 result.append('>'); |
| 387 } else { | 387 } else { |
| 388 // Check whether we have to write end tag for empty element. | 388 // Check whether we have to write end tag for empty element. |
| 389 if (param->isHTMLDocument) { | 389 if (param->isHTMLDocument) { |
| 390 result.append('>'); | 390 result.append('>'); |
| 391 // FIXME: This code is horribly wrong. WebFrameSerializerImpl must
die. | 391 // FIXME: This code is horribly wrong. WebFrameSerializerImpl must
die. |
| 392 if (!element->isHTMLElement() || !toHTMLElement(element)->ieForbidsI
nsertHTML()) { | 392 if (!element->isHTMLElement() || !toHTMLElement(element)->ieForbidsI
nsertHTML()) { |
| 393 // We need to write end tag when it is required. | 393 // We need to write end tag when it is required. |
| 394 result.append("</"); | 394 result.appendLiteral("</"); |
| 395 result.append(element->nodeName().lower()); | 395 result.append(element->nodeName().lower()); |
| 396 result.append('>'); | 396 result.append('>'); |
| 397 } | 397 } |
| 398 } else { | 398 } else { |
| 399 // For xml base document. | 399 // For xml base document. |
| 400 result.append(" />"); | 400 result.appendLiteral(" />"); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 // Do post action for end tag. | 403 // Do post action for end tag. |
| 404 result.append(postActionAfterSerializeEndTag(element, param)); | 404 result.append(postActionAfterSerializeEndTag(element, param)); |
| 405 // Save the result to data buffer. | 405 // Save the result to data buffer. |
| 406 saveHTMLContentToBuffer(result.toString(), param); | 406 saveHTMLContentToBuffer(result.toString(), param); |
| 407 } | 407 } |
| 408 | 408 |
| 409 void WebFrameSerializerImpl::buildContentForNode( | 409 void WebFrameSerializerImpl::buildContentForNode( |
| 410 Node* node, | 410 Node* node, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 // Report empty contents for invalid URLs. | 485 // Report empty contents for invalid URLs. |
| 486 m_client->didSerializeDataForFrame( | 486 m_client->didSerializeDataForFrame( |
| 487 WebCString(), WebFrameSerializerClient::CurrentFrameIsFinished); | 487 WebCString(), WebFrameSerializerClient::CurrentFrameIsFinished); |
| 488 } | 488 } |
| 489 | 489 |
| 490 DCHECK(m_dataBuffer.isEmpty()); | 490 DCHECK(m_dataBuffer.isEmpty()); |
| 491 return didSerialization; | 491 return didSerialization; |
| 492 } | 492 } |
| 493 | 493 |
| 494 } // namespace blink | 494 } // namespace blink |
| OLD | NEW |