Commit b694f8d5 authored by Jian Li's avatar Jian Li Committed by Commit Bot

Support saving image resource in object or embed element

Bug: 553478
Change-Id: I3407201b6542c01806766887cb66591cb3c9a8e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1672453Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Jian Li <jianli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671752}
parent 1495d8e1
...@@ -433,4 +433,20 @@ TEST_F(WebFrameSerializerSanitizationTest, PictureElement) { ...@@ -433,4 +433,20 @@ TEST_F(WebFrameSerializerSanitizationTest, PictureElement) {
mhtml.Find("Content-Location: http://www.test.com/1x.png")); mhtml.Find("Content-Location: http://www.test.com/1x.png"));
} }
TEST_F(WebFrameSerializerSanitizationTest, ImageInPluginElement) {
RegisterMockedFileURLLoad(KURL("http://www.test.com/1x.png"),
"frameserialization/1x.png");
RegisterMockedFileURLLoad(KURL("http://www.test.com/2x.png"),
"frameserialization/2x.png");
String mhtml =
GenerateMHTMLFromHtml("http://www.test.com", "image_in_plugin.html");
// Image resources for both object and embed elements should be added.
EXPECT_NE(WTF::kNotFound,
mhtml.Find("Content-Location: http://www.test.com/1x.png"));
EXPECT_NE(WTF::kNotFound,
mhtml.Find("Content-Location: http://www.test.com/2x.png"));
}
} // namespace blink } // namespace blink
...@@ -50,8 +50,10 @@ ...@@ -50,8 +50,10 @@
#include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h" #include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/html/html_image_element.h" #include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/html/html_image_loader.h"
#include "third_party/blink/renderer/core/html/html_link_element.h" #include "third_party/blink/renderer/core/html/html_link_element.h"
#include "third_party/blink/renderer/core/html/html_meta_element.h" #include "third_party/blink/renderer/core/html/html_meta_element.h"
#include "third_party/blink/renderer/core/html/html_plugin_element.h"
#include "third_party/blink/renderer/core/html/html_style_element.h" #include "third_party/blink/renderer/core/html/html_style_element.h"
#include "third_party/blink/renderer/core/html/image_document.h" #include "third_party/blink/renderer/core/html/image_document.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
...@@ -383,6 +385,13 @@ void FrameSerializer::AddResourceForElement(Document& document, ...@@ -383,6 +385,13 @@ void FrameSerializer::AddResourceForElement(Document& document,
} else if (const auto* style = ToHTMLStyleElementOrNull(element)) { } else if (const auto* style = ToHTMLStyleElementOrNull(element)) {
if (CSSStyleSheet* sheet = style->sheet()) if (CSSStyleSheet* sheet = style->sheet())
SerializeCSSStyleSheet(*sheet, NullURL()); SerializeCSSStyleSheet(*sheet, NullURL());
} else if (IsHTMLPlugInElement(element)) {
const auto* plugin = ToHTMLPlugInElement(&element);
if (plugin->IsImageType() && plugin->ImageLoader()) {
KURL image_url = document.CompleteURL(plugin->Url());
ImageResourceContent* cached_image = plugin->ImageLoader()->GetContent();
AddImageToResources(cached_image, image_url);
}
} }
} }
......
...@@ -103,6 +103,9 @@ class CORE_EXPORT HTMLPlugInElement ...@@ -103,6 +103,9 @@ class CORE_EXPORT HTMLPlugInElement
ParsedFeaturePolicy ConstructContainerPolicy( ParsedFeaturePolicy ConstructContainerPolicy(
Vector<String>* /* messages */) const override; Vector<String>* /* messages */) const override;
bool IsImageType() const;
HTMLImageLoader* ImageLoader() const { return image_loader_.Get(); }
protected: protected:
HTMLPlugInElement(const QualifiedName& tag_name, HTMLPlugInElement(const QualifiedName& tag_name,
Document&, Document&,
...@@ -127,7 +130,6 @@ class CORE_EXPORT HTMLPlugInElement ...@@ -127,7 +130,6 @@ class CORE_EXPORT HTMLPlugInElement
// if necessary. // if necessary.
virtual LayoutEmbeddedContent* LayoutEmbeddedContentForJSBindings() const; virtual LayoutEmbeddedContent* LayoutEmbeddedContentForJSBindings() const;
bool IsImageType() const;
LayoutEmbeddedObject* GetLayoutEmbeddedObject() const; LayoutEmbeddedObject* GetLayoutEmbeddedObject() const;
bool AllowedToLoadFrameURL(const String& url); bool AllowedToLoadFrameURL(const String& url);
bool RequestObject(const PluginParameters& plugin_params); bool RequestObject(const PluginParameters& plugin_params);
......
<html>
<head>
<meta charset="utf8">
<title>Test Image in Plugin Element</title>
</head>
<body>
<object data="1x.png" ></object>
<embed src="2x.png"></embed>
</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