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

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameSerializer.cpp

Issue 2538953002: Remove hidden elements from MHTML (Closed)
Patch Set: 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) 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 namespace { 73 namespace {
74 74
75 const int32_t secondsToMicroseconds = 1000 * 1000; 75 const int32_t secondsToMicroseconds = 1000 * 1000;
76 const int32_t maxSerializationTimeUmaMicroseconds = 10 * secondsToMicroseconds; 76 const int32_t maxSerializationTimeUmaMicroseconds = 10 * secondsToMicroseconds;
77 77
78 } // namespace 78 } // namespace
79 79
80 namespace blink { 80 namespace blink {
81 81
82 static bool shouldIgnoreElement(const Element& element) {
83 if (isHTMLScriptElement(element))
84 return true;
85 if (isHTMLNoScriptElement(element))
86 return true;
87 return isHTMLMetaElement(element) &&
88 toHTMLMetaElement(element).computeEncoding().isValid();
89 }
90
91 class SerializerMarkupAccumulator : public MarkupAccumulator { 82 class SerializerMarkupAccumulator : public MarkupAccumulator {
92 STACK_ALLOCATED(); 83 STACK_ALLOCATED();
93 84
94 public: 85 public:
95 SerializerMarkupAccumulator(FrameSerializer::Delegate&, 86 SerializerMarkupAccumulator(FrameSerializer::Delegate&,
96 const Document&, 87 const Document&,
97 HeapVector<Member<Node>>&); 88 HeapVector<Member<Node>>&);
98 ~SerializerMarkupAccumulator() override; 89 ~SerializerMarkupAccumulator() override;
99 90
100 protected: 91 protected:
101 void appendText(StringBuilder& out, Text&) override; 92 void appendText(StringBuilder& out, Text&) override;
102 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; 93 bool shouldIgnoreAttribute(const Element&, const Attribute&) override;
103 void appendElement(StringBuilder& out, Element&, Namespaces*) override; 94 void appendElement(StringBuilder& out, Element&, Namespaces*) override;
104 void appendAttribute(StringBuilder& out, 95 void appendAttribute(StringBuilder& out,
105 const Element&, 96 const Element&,
106 const Attribute&, 97 const Attribute&,
107 Namespaces*) override; 98 Namespaces*) override;
108 void appendStartTag(Node&, Namespaces* = nullptr) override; 99 void appendStartTag(Node&, Namespaces* = nullptr) override;
109 void appendEndTag(const Element&) override; 100 void appendEndTag(const Element&) override;
110 101
111 private: 102 private:
103 bool shouldIgnoreElement(const Element&) const;
112 void appendAttributeValue(StringBuilder& out, const String& attributeValue); 104 void appendAttributeValue(StringBuilder& out, const String& attributeValue);
113 void appendRewrittenAttribute(StringBuilder& out, 105 void appendRewrittenAttribute(StringBuilder& out,
114 const Element&, 106 const Element&,
115 const String& attributeName, 107 const String& attributeName,
116 const String& attributeValue); 108 const String& attributeValue);
117 109
118 FrameSerializer::Delegate& m_delegate; 110 FrameSerializer::Delegate& m_delegate;
119 Member<const Document> m_document; 111 Member<const Document> m_document;
120 112
121 // FIXME: |FrameSerializer| uses |m_nodes| for collecting nodes in document 113 // FIXME: |FrameSerializer| uses |m_nodes| for collecting nodes in document
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 Namespaces* namespaces) { 204 Namespaces* namespaces) {
213 MarkupAccumulator::appendStartTag(node, namespaces); 205 MarkupAccumulator::appendStartTag(node, namespaces);
214 m_nodes.append(&node); 206 m_nodes.append(&node);
215 } 207 }
216 208
217 void SerializerMarkupAccumulator::appendEndTag(const Element& element) { 209 void SerializerMarkupAccumulator::appendEndTag(const Element& element) {
218 if (!shouldIgnoreElement(element)) 210 if (!shouldIgnoreElement(element))
219 MarkupAccumulator::appendEndTag(element); 211 MarkupAccumulator::appendEndTag(element);
220 } 212 }
221 213
214 bool SerializerMarkupAccumulator::shouldIgnoreElement(
215 const Element& element) const {
216 if (isHTMLScriptElement(element))
217 return true;
218 if (isHTMLNoScriptElement(element))
219 return true;
220 if (isHTMLMetaElement(element) &&
221 toHTMLMetaElement(element).computeEncoding().isValid()) {
222 return true;
223 }
224 return m_delegate.shouldIgnoreElement(element);
carlosk 2016/11/30 23:30:22 This might be a dumb question but why is this logi
jianli 2016/12/01 02:19:38 It seems that this is useful in supporting multipl
225 }
226
222 void SerializerMarkupAccumulator::appendAttributeValue( 227 void SerializerMarkupAccumulator::appendAttributeValue(
223 StringBuilder& out, 228 StringBuilder& out,
224 const String& attributeValue) { 229 const String& attributeValue) {
225 MarkupFormatter::appendAttributeValue(out, attributeValue, 230 MarkupFormatter::appendAttributeValue(out, attributeValue,
226 m_document->isHTMLDocument()); 231 m_document->isHTMLDocument());
227 } 232 }
228 233
229 void SerializerMarkupAccumulator::appendRewrittenAttribute( 234 void SerializerMarkupAccumulator::appendRewrittenAttribute(
230 StringBuilder& out, 235 StringBuilder& out,
231 const Element& element, 236 const Element& element,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 emitsMinus = ch == '-'; 565 emitsMinus = ch == '-';
561 builder.append(ch); 566 builder.append(ch);
562 } 567 }
563 CString escapedUrl = builder.toString().ascii(); 568 CString escapedUrl = builder.toString().ascii();
564 return String::format("saved from url=(%04d)%s", 569 return String::format("saved from url=(%04d)%s",
565 static_cast<int>(escapedUrl.length()), 570 static_cast<int>(escapedUrl.length()),
566 escapedUrl.data()); 571 escapedUrl.data());
567 } 572 }
568 573
569 } // namespace blink 574 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698