Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: third_party/WebKit/Source/web/WebFrameSerializer.cpp

Issue 2886943003: [Offline Pages] Adding missing image/CSS detection in FrameSerializer. (Closed)
Patch Set: unittests (merged with TOT) Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
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 std::unique_ptr<MissingImageDetector> missing_image_detector(
123 new MissingImageDetector());
dcheng 2017/05/23 05:52:41 Nit: prefer auto missing_image_detector = WTF::Mak
romax 2017/05/27 01:00:04 Done.
124 std::unique_ptr<MissingCSSDetector> missing_css_detector(
125 new MissingCSSDetector());
126 problem_detectors_.AddDetector(std::move(missing_image_detector));
127 problem_detectors_.AddDetector(std::move(missing_css_detector));
128 }
129 }
115 130
116 MHTMLFrameSerializerDelegate::~MHTMLFrameSerializerDelegate() { 131 MHTMLFrameSerializerDelegate::~MHTMLFrameSerializerDelegate() {
117 if (web_delegate_.RemovePopupOverlay()) { 132 if (web_delegate_.RemovePopupOverlay()) {
118 UMA_HISTOGRAM_BOOLEAN( 133 UMA_HISTOGRAM_BOOLEAN(
119 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped", 134 "PageSerialization.MhtmlGeneration.PopupOverlaySkipped",
120 popup_overlays_skipped_); 135 popup_overlays_skipped_);
121 } 136 }
122 } 137 }
123 138
124 bool MHTMLFrameSerializerDelegate::ShouldIgnoreElement(const Element& element) { 139 bool MHTMLFrameSerializerDelegate::ShouldIgnoreElement(const Element& element) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (isHTMLImageElement(element)) { 288 if (isHTMLImageElement(element)) {
274 GetCustomAttributesForImageElement(toHTMLImageElement(element), 289 GetCustomAttributesForImageElement(toHTMLImageElement(element),
275 &attributes); 290 &attributes);
276 } else if (element.IsFormControlElement()) { 291 } else if (element.IsFormControlElement()) {
277 GetCustomAttributesForFormControlElement(element, &attributes); 292 GetCustomAttributesForFormControlElement(element, &attributes);
278 } 293 }
279 294
280 return attributes; 295 return attributes;
281 } 296 }
282 297
298 void MHTMLFrameSerializerDelegate::VisitNode(const Node* node) {
299 problem_detectors_.VisitNode(node);
300 }
301
283 void MHTMLFrameSerializerDelegate::GetCustomAttributesForImageElement( 302 void MHTMLFrameSerializerDelegate::GetCustomAttributesForImageElement(
284 const HTMLImageElement& element, 303 const HTMLImageElement& element,
285 Vector<Attribute>* attributes) { 304 Vector<Attribute>* attributes) {
286 // Currently only the value of src is pulled into the archive and the srcset 305 // Currently only the value of src is pulled into the archive and the srcset
287 // attribute is ignored (see shouldIgnoreAttribute() above). If the device 306 // attribute is ignored (see shouldIgnoreAttribute() above). If the device
288 // has a higher DPR, a different image from srcset could be loaded instead. 307 // 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 308 // When this occurs, we should provide the rendering width and height for
290 // <img> element if not set. 309 // <img> element if not set.
291 310
292 // The image should be loaded and participate the layout. 311 // The image should be loaded and participate the layout.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 const WebString& base_target) { 498 const WebString& base_target) {
480 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 499 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
481 if (base_target.IsEmpty()) 500 if (base_target.IsEmpty())
482 return String("<base href=\".\">"); 501 return String("<base href=\".\">");
483 String base_string = "<base href=\".\" target=\"" + 502 String base_string = "<base href=\".\" target=\"" +
484 static_cast<const String&>(base_target) + "\">"; 503 static_cast<const String&>(base_target) + "\">";
485 return base_string; 504 return base_string;
486 } 505 }
487 506
488 } // namespace blink 507 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/BUILD.gn ('k') | third_party/WebKit/Source/web/WebPageMissingCSSDetector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698