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

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: 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..2d81ba2dac9fd64a2125b0b8298bdf3a31af9ff5 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"
abarth-chromium 2013/11/18 06:57:10 Should this class move to the core/html/parser dir
oystein (OOO til 10th of July) 2013/11/18 22:18:42 It does live in an awkward location right now, but
#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,7 +80,13 @@ static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i
#endif
-BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser> > reference, PassOwnPtr<Configuration> config)
+void BackgroundHTMLParser::create(PassRefPtr<WeakReference<BackgroundHTMLParser> > reference, PassOwnPtr<Configuration> config, PassOwnPtr<TextResourceDecoder> decoder)
+{
+ new BackgroundHTMLParser(reference, config, decoder);
eseidel 2013/11/18 20:07:40 This reads very strange.
oystein (OOO til 10th of July) 2013/11/18 22:18:42 I agree (I just moved this from the header), I don
+ // Caller must free by calling stop().
eseidel 2013/11/18 20:07:40 If this is deleted via "stop" maybe it should be c
oystein (OOO til 10th of July) 2013/11/18 22:18:42 Done.
+}
+
+BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser> > reference, PassOwnPtr<Configuration> config, PassOwnPtr<TextResourceDecoder> decoder)
: m_weakFactory(reference, this)
, m_token(adoptPtr(new HTMLToken))
, m_tokenizer(HTMLTokenizer::create(config->options))
@@ -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(decoder)
+{
+}
+
+BackgroundHTMLParser::~BackgroundHTMLParser()
{
}
@@ -97,6 +111,37 @@ void BackgroundHTMLParser::append(const String& input)
pumpTokenizer();
}
+void BackgroundHTMLParser::appendBytes(PassRefPtr<SharedBuffer> data)
+{
+ RefPtr<SharedBuffer> buffer = data;
+ String decoded = m_decoder->decode(buffer->data(), buffer->size());
+ updateDocument(decoded);
+}
+
+void BackgroundHTMLParser::flush()
+{
+ String remainingData = m_decoder->flush();
eseidel 2013/11/18 20:07:40 I'm not sure the local buys you much.
oystein (OOO til 10th of July) 2013/11/18 22:18:42 error: non-const lvalue reference to type 'WTF::St
+ updateDocument(remainingData);
+}
+
+void BackgroundHTMLParser::updateDocument(String& decodedData)
+{
+ DocumentEncodingData encodingData;
+ encodingData.encoding = m_decoder->encoding();
eseidel 2013/11/18 20:07:40 This feels like DocumentEndodingData should be som
oystein (OOO til 10th of July) 2013/11/18 22:18:42 Done; Added TextResourceDecoder::getEncodingData()
+ encodingData.wasDetectedHeuristically = m_decoder->encodingWasDetectedHeuristically();
+ encodingData.sawDecodingError = m_decoder->sawError();
+
+ 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