Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(730)

Unified Diff: third_party/WebKit/Source/web/WebFrameSerializer.cpp

Issue 2538953002: Remove hidden elements from MHTML (Closed)
Patch Set: Fix trybots Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/WebFrameSerializer.cpp
diff --git a/third_party/WebKit/Source/web/WebFrameSerializer.cpp b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
index 08bb2044d4172f0023cc5bf3a4b64cc5ec7ed859..7b5b8b7b0964efb233eeb50d294f1f7704b4962e 100644
--- a/third_party/WebKit/Source/web/WebFrameSerializer.cpp
+++ b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
@@ -81,6 +81,7 @@ class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
public:
explicit MHTMLFrameSerializerDelegate(
WebFrameSerializer::MHTMLPartsGenerationDelegate&);
+ bool shouldIgnoreElement(const Element&) override;
bool shouldIgnoreAttribute(const Element&, const Attribute&) override;
bool rewriteLink(const Element&, String& rewrittenLink) override;
bool shouldSkipResourceWithURL(const KURL&) override;
@@ -96,6 +97,23 @@ MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate(
WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate)
: m_webDelegate(webDelegate) {}
+bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) {
+ // Do not include elements that are are set to hidden without affecting layout
+ // by the page. For those elements that are hidden by default, they will not
+ // be excluded:
+ // 1) All elements that are head or part of head, including head, meta, style,
+ // link and etc.
+ // 2) Some specific elements in body: meta, datalist, option and etc.
+ if (element.layoutObject())
+ return false;
+ if (isHTMLHeadElement(element) || isHTMLMetaElement(element) ||
+ isHTMLDataListElement(element) || isHTMLOptionElement(element)) {
+ return false;
+ }
+ Element* parent = element.parentElement();
+ return parent && !isHTMLHeadElement(parent);
+}
+
bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(
const Element& element,
const Attribute& attribute) {

Powered by Google App Engine
This is Rietveld 408576698