Skip to content
Permalink
Browse files
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):


Canonical link: https://commits.webkit.org/129827@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@144801 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
tonygentilcore committed Mar 5, 2013
1 parent 1cadce9 commit 67d2cc7793887eb50e93b0a1bc5ad14976d0cdc5
Showing 8 changed files with 64 additions and 44 deletions.
@@ -1,3 +1,36 @@
2013-03-05 Tony Gentilcore <tonyg@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 <andersca@apple.com>

Split StorageEventDispatcher::dispatch into two functions
@@ -59,6 +59,12 @@ static void checkThatPreloadsAreSafeToSendToAnotherThread(const PreloadRequestSt
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,11 +253,14 @@ void BackgroundHTMLParser::pumpTokenizer()
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()));
CompactHTMLToken token(m_token.get(), TextPosition(m_input.current().currentLine(), m_input.current().currentColumn()));
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());
}

if (xssInfo)
token.setXSSInfo(xssInfo.release());
CompactHTMLToken token(m_token.get(), TextPosition(m_input.current().currentLine(), m_input.current().currentColumn()));

m_preloadScanner->scan(token, m_pendingPreloads);

@@ -275,11 +284,13 @@ void BackgroundHTMLParser::sendTokensToMainThread()
#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();
@@ -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 @@ class BackgroundHTMLParser {

OwnPtr<CompactHTMLTokenStream> m_pendingTokens;
PreloadRequestStream m_pendingPreloads;
XSSInfoStream m_pendingXSSInfos;

OwnPtr<XSSAuditor> m_xssAuditor;
OwnPtr<TokenPreloadScanner> m_preloadScanner;
@@ -41,7 +41,6 @@ struct SameSizeAsCompactHTMLToken {
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 HTMLToken* token, const TextPosition& t
}
}

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 @@ bool CompactHTMLToken::isSafeToSendToAnotherThread() const
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)
@@ -40,7 +40,6 @@
namespace WebCore {

class QualifiedName;
class XSSInfo;

class CompactHTMLToken {
public:
@@ -56,7 +55,6 @@ class CompactHTMLToken {
};

CompactHTMLToken(const HTMLToken*, const TextPosition&);
CompactHTMLToken(const CompactHTMLToken&);

bool isSafeToSendToAnotherThread() const;

@@ -73,8 +71,6 @@ class CompactHTMLToken {
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 @@ class CompactHTMLToken {
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
@@ -393,14 +393,18 @@ void HTMLDocumentParser::processParsedChunkFromBackgroundParser(PassOwnPtr<Parse
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())
@@ -89,6 +89,7 @@ class HTMLDocumentParser : public ScriptableDocumentParser, HTMLScriptRunnerHos
struct ParsedChunk {
OwnPtr<CompactHTMLTokenStream> tokens;
PreloadRequestStream preloads;
XSSInfoStream xssInfos;
HTMLTokenizer::State tokenizerState;
HTMLInputCheckpoint inputCheckpoint;
TokenPreloadScannerCheckpoint preloadScannerCheckpoint;
@@ -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 @@ class XSSInfo {
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 @@ class XSSAuditorDelegate {
bool m_didNotifyClient;
};

typedef Vector<OwnPtr<XSSInfo> > XSSInfoStream;

}

#endif

0 comments on commit 67d2cc7

Please sign in to comment.