Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Unified Diff: Source/core/html/parser/BackgroundHTMLParser.cpp

Issue 74513003: Moved text decoding to the parser thread (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@parserthread_step25
Patch Set: DocumentEncodingData is now constructed from a decoder Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/parser/BackgroundHTMLParser.cpp
diff --git a/Source/core/html/parser/BackgroundHTMLParser.cpp b/Source/core/html/parser/BackgroundHTMLParser.cpp
index b04ebab5b4ac66afde6a7b60a64db55a496fab2b..69a0f35e82a3ae6961544c81711b9bed04ccb2f7 100644
--- a/Source/core/html/parser/BackgroundHTMLParser.cpp
+++ b/Source/core/html/parser/BackgroundHTMLParser.cpp
@@ -26,10 +26,13 @@
#include "config.h"
#include "core/html/parser/BackgroundHTMLParser.h"
+#include "core/fetch/TextResourceDecoder.h"
#include "core/html/parser/HTMLDocumentParser.h"
#include "core/html/parser/HTMLParserThread.h"
+#include "core/html/parser/HTMLToken.h"
#include "core/html/parser/HTMLTokenizer.h"
#include "core/html/parser/XSSAuditor.h"
+#include "platform/SharedBuffer.h"
#include "wtf/MainThread.h"
#include "wtf/text/TextPosition.h"
@@ -77,6 +80,12 @@ static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i
#endif
+void BackgroundHTMLParser::start(PassRefPtr<WeakReference<BackgroundHTMLParser> > reference, PassOwnPtr<Configuration> config)
+{
+ new BackgroundHTMLParser(reference, config);
+ // Caller must free by calling stop().
+}
+
BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser> > reference, PassOwnPtr<Configuration> config)
: m_weakFactory(reference, this)
, m_token(adoptPtr(new HTMLToken))
@@ -87,6 +96,11 @@ BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHT
, m_pendingTokens(adoptPtr(new CompactHTMLTokenStream))
, m_xssAuditor(config->xssAuditor.release())
, m_preloadScanner(config->preloadScanner.release())
+ , m_decoder(config->decoder.release())
+{
+}
+
+BackgroundHTMLParser::~BackgroundHTMLParser()
{
}
@@ -97,6 +111,33 @@ void BackgroundHTMLParser::append(const String& input)
pumpTokenizer();
}
+void BackgroundHTMLParser::appendBytes(PassOwnPtr<Vector<char> > buffer)
+{
+ String decoded = m_decoder->decode(buffer->data(), buffer->size());
+ updateDocument(decoded);
eseidel 2013/11/19 22:27:45 The local still isnt' needed. :)
oystein (OOO til 10th of July) 2013/11/19 22:52:19 Done.
+}
+
+void BackgroundHTMLParser::flush()
+{
+ String remainingData = m_decoder->flush();
+ updateDocument(remainingData);
eseidel 2013/11/19 22:27:45 Or here.
oystein (OOO til 10th of July) 2013/11/19 22:52:19 Done.
+}
+
+void BackgroundHTMLParser::updateDocument(String& decodedData)
eseidel 2013/11/19 22:27:45 Why is this a ref? Why not either by-value or a c
oystein (OOO til 10th of July) 2013/11/19 22:52:19 No reason in this case, just missed it after copyi
+{
+ DocumentEncodingData encodingData(*m_decoder.get());
+
+ if (encodingData != m_lastSeenEncodingData) {
+ m_lastSeenEncodingData = encodingData;
+ callOnMainThread(bind(&HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser, m_parser, encodingData));
+ }
+
+ if (decodedData.isEmpty())
+ return;
+
+ append(decodedData);
+}
+
void BackgroundHTMLParser::resumeFrom(PassOwnPtr<Checkpoint> checkpoint)
{
m_parser = checkpoint->parser;

Powered by Google App Engine
This is Rietveld 408576698