| OLD | NEW |
| 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 Loading... |
| 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 appendCustomAttributes(StringBuilder&, | 92 void appendCustomAttributes(StringBuilder&, |
| 102 const Element&, | 93 const Element&, |
| 103 Namespaces*) override; | 94 Namespaces*) override; |
| 104 void appendText(StringBuilder& out, Text&) override; | 95 void appendText(StringBuilder& out, Text&) override; |
| 105 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; | 96 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; |
| 106 void appendElement(StringBuilder& out, Element&, Namespaces*) override; | 97 void appendElement(StringBuilder& out, Element&, Namespaces*) override; |
| 107 void appendAttribute(StringBuilder& out, | 98 void appendAttribute(StringBuilder& out, |
| 108 const Element&, | 99 const Element&, |
| 109 const Attribute&, | 100 const Attribute&, |
| 110 Namespaces*) override; | 101 Namespaces*) override; |
| 111 void appendStartTag(Node&, Namespaces* = nullptr) override; | 102 void appendStartTag(Node&, Namespaces* = nullptr) override; |
| 112 void appendEndTag(const Element&) override; | 103 void appendEndTag(const Element&) override; |
| 113 | 104 |
| 114 private: | 105 private: |
| 106 bool shouldIgnoreElement(const Element&) const; |
| 115 void appendAttributeValue(StringBuilder& out, const String& attributeValue); | 107 void appendAttributeValue(StringBuilder& out, const String& attributeValue); |
| 116 void appendRewrittenAttribute(StringBuilder& out, | 108 void appendRewrittenAttribute(StringBuilder& out, |
| 117 const Element&, | 109 const Element&, |
| 118 const String& attributeName, | 110 const String& attributeName, |
| 119 const String& attributeValue); | 111 const String& attributeValue); |
| 120 | 112 |
| 121 FrameSerializer::Delegate& m_delegate; | 113 FrameSerializer::Delegate& m_delegate; |
| 122 Member<const Document> m_document; | 114 Member<const Document> m_document; |
| 123 | 115 |
| 124 // FIXME: |FrameSerializer| uses |m_nodes| for collecting nodes in document | 116 // FIXME: |FrameSerializer| uses |m_nodes| for collecting nodes in document |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 Namespaces* namespaces) { | 216 Namespaces* namespaces) { |
| 225 MarkupAccumulator::appendStartTag(node, namespaces); | 217 MarkupAccumulator::appendStartTag(node, namespaces); |
| 226 m_nodes.push_back(&node); | 218 m_nodes.push_back(&node); |
| 227 } | 219 } |
| 228 | 220 |
| 229 void SerializerMarkupAccumulator::appendEndTag(const Element& element) { | 221 void SerializerMarkupAccumulator::appendEndTag(const Element& element) { |
| 230 if (!shouldIgnoreElement(element)) | 222 if (!shouldIgnoreElement(element)) |
| 231 MarkupAccumulator::appendEndTag(element); | 223 MarkupAccumulator::appendEndTag(element); |
| 232 } | 224 } |
| 233 | 225 |
| 226 bool SerializerMarkupAccumulator::shouldIgnoreElement( |
| 227 const Element& element) const { |
| 228 if (isHTMLScriptElement(element)) |
| 229 return true; |
| 230 if (isHTMLNoScriptElement(element)) |
| 231 return true; |
| 232 if (isHTMLMetaElement(element) && |
| 233 toHTMLMetaElement(element).computeEncoding().isValid()) { |
| 234 return true; |
| 235 } |
| 236 return m_delegate.shouldIgnoreElement(element); |
| 237 } |
| 238 |
| 234 void SerializerMarkupAccumulator::appendAttributeValue( | 239 void SerializerMarkupAccumulator::appendAttributeValue( |
| 235 StringBuilder& out, | 240 StringBuilder& out, |
| 236 const String& attributeValue) { | 241 const String& attributeValue) { |
| 237 MarkupFormatter::appendAttributeValue(out, attributeValue, | 242 MarkupFormatter::appendAttributeValue(out, attributeValue, |
| 238 m_document->isHTMLDocument()); | 243 m_document->isHTMLDocument()); |
| 239 } | 244 } |
| 240 | 245 |
| 241 void SerializerMarkupAccumulator::appendRewrittenAttribute( | 246 void SerializerMarkupAccumulator::appendRewrittenAttribute( |
| 242 StringBuilder& out, | 247 StringBuilder& out, |
| 243 const Element& element, | 248 const Element& element, |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 emitsMinus = ch == '-'; | 584 emitsMinus = ch == '-'; |
| 580 builder.append(ch); | 585 builder.append(ch); |
| 581 } | 586 } |
| 582 CString escapedUrl = builder.toString().ascii(); | 587 CString escapedUrl = builder.toString().ascii(); |
| 583 return String::format("saved from url=(%04d)%s", | 588 return String::format("saved from url=(%04d)%s", |
| 584 static_cast<int>(escapedUrl.length()), | 589 static_cast<int>(escapedUrl.length()), |
| 585 escapedUrl.data()); | 590 escapedUrl.data()); |
| 586 } | 591 } |
| 587 | 592 |
| 588 } // namespace blink | 593 } // namespace blink |
| OLD | NEW |