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

Side by Side Diff: third_party/WebKit/Source/core/page/PageSerializer.cpp

Issue 1436683002: Making PageSerializer operate on single frames only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-removing-unused-code
Patch Set: Addressed 2nd round of CR feedback from Daniel. Created 5 years, 1 month 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 297 }
298 298
299 299
300 PageSerializer::PageSerializer(Vector<SerializedResource>* resources, PassOwnPtr <Delegate> delegate) 300 PageSerializer::PageSerializer(Vector<SerializedResource>* resources, PassOwnPtr <Delegate> delegate)
301 : m_resources(resources) 301 : m_resources(resources)
302 , m_blankFrameCounter(0) 302 , m_blankFrameCounter(0)
303 , m_delegate(delegate) 303 , m_delegate(delegate)
304 { 304 {
305 } 305 }
306 306
307 void PageSerializer::serialize(Page* page) 307 void PageSerializer::serializeFrame(LocalFrame& frame)
308 { 308 {
309 serializeFrame(page->deprecatedLocalMainFrame()); 309 ASSERT(frame.document());
310 } 310 Document& document = *frame.document();
311
312 void PageSerializer::serializeFrame(LocalFrame* frame)
313 {
314 ASSERT(frame->document());
315 Document& document = *frame->document();
316 KURL url = document.url(); 311 KURL url = document.url();
317 // FIXME: This probably wants isAboutBlankURL? to exclude other about: urls (like about:srcdoc)? 312 // FIXME: This probably wants isAboutBlankURL? to exclude other about: urls (like about:srcdoc)?
318 if (!url.isValid() || url.protocolIsAbout()) { 313 if (!url.isValid() || url.protocolIsAbout()) {
319 // For blank frames we generate a fake URL so they can be referenced by their containing frame. 314 // For blank frames we generate a fake URL so they can be referenced by their containing frame.
320 url = urlForBlankFrame(frame); 315 url = urlForBlankFrame(&frame);
321 } 316 }
322 317
323 if (m_resourceURLs.contains(url)) { 318 if (m_resourceURLs.contains(url)) {
324 // FIXME: We could have 2 frame with the same URL but which were dynamic ally changed and have now 319 // FIXME: We could have 2 frame with the same URL but which were dynamic ally changed and have now
325 // different content. So we should serialize both and somehow rename the frame src in the containing 320 // different content. So we should serialize both and somehow rename the frame src in the containing
326 // frame. Arg! 321 // frame. Arg!
327 return; 322 return;
328 } 323 }
329 324
330 // If frame is an image document, add the image and don't continue 325 // If frame is an image document, add the image and don't continue
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam es::hrefAttr)); 373 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam es::hrefAttr));
379 serializeCSSStyleSheet(*sheet, url); 374 serializeCSSStyleSheet(*sheet, url);
380 ASSERT(m_resourceURLs.contains(url)); 375 ASSERT(m_resourceURLs.contains(url));
381 } 376 }
382 } else if (isHTMLStyleElement(element)) { 377 } else if (isHTMLStyleElement(element)) {
383 HTMLStyleElement& styleElement = toHTMLStyleElement(element); 378 HTMLStyleElement& styleElement = toHTMLStyleElement(element);
384 if (CSSStyleSheet* sheet = styleElement.sheet()) 379 if (CSSStyleSheet* sheet = styleElement.sheet())
385 serializeCSSStyleSheet(*sheet, KURL()); 380 serializeCSSStyleSheet(*sheet, KURL());
386 } 381 }
387 } 382 }
388
389 for (Frame* childFrame = frame->tree().firstChild(); childFrame; childFrame = childFrame->tree().nextSibling()) {
390 // TODO(lukasza): This causes incomplete MHTML for OOPIFs.
391 // (crbug.com/538766)
392 if (childFrame->isLocalFrame())
393 serializeFrame(toLocalFrame(childFrame));
394 }
395 } 383 }
396 384
397 void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR L& url) 385 void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KUR L& url)
398 { 386 {
399 StringBuilder cssText; 387 StringBuilder cssText;
400 cssText.appendLiteral("@charset \""); 388 cssText.appendLiteral("@charset \"");
401 cssText.append(styleSheet.contents()->charset().lower()); 389 cssText.append(styleSheet.contents()->charset().lower());
402 cssText.appendLiteral("\";\n\n"); 390 cssText.appendLiteral("\";\n\n");
403 391
404 for (unsigned i = 0; i < styleSheet.length(); ++i) { 392 for (unsigned i = 0; i < styleSheet.length(); ++i) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 continue; 585 continue;
598 } 586 }
599 emitsMinus = ch == '-'; 587 emitsMinus = ch == '-';
600 builder.append(ch); 588 builder.append(ch);
601 } 589 }
602 CString escapedUrl = builder.toString().ascii(); 590 CString escapedUrl = builder.toString().ascii();
603 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data()); 591 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data());
604 } 592 }
605 593
606 } // namespace blink 594 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698