Changeset 141605 in webkit


Ignore:
Timestamp:
Feb 1, 2013 10:40:20 AM (11 years ago)
Author:
tonyg@chromium.org
Message:

Continue making XSSAuditor thread safe: Remove dependencies on m_parser from init()
https://bugs.webkit.org/show_bug.cgi?id=108531

Reviewed by Adam Barth.

The threaded HTML parser will create and init() the XSSAuditor on the main thread, but filterToken() will be called on the background.

No new tests because no change in functionality.

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::pumpTokenizer):

  • html/parser/XSSAuditor.cpp:

(WebCore::XSSAuditor::XSSAuditor):
(WebCore::XSSAuditor::init):
(WebCore::XSSAuditor::filterToken):

  • html/parser/XSSAuditor.h:

(WebCore):
(XSSAuditor):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r141603 r141605  
     12013-02-01  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Continue making XSSAuditor thread safe: Remove dependencies on m_parser from init()
     4        https://bugs.webkit.org/show_bug.cgi?id=108531
     5
     6        Reviewed by Adam Barth.
     7
     8        The threaded HTML parser will create and init() the XSSAuditor on the main thread, but filterToken() will be called on the background.
     9
     10        No new tests because no change in functionality.
     11
     12        * html/parser/HTMLDocumentParser.cpp:
     13        (WebCore::HTMLDocumentParser::pumpTokenizer):
     14        * html/parser/XSSAuditor.cpp:
     15        (WebCore::XSSAuditor::XSSAuditor):
     16        (WebCore::XSSAuditor::init):
     17        (WebCore::XSSAuditor::filterToken):
     18        * html/parser/XSSAuditor.h:
     19        (WebCore):
     20        (XSSAuditor):
     21
    1222013-02-01  Brady Eidson  <beidson@apple.com>
    223
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r141494 r141605  
    365365    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willWriteHTML(document(), m_input.current().length(), m_input.current().currentLine().zeroBasedInt());
    366366
     367    m_xssAuditor.init(document());
     368
    367369    while (canTakeNextToken(mode, session) && !session.needsYield) {
    368370        if (!isParsingFragment())
  • trunk/Source/WebCore/html/parser/XSSAuditor.cpp

    r141494 r141605  
    177177    , m_scriptTagNestingLevel(0)
    178178{
     179    ASSERT(isMainThread());
    179180    ASSERT(m_parser);
    180181    if (Frame* frame = parser->document()->frame()) {
     
    186187}
    187188
    188 void XSSAuditor::init()
     189void XSSAuditor::init(Document* document)
    189190{
    190191    const size_t miniumLengthForSuffixTree = 512; // FIXME: Tune this parameter.
    191192    const int suffixTreeDepth = 5;
    192193
     194    ASSERT(isMainThread());
     195    if (m_state == Initialized)
     196        return;
    193197    ASSERT(m_state == Uninitialized);
    194198    m_state = Initialized;
     
    199203    // In theory, the Document could have detached from the Frame after the
    200204    // XSSAuditor was constructed.
    201     if (!m_parser->document()->frame()) {
     205    if (!document->frame()) {
    202206        m_isEnabled = false;
    203207        return;
    204208    }
    205209
    206     const KURL& url = m_parser->document()->url();
     210    const KURL& url = document->url();
    207211
    208212    if (url.isEmpty()) {
     
    217221    }
    218222
    219     TextResourceDecoder* decoder = m_parser->document()->decoder();
     223    TextResourceDecoder* decoder = document->decoder();
    220224    m_decodedURL = fullyDecodeString(url.string(), decoder);
    221225    if (m_decodedURL.find(isRequiredForInjection) == notFound)
     
    223227
    224228    String httpBodyAsString;
    225     if (DocumentLoader* documentLoader = m_parser->document()->frame()->loader()->documentLoader()) {
     229    if (DocumentLoader* documentLoader = document->frame()->loader()->documentLoader()) {
    226230        DEFINE_STATIC_LOCAL(String, XSSProtectionHeader, (ASCIILiteral("X-XSS-Protection")));
    227231        String headerValue = documentLoader->response().httpHeaderField(XSSProtectionHeader);
     
    232236
    233237        if ((m_xssProtection == XSSProtectionEnabled || m_xssProtection == XSSProtectionBlockEnabled) && !reportURL.isEmpty()) {
    234             m_reportURL = m_parser->document()->completeURL(reportURL);
    235             if (MixedContentChecker::isMixedContent(m_parser->document()->securityOrigin(), m_reportURL)) {
     238            m_reportURL = document->completeURL(reportURL);
     239            if (MixedContentChecker::isMixedContent(document->securityOrigin(), m_reportURL)) {
    236240                errorDetails = "insecure reporting URL for secure page";
    237241                m_xssProtection = XSSProtectionInvalid;
     
    241245
    242246        if (m_xssProtection == XSSProtectionInvalid) {
    243             m_parser->document()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Error parsing header X-XSS-Protection: " + headerValue + ": "  + errorDetails + " at character position " + String::format("%u", errorPosition) + ". The default protections will be applied.");
     247            document->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Error parsing header X-XSS-Protection: " + headerValue + ": "  + errorDetails + " at character position " + String::format("%u", errorPosition) + ". The default protections will be applied.");
    244248            m_xssProtection = XSSProtectionEnabled;
    245249        }
     
    272276PassOwnPtr<DidBlockScriptRequest> XSSAuditor::filterToken(HTMLToken& token)
    273277{
    274     if (m_state == Uninitialized)
    275         init();
    276    
    277278    ASSERT(m_state == Initialized);
    278279    if (!m_isEnabled || m_xssProtection == XSSProtectionDisabled)
  • trunk/Source/WebCore/html/parser/XSSAuditor.h

    r141494 r141605  
    3535
    3636class DidBlockScriptRequest;
     37class Document;
    3738class HTMLDocumentParser;
    3839
     
    4243    explicit XSSAuditor(HTMLDocumentParser*);
    4344
     45    void init(Document*);
    4446    PassOwnPtr<DidBlockScriptRequest> filterToken(HTMLToken&);
    4547
     
    5759        ScriptLikeAttribute
    5860    };
    59 
    60     void init();
    6161
    6262    bool filterStartToken(HTMLToken&);
Note: See TracChangeset for help on using the changeset viewer.