Title: [109962] trunk/Source/WebCore
Revision
109962
Author
[email protected]
Date
2012-03-06 14:45:12 -0800 (Tue, 06 Mar 2012)

Log Message

Add state variable and ASSERTs to DocumentWriter to help track down
https://bugs.webkit.org/show_bug.cgi?id=80427 and prevent illegal usage
of DocumentWriter. This also makes endIfNotLoadingMainResource() private
as there is no external usage.

Patch by Raymes Khoury <[email protected]> on 2012-03-06
Reviewed by Adam Barth.

This only adds ASSERT/CRASH and does not change existing behaviour.

* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::DocumentWriter):
(WebCore::DocumentWriter::begin):
(WebCore::DocumentWriter::addData):
(WebCore::DocumentWriter::endIfNotLoadingMainResource):
(WebCore::DocumentWriter::setDocumentWasLoadedAsPartOfNavigation):
* loader/DocumentWriter.h:
(DocumentWriter):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (109961 => 109962)


--- trunk/Source/WebCore/ChangeLog	2012-03-06 22:41:28 UTC (rev 109961)
+++ trunk/Source/WebCore/ChangeLog	2012-03-06 22:45:12 UTC (rev 109962)
@@ -1,3 +1,23 @@
+2012-03-06  Raymes Khoury  <[email protected]>
+
+        Add state variable and ASSERTs to DocumentWriter to help track down
+        https://bugs.webkit.org/show_bug.cgi?id=80427 and prevent illegal usage
+        of DocumentWriter. This also makes endIfNotLoadingMainResource() private
+        as there is no external usage.
+
+        Reviewed by Adam Barth.
+
+        This only adds ASSERT/CRASH and does not change existing behaviour.
+
+        * loader/DocumentWriter.cpp:
+        (WebCore::DocumentWriter::DocumentWriter):
+        (WebCore::DocumentWriter::begin):
+        (WebCore::DocumentWriter::addData):
+        (WebCore::DocumentWriter::endIfNotLoadingMainResource):
+        (WebCore::DocumentWriter::setDocumentWasLoadedAsPartOfNavigation):
+        * loader/DocumentWriter.h:
+        (DocumentWriter):
+
 2012-03-06  Mihnea Ovidenie  <[email protected]>
 
         [CSSRegions][CSSOM]Restrict parsing of named flow name

Modified: trunk/Source/WebCore/loader/DocumentWriter.cpp (109961 => 109962)


--- trunk/Source/WebCore/loader/DocumentWriter.cpp	2012-03-06 22:41:28 UTC (rev 109961)
+++ trunk/Source/WebCore/loader/DocumentWriter.cpp	2012-03-06 22:45:12 UTC (rev 109962)
@@ -58,6 +58,7 @@
     : m_frame(frame)
     , m_hasReceivedSomeData(false)
     , m_encodingWasChosenByUser(false)
+    , m_state(NotStartedWritingState)
 {
 }
 
@@ -154,6 +155,8 @@
 
     if (m_frame->view() && m_frame->loader()->client()->hasHTMLView())
         m_frame->view()->setContentsSize(IntSize());
+
+    m_state = StartedWritingState;
 }
 
 TextResourceDecoder* DocumentWriter::createDecoderIfNeeded()
@@ -203,6 +206,15 @@
 
 void DocumentWriter::addData(const char* bytes, size_t length)
 {
+    // Check that we're inside begin()/end().
+    // FIXME: Change these to ASSERT once https://bugs.webkit.org/show_bug.cgi?id=80427 has
+    // been resolved.
+    if (m_state == NotStartedWritingState)
+        CRASH();
+    if (m_state == FinishedWritingState)
+        CRASH();
+
+    ASSERT(m_parser);
     m_parser->appendBytes(this, bytes, length);
 }
 
@@ -219,6 +231,10 @@
     if (m_frame->loader()->isLoadingMainResource() || !m_frame->page() || !m_frame->document())
         return;
 
+    // The parser is guaranteed to be released after this point. begin() would
+    // have to be called again before we can start writing more data.
+    m_state = FinishedWritingState;
+
     // http://bugs.webkit.org/show_bug.cgi?id=10854
     // The frame's last ref may be removed and it can be deleted by checkCompleted(), 
     // so we'll add a protective refcount
@@ -243,7 +259,7 @@
 
 void DocumentWriter::setDocumentWasLoadedAsPartOfNavigation()
 {
-    ASSERT(!m_parser->isStopped());
+    ASSERT(m_parser && !m_parser->isStopped());
     m_parser->setDocumentWasLoadedAsPartOfNavigation();
 }
 

Modified: trunk/Source/WebCore/loader/DocumentWriter.h (109961 => 109962)


--- trunk/Source/WebCore/loader/DocumentWriter.h	2012-03-06 22:41:28 UTC (rev 109961)
+++ trunk/Source/WebCore/loader/DocumentWriter.h	2012-03-06 22:45:12 UTC (rev 109962)
@@ -53,7 +53,6 @@
     void begin(const KURL&, bool dispatchWindowObjectAvailable = true, Document* ownerDocument = 0);
     void addData(const char* bytes, size_t length);
     void end();
-    void endIfNotLoadingMainResource();
     
     void setFrame(Frame* frame) { m_frame = frame; }
 
@@ -71,6 +70,7 @@
 private:
     PassRefPtr<Document> createDocument(const KURL&);
     void clear();
+    void endIfNotLoadingMainResource();
 
     Frame* m_frame;
 
@@ -81,6 +81,13 @@
     String m_encoding;
     RefPtr<TextResourceDecoder> m_decoder;
     RefPtr<DocumentParser> m_parser;
+
+    enum WriterState {
+        NotStartedWritingState,
+        StartedWritingState,
+        FinishedWritingState,
+    };
+    WriterState m_state;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to