Changeset 61904 in webkit


Ignore:
Timestamp:
Jun 25, 2010 2:37:08 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-25 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Split DocumentParser::write into separate append and insert calls
https://bugs.webkit.org/show_bug.cgi?id=41197

Unfortunately this is still somewhat confusing as
"insert" means "insert this data at the current
insertion point and run the parser synchronously
unless we're in a nested write call" and "append"
means "append this data to the end and run the
parser if not in a nested call or until possibly yielding".

This at least makes clearer which document parsers implement
which behavior, and paves the way for moving the decoding
logic into DocumentParser from DocumentWriter.

No functional changes, thus no tests.

  • dom/Document.cpp: (WebCore::Document::write):
  • dom/DocumentParser.h:
  • dom/RawDataDocumentParser.h: (WebCore::RawDataDocumentParser::insert): (WebCore::RawDataDocumentParser::append):
  • dom/XMLDocumentParser.cpp: (WebCore::XMLDocumentParser::insert): (WebCore::XMLDocumentParser::append):
  • dom/XMLDocumentParser.h:
  • dom/XMLDocumentParserLibxml2.cpp: (WebCore::XMLDocumentParser::resumeParsing):
  • html/HTMLDocumentParser.cpp: (WebCore::HTMLDocumentParser::insert): (WebCore::HTMLDocumentParser::append): (WebCore::HTMLDocumentParser::parseDocumentFragment):
  • html/HTMLDocumentParser.h:
  • html/LegacyHTMLDocumentParser.cpp: (WebCore::LegacyHTMLDocumentParser::insert): (WebCore::LegacyHTMLDocumentParser::append):
  • html/LegacyHTMLDocumentParser.h:
  • loader/DocumentWriter.cpp: (WebCore::DocumentWriter::replaceDocument): (WebCore::DocumentWriter::addData):
  • loader/FTPDirectoryDocument.cpp: (WebCore::FTPDirectoryDocumentParser::FTPDirectoryDocumentParser): (WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate): (WebCore::FTPDirectoryDocumentParser::append):
  • loader/TextDocument.cpp: (WebCore::TextDocumentParser::insert): (WebCore::TextDocumentParser::append): (WebCore::TextDocumentParser::finish):
Location:
trunk/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r61898 r61904  
     12010-06-25  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Split DocumentParser::write into separate append and insert calls
     6        https://bugs.webkit.org/show_bug.cgi?id=41197
     7
     8        Unfortunately this is still somewhat confusing as
     9        "insert" means "insert this data at the current
     10        insertion point and run the parser synchronously
     11        unless we're in a nested write call" and "append"
     12        means "append this data to the end and run the
     13        parser if not in a nested call or until possibly yielding".
     14
     15        This at least makes clearer which document parsers implement
     16        which behavior, and paves the way for moving the decoding
     17        logic into DocumentParser from DocumentWriter.
     18
     19        No functional changes, thus no tests.
     20
     21        * dom/Document.cpp:
     22        (WebCore::Document::write):
     23        * dom/DocumentParser.h:
     24        * dom/RawDataDocumentParser.h:
     25        (WebCore::RawDataDocumentParser::insert):
     26        (WebCore::RawDataDocumentParser::append):
     27        * dom/XMLDocumentParser.cpp:
     28        (WebCore::XMLDocumentParser::insert):
     29        (WebCore::XMLDocumentParser::append):
     30        * dom/XMLDocumentParser.h:
     31        * dom/XMLDocumentParserLibxml2.cpp:
     32        (WebCore::XMLDocumentParser::resumeParsing):
     33        * html/HTMLDocumentParser.cpp:
     34        (WebCore::HTMLDocumentParser::insert):
     35        (WebCore::HTMLDocumentParser::append):
     36        (WebCore::HTMLDocumentParser::parseDocumentFragment):
     37        * html/HTMLDocumentParser.h:
     38        * html/LegacyHTMLDocumentParser.cpp:
     39        (WebCore::LegacyHTMLDocumentParser::insert):
     40        (WebCore::LegacyHTMLDocumentParser::append):
     41        * html/LegacyHTMLDocumentParser.h:
     42        * loader/DocumentWriter.cpp:
     43        (WebCore::DocumentWriter::replaceDocument):
     44        (WebCore::DocumentWriter::addData):
     45        * loader/FTPDirectoryDocument.cpp:
     46        (WebCore::FTPDirectoryDocumentParser::FTPDirectoryDocumentParser):
     47        (WebCore::FTPDirectoryDocumentParser::loadDocumentTemplate):
     48        (WebCore::FTPDirectoryDocumentParser::append):
     49        * loader/TextDocument.cpp:
     50        (WebCore::TextDocumentParser::insert):
     51        (WebCore::TextDocumentParser::append):
     52        (WebCore::TextDocumentParser::finish):
     53
    1542010-06-25  Daniel Cheng  <dcheng@chromium.org>
    255
  • trunk/WebCore/dom/Document.cpp

    r61868 r61904  
    19991999
    20002000    ASSERT(m_parser);
    2001     // FIXME: forceSynchronous should always be the same as the bool passed to
    2002     // write().  However LegacyHTMLDocumentParser uses write("", false) to pump
    2003     // the parser (after running external scripts, etc.) thus necessitating a
    2004     // separate state for forceSynchronous.
    2005     bool wasForcedSynchronous = false;
    2006     LegacyHTMLDocumentParser* parser = m_parser->asHTMLDocumentParser();
    2007     if (parser) {
    2008         wasForcedSynchronous = parser->forceSynchronous();
    2009         parser->setForceSynchronous(true);
    2010     }
    2011 
    2012     m_parser->write(text, false);
    2013 
    2014     if (m_parser && parser && m_parser->asHTMLDocumentParser() == parser)
    2015         parser->setForceSynchronous(wasForcedSynchronous);
     2001    m_parser->insert(text);
    20162002
    20172003#ifdef INSTRUMENT_LAYOUT_SCHEDULING
  • trunk/WebCore/dom/DocumentFragment.cpp

    r61835 r61904  
    9292bool DocumentFragment::parseXML(const String& source, Element* parent, FragmentScriptingPermission scriptingPermission)
    9393{
    94     return parseXMLDocumentFragment(source, this, parent, scriptingPermission);
     94    return XMLDocumentParser::parseDocumentFragment(source, this, parent, scriptingPermission);
    9595}
    9696
  • trunk/WebCore/dom/DocumentParser.h

    r61789 r61904  
    3939    virtual ~DocumentParser() { }
    4040
    41     // Script output must be prepended, while new data
    42     // received during executing a script must be appended, hence the
    43     // extra bool to be able to distinguish between both cases.
    44     // document.write() always uses false, while the loader uses true.
    45     virtual void write(const SegmentedString&, bool isFromNetwork) = 0;
     41    // insert is use by document.write
     42    virtual void insert(const SegmentedString&) = 0;
     43    // apend is used by DocumentWriter (the loader)
     44    virtual void append(const SegmentedString&) = 0;
     45
    4646    virtual void finish() = 0;
    4747    virtual bool finishWasCalled() = 0;
  • trunk/WebCore/dom/RawDataDocumentParser.h

    r61789 r61904  
    5252
    5353private:
    54     virtual void write(const SegmentedString&, bool)
     54    virtual void insert(const SegmentedString&)
    5555    {
    5656        // <https://bugs.webkit.org/show_bug.cgi?id=25397>: JS code can always call document.write, we need to handle it.
     57        ASSERT_NOT_REACHED();
     58    }
     59
     60    virtual void append(const SegmentedString&)
     61    {
    5762        ASSERT_NOT_REACHED();
    5863    }
  • trunk/WebCore/dom/XMLDocumentParser.cpp

    r61737 r61904  
    117117}
    118118
    119 void XMLDocumentParser::write(const SegmentedString& s, bool /*appendData*/)
     119void XMLDocumentParser::insert(const SegmentedString& source)
     120{
     121    // FIXME: This is a hack to work around the fact that XMLHttpRequest
     122    // responseXML() calls Document::write() which in turn calls insert(). In
     123    // HTML, that's correct, as insert() implies a synchronous parse.  For XML,
     124    // all parsing is synchronous but document.write shouldn't be supported.
     125    append(source);
     126}
     127
     128void XMLDocumentParser::append(const SegmentedString& s)
    120129{
    121130    String parseString = s.toString();
  • trunk/WebCore/dom/XMLDocumentParser.h

    r61835 r61904  
    9191#endif
    9292
     93    static bool parseDocumentFragment(const String&, DocumentFragment*, Element* parent = 0, FragmentScriptingPermission = FragmentScriptingAllowed);
     94
    9395    private:
    9496        // From DocumentParser
    95         virtual void write(const SegmentedString&, bool appendData);
     97        virtual void insert(const SegmentedString&);
     98        virtual void append(const SegmentedString&);
    9699        virtual void finish();
    97100        virtual bool finishWasCalled();
     
    139142#endif
    140143    private:
    141         friend bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element*, FragmentScriptingPermission);
    142 
    143144        void initializeParserContext(const char* chunk = 0);
    144145
     
    207208
    208209HashMap<String, String> parseAttributes(const String&, bool& attrsOK);
    209 bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent = 0, FragmentScriptingPermission = FragmentScriptingAllowed);
    210210
    211211} // namespace WebCore
  • trunk/WebCore/dom/XMLDocumentParserLibxml2.cpp

    r61737 r61904  
    13641364    SegmentedString rest = m_pendingSrc;
    13651365    m_pendingSrc.clear();
    1366     write(rest, false);
     1366    append(rest);
    13671367
    13681368    // Finally, if finish() has been called and write() didn't result
     
    13741374// FIXME: This method should be possible to implement using the DocumentParser
    13751375// API, instead of needing to grab at libxml2 state directly.
    1376 bool parseXMLDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
     1376bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
    13771377{
    13781378    if (!chunk.length())
  • trunk/WebCore/dom/XMLDocumentParserQt.cpp

    r61738 r61904  
    246246    SegmentedString rest = m_pendingSrc;
    247247    m_pendingSrc.clear();
    248     write(rest, false);
    249 
    250     // Finally, if finish() has been called and write() didn't result
     248    append(rest);
     249
     250    // Finally, if finish() has been called and append() didn't result
    251251    // in any further callbacks being queued, call end()
    252252    if (m_finishCalled && !m_parserPaused && !m_pendingScript)
     
    254254}
    255255
    256 bool parseXMLDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
     256bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
    257257{
    258258    if (!chunk.length())
     
    261261    XMLDocumentParser parser(fragment, parent, scriptingPermission);
    262262
    263     parser.write(String("<qxmlstreamdummyelement>"), false);
    264     parser.write(chunk, false);
    265     parser.write(String("</qxmlstreamdummyelement>"), false);
     263    parser.append(String("<qxmlstreamdummyelement>"));
     264    parser.append(chunk);
     265    parser.append(String("</qxmlstreamdummyelement>"));
    266266    parser.finish();
    267267    return !parser.hasError();
  • trunk/WebCore/html/HTMLDocumentParser.cpp

    r61835 r61904  
    214214}
    215215
    216 void HTMLDocumentParser::write(const SegmentedString& source, bool isFromNetwork)
     216void HTMLDocumentParser::insert(const SegmentedString& source)
    217217{
    218218    if (m_parserStopped)
     
    220220
    221221    NestingLevelIncrementer nestingLevelIncrementer(m_writeNestingLevel);
    222 
    223     if (isFromNetwork) {
    224         m_input.appendToEnd(source);
    225         if (m_preloadScanner)
    226             m_preloadScanner->appendToEnd(source);
    227 
    228         if (m_writeNestingLevel > 1) {
    229             // We've gotten data off the network in a nested call to write().
    230             // We don't want to consume any more of the input stream now.  Do
    231             // not worry.  We'll consume this data in a less-nested write().
    232             return;
    233         }
    234     } else
    235         m_input.insertAtCurrentInsertionPoint(source);
    236 
    237     pumpTokenizerIfPossible(isFromNetwork ? AllowYield : ForceSynchronous);
     222    m_input.insertAtCurrentInsertionPoint(source);
     223    pumpTokenizerIfPossible(ForceSynchronous);
     224    endIfDelayed();
     225}
     226
     227void HTMLDocumentParser::append(const SegmentedString& source)
     228{
     229    if (m_parserStopped)
     230        return;
     231
     232    NestingLevelIncrementer nestingLevelIncrementer(m_writeNestingLevel);
     233
     234    m_input.appendToEnd(source);
     235    if (m_preloadScanner)
     236        m_preloadScanner->appendToEnd(source);
     237
     238    if (m_writeNestingLevel > 1) {
     239        // We've gotten data off the network in a nested write.
     240        // We don't want to consume any more of the input stream now.  Do
     241        // not worry.  We'll consume this data in a less-nested write().
     242        return;
     243    }
     244
     245    pumpTokenizerIfPossible(AllowYield);
    238246    endIfDelayed();
    239247}
     
    399407{
    400408    HTMLDocumentParser parser(fragment, scriptingPermission);
    401     parser.write(source, false);
     409    parser.insert(source); // Use insert() so that the parser will not yield.
    402410    parser.finish();
    403411    ASSERT(!parser.processingData()); // Make sure we're done. <rdar://problem/3963151>
  • trunk/WebCore/html/HTMLDocumentParser.h

    r61835 r61904  
    6565private:
    6666    // DocumentParser
    67     virtual void begin();
    68     virtual void write(const SegmentedString&, bool isFromNetwork);
     67    virtual void insert(const SegmentedString&);
     68    virtual void append(const SegmentedString&);
    6969    virtual void finish();
    7070    virtual bool finishWasCalled();
     
    102102    void resumeParsingAfterScriptExecution();
    103103
     104    void begin();
    104105    void attemptToEnd();
    105106    void endIfDelayed();
  • trunk/WebCore/html/LegacyHTMLDocumentParser.cpp

    r61835 r61904  
    17921792}
    17931793
     1794void LegacyHTMLDocumentParser::insert(const SegmentedString& source)
     1795{
     1796    // FIXME: forceSynchronous should always be the same as the bool passed to
     1797    // write().  However LegacyHTMLDocumentParser uses write("", false) to pump
     1798    // the parser (after running external scripts, etc.) thus necessitating a
     1799    // separate state for forceSynchronous.
     1800    bool wasForcedSynchronous = forceSynchronous();
     1801    setForceSynchronous(true);
     1802    write(source, false);
     1803    setForceSynchronous(wasForcedSynchronous);
     1804}
     1805
     1806void LegacyHTMLDocumentParser::append(const SegmentedString& source)
     1807{
     1808    write(source, true);
     1809}
     1810
    17941811void LegacyHTMLDocumentParser::stopParsing()
    17951812{
  • trunk/WebCore/html/LegacyHTMLDocumentParser.h

    r61835 r61904  
    158158protected:
    159159    // Exposed for FTPDirectoryDocumentParser
    160     virtual void write(const SegmentedString&, bool appendData);
     160    virtual void insert(const SegmentedString&);
    161161    virtual void finish();
    162162
    163163private:
    164164    // DocumentParser
     165    virtual void append(const SegmentedString&);
    165166    virtual bool finishWasCalled();
    166167    virtual bool isWaitingForScripts() const;
     
    184185
    185186    void willWriteHTML(const SegmentedString&);
     187    void write(const SegmentedString&, bool appendData);
    186188    ALWAYS_INLINE void advance(State&);
    187189    void didWriteHTML();
  • trunk/WebCore/loader/DocumentWriter.cpp

    r61868 r61904  
    7777        // case then we would need to call addData(char*, int) instead.
    7878        if (DocumentParser* parser = m_frame->document()->parser())
    79             parser->write(source, true);
     79            parser->append(source);
    8080    }
    8181
     
    204204    if (parser) {
    205205        ASSERT(!parser->wantsRawData());
    206         parser->write(decoded, true);
     206        parser->append(decoded);
    207207    }
    208208}
  • trunk/WebCore/loader/FTPDirectoryDocument.cpp

    r61868 r61904  
    5353    FTPDirectoryDocumentParser(HTMLDocument*);
    5454
    55     virtual void write(const SegmentedString&, bool appendData);
     55    virtual void append(const SegmentedString&);
    5656    virtual void finish();
    5757   
     
    101101    , m_buffer(static_cast<UChar*>(fastMalloc(sizeof(UChar) * m_size)))
    102102    , m_dest(m_buffer)
    103 {   
     103{
    104104}   
    105105
     
    302302        return false;
    303303    }
    304    
    305     // Tokenize the template as an HTML document synchronously
    306     setForceSynchronous(true);
    307     LegacyHTMLDocumentParser::write(String(templateDocumentData->data(), templateDocumentData->size()), true);
    308     setForceSynchronous(false);
     304
     305    LegacyHTMLDocumentParser::insert(String(templateDocumentData->data(), templateDocumentData->size()));
    309306   
    310307    RefPtr<Element> tableElement = document()->getElementById("ftpDirectoryTable");
     
    355352}
    356353
    357 void FTPDirectoryDocumentParser::write(const SegmentedString& s, bool /*appendData*/)
    358 {   
     354void FTPDirectoryDocumentParser::append(const SegmentedString& source)
     355{
    359356    // Make sure we have the table element to append to by loading the template set in the pref, or
    360357    // creating a very basic document with the appropriate table
     
    368365   
    369366    m_dest = m_buffer;
    370     SegmentedString str = s;
     367    SegmentedString str = source;
    371368    while (!str.isEmpty()) {
    372369        UChar c = *str;
  • trunk/WebCore/loader/TextDocument.cpp

    r61868 r61904  
    2626#include "TextDocument.h"
    2727
     28#include "DocumentParser.h"
    2829#include "Element.h"
    2930#include "HTMLNames.h"
     
    3132#include "SegmentedString.h"
    3233#include "Text.h"
    33 #include "XMLDocumentParser.h"
    3434
    3535using namespace std;
     
    4646
    4747private:
    48     virtual void write(const SegmentedString&, bool appendData);
     48    virtual void insert(const SegmentedString&);
     49    virtual void append(const SegmentedString&);
    4950    virtual void finish();
    5051    virtual bool finishWasCalled();
     
    100101}
    101102
    102 void TextDocumentParser::write(const SegmentedString& s, bool)
     103void TextDocumentParser::insert(const SegmentedString&)
     104{
     105    ASSERT_NOT_REACHED();
     106}
     107
     108void TextDocumentParser::append(const SegmentedString& s)
    103109{
    104110    ExceptionCode ec;
     
    163169{
    164170    if (!m_preElement)
    165         write(SegmentedString(), true); // Create document structure for an empty text document.
     171        append(SegmentedString()); // Create document structure for an empty text document.
    166172    m_preElement = 0;
    167173    fastFree(m_buffer);
Note: See TracChangeset for help on using the changeset viewer.