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

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

Issue 1366883002: [Reland] Post loading tasks on the appropriate WebFrameScheduler's queue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix UAF in BackgroundHTMLParser Created 5 years, 2 months 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "core/inspector/InspectorInstrumentation.h" 43 #include "core/inspector/InspectorInstrumentation.h"
44 #include "core/inspector/InspectorTraceEvents.h" 44 #include "core/inspector/InspectorTraceEvents.h"
45 #include "core/loader/DocumentLoader.h" 45 #include "core/loader/DocumentLoader.h"
46 #include "core/loader/NavigationScheduler.h" 46 #include "core/loader/NavigationScheduler.h"
47 #include "platform/SharedBuffer.h" 47 #include "platform/SharedBuffer.h"
48 #include "platform/ThreadSafeFunctional.h" 48 #include "platform/ThreadSafeFunctional.h"
49 #include "platform/ThreadedDataReceiver.h" 49 #include "platform/ThreadedDataReceiver.h"
50 #include "platform/TraceEvent.h" 50 #include "platform/TraceEvent.h"
51 #include "platform/heap/Handle.h" 51 #include "platform/heap/Handle.h"
52 #include "public/platform/Platform.h" 52 #include "public/platform/Platform.h"
53 #include "public/platform/WebFrameScheduler.h"
53 #include "public/platform/WebScheduler.h" 54 #include "public/platform/WebScheduler.h"
54 #include "public/platform/WebThread.h" 55 #include "public/platform/WebThread.h"
55 #include "wtf/RefCounted.h" 56 #include "wtf/RefCounted.h"
56 #include "wtf/TemporaryChange.h" 57 #include "wtf/TemporaryChange.h"
57 58
58 namespace blink { 59 namespace blink {
59 60
60 using namespace HTMLNames; 61 using namespace HTMLNames;
61 62
62 // This is a direct transcription of step 4 from: 63 // This is a direct transcription of step 4 from:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 WeakPtr<BackgroundHTMLParser> m_backgroundParser; 137 WeakPtr<BackgroundHTMLParser> m_backgroundParser;
137 }; 138 };
138 139
139 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors , ParserSynchronizationPolicy syncPolicy) 140 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors , ParserSynchronizationPolicy syncPolicy)
140 : ScriptableDocumentParser(document) 141 : ScriptableDocumentParser(document)
141 , m_options(&document) 142 , m_options(&document)
142 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) : nullptr) 143 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) : nullptr)
143 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create( m_options) : nullptr) 144 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create( m_options) : nullptr)
144 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) 145 , m_scriptRunner(HTMLScriptRunner::create(&document, this))
145 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy (), reportErrors, m_options)) 146 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy (), reportErrors, m_options))
146 , m_parserScheduler(HTMLParserScheduler::create(this)) 147 , m_loadingTaskRunner(adoptPtr(document.loadingTaskRunner()->clone()))
148 , m_parserScheduler(HTMLParserScheduler::create(this, m_loadingTaskRunner.ge t()))
147 , m_xssAuditorDelegate(&document) 149 , m_xssAuditorDelegate(&document)
148 , m_weakFactory(this) 150 , m_weakFactory(this)
149 , m_preloader(HTMLResourcePreloader::create(document)) 151 , m_preloader(HTMLResourcePreloader::create(document))
150 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) 152 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing)
151 , m_endWasDelayed(false) 153 , m_endWasDelayed(false)
152 , m_haveBackgroundParser(false) 154 , m_haveBackgroundParser(false)
153 , m_tasksWereSuspended(false) 155 , m_tasksWereSuspended(false)
154 , m_pumpSessionNestingLevel(0) 156 , m_pumpSessionNestingLevel(0)
155 , m_pumpSpeculationsSessionNestingLevel(0) 157 , m_pumpSpeculationsSessionNestingLevel(0)
156 , m_isParsingAtLineNumber(false) 158 , m_isParsingAtLineNumber(false)
157 { 159 {
158 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); 160 ASSERT(shouldUseThreading() || (m_token && m_tokenizer));
159 } 161 }
160 162
161 // FIXME: Member variables should be grouped into self-initializing structs to 163 // FIXME: Member variables should be grouped into self-initializing structs to
162 // minimize code duplication between these constructors. 164 // minimize code duplication between these constructors.
163 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy) 165 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont extElement, ParserContentPolicy parserContentPolicy)
164 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) 166 : ScriptableDocumentParser(fragment->document(), parserContentPolicy)
165 , m_options(&fragment->document()) 167 , m_options(&fragment->document())
166 , m_token(adoptPtr(new HTMLToken)) 168 , m_token(adoptPtr(new HTMLToken))
167 , m_tokenizer(HTMLTokenizer::create(m_options)) 169 , m_tokenizer(HTMLTokenizer::create(m_options))
168 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this ->parserContentPolicy(), m_options)) 170 , m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this ->parserContentPolicy(), m_options))
171 , m_loadingTaskRunner(adoptPtr(fragment->document().loadingTaskRunner()->clo ne()))
169 , m_xssAuditorDelegate(&fragment->document()) 172 , m_xssAuditorDelegate(&fragment->document())
170 , m_weakFactory(this) 173 , m_weakFactory(this)
171 , m_shouldUseThreading(false) 174 , m_shouldUseThreading(false)
172 , m_endWasDelayed(false) 175 , m_endWasDelayed(false)
173 , m_haveBackgroundParser(false) 176 , m_haveBackgroundParser(false)
174 , m_tasksWereSuspended(false) 177 , m_tasksWereSuspended(false)
175 , m_pumpSessionNestingLevel(0) 178 , m_pumpSessionNestingLevel(0)
176 , m_pumpSpeculationsSessionNestingLevel(0) 179 , m_pumpSpeculationsSessionNestingLevel(0)
177 { 180 {
178 bool reportErrors = false; // For now document fragment parsing never report s errors. 181 bool reportErrors = false; // For now document fragment parsing never report s errors.
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 if (document()->settings()) { 797 if (document()->settings()) {
795 if (document()->settings()->backgroundHtmlParserOutstandingTokenLimit()) 798 if (document()->settings()->backgroundHtmlParserOutstandingTokenLimit())
796 config->outstandingTokenLimit = document()->settings()->backgroundHt mlParserOutstandingTokenLimit(); 799 config->outstandingTokenLimit = document()->settings()->backgroundHt mlParserOutstandingTokenLimit();
797 if (document()->settings()->backgroundHtmlParserPendingTokenLimit()) 800 if (document()->settings()->backgroundHtmlParserPendingTokenLimit())
798 config->pendingTokenLimit = document()->settings()->backgroundHtmlPa rserPendingTokenLimit(); 801 config->pendingTokenLimit = document()->settings()->backgroundHtmlPa rserPendingTokenLimit();
799 } 802 }
800 803
801 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); 804 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread());
802 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); 805 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread());
803 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s tart, reference.release(), config.release(), 806 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s tart, reference.release(), config.release(),
804 AllowCrossThreadAccess(Platform::current()->currentThread()->scheduler() ))); 807 AllowCrossThreadAccess(m_loadingTaskRunner.get())));
805 } 808 }
806 809
807 void HTMLDocumentParser::stopBackgroundParser() 810 void HTMLDocumentParser::stopBackgroundParser()
808 { 811 {
809 ASSERT(shouldUseThreading()); 812 ASSERT(shouldUseThreading());
810 ASSERT(m_haveBackgroundParser); 813 ASSERT(m_haveBackgroundParser);
811 m_haveBackgroundParser = false; 814 m_haveBackgroundParser = false;
812 815
813 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s top, AllowCrossThreadAccess(m_backgroundParser))); 816 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s top, AllowCrossThreadAccess(m_backgroundParser)));
814 m_weakFactory.revokeAll(); 817 m_weakFactory.revokeAll();
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1136 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1134 { 1137 {
1135 ASSERT(decoder); 1138 ASSERT(decoder);
1136 DecodedDataDocumentParser::setDecoder(decoder); 1139 DecodedDataDocumentParser::setDecoder(decoder);
1137 1140
1138 if (m_haveBackgroundParser) 1141 if (m_haveBackgroundParser)
1139 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); 1142 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder()));
1140 } 1143 }
1141 1144
1142 } 1145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698