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