| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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 "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/html/parser/HTMLDocumentParser.h" | 29 #include "core/html/parser/HTMLDocumentParser.h" |
| 30 #include "core/html/parser/HTMLParserThread.h" | |
| 31 #include "core/html/parser/TextResourceDecoder.h" | 30 #include "core/html/parser/TextResourceDecoder.h" |
| 32 #include "core/html/parser/XSSAuditor.h" | 31 #include "core/html/parser/XSSAuditor.h" |
| 33 #include "wtf/MainThread.h" | 32 #include "wtf/MainThread.h" |
| 34 #include "wtf/text/TextPosition.h" | 33 #include "wtf/text/TextPosition.h" |
| 35 | 34 |
| 36 namespace WebCore { | 35 namespace WebCore { |
| 37 | 36 |
| 38 // On a network with high latency and high bandwidth, using a device | 37 // On a network with high latency and high bandwidth, using a device |
| 39 // with a fast CPU, we could end up speculatively tokenizing | 38 // with a fast CPU, we could end up speculatively tokenizing |
| 40 // the whole document, well ahead of when the main-thread actually needs it. | 39 // the whole document, well ahead of when the main-thread actually needs it. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 , m_xssAuditor(config->xssAuditor.release()) | 93 , m_xssAuditor(config->xssAuditor.release()) |
| 95 , m_preloadScanner(config->preloadScanner.release()) | 94 , m_preloadScanner(config->preloadScanner.release()) |
| 96 , m_decoder(config->decoder.release()) | 95 , m_decoder(config->decoder.release()) |
| 97 { | 96 { |
| 98 } | 97 } |
| 99 | 98 |
| 100 BackgroundHTMLParser::~BackgroundHTMLParser() | 99 BackgroundHTMLParser::~BackgroundHTMLParser() |
| 101 { | 100 { |
| 102 } | 101 } |
| 103 | 102 |
| 103 void BackgroundHTMLParser::acceptData(const char* data, int dataLength) |
| 104 { |
| 105 ASSERT(m_decoder); |
| 106 updateDocument(m_decoder->decode(data, dataLength)); |
| 107 } |
| 108 |
| 104 void BackgroundHTMLParser::append(const String& input) | 109 void BackgroundHTMLParser::append(const String& input) |
| 105 { | 110 { |
| 106 ASSERT(!m_input.current().isClosed()); | 111 ASSERT(!m_input.current().isClosed()); |
| 107 m_input.append(input); | 112 m_input.append(input); |
| 108 pumpTokenizer(); | 113 pumpTokenizer(); |
| 109 } | 114 } |
| 110 | 115 |
| 111 void BackgroundHTMLParser::appendBytes(PassOwnPtr<Vector<char> > buffer) | 116 void BackgroundHTMLParser::appendBytes(PassOwnPtr<Vector<char> > buffer) |
| 112 { | 117 { |
| 118 ASSERT(m_decoder); |
| 113 updateDocument(m_decoder->decode(buffer->data(), buffer->size())); | 119 updateDocument(m_decoder->decode(buffer->data(), buffer->size())); |
| 114 } | 120 } |
| 115 | 121 |
| 116 void BackgroundHTMLParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 122 void BackgroundHTMLParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| 117 { | 123 { |
| 124 ASSERT(decoder); |
| 118 m_decoder = decoder; | 125 m_decoder = decoder; |
| 119 } | 126 } |
| 120 | 127 |
| 121 void BackgroundHTMLParser::flush() | 128 void BackgroundHTMLParser::flush() |
| 122 { | 129 { |
| 130 ASSERT(m_decoder); |
| 123 updateDocument(m_decoder->flush()); | 131 updateDocument(m_decoder->flush()); |
| 124 } | 132 } |
| 125 | 133 |
| 126 void BackgroundHTMLParser::updateDocument(const String& decodedData) | 134 void BackgroundHTMLParser::updateDocument(const String& decodedData) |
| 127 { | 135 { |
| 128 DocumentEncodingData encodingData(*m_decoder.get()); | 136 DocumentEncodingData encodingData(*m_decoder.get()); |
| 129 | 137 |
| 130 if (encodingData != m_lastSeenEncodingData) { | 138 if (encodingData != m_lastSeenEncodingData) { |
| 131 m_lastSeenEncodingData = encodingData; | 139 m_lastSeenEncodingData = encodingData; |
| 132 | 140 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 chunk->treeBuilderState = m_treeBuilderSimulator.state(); | 252 chunk->treeBuilderState = m_treeBuilderSimulator.state(); |
| 245 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); | 253 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); |
| 246 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); | 254 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); |
| 247 chunk->tokens = m_pendingTokens.release(); | 255 chunk->tokens = m_pendingTokens.release(); |
| 248 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser, m_parser, chunk.release())); | 256 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser, m_parser, chunk.release())); |
| 249 | 257 |
| 250 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); | 258 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); |
| 251 } | 259 } |
| 252 | 260 |
| 253 } | 261 } |
| OLD | NEW |