Changeset 142363 in webkit


Ignore:
Timestamp:
Feb 9, 2013 9:52:19 AM (11 years ago)
Author:
eric@webkit.org
Message:

Fix TextDocumentParser to play nice with threading
https://bugs.webkit.org/show_bug.cgi?id=109240

Reviewed by Adam Barth.

Before the HTML5 parser re-write the text document parser
was completely custom. With the HTML5 parser, we just made
the TextDocumentParser use the HTMLDocumentParser with an
artificial script tag.

However, our solution was slightly over-engineered to avoid
lying about the column numbers of the first line of the text document
during parsing. :)

This change makes us use a simpler (and threading-compatible)
solution by just inserting a real "<pre>" tag into the
input stream instead of hacking one together with the treebuilder
and manually setting the Tokenizer state.

fast/parser/empty-text-resource.html covers this case.

  • html/parser/TextDocumentParser.cpp:

(WebCore::TextDocumentParser::TextDocumentParser):
(WebCore::TextDocumentParser::insertFakePreElement):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142359 r142363  
     12013-02-09  Eric Seidel  <eric@webkit.org>
     2
     3        Fix TextDocumentParser to play nice with threading
     4        https://bugs.webkit.org/show_bug.cgi?id=109240
     5
     6        Reviewed by Adam Barth.
     7
     8        Before the HTML5 parser re-write the text document parser
     9        was completely custom.  With the HTML5 parser, we just made
     10        the TextDocumentParser use the HTMLDocumentParser with an
     11        artificial script tag.
     12
     13        However, our solution was slightly over-engineered to avoid
     14        lying about the column numbers of the first line of the text document
     15        during parsing. :)
     16
     17        This change makes us use a simpler (and threading-compatible)
     18        solution by just inserting a real "<pre>" tag into the
     19        input stream instead of hacking one together with the treebuilder
     20        and manually setting the Tokenizer state.
     21
     22        fast/parser/empty-text-resource.html covers this case.
     23
     24        * html/parser/TextDocumentParser.cpp:
     25        (WebCore::TextDocumentParser::TextDocumentParser):
     26        (WebCore::TextDocumentParser::insertFakePreElement):
     27
    1282013-02-09  Kent Tamura  <tkent@chromium.org>
    229
  • trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp

    r142305 r142363  
    9797}
    9898
     99void BackgroundHTMLParser::forcePlaintextForTextDocument()
     100{
     101    // This is only used by the TextDocumentParser (a subclass of HTMLDocumentParser)
     102    // to force us into the PLAINTEXT state w/o using a <plaintext> tag.
     103    // The TextDocumentParser uses a <pre> tag for historical/compatibility reasons.
     104    m_tokenizer->setState(HTMLTokenizerState::PLAINTEXTState);
     105}
     106
    99107void BackgroundHTMLParser::markEndOfFile()
    100108{
  • trunk/Source/WebCore/html/parser/BackgroundHTMLParser.h

    r142305 r142363  
    5959    void stop();
    6060
     61    void forcePlaintextForTextDocument();
     62
    6163private:
    6264    BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser> >, const HTMLParserOptions&, const WeakPtr<HTMLDocumentParser>&, PassOwnPtr<XSSAuditor>);
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r142305 r142363  
    356356#endif // ENABLE(THREADED_HTML_PARSER)
    357357
     358void HTMLDocumentParser::forcePlaintextForTextDocument()
     359{
     360#if ENABLE(THREADED_HTML_PARSER)
     361    if (shouldUseThreading()) {
     362        // This method is called before any data is appended, so we have to start
     363        // the background parser ourselves.
     364        if (!m_haveBackgroundParser)
     365            startBackgroundParser();
     366
     367        HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::forcePlaintextForTextDocument, m_backgroundParser));
     368    } else
     369#endif
     370        m_tokenizer->setState(HTMLTokenizerState::PLAINTEXTState);
     371}
     372
    358373void HTMLDocumentParser::pumpTokenizer(SynchronousMode mode)
    359374{
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.h

    r142305 r142363  
    102102    HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); }
    103103
     104    void forcePlaintextForTextDocument();
     105
    104106private:
    105107    static PassRefPtr<HTMLDocumentParser> create(DocumentFragment* fragment, Element* contextElement, FragmentScriptingPermission permission)
  • trunk/Source/WebCore/html/parser/TextDocumentParser.cpp

    r141328 r142363  
    3939    , m_haveInsertedFakePreElement(false)
    4040{
    41     // FIXME: If we're using threading, we need to tell the BackgroundHTMLParser to use PLAINTEXTState.
    42     if (tokenizer())
    43         tokenizer()->setState(HTMLTokenizerState::PLAINTEXTState);
    4441}
    4542
     
    6259    // sending fake bytes through the front-end of the parser to avoid
    6360    // distrubing the line/column number calculations.
    64 
    6561    Vector<Attribute> attributes;
    6662    attributes.append(Attribute(styleAttr, "word-wrap: break-word; white-space: pre-wrap;"));
    6763    RefPtr<AtomicHTMLToken> fakePre = AtomicHTMLToken::create(HTMLTokenTypes::StartTag, preTag.localName(), attributes);
     64    treeBuilder()->constructTree(fakePre.get());
    6865
    69     treeBuilder()->constructTree(fakePre.get());
    7066    // Normally we would skip the first \n after a <pre> element, but we don't
    7167    // want to skip the first \n for text documents!
    7268    treeBuilder()->setShouldSkipLeadingNewline(false);
     69
     70    // Although Text Documents expose a "pre" element in their DOM, they
     71    // act like a <plaintext> tag, so we have to force plaintext mode.
     72    forcePlaintextForTextDocument();
    7373
    7474    m_haveInsertedFakePreElement = true;
Note: See TracChangeset for help on using the changeset viewer.