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