| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 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 29 matching lines...) Expand all Loading... |
| 40 #include "core/html/parser/HTMLTreeBuilder.h" | 40 #include "core/html/parser/HTMLTreeBuilder.h" |
| 41 #include "core/inspector/InspectorTraceEvents.h" | 41 #include "core/inspector/InspectorTraceEvents.h" |
| 42 #include "platform/SharedBuffer.h" | 42 #include "platform/SharedBuffer.h" |
| 43 #include "platform/TraceEvent.h" | 43 #include "platform/TraceEvent.h" |
| 44 #include "wtf/Functional.h" | 44 #include "wtf/Functional.h" |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
) | 48 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
) |
| 49 : DocumentParser(document) | 49 : DocumentParser(document) |
| 50 , m_options(&document) | 50 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, reportErrors)) |
| 51 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, reportErrors, m_opt
ions)) | |
| 52 , m_parserScheduler(HTMLParserScheduler::create(this)) | 51 , m_parserScheduler(HTMLParserScheduler::create(this)) |
| 53 , m_weakFactory(this) | 52 , m_weakFactory(this) |
| 54 , m_isFragment(false) | 53 , m_isFragment(false) |
| 55 , m_endWasDelayed(false) | 54 , m_endWasDelayed(false) |
| 56 , m_haveBackgroundParser(false) | 55 , m_haveBackgroundParser(false) |
| 57 , m_pumpSessionNestingLevel(0) | 56 , m_pumpSessionNestingLevel(0) |
| 58 { | 57 { |
| 59 ASSERT(shouldUseThreading()); | |
| 60 } | 58 } |
| 61 | 59 |
| 62 HTMLDocumentParser::~HTMLDocumentParser() | 60 HTMLDocumentParser::~HTMLDocumentParser() |
| 63 { | 61 { |
| 64 #if ENABLE(OILPAN) | 62 #if ENABLE(OILPAN) |
| 65 if (m_haveBackgroundParser) | 63 if (m_haveBackgroundParser) |
| 66 stopBackgroundParser(); | 64 stopBackgroundParser(); |
| 67 // In Oilpan, HTMLDocumentParser can die together with Document, and | 65 // In Oilpan, HTMLDocumentParser can die together with Document, and |
| 68 // detach() is not called in this case. | 66 // detach() is not called in this case. |
| 69 #else | 67 #else |
| 70 ASSERT(!m_parserScheduler); | 68 ASSERT(!m_parserScheduler); |
| 71 ASSERT(!m_pumpSessionNestingLevel); | 69 ASSERT(!m_pumpSessionNestingLevel); |
| 72 ASSERT(!m_haveBackgroundParser); | 70 ASSERT(!m_haveBackgroundParser); |
| 73 // FIXME: We should be able to ASSERT(m_speculations.isEmpty()), | 71 // FIXME: We should be able to ASSERT(m_speculations.isEmpty()), |
| 74 // but there are cases where that's not true currently. For example, | 72 // but there are cases where that's not true currently. For example, |
| 75 // we we're told to stop parsing before we've consumed all the input. | 73 // we we're told to stop parsing before we've consumed all the input. |
| 76 #endif | 74 #endif |
| 77 } | 75 } |
| 78 | 76 |
| 79 void HTMLDocumentParser::parse(mojo::ScopedDataPipeConsumerHandle source) | 77 void HTMLDocumentParser::parse(mojo::ScopedDataPipeConsumerHandle source) |
| 80 { | 78 { |
| 81 ASSERT(!isStopped()); | 79 ASSERT(!isStopped()); |
| 82 ASSERT(shouldUseThreading()); | |
| 83 ASSERT(!m_haveBackgroundParser); | 80 ASSERT(!m_haveBackgroundParser); |
| 84 m_haveBackgroundParser = true; | 81 m_haveBackgroundParser = true; |
| 85 | 82 |
| 86 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); | 83 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); |
| 87 config->options = m_options; | |
| 88 config->source = source.Pass(); | 84 config->source = source.Pass(); |
| 89 config->parser = m_weakFactory.createWeakPtr(); | 85 config->parser = m_weakFactory.createWeakPtr(); |
| 90 | 86 |
| 91 m_backgroundParser = BackgroundHTMLParser::create(config.release()); | 87 m_backgroundParser = BackgroundHTMLParser::create(config.release()); |
| 92 HTMLParserThread::taskRunner()->PostTask(FROM_HERE, | 88 HTMLParserThread::taskRunner()->PostTask(FROM_HERE, |
| 93 base::Bind(&BackgroundHTMLParser::start, m_backgroundParser)); | 89 base::Bind(&BackgroundHTMLParser::start, m_backgroundParser)); |
| 94 } | 90 } |
| 95 | 91 |
| 96 void HTMLDocumentParser::detach() | 92 void HTMLDocumentParser::detach() |
| 97 { | 93 { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 TRACE_EVENT0("blink", "HTMLDocumentParser::processParsedChunkFromBackgroundP
arser"); | 214 TRACE_EVENT0("blink", "HTMLDocumentParser::processParsedChunkFromBackgroundP
arser"); |
| 219 | 215 |
| 220 ASSERT_WITH_SECURITY_IMPLICATION(!document()->activeParserCount()); | 216 ASSERT_WITH_SECURITY_IMPLICATION(!document()->activeParserCount()); |
| 221 ASSERT(!isParsingFragment()); | 217 ASSERT(!isParsingFragment()); |
| 222 ASSERT(!isWaitingForScripts()); | 218 ASSERT(!isWaitingForScripts()); |
| 223 ASSERT(!isStopped()); | 219 ASSERT(!isStopped()); |
| 224 #if !ENABLE(OILPAN) | 220 #if !ENABLE(OILPAN) |
| 225 // ASSERT that this object is both attached to the Document and protected. | 221 // ASSERT that this object is both attached to the Document and protected. |
| 226 ASSERT(refCount() >= 2); | 222 ASSERT(refCount() >= 2); |
| 227 #endif | 223 #endif |
| 228 ASSERT(shouldUseThreading()); | |
| 229 ASSERT(!m_lastChunkBeforeScript); | 224 ASSERT(!m_lastChunkBeforeScript); |
| 230 | 225 |
| 231 ActiveParserSession session(contextForParsingSession()); | 226 ActiveParserSession session(contextForParsingSession()); |
| 232 | 227 |
| 233 OwnPtr<ParsedChunk> chunk(popChunk); | 228 OwnPtr<ParsedChunk> chunk(popChunk); |
| 234 OwnPtr<CompactHTMLTokenStream> tokens = chunk->tokens.release(); | 229 OwnPtr<CompactHTMLTokenStream> tokens = chunk->tokens.release(); |
| 235 | 230 |
| 236 for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != to
kens->end(); ++it) { | 231 for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != to
kens->end(); ++it) { |
| 237 ASSERT(!isWaitingForScripts()); | 232 ASSERT(!isWaitingForScripts()); |
| 238 | 233 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 { | 338 { |
| 344 return false; | 339 return false; |
| 345 } | 340 } |
| 346 | 341 |
| 347 void HTMLDocumentParser::startBackgroundParser() | 342 void HTMLDocumentParser::startBackgroundParser() |
| 348 { | 343 { |
| 349 } | 344 } |
| 350 | 345 |
| 351 void HTMLDocumentParser::stopBackgroundParser() | 346 void HTMLDocumentParser::stopBackgroundParser() |
| 352 { | 347 { |
| 353 ASSERT(shouldUseThreading()); | |
| 354 ASSERT(m_haveBackgroundParser); | 348 ASSERT(m_haveBackgroundParser); |
| 355 m_haveBackgroundParser = false; | 349 m_haveBackgroundParser = false; |
| 356 | 350 |
| 357 HTMLParserThread::taskRunner()->PostTask(FROM_HERE, | 351 HTMLParserThread::taskRunner()->PostTask(FROM_HERE, |
| 358 base::Bind(&BackgroundHTMLParser::stop, m_backgroundParser)); | 352 base::Bind(&BackgroundHTMLParser::stop, m_backgroundParser)); |
| 359 m_weakFactory.revokeAll(); | 353 m_weakFactory.revokeAll(); |
| 360 } | 354 } |
| 361 | 355 |
| 362 void HTMLDocumentParser::end() | 356 void HTMLDocumentParser::end() |
| 363 { | 357 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 { | 427 { |
| 434 if (!m_scriptRunner.hasPendingScripts()) | 428 if (!m_scriptRunner.hasPendingScripts()) |
| 435 return; | 429 return; |
| 436 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 430 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); |
| 437 m_scriptRunner.executePendingScripts(); | 431 m_scriptRunner.executePendingScripts(); |
| 438 if (!isWaitingForScripts()) | 432 if (!isWaitingForScripts()) |
| 439 resumeParsingAfterScriptExecution(); | 433 resumeParsingAfterScriptExecution(); |
| 440 } | 434 } |
| 441 | 435 |
| 442 } | 436 } |
| OLD | NEW |