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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 #include "platform/loader/fetch/ResourceRequest.h" | 54 #include "platform/loader/fetch/ResourceRequest.h" |
55 #include "platform/loader/fetch/ResourceResponse.h" | 55 #include "platform/loader/fetch/ResourceResponse.h" |
56 #include "platform/mhtml/MHTMLArchive.h" | 56 #include "platform/mhtml/MHTMLArchive.h" |
57 #include "platform/mhtml/MHTMLParser.h" | 57 #include "platform/mhtml/MHTMLParser.h" |
58 #include "platform/weborigin/KURL.h" | 58 #include "platform/weborigin/KURL.h" |
59 #include "platform/wtf/Assertions.h" | 59 #include "platform/wtf/Assertions.h" |
60 #include "platform/wtf/Deque.h" | 60 #include "platform/wtf/Deque.h" |
61 #include "platform/wtf/HashMap.h" | 61 #include "platform/wtf/HashMap.h" |
62 #include "platform/wtf/HashSet.h" | 62 #include "platform/wtf/HashSet.h" |
63 #include "platform/wtf/Noncopyable.h" | 63 #include "platform/wtf/Noncopyable.h" |
64 #include "platform/wtf/PtrUtil.h" | |
64 #include "platform/wtf/Vector.h" | 65 #include "platform/wtf/Vector.h" |
65 #include "platform/wtf/text/StringConcatenate.h" | 66 #include "platform/wtf/text/StringConcatenate.h" |
66 #include "public/platform/WebString.h" | 67 #include "public/platform/WebString.h" |
67 #include "public/platform/WebURL.h" | 68 #include "public/platform/WebURL.h" |
68 #include "public/platform/WebURLResponse.h" | 69 #include "public/platform/WebURLResponse.h" |
69 #include "public/platform/WebVector.h" | 70 #include "public/platform/WebVector.h" |
70 #include "public/web/WebDataSource.h" | 71 #include "public/web/WebDataSource.h" |
71 #include "public/web/WebDocument.h" | 72 #include "public/web/WebDocument.h" |
72 #include "public/web/WebFrame.h" | 73 #include "public/web/WebFrame.h" |
73 #include "public/web/WebFrameSerializerCacheControlPolicy.h" | 74 #include "public/web/WebFrameSerializerCacheControlPolicy.h" |
74 #include "public/web/WebFrameSerializerClient.h" | 75 #include "public/web/WebFrameSerializerClient.h" |
75 #include "web/WebFrameSerializerImpl.h" | 76 #include "web/WebFrameSerializerImpl.h" |
77 #include "web/WebPageMissingCSSDetector.h" | |
78 #include "web/WebPageMissingImageDetector.h" | |
79 #include "web/WebPageProblemDetector.h" | |
76 #include "web/WebRemoteFrameImpl.h" | 80 #include "web/WebRemoteFrameImpl.h" |
77 | 81 |
78 namespace blink { | 82 namespace blink { |
79 | 83 |
80 namespace { | 84 namespace { |
81 | 85 |
82 const int kPopupOverlayZIndexThreshold = 50; | 86 const int kPopupOverlayZIndexThreshold = 50; |
83 | 87 |
84 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { | 88 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { |
85 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); | 89 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); |
86 | 90 |
87 public: | 91 public: |
88 explicit MHTMLFrameSerializerDelegate( | 92 explicit MHTMLFrameSerializerDelegate( |
89 WebFrameSerializer::MHTMLPartsGenerationDelegate&); | 93 WebFrameSerializer::MHTMLPartsGenerationDelegate&); |
90 ~MHTMLFrameSerializerDelegate() override; | 94 ~MHTMLFrameSerializerDelegate() override; |
91 bool ShouldIgnoreElement(const Element&) override; | 95 bool ShouldIgnoreElement(const Element&) override; |
92 bool ShouldIgnoreAttribute(const Element&, const Attribute&) override; | 96 bool ShouldIgnoreAttribute(const Element&, const Attribute&) override; |
93 bool RewriteLink(const Element&, String& rewritten_link) override; | 97 bool RewriteLink(const Element&, String& rewritten_link) override; |
94 bool ShouldSkipResourceWithURL(const KURL&) override; | 98 bool ShouldSkipResourceWithURL(const KURL&) override; |
95 bool ShouldSkipResource( | 99 bool ShouldSkipResource( |
96 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; | 100 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; |
97 Vector<Attribute> GetCustomAttributes(const Element&) override; | 101 Vector<Attribute> GetCustomAttributes(const Element&) override; |
102 void VisitNode(const Node*) override; | |
fgorski
2017/05/30 17:37:50
should we also have visiting done here?
romax
2017/06/01 20:00:06
Done.
| |
98 | 103 |
99 private: | 104 private: |
100 bool ShouldIgnoreHiddenElement(const Element&); | 105 bool ShouldIgnoreHiddenElement(const Element&); |
101 bool ShouldIgnoreMetaElement(const Element&); | 106 bool ShouldIgnoreMetaElement(const Element&); |
102 bool ShouldIgnorePopupOverlayElement(const Element&); | 107 bool ShouldIgnorePopupOverlayElement(const Element&); |
103 void GetCustomAttributesForImageElement(const HTMLImageElement&, | 108 void GetCustomAttributesForImageElement(const HTMLImageElement&, |
104 Vector<Attribute>*); | 109 Vector<Attribute>*); |
105 void GetCustomAttributesForFormControlElement(const Element&, | 110 void GetCustomAttributesForFormControlElement(const Element&, |
106 Vector<Attribute>*); | 111 Vector<Attribute>*); |
107 | 112 |
108 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate_; | 113 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate_; |
109 bool popup_overlays_skipped_; | 114 bool popup_overlays_skipped_; |
115 WebPageProblemDetectorCollection problem_detectors_; | |
110 }; | 116 }; |
111 | 117 |
112 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( | 118 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
113 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate) | 119 WebFrameSerializer::MHTMLPartsGenerationDelegate& web_delegate) |
114 : web_delegate_(web_delegate), popup_overlays_skipped_(false) {} | 120 : web_delegate_(web_delegate), popup_overlays_skipped_(false) { |
121 if (web_delegate.UsePageProblemDetectors()) { | |
122 problem_detectors_.AddDetector(WTF::MakeUnique<MissingCSSDetector>()); | |
123 problem_detectors_.AddDetector(WTF::MakeUnique<MissingImageDetector>()); | |
124 } | |
125 } | |
115 | 126 |
116 MHTMLFrameSerializerDelegate::~MHTMLFrameSerializerDelegate() { | 127 MHTMLFrameSerializerDelegate::~MHTMLFrameSerializerDelegate() { |
117 if (web_delegate_.RemovePopupOverlay()) { | 128 if (web_delegate_.RemovePopupOverlay()) { |
118 UMA_HISTOGRAM_BOOLEAN( | 129 UMA_HISTOGRAM_BOOLEAN( |
119 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", | 130 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", |
120 popup_overlays_skipped_); | 131 popup_overlays_skipped_); |
121 } | 132 } |
122 } | 133 } |
123 | 134 |
124 bool MHTMLFrameSerializerDelegate::ShouldIgnoreElement(const Element& element) { | 135 bool MHTMLFrameSerializerDelegate::ShouldIgnoreElement(const Element& element) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 if (isHTMLImageElement(element)) { | 284 if (isHTMLImageElement(element)) { |
274 GetCustomAttributesForImageElement(toHTMLImageElement(element), | 285 GetCustomAttributesForImageElement(toHTMLImageElement(element), |
275 &attributes); | 286 &attributes); |
276 } else if (element.IsFormControlElement()) { | 287 } else if (element.IsFormControlElement()) { |
277 GetCustomAttributesForFormControlElement(element, &attributes); | 288 GetCustomAttributesForFormControlElement(element, &attributes); |
278 } | 289 } |
279 | 290 |
280 return attributes; | 291 return attributes; |
281 } | 292 } |
282 | 293 |
294 void MHTMLFrameSerializerDelegate::VisitNode(const Node* node) { | |
295 problem_detectors_.VisitNode(node); | |
296 } | |
297 | |
283 void MHTMLFrameSerializerDelegate::GetCustomAttributesForImageElement( | 298 void MHTMLFrameSerializerDelegate::GetCustomAttributesForImageElement( |
284 const HTMLImageElement& element, | 299 const HTMLImageElement& element, |
285 Vector<Attribute>* attributes) { | 300 Vector<Attribute>* attributes) { |
286 // Currently only the value of src is pulled into the archive and the srcset | 301 // Currently only the value of src is pulled into the archive and the srcset |
287 // attribute is ignored (see shouldIgnoreAttribute() above). If the device | 302 // attribute is ignored (see shouldIgnoreAttribute() above). If the device |
288 // has a higher DPR, a different image from srcset could be loaded instead. | 303 // has a higher DPR, a different image from srcset could be loaded instead. |
289 // When this occurs, we should provide the rendering width and height for | 304 // When this occurs, we should provide the rendering width and height for |
290 // <img> element if not set. | 305 // <img> element if not set. |
291 | 306 |
292 // The image should be loaded and participate the layout. | 307 // The image should be loaded and participate the layout. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 const WebString& base_target) { | 494 const WebString& base_target) { |
480 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. | 495 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
481 if (base_target.IsEmpty()) | 496 if (base_target.IsEmpty()) |
482 return String("<base href=\".\">"); | 497 return String("<base href=\".\">"); |
483 String base_string = "<base href=\".\" target=\"" + | 498 String base_string = "<base href=\".\" target=\"" + |
484 static_cast<const String&>(base_target) + "\">"; | 499 static_cast<const String&>(base_target) + "\">"; |
485 return base_string; | 500 return base_string; |
486 } | 501 } |
487 | 502 |
488 } // namespace blink | 503 } // namespace blink |
OLD | NEW |