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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 , m_tokenizer(nullptr) | 109 , m_tokenizer(nullptr) |
110 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) | 110 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) |
111 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) | 111 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) |
112 , m_parserScheduler(HTMLParserScheduler::create(this)) | 112 , m_parserScheduler(HTMLParserScheduler::create(this)) |
113 , m_xssAuditorDelegate(&document) | 113 , m_xssAuditorDelegate(&document) |
114 , m_weakFactory(this) | 114 , m_weakFactory(this) |
115 , m_preloader(HTMLResourcePreloader::create(document)) | 115 , m_preloader(HTMLResourcePreloader::create(document)) |
116 , m_isPinnedToMainThread(false) | 116 , m_isPinnedToMainThread(false) |
117 , m_endWasDelayed(false) | 117 , m_endWasDelayed(false) |
118 , m_haveBackgroundParser(false) | 118 , m_haveBackgroundParser(false) |
| 119 , m_tasksWereSuspended(false) |
119 , m_pumpSessionNestingLevel(0) | 120 , m_pumpSessionNestingLevel(0) |
120 { | 121 { |
121 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); | 122 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); |
122 } | 123 } |
123 | 124 |
124 // FIXME: Member variables should be grouped into self-initializing structs to | 125 // FIXME: Member variables should be grouped into self-initializing structs to |
125 // minimize code duplication between these constructors. | 126 // minimize code duplication between these constructors. |
126 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) | 127 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) |
127 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) | 128 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) |
128 , m_options(&fragment->document()) | 129 , m_options(&fragment->document()) |
129 , m_token(adoptPtr(new HTMLToken)) | 130 , m_token(adoptPtr(new HTMLToken)) |
130 , m_tokenizer(HTMLTokenizer::create(m_options)) | 131 , m_tokenizer(HTMLTokenizer::create(m_options)) |
131 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this
->parserContentPolicy(), m_options)) | 132 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this
->parserContentPolicy(), m_options)) |
132 , m_xssAuditorDelegate(&fragment->document()) | 133 , m_xssAuditorDelegate(&fragment->document()) |
133 , m_weakFactory(this) | 134 , m_weakFactory(this) |
134 , m_isPinnedToMainThread(true) | 135 , m_isPinnedToMainThread(true) |
135 , m_endWasDelayed(false) | 136 , m_endWasDelayed(false) |
136 , m_haveBackgroundParser(false) | 137 , m_haveBackgroundParser(false) |
| 138 , m_tasksWereSuspended(false) |
137 , m_pumpSessionNestingLevel(0) | 139 , m_pumpSessionNestingLevel(0) |
138 { | 140 { |
139 ASSERT(!shouldUseThreading()); | 141 ASSERT(!shouldUseThreading()); |
140 bool reportErrors = false; // For now document fragment parsing never report
s errors. | 142 bool reportErrors = false; // For now document fragment parsing never report
s errors. |
141 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report
Errors, m_options)); | 143 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report
Errors, m_options)); |
142 m_xssAuditor.initForFragment(); | 144 m_xssAuditor.initForFragment(); |
143 } | 145 } |
144 | 146 |
145 HTMLDocumentParser::~HTMLDocumentParser() | 147 HTMLDocumentParser::~HTMLDocumentParser() |
146 { | 148 { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 return true; | 329 return true; |
328 } | 330 } |
329 | 331 |
330 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa
rsedChunk> chunk) | 332 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa
rsedChunk> chunk) |
331 { | 333 { |
332 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser"); | 334 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser"); |
333 | 335 |
334 // alert(), runModalDialog, and the JavaScript Debugger all run nested event
loops | 336 // alert(), runModalDialog, and the JavaScript Debugger all run nested event
loops |
335 // which can cause this method to be re-entered. We detect re-entry using | 337 // which can cause this method to be re-entered. We detect re-entry using |
336 // hasActiveParser(), save the chunk as a speculation, and return. | 338 // hasActiveParser(), save the chunk as a speculation, and return. |
337 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active
ParserCount() > 0) { | 339 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active
ParserCount() > 0 || m_tasksWereSuspended) { |
| 340 if (m_tasksWereSuspended) |
| 341 m_parserScheduler->forceResumeAfterYield(); |
338 m_preloader->takeAndPreload(chunk->preloads); | 342 m_preloader->takeAndPreload(chunk->preloads); |
339 m_speculations.append(chunk); | 343 m_speculations.append(chunk); |
340 return; | 344 return; |
341 } | 345 } |
342 | 346 |
343 // processParsedChunkFromBackgroundParser can cause this parser to be detach
ed from the Document, | 347 // processParsedChunkFromBackgroundParser can cause this parser to be detach
ed from the Document, |
344 // but we need to ensure it isn't deleted yet. | 348 // but we need to ensure it isn't deleted yet. |
345 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 349 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); |
346 | 350 |
347 ASSERT(m_speculations.isEmpty()); | 351 ASSERT(m_speculations.isEmpty()); |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 { | 1000 { |
997 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f
ragment, contextElement, parserContentPolicy); | 1001 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f
ragment, contextElement, parserContentPolicy); |
998 parser->insert(source); // Use insert() so that the parser will not yield. | 1002 parser->insert(source); // Use insert() so that the parser will not yield. |
999 parser->finish(); | 1003 parser->finish(); |
1000 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/
3963151> | 1004 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/
3963151> |
1001 parser->detach(); // Allows ~DocumentParser to assert it was detached before
destruction. | 1005 parser->detach(); // Allows ~DocumentParser to assert it was detached before
destruction. |
1002 } | 1006 } |
1003 | 1007 |
1004 void HTMLDocumentParser::suspendScheduledTasks() | 1008 void HTMLDocumentParser::suspendScheduledTasks() |
1005 { | 1009 { |
| 1010 ASSERT(!m_tasksWereSuspended); |
| 1011 m_tasksWereSuspended = true; |
1006 if (m_parserScheduler) | 1012 if (m_parserScheduler) |
1007 m_parserScheduler->suspend(); | 1013 m_parserScheduler->suspend(); |
1008 } | 1014 } |
1009 | 1015 |
1010 void HTMLDocumentParser::resumeScheduledTasks() | 1016 void HTMLDocumentParser::resumeScheduledTasks() |
1011 { | 1017 { |
| 1018 ASSERT(m_tasksWereSuspended); |
| 1019 m_tasksWereSuspended = false; |
1012 if (m_parserScheduler) | 1020 if (m_parserScheduler) |
1013 m_parserScheduler->resume(); | 1021 m_parserScheduler->resume(); |
1014 } | 1022 } |
1015 | 1023 |
1016 void HTMLDocumentParser::appendBytes(const char* data, size_t length) | 1024 void HTMLDocumentParser::appendBytes(const char* data, size_t length) |
1017 { | 1025 { |
1018 if (!length || isStopped()) | 1026 if (!length || isStopped()) |
1019 return; | 1027 return; |
1020 | 1028 |
1021 if (shouldUseThreading()) { | 1029 if (shouldUseThreading()) { |
(...skipping 26 matching lines...) Expand all Loading... |
1048 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1056 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
1049 { | 1057 { |
1050 ASSERT(decoder); | 1058 ASSERT(decoder); |
1051 DecodedDataDocumentParser::setDecoder(decoder); | 1059 DecodedDataDocumentParser::setDecoder(decoder); |
1052 | 1060 |
1053 if (m_haveBackgroundParser) | 1061 if (m_haveBackgroundParser) |
1054 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); | 1062 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); |
1055 } | 1063 } |
1056 | 1064 |
1057 } | 1065 } |
OLD | NEW |