| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 { | 166 { |
| 167 Document* document = toWebLocalFrameImpl(topLevelFrame)->frame()->document()
; | 167 Document* document = toWebLocalFrameImpl(topLevelFrame)->frame()->document()
; |
| 168 | 168 |
| 169 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); | 169 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); |
| 170 MHTMLArchive::generateMHTMLHeader( | 170 MHTMLArchive::generateMHTMLHeader( |
| 171 boundary, document->title(), document->suggestedMIMEType(), | 171 boundary, document->title(), document->suggestedMIMEType(), |
| 172 *buffer); | 172 *buffer); |
| 173 return PassRefPtr<SharedBuffer>(buffer); | 173 return PassRefPtr<SharedBuffer>(buffer); |
| 174 } | 174 } |
| 175 | 175 |
| 176 WebVector<WebURL> WebPageSerializer::enumerateMHTMLResources(WebLocalFrame* webF
rame) |
| 177 { |
| 178 Vector<SerializedResource> resources; |
| 179 PageSerializer serializer(resources, nullptr); |
| 180 serializer.serializeFrame(*toWebLocalFrameImpl(webFrame)->frame()); |
| 181 |
| 182 Vector<WebURL> result; |
| 183 for (size_t i = 0; i < resources.size(); i++) { |
| 184 const SerializedResource& resource = resources[i]; |
| 185 if (i != 0) // Report only resources, not the frame. |
| 186 result.append(resource.url); |
| 187 } |
| 188 |
| 189 return result; |
| 190 } |
| 191 |
| 176 WebData WebPageSerializer::generateMHTMLParts( | 192 WebData WebPageSerializer::generateMHTMLParts( |
| 177 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, | 193 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, |
| 178 const WebVector<std::pair<WebFrame*, WebString>>& webFrameToContentID) | 194 const WebVector<std::pair<WebFrame*, WebString>>& webFrameToContentID, |
| 195 const WebVector<WebURL>& resourcesToSkip) |
| 179 { | 196 { |
| 180 // Translate arguments from public to internal blink APIs. | 197 // Translate arguments from public to internal blink APIs. |
| 181 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); | 198 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); |
| 182 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding | 199 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding |
| 183 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding | 200 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding |
| 184 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; | 201 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; |
| 185 ContentIDMap frameToContentID = | 202 ContentIDMap frameToContentID = |
| 186 createFrameToContentIDMap(webFrameToContentID); | 203 createFrameToContentIDMap(webFrameToContentID); |
| 187 | 204 |
| 188 // Serialize. | 205 // Serialize. |
| 189 Vector<SerializedResource> resources; | 206 Vector<SerializedResource> resources; |
| 190 MHTMLPageSerializerDelegate delegate(frameToContentID); | 207 MHTMLPageSerializerDelegate delegate(frameToContentID); |
| 191 PageSerializer serializer(resources, &delegate); | 208 PageSerializer serializer(resources, &delegate); |
| 192 serializer.serializeFrame(*frame); | 209 serializer.serializeFrame(*frame); |
| 193 | 210 |
| 194 // Encode serializer's output as MHTML. | 211 // Encode serializer's output as MHTML. |
| 195 RefPtr<SharedBuffer> output = SharedBuffer::create(); | 212 RefPtr<SharedBuffer> output = SharedBuffer::create(); |
| 196 bool isFirstResource = true; | 213 bool isFirstResource = true; |
| 197 for (const SerializedResource& resource : resources) { | 214 for (const SerializedResource& resource : resources) { |
| 198 // Frame is the 1st resource (see PageSerializer::serializeFrame doc | 215 // Frame is the 1st resource (see PageSerializer::serializeFrame doc |
| 199 // comment). Frames need a Content-ID header. | 216 // comment). Frames need a Content-ID header. |
| 200 String contentID = isFirstResource ? frameToContentID.get(frame) : Strin
g(); | 217 String contentID = isFirstResource ? frameToContentID.get(frame) : Strin
g(); |
| 201 | 218 |
| 219 // Resources don't yet get a Content ID and are deduped based on URI. |
| 220 if (contentID.isEmpty() && resourcesToSkip.contains(resource.url)) |
| 221 continue; |
| 222 |
| 202 MHTMLArchive::generateMHTMLPart( | 223 MHTMLArchive::generateMHTMLPart( |
| 203 boundary, contentID, encodingPolicy, resource, *output); | 224 boundary, contentID, encodingPolicy, resource, *output); |
| 204 | 225 |
| 205 isFirstResource = false; | 226 isFirstResource = false; |
| 206 } | 227 } |
| 207 return output.release(); | 228 return output.release(); |
| 208 } | 229 } |
| 209 | 230 |
| 210 WebData WebPageSerializer::generateMHTMLFooter(const WebString& boundary) | 231 WebData WebPageSerializer::generateMHTMLFooter(const WebString& boundary) |
| 211 { | 232 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) | 265 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar
get) |
| 245 { | 266 { |
| 246 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|. | 267 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|. |
| 247 if (baseTarget.isEmpty()) | 268 if (baseTarget.isEmpty()) |
| 248 return String("<base href=\".\">"); | 269 return String("<base href=\".\">"); |
| 249 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; | 270 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; |
| 250 return baseString; | 271 return baseString; |
| 251 } | 272 } |
| 252 | 273 |
| 253 } // namespace blink | 274 } // namespace blink |
| OLD | NEW |