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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameSerializer.cpp

Issue 2538953002: Remove hidden elements from MHTML (Closed)
Patch Set: Address feedback 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 namespace blink { 74 namespace blink {
75 75
76 namespace { 76 namespace {
77 77
78 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { 78 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
79 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); 79 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate);
80 80
81 public: 81 public:
82 explicit MHTMLFrameSerializerDelegate( 82 explicit MHTMLFrameSerializerDelegate(
83 WebFrameSerializer::MHTMLPartsGenerationDelegate&); 83 WebFrameSerializer::MHTMLPartsGenerationDelegate&);
84 bool shouldIgnoreElement(const Element&) override;
84 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; 85 bool shouldIgnoreAttribute(const Element&, const Attribute&) override;
85 bool rewriteLink(const Element&, String& rewrittenLink) override; 86 bool rewriteLink(const Element&, String& rewrittenLink) override;
86 bool shouldSkipResourceWithURL(const KURL&) override; 87 bool shouldSkipResourceWithURL(const KURL&) override;
87 bool shouldSkipResource(const Resource&) override; 88 bool shouldSkipResource(const Resource&) override;
88 89
89 private: 90 private:
90 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; 91 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate;
91 }; 92 };
92 93
93 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( 94 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate(
94 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) 95 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate)
95 : m_webDelegate(webDelegate) {} 96 : m_webDelegate(webDelegate) {}
96 97
98 bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) {
99 // Do not include elements that are hidden and affect no layout.
100 return !element.layoutObject();
tkent 2016/12/01 14:56:43 Though I suggested this, it drops <head>, <meta>,
jianli 2016/12/07 02:21:02 We don't want to drop <head>, <meta>, <style>, <li
101 }
102
97 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( 103 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(
98 const Element& element, 104 const Element& element,
99 const Attribute& attribute) { 105 const Attribute& attribute) {
100 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display 106 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display
101 // images, as only the value of src is pulled into the archive. Discarding 107 // images, as only the value of src is pulled into the archive. Discarding
102 // srcset prevents the problem. Long term we should make sure to MHTML plays 108 // srcset prevents the problem. Long term we should make sure to MHTML plays
103 // nicely with srcset. 109 // nicely with srcset.
104 if (attribute.localName() == HTMLNames::srcsetAttr) 110 if (attribute.localName() == HTMLNames::srcsetAttr)
105 return true; 111 return true;
106 112
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 const WebString& baseTarget) { 320 const WebString& baseTarget) {
315 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 321 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
316 if (baseTarget.isEmpty()) 322 if (baseTarget.isEmpty())
317 return String("<base href=\".\">"); 323 return String("<base href=\".\">");
318 String baseString = "<base href=\".\" target=\"" + 324 String baseString = "<base href=\".\" target=\"" +
319 static_cast<const String&>(baseTarget) + "\">"; 325 static_cast<const String&>(baseTarget) + "\">";
320 return baseString; 326 return baseString;
321 } 327 }
322 328
323 } // namespace blink 329 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698