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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 namespace { | 80 namespace { |
81 | 81 |
82 const int kPopupOverlayZIndexThreshold = 50; | 82 const int kPopupOverlayZIndexThreshold = 50; |
83 | 83 |
84 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { | 84 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { |
85 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); | 85 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); |
86 | 86 |
87 public: | 87 public: |
88 explicit MHTMLFrameSerializerDelegate( | 88 explicit MHTMLFrameSerializerDelegate( |
89 WebFrameSerializer::MHTMLPartsGenerationDelegate&); | 89 WebFrameSerializer::MHTMLPartsGenerationDelegate&); |
| 90 ~MHTMLFrameSerializerDelegate() override; |
90 bool ShouldIgnoreElement(const Element&) override; | 91 bool ShouldIgnoreElement(const Element&) override; |
91 bool ShouldIgnoreAttribute(const Element&, const Attribute&) override; | 92 bool ShouldIgnoreAttribute(const Element&, const Attribute&) override; |
92 bool RewriteLink(const Element&, String& rewritten_link) override; | 93 bool RewriteLink(const Element&, String& rewritten_link) override; |
93 bool ShouldSkipResourceWithURL(const KURL&) override; | 94 bool ShouldSkipResourceWithURL(const KURL&) override; |
94 bool ShouldSkipResource( | 95 bool ShouldSkipResource( |
95 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; | 96 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; |
96 Vector<Attribute> GetCustomAttributes(const Element&) override; | 97 Vector<Attribute> GetCustomAttributes(const Element&) override; |
97 | 98 |
98 private: | 99 private: |
99 bool ShouldIgnoreHiddenElement(const Element&); | 100 bool ShouldIgnoreHiddenElement(const Element&); |
100 bool ShouldIgnoreMetaElement(const Element&); | 101 bool ShouldIgnoreMetaElement(const Element&); |
101 bool ShouldIgnorePopupOverlayElement(const Element&); | 102 bool ShouldIgnorePopupOverlayElement(const Element&); |
102 void GetCustomAttributesForImageElement(const HTMLImageElement&, | 103 void GetCustomAttributesForImageElement(const HTMLImageElement&, |
103 Vector<Attribute>*); | 104 Vector<Attribute>*); |
104 void GetCustomAttributesForFormControlElement(const Element&, | 105 void GetCustomAttributesForFormControlElement(const Element&, |
105 Vector<Attribute>*); | 106 Vector<Attribute>*); |
106 | 107 |
107 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate_; | 108 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate_; |
| 109 bool popup_overlays_skipped_; |
108 }; | 110 }; |
109 | 111 |
110 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( | 112 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
111 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate) | 113 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate) |
112 : web_delegate_(web_delegate) {} | 114 : web_delegate_(web_delegate), popup_overlays_skipped_(false) {} |
| 115 |
| 116 MHTMLFrameSerializerDelegate::~MHTMLFrameSerializerDelegate() { |
| 117 if (web_delegate_.RemovePopupOverlay()) { |
| 118 UMA_HISTOGRAM_BOOLEAN( |
| 119 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", |
| 120 popup_overlays_skipped_); |
| 121 } |
| 122 } |
113 | 123 |
114 bool MHTMLFrameSerializerDelegate::ShouldIgnoreElement(const Element& element) { | 124 bool MHTMLFrameSerializerDelegate::ShouldIgnoreElement(const Element& element) { |
115 if (ShouldIgnoreHiddenElement(element)) | 125 if (ShouldIgnoreHiddenElement(element)) |
116 return true; | 126 return true; |
117 if (ShouldIgnoreMetaElement(element)) | 127 if (ShouldIgnoreMetaElement(element)) |
118 return true; | 128 return true; |
119 if (web_delegate_.RemovePopupOverlay() && | 129 if (web_delegate_.RemovePopupOverlay() && |
120 ShouldIgnorePopupOverlayElement(element)) { | 130 ShouldIgnorePopupOverlayElement(element)) { |
121 return true; | 131 return true; |
122 } | 132 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 LocalDOMWindow* window = element.GetDocument().domWindow(); | 173 LocalDOMWindow* window = element.GetDocument().domWindow(); |
164 DCHECK(window); | 174 DCHECK(window); |
165 LayoutPoint center_point(window->innerWidth() / 2, window->innerHeight() / 2); | 175 LayoutPoint center_point(window->innerWidth() / 2, window->innerHeight() / 2); |
166 if (!box->FrameRect().Contains(center_point)) | 176 if (!box->FrameRect().Contains(center_point)) |
167 return false; | 177 return false; |
168 | 178 |
169 // The z-index should be greater than the threshold. | 179 // The z-index should be greater than the threshold. |
170 if (box->Style()->ZIndex() < kPopupOverlayZIndexThreshold) | 180 if (box->Style()->ZIndex() < kPopupOverlayZIndexThreshold) |
171 return false; | 181 return false; |
172 | 182 |
| 183 popup_overlays_skipped_ = true; |
| 184 |
173 return true; | 185 return true; |
174 } | 186 } |
175 | 187 |
176 bool MHTMLFrameSerializerDelegate::ShouldIgnoreAttribute( | 188 bool MHTMLFrameSerializerDelegate::ShouldIgnoreAttribute( |
177 const Element& element, | 189 const Element& element, |
178 const Attribute& attribute) { | 190 const Attribute& attribute) { |
179 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display | 191 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display |
180 // images, as only the value of src is pulled into the archive. Discarding | 192 // images, as only the value of src is pulled into the archive. Discarding |
181 // srcset prevents the problem. Long term we should make sure to MHTML plays | 193 // srcset prevents the problem. Long term we should make sure to MHTML plays |
182 // nicely with srcset. | 194 // nicely with srcset. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 const WebString& base_target) { | 472 const WebString& base_target) { |
461 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. | 473 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
462 if (base_target.IsEmpty()) | 474 if (base_target.IsEmpty()) |
463 return String("<base href=\".\">"); | 475 return String("<base href=\".\">"); |
464 String base_string = "<base href=\".\" target=\"" + | 476 String base_string = "<base href=\".\" target=\"" + |
465 static_cast<const String&>(base_target) + "\">"; | 477 static_cast<const String&>(base_target) + "\">"; |
466 return base_string; | 478 return base_string; |
467 } | 479 } |
468 | 480 |
469 } // namespace blink | 481 } // namespace blink |
OLD | NEW |