| 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 25 matching lines...) Expand all Loading... |
| 36 #include "core/frame/Frame.h" | 36 #include "core/frame/Frame.h" |
| 37 #include "core/frame/FrameSerializer.h" | 37 #include "core/frame/FrameSerializer.h" |
| 38 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/RemoteFrame.h" | 39 #include "core/frame/RemoteFrame.h" |
| 40 #include "core/html/HTMLAllCollection.h" | 40 #include "core/html/HTMLAllCollection.h" |
| 41 #include "core/html/HTMLFrameElementBase.h" | 41 #include "core/html/HTMLFrameElementBase.h" |
| 42 #include "core/html/HTMLFrameOwnerElement.h" | 42 #include "core/html/HTMLFrameOwnerElement.h" |
| 43 #include "core/html/HTMLImageElement.h" | 43 #include "core/html/HTMLImageElement.h" |
| 44 #include "core/html/HTMLInputElement.h" | 44 #include "core/html/HTMLInputElement.h" |
| 45 #include "core/html/HTMLTableElement.h" | 45 #include "core/html/HTMLTableElement.h" |
| 46 #include "core/layout/LayoutBox.h" |
| 46 #include "core/loader/DocumentLoader.h" | 47 #include "core/loader/DocumentLoader.h" |
| 47 #include "platform/Histogram.h" | 48 #include "platform/Histogram.h" |
| 48 #include "platform/SerializedResource.h" | 49 #include "platform/SerializedResource.h" |
| 49 #include "platform/SharedBuffer.h" | 50 #include "platform/SharedBuffer.h" |
| 50 #include "platform/instrumentation/tracing/TraceEvent.h" | 51 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 51 #include "platform/mhtml/MHTMLArchive.h" | 52 #include "platform/mhtml/MHTMLArchive.h" |
| 52 #include "platform/mhtml/MHTMLParser.h" | 53 #include "platform/mhtml/MHTMLParser.h" |
| 53 #include "platform/network/ResourceRequest.h" | 54 #include "platform/network/ResourceRequest.h" |
| 54 #include "platform/network/ResourceResponse.h" | 55 #include "platform/network/ResourceResponse.h" |
| 55 #include "platform/weborigin/KURL.h" | 56 #include "platform/weborigin/KURL.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 #include "wtf/HashMap.h" | 71 #include "wtf/HashMap.h" |
| 71 #include "wtf/HashSet.h" | 72 #include "wtf/HashSet.h" |
| 72 #include "wtf/Noncopyable.h" | 73 #include "wtf/Noncopyable.h" |
| 73 #include "wtf/Vector.h" | 74 #include "wtf/Vector.h" |
| 74 #include "wtf/text/StringConcatenate.h" | 75 #include "wtf/text/StringConcatenate.h" |
| 75 | 76 |
| 76 namespace blink { | 77 namespace blink { |
| 77 | 78 |
| 78 namespace { | 79 namespace { |
| 79 | 80 |
| 81 const int kPopupOverlayZIndexThreshold = 50; |
| 82 |
| 80 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { | 83 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { |
| 81 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); | 84 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); |
| 82 | 85 |
| 83 public: | 86 public: |
| 84 explicit MHTMLFrameSerializerDelegate( | 87 explicit MHTMLFrameSerializerDelegate( |
| 85 WebFrameSerializer::MHTMLPartsGenerationDelegate&); | 88 WebFrameSerializer::MHTMLPartsGenerationDelegate&); |
| 86 bool shouldIgnoreElement(const Element&) override; | 89 bool shouldIgnoreElement(const Element&) override; |
| 87 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; | 90 bool shouldIgnoreAttribute(const Element&, const Attribute&) override; |
| 88 bool rewriteLink(const Element&, String& rewrittenLink) override; | 91 bool rewriteLink(const Element&, String& rewrittenLink) override; |
| 89 bool shouldSkipResourceWithURL(const KURL&) override; | 92 bool shouldSkipResourceWithURL(const KURL&) override; |
| 90 bool shouldSkipResource( | 93 bool shouldSkipResource( |
| 91 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; | 94 FrameSerializer::ResourceHasCacheControlNoStoreHeader) override; |
| 92 Vector<Attribute> getCustomAttributes(const Element&) override; | 95 Vector<Attribute> getCustomAttributes(const Element&) override; |
| 93 | 96 |
| 94 private: | 97 private: |
| 98 bool shouldIgnoreHiddenElement(const Element&); |
| 99 bool shouldIgnorePopupOverlayElement(const Element&); |
| 95 void getCustomAttributesForImageElement(const HTMLImageElement&, | 100 void getCustomAttributesForImageElement(const HTMLImageElement&, |
| 96 Vector<Attribute>*); | 101 Vector<Attribute>*); |
| 97 void getCustomAttributesForFormControlElement(const Element&, | 102 void getCustomAttributesForFormControlElement(const Element&, |
| 98 Vector<Attribute>*); | 103 Vector<Attribute>*); |
| 99 | 104 |
| 100 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; | 105 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; |
| 101 }; | 106 }; |
| 102 | 107 |
| 103 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( | 108 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
| 104 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) | 109 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) |
| 105 : m_webDelegate(webDelegate) {} | 110 : m_webDelegate(webDelegate) {} |
| 106 | 111 |
| 107 bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) { | 112 bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) { |
| 113 if (shouldIgnoreHiddenElement(element)) |
| 114 return true; |
| 115 if (m_webDelegate.removePopupOverlay() && |
| 116 shouldIgnorePopupOverlayElement(element)) { |
| 117 return true; |
| 118 } |
| 119 return false; |
| 120 } |
| 121 |
| 122 bool MHTMLFrameSerializerDelegate::shouldIgnoreHiddenElement( |
| 123 const Element& element) { |
| 108 // Do not include elements that are are set to hidden without affecting layout | 124 // 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 | 125 // by the page. For those elements that are hidden by default, they will not |
| 110 // be excluded: | 126 // be excluded: |
| 111 // 1) All elements that are head or part of head, including head, meta, style, | 127 // 1) All elements that are head or part of head, including head, meta, style, |
| 112 // link and etc. | 128 // link and etc. |
| 113 // 2) Some specific elements in body: meta, style, datalist, option and etc. | 129 // 2) Some specific elements in body: meta, style, datalist, option and etc. |
| 114 if (element.layoutObject()) | 130 if (element.layoutObject()) |
| 115 return false; | 131 return false; |
| 116 if (isHTMLHeadElement(element) || isHTMLMetaElement(element) || | 132 if (isHTMLHeadElement(element) || isHTMLMetaElement(element) || |
| 117 isHTMLStyleElement(element) || isHTMLDataListElement(element) || | 133 isHTMLStyleElement(element) || isHTMLDataListElement(element) || |
| 118 isHTMLOptionElement(element)) { | 134 isHTMLOptionElement(element)) { |
| 119 return false; | 135 return false; |
| 120 } | 136 } |
| 121 Element* parent = element.parentElement(); | 137 Element* parent = element.parentElement(); |
| 122 return parent && !isHTMLHeadElement(parent); | 138 return parent && !isHTMLHeadElement(parent); |
| 123 } | 139 } |
| 124 | 140 |
| 141 bool MHTMLFrameSerializerDelegate::shouldIgnorePopupOverlayElement( |
| 142 const Element& element) { |
| 143 // The element should be visible. |
| 144 LayoutBox* box = element.layoutBox(); |
| 145 if (!box) |
| 146 return false; |
| 147 |
| 148 // The bounding box of the element should contain center point of the |
| 149 // viewport. |
| 150 LocalDOMWindow* window = element.document().domWindow(); |
| 151 DCHECK(window); |
| 152 LayoutPoint centerPoint(window->innerWidth() / 2, window->innerHeight() / 2); |
| 153 if (!box->frameRect().contains(centerPoint)) |
| 154 return false; |
| 155 |
| 156 // The z-index should be greater than the threshold. |
| 157 if (box->style()->zIndex() < kPopupOverlayZIndexThreshold) |
| 158 return false; |
| 159 |
| 160 return true; |
| 161 } |
| 162 |
| 125 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( | 163 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute( |
| 126 const Element& element, | 164 const Element& element, |
| 127 const Attribute& attribute) { | 165 const Attribute& attribute) { |
| 128 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display | 166 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display |
| 129 // images, as only the value of src is pulled into the archive. Discarding | 167 // images, as only the value of src is pulled into the archive. Discarding |
| 130 // srcset prevents the problem. Long term we should make sure to MHTML plays | 168 // srcset prevents the problem. Long term we should make sure to MHTML plays |
| 131 // nicely with srcset. | 169 // nicely with srcset. |
| 132 if (attribute.localName() == HTMLNames::srcsetAttr) | 170 if (attribute.localName() == HTMLNames::srcsetAttr) |
| 133 return true; | 171 return true; |
| 134 | 172 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 const WebString& baseTarget) { | 455 const WebString& baseTarget) { |
| 418 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. | 456 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
| 419 if (baseTarget.isEmpty()) | 457 if (baseTarget.isEmpty()) |
| 420 return String("<base href=\".\">"); | 458 return String("<base href=\".\">"); |
| 421 String baseString = "<base href=\".\" target=\"" + | 459 String baseString = "<base href=\".\" target=\"" + |
| 422 static_cast<const String&>(baseTarget) + "\">"; | 460 static_cast<const String&>(baseTarget) + "\">"; |
| 423 return baseString; | 461 return baseString; |
| 424 } | 462 } |
| 425 | 463 |
| 426 } // namespace blink | 464 } // namespace blink |
| OLD | NEW |