| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 BackgroundHTMLParser* parser = new BackgroundHTMLParser(config); | 55 BackgroundHTMLParser* parser = new BackgroundHTMLParser(config); |
| 56 return parser->m_weakFactory.GetWeakPtr(); | 56 return parser->m_weakFactory.GetWeakPtr(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 BackgroundHTMLParser::BackgroundHTMLParser(PassOwnPtr<Configuration> config) | 59 BackgroundHTMLParser::BackgroundHTMLParser(PassOwnPtr<Configuration> config) |
| 60 : m_token(adoptPtr(new HTMLToken)) | 60 : m_token(adoptPtr(new HTMLToken)) |
| 61 , m_tokenizer(HTMLTokenizer::create(config->options)) | 61 , m_tokenizer(HTMLTokenizer::create(config->options)) |
| 62 , m_parser(config->parser) | 62 , m_parser(config->parser) |
| 63 , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream)) | 63 , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream)) |
| 64 , m_decoder(TextResourceDecoder::create()) | 64 , m_decoder(TextResourceDecoder::create()) |
| 65 , m_source(config->source.Pass()) |
| 65 , m_weakFactory(this) | 66 , m_weakFactory(this) |
| 66 { | 67 { |
| 67 } | 68 } |
| 68 | 69 |
| 69 BackgroundHTMLParser::~BackgroundHTMLParser() | 70 BackgroundHTMLParser::~BackgroundHTMLParser() |
| 70 { | 71 { |
| 71 } | 72 } |
| 72 | 73 |
| 73 void BackgroundHTMLParser::appendRawBytesFromMainThread(PassOwnPtr<Vector<char>
> buffer) | 74 void BackgroundHTMLParser::start() |
| 74 { | 75 { |
| 75 updateDocument(m_decoder->decode(buffer->data(), buffer->size())); | 76 m_drainer = adoptPtr(new DataPipeDrainer(this, m_source.Pass())); |
| 76 } | |
| 77 | |
| 78 void BackgroundHTMLParser::appendDecodedBytes(const String& input) | |
| 79 { | |
| 80 ASSERT(!m_input.isClosed()); | |
| 81 m_input.append(SegmentedString(input)); | |
| 82 pumpTokenizer(); | |
| 83 } | |
| 84 | |
| 85 void BackgroundHTMLParser::flush() | |
| 86 { | |
| 87 updateDocument(m_decoder->flush()); | |
| 88 } | |
| 89 | |
| 90 void BackgroundHTMLParser::updateDocument(const String& decodedData) | |
| 91 { | |
| 92 if (decodedData.isEmpty()) | |
| 93 return; | |
| 94 | |
| 95 appendDecodedBytes(decodedData); | |
| 96 } | |
| 97 | |
| 98 void BackgroundHTMLParser::finish() | |
| 99 { | |
| 100 markEndOfFile(); | |
| 101 pumpTokenizer(); | |
| 102 } | 77 } |
| 103 | 78 |
| 104 void BackgroundHTMLParser::stop() | 79 void BackgroundHTMLParser::stop() |
| 105 { | 80 { |
| 106 delete this; | 81 delete this; |
| 107 } | 82 } |
| 108 | 83 |
| 84 void BackgroundHTMLParser::OnDataAvailable(const void* data, size_t numberOfByte
s) |
| 85 { |
| 86 ASSERT(!m_input.isClosed()); |
| 87 String input = m_decoder->decode(static_cast<const char*>(data), numberOfByt
es); |
| 88 m_input.append(SegmentedString(input)); |
| 89 pumpTokenizer(); |
| 90 } |
| 91 |
| 92 void BackgroundHTMLParser::OnDataComplete() |
| 93 { |
| 94 ASSERT(!m_input.isClosed()); |
| 95 finish(); |
| 96 } |
| 97 |
| 98 void BackgroundHTMLParser::finish() |
| 99 { |
| 100 m_input.append(SegmentedString(m_decoder->flush())); |
| 101 markEndOfFile(); |
| 102 pumpTokenizer(); |
| 103 } |
| 104 |
| 109 void BackgroundHTMLParser::markEndOfFile() | 105 void BackgroundHTMLParser::markEndOfFile() |
| 110 { | 106 { |
| 111 ASSERT(!m_input.isClosed()); | 107 ASSERT(!m_input.isClosed()); |
| 112 m_input.append(SegmentedString(String(&kEndOfFileMarker, 1))); | 108 m_input.append(SegmentedString(String(&kEndOfFileMarker, 1))); |
| 113 m_input.close(); | 109 m_input.close(); |
| 114 } | 110 } |
| 115 | 111 |
| 116 bool BackgroundHTMLParser::updateTokenizerState(const CompactHTMLToken& token) | 112 bool BackgroundHTMLParser::updateTokenizerState(const CompactHTMLToken& token) |
| 117 { | 113 { |
| 118 if (token.type() == HTMLToken::StartTag) { | 114 if (token.type() == HTMLToken::StartTag) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 #endif | 162 #endif |
| 167 | 163 |
| 168 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar
ser::ParsedChunk); | 164 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar
ser::ParsedChunk); |
| 169 chunk->tokens = m_pendingTokens.release(); | 165 chunk->tokens = m_pendingTokens.release(); |
| 170 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser, m_parser, chunk.release())); | 166 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser, m_parser, chunk.release())); |
| 171 | 167 |
| 172 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); | 168 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); |
| 173 } | 169 } |
| 174 | 170 |
| 175 } | 171 } |
| OLD | NEW |