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

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

Issue 2614663004: Pause HTML parser for external stylesheets in the body (Closed)
Patch Set: merge to trunk Created 3 years, 11 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 HTMLDocumentParser(Document&, 163 HTMLDocumentParser(Document&,
164 ParserContentPolicy, 164 ParserContentPolicy,
165 ParserSynchronizationPolicy); 165 ParserSynchronizationPolicy);
166 166
167 // DocumentParser 167 // DocumentParser
168 void detach() final; 168 void detach() final;
169 bool hasInsertionPoint() final; 169 bool hasInsertionPoint() final;
170 void prepareToStopParsing() final; 170 void prepareToStopParsing() final;
171 void stopParsing() final; 171 void stopParsing() final;
172 bool isPaused() const {
173 return isWaitingForScripts() || m_isWaitingForStylesheets;
174 }
172 bool isWaitingForScripts() const final; 175 bool isWaitingForScripts() const final;
173 bool isExecutingScript() const final; 176 bool isExecutingScript() const final;
174 void executeScriptsWaitingForResources() final; 177 void executeScriptsWaitingForResources() final;
178 void didAddPendingStylesheetInBody() final;
179 void didLoadAllStylesheets() final;
175 void documentElementAvailable() override; 180 void documentElementAvailable() override;
176 181
177 // HTMLParserScriptRunnerHost 182 // HTMLParserScriptRunnerHost
178 void notifyScriptLoaded(PendingScript*) final; 183 void notifyScriptLoaded(PendingScript*) final;
179 HTMLInputStream& inputStream() final { return m_input; } 184 HTMLInputStream& inputStream() final { return m_input; }
180 bool hasPreloadScanner() const final { 185 bool hasPreloadScanner() const final {
181 return m_preloadScanner.get() && !shouldUseThreading(); 186 return m_preloadScanner.get() && !shouldUseThreading();
182 } 187 }
183 void appendCurrentInputStreamToPreloadScannerAndScan() final; 188 void appendCurrentInputStreamToPreloadScannerAndScan() final;
184 189
185 void startBackgroundParser(); 190 void startBackgroundParser();
186 void stopBackgroundParser(); 191 void stopBackgroundParser();
187 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk); 192 void validateSpeculations(std::unique_ptr<TokenizedChunk> lastChunk);
188 void discardSpeculationsAndResumeFrom( 193 void discardSpeculationsAndResumeFrom(
189 std::unique_ptr<TokenizedChunk> lastChunk, 194 std::unique_ptr<TokenizedChunk> lastChunk,
190 std::unique_ptr<HTMLToken>, 195 std::unique_ptr<HTMLToken>,
191 std::unique_ptr<HTMLTokenizer>); 196 std::unique_ptr<HTMLTokenizer>);
192 size_t processTokenizedChunkFromBackgroundParser( 197 size_t processTokenizedChunkFromBackgroundParser(
193 std::unique_ptr<TokenizedChunk>); 198 std::unique_ptr<TokenizedChunk>);
194 void pumpPendingSpeculations(); 199 void pumpPendingSpeculations();
195 200
196 bool canTakeNextToken(); 201 bool canTakeNextToken();
197 void pumpTokenizer(); 202 void pumpTokenizer();
198 void pumpTokenizerIfPossible(); 203 void pumpTokenizerIfPossible();
199 void constructTreeFromHTMLToken(); 204 void constructTreeFromHTMLToken();
200 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&); 205 void constructTreeFromCompactHTMLToken(const CompactHTMLToken&);
201 206
202 void runScriptsForPausedTreeBuilder(); 207 void runScriptsForPausedTreeBuilder();
203 void resumeParsingAfterScriptExecution(); 208 void resumeParsingAfterPause();
204 209
205 void attemptToEnd(); 210 void attemptToEnd();
206 void endIfDelayed(); 211 void endIfDelayed();
207 void attemptToRunDeferredScriptsAndEnd(); 212 void attemptToRunDeferredScriptsAndEnd();
208 void end(); 213 void end();
209 214
210 bool shouldUseThreading() const { return m_shouldUseThreading; } 215 bool shouldUseThreading() const { return m_shouldUseThreading; }
211 216
212 bool isParsingFragment() const; 217 bool isParsingFragment() const;
213 bool isScheduledForResume() const; 218 bool isScheduledForResume() const;
214 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } 219 bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; }
215 bool shouldDelayEnd() const { 220 bool shouldDelayEnd() const {
216 return inPumpSession() || isWaitingForScripts() || isScheduledForResume() || 221 return inPumpSession() || isPaused() || isScheduledForResume() ||
217 isExecutingScript(); 222 isExecutingScript();
218 } 223 }
219 224
220 std::unique_ptr<HTMLPreloadScanner> createPreloadScanner(); 225 std::unique_ptr<HTMLPreloadScanner> createPreloadScanner();
221 226
222 // Let the given HTMLPreloadScanner scan the input it has, and then preloads 227 // Let the given HTMLPreloadScanner scan the input it has, and then preloads
223 // resources using the resulting PreloadRequests and |m_preloader|. 228 // resources using the resulting PreloadRequests and |m_preloader|.
224 void scanAndPreload(HTMLPreloadScanner*); 229 void scanAndPreload(HTMLPreloadScanner*);
225 void fetchQueuedPreloads(); 230 void fetchQueuedPreloads();
226 231
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // A scanner used only for input provided to the insert() method. 263 // A scanner used only for input provided to the insert() method.
259 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner; 264 std::unique_ptr<HTMLPreloadScanner> m_insertionPreloadScanner;
260 265
261 RefPtr<WebTaskRunner> m_loadingTaskRunner; 266 RefPtr<WebTaskRunner> m_loadingTaskRunner;
262 Member<HTMLParserScheduler> m_parserScheduler; 267 Member<HTMLParserScheduler> m_parserScheduler;
263 HTMLSourceTracker m_sourceTracker; 268 HTMLSourceTracker m_sourceTracker;
264 TextPosition m_textPosition; 269 TextPosition m_textPosition;
265 XSSAuditor m_xssAuditor; 270 XSSAuditor m_xssAuditor;
266 XSSAuditorDelegate m_xssAuditorDelegate; 271 XSSAuditorDelegate m_xssAuditorDelegate;
267 272
268 // FIXME: m_lastChunkBeforeScript, m_tokenizer, m_token, and m_input should be 273 // FIXME: m_lastChunkBeforePause, m_tokenizer, m_token, and m_input should be
269 // combined into a single state object so they can be set and cleared together 274 // combined into a single state object so they can be set and cleared together
270 // and passed between threads together. 275 // and passed between threads together.
271 std::unique_ptr<TokenizedChunk> m_lastChunkBeforeScript; 276 std::unique_ptr<TokenizedChunk> m_lastChunkBeforePause;
272 Deque<std::unique_ptr<TokenizedChunk>> m_speculations; 277 Deque<std::unique_ptr<TokenizedChunk>> m_speculations;
273 WeakPtrFactory<HTMLDocumentParser> m_weakFactory; 278 WeakPtrFactory<HTMLDocumentParser> m_weakFactory;
274 WeakPtr<BackgroundHTMLParser> m_backgroundParser; 279 WeakPtr<BackgroundHTMLParser> m_backgroundParser;
275 Member<HTMLResourcePreloader> m_preloader; 280 Member<HTMLResourcePreloader> m_preloader;
276 PreloadRequestStream m_queuedPreloads; 281 PreloadRequestStream m_queuedPreloads;
277 Vector<String> m_queuedDocumentWriteScripts; 282 Vector<String> m_queuedDocumentWriteScripts;
278 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue; 283 RefPtr<TokenizedChunkQueue> m_tokenizedChunkQueue;
279 std::unique_ptr<DocumentWriteEvaluator> m_evaluator; 284 std::unique_ptr<DocumentWriteEvaluator> m_evaluator;
280 285
281 // If this is non-null, then there is a meta CSP token somewhere in the 286 // If this is non-null, then there is a meta CSP token somewhere in the
282 // speculation buffer. Preloads will be deferred until a token matching this 287 // speculation buffer. Preloads will be deferred until a token matching this
283 // pointer is parsed and the CSP policy is applied. Note that this pointer 288 // pointer is parsed and the CSP policy is applied. Note that this pointer
284 // tracks the *last* meta token in the speculation buffer, so it overestimates 289 // tracks the *last* meta token in the speculation buffer, so it overestimates
285 // how long to defer preloads. This is for simplicity, as the alternative 290 // how long to defer preloads. This is for simplicity, as the alternative
286 // would require keeping track of token positions of preload requests. 291 // would require keeping track of token positions of preload requests.
287 CompactHTMLToken* m_pendingCSPMetaToken; 292 CompactHTMLToken* m_pendingCSPMetaToken;
288 293
294 TaskHandle m_resumeParsingTaskHandle;
295
289 bool m_shouldUseThreading; 296 bool m_shouldUseThreading;
290 bool m_endWasDelayed; 297 bool m_endWasDelayed;
291 bool m_haveBackgroundParser; 298 bool m_haveBackgroundParser;
292 bool m_tasksWereSuspended; 299 bool m_tasksWereSuspended;
293 unsigned m_pumpSessionNestingLevel; 300 unsigned m_pumpSessionNestingLevel;
294 unsigned m_pumpSpeculationsSessionNestingLevel; 301 unsigned m_pumpSpeculationsSessionNestingLevel;
295 bool m_isParsingAtLineNumber; 302 bool m_isParsingAtLineNumber;
296 bool m_triedLoadingLinkHeaders; 303 bool m_triedLoadingLinkHeaders;
304 bool m_addedPendingStylesheetInBody;
305 bool m_isWaitingForStylesheets;
297 }; 306 };
298 307
299 } // namespace blink 308 } // namespace blink
300 309
301 #endif // HTMLDocumentParser_h 310 #endif // HTMLDocumentParser_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698