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

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

Issue 2640923003: Remove popup overlay from MHTML when requested (Closed)
Patch Set: Created 3 years, 11 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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "public/web/WebFrameSerializer.h" 31 #include "public/web/WebFrameSerializer.h"
32 32
33 #include "core/HTMLNames.h" 33 #include "core/HTMLNames.h"
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/Element.h" 35 #include "core/dom/Element.h"
36 #include "core/frame/Frame.h" 36 #include "core/frame/Frame.h"
37 #include "core/frame/FrameHost.h"
37 #include "core/frame/FrameSerializer.h" 38 #include "core/frame/FrameSerializer.h"
38 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
39 #include "core/frame/RemoteFrame.h" 40 #include "core/frame/RemoteFrame.h"
41 #include "core/frame/VisualViewport.h"
40 #include "core/html/HTMLAllCollection.h" 42 #include "core/html/HTMLAllCollection.h"
41 #include "core/html/HTMLFrameElementBase.h" 43 #include "core/html/HTMLFrameElementBase.h"
42 #include "core/html/HTMLFrameOwnerElement.h" 44 #include "core/html/HTMLFrameOwnerElement.h"
43 #include "core/html/HTMLImageElement.h" 45 #include "core/html/HTMLImageElement.h"
44 #include "core/html/HTMLInputElement.h" 46 #include "core/html/HTMLInputElement.h"
45 #include "core/html/HTMLTableElement.h" 47 #include "core/html/HTMLTableElement.h"
48 #include "core/layout/LayoutBox.h"
46 #include "core/loader/DocumentLoader.h" 49 #include "core/loader/DocumentLoader.h"
50 #include "core/page/Page.h"
47 #include "platform/Histogram.h" 51 #include "platform/Histogram.h"
48 #include "platform/SerializedResource.h" 52 #include "platform/SerializedResource.h"
49 #include "platform/SharedBuffer.h" 53 #include "platform/SharedBuffer.h"
50 #include "platform/instrumentation/tracing/TraceEvent.h" 54 #include "platform/instrumentation/tracing/TraceEvent.h"
51 #include "platform/mhtml/MHTMLArchive.h" 55 #include "platform/mhtml/MHTMLArchive.h"
52 #include "platform/mhtml/MHTMLParser.h" 56 #include "platform/mhtml/MHTMLParser.h"
53 #include "platform/network/ResourceRequest.h" 57 #include "platform/network/ResourceRequest.h"
54 #include "platform/network/ResourceResponse.h" 58 #include "platform/network/ResourceResponse.h"
55 #include "platform/weborigin/KURL.h" 59 #include "platform/weborigin/KURL.h"
56 #include "public/platform/WebString.h" 60 #include "public/platform/WebString.h"
(...skipping 13 matching lines...) Expand all
70 #include "wtf/HashMap.h" 74 #include "wtf/HashMap.h"
71 #include "wtf/HashSet.h" 75 #include "wtf/HashSet.h"
72 #include "wtf/Noncopyable.h" 76 #include "wtf/Noncopyable.h"
73 #include "wtf/Vector.h" 77 #include "wtf/Vector.h"
74 #include "wtf/text/StringConcatenate.h" 78 #include "wtf/text/StringConcatenate.h"
75 79
76 namespace blink { 80 namespace blink {
77 81
78 namespace { 82 namespace {
79 83
84 const int kPopupOverlayZIndexThreshold = 50;
85
80 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { 86 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
81 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); 87 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate);
82 88
83 public: 89 public:
84 explicit MHTMLFrameSerializerDelegate( 90 explicit MHTMLFrameSerializerDelegate(
85 WebFrameSerializer::MHTMLPartsGenerationDelegate&); 91 WebFrameSerializer::MHTMLPartsGenerationDelegate&);
86 bool shouldIgnoreElement(const Element&) override; 92 bool shouldIgnoreElement(const Element&) override;
87 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; 93 bool shouldIgnoreAttribute(const Element&, const Attribute&) override;
88 bool rewriteLink(const Element&, String& rewrittenLink) override; 94 bool rewriteLink(const Element&, String& rewrittenLink) override;
89 bool shouldSkipResourceWithURL(const KURL&) override; 95 bool shouldSkipResourceWithURL(const KURL&) override;
90 bool shouldSkipResource( 96 bool shouldSkipResource(
91 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; 97 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override;
92 Vector<Attribute> getCustomAttributes(const Element&) override; 98 Vector<Attribute> getCustomAttributes(const Element&) override;
93 99
94 private: 100 private:
101 bool shouldIgnoreHiddenElement(const Element&);
102 bool shouldIgnorePopupOverlayElement(const Element&);
95 void getCustomAttributesForImageElement(const HTMLImageElement&, 103 void getCustomAttributesForImageElement(const HTMLImageElement&,
96 Vector<Attribute>*); 104 Vector<Attribute>*);
97 void getCustomAttributesForFormControlElement(const Element&, 105 void getCustomAttributesForFormControlElement(const Element&,
98 Vector<Attribute>*); 106 Vector<Attribute>*);
99 107
100 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; 108 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate;
101 }; 109 };
102 110
103 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( 111 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate(
104 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) 112 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate)
105 : m_webDelegate(webDelegate) {} 113 : m_webDelegate(webDelegate) {}
106 114
107 bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) { 115 bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) {
116 if (shouldIgnoreHiddenElement(element))
117 return true;
118 if (m_webDelegate.removePopupOverlay() &&
119 shouldIgnorePopupOverlayElement(element)) {
120 return true;
121 }
122 return false;
123 }
124
125 bool MHTMLFrameSerializerDelegate::shouldIgnoreHiddenElement(
126 const Element& element) {
108 // Do not include elements that are are set to hidden without affecting layout 127 // Do not include elements that are are set to hidden without affecting layout
109 // by the page. For those elements that are hidden by default, they will not 128 // by the page. For those elements that are hidden by default, they will not
110 // be excluded: 129 // be excluded:
111 // 1) All elements that are head or part of head, including head, meta, style, 130 // 1) All elements that are head or part of head, including head, meta, style,
112 // link and etc. 131 // link and etc.
113 // 2) Some specific elements in body: meta, datalist, option and etc. 132 // 2) Some specific elements in body: meta, datalist, option and etc.
114 if (element.layoutObject()) 133 if (element.layoutObject())
115 return false; 134 return false;
116 if (isHTMLHeadElement(element) || isHTMLMetaElement(element) || 135 if (isHTMLHeadElement(element) || isHTMLMetaElement(element) ||
117 isHTMLDataListElement(element) || isHTMLOptionElement(element)) { 136 isHTMLDataListElement(element) || isHTMLOptionElement(element)) {
118 return false; 137 return false;
119 } 138 }
120 Element* parent = element.parentElement(); 139 Element* parent = element.parentElement();
121 return parent && !isHTMLHeadElement(parent); 140 return parent && !isHTMLHeadElement(parent);
122 } 141 }
123 142
143 bool MHTMLFrameSerializerDelegate::shouldIgnorePopupOverlayElement(
144 const Element& element) {
145 // The element should be visible.
146 LayoutBox* box = element.layoutBox();
147 if (!box || box->style()->display() == EDisplay::None)
dcheng 2017/01/19 18:24:55 Note that an element styled with display:none won'
jianli 2017/01/19 23:55:22 Done.
148 return false;
149
150 // The bounding box of the element should contain center point of the
Pete Williamson 2017/01/19 18:08:28 FYI - I have seen some popups in EM pages that do
jianli 2017/01/19 23:55:22 The 1st one is covered while the 2nd one is not ha
151 // viewport.
152 LocalDOMWindow* window = element.document().domWindow();
dcheng 2017/01/19 18:24:55 Nit: DCHECK instead of guarding with if, since we
jianli 2017/01/19 23:55:22 Done.
153 if (!window)
154 return false;
155 LayoutPoint centerPoint(window->innerWidth() / 2, window->innerHeight() / 2);
156 if (!box->frameRect().contains(centerPoint))
157 return false;
158
159 // The z-index should be greater than the threshold.
160 if (box->style()->zIndex() < kPopupOverlayZIndexThreshold)
161 return false;
162
163 return true;
164 }
165
124 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( 166 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(
125 const Element& element, 167 const Element& element,
126 const Attribute& attribute) { 168 const Attribute& attribute) {
127 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display 169 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display
128 // images, as only the value of src is pulled into the archive. Discarding 170 // images, as only the value of src is pulled into the archive. Discarding
129 // srcset prevents the problem. Long term we should make sure to MHTML plays 171 // srcset prevents the problem. Long term we should make sure to MHTML plays
130 // nicely with srcset. 172 // nicely with srcset.
131 if (attribute.localName() == HTMLNames::srcsetAttr) 173 if (attribute.localName() == HTMLNames::srcsetAttr)
132 return true; 174 return true;
133 175
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 const WebString& baseTarget) { 458 const WebString& baseTarget) {
417 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 459 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
418 if (baseTarget.isEmpty()) 460 if (baseTarget.isEmpty())
419 return String("<base href=\".\">"); 461 return String("<base href=\".\">");
420 String baseString = "<base href=\".\" target=\"" + 462 String baseString = "<base href=\".\" target=\"" +
421 static_cast<const String&>(baseTarget) + "\">"; 463 static_cast<const String&>(baseTarget) + "\">";
422 return baseString; 464 return baseString;
423 } 465 }
424 466
425 } // namespace blink 467 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698