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

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: Rebasing... 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 Frame* frame = frameOwner.contentFrame(); 183 Frame* frame = frameOwner.contentFrame();
184 // FIXME: RemoteFrames not currently supported here. 184 // FIXME: RemoteFrames not currently supported here.
185 if (!frame || !frame->isLocalFrame()) 185 if (!frame || !frame->isLocalFrame())
186 return; 186 return;
187 187
188 KURL url = toLocalFrame(frame)->document()->url(); 188 KURL url = toLocalFrame(frame)->document()->url();
189 if (url.isValid() && !url.protocolIsAbout()) 189 if (url.isValid() && !url.protocolIsAbout())
190 return; 190 return;
191 191
192 // We need to give a fake location to blank frames so they can be referenced by the serialized frame. 192 // We need to give a fake location to blank frames so they can be referenced by the serialized frame.
193 url = m_serializer->urlForBlankFrame(toLocalFrame(frame)); 193 url = m_serializer->urlForBlankFrame(*toLocalFrame(frame));
194 appendAttribute(result, element, Attribute(frameOwnerURLAttributeName(frameO wner), AtomicString(url.string())), namespaces); 194 appendAttribute(result, element, Attribute(frameOwnerURLAttributeName(frameO wner), AtomicString(url.string())), namespaces);
195 } 195 }
196 196
197 void SerializerMarkupAccumulator::appendStartTag(Node& node, Namespaces* namespa ces) 197 void SerializerMarkupAccumulator::appendStartTag(Node& node, Namespaces* namespa ces)
198 { 198 {
199 MarkupAccumulator::appendStartTag(node, namespaces); 199 MarkupAccumulator::appendStartTag(node, namespaces);
200 m_nodes.append(&node); 200 m_nodes.append(&node);
201 } 201 }
202 202
203 void SerializerMarkupAccumulator::appendEndTag(const Element& element) 203 void SerializerMarkupAccumulator::appendEndTag(const Element& element)
(...skipping 93 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(const 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
(...skipping 52 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 void PageSerializer::registerRewriteURL(const String& from, const String& to) 542 void PageSerializer::registerRewriteURL(const String& from, const String& to)
555 { 543 {
556 m_rewriteURLs.set(from, to); 544 m_rewriteURLs.set(from, to);
557 } 545 }
558 546
559 void PageSerializer::setRewriteURLFolder(const String& rewriteFolder) 547 void PageSerializer::setRewriteURLFolder(const String& rewriteFolder)
560 { 548 {
561 m_rewriteFolder = rewriteFolder; 549 m_rewriteFolder = rewriteFolder;
562 } 550 }
563 551
564 KURL PageSerializer::urlForBlankFrame(LocalFrame* frame) 552 KURL PageSerializer::urlForBlankFrame(const LocalFrame& frame)
565 { 553 {
566 BlankFrameURLMap::iterator iter = m_blankFrameURLs.find(frame); 554 BlankFrameURLMap::iterator iter = m_blankFrameURLs.find(&frame);
567 if (iter != m_blankFrameURLs.end()) 555 if (iter != m_blankFrameURLs.end())
568 return iter->value; 556 return iter->value;
569 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++); 557 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++);
570 KURL fakeURL(ParsedURLString, url); 558 KURL fakeURL(ParsedURLString, url);
571 m_blankFrameURLs.add(frame, fakeURL); 559 m_blankFrameURLs.add(&frame, fakeURL);
572 560
573 return fakeURL; 561 return fakeURL;
574 } 562 }
575 563
576 PageSerializer::Delegate* PageSerializer::delegate() 564 PageSerializer::Delegate* PageSerializer::delegate()
577 { 565 {
578 return m_delegate.get(); 566 return m_delegate.get();
579 } 567 }
580 568
581 // Returns MOTW (Mark of the Web) declaration before html tag which is in 569 // Returns MOTW (Mark of the Web) declaration before html tag which is in
(...skipping 12 matching lines...) Expand all
594 continue; 582 continue;
595 } 583 }
596 emitsMinus = ch == '-'; 584 emitsMinus = ch == '-';
597 builder.append(ch); 585 builder.append(ch);
598 } 586 }
599 CString escapedUrl = builder.toString().ascii(); 587 CString escapedUrl = builder.toString().ascii();
600 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data()); 588 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl .length()), escapedUrl.data());
601 } 589 }
602 590
603 } // namespace blink 591 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/PageSerializer.h ('k') | third_party/WebKit/Source/platform/mhtml/MHTMLArchive.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698