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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 bool needSkip; | 295 bool needSkip; |
296 StringBuilder result; | 296 StringBuilder result; |
297 // Do pre action for open tag. | 297 // Do pre action for open tag. |
298 result.append(preActionBeforeSerializeOpenTag(element, param, &needSkip)); | 298 result.append(preActionBeforeSerializeOpenTag(element, param, &needSkip)); |
299 if (needSkip) | 299 if (needSkip) |
300 return; | 300 return; |
301 // Add open tag | 301 // Add open tag |
302 result.append('<'); | 302 result.append('<'); |
303 result.append(element->nodeName().lower()); | 303 result.append(element->nodeName().lower()); |
304 // Go through all attributes and serialize them. | 304 // Go through all attributes and serialize them. |
305 if (element->hasAttributes()) { | 305 AttributeCollection attributes = element->attributes(); |
306 AttributeCollection attributes = element->attributes(); | 306 AttributeCollection::const_iterator end = attributes.end(); |
307 AttributeCollection::const_iterator end = attributes.end(); | 307 for (AttributeCollection::const_iterator it = attributes.begin(); it != end;
++it) { |
308 for (AttributeCollection::const_iterator it = attributes.begin(); it !=
end; ++it) { | 308 result.append(' '); |
309 result.append(' '); | 309 // Add attribute pair |
310 // Add attribute pair | 310 result.append(it->name().toString()); |
311 result.append(it->name().toString()); | 311 result.appendLiteral("=\""); |
312 result.appendLiteral("=\""); | 312 if (!it->value().isEmpty()) { |
313 if (!it->value().isEmpty()) { | 313 const String& attrValue = it->value(); |
314 const String& attrValue = it->value(); | |
315 | 314 |
316 // Check whether we need to replace some resource links | 315 // Check whether we need to replace some resource links |
317 // with local resource paths. | 316 // with local resource paths. |
318 const QualifiedName& attrName = it->name(); | 317 const QualifiedName& attrName = it->name(); |
319 if (element->hasLegalLinkAttribute(attrName)) { | 318 if (element->hasLegalLinkAttribute(attrName)) { |
320 // For links start with "javascript:", we do not change it. | 319 // For links start with "javascript:", we do not change it. |
321 if (attrValue.startsWith("javascript:", false)) | 320 if (attrValue.startsWith("javascript:", false)) { |
322 result.append(attrValue); | 321 result.append(attrValue); |
323 else { | 322 } else { |
324 // Get the absolute link | 323 // Get the absolute link |
325 WebLocalFrameImpl* subFrame = WebLocalFrameImpl::fromFra
meOwnerElement(element); | 324 WebLocalFrameImpl* subFrame = WebLocalFrameImpl::fromFrameOw
nerElement(element); |
326 String completeURL = subFrame ? subFrame->frame()->docum
ent()->url() : | 325 String completeURL = subFrame ? subFrame->frame()->document(
)->url() : |
327 param->document->complet
eURL(attrValue); | 326 param->document->completeURL
(attrValue); |
328 // Check whether we have local files for those link. | 327 // Check whether we have local files for those link. |
329 if (m_localLinks.contains(completeURL)) { | 328 if (m_localLinks.contains(completeURL)) { |
330 if (!param->directoryName.isEmpty()) { | 329 if (!param->directoryName.isEmpty()) { |
331 result.appendLiteral("./"); | 330 result.appendLiteral("./"); |
332 result.append(param->directoryName); | 331 result.append(param->directoryName); |
333 result.append('/'); | 332 result.append('/'); |
334 } | 333 } |
335 result.append(m_localLinks.get(completeURL)); | 334 result.append(m_localLinks.get(completeURL)); |
336 } else | 335 } else { |
337 result.append(completeURL); | 336 result.append(completeURL); |
338 } | 337 } |
339 } else { | |
340 if (param->isHTMLDocument) | |
341 result.append(m_htmlEntities.convertEntitiesInString(att
rValue)); | |
342 else | |
343 result.append(m_xmlEntities.convertEntitiesInString(attr
Value)); | |
344 } | 338 } |
| 339 } else { |
| 340 if (param->isHTMLDocument) |
| 341 result.append(m_htmlEntities.convertEntitiesInString(attrVal
ue)); |
| 342 else |
| 343 result.append(m_xmlEntities.convertEntitiesInString(attrValu
e)); |
345 } | 344 } |
346 result.append('\"'); | |
347 } | 345 } |
| 346 result.append('\"'); |
348 } | 347 } |
349 | 348 |
350 // Do post action for open tag. | 349 // Do post action for open tag. |
351 String addedContents = postActionAfterSerializeOpenTag(element, param); | 350 String addedContents = postActionAfterSerializeOpenTag(element, param); |
352 // Complete the open tag for element when it has child/children. | 351 // Complete the open tag for element when it has child/children. |
353 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) | 352 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) |
354 result.append('>'); | 353 result.append('>'); |
355 // Append the added contents generate in post action of open tag. | 354 // Append the added contents generate in post action of open tag. |
356 result.append(addedContents); | 355 result.append(addedContents); |
357 // Save the result to data buffer. | 356 // Save the result to data buffer. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 | 514 |
516 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); | 515 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); |
517 } | 516 } |
518 | 517 |
519 ASSERT(m_dataBuffer.isEmpty()); | 518 ASSERT(m_dataBuffer.isEmpty()); |
520 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali
zerClient::AllFramesAreFinished); | 519 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali
zerClient::AllFramesAreFinished); |
521 return didSerialization; | 520 return didSerialization; |
522 } | 521 } |
523 | 522 |
524 } // namespace blink | 523 } // namespace blink |
OLD | NEW |