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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 { | 159 { |
160 Document* document = toWebLocalFrameImpl(frame)->frame()->document(); | 160 Document* document = toWebLocalFrameImpl(frame)->frame()->document(); |
161 | 161 |
162 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); | 162 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); |
163 MHTMLArchive::generateMHTMLHeader( | 163 MHTMLArchive::generateMHTMLHeader( |
164 boundary, document->title(), document->suggestedMIMEType(), | 164 boundary, document->title(), document->suggestedMIMEType(), |
165 *buffer); | 165 *buffer); |
166 return buffer.release(); | 166 return buffer.release(); |
167 } | 167 } |
168 | 168 |
| 169 WebVector<WebURL> WebPageSerializer::enumerateMHTMLResources(WebLocalFrame* webF
rame) |
| 170 { |
| 171 Vector<SerializedResource> resources; |
| 172 PageSerializer serializer(resources, nullptr); |
| 173 serializer.serializeFrame(*toWebLocalFrameImpl(webFrame)->frame()); |
| 174 |
| 175 Vector<WebURL> result; |
| 176 for (size_t i = 0; i < resources.size(); i++) { |
| 177 const SerializedResource& resource = resources[i]; |
| 178 if (i != 0) // Report only resources, not the frame. |
| 179 result.append(resource.url); |
| 180 } |
| 181 |
| 182 return result; |
| 183 } |
| 184 |
169 WebData WebPageSerializer::generateMHTMLParts( | 185 WebData WebPageSerializer::generateMHTMLParts( |
170 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, | 186 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, |
171 const WebVector<std::pair<WebFrame*, WebString>>& webFrameToContentID) | 187 const WebVector<std::pair<WebFrame*, WebString>>& webFrameToContentID, |
| 188 const WebVector<WebURL>& resourcesToSkip) |
172 { | 189 { |
173 // Translate arguments from public to internal blink APIs. | 190 // Translate arguments from public to internal blink APIs. |
174 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); | 191 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); |
175 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding | 192 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding |
176 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding | 193 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding |
177 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; | 194 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; |
178 ContentIDMap frameToContentID = createFrameToContentIDMap(webFrameToContentI
D); | 195 ContentIDMap frameToContentID = |
| 196 createFrameToContentIDMap(webFrameToContentID); |
179 | 197 |
180 // Serialize. | 198 // Serialize. |
181 Vector<SerializedResource> resources; | 199 Vector<SerializedResource> resources; |
182 MHTMLPageSerializerDelegate delegate(frameToContentID); | 200 MHTMLPageSerializerDelegate delegate(frameToContentID); |
183 PageSerializer serializer(resources, &delegate); | 201 PageSerializer serializer(resources, &delegate); |
184 serializer.serializeFrame(*frame); | 202 serializer.serializeFrame(*frame); |
185 | 203 |
186 // Encode serializer's output as MHTML. | 204 // Encode serializer's output as MHTML. |
187 RefPtr<SharedBuffer> output = SharedBuffer::create(); | 205 RefPtr<SharedBuffer> output = SharedBuffer::create(); |
188 bool isFirstResource = true; | 206 bool isFirstResource = true; |
189 for (const SerializedResource& resource : resources) { | 207 for (const SerializedResource& resource : resources) { |
190 // Frame is the 1st resource (see PageSerializer::serializeFrame doc | 208 // Frame is the 1st resource (see PageSerializer::serializeFrame doc |
191 // comment). Frames need a Content-ID header. | 209 // comment). Frames need a Content-ID header. |
192 String contentID = isFirstResource ? frameToContentID.get(frame) : Strin
g(); | 210 String contentID = isFirstResource ? frameToContentID.get(frame) : Strin
g(); |
193 | 211 |
| 212 // Resources don't yet get a Content ID and are deduped based on URI. |
| 213 if (contentID.isEmpty() && resourcesToSkip.contains(resource.url)) |
| 214 continue; |
| 215 |
194 MHTMLArchive::generateMHTMLPart( | 216 MHTMLArchive::generateMHTMLPart( |
195 boundary, contentID, encodingPolicy, resource, *output); | 217 boundary, contentID, encodingPolicy, resource, *output); |
196 | 218 |
197 isFirstResource = false; | 219 isFirstResource = false; |
198 } | 220 } |
199 return output.release(); | 221 return output.release(); |
200 } | 222 } |
201 | 223 |
202 WebData WebPageSerializer::generateMHTMLFooter(const WebString& boundary) | 224 WebData WebPageSerializer::generateMHTMLFooter(const WebString& boundary) |
203 { | 225 { |
(...skipping 30 matching lines...) Expand all Loading... |
234 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) | 256 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) |
235 { | 257 { |
236 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|. | 258 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|. |
237 if (baseTarget.isEmpty()) | 259 if (baseTarget.isEmpty()) |
238 return String("<base href=\".\">"); | 260 return String("<base href=\".\">"); |
239 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; | 261 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; |
240 return baseString; | 262 return baseString; |
241 } | 263 } |
242 | 264 |
243 } // namespace blink | 265 } // namespace blink |
OLD | NEW |