| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 || (contextTag.matches(noscriptTag) && options.scriptEnabled) | 78 || (contextTag.matches(noscriptTag) && options.scriptEnabled) |
| 79 || contextTag.matches(noframesTag)) | 79 || contextTag.matches(noframesTag)) |
| 80 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN
TEXTState; | 80 return reportErrors ? HTMLTokenizer::RAWTEXTState : HTMLTokenizer::PLAIN
TEXTState; |
| 81 if (contextTag.matches(scriptTag)) | 81 if (contextTag.matches(scriptTag)) |
| 82 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; | 82 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; |
| 83 if (contextTag.matches(plaintextTag)) | 83 if (contextTag.matches(plaintextTag)) |
| 84 return HTMLTokenizer::PLAINTEXTState; | 84 return HTMLTokenizer::PLAINTEXTState; |
| 85 return HTMLTokenizer::DataState; | 85 return HTMLTokenizer::DataState; |
| 86 } | 86 } |
| 87 | 87 |
| 88 class ParserDataReceiver final : public RefCountedWillBeGarbageCollectedFinalize
d<ParserDataReceiver>, public ThreadedDataReceiver, public DocumentLifecycleObse
rver { | 88 class ParserDataReceiver final : public GarbageCollectedFinalized<ParserDataRece
iver>, public ThreadedDataReceiver, public DocumentLifecycleObserver { |
| 89 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ParserDataReceiver); | 89 USING_GARBAGE_COLLECTED_MIXIN(ParserDataReceiver); |
| 90 public: | 90 public: |
| 91 static PassRefPtrWillBeRawPtr<ParserDataReceiver> create(WeakPtr<BackgroundH
TMLParser> backgroundParser, Document* document) | 91 static RawPtr<ParserDataReceiver> create(WeakPtr<BackgroundHTMLParser> backg
roundParser, Document* document) |
| 92 { | 92 { |
| 93 return adoptRefWillBeNoop(new ParserDataReceiver(backgroundParser, docum
ent)); | 93 return (new ParserDataReceiver(backgroundParser, document)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 #if !ENABLE(OILPAN) | 96 #if !ENABLE(OILPAN) |
| 97 void ref() override { RefCounted<ParserDataReceiver>::ref(); } | 97 void ref() override { RefCounted<ParserDataReceiver>::ref(); } |
| 98 void deref() override { RefCounted<ParserDataReceiver>::deref(); } | 98 void deref() override { RefCounted<ParserDataReceiver>::deref(); } |
| 99 #endif | 99 #endif |
| 100 | 100 |
| 101 // ThreadedDataReceiver | 101 // ThreadedDataReceiver |
| 102 void acceptData(const char* data, int dataLength) override | 102 void acceptData(const char* data, int dataLength) override |
| 103 { | 103 { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // This kicks off "Once the user agent stops parsing" as described by: | 252 // This kicks off "Once the user agent stops parsing" as described by: |
| 253 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#the-
end | 253 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#the-
end |
| 254 void HTMLDocumentParser::prepareToStopParsing() | 254 void HTMLDocumentParser::prepareToStopParsing() |
| 255 { | 255 { |
| 256 // FIXME: It may not be correct to disable this for the background parser. | 256 // FIXME: It may not be correct to disable this for the background parser. |
| 257 // That means hasInsertionPoint() may not be correct in some cases. | 257 // That means hasInsertionPoint() may not be correct in some cases. |
| 258 ASSERT(!hasInsertionPoint() || m_haveBackgroundParser); | 258 ASSERT(!hasInsertionPoint() || m_haveBackgroundParser); |
| 259 | 259 |
| 260 // pumpTokenizer can cause this parser to be detached from the Document, | 260 // pumpTokenizer can cause this parser to be detached from the Document, |
| 261 // but we need to ensure it isn't deleted yet. | 261 // but we need to ensure it isn't deleted yet. |
| 262 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 262 RawPtr<HTMLDocumentParser> protect(this); |
| 263 | 263 |
| 264 // NOTE: This pump should only ever emit buffered character tokens. | 264 // NOTE: This pump should only ever emit buffered character tokens. |
| 265 if (m_tokenizer) { | 265 if (m_tokenizer) { |
| 266 ASSERT(!m_haveBackgroundParser); | 266 ASSERT(!m_haveBackgroundParser); |
| 267 pumpTokenizerIfPossible(); | 267 pumpTokenizerIfPossible(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 if (isStopped()) | 270 if (isStopped()) |
| 271 return; | 271 return; |
| 272 | 272 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Used by HTMLParserScheduler | 310 // Used by HTMLParserScheduler |
| 311 void HTMLDocumentParser::resumeParsingAfterYield() | 311 void HTMLDocumentParser::resumeParsingAfterYield() |
| 312 { | 312 { |
| 313 ASSERT(shouldUseThreading()); | 313 ASSERT(shouldUseThreading()); |
| 314 ASSERT(m_haveBackgroundParser); | 314 ASSERT(m_haveBackgroundParser); |
| 315 | 315 |
| 316 // pumpPendingSpeculations can cause this parser to be detached from the Doc
ument, | 316 // pumpPendingSpeculations can cause this parser to be detached from the Doc
ument, |
| 317 // but we need to ensure it isn't deleted yet. | 317 // but we need to ensure it isn't deleted yet. |
| 318 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 318 RawPtr<HTMLDocumentParser> protect(this); |
| 319 pumpPendingSpeculations(); | 319 pumpPendingSpeculations(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void HTMLDocumentParser::runScriptsForPausedTreeBuilder() | 322 void HTMLDocumentParser::runScriptsForPausedTreeBuilder() |
| 323 { | 323 { |
| 324 ASSERT(scriptingContentIsAllowed(parserContentPolicy())); | 324 ASSERT(scriptingContentIsAllowed(parserContentPolicy())); |
| 325 | 325 |
| 326 TextPosition scriptStartPosition = TextPosition::belowRangePosition(); | 326 TextPosition scriptStartPosition = TextPosition::belowRangePosition(); |
| 327 RefPtrWillBeRawPtr<Element> scriptElement = m_treeBuilder->takeScriptToProce
ss(scriptStartPosition); | 327 RawPtr<Element> scriptElement = m_treeBuilder->takeScriptToProcess(scriptSta
rtPosition); |
| 328 // We will not have a scriptRunner when parsing a DocumentFragment. | 328 // We will not have a scriptRunner when parsing a DocumentFragment. |
| 329 if (m_scriptRunner) | 329 if (m_scriptRunner) |
| 330 m_scriptRunner->execute(scriptElement.release(), scriptStartPosition); | 330 m_scriptRunner->execute(scriptElement.release(), scriptStartPosition); |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool HTMLDocumentParser::canTakeNextToken() | 333 bool HTMLDocumentParser::canTakeNextToken() |
| 334 { | 334 { |
| 335 if (isStopped()) | 335 if (isStopped()) |
| 336 return false; | 336 return false; |
| 337 | 337 |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 | 746 |
| 747 void HTMLDocumentParser::insert(const SegmentedString& source) | 747 void HTMLDocumentParser::insert(const SegmentedString& source) |
| 748 { | 748 { |
| 749 if (isStopped()) | 749 if (isStopped()) |
| 750 return; | 750 return; |
| 751 | 751 |
| 752 TRACE_EVENT1("blink", "HTMLDocumentParser::insert", "source_length", source.
length()); | 752 TRACE_EVENT1("blink", "HTMLDocumentParser::insert", "source_length", source.
length()); |
| 753 | 753 |
| 754 // pumpTokenizer can cause this parser to be detached from the Document, | 754 // pumpTokenizer can cause this parser to be detached from the Document, |
| 755 // but we need to ensure it isn't deleted yet. | 755 // but we need to ensure it isn't deleted yet. |
| 756 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 756 RawPtr<HTMLDocumentParser> protect(this); |
| 757 | 757 |
| 758 if (!m_tokenizer) { | 758 if (!m_tokenizer) { |
| 759 ASSERT(!inPumpSession()); | 759 ASSERT(!inPumpSession()); |
| 760 ASSERT(m_haveBackgroundParser || wasCreatedByScript()); | 760 ASSERT(m_haveBackgroundParser || wasCreatedByScript()); |
| 761 m_token = adoptPtr(new HTMLToken); | 761 m_token = adoptPtr(new HTMLToken); |
| 762 m_tokenizer = HTMLTokenizer::create(m_options); | 762 m_tokenizer = HTMLTokenizer::create(m_options); |
| 763 } | 763 } |
| 764 | 764 |
| 765 SegmentedString excludedLineNumberSource(source); | 765 SegmentedString excludedLineNumberSource(source); |
| 766 excludedLineNumberSource.setExcludeLineNumbers(); | 766 excludedLineNumberSource.setExcludeLineNumbers(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 { | 840 { |
| 841 if (isStopped()) | 841 if (isStopped()) |
| 842 return; | 842 return; |
| 843 | 843 |
| 844 // We should never reach this point if we're using a parser thread, | 844 // We should never reach this point if we're using a parser thread, |
| 845 // as appendBytes() will directly ship the data to the thread. | 845 // as appendBytes() will directly ship the data to the thread. |
| 846 ASSERT(!shouldUseThreading()); | 846 ASSERT(!shouldUseThreading()); |
| 847 | 847 |
| 848 // pumpTokenizer can cause this parser to be detached from the Document, | 848 // pumpTokenizer can cause this parser to be detached from the Document, |
| 849 // but we need to ensure it isn't deleted yet. | 849 // but we need to ensure it isn't deleted yet. |
| 850 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 850 RawPtr<HTMLDocumentParser> protect(this); |
| 851 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentParser::
append", "size", inputSource.length()); | 851 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), "HTMLDocumentParser::
append", "size", inputSource.length()); |
| 852 const SegmentedString source(inputSource); | 852 const SegmentedString source(inputSource); |
| 853 | 853 |
| 854 if (m_preloadScanner) { | 854 if (m_preloadScanner) { |
| 855 if (m_input.current().isEmpty() && !isWaitingForScripts()) { | 855 if (m_input.current().isEmpty() && !isWaitingForScripts()) { |
| 856 // We have parsed until the end of the current input and so are now
moving ahead of the preload scanner. | 856 // We have parsed until the end of the current input and so are now
moving ahead of the preload scanner. |
| 857 // Clear the scanner so we know to scan starting from the current in
put point if we block again. | 857 // Clear the scanner so we know to scan starting from the current in
put point if we block again. |
| 858 m_preloadScanner.clear(); | 858 m_preloadScanner.clear(); |
| 859 } else { | 859 } else { |
| 860 m_preloadScanner->appendToEnd(source); | 860 m_preloadScanner->appendToEnd(source); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 prepareToStopParsing(); | 927 prepareToStopParsing(); |
| 928 } | 928 } |
| 929 | 929 |
| 930 void HTMLDocumentParser::finish() | 930 void HTMLDocumentParser::finish() |
| 931 { | 931 { |
| 932 // FIXME: We should ASSERT(!m_parserStopped) here, since it does not | 932 // FIXME: We should ASSERT(!m_parserStopped) here, since it does not |
| 933 // makes sense to call any methods on DocumentParser once it's been stopped. | 933 // makes sense to call any methods on DocumentParser once it's been stopped. |
| 934 // However, FrameLoader::stop calls DocumentParser::finish unconditionally. | 934 // However, FrameLoader::stop calls DocumentParser::finish unconditionally. |
| 935 | 935 |
| 936 // flush may ending up executing arbitrary script, and possibly detach the p
arser. | 936 // flush may ending up executing arbitrary script, and possibly detach the p
arser. |
| 937 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 937 RawPtr<HTMLDocumentParser> protect(this); |
| 938 flush(); | 938 flush(); |
| 939 if (isDetached()) | 939 if (isDetached()) |
| 940 return; | 940 return; |
| 941 | 941 |
| 942 // Empty documents never got an append() call, and thus have never started | 942 // Empty documents never got an append() call, and thus have never started |
| 943 // a background parser. In those cases, we ignore shouldUseThreading() | 943 // a background parser. In those cases, we ignore shouldUseThreading() |
| 944 // and fall through to the non-threading case. | 944 // and fall through to the non-threading case. |
| 945 if (m_haveBackgroundParser) { | 945 if (m_haveBackgroundParser) { |
| 946 if (!m_input.haveSeenEndOfFile()) | 946 if (!m_input.haveSeenEndOfFile()) |
| 947 m_input.closeWithoutMarkingEndOfFile(); | 947 m_input.closeWithoutMarkingEndOfFile(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 void HTMLDocumentParser::resumeParsingAfterScriptExecution() | 1018 void HTMLDocumentParser::resumeParsingAfterScriptExecution() |
| 1019 { | 1019 { |
| 1020 ASSERT(!isExecutingScript()); | 1020 ASSERT(!isExecutingScript()); |
| 1021 ASSERT(!isWaitingForScripts()); | 1021 ASSERT(!isWaitingForScripts()); |
| 1022 | 1022 |
| 1023 if (m_haveBackgroundParser) { | 1023 if (m_haveBackgroundParser) { |
| 1024 validateSpeculations(m_lastChunkBeforeScript.release()); | 1024 validateSpeculations(m_lastChunkBeforeScript.release()); |
| 1025 ASSERT(!m_lastChunkBeforeScript); | 1025 ASSERT(!m_lastChunkBeforeScript); |
| 1026 // processParsedChunkFromBackgroundParser can cause this parser to be de
tached from the Document, | 1026 // processParsedChunkFromBackgroundParser can cause this parser to be de
tached from the Document, |
| 1027 // but we need to ensure it isn't deleted yet. | 1027 // but we need to ensure it isn't deleted yet. |
| 1028 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 1028 RawPtr<HTMLDocumentParser> protect(this); |
| 1029 pumpPendingSpeculations(); | 1029 pumpPendingSpeculations(); |
| 1030 return; | 1030 return; |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 m_insertionPreloadScanner.clear(); | 1033 m_insertionPreloadScanner.clear(); |
| 1034 pumpTokenizerIfPossible(); | 1034 pumpTokenizerIfPossible(); |
| 1035 endIfDelayed(); | 1035 endIfDelayed(); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan() | 1038 void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan() |
| 1039 { | 1039 { |
| 1040 ASSERT(m_preloadScanner); | 1040 ASSERT(m_preloadScanner); |
| 1041 m_preloadScanner->appendToEnd(m_input.current()); | 1041 m_preloadScanner->appendToEnd(m_input.current()); |
| 1042 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); | 1042 m_preloadScanner->scan(m_preloader.get(), document()->baseElementURL()); |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 void HTMLDocumentParser::notifyScriptLoaded(Resource* cachedResource) | 1045 void HTMLDocumentParser::notifyScriptLoaded(Resource* cachedResource) |
| 1046 { | 1046 { |
| 1047 // pumpTokenizer can cause this parser to be detached from the Document, | 1047 // pumpTokenizer can cause this parser to be detached from the Document, |
| 1048 // but we need to ensure it isn't deleted yet. | 1048 // but we need to ensure it isn't deleted yet. |
| 1049 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 1049 RawPtr<HTMLDocumentParser> protect(this); |
| 1050 | 1050 |
| 1051 ASSERT(m_scriptRunner); | 1051 ASSERT(m_scriptRunner); |
| 1052 ASSERT(!isExecutingScript()); | 1052 ASSERT(!isExecutingScript()); |
| 1053 | 1053 |
| 1054 if (isStopped()) { | 1054 if (isStopped()) { |
| 1055 return; | 1055 return; |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 if (isStopping()) { | 1058 if (isStopping()) { |
| 1059 attemptToRunDeferredScriptsAndEnd(); | 1059 attemptToRunDeferredScriptsAndEnd(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1071 // so this will not be called in the DocumentFragment case. | 1071 // so this will not be called in the DocumentFragment case. |
| 1072 ASSERT(m_scriptRunner); | 1072 ASSERT(m_scriptRunner); |
| 1073 // Ignore calls unless we have a script blocking the parser waiting on a | 1073 // Ignore calls unless we have a script blocking the parser waiting on a |
| 1074 // stylesheet load. Otherwise we are currently parsing and this | 1074 // stylesheet load. Otherwise we are currently parsing and this |
| 1075 // is a re-entrant call from encountering a </ style> tag. | 1075 // is a re-entrant call from encountering a </ style> tag. |
| 1076 if (!m_scriptRunner->hasScriptsWaitingForResources()) | 1076 if (!m_scriptRunner->hasScriptsWaitingForResources()) |
| 1077 return; | 1077 return; |
| 1078 | 1078 |
| 1079 // pumpTokenizer can cause this parser to be detached from the Document, | 1079 // pumpTokenizer can cause this parser to be detached from the Document, |
| 1080 // but we need to ensure it isn't deleted yet. | 1080 // but we need to ensure it isn't deleted yet. |
| 1081 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | 1081 RawPtr<HTMLDocumentParser> protect(this); |
| 1082 m_scriptRunner->executeScriptsWaitingForResources(); | 1082 m_scriptRunner->executeScriptsWaitingForResources(); |
| 1083 if (!isWaitingForScripts()) | 1083 if (!isWaitingForScripts()) |
| 1084 resumeParsingAfterScriptExecution(); | 1084 resumeParsingAfterScriptExecution(); |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 void HTMLDocumentParser::parseDocumentFragment(const String& source, DocumentFra
gment* fragment, Element* contextElement, ParserContentPolicy parserContentPolic
y) | 1087 void HTMLDocumentParser::parseDocumentFragment(const String& source, DocumentFra
gment* fragment, Element* contextElement, ParserContentPolicy parserContentPolic
y) |
| 1088 { | 1088 { |
| 1089 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f
ragment, contextElement, parserContentPolicy); | 1089 RawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(fragment, con
textElement, parserContentPolicy); |
| 1090 parser->append(source); | 1090 parser->append(source); |
| 1091 parser->finish(); | 1091 parser->finish(); |
| 1092 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/
3963151> | 1092 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/
3963151> |
| 1093 parser->detach(); // Allows ~DocumentParser to assert it was detached before
destruction. | 1093 parser->detach(); // Allows ~DocumentParser to assert it was detached before
destruction. |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 void HTMLDocumentParser::suspendScheduledTasks() | 1096 void HTMLDocumentParser::suspendScheduledTasks() |
| 1097 { | 1097 { |
| 1098 ASSERT(!m_tasksWereSuspended); | 1098 ASSERT(!m_tasksWereSuspended); |
| 1099 m_tasksWereSuspended = true; | 1099 m_tasksWereSuspended = true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1155 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| 1156 { | 1156 { |
| 1157 ASSERT(decoder); | 1157 ASSERT(decoder); |
| 1158 DecodedDataDocumentParser::setDecoder(decoder); | 1158 DecodedDataDocumentParser::setDecoder(decoder); |
| 1159 | 1159 |
| 1160 if (m_haveBackgroundParser) | 1160 if (m_haveBackgroundParser) |
| 1161 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); | 1161 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 } // namespace blink | 1164 } // namespace blink |
| OLD | NEW |