| 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 11 matching lines...) Expand all Loading... |
| 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 "core/html/parser/BackgroundHTMLParser.h" | 26 #include "core/html/parser/BackgroundHTMLParser.h" |
| 27 | 27 |
| 28 #include "core/HTMLNames.h" | 28 #include "core/HTMLNames.h" |
| 29 #include "core/html/parser/HTMLDocumentParser.h" | 29 #include "core/html/parser/HTMLDocumentParser.h" |
| 30 #include "core/html/parser/TextResourceDecoder.h" | 30 #include "core/html/parser/TextResourceDecoder.h" |
| 31 #include "core/html/parser/XSSAuditor.h" | 31 #include "core/html/parser/XSSAuditor.h" |
| 32 #include "platform/CrossThreadFunctional.h" |
| 32 #include "platform/Histogram.h" | 33 #include "platform/Histogram.h" |
| 33 #include "platform/ThreadSafeFunctional.h" | |
| 34 #include "platform/TraceEvent.h" | 34 #include "platform/TraceEvent.h" |
| 35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 36 #include "public/platform/WebTaskRunner.h" | 36 #include "public/platform/WebTaskRunner.h" |
| 37 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
| 38 #include "wtf/PtrUtil.h" | 38 #include "wtf/PtrUtil.h" |
| 39 #include "wtf/text/TextPosition.h" | 39 #include "wtf/text/TextPosition.h" |
| 40 #include <memory> | 40 #include <memory> |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 152 } |
| 153 | 153 |
| 154 void BackgroundHTMLParser::updateDocument(const String& decodedData) | 154 void BackgroundHTMLParser::updateDocument(const String& decodedData) |
| 155 { | 155 { |
| 156 DocumentEncodingData encodingData(*m_decoder.get()); | 156 DocumentEncodingData encodingData(*m_decoder.get()); |
| 157 | 157 |
| 158 if (encodingData != m_lastSeenEncodingData) { | 158 if (encodingData != m_lastSeenEncodingData) { |
| 159 m_lastSeenEncodingData = encodingData; | 159 m_lastSeenEncodingData = encodingData; |
| 160 | 160 |
| 161 m_xssAuditor->setEncoding(encodingData.encoding()); | 161 m_xssAuditor->setEncoding(encodingData.encoding()); |
| 162 runOnMainThread(threadSafeBind(&HTMLDocumentParser::didReceiveEncodingDa
taFromBackgroundParser, m_parser, encodingData)); | 162 runOnMainThread(crossThreadBind(&HTMLDocumentParser::didReceiveEncodingD
ataFromBackgroundParser, m_parser, encodingData)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (decodedData.isEmpty()) | 165 if (decodedData.isEmpty()) |
| 166 return; | 166 return; |
| 167 | 167 |
| 168 appendDecodedBytes(decodedData); | 168 appendDecodedBytes(decodedData); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint) | 171 void BackgroundHTMLParser::resumeFrom(std::unique_ptr<Checkpoint> checkpoint) |
| 172 { | 172 { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 chunk->startingScript = m_startingScript; | 310 chunk->startingScript = m_startingScript; |
| 311 chunk->likelyDocumentWriteScriptIndices.swap(m_likelyDocumentWriteScriptIndi
ces); | 311 chunk->likelyDocumentWriteScriptIndices.swap(m_likelyDocumentWriteScriptIndi
ces); |
| 312 m_startingScript = false; | 312 m_startingScript = false; |
| 313 | 313 |
| 314 bool isEmpty = m_parsedChunkQueue->enqueue(std::move(chunk)); | 314 bool isEmpty = m_parsedChunkQueue->enqueue(std::move(chunk)); |
| 315 | 315 |
| 316 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, ("Parser.ChunkEn
queueTime", 1, 10000, 50)); | 316 DEFINE_STATIC_LOCAL(CustomCountHistogram, chunkEnqueueTime, ("Parser.ChunkEn
queueTime", 1, 10000, 50)); |
| 317 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); | 317 chunkEnqueueTime.count(monotonicallyIncreasingTimeMS() - chunkStartTime); |
| 318 | 318 |
| 319 if (isEmpty) { | 319 if (isEmpty) { |
| 320 runOnMainThread(threadSafeBind(&HTMLDocumentParser::notifyPendingParsedC
hunks, m_parser)); | 320 runOnMainThread(crossThreadBind(&HTMLDocumentParser::notifyPendingParsed
Chunks, m_parser)); |
| 321 } | 321 } |
| 322 | 322 |
| 323 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream); | 323 m_pendingTokens = wrapUnique(new CompactHTMLTokenStream); |
| 324 } | 324 } |
| 325 | 325 |
| 326 // If the background parser is already running on the main thread, then it is | 326 // If the background parser is already running on the main thread, then it is |
| 327 // not necessary to post a task to the main thread to run asynchronously. The | 327 // not necessary to post a task to the main thread to run asynchronously. The |
| 328 // main parser deals with chunking up its own work. | 328 // main parser deals with chunking up its own work. |
| 329 // TODO(csharrison): This is a pretty big hack because we don't actually need a | 329 // TODO(csharrison): This is a pretty big hack because we don't actually need a |
| 330 // CrossThreadClosure in these cases. This is just experimental. | 330 // CrossThreadClosure in these cases. This is just experimental. |
| 331 void BackgroundHTMLParser::runOnMainThread(std::unique_ptr<CrossThreadClosure> c
losure) | 331 void BackgroundHTMLParser::runOnMainThread(std::unique_ptr<CrossThreadClosure> c
losure) |
| 332 { | 332 { |
| 333 if (isMainThread()) | 333 if (isMainThread()) |
| 334 (*closure)(); | 334 (*closure)(); |
| 335 else | 335 else |
| 336 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure)); | 336 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure)); |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace blink | 339 } // namespace blink |
| OLD | NEW |