Title: [144801] trunk/Source/WebCore
Revision
144801
Author
to...@chromium.org
Date
2013-03-05 12:44:37 -0800 (Tue, 05 Mar 2013)

Log Message

CompactHTMLToken does not need an XSSInfo pointer
https://bugs.webkit.org/show_bug.cgi?id=111423

Reviewed by Eric Seidel.

The CompactHTMLToken should remain as small as possible because it is copied. This shrinks the size by one pointer
by moving a relatively uncommon attribute out to its own Vector.

No new tests because no new functionality.

* html/parser/BackgroundHTMLParser.cpp:
(WebCore::checkThatXSSInfosAreSafeToSendToAnotherThread):
(WebCore):
(WebCore::BackgroundHTMLParser::pumpTokenizer):
(WebCore::BackgroundHTMLParser::sendTokensToMainThread):
* html/parser/BackgroundHTMLParser.h:
(BackgroundHTMLParser):
* html/parser/CompactHTMLToken.cpp:
(SameSizeAsCompactHTMLToken):
(WebCore::CompactHTMLToken::isSafeToSendToAnotherThread):
* html/parser/CompactHTMLToken.h:
(WebCore):
(CompactHTMLToken):
* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):
* html/parser/HTMLDocumentParser.h:
(ParsedChunk):
* html/parser/XSSAuditorDelegate.h:
(XSSInfo):
(WebCore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (144800 => 144801)


--- trunk/Source/WebCore/ChangeLog	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/ChangeLog	2013-03-05 20:44:37 UTC (rev 144801)
@@ -1,3 +1,36 @@
+2013-03-05  Tony Gentilcore  <to...@chromium.org>
+
+        CompactHTMLToken does not need an XSSInfo pointer
+        https://bugs.webkit.org/show_bug.cgi?id=111423
+
+        Reviewed by Eric Seidel.
+
+        The CompactHTMLToken should remain as small as possible because it is copied. This shrinks the size by one pointer
+        by moving a relatively uncommon attribute out to its own Vector.
+
+        No new tests because no new functionality.
+
+        * html/parser/BackgroundHTMLParser.cpp:
+        (WebCore::checkThatXSSInfosAreSafeToSendToAnotherThread):
+        (WebCore):
+        (WebCore::BackgroundHTMLParser::pumpTokenizer):
+        (WebCore::BackgroundHTMLParser::sendTokensToMainThread):
+        * html/parser/BackgroundHTMLParser.h:
+        (BackgroundHTMLParser):
+        * html/parser/CompactHTMLToken.cpp:
+        (SameSizeAsCompactHTMLToken):
+        (WebCore::CompactHTMLToken::isSafeToSendToAnotherThread):
+        * html/parser/CompactHTMLToken.h:
+        (WebCore):
+        (CompactHTMLToken):
+        * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):
+        * html/parser/HTMLDocumentParser.h:
+        (ParsedChunk):
+        * html/parser/XSSAuditorDelegate.h:
+        (XSSInfo):
+        (WebCore):
+
 2013-03-05  Anders Carlsson  <ander...@apple.com>
 
         Split StorageEventDispatcher::dispatch into two functions

Modified: trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp (144800 => 144801)


--- trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp	2013-03-05 20:44:37 UTC (rev 144801)
@@ -59,6 +59,12 @@
         ASSERT(preloads[i]->isSafeToSendToAnotherThread());
 }
 
+static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& xssInfos)
+{
+    for (size_t i = 0; i < xssInfos.size(); ++i)
+        ASSERT(xssInfos[i]->isSafeToSendToAnotherThread());
+}
+
 #endif
 
 static bool tokenExitsForeignContent(const CompactHTMLToken& token)
@@ -247,12 +253,15 @@
         m_sourceTracker.end(m_input.current(), m_tokenizer.get(), *m_token);
 
         {
-            OwnPtr<XSSInfo> xssInfo = m_xssAuditor->filterToken(FilterTokenRequest(*m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA()));
+            TextPosition position = TextPosition(m_input.current().currentLine(), m_input.current().currentColumn());
+
+            if (OwnPtr<XSSInfo> xssInfo = m_xssAuditor->filterToken(FilterTokenRequest(*m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA()))) {
+                xssInfo->m_textPosition = position;
+                m_pendingXSSInfos.append(xssInfo.release());
+            }
+
             CompactHTMLToken token(m_token.get(), TextPosition(m_input.current().currentLine(), m_input.current().currentColumn()));
 
-            if (xssInfo)
-                token.setXSSInfo(xssInfo.release());
-
             m_preloadScanner->scan(token, m_pendingPreloads);
 
             m_pendingTokens->append(token);
@@ -275,11 +284,13 @@
 #ifndef NDEBUG
     checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get());
     checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads);
+    checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos);
 #endif
 
     OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentParser::ParsedChunk);
     chunk->tokens = m_pendingTokens.release();
     chunk->preloads.swap(m_pendingPreloads);
+    chunk->xssInfos.swap(m_pendingXSSInfos);
     chunk->tokenizerState = m_tokenizer->state();
     chunk->inputCheckpoint = m_input.createCheckpoint();
     chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint();

Modified: trunk/Source/WebCore/html/parser/BackgroundHTMLParser.h (144800 => 144801)


--- trunk/Source/WebCore/html/parser/BackgroundHTMLParser.h	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/BackgroundHTMLParser.h	2013-03-05 20:44:37 UTC (rev 144801)
@@ -35,6 +35,7 @@
 #include "HTMLSourceTracker.h"
 #include "HTMLToken.h"
 #include "HTMLTokenizer.h"
+#include "XSSAuditorDelegate.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
@@ -105,6 +106,7 @@
 
     OwnPtr<CompactHTMLTokenStream> m_pendingTokens;
     PreloadRequestStream m_pendingPreloads;
+    XSSInfoStream m_pendingXSSInfos;
 
     OwnPtr<XSSAuditor> m_xssAuditor;
     OwnPtr<TokenPreloadScanner> m_preloadScanner;

Modified: trunk/Source/WebCore/html/parser/CompactHTMLToken.cpp (144800 => 144801)


--- trunk/Source/WebCore/html/parser/CompactHTMLToken.cpp	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/CompactHTMLToken.cpp	2013-03-05 20:44:37 UTC (rev 144801)
@@ -41,7 +41,6 @@
     String name;
     Vector<Attribute> vector;
     TextPosition textPosition;
-    OwnPtr<XSSInfo> xssInfo;
 };
 
 COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), CompactHTMLToken_should_stay_small);
@@ -89,19 +88,6 @@
     }
 }
 
-CompactHTMLToken::CompactHTMLToken(const CompactHTMLToken& other)
-    : m_type(other.m_type)
-    , m_selfClosing(other.m_selfClosing)
-    , m_isAll8BitData(other.m_isAll8BitData)
-    , m_doctypeForcesQuirks(other.m_doctypeForcesQuirks)
-    , m_data(other.m_data)
-    , m_attributes(other.m_attributes)
-    , m_textPosition(other.m_textPosition)
-{
-    if (other.m_xssInfo)
-        m_xssInfo = adoptPtr(new XSSInfo(*other.m_xssInfo));
-}
-
 const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const QualifiedName& name) const
 {
     for (unsigned i = 0; i < m_attributes.size(); ++i) {
@@ -119,21 +105,9 @@
         if (!it->value.isSafeToSendToAnotherThread())
             return false;
     }
-    if (m_xssInfo && !m_xssInfo->isSafeToSendToAnotherThread())
-        return false;
     return m_data.isSafeToSendToAnotherThread();
 }
 
-XSSInfo* CompactHTMLToken::xssInfo() const
-{
-    return m_xssInfo.get();
 }
 
-void CompactHTMLToken::setXSSInfo(PassOwnPtr<XSSInfo> xssInfo)
-{
-    m_xssInfo = xssInfo;
-}
-
-}
-
 #endif // ENABLE(THREADED_HTML_PARSER)

Modified: trunk/Source/WebCore/html/parser/CompactHTMLToken.h (144800 => 144801)


--- trunk/Source/WebCore/html/parser/CompactHTMLToken.h	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/CompactHTMLToken.h	2013-03-05 20:44:37 UTC (rev 144801)
@@ -40,7 +40,6 @@
 namespace WebCore {
 
 class QualifiedName;
-class XSSInfo;
 
 class CompactHTMLToken {
 public:
@@ -56,7 +55,6 @@
     };
 
     CompactHTMLToken(const HTMLToken*, const TextPosition&);
-    CompactHTMLToken(const CompactHTMLToken&);
 
     bool isSafeToSendToAnotherThread() const;
 
@@ -73,8 +71,6 @@
     const String& publicIdentifier() const { return m_attributes[0].name; }
     const String& systemIdentifier() const { return m_attributes[0].value; }
     bool doctypeForcesQuirks() const { return m_doctypeForcesQuirks; }
-    XSSInfo* xssInfo() const;
-    void setXSSInfo(PassOwnPtr<XSSInfo>);
 
 private:
     unsigned m_type : 4;
@@ -85,19 +81,12 @@
     String m_data; // "name", "characters", or "data" depending on m_type
     Vector<Attribute> m_attributes;
     TextPosition m_textPosition;
-    OwnPtr<XSSInfo> m_xssInfo;
 };
 
 typedef Vector<CompactHTMLToken> CompactHTMLTokenStream;
 
 }
 
-namespace WTF {
-// This is required for a struct with OwnPtr. We know CompactHTMLToken is simple enough that
-// initializing to 0 and moving with memcpy (and then not destructing the original) will work.
-template<> struct VectorTraits<WebCore::CompactHTMLToken> : SimpleClassVectorTraits { };
-}
-
 #endif // ENABLE(THREADED_HTML_PARSER)
 
 #endif

Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (144800 => 144801)


--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-03-05 20:44:37 UTC (rev 144801)
@@ -393,14 +393,18 @@
     m_currentChunk = chunk;
     OwnPtr<CompactHTMLTokenStream> tokens = m_currentChunk->tokens.release();
 
+    for (XSSInfoStream::const_iterator it = m_currentChunk->xssInfos.begin(); it != m_currentChunk->xssInfos.end(); ++it) {
+        m_textPosition = (*it)->m_textPosition;
+        m_xssAuditorDelegate.didBlockScript(**it); 
+        if (isStopped())
+            break;
+    }
+
     for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != tokens->end(); ++it) {
         ASSERT(!isWaitingForScripts());
 
         m_textPosition = it->textPosition();
 
-        if (XSSInfo* xssInfo = it->xssInfo())
-            m_xssAuditorDelegate.didBlockScript(*xssInfo);
-
         constructTreeFromCompactHTMLToken(*it);
 
         if (isStopped())

Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.h (144800 => 144801)


--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.h	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.h	2013-03-05 20:44:37 UTC (rev 144801)
@@ -89,6 +89,7 @@
     struct ParsedChunk {
         OwnPtr<CompactHTMLTokenStream> tokens;
         PreloadRequestStream preloads;
+        XSSInfoStream xssInfos;
         HTMLTokenizer::State tokenizerState;
         HTMLInputCheckpoint inputCheckpoint;
         TokenPreloadScannerCheckpoint preloadScannerCheckpoint;

Modified: trunk/Source/WebCore/html/parser/XSSAuditorDelegate.h (144800 => 144801)


--- trunk/Source/WebCore/html/parser/XSSAuditorDelegate.h	2013-03-05 20:31:04 UTC (rev 144800)
+++ trunk/Source/WebCore/html/parser/XSSAuditorDelegate.h	2013-03-05 20:44:37 UTC (rev 144801)
@@ -27,7 +27,10 @@
 #define XSSAuditorDelegate_h
 
 #include "KURL.h"
+#include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/TextPosition.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -47,6 +50,7 @@
     String m_originalURL;
     String m_originalHTTPBody;
     bool m_didBlockEntirePage;
+    TextPosition m_textPosition;
 
 private:
     XSSInfo(const KURL& reportURL, const String& originalURL, const String& originalHTTPBody, bool didBlockEntirePage)
@@ -69,6 +73,8 @@
     bool m_didNotifyClient;
 };
 
+typedef Vector<OwnPtr<XSSInfo> > XSSInfoStream;
+
 }
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to