Changeset 69675 in webkit


Ignore:
Timestamp:
Oct 13, 2010 11:12:42 AM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-10-13 Adam Barth <abarth@webkit.org>

Reviewed by Tony Chang.

[Chromium] Clean up WebPageSerializerImpl::serialize
https://bugs.webkit.org/show_bug.cgi?id=47577

This patch shouldn't have any behavior change. I'm just trying to
understand what this code does.

  • src/WebPageSerializerImpl.cpp: (WebKit::WebPageSerializerImpl::saveHTMLContentToBuffer): (WebKit::WebPageSerializerImpl::encodeAndFlushBuffer): (WebKit::WebPageSerializerImpl::serialize):
  • src/WebPageSerializerImpl.h:
Location:
trunk/WebKit/chromium
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r69673 r69675  
     12010-10-13  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        [Chromium] Clean up WebPageSerializerImpl::serialize
     6        https://bugs.webkit.org/show_bug.cgi?id=47577
     7
     8        This patch shouldn't have any behavior change.  I'm just trying to
     9        understand what this code does.
     10
     11        * src/WebPageSerializerImpl.cpp:
     12        (WebKit::WebPageSerializerImpl::saveHTMLContentToBuffer):
     13        (WebKit::WebPageSerializerImpl::encodeAndFlushBuffer):
     14        (WebKit::WebPageSerializerImpl::serialize):
     15        * src/WebPageSerializerImpl.h:
     16
    1172010-10-13  John Knottenbelt  <jknotten@chromium.org>
    218
  • trunk/WebKit/chromium/src/WebPageSerializerImpl.cpp

    r69668 r69675  
    270270    encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsNotFinished,
    271271                         param,
    272                          0);
     272                         DoNotForceFlush);
    273273}
    274274
     
    276276    WebPageSerializerClient::PageSerializationStatus status,
    277277    SerializeDomParam* param,
    278     bool force)
     278    FlushOption flushOption)
    279279{
    280280    // Data buffer is not full nor do we want to force flush.
    281     if (!force && m_dataBuffer.size() <= dataBufferCapacity)
     281    if (flushOption != ForceFlush && m_dataBuffer.size() <= dataBufferCapacity)
    282282        return;
    283283
     
    490490bool WebPageSerializerImpl::serialize()
    491491{
    492     // Collect target frames.
    493492    if (!m_framesCollected)
    494493        collectTargetFrames();
     494
    495495    bool didSerialization = false;
    496     // Get KURL for main frame.
    497     KURL mainPageURL = m_specifiedWebFrameImpl->frame()->loader()->url();
    498 
    499     // Go through all frames for serializing DOM for whole page, include
    500     // sub-frames.
    501     for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) {
    502         // Get current serializing frame.
    503         WebFrameImpl* currentFrame = m_frames[i];
    504         // Get current using document.
    505         Document* currentDoc = currentFrame->frame()->document();
    506         // Get current frame's URL.
    507         const KURL& currentFrameURL = currentFrame->frame()->loader()->url();
    508 
    509         // Check whether we have done this document.
    510         if (currentFrameURL.isValid() && m_localLinks.contains(currentFrameURL.string())) {
    511             // A new document, we will serialize it.
    512             didSerialization = true;
    513             // Get target encoding for current document.
    514             String encoding = currentFrame->frame()->loader()->writer()->encoding();
    515             // Create the text encoding object with target encoding.
    516             TextEncoding textEncoding(encoding);
    517             // Construct serialize parameter for late processing document.
    518             SerializeDomParam param(currentFrameURL,
    519                                     encoding.length() ? textEncoding : UTF8Encoding(),
    520                                     currentDoc,
    521                                     currentFrameURL == mainPageURL ? m_localDirectoryName : "");
    522 
    523             // Process current document.
    524             Element* rootElement = currentDoc->documentElement();
    525             if (rootElement)
    526                 buildContentForNode(rootElement, &param);
    527 
    528             // Flush the remainder data and finish serializing current frame.
    529             encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished,
    530                                  &param,
    531                                  1);
    532         }
    533     }
    534 
    535     // We have done call frames, so we send message to embedder to tell it that
    536     // frames are finished serializing.
     496    KURL mainURL = m_specifiedWebFrameImpl->frame()->document()->url();
     497
     498    for (unsigned i = 0; i < m_frames.size(); ++i) {
     499        WebFrameImpl* webFrame = m_frames[i];
     500        Document* document = webFrame->frame()->document();
     501        const KURL& url = document->url();
     502
     503        if (!url.isValid() || !m_localLinks.contains(url.string()))
     504            continue;
     505
     506        didSerialization = true;
     507
     508        String encoding = webFrame->frame()->loader()->writer()->encoding();
     509        const TextEncoding& textEncoding = encoding.isEmpty() ? UTF8Encoding() : TextEncoding(encoding);
     510        String directoryName = url == mainURL ? m_localDirectoryName : "";
     511
     512        SerializeDomParam param(url, textEncoding, document, directoryName);
     513
     514        Element* documentElement = document->documentElement();
     515        if (documentElement)
     516            buildContentForNode(documentElement, &param);
     517
     518        encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &param, ForceFlush);
     519    }
     520
    537521    ASSERT(m_dataBuffer.isEmpty());
    538     m_client->didSerializeDataForFrame(KURL(),
    539                                        WebCString("", 0),
    540                                        WebPageSerializerClient::AllFramesAreFinished);
     522    m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSerializerClient::AllFramesAreFinished);
    541523    return didSerialization;
    542524}
  • trunk/WebKit/chromium/src/WebPageSerializerImpl.h

    r69668 r69675  
    162162    void saveHTMLContentToBuffer(const WTF::String& content,
    163163                                 SerializeDomParam* param);
     164
     165    enum FlushOption {
     166        ForceFlush,
     167        DoNotForceFlush,
     168    };
     169
    164170    // Flushes the content buffer by encoding and sending the content to the
    165171    // WebPageSerializerClient. Content is not flushed if the buffer is not full
     
    167173    void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus status,
    168174                              SerializeDomParam* param,
    169                               bool force);
     175                              FlushOption);
    170176    // Serialize open tag of an specified element.
    171177    void openTagToString(const WebCore::Element* element,
Note: See TracChangeset for help on using the changeset viewer.