| OLD | NEW |
| 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 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // https://bugs.webkit.org/show_bug.cgi?id=110408. | 62 // https://bugs.webkit.org/show_bug.cgi?id=110408. |
| 63 static const size_t defaultPendingTokenLimit = 1000; | 63 static const size_t defaultPendingTokenLimit = 1000; |
| 64 | 64 |
| 65 using namespace HTMLNames; | 65 using namespace HTMLNames; |
| 66 | 66 |
| 67 #if DCHECK_IS_ON() | 67 #if DCHECK_IS_ON() |
| 68 | 68 |
| 69 static void checkThatTokensAreSafeToSendToAnotherThread( | 69 static void checkThatTokensAreSafeToSendToAnotherThread( |
| 70 const CompactHTMLTokenStream* tokens) { | 70 const CompactHTMLTokenStream* tokens) { |
| 71 for (size_t i = 0; i < tokens->size(); ++i) | 71 for (size_t i = 0; i < tokens->size(); ++i) |
| 72 ASSERT(tokens->at(i).isSafeToSendToAnotherThread()); | 72 DCHECK(tokens->at(i).isSafeToSendToAnotherThread()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 static void checkThatPreloadsAreSafeToSendToAnotherThread( | 75 static void checkThatPreloadsAreSafeToSendToAnotherThread( |
| 76 const PreloadRequestStream& preloads) { | 76 const PreloadRequestStream& preloads) { |
| 77 for (size_t i = 0; i < preloads.size(); ++i) | 77 for (size_t i = 0; i < preloads.size(); ++i) |
| 78 ASSERT(preloads[i]->isSafeToSendToAnotherThread()); | 78 DCHECK(preloads[i]->isSafeToSendToAnotherThread()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static void checkThatXSSInfosAreSafeToSendToAnotherThread( | 81 static void checkThatXSSInfosAreSafeToSendToAnotherThread( |
| 82 const XSSInfoStream& infos) { | 82 const XSSInfoStream& infos) { |
| 83 for (size_t i = 0; i < infos.size(); ++i) | 83 for (size_t i = 0; i < infos.size(); ++i) |
| 84 ASSERT(infos[i]->isSafeToSendToAnotherThread()); | 84 DCHECK(infos[i]->isSafeToSendToAnotherThread()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 #endif | 87 #endif |
| 88 | 88 |
| 89 WeakPtr<BackgroundHTMLParser> BackgroundHTMLParser::create( | 89 WeakPtr<BackgroundHTMLParser> BackgroundHTMLParser::create( |
| 90 std::unique_ptr<Configuration> config, | 90 std::unique_ptr<Configuration> config, |
| 91 RefPtr<WebTaskRunner> loadingTaskRunner) { | 91 RefPtr<WebTaskRunner> loadingTaskRunner) { |
| 92 auto* backgroundParser = | 92 auto* backgroundParser = |
| 93 new BackgroundHTMLParser(std::move(config), std::move(loadingTaskRunner)); | 93 new BackgroundHTMLParser(std::move(config), std::move(loadingTaskRunner)); |
| 94 return backgroundParser->m_weakFactory.createWeakPtr(); | 94 return backgroundParser->m_weakFactory.createWeakPtr(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 121 m_pendingTokenLimit(config->pendingTokenLimit), | 121 m_pendingTokenLimit(config->pendingTokenLimit), |
| 122 m_xssAuditor(std::move(config->xssAuditor)), | 122 m_xssAuditor(std::move(config->xssAuditor)), |
| 123 m_decoder(std::move(config->decoder)), | 123 m_decoder(std::move(config->decoder)), |
| 124 m_loadingTaskRunner(std::move(loadingTaskRunner)), | 124 m_loadingTaskRunner(std::move(loadingTaskRunner)), |
| 125 m_tokenizedChunkQueue(std::move(config->tokenizedChunkQueue)), | 125 m_tokenizedChunkQueue(std::move(config->tokenizedChunkQueue)), |
| 126 m_pendingCSPMetaTokenIndex( | 126 m_pendingCSPMetaTokenIndex( |
| 127 HTMLDocumentParser::TokenizedChunk::noPendingToken), | 127 HTMLDocumentParser::TokenizedChunk::noPendingToken), |
| 128 m_startingScript(false), | 128 m_startingScript(false), |
| 129 m_lastBytesReceivedTime(0.0), | 129 m_lastBytesReceivedTime(0.0), |
| 130 m_shouldCoalesceChunks(config->shouldCoalesceChunks) { | 130 m_shouldCoalesceChunks(config->shouldCoalesceChunks) { |
| 131 ASSERT(m_outstandingTokenLimit > 0); | 131 DCHECK_GT(m_outstandingTokenLimit, 0u); |
| 132 ASSERT(m_pendingTokenLimit > 0); | 132 DCHECK_GT(m_pendingTokenLimit, 0u); |
| 133 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit); | 133 DCHECK_GE(m_outstandingTokenLimit, m_pendingTokenLimit); |
| 134 } | 134 } |
| 135 | 135 |
| 136 BackgroundHTMLParser::~BackgroundHTMLParser() {} | 136 BackgroundHTMLParser::~BackgroundHTMLParser() {} |
| 137 | 137 |
| 138 void BackgroundHTMLParser::appendRawBytesFromMainThread( | 138 void BackgroundHTMLParser::appendRawBytesFromMainThread( |
| 139 std::unique_ptr<Vector<char>> buffer, | 139 std::unique_ptr<Vector<char>> buffer, |
| 140 double bytesReceivedTime) { | 140 double bytesReceivedTime) { |
| 141 ASSERT(m_decoder); | 141 DCHECK(m_decoder); |
| 142 m_lastBytesReceivedTime = bytesReceivedTime; | 142 m_lastBytesReceivedTime = bytesReceivedTime; |
| 143 DEFINE_STATIC_LOCAL(CustomCountHistogram, queueDelay, | 143 DEFINE_STATIC_LOCAL(CustomCountHistogram, queueDelay, |
| 144 ("Parser.AppendBytesDelay", 1, 5000, 50)); | 144 ("Parser.AppendBytesDelay", 1, 5000, 50)); |
| 145 queueDelay.count(monotonicallyIncreasingTimeMS() - bytesReceivedTime); | 145 queueDelay.count(monotonicallyIncreasingTimeMS() - bytesReceivedTime); |
| 146 updateDocument(m_decoder->decode(buffer->data(), buffer->size())); | 146 updateDocument(m_decoder->decode(buffer->data(), buffer->size())); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void BackgroundHTMLParser::appendDecodedBytes(const String& input) { | 149 void BackgroundHTMLParser::appendDecodedBytes(const String& input) { |
| 150 ASSERT(!m_input.current().isClosed()); | 150 DCHECK(!m_input.current().isClosed()); |
| 151 m_input.append(input); | 151 m_input.append(input); |
| 152 pumpTokenizer(); | 152 pumpTokenizer(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void BackgroundHTMLParser::setDecoder( | 155 void BackgroundHTMLParser::setDecoder( |
| 156 std::unique_ptr<TextResourceDecoder> decoder) { | 156 std::unique_ptr<TextResourceDecoder> decoder) { |
| 157 ASSERT(decoder); | 157 DCHECK(decoder); |
| 158 m_decoder = std::move(decoder); | 158 m_decoder = std::move(decoder); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void BackgroundHTMLParser::flush() { | 161 void BackgroundHTMLParser::flush() { |
| 162 ASSERT(m_decoder); | 162 DCHECK(m_decoder); |
| 163 updateDocument(m_decoder->flush()); | 163 updateDocument(m_decoder->flush()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void BackgroundHTMLParser::updateDocument(const String& decodedData) { | 166 void BackgroundHTMLParser::updateDocument(const String& decodedData) { |
| 167 DocumentEncodingData encodingData(*m_decoder.get()); | 167 DocumentEncodingData encodingData(*m_decoder.get()); |
| 168 | 168 |
| 169 if (encodingData != m_lastSeenEncodingData) { | 169 if (encodingData != m_lastSeenEncodingData) { |
| 170 m_lastSeenEncodingData = encodingData; | 170 m_lastSeenEncodingData = encodingData; |
| 171 | 171 |
| 172 m_xssAuditor->setEncoding(encodingData.encoding()); | 172 m_xssAuditor->setEncoding(encodingData.encoding()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 void BackgroundHTMLParser::forcePlaintextForTextDocument() { | 214 void BackgroundHTMLParser::forcePlaintextForTextDocument() { |
| 215 // This is only used by the TextDocumentParser (a subclass of | 215 // This is only used by the TextDocumentParser (a subclass of |
| 216 // HTMLDocumentParser) to force us into the PLAINTEXT state w/o using a | 216 // HTMLDocumentParser) to force us into the PLAINTEXT state w/o using a |
| 217 // <plaintext> tag. The TextDocumentParser uses a <pre> tag for historical / | 217 // <plaintext> tag. The TextDocumentParser uses a <pre> tag for historical / |
| 218 // compatibility reasons. | 218 // compatibility reasons. |
| 219 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); | 219 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void BackgroundHTMLParser::markEndOfFile() { | 222 void BackgroundHTMLParser::markEndOfFile() { |
| 223 ASSERT(!m_input.current().isClosed()); | 223 DCHECK(!m_input.current().isClosed()); |
| 224 m_input.append(String(&kEndOfFileMarker, 1)); | 224 m_input.append(String(&kEndOfFileMarker, 1)); |
| 225 m_input.close(); | 225 m_input.close(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void BackgroundHTMLParser::pumpTokenizer() { | 228 void BackgroundHTMLParser::pumpTokenizer() { |
| 229 TRACE_EVENT0("loading", "BackgroundHTMLParser::pumpTokenizer"); | 229 TRACE_EVENT0("loading", "BackgroundHTMLParser::pumpTokenizer"); |
| 230 HTMLTreeBuilderSimulator::SimulatedToken simulatedToken = | 230 HTMLTreeBuilderSimulator::SimulatedToken simulatedToken = |
| 231 HTMLTreeBuilderSimulator::OtherToken; | 231 HTMLTreeBuilderSimulator::OtherToken; |
| 232 | 232 |
| 233 // No need to start speculating until the main thread has almost caught up. | 233 // No need to start speculating until the main thread has almost caught up. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 if (isMainThread()) { | 379 if (isMainThread()) { |
| 380 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 380 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
| 381 } else { | 381 } else { |
| 382 m_loadingTaskRunner->postTask( | 382 m_loadingTaskRunner->postTask( |
| 383 BLINK_FROM_HERE, | 383 BLINK_FROM_HERE, |
| 384 crossThreadBind(function, std::forward<Ps>(parameters)...)); | 384 crossThreadBind(function, std::forward<Ps>(parameters)...)); |
| 385 } | 385 } |
| 386 } | 386 } |
| 387 | 387 |
| 388 } // namespace blink | 388 } // namespace blink |
| OLD | NEW |