[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

eric at webkit.org eric at webkit.org
Wed Dec 22 12:27:04 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 508cf9e22d1d519075e76fca88fc2be9077ae133
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Aug 23 23:44:10 2010 +0000

    2010-08-23  Eric Seidel  <eric at webkit.org>
    
            Reviewed by Adam Barth.
    
            fast/dom/script-innerHTML-x.xhtml fails when run with the HTML5 TreeBuilder in fragment mode
            https://bugs.webkit.org/show_bug.cgi?id=44447
    
            This special handling for script/style used to exist in
            setInnerHTML.  HTML5 moves this logic into the HTML and XML
            parsers instead of in setInnerHTML.
    
            In order to share this logic between WebKit's two XML parsers
            I had to clean up a bit of the libxml2 parser and add a
            new appendFragmentSource method.
    
            Covered by fast/dom/script-innerHTML-x.xhtml.
    
            * dom/XMLDocumentParser.cpp:
            (WebCore::XMLDocumentParser::end):
             - Now that libxml2 is calling finish() for fragments (Qt already was)
               I went through and removed this unneeded style update after fragment parsing.
            (WebCore::XMLDocumentParser::parseDocumentFragment):
             - Yay for shared code!
             - This is where I added the style/script hack moved from setInnerHTML.
            * dom/XMLDocumentParser.h:
             - Fix indent.
            * dom/XMLDocumentParserLibxml2.cpp:
             - Removed parseDocumentFragment and moved necessary libxml-specific
               logic into appendFragmentSource.
            (WebCore::XMLDocumentParser::appendFragmentSource):
            * dom/XMLDocumentParserQt.cpp:
            (WebCore::XMLDocumentParser::appendFragmentSource):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65842 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 4672354..d2b23f3 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,36 @@
+2010-08-23  Eric Seidel  <eric at webkit.org>
+
+        Reviewed by Adam Barth.
+
+        fast/dom/script-innerHTML-x.xhtml fails when run with the HTML5 TreeBuilder in fragment mode
+        https://bugs.webkit.org/show_bug.cgi?id=44447
+
+        This special handling for script/style used to exist in
+        setInnerHTML.  HTML5 moves this logic into the HTML and XML
+        parsers instead of in setInnerHTML.
+
+        In order to share this logic between WebKit's two XML parsers
+        I had to clean up a bit of the libxml2 parser and add a
+        new appendFragmentSource method.
+
+        Covered by fast/dom/script-innerHTML-x.xhtml.
+
+        * dom/XMLDocumentParser.cpp:
+        (WebCore::XMLDocumentParser::end):
+         - Now that libxml2 is calling finish() for fragments (Qt already was)
+           I went through and removed this unneeded style update after fragment parsing.
+        (WebCore::XMLDocumentParser::parseDocumentFragment):
+         - Yay for shared code!
+         - This is where I added the style/script hack moved from setInnerHTML.
+        * dom/XMLDocumentParser.h:
+         - Fix indent.
+        * dom/XMLDocumentParserLibxml2.cpp:
+         - Removed parseDocumentFragment and moved necessary libxml-specific
+           logic into appendFragmentSource.
+        (WebCore::XMLDocumentParser::appendFragmentSource):
+        * dom/XMLDocumentParserQt.cpp:
+        (WebCore::XMLDocumentParser::appendFragmentSource):
+
 2010-08-23  Kenneth Russell  <kbr at google.com>
 
         Reviewed by Dimitri Glazkov.
diff --git a/WebCore/dom/XMLDocumentParser.cpp b/WebCore/dom/XMLDocumentParser.cpp
index a3828d5..054e4e3 100644
--- a/WebCore/dom/XMLDocumentParser.cpp
+++ b/WebCore/dom/XMLDocumentParser.cpp
@@ -213,6 +213,10 @@ void XMLDocumentParser::exitText()
 
 void XMLDocumentParser::end()
 {
+    // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is called.
+    // I don't believe XMLDocumentParserQt needs doEnd called in the fragment case.
+    ASSERT(!m_parsingFragment);
+
     doEnd();
 
     // doEnd() could process a script tag, thus pausing parsing.
@@ -227,8 +231,7 @@ void XMLDocumentParser::end()
     }
 
     clearCurrentNodeStack();
-    if (!m_parsingFragment)
-        document()->finishedParsing();
+    document()->finishedParsing();
 }
 
 void XMLDocumentParser::finish()
@@ -369,4 +372,25 @@ void XMLDocumentParser::pauseParsing()
     m_parserPaused = true;
 }
 
+bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* contextElement, FragmentScriptingPermission scriptingPermission)
+{
+    if (!chunk.length())
+        return true;
+
+    // FIXME: We need to implement the HTML5 XML Fragment parsing algorithm:
+    // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#xml-fragment-parsing-algorithm
+    // For now we have a hack for script/style innerHTML support:
+    if (contextElement && (contextElement->hasLocalName(HTMLNames::scriptTag) || contextElement->hasLocalName(HTMLNames::styleTag))) {
+        fragment->parserAddChild(fragment->document()->createTextNode(chunk));
+        return true;
+    }
+
+    RefPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, contextElement, scriptingPermission);
+    bool wellFormed = parser->appendFragmentSource(chunk);
+    // Do not call finish().  Current finish() and doEnd() implementations touch the main Document/loader
+    // and can cause crashes in the fragment case.
+    parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction.
+    return wellFormed; // appendFragmentSource()'s wellFormed is more permissive than wellFormed().
 }
+
+} // namespace WebCore
diff --git a/WebCore/dom/XMLDocumentParser.h b/WebCore/dom/XMLDocumentParser.h
index cdc770e..39bbcd9 100644
--- a/WebCore/dom/XMLDocumentParser.h
+++ b/WebCore/dom/XMLDocumentParser.h
@@ -97,7 +97,7 @@ namespace WebCore {
         bool isWMLDocument() const;
 #endif
 
-    static bool parseDocumentFragment(const String&, DocumentFragment*, Element* parent = 0, FragmentScriptingPermission = FragmentScriptingAllowed);
+        static bool parseDocumentFragment(const String&, DocumentFragment*, Element* parent = 0, FragmentScriptingPermission = FragmentScriptingAllowed);
 
         // WMLErrorHandling uses these functions.
         virtual bool wellFormed() const { return !m_sawError; }
@@ -124,6 +124,8 @@ namespace WebCore {
         void pauseParsing();
         void resumeParsing();
 
+        bool appendFragmentSource(const String&);
+
 #if USE(QXMLSTREAM)
 private:
         void parse();
diff --git a/WebCore/dom/XMLDocumentParserLibxml2.cpp b/WebCore/dom/XMLDocumentParserLibxml2.cpp
index 861853c..444edc5 100644
--- a/WebCore/dom/XMLDocumentParserLibxml2.cpp
+++ b/WebCore/dom/XMLDocumentParserLibxml2.cpp
@@ -1274,8 +1274,10 @@ void XMLDocumentParser::initializeParserContext(const char* chunk)
     XMLDocumentParserScope scope(document()->docLoader());
     if (m_parsingFragment)
         m_context = XMLParserContext::createMemoryParser(&sax, this, chunk);
-    else
+    else {
+        ASSERT(!chunk);
         m_context = XMLParserContext::createStringParser(&sax, this);
+    }
 }
 
 void XMLDocumentParser::doEnd()
@@ -1371,31 +1373,29 @@ void XMLDocumentParser::resumeParsing()
         end();
 }
 
-// FIXME: This method should be possible to implement using the DocumentParser
-// API, instead of needing to grab at libxml2 state directly.
-bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
+bool XMLDocumentParser::appendFragmentSource(const String& chunk)
 {
-    if (!chunk.length())
-        return true;
-
-    RefPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, parent, scriptingPermission);
+    ASSERT(!m_context);
+    ASSERT(m_parsingFragment);
 
     CString chunkAsUtf8 = chunk.utf8();
-    parser->initializeParserContext(chunkAsUtf8.data());
-
-    xmlParseContent(parser->context());
-
-    parser->endDocument();
+    initializeParserContext(chunkAsUtf8.data());
+    xmlParseContent(context());
+    endDocument(); // Close any open text nodes.
 
+    // FIXME: If this code is actually needed, it should probably move to finish()
+    // XMLDocumentParserQt has a similar check (m_stream.error() == QXmlStreamReader::PrematureEndOfDocumentError) in doEnd().
     // Check if all the chunk has been processed.
-    long bytesProcessed = xmlByteConsumed(parser->context());
-    if (bytesProcessed == -1 || ((unsigned long)bytesProcessed) != chunkAsUtf8.length())
+    long bytesProcessed = xmlByteConsumed(context());
+    if (bytesProcessed == -1 || ((unsigned long)bytesProcessed) != chunkAsUtf8.length()) {
+        // FIXME: I don't believe we can hit this case without also having seen an error.
+        // If we hit this ASSERT, we've found a test case which demonstrates the need for this code.
+        ASSERT(m_sawError);
         return false;
-
-    parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction.
+    }
 
     // No error if the chunk is well formed or it is not but we have no error.
-    return parser->context()->wellFormed || !xmlCtxtGetLastError(parser->context());
+    return context()->wellFormed || !xmlCtxtGetLastError(context());
 }
 
 // --------------------------------
diff --git a/WebCore/dom/XMLDocumentParserQt.cpp b/WebCore/dom/XMLDocumentParserQt.cpp
index 148cff0..115a3e9 100644
--- a/WebCore/dom/XMLDocumentParserQt.cpp
+++ b/WebCore/dom/XMLDocumentParserQt.cpp
@@ -254,19 +254,13 @@ void XMLDocumentParser::resumeParsing()
         end();
 }
 
-bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
+bool XMLDocumentParser::appendFragmentSource(const String& source)
 {
-    if (!chunk.length())
-        return true;
-
-    RefPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, parent, scriptingPermission);
-
-    parser->append(String("<qxmlstreamdummyelement>"));
-    parser->append(chunk);
-    parser->append(String("</qxmlstreamdummyelement>"));
-    parser->finish();
-    parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction.
-    return !parser->hasError();
+    ASSERT(!m_sawFirstElement);
+    append(String("<qxmlstreamdummyelement>"));
+    append(source);
+    append(String("</qxmlstreamdummyelement>"));
+    return !hasError();
 }
 
 // --------------------------------

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list