Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 , m_options(config->options) | 105 , m_options(config->options) |
| 106 , m_outstandingTokenLimit(config->outstandingTokenLimit) | 106 , m_outstandingTokenLimit(config->outstandingTokenLimit) |
| 107 , m_parser(config->parser) | 107 , m_parser(config->parser) |
| 108 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)) | 108 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)) |
| 109 , m_pendingTokenLimit(config->pendingTokenLimit) | 109 , m_pendingTokenLimit(config->pendingTokenLimit) |
| 110 , m_xssAuditor(std::move(config->xssAuditor)) | 110 , m_xssAuditor(std::move(config->xssAuditor)) |
| 111 , m_preloadScanner(wrapUnique(new TokenPreloadScanner(documentURL, std::move (cachedDocumentParameters), mediaValuesCachedData))) | 111 , m_preloadScanner(wrapUnique(new TokenPreloadScanner(documentURL, std::move (cachedDocumentParameters), mediaValuesCachedData))) |
| 112 , m_decoder(std::move(config->decoder)) | 112 , m_decoder(std::move(config->decoder)) |
| 113 , m_loadingTaskRunner(std::move(loadingTaskRunner)) | 113 , m_loadingTaskRunner(std::move(loadingTaskRunner)) |
| 114 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()) | 114 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()) |
| 115 , m_pendingCSPMetaTokenIndex(-1) | |
| 115 , m_startingScript(false) | 116 , m_startingScript(false) |
| 116 , m_lastBytesReceivedTime(0.0) | 117 , m_lastBytesReceivedTime(0.0) |
| 117 , m_shouldCoalesceChunks(config->shouldCoalesceChunks) | 118 , m_shouldCoalesceChunks(config->shouldCoalesceChunks) |
| 118 { | 119 { |
| 119 ASSERT(m_outstandingTokenLimit > 0); | 120 ASSERT(m_outstandingTokenLimit > 0); |
| 120 ASSERT(m_pendingTokenLimit > 0); | 121 ASSERT(m_pendingTokenLimit > 0); |
| 121 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit); | 122 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit); |
| 122 } | 123 } |
| 123 | 124 |
| 124 BackgroundHTMLParser::~BackgroundHTMLParser() | 125 BackgroundHTMLParser::~BackgroundHTMLParser() |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 TextPosition position = TextPosition(m_input.current().currentLine() , m_input.current().currentColumn()); | 246 TextPosition position = TextPosition(m_input.current().currentLine() , m_input.current().currentColumn()); |
| 246 | 247 |
| 247 if (std::unique_ptr<XSSInfo> xssInfo = m_xssAuditor->filterToken(Fil terTokenRequest(*m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA()))) { | 248 if (std::unique_ptr<XSSInfo> xssInfo = m_xssAuditor->filterToken(Fil terTokenRequest(*m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA()))) { |
| 248 xssInfo->m_textPosition = position; | 249 xssInfo->m_textPosition = position; |
| 249 m_pendingXSSInfos.append(std::move(xssInfo)); | 250 m_pendingXSSInfos.append(std::move(xssInfo)); |
| 250 } | 251 } |
| 251 | 252 |
| 252 CompactHTMLToken token(m_token.get(), position); | 253 CompactHTMLToken token(m_token.get(), position); |
| 253 | 254 |
| 254 bool shouldEvaluateForDocumentWrite = false; | 255 bool shouldEvaluateForDocumentWrite = false; |
| 255 m_preloadScanner->scan(token, m_input.current(), m_pendingPreloads, &m_viewportDescription, &shouldEvaluateForDocumentWrite); | 256 bool isCSPMetaTag = false; |
| 257 m_preloadScanner->scan(token, m_input.current(), m_pendingPreloads, &m_viewportDescription, &isCSPMetaTag, &shouldEvaluateForDocumentWrite); | |
| 256 | 258 |
| 257 simulatedToken = m_treeBuilderSimulator.simulate(token, m_tokenizer. get()); | 259 simulatedToken = m_treeBuilderSimulator.simulate(token, m_tokenizer. get()); |
| 258 | 260 |
| 259 // Break chunks before a script tag is inserted and flag the chunk a s starting a script | 261 // Break chunks before a script tag is inserted and flag the chunk a s starting a script |
| 260 // so the main parser can decide if it should yield before processin g the chunk. | 262 // so the main parser can decide if it should yield before processin g the chunk. |
| 261 if (simulatedToken == HTMLTreeBuilderSimulator::ScriptStart) { | 263 if (simulatedToken == HTMLTreeBuilderSimulator::ScriptStart) { |
| 262 shouldNotifyMainThread |= queueChunkForMainThread(); | 264 shouldNotifyMainThread |= queueChunkForMainThread(); |
| 263 m_startingScript = true; | 265 m_startingScript = true; |
| 264 } | 266 } |
| 265 | 267 |
| 266 m_pendingTokens->append(token); | 268 m_pendingTokens->append(token); |
| 269 if (isCSPMetaTag) { | |
| 270 m_pendingCSPMetaTokenIndex = m_pendingTokens->size() - 1; | |
| 271 } | |
| 267 if (shouldEvaluateForDocumentWrite) { | 272 if (shouldEvaluateForDocumentWrite) { |
| 268 m_likelyDocumentWriteScriptIndices.append(m_pendingTokens->size( ) - 1); | 273 m_likelyDocumentWriteScriptIndices.append(m_pendingTokens->size( ) - 1); |
| 269 } | 274 } |
| 270 } | 275 } |
| 271 | 276 |
| 272 m_token->clear(); | 277 m_token->clear(); |
| 273 | 278 |
| 274 if (simulatedToken == HTMLTreeBuilderSimulator::ScriptEnd || m_pendingTo kens->size() >= m_pendingTokenLimit) { | 279 if (simulatedToken == HTMLTreeBuilderSimulator::ScriptEnd || m_pendingTo kens->size() >= m_pendingTokenLimit) { |
| 275 shouldNotifyMainThread |= queueChunkForMainThread(); | 280 shouldNotifyMainThread |= queueChunkForMainThread(); |
| 276 // If we're far ahead of the main thread, yield for a bit to avoid c onsuming too much memory. | 281 // If we're far ahead of the main thread, yield for a bit to avoid c onsuming too much memory. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 if (m_viewportDescription.set) | 322 if (m_viewportDescription.set) |
| 318 chunk->viewport = m_viewportDescription; | 323 chunk->viewport = m_viewportDescription; |
| 319 chunk->xssInfos.swap(m_pendingXSSInfos); | 324 chunk->xssInfos.swap(m_pendingXSSInfos); |
| 320 chunk->tokenizerState = m_tokenizer->getState(); | 325 chunk->tokenizerState = m_tokenizer->getState(); |
| 321 chunk->treeBuilderState = m_treeBuilderSimulator.state(); | 326 chunk->treeBuilderState = m_treeBuilderSimulator.state(); |
| 322 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); | 327 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); |
| 323 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); | 328 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); |
| 324 chunk->tokens = std::move(m_pendingTokens); | 329 chunk->tokens = std::move(m_pendingTokens); |
| 325 chunk->startingScript = m_startingScript; | 330 chunk->startingScript = m_startingScript; |
| 326 chunk->likelyDocumentWriteScriptIndices.swap(m_likelyDocumentWriteScriptIndi ces); | 331 chunk->likelyDocumentWriteScriptIndices.swap(m_likelyDocumentWriteScriptIndi ces); |
| 332 chunk->pendingCSPMetaTokenIndex = m_pendingCSPMetaTokenIndex; | |
|
kouhei (in TOK)
2016/08/23 02:18:39
single space after =
Charlie Harrison
2016/08/23 03:08:41
Done.
| |
| 327 m_startingScript = false; | 333 m_startingScript = false; |
| 334 m_pendingCSPMetaTokenIndex = -1; | |
| 328 | 335 |
| 329 bool isEmpty = m_tokenizedChunkQueue->enqueue(std::move(chunk)); | 336 bool isEmpty = m_tokenizedChunkQueue->enqueue(std::move(chunk)); |
| 330 | 337 |
| 331 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, ("Parser.ChunkEn queueTime", 1, 10000, 50)); | 338 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, ("Parser.ChunkEn queueTime", 1, 10000, 50)); |
| 332 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); | 339 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); |
| 333 | 340 |
| 334 | 341 |
| 335 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream); | 342 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream); |
| 336 return isEmpty; | 343 return isEmpty; |
| 337 } | 344 } |
| 338 | 345 |
| 339 // If the background parser is already running on the main thread, then it is | 346 // If the background parser is already running on the main thread, then it is |
| 340 // not necessary to post a task to the main thread to run asynchronously. The | 347 // not necessary to post a task to the main thread to run asynchronously. The |
| 341 // main parser deals with chunking up its own work. | 348 // main parser deals with chunking up its own work. |
| 342 // TODO(csharrison): This is a pretty big hack because we don't actually need a | 349 // TODO(csharrison): This is a pretty big hack because we don't actually need a |
| 343 // CrossThreadClosure in these cases. This is just experimental. | 350 // CrossThreadClosure in these cases. This is just experimental. |
| 344 template <typename FunctionType, typename... Ps> | 351 template <typename FunctionType, typename... Ps> |
| 345 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters) | 352 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame ters) |
| 346 { | 353 { |
| 347 if (isMainThread()) { | 354 if (isMainThread()) { |
| 348 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 355 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
| 349 } else { | 356 } else { |
| 350 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...)); | 357 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(function, std::forward<Ps>(parameters)...)); |
| 351 } | 358 } |
| 352 } | 359 } |
| 353 | 360 |
| 354 } // namespace blink | 361 } // namespace blink |
| OLD | NEW |