| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 if (m_resourceURLs.contains(url)) { | 323 if (m_resourceURLs.contains(url)) { |
| 324 // FIXME: We could have 2 frame with the same URL but which were dynamic
ally changed and have now | 324 // FIXME: We could have 2 frame with the same URL but which were dynamic
ally changed and have now |
| 325 // different content. So we should serialize both and somehow rename the
frame src in the containing | 325 // different content. So we should serialize both and somehow rename the
frame src in the containing |
| 326 // frame. Arg! | 326 // frame. Arg! |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 // If frame is an image document, add the image and don't continue | 330 // If frame is an image document, add the image and don't continue |
| 331 if (document.isImageDocument()) { | 331 if (document.isImageDocument()) { |
| 332 ImageDocument& imageDocument = toImageDocument(document); | 332 ImageDocument& imageDocument = toImageDocument(document); |
| 333 addImageToResources(imageDocument.cachedImage(), imageDocument.imageElem
ent()->layoutObject(), url); | 333 addImageToResources(imageDocument.cachedImage(), url); |
| 334 return; | 334 return; |
| 335 } | 335 } |
| 336 | 336 |
| 337 WillBeHeapVector<RawPtrWillBeMember<Node>> serializedNodes; | 337 WillBeHeapVector<RawPtrWillBeMember<Node>> serializedNodes; |
| 338 String text; | 338 String text; |
| 339 if (!m_rewriteURLs.isEmpty()) { | 339 if (!m_rewriteURLs.isEmpty()) { |
| 340 LinkChangeSerializerMarkupAccumulator accumulator(this, document, serial
izedNodes, m_rewriteURLs, m_rewriteFolder); | 340 LinkChangeSerializerMarkupAccumulator accumulator(this, document, serial
izedNodes, m_rewriteURLs, m_rewriteFolder); |
| 341 text = serializeNodes<EditingStrategy>(accumulator, document, IncludeNod
e); | 341 text = serializeNodes<EditingStrategy>(accumulator, document, IncludeNod
e); |
| 342 } else { | 342 } else { |
| 343 SerializerMarkupAccumulator accumulator(this, document, serializedNodes)
; | 343 SerializerMarkupAccumulator accumulator(this, document, serializedNodes)
; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 357 // We have to process in-line style as it might contain some resources (
typically background images). | 357 // We have to process in-line style as it might contain some resources (
typically background images). |
| 358 if (element.isStyledElement()) { | 358 if (element.isStyledElement()) { |
| 359 retrieveResourcesForProperties(element.inlineStyle(), document); | 359 retrieveResourcesForProperties(element.inlineStyle(), document); |
| 360 retrieveResourcesForProperties(element.presentationAttributeStyle(),
document); | 360 retrieveResourcesForProperties(element.presentationAttributeStyle(),
document); |
| 361 } | 361 } |
| 362 | 362 |
| 363 if (isHTMLImageElement(element)) { | 363 if (isHTMLImageElement(element)) { |
| 364 HTMLImageElement& imageElement = toHTMLImageElement(element); | 364 HTMLImageElement& imageElement = toHTMLImageElement(element); |
| 365 KURL url = document.completeURL(imageElement.getAttribute(HTMLNames:
:srcAttr)); | 365 KURL url = document.completeURL(imageElement.getAttribute(HTMLNames:
:srcAttr)); |
| 366 ImageResource* cachedImage = imageElement.cachedImage(); | 366 ImageResource* cachedImage = imageElement.cachedImage(); |
| 367 addImageToResources(cachedImage, imageElement.layoutObject(), url); | 367 addImageToResources(cachedImage, url); |
| 368 } else if (isHTMLInputElement(element)) { | 368 } else if (isHTMLInputElement(element)) { |
| 369 HTMLInputElement& inputElement = toHTMLInputElement(element); | 369 HTMLInputElement& inputElement = toHTMLInputElement(element); |
| 370 if (inputElement.type() == InputTypeNames::image && inputElement.ima
geLoader()) { | 370 if (inputElement.type() == InputTypeNames::image && inputElement.ima
geLoader()) { |
| 371 KURL url = inputElement.src(); | 371 KURL url = inputElement.src(); |
| 372 ImageResource* cachedImage = inputElement.imageLoader()->image()
; | 372 ImageResource* cachedImage = inputElement.imageLoader()->image()
; |
| 373 addImageToResources(cachedImage, inputElement.layoutObject(), ur
l); | 373 addImageToResources(cachedImage, url); |
| 374 } | 374 } |
| 375 } else if (isHTMLLinkElement(element)) { | 375 } else if (isHTMLLinkElement(element)) { |
| 376 HTMLLinkElement& linkElement = toHTMLLinkElement(element); | 376 HTMLLinkElement& linkElement = toHTMLLinkElement(element); |
| 377 if (CSSStyleSheet* sheet = linkElement.sheet()) { | 377 if (CSSStyleSheet* sheet = linkElement.sheet()) { |
| 378 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam
es::hrefAttr)); | 378 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam
es::hrefAttr)); |
| 379 serializeCSSStyleSheet(*sheet, url); | 379 serializeCSSStyleSheet(*sheet, url); |
| 380 ASSERT(m_resourceURLs.contains(url)); | 380 ASSERT(m_resourceURLs.contains(url)); |
| 381 } | 381 } |
| 382 } else if (isHTMLStyleElement(element)) { | 382 } else if (isHTMLStyleElement(element)) { |
| 383 HTMLStyleElement& styleElement = toHTMLStyleElement(element); | 383 HTMLStyleElement& styleElement = toHTMLStyleElement(element); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 if (!data) { | 482 if (!data) { |
| 483 WTF_LOG_ERROR("No data for resource %s", url.string().utf8().data()); | 483 WTF_LOG_ERROR("No data for resource %s", url.string().utf8().data()); |
| 484 return; | 484 return; |
| 485 } | 485 } |
| 486 | 486 |
| 487 String mimeType = resource->response().mimeType(); | 487 String mimeType = resource->response().mimeType(); |
| 488 m_resources->append(SerializedResource(url, mimeType, data)); | 488 m_resources->append(SerializedResource(url, mimeType, data)); |
| 489 m_resourceURLs.add(url); | 489 m_resourceURLs.add(url); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void PageSerializer::addImageToResources(ImageResource* image, LayoutObject* ima
geLayoutObject, const KURL& url) | 492 void PageSerializer::addImageToResources(ImageResource* image, const KURL& url) |
| 493 { | 493 { |
| 494 if (!shouldAddURL(url)) | 494 if (!shouldAddURL(url)) |
| 495 return; | 495 return; |
| 496 | 496 |
| 497 if (!image || !image->hasImage() || image->errorOccurred()) | 497 if (!image || !image->hasImage() || image->errorOccurred()) |
| 498 return; | 498 return; |
| 499 | 499 |
| 500 RefPtr<SharedBuffer> data = imageLayoutObject ? image->imageForLayoutObject(
imageLayoutObject)->data() : nullptr; | 500 RefPtr<SharedBuffer> data = image->image()->data(); |
| 501 if (!data) | |
| 502 data = image->image()->data(); | |
| 503 | |
| 504 addToResources(image, data, url); | 501 addToResources(image, data, url); |
| 505 } | 502 } |
| 506 | 503 |
| 507 void PageSerializer::addFontToResources(FontResource* font) | 504 void PageSerializer::addFontToResources(FontResource* font) |
| 508 { | 505 { |
| 509 if (!font || !shouldAddURL(font->url()) || !font->isLoaded() || !font->resou
rceBuffer()) | 506 if (!font || !shouldAddURL(font->url()) || !font->isLoaded() || !font->resou
rceBuffer()) |
| 510 return; | 507 return; |
| 511 | 508 |
| 512 RefPtr<SharedBuffer> data(font->resourceBuffer()); | 509 RefPtr<SharedBuffer> data(font->resourceBuffer()); |
| 513 | 510 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 532 void PageSerializer::retrieveResourcesForCSSValue(CSSValue* cssValue, Document&
document) | 529 void PageSerializer::retrieveResourcesForCSSValue(CSSValue* cssValue, Document&
document) |
| 533 { | 530 { |
| 534 if (cssValue->isImageValue()) { | 531 if (cssValue->isImageValue()) { |
| 535 CSSImageValue* imageValue = toCSSImageValue(cssValue); | 532 CSSImageValue* imageValue = toCSSImageValue(cssValue); |
| 536 if (imageValue->isCachePending()) | 533 if (imageValue->isCachePending()) |
| 537 return; | 534 return; |
| 538 StyleImage* styleImage = imageValue->cachedImage(); | 535 StyleImage* styleImage = imageValue->cachedImage(); |
| 539 if (!styleImage || !styleImage->isImageResource()) | 536 if (!styleImage || !styleImage->isImageResource()) |
| 540 return; | 537 return; |
| 541 | 538 |
| 542 addImageToResources(styleImage->cachedImage(), nullptr, styleImage->cach
edImage()->url()); | 539 addImageToResources(styleImage->cachedImage(), styleImage->cachedImage()
->url()); |
| 543 } else if (cssValue->isFontFaceSrcValue()) { | 540 } else if (cssValue->isFontFaceSrcValue()) { |
| 544 CSSFontFaceSrcValue* fontFaceSrcValue = toCSSFontFaceSrcValue(cssValue); | 541 CSSFontFaceSrcValue* fontFaceSrcValue = toCSSFontFaceSrcValue(cssValue); |
| 545 if (fontFaceSrcValue->isLocal()) { | 542 if (fontFaceSrcValue->isLocal()) { |
| 546 return; | 543 return; |
| 547 } | 544 } |
| 548 | 545 |
| 549 addFontToResources(fontFaceSrcValue->fetch(&document)); | 546 addFontToResources(fontFaceSrcValue->fetch(&document)); |
| 550 } else if (cssValue->isValueList()) { | 547 } else if (cssValue->isValueList()) { |
| 551 CSSValueList* cssValueList = toCSSValueList(cssValue); | 548 CSSValueList* cssValueList = toCSSValueList(cssValue); |
| 552 for (unsigned i = 0; i < cssValueList->length(); i++) | 549 for (unsigned i = 0; i < cssValueList->length(); i++) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 continue; | 594 continue; |
| 598 } | 595 } |
| 599 emitsMinus = ch == '-'; | 596 emitsMinus = ch == '-'; |
| 600 builder.append(ch); | 597 builder.append(ch); |
| 601 } | 598 } |
| 602 CString escapedUrl = builder.toString().ascii(); | 599 CString escapedUrl = builder.toString().ascii(); |
| 603 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); | 600 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); |
| 604 } | 601 } |
| 605 | 602 |
| 606 } // namespace blink | 603 } // namespace blink |
| OLD | NEW |