Title: [88609] trunk/Source/WebCore
Revision
88609
Author
[email protected]
Date
2011-06-11 17:51:11 -0700 (Sat, 11 Jun 2011)

Log Message

2011-06-11  Adam Barth  <[email protected]>

        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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (88608 => 88609)


--- trunk/Source/WebCore/ChangeLog	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/ChangeLog	2011-06-12 00:51:11 UTC (rev 88609)
@@ -1,3 +1,37 @@
+2011-06-11  Adam Barth  <[email protected]>
+
+        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):
+
 2011-06-11  Dimitri Glazkov  <[email protected]>
 
         Unreviewed, rolling out r88569.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (88608 => 88609)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-06-12 00:51:11 UTC (rev 88609)
@@ -7437,7 +7437,7 @@
 		417253A91354BBBC00360F2A /* MediaControlElements.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControlElements.h; sourceTree = "<group>"; };
 		417DA4CE13734326007C57FB /* Internals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Internals.h; sourceTree = "<group>"; };
 		417DA4CF13734326007C57FB /* Internals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Internals.cpp; sourceTree = "<group>"; };
-		417DA6D013734E02007C57FB /* WebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = WebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+		417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libWebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		417DA71B13735DFA007C57FB /* JSInternals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInternals.cpp; sourceTree = "<group>"; };
 		417DA71C13735DFA007C57FB /* JSInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternals.h; sourceTree = "<group>"; };
 		41813F9113818AD60057AAA4 /* Internals.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Internals.idl; sourceTree = "<group>"; };
@@ -12730,7 +12730,7 @@
 			isa = PBXGroup;
 			children = (
 				5D87BB4F11E3EAEB00702B6F /* WebCoreExportFileGenerator */,
-				417DA6D013734E02007C57FB /* WebCoreTestSupport.dylib */,
+				417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */,
 				93F19B1A08245E5A001E9ABC /* WebCore.framework */,
 			);
 			name = Products;
@@ -23194,7 +23194,7 @@
 			);
 			name = WebCoreTestSupport;
 			productName = WebCoreTestSupport;
-			productReference = 417DA6D013734E02007C57FB /* WebCoreTestSupport.dylib */;
+			productReference = 417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */;
 			productType = "com.apple.product-type.library.dynamic";
 		};
 		5D87BB4E11E3EAEB00702B6F /* WebCoreExportFileGenerator */ = {

Modified: trunk/Source/WebCore/dom/DecodedDataDocumentParser.cpp (88608 => 88609)


--- trunk/Source/WebCore/dom/DecodedDataDocumentParser.cpp	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/dom/DecodedDataDocumentParser.cpp	2011-06-12 00:51:11 UTC (rev 88609)
@@ -37,22 +37,27 @@
 {
 }
 
-void DecodedDataDocumentParser::appendBytes(DocumentWriter* writer , const char* data, int length, bool shouldFlush)
+void DecodedDataDocumentParser::appendBytes(DocumentWriter* writer, const char* data, int length)
 {
-    if (!length && !shouldFlush)
+    if (!length)
         return;
 
-    TextResourceDecoder* decoder = writer->createDecoderIfNeeded();
-    String decoded = decoder->decode(data, length);
-    if (shouldFlush)
-        decoded += decoder->flush();
+    String decoded = writer->createDecoderIfNeeded()->decode(data, length);
     if (decoded.isEmpty())
         return;
 
     writer->reportDataReceived();
-
     append(decoded);
 }
 
+void DecodedDataDocumentParser::flush(DocumentWriter* writer)
+{
+    String remainingData = writer->createDecoderIfNeeded()->flush();
+    if (remainingData.isEmpty())
+        return;
+
+    writer->reportDataReceived();
+    append(remainingData);
+}
+
 };
-

Modified: trunk/Source/WebCore/dom/DecodedDataDocumentParser.h (88608 => 88609)


--- trunk/Source/WebCore/dom/DecodedDataDocumentParser.h	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/dom/DecodedDataDocumentParser.h	2011-06-12 00:51:11 UTC (rev 88609)
@@ -40,11 +40,12 @@
     explicit DecodedDataDocumentParser(Document*);
 
 private:
-    // append is used by DocumentWriter::replaceDocument
+    // append is used by DocumentWriter::replaceDocument.
     virtual void append(const SegmentedString&) = 0;
 
-    // appendBytes is used by DocumentWriter (the loader)
-    virtual void appendBytes(DocumentWriter*, const char* bytes, int length, bool flush);
+    // appendBytes and flush are used by DocumentWriter (the loader).
+    virtual void appendBytes(DocumentWriter*, const char* bytes, int length);
+    virtual void flush(DocumentWriter*);
 };
 
 }

Modified: trunk/Source/WebCore/dom/DocumentParser.h (88608 => 88609)


--- trunk/Source/WebCore/dom/DocumentParser.h	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/dom/DocumentParser.h	2011-06-12 00:51:11 UTC (rev 88609)
@@ -42,11 +42,12 @@
     // http://www.whatwg.org/specs/web-apps/current-work/#insertion-point
     virtual bool hasInsertionPoint() { return true; }
 
-    // insert is used by document.write
+    // insert is used by document.write.
     virtual void insert(const SegmentedString&) = 0;
 
-    // appendBytes is used by DocumentWriter (the loader)
-    virtual void appendBytes(DocumentWriter*, const char* bytes, int length, bool flush) = 0;
+    // appendBytes and flush are used by DocumentWriter (the loader).
+    virtual void appendBytes(DocumentWriter*, const char* bytes, int length) = 0;
+    virtual void flush(DocumentWriter*) = 0;
 
     // FIXME: append() should be private, but DocumentWriter::replaceDocument
     // uses it for now.

Modified: trunk/Source/WebCore/dom/RawDataDocumentParser.h (88608 => 88609)


--- trunk/Source/WebCore/dom/RawDataDocumentParser.h	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/dom/RawDataDocumentParser.h	2011-06-12 00:51:11 UTC (rev 88609)
@@ -44,6 +44,12 @@
     }
 
 private:
+    virtual void flush(DocumentWriter* writer)
+    {
+        // Make sure appendBytes is called at least once.
+        appendBytes(writer, 0, 0);
+    }
+
     virtual void insert(const SegmentedString&)
     {
         // <https://bugs.webkit.org/show_bug.cgi?id=25397>: JS code can always call document.write, we need to handle it.

Modified: trunk/Source/WebCore/html/ImageDocument.cpp (88608 => 88609)


--- trunk/Source/WebCore/html/ImageDocument.cpp	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/html/ImageDocument.cpp	2011-06-12 00:51:11 UTC (rev 88609)
@@ -90,7 +90,7 @@
     {
     }
 
-    virtual void appendBytes(DocumentWriter*, const char*, int, bool);
+    virtual void appendBytes(DocumentWriter*, const char*, int);
     virtual void finish();
 };
 
@@ -124,7 +124,7 @@
     return frame ? frame->pageZoomFactor() : 1;
 }
 
-void ImageDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool)
+void ImageDocumentParser::appendBytes(DocumentWriter*, const char*, int)
 {
     Frame* frame = document()->frame();
     Settings* settings = frame->settings();

Modified: trunk/Source/WebCore/html/MediaDocument.cpp (88608 => 88609)


--- trunk/Source/WebCore/html/MediaDocument.cpp	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/html/MediaDocument.cpp	2011-06-12 00:51:11 UTC (rev 88609)
@@ -60,7 +60,7 @@
     {
     }
 
-    virtual void appendBytes(DocumentWriter*, const char*, int, bool);
+    virtual void appendBytes(DocumentWriter*, const char*, int);
 
     void createDocumentStructure();
 
@@ -103,7 +103,7 @@
     frame->loader()->activeDocumentLoader()->mainResourceLoader()->setShouldBufferData(false);
 }
 
-void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool)
+void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, int)
 {
     if (m_mediaElement)
         return;

Modified: trunk/Source/WebCore/html/PluginDocument.cpp (88608 => 88609)


--- trunk/Source/WebCore/html/PluginDocument.cpp	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/html/PluginDocument.cpp	2011-06-12 00:51:11 UTC (rev 88609)
@@ -58,7 +58,7 @@
     {
     }
 
-    virtual void appendBytes(DocumentWriter*, const char*, int, bool);
+    virtual void appendBytes(DocumentWriter*, const char*, int);
 
     void createDocumentStructure();
 
@@ -103,7 +103,7 @@
     body->appendChild(embedElement, ec);    
 }
 
-void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, int, bool)
+void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, int)
 {
     if (m_embedElement)
         return;

Modified: trunk/Source/WebCore/loader/DocumentWriter.cpp (88608 => 88609)


--- trunk/Source/WebCore/loader/DocumentWriter.cpp	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/loader/DocumentWriter.cpp	2011-06-12 00:51:11 UTC (rev 88609)
@@ -56,7 +56,7 @@
     
 DocumentWriter::DocumentWriter(Frame* frame)
     : m_frame(frame)
-    , m_receivedData(false)
+    , m_hasReceivedSomeData(false)
     , m_encodingWasChosenByUser(false)
 {
 }
@@ -70,8 +70,8 @@
     begin(m_frame->document()->url(), true, m_frame->document()->securityOrigin());
 
     if (!source.isNull()) {
-        if (!m_receivedData) {
-            m_receivedData = true;
+        if (!m_hasReceivedSomeData) {
+            m_hasReceivedSomeData = true;
             m_frame->document()->setCompatibilityMode(Document::NoQuirksMode);
         }
 
@@ -87,7 +87,7 @@
 void DocumentWriter::clear()
 {
     m_decoder = 0;
-    m_receivedData = false;
+    m_hasReceivedSomeData = false;
     if (!m_encodingWasChosenByUser)
         m_encoding = String();
 }
@@ -144,6 +144,9 @@
 
     document->implicitOpen();
 
+    // We grab a reference to the parser so that we'll always send data to the
+    // original parser, even if the document acquires a new parser (e.g., via
+    // document.open).
     m_parser = document->parser();
 
     if (m_frame->view() && m_frame->loader()->client()->hasHTMLView())
@@ -187,20 +190,20 @@
 void DocumentWriter::reportDataReceived()
 {
     ASSERT(m_decoder);
-    if (!m_receivedData) {
-        m_receivedData = true;
-        if (m_decoder->encoding().usesVisualOrdering())
-            m_frame->document()->setVisuallyOrdered();
-        m_frame->document()->recalcStyle(Node::Force);
-    }
+    if (m_hasReceivedSomeData)
+        return;
+    m_hasReceivedSomeData = true;
+    if (m_decoder->encoding().usesVisualOrdering())
+        m_frame->document()->setVisuallyOrdered();
+    m_frame->document()->recalcStyle(Node::Force);
 }
 
-void DocumentWriter::addData(const char* str, int len, bool flush)
+void DocumentWriter::addData(const char* bytes, int length)
 {
-    if (len == -1)
-        len = strlen(str);
+    if (length == -1)
+        length = strlen(bytes);
 
-    m_parser->appendBytes(this, str, len, flush);
+    m_parser->appendBytes(this, bytes, length);
 }
 
 void DocumentWriter::end()
@@ -219,9 +222,8 @@
     // so we'll add a protective refcount
     RefPtr<Frame> protector(m_frame);
 
-    // FIXME: Can we remove this call? Finishing the parser should flush anyway.
-    addData(0, 0, true);
-
+    // FIXME: m_parser->finish() should imply m_parser->flush().
+    m_parser->flush(this);
     if (!m_parser)
         return;
     m_parser->finish();

Modified: trunk/Source/WebCore/loader/DocumentWriter.h (88608 => 88609)


--- trunk/Source/WebCore/loader/DocumentWriter.h	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/loader/DocumentWriter.h	2011-06-12 00:51:11 UTC (rev 88609)
@@ -51,7 +51,7 @@
 
     void begin();
     void begin(const KURL&, bool dispatchWindowObjectAvailable = true, SecurityOrigin* forcedSecurityOrigin = 0);
-    void addData(const char* string, int length = -1, bool flush = false);
+    void addData(const char* bytes, int length = -1);
     void end();
     void endIfNotLoadingMainResource();
     
@@ -82,7 +82,7 @@
 
     Frame* m_frame;
 
-    bool m_receivedData;
+    bool m_hasReceivedSomeData;
     String m_mimeType;
 
     bool m_encodingWasChosenByUser;

Modified: trunk/Source/WebCore/loader/SinkDocument.cpp (88608 => 88609)


--- trunk/Source/WebCore/loader/SinkDocument.cpp	2011-06-11 20:34:42 UTC (rev 88608)
+++ trunk/Source/WebCore/loader/SinkDocument.cpp	2011-06-12 00:51:11 UTC (rev 88609)
@@ -44,7 +44,7 @@
     }
 
     // Ignore all data.
-    virtual void appendBytes(DocumentWriter*, const char*, int, bool) { }
+    virtual void appendBytes(DocumentWriter*, const char*, int) { }
 };
 
 SinkDocument::SinkDocument(Frame* frame, const KURL& url)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to