Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameSerializer.cpp

Issue 2605413002: MHTML generation: discard serialized resources by the measure they are encoded. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 out.append("\""); 262 out.append("\"");
263 } 263 }
264 264
265 // TODO(tiger): Right now there is no support for rewriting URLs inside CSS 265 // TODO(tiger): Right now there is no support for rewriting URLs inside CSS
266 // documents which leads to bugs like <https://crbug.com/251898>. Not being 266 // documents which leads to bugs like <https://crbug.com/251898>. Not being
267 // able to rewrite URLs inside CSS documents means that resources imported from 267 // able to rewrite URLs inside CSS documents means that resources imported from
268 // url(...) statements in CSS might not work when rewriting links for the 268 // url(...) statements in CSS might not work when rewriting links for the
269 // "Webpage, Complete" method of saving a page. It will take some work but it 269 // "Webpage, Complete" method of saving a page. It will take some work but it
270 // needs to be done if we want to continue to support non-MHTML saved pages. 270 // needs to be done if we want to continue to support non-MHTML saved pages.
271 271
272 FrameSerializer::FrameSerializer(Vector<SerializedResource>& resources, 272 FrameSerializer::FrameSerializer(Deque<SerializedResource>& resources,
273 Delegate& delegate) 273 Delegate& delegate)
274 : m_resources(&resources), 274 : m_resources(&resources),
275 m_isSerializingCss(false), 275 m_isSerializingCss(false),
276 m_delegate(delegate) {} 276 m_delegate(delegate) {}
277 277
278 void FrameSerializer::serializeFrame(const LocalFrame& frame) { 278 void FrameSerializer::serializeFrame(const LocalFrame& frame) {
279 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame"); 279 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame");
280 ASSERT(frame.document()); 280 ASSERT(frame.document());
281 Document& document = *frame.document(); 281 Document& document = *frame.document();
282 KURL url = document.url(); 282 KURL url = document.url();
(...skipping 10 matching lines...) Expand all
293 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame HTML"); 293 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame HTML");
294 SCOPED_BLINK_UMA_HISTOGRAM_TIMER( 294 SCOPED_BLINK_UMA_HISTOGRAM_TIMER(
295 "PageSerialization.SerializationTime.Html"); 295 "PageSerialization.SerializationTime.Html");
296 SerializerMarkupAccumulator accumulator(m_delegate, document, 296 SerializerMarkupAccumulator accumulator(m_delegate, document,
297 serializedNodes); 297 serializedNodes);
298 String text = 298 String text =
299 serializeNodes<EditingStrategy>(accumulator, document, IncludeNode); 299 serializeNodes<EditingStrategy>(accumulator, document, IncludeNode);
300 300
301 CString frameHTML = 301 CString frameHTML =
302 document.encoding().encode(text, WTF::EntitiesForUnencodables); 302 document.encoding().encode(text, WTF::EntitiesForUnencodables);
303 m_resources->push_back(SerializedResource( 303 m_resources->append(SerializedResource(
304 url, document.suggestedMIMEType(), 304 url, document.suggestedMIMEType(),
305 SharedBuffer::create(frameHTML.data(), frameHTML.length()))); 305 SharedBuffer::create(frameHTML.data(), frameHTML.length())));
306 } 306 }
307 307
308 for (Node* node : serializedNodes) { 308 for (Node* node : serializedNodes) {
309 ASSERT(node); 309 ASSERT(node);
310 if (!node->isElementNode()) 310 if (!node->isElementNode())
311 continue; 311 continue;
312 312
313 Element& element = toElement(*node); 313 Element& element = toElement(*node);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 PassRefPtr<const SharedBuffer> data, 470 PassRefPtr<const SharedBuffer> data,
471 const KURL& url) { 471 const KURL& url) {
472 if (m_delegate.shouldSkipResource(hasCacheControlNoStoreHeader)) 472 if (m_delegate.shouldSkipResource(hasCacheControlNoStoreHeader))
473 return; 473 return;
474 474
475 if (!data) { 475 if (!data) {
476 DLOG(ERROR) << "No data for resource " << url.getString(); 476 DLOG(ERROR) << "No data for resource " << url.getString();
477 return; 477 return;
478 } 478 }
479 479
480 m_resources->push_back(SerializedResource(url, mimeType, std::move(data))); 480 m_resources->append(SerializedResource(url, mimeType, std::move(data)));
481 m_resourceURLs.add(url); 481 m_resourceURLs.add(url);
482 } 482 }
483 483
484 void FrameSerializer::addImageToResources(ImageResourceContent* image, 484 void FrameSerializer::addImageToResources(ImageResourceContent* image,
485 const KURL& url) { 485 const KURL& url) {
486 if (!image || !image->hasImage() || image->errorOccurred() || 486 if (!image || !image->hasImage() || image->errorOccurred() ||
487 !shouldAddURL(url)) 487 !shouldAddURL(url))
488 return; 488 return;
489 489
490 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", 490 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources",
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 emitsMinus = ch == '-'; 584 emitsMinus = ch == '-';
585 builder.append(ch); 585 builder.append(ch);
586 } 586 }
587 CString escapedUrl = builder.toString().ascii(); 587 CString escapedUrl = builder.toString().ascii();
588 return String::format("saved from url=(%04d)%s", 588 return String::format("saved from url=(%04d)%s",
589 static_cast<int>(escapedUrl.length()), 589 static_cast<int>(escapedUrl.length()),
590 escapedUrl.data()); 590 escapedUrl.data());
591 } 591 }
592 592
593 } // namespace blink 593 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698