Chromium Code Reviews| Index: third_party/WebKit/Source/web/WebFrameSerializer.cpp |
| diff --git a/third_party/WebKit/Source/web/WebFrameSerializer.cpp b/third_party/WebKit/Source/web/WebFrameSerializer.cpp |
| index 9a266f1dce7545ba1fe7dfa7d3a26905d186d893..cd7c1c57e5ec8ac39183b52c368e28e187245bad 100644 |
| --- a/third_party/WebKit/Source/web/WebFrameSerializer.cpp |
| +++ b/third_party/WebKit/Source/web/WebFrameSerializer.cpp |
| @@ -34,16 +34,20 @@ |
| #include "core/dom/Document.h" |
| #include "core/dom/Element.h" |
| #include "core/frame/Frame.h" |
| +#include "core/frame/FrameHost.h" |
| #include "core/frame/FrameSerializer.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/RemoteFrame.h" |
| +#include "core/frame/VisualViewport.h" |
| #include "core/html/HTMLAllCollection.h" |
| #include "core/html/HTMLFrameElementBase.h" |
| #include "core/html/HTMLFrameOwnerElement.h" |
| #include "core/html/HTMLImageElement.h" |
| #include "core/html/HTMLInputElement.h" |
| #include "core/html/HTMLTableElement.h" |
| +#include "core/layout/LayoutBox.h" |
| #include "core/loader/DocumentLoader.h" |
| +#include "core/page/Page.h" |
| #include "platform/Histogram.h" |
| #include "platform/SerializedResource.h" |
| #include "platform/SharedBuffer.h" |
| @@ -77,6 +81,8 @@ namespace blink { |
| namespace { |
| +const int kPopupOverlayZIndexThreshold = 50; |
| + |
| class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { |
| WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); |
| @@ -92,6 +98,8 @@ class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { |
| Vector<Attribute> getCustomAttributes(const Element&) override; |
| private: |
| + bool shouldIgnoreHiddenElement(const Element&); |
| + bool shouldIgnorePopupOverlayElement(const Element&); |
| void getCustomAttributesForImageElement(const HTMLImageElement&, |
| Vector<Attribute>*); |
| void getCustomAttributesForFormControlElement(const Element&, |
| @@ -105,6 +113,17 @@ MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
| : m_webDelegate(webDelegate) {} |
| bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) { |
| + if (shouldIgnoreHiddenElement(element)) |
| + return true; |
| + if (m_webDelegate.removePopupOverlay() && |
| + shouldIgnorePopupOverlayElement(element)) { |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +bool MHTMLFrameSerializerDelegate::shouldIgnoreHiddenElement( |
| + const Element& element) { |
| // Do not include elements that are are set to hidden without affecting layout |
| // by the page. For those elements that are hidden by default, they will not |
| // be excluded: |
| @@ -121,6 +140,29 @@ bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) { |
| return parent && !isHTMLHeadElement(parent); |
| } |
| +bool MHTMLFrameSerializerDelegate::shouldIgnorePopupOverlayElement( |
| + const Element& element) { |
| + // The element should be visible. |
| + LayoutBox* box = element.layoutBox(); |
| + 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.
|
| + return false; |
| + |
| + // 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
|
| + // viewport. |
| + 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.
|
| + if (!window) |
| + return false; |
| + LayoutPoint centerPoint(window->innerWidth() / 2, window->innerHeight() / 2); |
| + if (!box->frameRect().contains(centerPoint)) |
| + return false; |
| + |
| + // The z-index should be greater than the threshold. |
| + if (box->style()->zIndex() < kPopupOverlayZIndexThreshold) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( |
| const Element& element, |
| const Attribute& attribute) { |