Commit 8db3aede authored by Jian Li's avatar Jian Li Committed by Commit Bot

Support serializing picture element

For picture element, we should not remove srcset attribute from
source child elements and we should add image resource for
ImageSourceURL().

Bug: 915982
Change-Id: I6374ab2177eb5c0324d4fcb036cb9b67beb90c48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662949Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670159}
parent 85451876
......@@ -235,8 +235,10 @@ bool MHTMLFrameSerializerDelegate::ShouldIgnoreAttribute(
// images, as only the value of src is pulled into the archive. Discarding
// srcset prevents the problem. Long term we should make sure to MHTML plays
// nicely with srcset.
if (attribute.LocalName() == html_names::kSrcsetAttr)
if (IsHTMLImageElement(element) &&
attribute.LocalName() == html_names::kSrcsetAttr) {
return true;
}
// Do not save ping attribute since anyway the ping will be blocked from
// MHTML.
......
......@@ -413,4 +413,24 @@ TEST_F(WebFrameSerializerSanitizationTest, StyleElementsWithDynamicCSS) {
EXPECT_EQ(WTF::kNotFound, mhtml.Find("h1 { color: green; }"));
}
TEST_F(WebFrameSerializerSanitizationTest, PictureElement) {
RegisterMockedFileURLLoad(KURL("http://www.test.com/1x.png"),
"frameserialization/1x.png");
RegisterMockedFileURLLoad(KURL("http://www.test.com/2x.png"),
"frameserialization/2x.png");
WebView()->MainFrameWidget()->Resize(WebSize(500, 500));
String mhtml = GenerateMHTMLFromHtml("http://www.test.com", "picture.html");
// srcset attribute should be kept.
EXPECT_EQ(2, MatchSubstring(mhtml, "srcset=", 7));
// 2x.png resource should be added.
EXPECT_NE(WTF::kNotFound,
mhtml.Find("Content-Location: http://www.test.com/2x.png"));
EXPECT_EQ(WTF::kNotFound,
mhtml.Find("Content-Location: http://www.test.com/1x.png"));
}
} // namespace blink
......@@ -361,8 +361,11 @@ void FrameSerializer::AddResourceForElement(Document& document,
}
if (const auto* image = ToHTMLImageElementOrNull(element)) {
KURL image_url =
document.CompleteURL(image->getAttribute(html_names::kSrcAttr));
// ImageSourceURL() works for both scenarios:
// * parent element is <picture>: best fit image URL from sibling source
// element
// * single <img> element: image url contained in href attribute
KURL image_url = document.CompleteURL(image->ImageSourceURL());
ImageResourceContent* cached_image = image->CachedImage();
AddImageToResources(cached_image, image_url);
} else if (const auto* input = ToHTMLInputElementOrNull(element)) {
......
<html>
<head>
<meta charset="utf8">
<title>Test Picture Element</title>
</head>
<body>
<picture>
<source media="(min-width: 500px)" srcset="2x.png">
<source media="(min-width: 200px)" srcset="1x.png">
<img />
</picture>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment