| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 base::WeakPtr<BackgroundHTMLParser> BackgroundHTMLParser::create(PassOwnPtr<Back
groundHTMLParser::Configuration> config) | 55 base::WeakPtr<BackgroundHTMLParser> BackgroundHTMLParser::create(PassOwnPtr<Back
groundHTMLParser::Configuration> config) |
| 56 { | 56 { |
| 57 // Caller must free by calling stop(). | 57 // Caller must free by calling stop(). |
| 58 BackgroundHTMLParser* parser = new BackgroundHTMLParser(config); | 58 BackgroundHTMLParser* parser = new BackgroundHTMLParser(config); |
| 59 return parser->m_weakFactory.GetWeakPtr(); | 59 return parser->m_weakFactory.GetWeakPtr(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 BackgroundHTMLParser::BackgroundHTMLParser(PassOwnPtr<Configuration> config) | 62 BackgroundHTMLParser::BackgroundHTMLParser(PassOwnPtr<Configuration> config) |
| 63 : m_token(adoptPtr(new HTMLToken)) | 63 : m_state(InitialState) |
| 64 , m_token(adoptPtr(new HTMLToken)) |
| 64 , m_tokenizer(HTMLTokenizer::create()) | 65 , m_tokenizer(HTMLTokenizer::create()) |
| 65 , m_parser(config->parser) | 66 , m_parser(config->parser) |
| 66 , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream)) | 67 , m_pendingTokens(adoptPtr(new CompactHTMLTokenStream)) |
| 67 , m_decoder(TextResourceDecoder::create()) | 68 , m_decoder(TextResourceDecoder::create()) |
| 68 , m_source(config->source.Pass()) | 69 , m_source(config->source.Pass()) |
| 69 , m_weakFactory(this) | 70 , m_weakFactory(this) |
| 70 { | 71 { |
| 71 } | 72 } |
| 72 | 73 |
| 73 BackgroundHTMLParser::~BackgroundHTMLParser() | 74 BackgroundHTMLParser::~BackgroundHTMLParser() |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 { | 110 { |
| 110 ASSERT(!m_input.isClosed()); | 111 ASSERT(!m_input.isClosed()); |
| 111 m_input.append(SegmentedString(String(&kEndOfFileMarker, 1))); | 112 m_input.append(SegmentedString(String(&kEndOfFileMarker, 1))); |
| 112 m_input.close(); | 113 m_input.close(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool BackgroundHTMLParser::updateTokenizerState(const CompactHTMLToken& token) | 116 bool BackgroundHTMLParser::updateTokenizerState(const CompactHTMLToken& token) |
| 116 { | 117 { |
| 117 if (token.type() == HTMLToken::StartTag) { | 118 if (token.type() == HTMLToken::StartTag) { |
| 118 const String& tagName = token.data(); | 119 const String& tagName = token.data(); |
| 120 |
| 119 if (threadSafeMatch(tagName, HTMLNames::scriptTag) || threadSafeMatch(ta
gName, HTMLNames::styleTag)) | 121 if (threadSafeMatch(tagName, HTMLNames::scriptTag) || threadSafeMatch(ta
gName, HTMLNames::styleTag)) |
| 120 m_tokenizer->setState(HTMLTokenizer::RawDataState); | 122 m_tokenizer->setState(HTMLTokenizer::RawDataState); |
| 123 |
| 124 if (threadSafeMatch(tagName, HTMLNames::importTag)) { |
| 125 m_state = DidSeeImportState; |
| 126 return true; |
| 127 } |
| 128 |
| 129 if (m_state == InitialState) |
| 130 return true; |
| 131 |
| 132 m_state = InitialState; |
| 133 return false; |
| 121 } | 134 } |
| 122 | 135 |
| 123 return token.type() != HTMLToken::EndTag || !threadSafeMatch(token.data(), H
TMLNames::scriptTag); | 136 return token.type() != HTMLToken::EndTag || !threadSafeMatch(token.data(), H
TMLNames::scriptTag); |
| 124 } | 137 } |
| 125 | 138 |
| 126 void BackgroundHTMLParser::pumpTokenizer() | 139 void BackgroundHTMLParser::pumpTokenizer() |
| 127 { | 140 { |
| 128 while (true) { | 141 while (true) { |
| 129 if (!m_tokenizer->nextToken(m_input, *m_token)) { | 142 if (!m_tokenizer->nextToken(m_input, *m_token)) { |
| 130 // We've reached the end of our current input. | 143 // We've reached the end of our current input. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 155 | 168 |
| 156 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar
ser::ParsedChunk); | 169 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar
ser::ParsedChunk); |
| 157 chunk->tokens = m_pendingTokens.release(); | 170 chunk->tokens = m_pendingTokens.release(); |
| 158 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE, | 171 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE, |
| 159 base::Bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParse
r, m_parser, chunk.release())); | 172 base::Bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParse
r, m_parser, chunk.release())); |
| 160 | 173 |
| 161 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); | 174 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); |
| 162 } | 175 } |
| 163 | 176 |
| 164 } | 177 } |
| OLD | NEW |