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..0346f19aa5a4a464c24f65f63d21dad2dd6e31d2 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,44 @@ 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); |
|
abarth-chromium
2013/11/25 21:45:40
It's too bad we end up with an extra memcpy here.
oystein (OOO til 10th of July)
2013/11/27 00:47:30
Yep it'll go away then (or at least only be used f
|
| + TRACE_EVENT1("net", "HTMLDocumentParser::appendBytes", "size", (unsigned)length); |
| + |
| + 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(); |
| +} |
| + |
| +void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| +{ |
| + DecodedDataDocumentParser::setDecoder(decoder); |
| + |
| + if (m_haveBackgroundParser) |
| + HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDecoder, m_backgroundParser, takeDecoder())); |
| +} |
| + |
| } |