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

Side by Side Diff: Source/core/html/parser/BackgroundHTMLParser.cpp

Issue 100563004: Redirect HTML resource bytes directly to parser thread (Blink side CL) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@parserthread_decodermove
Patch Set: Conflict fix Created 6 years, 8 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/html/parser/BackgroundHTMLParser.h" 27 #include "core/html/parser/BackgroundHTMLParser.h"
28 28
29 #include "core/html/parser/HTMLDocumentParser.h" 29 #include "core/html/parser/HTMLDocumentParser.h"
30 #include "core/html/parser/HTMLParserThread.h"
31 #include "core/html/parser/TextResourceDecoder.h" 30 #include "core/html/parser/TextResourceDecoder.h"
32 #include "core/html/parser/XSSAuditor.h" 31 #include "core/html/parser/XSSAuditor.h"
33 #include "wtf/MainThread.h" 32 #include "wtf/MainThread.h"
34 #include "wtf/text/TextPosition.h" 33 #include "wtf/text/TextPosition.h"
35 34
36 namespace WebCore { 35 namespace WebCore {
37 36
38 // On a network with high latency and high bandwidth, using a device 37 // On a network with high latency and high bandwidth, using a device
39 // with a fast CPU, we could end up speculatively tokenizing 38 // with a fast CPU, we could end up speculatively tokenizing
40 // the whole document, well ahead of when the main-thread actually needs it. 39 // the whole document, well ahead of when the main-thread actually needs it.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 , m_xssAuditor(config->xssAuditor.release()) 93 , m_xssAuditor(config->xssAuditor.release())
95 , m_preloadScanner(config->preloadScanner.release()) 94 , m_preloadScanner(config->preloadScanner.release())
96 , m_decoder(config->decoder.release()) 95 , m_decoder(config->decoder.release())
97 { 96 {
98 } 97 }
99 98
100 BackgroundHTMLParser::~BackgroundHTMLParser() 99 BackgroundHTMLParser::~BackgroundHTMLParser()
101 { 100 {
102 } 101 }
103 102
104 void BackgroundHTMLParser::append(const String& input) 103 void BackgroundHTMLParser::appendRawBytesFromParserThread(const char* data, int dataLength)
104 {
105 ASSERT(m_decoder);
106 updateDocument(m_decoder->decode(data, dataLength));
107 }
108
109 void BackgroundHTMLParser::appendRawBytesFromMainThread(PassOwnPtr<Vector<char> > buffer)
110 {
111 ASSERT(m_decoder);
112 updateDocument(m_decoder->decode(buffer->data(), buffer->size()));
113 }
114
115 void BackgroundHTMLParser::appendDecodedBytes(const String& input)
105 { 116 {
106 ASSERT(!m_input.current().isClosed()); 117 ASSERT(!m_input.current().isClosed());
107 m_input.append(input); 118 m_input.append(input);
108 pumpTokenizer(); 119 pumpTokenizer();
109 } 120 }
110 121
111 void BackgroundHTMLParser::appendBytes(PassOwnPtr<Vector<char> > buffer)
112 {
113 updateDocument(m_decoder->decode(buffer->data(), buffer->size()));
114 }
115
116 void BackgroundHTMLParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 122 void BackgroundHTMLParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
117 { 123 {
124 ASSERT(decoder);
118 m_decoder = decoder; 125 m_decoder = decoder;
119 } 126 }
120 127
121 void BackgroundHTMLParser::flush() 128 void BackgroundHTMLParser::flush()
122 { 129 {
130 ASSERT(m_decoder);
123 updateDocument(m_decoder->flush()); 131 updateDocument(m_decoder->flush());
124 } 132 }
125 133
126 void BackgroundHTMLParser::updateDocument(const String& decodedData) 134 void BackgroundHTMLParser::updateDocument(const String& decodedData)
127 { 135 {
128 DocumentEncodingData encodingData(*m_decoder.get()); 136 DocumentEncodingData encodingData(*m_decoder.get());
129 137
130 if (encodingData != m_lastSeenEncodingData) { 138 if (encodingData != m_lastSeenEncodingData) {
131 m_lastSeenEncodingData = encodingData; 139 m_lastSeenEncodingData = encodingData;
132 140
133 m_xssAuditor->setEncoding(encodingData.encoding()); 141 m_xssAuditor->setEncoding(encodingData.encoding());
134 callOnMainThread(bind(&HTMLDocumentParser::didReceiveEncodingDataFromBac kgroundParser, m_parser, encodingData)); 142 callOnMainThread(bind(&HTMLDocumentParser::didReceiveEncodingDataFromBac kgroundParser, m_parser, encodingData));
135 } 143 }
136 144
137 if (decodedData.isEmpty()) 145 if (decodedData.isEmpty())
138 return; 146 return;
139 147
140 append(decodedData); 148 appendDecodedBytes(decodedData);
141 } 149 }
142 150
143 void BackgroundHTMLParser::resumeFrom(PassOwnPtr<Checkpoint> checkpoint) 151 void BackgroundHTMLParser::resumeFrom(PassOwnPtr<Checkpoint> checkpoint)
144 { 152 {
145 m_parser = checkpoint->parser; 153 m_parser = checkpoint->parser;
146 m_token = checkpoint->token.release(); 154 m_token = checkpoint->token.release();
147 m_tokenizer = checkpoint->tokenizer.release(); 155 m_tokenizer = checkpoint->tokenizer.release();
148 m_treeBuilderSimulator.setState(checkpoint->treeBuilderState); 156 m_treeBuilderSimulator.setState(checkpoint->treeBuilderState);
149 m_input.rewindTo(checkpoint->inputCheckpoint, checkpoint->unparsedInput); 157 m_input.rewindTo(checkpoint->inputCheckpoint, checkpoint->unparsedInput);
150 m_preloadScanner->rewindTo(checkpoint->preloadScannerCheckpoint); 158 m_preloadScanner->rewindTo(checkpoint->preloadScannerCheckpoint);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 chunk->treeBuilderState = m_treeBuilderSimulator.state(); 252 chunk->treeBuilderState = m_treeBuilderSimulator.state();
245 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); 253 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size());
246 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); 254 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint();
247 chunk->tokens = m_pendingTokens.release(); 255 chunk->tokens = m_pendingTokens.release();
248 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser, m_parser, chunk.release())); 256 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser, m_parser, chunk.release()));
249 257
250 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); 258 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream);
251 } 259 }
252 260
253 } 261 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/BackgroundHTMLParser.h ('k') | Source/core/html/parser/HTMLDocumentParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698