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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 || (!frame->parent() && cacheControlPolicy == WebFrameSerializerCacheCon
trolPolicy::FailForNoStoreMainFrame); | 172 || (!frame->parent() && cacheControlPolicy == WebFrameSerializerCacheCon
trolPolicy::FailForNoStoreMainFrame); |
173 | 173 |
174 if (!needToCheckNoStore) | 174 if (!needToCheckNoStore) |
175 return true; | 175 return true; |
176 | 176 |
177 return !cacheControlNoStoreHeaderPresent(*webLocalFrameImpl); | 177 return !cacheControlNoStoreHeaderPresent(*webLocalFrameImpl); |
178 } | 178 } |
179 | 179 |
180 } // namespace | 180 } // namespace |
181 | 181 |
182 WebData WebFrameSerializer::generateMHTMLHeader( | 182 std::vector<char> WebFrameSerializer::generateMHTMLHeader( |
183 const WebString& boundary, WebLocalFrame* frame, MHTMLPartsGenerationDelegat
e* delegate) | 183 const WebString& boundary, WebLocalFrame* frame, MHTMLPartsGenerationDelegat
e* delegate) |
184 { | 184 { |
185 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLHeader"
); | 185 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLHeader"
); |
186 DCHECK(frame); | 186 DCHECK(frame); |
187 DCHECK(delegate); | 187 DCHECK(delegate); |
188 | 188 |
189 if (!frameShouldBeSerializedAsMHTML(frame, delegate->cacheControlPolicy())) | 189 if (!frameShouldBeSerializedAsMHTML(frame, delegate->cacheControlPolicy())) |
190 return WebData(); | 190 return std::move(std::vector<char>()); |
191 | 191 |
192 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); | 192 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); |
193 DCHECK(webLocalFrameImpl); | 193 DCHECK(webLocalFrameImpl); |
194 | 194 |
195 Document* document = webLocalFrameImpl->frame()->document(); | 195 Document* document = webLocalFrameImpl->frame()->document(); |
196 | 196 |
197 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); | 197 std::vector<char> output; |
198 MHTMLArchive::generateMHTMLHeader( | 198 MHTMLArchive::generateMHTMLHeader( |
199 boundary, document->title(), document->suggestedMIMEType(), | 199 boundary, document->title(), document->suggestedMIMEType(), output); |
200 *buffer); | 200 return std::move(output); |
201 return buffer.release(); | |
202 } | 201 } |
203 | 202 |
204 WebData WebFrameSerializer::generateMHTMLParts( | 203 std::vector<char> WebFrameSerializer::generateMHTMLParts( |
205 const WebString& boundary, WebLocalFrame* webFrame, MHTMLPartsGenerationDele
gate* webDelegate) | 204 const WebString& boundary, WebLocalFrame* webFrame, MHTMLPartsGenerationDele
gate* webDelegate) |
206 { | 205 { |
207 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLParts")
; | 206 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLParts")
; |
208 DCHECK(webFrame); | 207 DCHECK(webFrame); |
209 DCHECK(webDelegate); | 208 DCHECK(webDelegate); |
210 | 209 |
211 if (!frameShouldBeSerializedAsMHTML(webFrame, webDelegate->cacheControlPolic
y())) | 210 if (!frameShouldBeSerializedAsMHTML(webFrame, webDelegate->cacheControlPolic
y())) |
212 return WebData(); | 211 return std::move(std::vector<char>()); |
213 | 212 |
214 // Translate arguments from public to internal blink APIs. | 213 // Translate arguments from public to internal blink APIs. |
215 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); | 214 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); |
216 MHTMLArchive::EncodingPolicy encodingPolicy = webDelegate->useBinaryEncoding
() | 215 MHTMLArchive::EncodingPolicy encodingPolicy = webDelegate->useBinaryEncoding
() |
217 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding | 216 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding |
218 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; | 217 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; |
219 | 218 |
220 // Serialize. | 219 // Serialize. |
221 TRACE_EVENT_BEGIN0("page-serialization", "WebFrameSerializer::generateMHTMLP
arts serializing"); | 220 TRACE_EVENT_BEGIN0("page-serialization", "WebFrameSerializer::generateMHTMLP
arts serializing"); |
222 Vector<SerializedResource> resources; | 221 Vector<SerializedResource> resources; |
223 { | 222 { |
224 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("PageSerialization.MhtmlGeneration.Seri
alizationTime.SingleFrame"); | 223 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("PageSerialization.MhtmlGeneration.Seri
alizationTime.SingleFrame"); |
225 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); | 224 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); |
226 FrameSerializer serializer(resources, coreDelegate); | 225 FrameSerializer serializer(resources, coreDelegate); |
227 serializer.serializeFrame(*frame); | 226 serializer.serializeFrame(*frame); |
228 } | 227 } |
229 TRACE_EVENT_END1("page-serialization", "WebFrameSerializer::generateMHTMLPar
ts serializing", | 228 TRACE_EVENT_END1("page-serialization", "WebFrameSerializer::generateMHTMLPar
ts serializing", |
230 "resource count", static_cast<unsigned long long>(resources.size())); | 229 "resource count", static_cast<unsigned long long>(resources.size())); |
231 | 230 |
232 // Get Content-ID for the frame being serialized. | 231 // Get Content-ID for the frame being serialized. |
233 String frameContentID = webDelegate->getContentID(webFrame); | 232 String frameContentID = webDelegate->getContentID(webFrame); |
234 | 233 |
235 // Encode serializer's output as MHTML. | 234 // Encode serializer's output as MHTML. |
236 RefPtr<SharedBuffer> output = SharedBuffer::create(); | 235 std::vector<char> output; |
237 { | 236 { |
238 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("PageSerialization.MhtmlGeneration.Enco
dingTime.SingleFrame"); | 237 SCOPED_BLINK_UMA_HISTOGRAM_TIMER("PageSerialization.MhtmlGeneration.Enco
dingTime.SingleFrame"); |
239 bool isFirstResource = true; | 238 bool isFirstResource = true; |
240 for (const SerializedResource& resource : resources) { | 239 for (const SerializedResource& resource : resources) { |
241 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTM
LParts encoding"); | 240 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTM
LParts encoding"); |
242 // Frame is the 1st resource (see FrameSerializer::serializeFrame do
c | 241 // Frame is the 1st resource (see FrameSerializer::serializeFrame do
c |
243 // comment). Frames get a Content-ID header. | 242 // comment). Frames get a Content-ID header. |
244 String contentID = isFirstResource ? frameContentID : String(); | 243 String contentID = isFirstResource ? frameContentID : String(); |
245 | 244 |
246 MHTMLArchive::generateMHTMLPart( | 245 MHTMLArchive::generateMHTMLPart( |
247 boundary, contentID, encodingPolicy, resource, *output); | 246 boundary, contentID, encodingPolicy, resource, output); |
248 | 247 |
249 isFirstResource = false; | 248 isFirstResource = false; |
250 } | 249 } |
251 } | 250 } |
252 return output.release(); | 251 return std::move(output); |
253 } | 252 } |
254 | 253 |
255 WebData WebFrameSerializer::generateMHTMLFooter(const WebString& boundary) | 254 std::vector<char> WebFrameSerializer::generateMHTMLFooter(const WebString& bound
ary) |
256 { | 255 { |
257 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter"
); | 256 TRACE_EVENT0("page-serialization", "WebFrameSerializer::generateMHTMLFooter"
); |
258 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); | 257 std::vector<char> output; |
259 MHTMLArchive::generateMHTMLFooter(boundary, *buffer); | 258 MHTMLArchive::generateMHTMLFooter(boundary, output); |
260 return buffer.release(); | 259 return std::move(output); |
261 } | 260 } |
262 | 261 |
263 bool WebFrameSerializer::serialize( | 262 bool WebFrameSerializer::serialize( |
264 WebLocalFrame* frame, | 263 WebLocalFrame* frame, |
265 WebFrameSerializerClient* client, | 264 WebFrameSerializerClient* client, |
266 WebFrameSerializer::LinkRewritingDelegate* delegate) | 265 WebFrameSerializer::LinkRewritingDelegate* delegate) |
267 { | 266 { |
268 WebFrameSerializerImpl serializerImpl(frame, client, delegate); | 267 WebFrameSerializerImpl serializerImpl(frame, client, delegate); |
269 return serializerImpl.serialize(); | 268 return serializerImpl.serialize(); |
270 } | 269 } |
(...skipping 17 matching lines...) Expand all Loading... |
288 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa
rget) | 287 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa
rget) |
289 { | 288 { |
290 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. | 289 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. |
291 if (baseTarget.isEmpty()) | 290 if (baseTarget.isEmpty()) |
292 return String("<base href=\".\">"); | 291 return String("<base href=\".\">"); |
293 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; | 292 String baseString = "<base href=\".\" target=\"" + static_cast<const String&
>(baseTarget) + "\">"; |
294 return baseString; | 293 return baseString; |
295 } | 294 } |
296 | 295 |
297 } // namespace blink | 296 } // namespace blink |
OLD | NEW |