OLD | NEW |
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 Loading... |
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( | 88 bool shouldSkipResource( |
88 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; | 89 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; |
89 Vector<Attribute> getCustomAttributes(const Element&) override; | 90 Vector<Attribute> getCustomAttributes(const Element&) override; |
90 | 91 |
91 private: | 92 private: |
92 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; | 93 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; |
93 }; | 94 }; |
94 | 95 |
95 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( | 96 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
96 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) | 97 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) |
97 : m_webDelegate(webDelegate) {} | 98 : m_webDelegate(webDelegate) {} |
98 | 99 |
| 100 bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) { |
| 101 // Do not include elements that are are set to hidden without affecting layout |
| 102 // by the page. For those elements that are hidden by default, they will not |
| 103 // be excluded: |
| 104 // 1) All elements that are head or part of head, including head, meta, style, |
| 105 // link and etc. |
| 106 // 2) Some specific elements in body: meta, datalist, option and etc. |
| 107 if (element.layoutObject()) |
| 108 return false; |
| 109 if (isHTMLHeadElement(element) || isHTMLMetaElement(element) || |
| 110 isHTMLDataListElement(element) || isHTMLOptionElement(element)) { |
| 111 return false; |
| 112 } |
| 113 Element* parent = element.parentElement(); |
| 114 return parent && !isHTMLHeadElement(parent); |
| 115 } |
| 116 |
99 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( | 117 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( |
100 const Element& element, | 118 const Element& element, |
101 const Attribute& attribute) { | 119 const Attribute& attribute) { |
102 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display | 120 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display |
103 // images, as only the value of src is pulled into the archive. Discarding | 121 // images, as only the value of src is pulled into the archive. Discarding |
104 // srcset prevents the problem. Long term we should make sure to MHTML plays | 122 // srcset prevents the problem. Long term we should make sure to MHTML plays |
105 // nicely with srcset. | 123 // nicely with srcset. |
106 if (attribute.localName() == HTMLNames::srcsetAttr) | 124 if (attribute.localName() == HTMLNames::srcsetAttr) |
107 return true; | 125 return true; |
108 | 126 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 const WebString& baseTarget) { | 361 const WebString& baseTarget) { |
344 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. | 362 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
345 if (baseTarget.isEmpty()) | 363 if (baseTarget.isEmpty()) |
346 return String("<base href=\".\">"); | 364 return String("<base href=\".\">"); |
347 String baseString = "<base href=\".\" target=\"" + | 365 String baseString = "<base href=\".\" target=\"" + |
348 static_cast<const String&>(baseTarget) + "\">"; | 366 static_cast<const String&>(baseTarget) + "\">"; |
349 return baseString; | 367 return baseString; |
350 } | 368 } |
351 | 369 |
352 } // namespace blink | 370 } // namespace blink |
OLD | NEW |