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

Side by Side Diff: third_party/WebKit/Source/web/WebPageSerializerImpl.cpp

Issue 1371533002: Remove "recursive" parameter from WebPageSerializer::serialize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-serialization-complete-serialization
Patch Set: Created 5 years, 3 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) 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 case Node::DOCUMENT_TYPE_NODE: 418 case Node::DOCUMENT_TYPE_NODE:
419 param->haveSeenDocType = true; 419 param->haveSeenDocType = true;
420 default: 420 default:
421 // For other type node, call default action. 421 // For other type node, call default action.
422 saveHTMLContentToBuffer(createMarkup(node), param); 422 saveHTMLContentToBuffer(createMarkup(node), param);
423 break; 423 break;
424 } 424 }
425 } 425 }
426 426
427 WebPageSerializerImpl::WebPageSerializerImpl(WebFrame* frame, 427 WebPageSerializerImpl::WebPageSerializerImpl(WebFrame* frame,
428 bool recursiveSerialization,
429 WebPageSerializerClient* client, 428 WebPageSerializerClient* client,
430 const WebVector<WebURL>& links, 429 const WebVector<WebURL>& links,
431 const WebVector<WebString>& localPa ths, 430 const WebVector<WebString>& localPa ths,
432 const WebString& localDirectoryName ) 431 const WebString& localDirectoryName )
433 : m_client(client) 432 : m_client(client)
434 , m_recursiveSerialization(recursiveSerialization)
435 , m_framesCollected(false)
436 , m_localDirectoryName(localDirectoryName) 433 , m_localDirectoryName(localDirectoryName)
437 , m_htmlEntities(false) 434 , m_htmlEntities(false)
438 , m_xmlEntities(true) 435 , m_xmlEntities(true)
439 { 436 {
440 // Must specify available webframe. 437 // Must specify available webframe.
441 ASSERT(frame); 438 ASSERT(frame);
442 m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame); 439 m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame);
443 // Make sure we have non 0 client. 440 // Make sure we have non 0 client.
444 ASSERT(client); 441 ASSERT(client);
445 // Build local resources map. 442 // Build local resources map.
446 ASSERT(links.size() == localPaths.size()); 443 ASSERT(links.size() == localPaths.size());
447 for (size_t i = 0; i < links.size(); i++) { 444 for (size_t i = 0; i < links.size(); i++) {
448 KURL url = links[i]; 445 KURL url = links[i];
449 ASSERT(!m_localLinks.contains(url.string())); 446 ASSERT(!m_localLinks.contains(url.string()));
450 m_localLinks.set(url.string(), localPaths[i]); 447 m_localLinks.set(url.string(), localPaths[i]);
451 } 448 }
452 449
453 ASSERT(m_dataBuffer.isEmpty()); 450 ASSERT(m_dataBuffer.isEmpty());
454 } 451 }
455 452
456 void WebPageSerializerImpl::collectTargetFrames()
457 {
458 ASSERT(!m_framesCollected);
459 m_framesCollected = true;
460
461 // First, process main frame.
462 m_frames.append(m_specifiedWebLocalFrameImpl);
463 // Return now if user only needs to serialize specified frame, not including
464 // all sub-frames.
465 if (!m_recursiveSerialization)
466 return;
467 // Collect all frames inside the specified frame.
468 for (WebLocalFrameImpl* frame : m_frames) {
469 // Get current using document.
470 Document* currentDoc = frame->frame()->document();
471 // Go through sub-frames.
472 RefPtrWillBeRawPtr<HTMLAllCollection> all = currentDoc->all();
473
474 for (unsigned i = 0; Element* element = all->item(i); ++i) {
475 if (!element->isHTMLElement())
476 continue;
477 WebLocalFrameImpl* webFrame =
478 WebLocalFrameImpl::fromFrameOwnerElement(element);
479 if (webFrame)
480 m_frames.append(webFrame);
481 }
482 }
483 }
484
485 bool WebPageSerializerImpl::serialize() 453 bool WebPageSerializerImpl::serialize()
486 { 454 {
487 if (!m_framesCollected)
488 collectTargetFrames();
489
490 bool didSerialization = false; 455 bool didSerialization = false;
491 KURL mainURL = m_specifiedWebLocalFrameImpl->frame()->document()->url(); 456 KURL mainURL = m_specifiedWebLocalFrameImpl->frame()->document()->url();
492 457
493 for (unsigned i = 0; i < m_frames.size(); ++i) { 458 WebLocalFrameImpl* webFrame = m_specifiedWebLocalFrameImpl;
494 WebLocalFrameImpl* webFrame = m_frames[i]; 459 Document* document = webFrame->frame()->document();
495 Document* document = webFrame->frame()->document(); 460 const KURL& url = document->url();
496 const KURL& url = document->url();
497 461
498 if (!url.isValid() || !m_localLinks.contains(url.string())) 462 if (url.isValid() || m_localLinks.contains(url.string())) {
dcheng 2015/09/25 19:53:52 Should this be &&?
Łukasz Anforowicz 2015/09/25 20:35:57 Right. My bad.
499 continue;
500
501 didSerialization = true; 463 didSerialization = true;
502 464
503 const WTF::TextEncoding& textEncoding = document->encoding().isValid() ? document->encoding() : UTF8Encoding(); 465 const WTF::TextEncoding& textEncoding = document->encoding().isValid() ? document->encoding() : UTF8Encoding();
504 String directoryName = url == mainURL ? m_localDirectoryName : ""; 466 String directoryName = url == mainURL ? m_localDirectoryName : "";
505 467
506 SerializeDomParam param(url, textEncoding, document, directoryName); 468 SerializeDomParam param(url, textEncoding, document, directoryName);
507 469
508 Element* documentElement = document->documentElement(); 470 Element* documentElement = document->documentElement();
509 if (documentElement) 471 if (documentElement)
510 buildContentForNode(documentElement, &param); 472 buildContentForNode(documentElement, &param);
511 473
512 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p aram, ForceFlush); 474 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p aram, ForceFlush);
513 } 475 }
514 476
515 ASSERT(m_dataBuffer.isEmpty()); 477 ASSERT(m_dataBuffer.isEmpty());
516 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali zerClient::AllFramesAreFinished); 478 m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSeriali zerClient::AllFramesAreFinished);
517 return didSerialization; 479 return didSerialization;
518 } 480 }
519 481
520 } // namespace blink 482 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698