| 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 29 matching lines...) Expand all Loading... |
| 40 #include "core/css/CSSStyleDeclaration.h" | 40 #include "core/css/CSSStyleDeclaration.h" |
| 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/ImageResource.h" | 50 #include "core/fetch/ImageResourceContent.h" |
| 51 #include "core/frame/LocalFrame.h" | 51 #include "core/frame/LocalFrame.h" |
| 52 #include "core/html/HTMLFrameElementBase.h" | 52 #include "core/html/HTMLFrameElementBase.h" |
| 53 #include "core/html/HTMLImageElement.h" | 53 #include "core/html/HTMLImageElement.h" |
| 54 #include "core/html/HTMLInputElement.h" | 54 #include "core/html/HTMLInputElement.h" |
| 55 #include "core/html/HTMLLinkElement.h" | 55 #include "core/html/HTMLLinkElement.h" |
| 56 #include "core/html/HTMLMetaElement.h" | 56 #include "core/html/HTMLMetaElement.h" |
| 57 #include "core/html/HTMLStyleElement.h" | 57 #include "core/html/HTMLStyleElement.h" |
| 58 #include "core/html/ImageDocument.h" | 58 #include "core/html/ImageDocument.h" |
| 59 #include "core/loader/resource/FontResource.h" | 59 #include "core/loader/resource/FontResource.h" |
| 60 #include "core/style/StyleFetchedImage.h" | 60 #include "core/style/StyleFetchedImage.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if (element.isStyledElement()) { | 311 if (element.isStyledElement()) { |
| 312 retrieveResourcesForProperties(element.inlineStyle(), document); | 312 retrieveResourcesForProperties(element.inlineStyle(), document); |
| 313 retrieveResourcesForProperties(element.presentationAttributeStyle(), | 313 retrieveResourcesForProperties(element.presentationAttributeStyle(), |
| 314 document); | 314 document); |
| 315 } | 315 } |
| 316 | 316 |
| 317 if (isHTMLImageElement(element)) { | 317 if (isHTMLImageElement(element)) { |
| 318 HTMLImageElement& imageElement = toHTMLImageElement(element); | 318 HTMLImageElement& imageElement = toHTMLImageElement(element); |
| 319 KURL url = | 319 KURL url = |
| 320 document.completeURL(imageElement.getAttribute(HTMLNames::srcAttr)); | 320 document.completeURL(imageElement.getAttribute(HTMLNames::srcAttr)); |
| 321 ImageResource* cachedImage = imageElement.cachedImage(); | 321 ImageResourceContent* cachedImage = imageElement.cachedImage(); |
| 322 addImageToResources(cachedImage, url); | 322 addImageToResources(cachedImage, url); |
| 323 } else if (isHTMLInputElement(element)) { | 323 } else if (isHTMLInputElement(element)) { |
| 324 HTMLInputElement& inputElement = toHTMLInputElement(element); | 324 HTMLInputElement& inputElement = toHTMLInputElement(element); |
| 325 if (inputElement.type() == InputTypeNames::image && | 325 if (inputElement.type() == InputTypeNames::image && |
| 326 inputElement.imageLoader()) { | 326 inputElement.imageLoader()) { |
| 327 KURL url = inputElement.src(); | 327 KURL url = inputElement.src(); |
| 328 ImageResource* cachedImage = inputElement.imageLoader()->image(); | 328 ImageResourceContent* cachedImage = inputElement.imageLoader()->image(); |
| 329 addImageToResources(cachedImage, url); | 329 addImageToResources(cachedImage, url); |
| 330 } | 330 } |
| 331 } else if (isHTMLLinkElement(element)) { | 331 } else if (isHTMLLinkElement(element)) { |
| 332 HTMLLinkElement& linkElement = toHTMLLinkElement(element); | 332 HTMLLinkElement& linkElement = toHTMLLinkElement(element); |
| 333 if (CSSStyleSheet* sheet = linkElement.sheet()) { | 333 if (CSSStyleSheet* sheet = linkElement.sheet()) { |
| 334 KURL url = | 334 KURL url = |
| 335 document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); | 335 document.completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); |
| 336 serializeCSSStyleSheet(*sheet, url); | 336 serializeCSSStyleSheet(*sheet, url); |
| 337 } | 337 } |
| 338 } else if (isHTMLStyleElement(element)) { | 338 } else if (isHTMLStyleElement(element)) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 case CSSRule::kViewportRule: | 452 case CSSRule::kViewportRule: |
| 453 break; | 453 break; |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 | 456 |
| 457 bool FrameSerializer::shouldAddURL(const KURL& url) { | 457 bool FrameSerializer::shouldAddURL(const KURL& url) { |
| 458 return url.isValid() && !m_resourceURLs.contains(url) && | 458 return url.isValid() && !m_resourceURLs.contains(url) && |
| 459 !url.protocolIsData() && !m_delegate.shouldSkipResourceWithURL(url); | 459 !url.protocolIsData() && !m_delegate.shouldSkipResourceWithURL(url); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void FrameSerializer::addToResources(const Resource& resource, | 462 void FrameSerializer::addToResources( |
| 463 PassRefPtr<const SharedBuffer> data, | 463 const String& mimeType, |
| 464 const KURL& url) { | 464 ResourceHasCacheControlNoStoreHeader hasCacheControlNoStoreHeader, |
| 465 if (m_delegate.shouldSkipResource(resource)) | 465 PassRefPtr<const SharedBuffer> data, |
| 466 const KURL& url) { |
| 467 if (m_delegate.shouldSkipResource(hasCacheControlNoStoreHeader)) |
| 466 return; | 468 return; |
| 467 | 469 |
| 468 if (!data) { | 470 if (!data) { |
| 469 DLOG(ERROR) << "No data for resource " << url.getString(); | 471 DLOG(ERROR) << "No data for resource " << url.getString(); |
| 470 return; | 472 return; |
| 471 } | 473 } |
| 472 | 474 |
| 473 String mimeType = resource.response().mimeType(); | |
| 474 m_resources->append(SerializedResource(url, mimeType, std::move(data))); | 475 m_resources->append(SerializedResource(url, mimeType, std::move(data))); |
| 475 m_resourceURLs.add(url); | 476 m_resourceURLs.add(url); |
| 476 } | 477 } |
| 477 | 478 |
| 478 void FrameSerializer::addImageToResources(ImageResource* image, | 479 void FrameSerializer::addImageToResources(ImageResourceContent* image, |
| 479 const KURL& url) { | 480 const KURL& url) { |
| 480 if (!image || !image->hasImage() || image->errorOccurred() || | 481 if (!image || !image->hasImage() || image->errorOccurred() || |
| 481 !shouldAddURL(url)) | 482 !shouldAddURL(url)) |
| 482 return; | 483 return; |
| 483 | 484 |
| 484 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", | 485 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", |
| 485 "type", "image", "url", url.elidedString().utf8().data()); | 486 "type", "image", "url", url.elidedString().utf8().data()); |
| 486 double imageStartTime = monotonicallyIncreasingTime(); | 487 double imageStartTime = monotonicallyIncreasingTime(); |
| 487 | 488 |
| 488 RefPtr<const SharedBuffer> data = image->getImage()->data(); | 489 RefPtr<const SharedBuffer> data = image->getImage()->data(); |
| 489 addToResources(*image, data, url); | 490 addToResources(image->response().mimeType(), |
| 491 image->hasCacheControlNoStoreHeader() |
| 492 ? HasCacheControlNoStoreHeader |
| 493 : NoCacheControlNoStoreHeader, |
| 494 data, url); |
| 490 | 495 |
| 491 // If we're already reporting time for CSS serialization don't report it for | 496 // If we're already reporting time for CSS serialization don't report it for |
| 492 // this image to avoid reporting the same time twice. | 497 // this image to avoid reporting the same time twice. |
| 493 if (!m_isSerializingCss) { | 498 if (!m_isSerializingCss) { |
| 494 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram, | 499 DEFINE_STATIC_LOCAL(CustomCountHistogram, imageHistogram, |
| 495 ("PageSerialization.SerializationTime.ImageElement", 0, | 500 ("PageSerialization.SerializationTime.ImageElement", 0, |
| 496 maxSerializationTimeUmaMicroseconds, 50)); | 501 maxSerializationTimeUmaMicroseconds, 50)); |
| 497 imageHistogram.count( | 502 imageHistogram.count( |
| 498 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) * | 503 static_cast<int64_t>((monotonicallyIncreasingTime() - imageStartTime) * |
| 499 secondsToMicroseconds)); | 504 secondsToMicroseconds)); |
| 500 } | 505 } |
| 501 } | 506 } |
| 502 | 507 |
| 503 void FrameSerializer::addFontToResources(FontResource* font) { | 508 void FrameSerializer::addFontToResources(FontResource* font) { |
| 504 if (!font || !font->isLoaded() || !font->resourceBuffer() || | 509 if (!font || !font->isLoaded() || !font->resourceBuffer() || |
| 505 !shouldAddURL(font->url())) | 510 !shouldAddURL(font->url())) |
| 506 return; | 511 return; |
| 507 | 512 |
| 508 RefPtr<const SharedBuffer> data(font->resourceBuffer()); | 513 RefPtr<const SharedBuffer> data(font->resourceBuffer()); |
| 509 | 514 |
| 510 addToResources(*font, data, font->url()); | 515 addToResources(font->response().mimeType(), |
| 516 font->hasCacheControlNoStoreHeader() |
| 517 ? HasCacheControlNoStoreHeader |
| 518 : NoCacheControlNoStoreHeader, |
| 519 data, font->url()); |
| 511 } | 520 } |
| 512 | 521 |
| 513 void FrameSerializer::retrieveResourcesForProperties( | 522 void FrameSerializer::retrieveResourcesForProperties( |
| 514 const StylePropertySet* styleDeclaration, | 523 const StylePropertySet* styleDeclaration, |
| 515 Document& document) { | 524 Document& document) { |
| 516 if (!styleDeclaration) | 525 if (!styleDeclaration) |
| 517 return; | 526 return; |
| 518 | 527 |
| 519 // The background-image and list-style-image (for ul or ol) are the CSS | 528 // The background-image and list-style-image (for ul or ol) are the CSS |
| 520 // properties that make use of images. We iterate to make sure we include any | 529 // 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... |
| 570 emitsMinus = ch == '-'; | 579 emitsMinus = ch == '-'; |
| 571 builder.append(ch); | 580 builder.append(ch); |
| 572 } | 581 } |
| 573 CString escapedUrl = builder.toString().ascii(); | 582 CString escapedUrl = builder.toString().ascii(); |
| 574 return String::format("saved from url=(%04d)%s", | 583 return String::format("saved from url=(%04d)%s", |
| 575 static_cast<int>(escapedUrl.length()), | 584 static_cast<int>(escapedUrl.length()), |
| 576 escapedUrl.data()); | 585 escapedUrl.data()); |
| 577 } | 586 } |
| 578 | 587 |
| 579 } // namespace blink | 588 } // namespace blink |
| OLD | NEW |