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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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/WebPageSerializer.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/FrameSerializer.h" |
37 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
38 #include "core/frame/RemoteFrame.h" | 39 #include "core/frame/RemoteFrame.h" |
39 #include "core/html/HTMLAllCollection.h" | 40 #include "core/html/HTMLAllCollection.h" |
40 #include "core/html/HTMLFrameElementBase.h" | 41 #include "core/html/HTMLFrameElementBase.h" |
41 #include "core/html/HTMLFrameOwnerElement.h" | 42 #include "core/html/HTMLFrameOwnerElement.h" |
42 #include "core/html/HTMLInputElement.h" | 43 #include "core/html/HTMLInputElement.h" |
43 #include "core/html/HTMLTableElement.h" | 44 #include "core/html/HTMLTableElement.h" |
44 #include "core/loader/DocumentLoader.h" | 45 #include "core/loader/DocumentLoader.h" |
45 #include "core/page/PageSerializer.h" | |
46 #include "platform/SerializedResource.h" | 46 #include "platform/SerializedResource.h" |
47 #include "platform/SharedBuffer.h" | 47 #include "platform/SharedBuffer.h" |
48 #include "platform/mhtml/MHTMLArchive.h" | 48 #include "platform/mhtml/MHTMLArchive.h" |
49 #include "platform/mhtml/MHTMLParser.h" | 49 #include "platform/mhtml/MHTMLParser.h" |
50 #include "platform/weborigin/KURL.h" | 50 #include "platform/weborigin/KURL.h" |
51 #include "public/platform/WebCString.h" | 51 #include "public/platform/WebCString.h" |
52 #include "public/platform/WebString.h" | 52 #include "public/platform/WebString.h" |
53 #include "public/platform/WebURL.h" | 53 #include "public/platform/WebURL.h" |
54 #include "public/platform/WebVector.h" | 54 #include "public/platform/WebVector.h" |
55 #include "public/web/WebDocument.h" | 55 #include "public/web/WebDocument.h" |
56 #include "public/web/WebFrame.h" | 56 #include "public/web/WebFrame.h" |
57 #include "public/web/WebPageSerializerClient.h" | 57 #include "public/web/WebFrameSerializerClient.h" |
| 58 #include "web/WebFrameSerializerImpl.h" |
58 #include "web/WebLocalFrameImpl.h" | 59 #include "web/WebLocalFrameImpl.h" |
59 #include "web/WebPageSerializerImpl.h" | |
60 #include "web/WebRemoteFrameImpl.h" | 60 #include "web/WebRemoteFrameImpl.h" |
61 #include "wtf/Assertions.h" | 61 #include "wtf/Assertions.h" |
62 #include "wtf/HashMap.h" | 62 #include "wtf/HashMap.h" |
63 #include "wtf/HashSet.h" | 63 #include "wtf/HashSet.h" |
64 #include "wtf/Noncopyable.h" | 64 #include "wtf/Noncopyable.h" |
65 #include "wtf/Vector.h" | 65 #include "wtf/Vector.h" |
66 #include "wtf/text/StringConcatenate.h" | 66 #include "wtf/text/StringConcatenate.h" |
67 | 67 |
68 namespace blink { | 68 namespace blink { |
69 | 69 |
70 namespace { | 70 namespace { |
71 | 71 |
72 class MHTMLPageSerializerDelegate final : public PageSerializer::Delegate { | 72 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { |
73 WTF_MAKE_NONCOPYABLE(MHTMLPageSerializerDelegate); | 73 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); |
74 public: | 74 public: |
75 explicit MHTMLPageSerializerDelegate(WebPageSerializer::MHTMLPartsGeneration
Delegate&); | 75 explicit MHTMLFrameSerializerDelegate(WebFrameSerializer::MHTMLPartsGenerati
onDelegate&); |
76 bool shouldIgnoreAttribute(const Attribute&) override; | 76 bool shouldIgnoreAttribute(const Attribute&) override; |
77 bool rewriteLink(const Element&, String& rewrittenLink) override; | 77 bool rewriteLink(const Element&, String& rewrittenLink) override; |
78 bool shouldSkipResource(const KURL&) override; | 78 bool shouldSkipResource(const KURL&) override; |
79 | 79 |
80 private: | 80 private: |
81 WebPageSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; | 81 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; |
82 }; | 82 }; |
83 | 83 |
84 MHTMLPageSerializerDelegate::MHTMLPageSerializerDelegate( | 84 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
85 WebPageSerializer::MHTMLPartsGenerationDelegate& webDelegate) | 85 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) |
86 : m_webDelegate(webDelegate) | 86 : m_webDelegate(webDelegate) |
87 { | 87 { |
88 } | 88 } |
89 | 89 |
90 bool MHTMLPageSerializerDelegate::shouldIgnoreAttribute(const Attribute& attribu
te) | 90 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(const Attribute& attrib
ute) |
91 { | 91 { |
92 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display i
mages, as only the value of src | 92 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display i
mages, as only the value of src |
93 // is pulled into the archive. Discarding srcset prevents the problem. Long
term we should make sure to MHTML | 93 // is pulled into the archive. Discarding srcset prevents the problem. Long
term we should make sure to MHTML |
94 // plays nicely with srcset. | 94 // plays nicely with srcset. |
95 return attribute.localName() == HTMLNames::srcsetAttr; | 95 return attribute.localName() == HTMLNames::srcsetAttr; |
96 } | 96 } |
97 | 97 |
98 bool MHTMLPageSerializerDelegate::rewriteLink( | 98 bool MHTMLFrameSerializerDelegate::rewriteLink( |
99 const Element& element, | 99 const Element& element, |
100 String& rewrittenLink) | 100 String& rewrittenLink) |
101 { | 101 { |
102 if (!element.isFrameOwnerElement()) | 102 if (!element.isFrameOwnerElement()) |
103 return false; | 103 return false; |
104 | 104 |
105 auto* frameOwnerElement = toHTMLFrameOwnerElement(&element); | 105 auto* frameOwnerElement = toHTMLFrameOwnerElement(&element); |
106 Frame* frame = frameOwnerElement->contentFrame(); | 106 Frame* frame = frameOwnerElement->contentFrame(); |
107 if (!frame) | 107 if (!frame) |
108 return false; | 108 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
122 || doc->isXHTMLDocument() || doc->isImageDocument(); | 122 || doc->isXHTMLDocument() || doc->isImageDocument(); |
123 if (isHandledBySerializer) { | 123 if (isHandledBySerializer) { |
124 rewrittenLink = cidURI.string(); | 124 rewrittenLink = cidURI.string(); |
125 return true; | 125 return true; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 return false; | 129 return false; |
130 } | 130 } |
131 | 131 |
132 bool MHTMLPageSerializerDelegate::shouldSkipResource(const KURL& url) | 132 bool MHTMLFrameSerializerDelegate::shouldSkipResource(const KURL& url) |
133 { | 133 { |
134 return m_webDelegate.shouldSkipResource(url); | 134 return m_webDelegate.shouldSkipResource(url); |
135 } | 135 } |
136 | 136 |
137 } // namespace | 137 } // namespace |
138 | 138 |
139 WebData WebPageSerializer::generateMHTMLHeader( | 139 WebData WebFrameSerializer::generateMHTMLHeader( |
140 const WebString& boundary, WebLocalFrame* frame) | 140 const WebString& boundary, WebLocalFrame* frame) |
141 { | 141 { |
142 Document* document = toWebLocalFrameImpl(frame)->frame()->document(); | 142 Document* document = toWebLocalFrameImpl(frame)->frame()->document(); |
143 | 143 |
144 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); | 144 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); |
145 MHTMLArchive::generateMHTMLHeader( | 145 MHTMLArchive::generateMHTMLHeader( |
146 boundary, document->title(), document->suggestedMIMEType(), | 146 boundary, document->title(), document->suggestedMIMEType(), |
147 *buffer); | 147 *buffer); |
148 return buffer.release(); | 148 return buffer.release(); |
149 } | 149 } |
150 | 150 |
151 WebData WebPageSerializer::generateMHTMLParts( | 151 WebData WebFrameSerializer::generateMHTMLParts( |
152 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, | 152 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, |
153 MHTMLPartsGenerationDelegate* webDelegate) | 153 MHTMLPartsGenerationDelegate* webDelegate) |
154 { | 154 { |
155 ASSERT(webFrame); | 155 ASSERT(webFrame); |
156 ASSERT(webDelegate); | 156 ASSERT(webDelegate); |
157 | 157 |
158 // Translate arguments from public to internal blink APIs. | 158 // Translate arguments from public to internal blink APIs. |
159 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); | 159 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); |
160 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding | 160 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding |
161 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding | 161 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding |
162 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; | 162 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; |
163 | 163 |
164 // Serialize. | 164 // Serialize. |
165 Vector<SerializedResource> resources; | 165 Vector<SerializedResource> resources; |
166 MHTMLPageSerializerDelegate coreDelegate(*webDelegate); | 166 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); |
167 PageSerializer serializer(resources, coreDelegate); | 167 FrameSerializer serializer(resources, coreDelegate); |
168 serializer.serializeFrame(*frame); | 168 serializer.serializeFrame(*frame); |
169 | 169 |
170 // Get Content-ID for the frame being serialized. | 170 // Get Content-ID for the frame being serialized. |
171 String frameContentID = webDelegate->getContentID(*webFrame); | 171 String frameContentID = webDelegate->getContentID(*webFrame); |
172 ASSERT(!frameContentID.isEmpty()); | 172 ASSERT(!frameContentID.isEmpty()); |
173 | 173 |
174 // Encode serializer's output as MHTML. | 174 // Encode serializer's output as MHTML. |
175 RefPtr<SharedBuffer> output = SharedBuffer::create(); | 175 RefPtr<SharedBuffer> output = SharedBuffer::create(); |
176 bool isFirstResource = true; | 176 bool isFirstResource = true; |
177 for (const SerializedResource& resource : resources) { | 177 for (const SerializedResource& resource : resources) { |
178 // Frame is the 1st resource (see PageSerializer::serializeFrame doc | 178 // Frame is the 1st resource (see FrameSerializer::serializeFrame doc |
179 // comment). Frames get a Content-ID header. | 179 // comment). Frames get a Content-ID header. |
180 String contentID = isFirstResource ? frameContentID : String(); | 180 String contentID = isFirstResource ? frameContentID : String(); |
181 | 181 |
182 MHTMLArchive::generateMHTMLPart( | 182 MHTMLArchive::generateMHTMLPart( |
183 boundary, contentID, encodingPolicy, resource, *output); | 183 boundary, contentID, encodingPolicy, resource, *output); |
184 | 184 |
185 isFirstResource = false; | 185 isFirstResource = false; |
186 } | 186 } |
187 return output.release(); | 187 return output.release(); |
188 } | 188 } |
189 | 189 |
190 WebData WebPageSerializer::generateMHTMLFooter(const WebString& boundary) | 190 WebData WebFrameSerializer::generateMHTMLFooter(const WebString& boundary) |
191 { | 191 { |
192 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); | 192 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); |
193 MHTMLArchive::generateMHTMLFooter(boundary, *buffer); | 193 MHTMLArchive::generateMHTMLFooter(boundary, *buffer); |
194 return buffer.release(); | 194 return buffer.release(); |
195 } | 195 } |
196 | 196 |
197 bool WebPageSerializer::serialize( | 197 bool WebFrameSerializer::serialize( |
198 WebLocalFrame* frame, | 198 WebLocalFrame* frame, |
199 WebPageSerializerClient* client, | 199 WebFrameSerializerClient* client, |
200 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths) | 200 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths) |
201 { | 201 { |
202 WebPageSerializerImpl serializerImpl(frame, client, urlsToLocalPaths); | 202 WebFrameSerializerImpl serializerImpl(frame, client, urlsToLocalPaths); |
203 return serializerImpl.serialize(); | 203 return serializerImpl.serialize(); |
204 } | 204 } |
205 | 205 |
206 WebString WebPageSerializer::generateMetaCharsetDeclaration(const WebString& cha
rset) | 206 WebString WebFrameSerializer::generateMetaCharsetDeclaration(const WebString& ch
arset) |
207 { | 207 { |
208 // TODO(yosin) We should call |PageSerializer::metaCharsetDeclarationOf()|. | 208 // TODO(yosin) We should call |FrameSerializer::metaCharsetDeclarationOf()|. |
209 String charsetString = "<meta http-equiv=\"Content-Type\" content=\"text/htm
l; charset=" + static_cast<const String&>(charset) + "\">"; | 209 String charsetString = "<meta http-equiv=\"Content-Type\" content=\"text/htm
l; charset=" + static_cast<const String&>(charset) + "\">"; |
210 return charsetString; | 210 return charsetString; |
211 } | 211 } |
212 | 212 |
213 WebString WebPageSerializer::generateMarkOfTheWebDeclaration(const WebURL& url) | 213 WebString WebFrameSerializer::generateMarkOfTheWebDeclaration(const WebURL& url) |
214 { | 214 { |
215 StringBuilder builder; | 215 StringBuilder builder; |
216 builder.append("\n<!-- "); | 216 builder.append("\n<!-- "); |
217 builder.append(PageSerializer::markOfTheWebDeclaration(url)); | 217 builder.append(FrameSerializer::markOfTheWebDeclaration(url)); |
218 builder.append(" -->\n"); | 218 builder.append(" -->\n"); |
219 return builder.toString(); | 219 return builder.toString(); |
220 } | 220 } |
221 | 221 |
222 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) | 222 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa
rget) |
223 { | 223 { |
224 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|. | 224 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
225 if (baseTarget.isEmpty()) | 225 if (baseTarget.isEmpty()) |
226 return String("<base href=\".\">"); | 226 return String("<base href=\".\">"); |
227 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; | 227 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; |
228 return baseString; | 228 return baseString; |
229 } | 229 } |
230 | 230 |
231 } // namespace blink | 231 } // namespace blink |
OLD | NEW |