| 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 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/html/parser/BackgroundHTMLParser.h" | 27 #include "core/html/parser/BackgroundHTMLParser.h" |
| 28 | 28 |
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" |
| 30 #include "core/html/parser/HTMLDocumentParser.h" | 30 #include "core/html/parser/HTMLDocumentParser.h" |
| 31 #include "core/html/parser/TextResourceDecoder.h" | 31 #include "core/html/parser/TextResourceDecoder.h" |
| 32 #include "core/html/parser/XSSAuditor.h" | 32 #include "core/html/parser/XSSAuditor.h" |
| 33 #include "platform/Task.h" | 33 #include "platform/Task.h" |
| 34 #include "platform/ThreadSafeFunctional.h" | 34 #include "platform/ThreadSafeFunctional.h" |
| 35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 36 #include "public/platform/WebTaskRunner.h" | 36 #include "public/platform/WebScheduler.h" |
| 37 #include "wtf/text/TextPosition.h" | 37 #include "wtf/text/TextPosition.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 // On a network with high latency and high bandwidth, using a device | 41 // On a network with high latency and high bandwidth, using a device |
| 42 // with a fast CPU, we could end up speculatively tokenizing | 42 // with a fast CPU, we could end up speculatively tokenizing |
| 43 // the whole document, well ahead of when the main-thread actually needs it. | 43 // the whole document, well ahead of when the main-thread actually needs it. |
| 44 // This is a waste of memory (and potentially time if the speculation fails). | 44 // This is a waste of memory (and potentially time if the speculation fails). |
| 45 // So we limit our outstanding tokens arbitrarily to 10,000. | 45 // So we limit our outstanding tokens arbitrarily to 10,000. |
| 46 // Our maximal memory spent speculating will be approximately: | 46 // Our maximal memory spent speculating will be approximately: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i
nfos) | 76 static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& i
nfos) |
| 77 { | 77 { |
| 78 for (size_t i = 0; i < infos.size(); ++i) | 78 for (size_t i = 0; i < infos.size(); ++i) |
| 79 ASSERT(infos[i]->isSafeToSendToAnotherThread()); | 79 ASSERT(infos[i]->isSafeToSendToAnotherThread()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 void BackgroundHTMLParser::start(PassRefPtr<WeakReference<BackgroundHTMLParser>>
reference, PassOwnPtr<Configuration> config, WebTaskRunner* loadingTaskRunner) | 84 void BackgroundHTMLParser::start(PassRefPtr<WeakReference<BackgroundHTMLParser>>
reference, PassOwnPtr<Configuration> config, WebScheduler* scheduler) |
| 85 { | 85 { |
| 86 new BackgroundHTMLParser(reference, config, loadingTaskRunner); | 86 new BackgroundHTMLParser(reference, config, scheduler); |
| 87 // Caller must free by calling stop(). | 87 // Caller must free by calling stop(). |
| 88 } | 88 } |
| 89 | 89 |
| 90 BackgroundHTMLParser::Configuration::Configuration() | 90 BackgroundHTMLParser::Configuration::Configuration() |
| 91 : outstandingTokenLimit(defaultOutstandingTokenLimit) | 91 : outstandingTokenLimit(defaultOutstandingTokenLimit) |
| 92 , pendingTokenLimit(defaultPendingTokenLimit) | 92 , pendingTokenLimit(defaultPendingTokenLimit) |
| 93 { | 93 { |
| 94 } | 94 } |
| 95 | 95 |
| 96 BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHT
MLParser>> reference, PassOwnPtr<Configuration> config, WebTaskRunner* loadingTa
skRunner) | 96 BackgroundHTMLParser::BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHT
MLParser>> reference, PassOwnPtr<Configuration> config, WebScheduler* scheduler) |
| 97 : m_weakFactory(reference, this) | 97 : m_weakFactory(reference, this) |
| 98 , m_token(adoptPtr(new HTMLToken)) | 98 , m_token(adoptPtr(new HTMLToken)) |
| 99 , m_tokenizer(HTMLTokenizer::create(config->options)) | 99 , m_tokenizer(HTMLTokenizer::create(config->options)) |
| 100 , m_treeBuilderSimulator(config->options) | 100 , m_treeBuilderSimulator(config->options) |
| 101 , m_options(config->options) | 101 , m_options(config->options) |
| 102 , m_outstandingTokenLimit(config->outstandingTokenLimit) | 102 , m_outstandingTokenLimit(config->outstandingTokenLimit) |
| 103 , m_parser(config->parser) | 103 , m_parser(config->parser) |
| 104 , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream)) | 104 , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream)) |
| 105 , m_pendingTokenLimit(config->pendingTokenLimit) | 105 , m_pendingTokenLimit(config->pendingTokenLimit) |
| 106 , m_xssAuditor(config->xssAuditor.release()) | 106 , m_xssAuditor(config->xssAuditor.release()) |
| 107 , m_preloadScanner(config->preloadScanner.release()) | 107 , m_preloadScanner(config->preloadScanner.release()) |
| 108 , m_decoder(config->decoder.release()) | 108 , m_decoder(config->decoder.release()) |
| 109 , m_loadingTaskRunner(loadingTaskRunner) | 109 , m_scheduler(scheduler) |
| 110 , m_startingScript(false) | 110 , m_startingScript(false) |
| 111 { | 111 { |
| 112 ASSERT(m_outstandingTokenLimit > 0); | 112 ASSERT(m_outstandingTokenLimit > 0); |
| 113 ASSERT(m_pendingTokenLimit > 0); | 113 ASSERT(m_pendingTokenLimit > 0); |
| 114 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit); | 114 ASSERT(m_outstandingTokenLimit >= m_pendingTokenLimit); |
| 115 } | 115 } |
| 116 | 116 |
| 117 BackgroundHTMLParser::~BackgroundHTMLParser() | 117 BackgroundHTMLParser::~BackgroundHTMLParser() |
| 118 { | 118 { |
| 119 } | 119 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 void BackgroundHTMLParser::updateDocument(const String& decodedData) | 152 void BackgroundHTMLParser::updateDocument(const String& decodedData) |
| 153 { | 153 { |
| 154 DocumentEncodingData encodingData(*m_decoder.get()); | 154 DocumentEncodingData encodingData(*m_decoder.get()); |
| 155 | 155 |
| 156 if (encodingData != m_lastSeenEncodingData) { | 156 if (encodingData != m_lastSeenEncodingData) { |
| 157 m_lastSeenEncodingData = encodingData; | 157 m_lastSeenEncodingData = encodingData; |
| 158 | 158 |
| 159 m_xssAuditor->setEncoding(encodingData.encoding()); | 159 m_xssAuditor->setEncoding(encodingData.encoding()); |
| 160 m_loadingTaskRunner->postTask( | 160 m_scheduler->loadingTaskRunner()->postTask( |
| 161 FROM_HERE, | 161 FROM_HERE, |
| 162 threadSafeBind(&HTMLDocumentParser::didReceiveEncodingDataFromBackgr
oundParser, AllowCrossThreadAccess(m_parser), encodingData)); | 162 threadSafeBind(&HTMLDocumentParser::didReceiveEncodingDataFromBackgr
oundParser, AllowCrossThreadAccess(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 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 chunk->preloads.swap(m_pendingPreloads); | 284 chunk->preloads.swap(m_pendingPreloads); |
| 285 chunk->xssInfos.swap(m_pendingXSSInfos); | 285 chunk->xssInfos.swap(m_pendingXSSInfos); |
| 286 chunk->tokenizerState = m_tokenizer->state(); | 286 chunk->tokenizerState = m_tokenizer->state(); |
| 287 chunk->treeBuilderState = m_treeBuilderSimulator.state(); | 287 chunk->treeBuilderState = m_treeBuilderSimulator.state(); |
| 288 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); | 288 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); |
| 289 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); | 289 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); |
| 290 chunk->tokens = m_pendingTokens.release(); | 290 chunk->tokens = m_pendingTokens.release(); |
| 291 chunk->startingScript = m_startingScript; | 291 chunk->startingScript = m_startingScript; |
| 292 m_startingScript = false; | 292 m_startingScript = false; |
| 293 | 293 |
| 294 m_loadingTaskRunner->postTask( | 294 m_scheduler->loadingTaskRunner()->postTask( |
| 295 FROM_HERE, | 295 FROM_HERE, |
| 296 new Task(threadSafeBind(&HTMLDocumentParser::didReceiveParsedChunkFromBa
ckgroundParser, AllowCrossThreadAccess(m_parser), chunk.release()))); | 296 new Task(threadSafeBind(&HTMLDocumentParser::didReceiveParsedChunkFromBa
ckgroundParser, AllowCrossThreadAccess(m_parser), chunk.release()))); |
| 297 | 297 |
| 298 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); | 298 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); |
| 299 } | 299 } |
| 300 | 300 |
| 301 } | 301 } |
| OLD | NEW |