Changeset 139042 in webkit


Ignore:
Timestamp:
Jan 8, 2013, 12:23:01 AM (13 years ago)
Author:
abarth@webkit.org
Message:

HTMLTreeBuilder shouldn't keep a Document pointer
https://bugs.webkit.org/show_bug.cgi?id=106268

Reviewed by Eric Seidel.

The tree builder shouldn't interact with the Document directly.
Instead, the tree builder should use the HTMLConstructionSite to
interact with the document.

Unfortunately, the HTMLTreeBuilder does need to read back one bit of
information (the quirks mode) from the Document. Currently the
HTMLConstructionSite reads the information directly from the Document.
If/when we move the parser onto its own thread, we'll need to keep
track of this bit on the parser thread. (We should be able to
encapsulate all that logic in the HTMLConstructionSite.)

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::HTMLConstructionSite::setDefaultCompatibilityMode):
(WebCore):
(WebCore::HTMLConstructionSite::finishedParsing):
(WebCore::HTMLConstructionSite::inQuirksMode):

  • html/parser/HTMLConstructionSite.h:

(HTMLConstructionSite):

  • html/parser/HTMLTreeBuilder.cpp:

(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::detach):
(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::defaultForInitial):
(WebCore::HTMLTreeBuilder::finished):

  • html/parser/HTMLTreeBuilder.h:

(HTMLTreeBuilder):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r139040 r139042  
     12013-01-08  Adam Barth  <abarth@webkit.org>
     2
     3        HTMLTreeBuilder shouldn't keep a Document pointer
     4        https://bugs.webkit.org/show_bug.cgi?id=106268
     5
     6        Reviewed by Eric Seidel.
     7
     8        The tree builder shouldn't interact with the Document directly.
     9        Instead, the tree builder should use the HTMLConstructionSite to
     10        interact with the document.
     11
     12        Unfortunately, the HTMLTreeBuilder does need to read back one bit of
     13        information (the quirks mode) from the Document. Currently the
     14        HTMLConstructionSite reads the information directly from the Document.
     15        If/when we move the parser onto its own thread, we'll need to keep
     16        track of this bit on the parser thread. (We should be able to
     17        encapsulate all that logic in the HTMLConstructionSite.)
     18
     19        * html/parser/HTMLConstructionSite.cpp:
     20        (WebCore::HTMLConstructionSite::setDefaultCompatibilityMode):
     21        (WebCore):
     22        (WebCore::HTMLConstructionSite::finishedParsing):
     23        (WebCore::HTMLConstructionSite::inQuirksMode):
     24        * html/parser/HTMLConstructionSite.h:
     25        (HTMLConstructionSite):
     26        * html/parser/HTMLTreeBuilder.cpp:
     27        (WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
     28        (WebCore::HTMLTreeBuilder::detach):
     29        (WebCore::HTMLTreeBuilder::processStartTagForInBody):
     30        (WebCore::HTMLTreeBuilder::defaultForInitial):
     31        (WebCore::HTMLTreeBuilder::finished):
     32        * html/parser/HTMLTreeBuilder.h:
     33        (HTMLTreeBuilder):
     34
    1352013-01-08  Yuki Sekiguchi  <yuki.sekiguchi@access-company.com>
    236
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r136467 r139042  
    226226}
    227227
     228void HTMLConstructionSite::setDefaultCompatibilityMode()
     229{
     230    if (m_isParsingFragment)
     231        return;
     232    if (m_document->isSrcdocDocument())
     233        return;
     234    m_document->setCompatibilityMode(Document::QuirksMode);
     235}
     236
     237void HTMLConstructionSite::finishedParsing()
     238{
     239    m_document->finishedParsing();
     240}
     241
    228242void HTMLConstructionSite::insertDoctype(AtomicHTMLToken* token)
    229243{
     
    481495}
    482496
     497bool HTMLConstructionSite::inQuirksMode()
     498{
     499    // When we move the parser onto a background thread, we'll need to keep track of this bit on the parser thread.
     500    return m_document->inQuirksMode();
     501}
     502
    483503void HTMLConstructionSite::findFosterSite(HTMLConstructionSiteTask& task)
    484504{
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.h

    r136467 r139042  
    8080    void executeQueuedTasks();
    8181
     82    void setDefaultCompatibilityMode();
     83    void finishedParsing();
     84
    8285    void insertDoctype(AtomicHTMLToken*);
    8386    void insertComment(AtomicHTMLToken*);
     
    108111    void generateImpliedEndTags();
    109112    void generateImpliedEndTagsWithExclusion(const AtomicString& tagName);
     113
     114    bool inQuirksMode();
    110115
    111116    bool isEmpty() const { return !m_openElements.stackDepth(); }
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r139020 r139042  
    2929
    3030#include "Comment.h"
    31 #include "DOMWindow.h"
    3231#include "DocumentFragment.h"
    3332#include "DocumentType.h"
     
    272271HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, HTMLDocument* document, bool, const HTMLParserOptions& options)
    273272    : m_framesetOk(true)
    274     , m_document(document)
     273#ifndef NDEBUG
     274    , m_isAttached(true)
     275#endif
    275276    , m_tree(document, options.maximumDOMTreeDepth)
    276277    , m_insertionMode(InitialMode)
     
    287288HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, FragmentScriptingPermission scriptingPermission, const HTMLParserOptions& options)
    288289    : m_framesetOk(true)
     290#ifndef NDEBUG
     291    , m_isAttached(true)
     292#endif
    289293    , m_fragmentContext(fragment, contextElement, scriptingPermission)
    290     , m_document(fragment->document())
    291294    , m_tree(fragment, scriptingPermission, options.maximumDOMTreeDepth)
    292295    , m_insertionMode(InitialMode)
     
    323326void HTMLTreeBuilder::detach()
    324327{
     328#ifndef NDEBUG
    325329    // This call makes little sense in fragment mode, but for consistency
    326330    // DocumentParser expects detach() to always be called before it's destroyed.
    327     m_document = 0;
     331    m_isAttached = false;
     332#endif
    328333    // HTMLConstructionSite might be on the callstack when detach() is called
    329334    // otherwise we'd just call m_tree.clear() here instead.
     
    825830    }
    826831    if (token->name() == tableTag) {
    827         if (!m_document->inQuirksMode() && m_tree.openElements()->inButtonScope(pTag))
     832        if (!m_tree.inQuirksMode() && m_tree.openElements()->inButtonScope(pTag))
    828833            processFakeEndTag(pTag);
    829834        m_tree.insertHTMLElement(token);
     
    26132618{
    26142619    notImplemented();
    2615     if (!m_fragmentContext.fragment() && !m_document->isSrcdocDocument())
    2616         m_document->setCompatibilityMode(Document::QuirksMode);
     2620    m_tree.setDefaultCompatibilityMode();
    26172621    // FIXME: parse error
    26182622    setInsertionMode(BeforeHTMLMode);
     
    29042908#endif
    29052909
    2906     ASSERT(m_document);
     2910    ASSERT(m_isAttached);
    29072911    // Warning, this may detach the parser. Do not do anything else after this.
    2908     m_document->finishedParsing();
     2912    m_tree.finishedParsing();
    29092913}
    29102914
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.h

    r139020 r139042  
    188188    void processCloseWhenNestedTag(AtomicHTMLToken*);
    189189
    190     bool m_framesetOk;
    191 
    192190    void parseError(AtomicHTMLToken*);
    193191
     
    221219    };
    222220
     221    bool m_framesetOk;
     222#ifndef NDEBUG
     223    bool m_isAttached;
     224#endif
    223225    FragmentParsingContext m_fragmentContext;
    224 
    225     Document* m_document;
    226226    HTMLConstructionSite m_tree;
    227227
Note: See TracChangeset for help on using the changeset viewer.