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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
109 | 109 |
110 WebString contentID = m_webDelegate.getContentID(*WebFrame::fromFrame(frame)
); | 110 WebString contentID = m_webDelegate.getContentID(WebFrame::fromFrame(frame))
; |
111 KURL cidURI = MHTMLParser::convertContentIDToURI(contentID); | 111 KURL cidURI = MHTMLParser::convertContentIDToURI(contentID); |
112 ASSERT(cidURI.isValid()); | 112 ASSERT(cidURI.isValid()); |
113 | 113 |
114 if (isHTMLFrameElementBase(&element)) { | 114 if (isHTMLFrameElementBase(&element)) { |
115 rewrittenLink = cidURI.string(); | 115 rewrittenLink = cidURI.string(); |
116 return true; | 116 return true; |
117 } | 117 } |
118 | 118 |
119 if (isHTMLObjectElement(&element)) { | 119 if (isHTMLObjectElement(&element)) { |
120 Document* doc = frameOwnerElement->contentDocument(); | 120 Document* doc = frameOwnerElement->contentDocument(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); | 166 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); |
167 FrameSerializer 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 FrameSerializer::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 WebFrameSerializer::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 WebFrameSerializer::serialize( | 197 bool WebFrameSerializer::serialize( |
198 WebLocalFrame* frame, | 198 WebLocalFrame* frame, |
199 WebFrameSerializerClient* client, | 199 WebFrameSerializerClient* client, |
200 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths) | 200 WebFrameSerializer::LinkRewritingDelegate* delegate) |
201 { | 201 { |
202 WebFrameSerializerImpl serializerImpl(frame, client, urlsToLocalPaths); | 202 WebFrameSerializerImpl serializerImpl(frame, client, delegate); |
203 return serializerImpl.serialize(); | 203 return serializerImpl.serialize(); |
204 } | 204 } |
205 | 205 |
206 WebString WebFrameSerializer::generateMetaCharsetDeclaration(const WebString& ch
arset) | 206 WebString WebFrameSerializer::generateMetaCharsetDeclaration(const WebString& ch
arset) |
207 { | 207 { |
208 // TODO(yosin) We should call |FrameSerializer::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 WebFrameSerializer::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(FrameSerializer::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 WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa
rget) | 222 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa
rget) |
223 { | 223 { |
224 // TODO(yosin) We should call |FrameSerializer::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 |