| 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 17 matching lines...) Expand all Loading... |
| 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/CrossThreadFunctional.h" |
| 33 #include "platform/Histogram.h" | 33 #include "platform/Histogram.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/Functional.h" | |
| 39 #include "wtf/PtrUtil.h" | 38 #include "wtf/PtrUtil.h" |
| 40 #include "wtf/text/TextPosition.h" | 39 #include "wtf/text/TextPosition.h" |
| 41 #include <memory> | 40 #include <memory> |
| 42 | 41 |
| 43 namespace blink { | 42 namespace blink { |
| 44 | 43 |
| 45 // On a network with high latency and high bandwidth, using a device | 44 // On a network with high latency and high bandwidth, using a device |
| 46 // with a fast CPU, we could end up speculatively tokenizing | 45 // with a fast CPU, we could end up speculatively tokenizing |
| 47 // the whole document, well ahead of when the main-thread actually needs it. | 46 // the whole document, well ahead of when the main-thread actually needs it. |
| 48 // This is a waste of memory (and potentially time if the speculation fails). | 47 // This is a waste of memory (and potentially time if the speculation fails). |
| (...skipping 29 matching lines...) Expand all Loading... |
| 78 } | 77 } |
| 79 | 78 |
| 80 static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i
nfos) | 79 static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i
nfos) |
| 81 { | 80 { |
| 82 for (size_t i = 0; i < infos.size(); ++i) | 81 for (size_t i = 0; i < infos.size(); ++i) |
| 83 ASSERT(infos[i]->isSafeToSendToAnotherThread()); | 82 ASSERT(infos[i]->isSafeToSendToAnotherThread()); |
| 84 } | 83 } |
| 85 | 84 |
| 86 #endif | 85 #endif |
| 87 | 86 |
| 88 WeakPtr<BackgroundHTMLParser> BackgroundHTMLParser::create(std::unique_ptr<Confi
guration> config, std::unique_ptr<WebTaskRunner> loadingTaskRunner) | 87 void BackgroundHTMLParser::start(PassRefPtr<WeakReference<BackgroundHTMLParser>>
reference, std::unique_ptr<Configuration> config, const KURL& documentURL, std:
:unique_ptr<CachedDocumentParameters> cachedDocumentParameters, const MediaValue
sCached::MediaValuesCachedData& mediaValuesCachedData, std::unique_ptr<WebTaskRu
nner> loadingTaskRunner) |
| 89 { | 88 { |
| 90 auto* backgroundParser = new BackgroundHTMLParser(std::move(config), std::mo
ve(loadingTaskRunner)); | 89 new BackgroundHTMLParser(reference, std::move(config), documentURL, std::mov
e(cachedDocumentParameters), mediaValuesCachedData, std::move(loadingTaskRunner)
); |
| 91 return backgroundParser->m_weakFactory.createWeakPtr(); | 90 // Caller must free by calling stop(). |
| 92 } | 91 } |
| 93 | 92 |
| 94 void BackgroundHTMLParser::init(const KURL& documentURL, std::unique_ptr<CachedD
ocumentParameters> cachedDocumentParameters, const MediaValuesCached::MediaValue
sCachedData& mediaValuesCachedData) | |
| 95 { | |
| 96 m_preloadScanner.reset(new TokenPreloadScanner(documentURL, std::move(cached
DocumentParameters), mediaValuesCachedData)); | |
| 97 } | |
| 98 | |
| 99 | |
| 100 BackgroundHTMLParser::Configuration::Configuration() | 93 BackgroundHTMLParser::Configuration::Configuration() |
| 101 : outstandingTokenLimit(defaultOutstandingTokenLimit) | 94 : outstandingTokenLimit(defaultOutstandingTokenLimit) |
| 102 , pendingTokenLimit(defaultPendingTokenLimit) | 95 , pendingTokenLimit(defaultPendingTokenLimit) |
| 103 , shouldCoalesceChunks(false) | 96 , shouldCoalesceChunks(false) |
| 104 { | 97 { |
| 105 } | 98 } |
| 106 | 99 |
| 107 BackgroundHTMLParser::BackgroundHTMLParser(std::unique_ptr<Configuration> config
, std::unique_ptr<WebTaskRunner> loadingTaskRunner) | 100 BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHT
MLParser>> reference, std::unique_ptr<Configuration> config, const KURL& documen
tURL, std::unique_ptr<CachedDocumentParameters> cachedDocumentParameters, const
MediaValuesCached::MediaValuesCachedData& mediaValuesCachedData, std::unique_ptr
<WebTaskRunner> loadingTaskRunner) |
| 108 : m_weakFactory(this) | 101 : m_weakFactory(reference, this) |
| 109 , m_token(wrapUnique(new HTMLToken)) | 102 , m_token(wrapUnique(new HTMLToken)) |
| 110 , m_tokenizer(HTMLTokenizer::create(config->options)) | 103 , m_tokenizer(HTMLTokenizer::create(config->options)) |
| 111 , m_treeBuilderSimulator(config->options) | 104 , m_treeBuilderSimulator(config->options) |
| 112 , m_options(config->options) | 105 , m_options(config->options) |
| 113 , m_outstandingTokenLimit(config->outstandingTokenLimit) | 106 , m_outstandingTokenLimit(config->outstandingTokenLimit) |
| 114 , m_parser(config->parser) | 107 , m_parser(config->parser) |
| 115 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)) | 108 , m_pendingTokens(wrapUnique(new CompactHTMLTokenStream)) |
| 116 , m_pendingTokenLimit(config->pendingTokenLimit) | 109 , m_pendingTokenLimit(config->pendingTokenLimit) |
| 117 , m_xssAuditor(std::move(config->xssAuditor)) | 110 , m_xssAuditor(std::move(config->xssAuditor)) |
| 111 , m_preloadScanner(wrapUnique(new TokenPreloadScanner(documentURL, std::move
(cachedDocumentParameters), mediaValuesCachedData))) |
| 118 , m_decoder(std::move(config->decoder)) | 112 , m_decoder(std::move(config->decoder)) |
| 119 , m_loadingTaskRunner(std::move(loadingTaskRunner)) | 113 , m_loadingTaskRunner(std::move(loadingTaskRunner)) |
| 120 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()) | 114 , m_tokenizedChunkQueue(config->tokenizedChunkQueue.release()) |
| 121 , m_pendingCSPMetaTokenIndex(HTMLDocumentParser::TokenizedChunk::noPendingTo
ken) | 115 , m_pendingCSPMetaTokenIndex(HTMLDocumentParser::TokenizedChunk::noPendingTo
ken) |
| 122 , m_startingScript(false) | 116 , m_startingScript(false) |
| 123 , m_lastBytesReceivedTime(0.0) | 117 , m_lastBytesReceivedTime(0.0) |
| 124 , m_shouldCoalesceChunks(config->shouldCoalesceChunks) | 118 , m_shouldCoalesceChunks(config->shouldCoalesceChunks) |
| 125 { | 119 { |
| 126 ASSERT(m_outstandingTokenLimit > 0); | 120 ASSERT(m_outstandingTokenLimit > 0); |
| 127 ASSERT(m_pendingTokenLimit > 0); | 121 ASSERT(m_pendingTokenLimit > 0); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame
ters) | 352 void BackgroundHTMLParser::runOnMainThread(FunctionType function, Ps&&... parame
ters) |
| 359 { | 353 { |
| 360 if (isMainThread()) { | 354 if (isMainThread()) { |
| 361 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 355 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
| 362 } else { | 356 } else { |
| 363 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)...)); |
| 364 } | 358 } |
| 365 } | 359 } |
| 366 | 360 |
| 367 } // namespace blink | 361 } // namespace blink |
| OLD | NEW |