| 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 30 matching lines...) Expand all Loading... |
| 41 #include "core/css/CSSStyleRule.h" | 41 #include "core/css/CSSStyleRule.h" |
| 42 #include "core/css/CSSValueList.h" | 42 #include "core/css/CSSValueList.h" |
| 43 #include "core/css/StylePropertySet.h" | 43 #include "core/css/StylePropertySet.h" |
| 44 #include "core/css/StyleRule.h" | 44 #include "core/css/StyleRule.h" |
| 45 #include "core/css/StyleSheetContents.h" | 45 #include "core/css/StyleSheetContents.h" |
| 46 #include "core/dom/Document.h" | 46 #include "core/dom/Document.h" |
| 47 #include "core/dom/Element.h" | 47 #include "core/dom/Element.h" |
| 48 #include "core/dom/Text.h" | 48 #include "core/dom/Text.h" |
| 49 #include "core/editing/serializers/MarkupAccumulator.h" | 49 #include "core/editing/serializers/MarkupAccumulator.h" |
| 50 #include "core/fetch/FontResource.h" | 50 #include "core/fetch/FontResource.h" |
| 51 #include "core/fetch/ImageResource.h" | 51 #include "core/fetch/ImageResourceContent.h" |
| 52 #include "core/frame/LocalFrame.h" | 52 #include "core/frame/LocalFrame.h" |
| 53 #include "core/html/HTMLFrameElementBase.h" | 53 #include "core/html/HTMLFrameElementBase.h" |
| 54 #include "core/html/HTMLImageElement.h" | 54 #include "core/html/HTMLImageElement.h" |
| 55 #include "core/html/HTMLInputElement.h" | 55 #include "core/html/HTMLInputElement.h" |
| 56 #include "core/html/HTMLLinkElement.h" | 56 #include "core/html/HTMLLinkElement.h" |
| 57 #include "core/html/HTMLMetaElement.h" | 57 #include "core/html/HTMLMetaElement.h" |
| 58 #include "core/html/HTMLStyleElement.h" | 58 #include "core/html/HTMLStyleElement.h" |
| 59 #include "core/html/ImageDocument.h" | 59 #include "core/html/ImageDocument.h" |
| 60 #include "core/style/StyleFetchedImage.h" | 60 #include "core/style/StyleFetchedImage.h" |
| 61 #include "core/style/StyleImage.h" | 61 #include "core/style/StyleImage.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (element.isStyledElement()) { | 298 if (element.isStyledElement()) { |
| 299 retrieveResourcesForProperties(element.inlineStyle(), document); | 299 retrieveResourcesForProperties(element.inlineStyle(), document); |
| 300 retrieveResourcesForProperties(element.presentationAttributeStyle(), | 300 retrieveResourcesForProperties(element.presentationAttributeStyle(), |
| 301 document); | 301 document); |
| 302 } | 302 } |
| 303 | 303 |
| 304 if (isHTMLImageElement(element)) { | 304 if (isHTMLImageElement(element)) { |
| 305 HTMLImageElement& imageElement = toHTMLImageElement(element); | 305 HTMLImageElement& imageElement = toHTMLImageElement(element); |
| 306 KURL url = | 306 KURL url = |
| 307 document.completeURL(imageElement.getAttribute(HTMLNames::srcAttr)); | 307 document.completeURL(imageElement.getAttribute(HTMLNames::srcAttr)); |
| 308 ImageResource* cachedImage = imageElement.cachedImage(); | 308 ImageResourceContent* cachedImage = imageElement.cachedImage(); |
| 309 addImageToResources(cachedImage, url); | 309 addImageToResources(cachedImage, url); |
| 310 } else if (isHTMLInputElement(element)) { | 310 } else if (isHTMLInputElement(element)) { |
| 311 HTMLInputElement& inputElement = toHTMLInputElement(element); | 311 HTMLInputElement& inputElement = toHTMLInputElement(element); |
| 312 if (inputElement.type() == InputTypeNames::image && | 312 if (inputElement.type() == InputTypeNames::image && |
| 313 inputElement.imageLoader()) { | 313 inputElement.imageLoader()) { |
| 314 KURL url = inputElement.src(); | 314 KURL url = inputElement.src(); |
| 315 ImageResource* cachedImage = inputElement.imageLoader()->image(); | 315 ImageResourceContent* cachedImage = inputElement.imageLoader()->image(); |
| 316 addImageToResources(cachedImage, url); | 316 addImageToResources(cachedImage, url); |
| 317 } | 317 } |
| 318 } else if (isHTMLLinkElement(element)) { | 318 } else if (isHTMLLinkElement(element)) { |
| 319 HTMLLinkElement& linkElement = toHTMLLinkElement(element); | 319 HTMLLinkElement& linkElement = toHTMLLinkElement(element); |
| 320 if (CSSStyleSheet* sheet = linkElement.sheet()) { | 320 if (CSSStyleSheet* sheet = linkElement.sheet()) { |
| 321 KURL url = | 321 KURL url = |
| 322 document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); | 322 document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); |
| 323 serializeCSSStyleSheet(*sheet, url); | 323 serializeCSSStyleSheet(*sheet, url); |
| 324 } | 324 } |
| 325 } else if (isHTMLStyleElement(element)) { | 325 } else if (isHTMLStyleElement(element)) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 case CSSRule::kViewportRule: | 439 case CSSRule::kViewportRule: |
| 440 break; | 440 break; |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 bool FrameSerializer::shouldAddURL(const KURL& url) { | 444 bool FrameSerializer::shouldAddURL(const KURL& url) { |
| 445 return url.isValid() && !m_resourceURLs.contains(url) && | 445 return url.isValid() && !m_resourceURLs.contains(url) && |
| 446 !url.protocolIsData() && !m_delegate.shouldSkipResourceWithURL(url); | 446 !url.protocolIsData() && !m_delegate.shouldSkipResourceWithURL(url); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void FrameSerializer::addToResources(const Resource& resource, | 449 void FrameSerializer::addToResources(const String& mimeType, |
| 450 bool hasCacheControlNoStoreHeader, |
| 450 PassRefPtr<const SharedBuffer> data, | 451 PassRefPtr<const SharedBuffer> data, |
| 451 const KURL& url) { | 452 const KURL& url) { |
| 452 if (m_delegate.shouldSkipResource(resource)) | 453 if (m_delegate.shouldSkipResource(hasCacheControlNoStoreHeader)) |
| 453 return; | 454 return; |
| 454 | 455 |
| 455 if (!data) { | 456 if (!data) { |
| 456 DLOG(ERROR) << "No data for resource " << url.getString(); | 457 DLOG(ERROR) << "No data for resource " << url.getString(); |
| 457 return; | 458 return; |
| 458 } | 459 } |
| 459 | 460 |
| 460 String mimeType = resource.response().mimeType(); | |
| 461 m_resources->append(SerializedResource(url, mimeType, std::move(data))); | 461 m_resources->append(SerializedResource(url, mimeType, std::move(data))); |
| 462 m_resourceURLs.add(url); | 462 m_resourceURLs.add(url); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void FrameSerializer::addImageToResources(ImageResource* image, | 465 void FrameSerializer::addImageToResources(ImageResourceContent* image, |
| 466 const KURL& url) { | 466 const KURL& url) { |
| 467 if (!image || !image->hasImage() || image->errorOccurred() || | 467 if (!image || !image->hasImage() || image->errorOccurred() || |
| 468 !shouldAddURL(url)) | 468 !shouldAddURL(url)) |
| 469 return; | 469 return; |
| 470 | 470 |
| 471 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", | 471 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", |
| 472 "type", "image", "url", url.elidedString().utf8().data()); | 472 "type", "image", "url", url.elidedString().utf8().data()); |
| 473 double imageStartTime = monotonicallyIncreasingTime(); | 473 double imageStartTime = monotonicallyIncreasingTime(); |
| 474 | 474 |
| 475 RefPtr<const SharedBuffer> data = image->getImage()->data(); | 475 RefPtr<const SharedBuffer> data = image->getImage()->data(); |
| 476 addToResources(*image, data, url); | 476 addToResources(image->response().mimeType(), |
| 477 image->hasCacheControlNoStoreHeader(), data, url); |
| 477 | 478 |
| 478 // If we're already reporting time for CSS serialization don't report it for | 479 // If we're already reporting time for CSS serialization don't report it for |
| 479 // this image to avoid reporting the same time twice. | 480 // this image to avoid reporting the same time twice. |
| 480 if (!m_isSerializingCss) { | 481 if (!m_isSerializingCss) { |
| 481 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram, | 482 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram, |
| 482 ("PageSerialization.SerializationTime.ImageElement", 0, | 483 ("PageSerialization.SerializationTime.ImageElement", 0, |
| 483 maxSerializationTimeUmaMicroseconds, 50)); | 484 maxSerializationTimeUmaMicroseconds, 50)); |
| 484 imageHistogram.count( | 485 imageHistogram.count( |
| 485 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) * | 486 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) * |
| 486 secondsToMicroseconds)); | 487 secondsToMicroseconds)); |
| 487 } | 488 } |
| 488 } | 489 } |
| 489 | 490 |
| 490 void FrameSerializer::addFontToResources(FontResource* font) { | 491 void FrameSerializer::addFontToResources(FontResource* font) { |
| 491 if (!font || !font->isLoaded() || !font->resourceBuffer() || | 492 if (!font || !font->isLoaded() || !font->resourceBuffer() || |
| 492 !shouldAddURL(font->url())) | 493 !shouldAddURL(font->url())) |
| 493 return; | 494 return; |
| 494 | 495 |
| 495 RefPtr<const SharedBuffer> data(font->resourceBuffer()); | 496 RefPtr<const SharedBuffer> data(font->resourceBuffer()); |
| 496 | 497 |
| 497 addToResources(*font, data, font->url()); | 498 addToResources(font->response().mimeType(), |
| 499 font->hasCacheControlNoStoreHeader(), data, font->url()); |
| 498 } | 500 } |
| 499 | 501 |
| 500 void FrameSerializer::retrieveResourcesForProperties( | 502 void FrameSerializer::retrieveResourcesForProperties( |
| 501 const StylePropertySet* styleDeclaration, | 503 const StylePropertySet* styleDeclaration, |
| 502 Document& document) { | 504 Document& document) { |
| 503 if (!styleDeclaration) | 505 if (!styleDeclaration) |
| 504 return; | 506 return; |
| 505 | 507 |
| 506 // The background-image and list-style-image (for ul or ol) are the CSS | 508 // The background-image and list-style-image (for ul or ol) are the CSS |
| 507 // properties that make use of images. We iterate to make sure we include any | 509 // properties that make use of images. We iterate to make sure we include any |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 emitsMinus = ch == '-'; | 559 emitsMinus = ch == '-'; |
| 558 builder.append(ch); | 560 builder.append(ch); |
| 559 } | 561 } |
| 560 CString escapedUrl = builder.toString().ascii(); | 562 CString escapedUrl = builder.toString().ascii(); |
| 561 return String::format("saved from url=(%04d)%s", | 563 return String::format("saved from url=(%04d)%s", |
| 562 static_cast<int>(escapedUrl.length()), | 564 static_cast<int>(escapedUrl.length()), |
| 563 escapedUrl.data()); | 565 escapedUrl.data()); |
| 564 } | 566 } |
| 565 | 567 |
| 566 } // namespace blink | 568 } // namespace blink |
| OLD | NEW |