Changeset 88609 in webkit


Ignore:
Timestamp:
Jun 11, 2011 5:51:11 PM (13 years ago)
Author:
abarth@webkit.org
Message:

2011-06-11 Adam Barth <abarth@webkit.org>

Reviewed by Darin Adler.

DocumentParser::appendBytes shouldn't have a "flush" boolean parameter
https://bugs.webkit.org/show_bug.cgi?id=62499

This patch removes the "flush" Boolean parameter from
DocumentParser::appendBytes in favor of a new flush method. This makes
some code in DocumentWriter look less ridiculous.

There's still lots of on contorting to do here, but it's a start.

  • dom/DecodedDataDocumentParser.cpp: (WebCore::DecodedDataDocumentParser::appendBytes): (WebCore::DecodedDataDocumentParser::flush):
  • dom/DecodedDataDocumentParser.h:
  • dom/DocumentParser.h:
  • dom/RawDataDocumentParser.h: (WebCore::RawDataDocumentParser::flush):
  • html/ImageDocument.cpp: (WebCore::ImageDocumentParser::appendBytes):
  • html/MediaDocument.cpp: (WebCore::MediaDocumentParser::appendBytes):
  • html/PluginDocument.cpp: (WebCore::PluginDocumentParser::appendBytes):
  • loader/DocumentWriter.cpp: (WebCore::DocumentWriter::reportDataReceived): (WebCore::DocumentWriter::addData): (WebCore::DocumentWriter::endIfNotLoadingMainResource):
  • loader/DocumentWriter.h:
  • loader/SinkDocument.cpp: (WebCore::SinkDocumentParser::appendBytes):
Location:
trunk/Source/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r88606 r88609  
     12011-06-11  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        DocumentParser::appendBytes shouldn't have a "flush" boolean parameter
     6        https://bugs.webkit.org/show_bug.cgi?id=62499
     7
     8        This patch removes the "flush" Boolean parameter from
     9        DocumentParser::appendBytes in favor of a new flush method.  This makes
     10        some code in DocumentWriter look less ridiculous.
     11
     12        There's still lots of on contorting to do here, but it's a start.
     13
     14        * dom/DecodedDataDocumentParser.cpp:
     15        (WebCore::DecodedDataDocumentParser::appendBytes):
     16        (WebCore::DecodedDataDocumentParser::flush):
     17        * dom/DecodedDataDocumentParser.h:
     18        * dom/DocumentParser.h:
     19        * dom/RawDataDocumentParser.h:
     20        (WebCore::RawDataDocumentParser::flush):
     21        * html/ImageDocument.cpp:
     22        (WebCore::ImageDocumentParser::appendBytes):
     23        * html/MediaDocument.cpp:
     24        (WebCore::MediaDocumentParser::appendBytes):
     25        * html/PluginDocument.cpp:
     26        (WebCore::PluginDocumentParser::appendBytes):
     27        * loader/DocumentWriter.cpp:
     28        (WebCore::DocumentWriter::reportDataReceived):
     29        (WebCore::DocumentWriter::addData):
     30        (WebCore::DocumentWriter::endIfNotLoadingMainResource):
     31        * loader/DocumentWriter.h:
     32        * loader/SinkDocument.cpp:
     33        (WebCore::SinkDocumentParser::appendBytes):
     34
    1352011-06-11  Dimitri Glazkov  <dglazkov@chromium.org>
    236
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r88380 r88609  
    74387438                417DA4CE13734326007C57FB /* Internals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Internals.h; sourceTree = "<group>"; };
    74397439                417DA4CF13734326007C57FB /* Internals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Internals.cpp; sourceTree = "<group>"; };
    7440                 417DA6D013734E02007C57FB /* WebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = WebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
     7440                417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libWebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
    74417441                417DA71B13735DFA007C57FB /* JSInternals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInternals.cpp; sourceTree = "<group>"; };
    74427442                417DA71C13735DFA007C57FB /* JSInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternals.h; sourceTree = "<group>"; };
     
    1273112731                        children = (
    1273212732                                5D87BB4F11E3EAEB00702B6F /* WebCoreExportFileGenerator */,
    12733                                 417DA6D013734E02007C57FB /* WebCoreTestSupport.dylib */,
     12733                                417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */,
    1273412734                                93F19B1A08245E5A001E9ABC /* WebCore.framework */,
    1273512735                        );
     
    2319523195                        name = WebCoreTestSupport;
    2319623196                        productName = WebCoreTestSupport;
    23197                         productReference = 417DA6D013734E02007C57FB /* WebCoreTestSupport.dylib */;
     23197                        productReference = 417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */;
    2319823198                        productType = "com.apple.product-type.library.dynamic";
    2319923199                };
  • trunk/Source/WebCore/dom/DecodedDataDocumentParser.cpp

    r66967 r88609  
    3838}
    3939
    40 void DecodedDataDocumentParser::appendBytes(DocumentWriter* writer , const char* data, int length, bool shouldFlush)
     40void DecodedDataDocumentParser::appendBytes(DocumentWriter* writer, const char* data, int length)
    4141{
    42     if (!length && !shouldFlush)
     42    if (!length)
    4343        return;
    4444
    45     TextResourceDecoder* decoder = writer->createDecoderIfNeeded();
    46     String decoded = decoder->decode(data, length);
    47     if (shouldFlush)
    48         decoded += decoder->flush();
     45    String decoded = writer->createDecoderIfNeeded()->decode(data, length);
    4946    if (decoded.isEmpty())
    5047        return;
    5148
    5249    writer->reportDataReceived();
    53 
    5450    append(decoded);
    5551}
    5652
     53void DecodedDataDocumentParser::flush(DocumentWriter* writer)
     54{
     55    String remainingData = writer->createDecoderIfNeeded()->flush();
     56    if (remainingData.isEmpty())
     57        return;
     58
     59    writer->reportDataReceived();
     60    append(remainingData);
     61}
     62
    5763};
    58 
  • trunk/Source/WebCore/dom/DecodedDataDocumentParser.h

    r66967 r88609  
    4141
    4242private:
    43     // append is used by DocumentWriter::replaceDocument
     43    // append is used by DocumentWriter::replaceDocument.
    4444    virtual void append(const SegmentedString&) = 0;
    4545
    46     // appendBytes is used by DocumentWriter (the loader)
    47     virtual void appendBytes(DocumentWriter*, const char* bytes, int length, bool flush);
     46    // appendBytes and flush are used by DocumentWriter (the loader).
     47    virtual void appendBytes(DocumentWriter*, const char* bytes, int length);
     48    virtual void flush(DocumentWriter*);
    4849};
    4950
  • trunk/Source/WebCore/dom/DocumentParser.h

    r75066 r88609  
    4343    virtual bool hasInsertionPoint() { return true; }
    4444
    45     // insert is used by document.write
     45    // insert is used by document.write.
    4646    virtual void insert(const SegmentedString&) = 0;
    4747
    48     // appendBytes is used by DocumentWriter (the loader)
    49     virtual void appendBytes(DocumentWriter*, const char* bytes, int length, bool flush) = 0;
     48    // appendBytes and flush are used by DocumentWriter (the loader).
     49    virtual void appendBytes(DocumentWriter*, const char* bytes, int length) = 0;
     50    virtual void flush(DocumentWriter*) = 0;
    5051
    5152    // FIXME: append() should be private, but DocumentWriter::replaceDocument
  • trunk/Source/WebCore/dom/RawDataDocumentParser.h

    r66670 r88609  
    4545
    4646private:
     47    virtual void flush(DocumentWriter* writer)
     48    {
     49        // Make sure appendBytes is called at least once.
     50        appendBytes(writer, 0, 0);
     51    }
     52
    4753    virtual void insert(const SegmentedString&)
    4854    {
  • trunk/Source/WebCore/html/ImageDocument.cpp

    r79288 r88609  
    9191    }
    9292
    93     virtual void appendBytes(DocumentWriter*, const char*, int, bool);
     93    virtual void appendBytes(DocumentWriter*, const char*, int);
    9494    virtual void finish();
    9595};
     
    125125}
    126126
    127 void ImageDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool)
     127void ImageDocumentParser::appendBytes(DocumentWriter*, const char*, int)
    128128{
    129129    Frame* frame = document()->frame();
  • trunk/Source/WebCore/html/MediaDocument.cpp

    r88600 r88609  
    6161    }
    6262
    63     virtual void appendBytes(DocumentWriter*, const char*, int, bool);
     63    virtual void appendBytes(DocumentWriter*, const char*, int);
    6464
    6565    void createDocumentStructure();
     
    104104}
    105105
    106 void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool)
     106void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, int)
    107107{
    108108    if (m_mediaElement)
  • trunk/Source/WebCore/html/PluginDocument.cpp

    r88600 r88609  
    5959    }
    6060
    61     virtual void appendBytes(DocumentWriter*, const char*, int, bool);
     61    virtual void appendBytes(DocumentWriter*, const char*, int);
    6262
    6363    void createDocumentStructure();
     
    104104}
    105105
    106 void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool)
     106void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, int)
    107107{
    108108    if (m_embedElement)
  • trunk/Source/WebCore/loader/DocumentWriter.cpp

    r88583 r88609  
    5757DocumentWriter::DocumentWriter(Frame* frame)
    5858    : m_frame(frame)
    59     , m_receivedData(false)
     59    , m_hasReceivedSomeData(false)
    6060    , m_encodingWasChosenByUser(false)
    6161{
     
    7171
    7272    if (!source.isNull()) {
    73         if (!m_receivedData) {
    74             m_receivedData = true;
     73        if (!m_hasReceivedSomeData) {
     74            m_hasReceivedSomeData = true;
    7575            m_frame->document()->setCompatibilityMode(Document::NoQuirksMode);
    7676        }
     
    8888{
    8989    m_decoder = 0;
    90     m_receivedData = false;
     90    m_hasReceivedSomeData = false;
    9191    if (!m_encodingWasChosenByUser)
    9292        m_encoding = String();
     
    145145    document->implicitOpen();
    146146
     147    // We grab a reference to the parser so that we'll always send data to the
     148    // original parser, even if the document acquires a new parser (e.g., via
     149    // document.open).
    147150    m_parser = document->parser();
    148151
     
    188191{
    189192    ASSERT(m_decoder);
    190     if (!m_receivedData) {
    191         m_receivedData = true;
    192         if (m_decoder->encoding().usesVisualOrdering())
    193             m_frame->document()->setVisuallyOrdered();
    194         m_frame->document()->recalcStyle(Node::Force);
    195     }
    196 }
    197 
    198 void DocumentWriter::addData(const char* str, int len, bool flush)
    199 {
    200     if (len == -1)
    201         len = strlen(str);
    202 
    203     m_parser->appendBytes(this, str, len, flush);
     193    if (m_hasReceivedSomeData)
     194        return;
     195    m_hasReceivedSomeData = true;
     196    if (m_decoder->encoding().usesVisualOrdering())
     197        m_frame->document()->setVisuallyOrdered();
     198    m_frame->document()->recalcStyle(Node::Force);
     199}
     200
     201void DocumentWriter::addData(const char* bytes, int length)
     202{
     203    if (length == -1)
     204        length = strlen(bytes);
     205
     206    m_parser->appendBytes(this, bytes, length);
    204207}
    205208
     
    220223    RefPtr<Frame> protector(m_frame);
    221224
    222     // FIXME: Can we remove this call? Finishing the parser should flush anyway.
    223     addData(0, 0, true);
    224 
     225    // FIXME: m_parser->finish() should imply m_parser->flush().
     226    m_parser->flush(this);
    225227    if (!m_parser)
    226228        return;
  • trunk/Source/WebCore/loader/DocumentWriter.h

    r88583 r88609  
    5252    void begin();
    5353    void begin(const KURL&, bool dispatchWindowObjectAvailable = true, SecurityOrigin* forcedSecurityOrigin = 0);
    54     void addData(const char* string, int length = -1, bool flush = false);
     54    void addData(const char* bytes, int length = -1);
    5555    void end();
    5656    void endIfNotLoadingMainResource();
     
    8383    Frame* m_frame;
    8484
    85     bool m_receivedData;
     85    bool m_hasReceivedSomeData;
    8686    String m_mimeType;
    8787
  • trunk/Source/WebCore/loader/SinkDocument.cpp

    r66247 r88609  
    4545
    4646    // Ignore all data.
    47     virtual void appendBytes(DocumentWriter*, const char*, int, bool) { }
     47    virtual void appendBytes(DocumentWriter*, const char*, int) { }
    4848};
    4949
Note: See TracChangeset for help on using the changeset viewer.