Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: Source/core/html/parser/HTMLDocumentParser.cpp

Issue 625583002: Properly suspend HTMLDocumentParser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 , m_pumpSpeculationsSessionNestingLevel(0) 121 , m_pumpSpeculationsSessionNestingLevel(0)
121 { 122 {
122 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); 123 ASSERT(shouldUseThreading() || (m_token && m_tokenizer));
123 } 124 }
124 125
125 // FIXME: Member variables should be grouped into self-initializing structs to 126 // FIXME: Member variables should be grouped into self-initializing structs to
126 // minimize code duplication between these constructors. 127 // minimize code duplication between these constructors.
127 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy) 128 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy)
128 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) 129 : ScriptableDocumentParser(fragment->document(), parserContentPolicy)
129 , m_options(&fragment->document()) 130 , m_options(&fragment->document())
130 , m_token(adoptPtr(new HTMLToken)) 131 , m_token(adoptPtr(new HTMLToken))
131 , m_tokenizer(HTMLTokenizer::create(m_options)) 132 , m_tokenizer(HTMLTokenizer::create(m_options))
132 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this ->parserContentPolicy(), m_options)) 133 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this ->parserContentPolicy(), m_options))
133 , m_xssAuditorDelegate(&fragment->document()) 134 , m_xssAuditorDelegate(&fragment->document())
134 , m_weakFactory(this) 135 , m_weakFactory(this)
135 , m_isPinnedToMainThread(true) 136 , m_isPinnedToMainThread(true)
136 , m_endWasDelayed(false) 137 , m_endWasDelayed(false)
137 , m_haveBackgroundParser(false) 138 , m_haveBackgroundParser(false)
139 , m_tasksWereSuspended(false)
138 , m_pumpSessionNestingLevel(0) 140 , m_pumpSessionNestingLevel(0)
139 , m_pumpSpeculationsSessionNestingLevel(0) 141 , m_pumpSpeculationsSessionNestingLevel(0)
140 { 142 {
141 ASSERT(!shouldUseThreading()); 143 ASSERT(!shouldUseThreading());
142 bool reportErrors = false; // For now document fragment parsing never report s errors. 144 bool reportErrors = false; // For now document fragment parsing never report s errors.
143 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report Errors, m_options)); 145 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report Errors, m_options));
144 m_xssAuditor.initForFragment(); 146 m_xssAuditor.initForFragment();
145 } 147 }
146 148
147 HTMLDocumentParser::~HTMLDocumentParser() 149 HTMLDocumentParser::~HTMLDocumentParser()
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return true; 324 return true;
323 } 325 }
324 326
325 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa rsedChunk> chunk) 327 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa rsedChunk> chunk)
326 { 328 {
327 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser"); 329 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser");
328 330
329 // alert(), runModalDialog, and the JavaScript Debugger all run nested event loops 331 // alert(), runModalDialog, and the JavaScript Debugger all run nested event loops
330 // which can cause this method to be re-entered. We detect re-entry using 332 // which can cause this method to be re-entered. We detect re-entry using
331 // hasActiveParser(), save the chunk as a speculation, and return. 333 // hasActiveParser(), save the chunk as a speculation, and return.
332 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active ParserCount() > 0) { 334 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active ParserCount() > 0 || m_tasksWereSuspended || isScheduledForResume()) {
335 if (m_tasksWereSuspended)
336 m_parserScheduler->forceResumeAfterYield();
333 m_preloader->takeAndPreload(chunk->preloads); 337 m_preloader->takeAndPreload(chunk->preloads);
334 m_speculations.append(chunk); 338 m_speculations.append(chunk);
335 return; 339 return;
336 } 340 }
337 341
338 // processParsedChunkFromBackgroundParser can cause this parser to be detach ed from the Document, 342 // processParsedChunkFromBackgroundParser can cause this parser to be detach ed from the Document,
339 // but we need to ensure it isn't deleted yet. 343 // but we need to ensure it isn't deleted yet.
340 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); 344 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this);
341 345
342 ASSERT(m_speculations.isEmpty()); 346 ASSERT(m_speculations.isEmpty());
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 { 1009 {
1006 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f ragment, contextElement, parserContentPolicy); 1010 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f ragment, contextElement, parserContentPolicy);
1007 parser->insert(source); // Use insert() so that the parser will not yield. 1011 parser->insert(source); // Use insert() so that the parser will not yield.
1008 parser->finish(); 1012 parser->finish();
1009 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/ 3963151> 1013 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/ 3963151>
1010 parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction. 1014 parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction.
1011 } 1015 }
1012 1016
1013 void HTMLDocumentParser::suspendScheduledTasks() 1017 void HTMLDocumentParser::suspendScheduledTasks()
1014 { 1018 {
1019 ASSERT(!m_tasksWereSuspended);
1020 m_tasksWereSuspended = true;
1015 if (m_parserScheduler) 1021 if (m_parserScheduler)
1016 m_parserScheduler->suspend(); 1022 m_parserScheduler->suspend();
1017 } 1023 }
1018 1024
1019 void HTMLDocumentParser::resumeScheduledTasks() 1025 void HTMLDocumentParser::resumeScheduledTasks()
1020 { 1026 {
1027 ASSERT(m_tasksWereSuspended);
1028 m_tasksWereSuspended = false;
1021 if (m_parserScheduler) 1029 if (m_parserScheduler)
1022 m_parserScheduler->resume(); 1030 m_parserScheduler->resume();
1023 } 1031 }
1024 1032
1025 void HTMLDocumentParser::appendBytes(const char* data, size_t length) 1033 void HTMLDocumentParser::appendBytes(const char* data, size_t length)
1026 { 1034 {
1027 if (!length || isStopped()) 1035 if (!length || isStopped())
1028 return; 1036 return;
1029 1037
1030 if (shouldUseThreading()) { 1038 if (shouldUseThreading()) {
(...skipping 26 matching lines...) Expand all
1057 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1065 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1058 { 1066 {
1059 ASSERT(decoder); 1067 ASSERT(decoder);
1060 DecodedDataDocumentParser::setDecoder(decoder); 1068 DecodedDataDocumentParser::setDecoder(decoder);
1061 1069
1062 if (m_haveBackgroundParser) 1070 if (m_haveBackgroundParser)
1063 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1071 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1064 } 1072 }
1065 1073
1066 } 1074 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLDocumentParser.h ('k') | Source/core/html/parser/HTMLParserScheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698