Chromium Code Reviews| Index: Source/core/html/parser/HTMLDocumentParser.cpp |
| diff --git a/Source/core/html/parser/HTMLDocumentParser.cpp b/Source/core/html/parser/HTMLDocumentParser.cpp |
| index f3a7f49f75121a265fcd27f833d2356e1963e752..a6ac2456257bde137c356e3e6e986c6861eae356 100644 |
| --- a/Source/core/html/parser/HTMLDocumentParser.cpp |
| +++ b/Source/core/html/parser/HTMLDocumentParser.cpp |
| @@ -42,6 +42,7 @@ |
| #include "core/html/parser/HTMLTreeBuilder.h" |
| #include "core/inspector/InspectorInstrumentation.h" |
| #include "core/frame/Frame.h" |
| +#include "platform/SharedBuffer.h" |
| #include "platform/TraceEvent.h" |
| #include "wtf/Functional.h" |
| @@ -320,6 +321,11 @@ void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa |
| pumpPendingSpeculations(); |
| } |
| +void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const DocumentEncodingData& data) |
| +{ |
| + document()->setEncodingData(data); |
| +} |
| + |
| void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) |
| { |
| ASSERT(chunk); |
| @@ -672,10 +678,11 @@ void HTMLDocumentParser::startBackgroundParser() |
| config->xssAuditor = adoptPtr(new XSSAuditor); |
| config->xssAuditor->init(document(), &m_xssAuditorDelegate); |
| config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().copy(), document()->devicePixelRatio())); |
| + config->decoder = takeDecoder(); |
| ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); |
| ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); |
| - HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::create, reference.release(), config.release())); |
| + HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::start, reference.release(), config.release())); |
| } |
| void HTMLDocumentParser::stopBackgroundParser() |
| @@ -693,19 +700,9 @@ void HTMLDocumentParser::append(PassRefPtr<StringImpl> inputSource) |
| if (isStopped()) |
| return; |
| - if (shouldUseThreading()) { |
| - if (!m_haveBackgroundParser) |
| - startBackgroundParser(); |
| - |
| - ASSERT(inputSource->hasOneRef()); |
| - TRACE_EVENT1("net", "HTMLDocumentParser::append", "size", inputSource->length()); |
| - // NOTE: Important that the String temporary is destroyed before we post the task |
| - // otherwise the String could call deref() on a StringImpl now owned by the background parser. |
| - // We would like to ASSERT(closure.arg3()->hasOneRef()) but sadly the args are private. |
| - Closure closure = bind(&BackgroundHTMLParser::append, m_backgroundParser, String(inputSource)); |
| - HTMLParserThread::shared()->postTask(closure); |
| - return; |
| - } |
| + // We should never reach this point if we're using a parser thread, |
| + // as appendBytes() will directly ship the data to the thread. |
| + ASSERT(!shouldUseThreading()); |
| // pumpTokenizer can cause this parser to be detached from the Document, |
| // but we need to ensure it isn't deleted yet. |
| @@ -971,4 +968,36 @@ void HTMLDocumentParser::resumeScheduledTasks() |
| m_parserScheduler->resume(); |
| } |
| +void HTMLDocumentParser::appendBytes(const char* data, size_t length) |
| +{ |
| + if (!length || isDetached()) |
| + return; |
| + |
| + if (shouldUseThreading()) { |
| + if (!m_haveBackgroundParser) |
| + startBackgroundParser(); |
| + |
| + OwnPtr<Vector<char> > buffer = adoptPtr(new Vector<char>(length)); |
| + memcpy(buffer->data(), data, length); |
| + TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned)length); |
|
eseidel
2013/11/19 22:27:45
Did you mean for this only to be in the threaded p
oystein (OOO til 10th of July)
2013/11/19 22:52:19
Yeah there's an equivalent trace for the non-threa
|
| + |
| + HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::appendBytes, m_backgroundParser, buffer.release())); |
| + return; |
| + } |
| + |
| + DecodedDataDocumentParser::appendBytes(data, length); |
| +} |
| + |
| +void HTMLDocumentParser::flush() |
| +{ |
| + // If we've got no decoder, we never received any data. |
| + if (isDetached() || needsDecoder()) |
| + return; |
| + |
| + if (m_haveBackgroundParser) |
| + HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::flush, m_backgroundParser)); |
| + else |
| + DecodedDataDocumentParser::flush(); |
| +} |
| + |
| } |