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

Side by Side Diff: sky/engine/core/html/parser/BackgroundHTMLParser.cpp

Issue 934083002: Remove the concept of pendingScripts from HTMLScriptRunner (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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) 2013 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2013 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 pumpTokenizer(); 106 pumpTokenizer();
107 } 107 }
108 108
109 void BackgroundHTMLParser::markEndOfFile() 109 void BackgroundHTMLParser::markEndOfFile()
110 { 110 {
111 ASSERT(!m_input.isClosed()); 111 ASSERT(!m_input.isClosed());
112 m_input.append(SegmentedString(String(&kEndOfFileMarker, 1))); 112 m_input.append(SegmentedString(String(&kEndOfFileMarker, 1)));
113 m_input.close(); 113 m_input.close();
114 } 114 }
115 115
116 bool BackgroundHTMLParser::updateTokenizerState(const CompactHTMLToken& token) 116 BackgroundHTMLParser::ContinueBehavior BackgroundHTMLParser::updateTokenizerStat e(const CompactHTMLToken& lastToken)
117 { 117 {
118 if (token.type() == HTMLToken::StartTag) { 118 if (lastToken.type() == HTMLToken::StartTag) {
119 const String& tagName = token.data(); 119 const String& tagName = lastToken.data();
120 120
121 if (threadSafeMatch(tagName, HTMLNames::scriptTag) || threadSafeMatch(ta gName, HTMLNames::styleTag)) 121 if (threadSafeMatch(tagName, HTMLNames::scriptTag) || threadSafeMatch(ta gName, HTMLNames::styleTag))
122 m_tokenizer->setState(HTMLTokenizer::RawDataState); 122 m_tokenizer->setState(HTMLTokenizer::RawDataState);
123 123
124 if (threadSafeMatch(tagName, HTMLNames::importTag)) { 124 if (threadSafeMatch(tagName, HTMLNames::importTag)) {
125 m_state = DidSeeImportState; 125 m_state = DidSeeImportState;
126 return true; 126 return ContinueParsing;
127 } 127 }
128 128
129 if (m_state == InitialState) 129 if (m_state == InitialState)
130 return true; 130 return ContinueParsing;
131 131
132 // If we hit a start tag which is not an <import> tag while in the
133 // have-seen-import state, we need to send all but the last token.
134 // This lets the main thread see all import tags in one chunk.
135 // TODO(eseidel): We could replace this with a preloader and then
136 // simply yield after every </import> regardless.
132 m_state = InitialState; 137 m_state = InitialState;
133 return false; 138 return SendTokensExceptingLast;
134 } 139 }
135 140
136 return token.type() != HTMLToken::EndTag || !threadSafeMatch(token.data(), H TMLNames::scriptTag); 141 // We send all tokens at the end of every </script>
142 if (lastToken.type() == HTMLToken::EndTag && threadSafeMatch(lastToken.data( ), HTMLNames::scriptTag))
143 return SendTokensIncludingLast;
144
145 return ContinueParsing;
137 } 146 }
138 147
139 void BackgroundHTMLParser::pumpTokenizer() 148 void BackgroundHTMLParser::pumpTokenizer()
140 { 149 {
141 while (true) { 150 while (true) {
142 if (!m_tokenizer->nextToken(m_input, *m_token)) { 151 if (!m_tokenizer->nextToken(m_input, *m_token)) {
143 // We've reached the end of our current input. 152 // We've reached the end of our current input.
144 sendTokensToMainThread(); 153 sendTokensToMainThread();
145 break; 154 break;
146 } 155 }
147 156
157 ContinueBehavior result;
148 { 158 {
149 CompactHTMLToken token(m_token.get(), TextPosition(m_input.currentLi ne(), m_input.currentColumn())); 159 CompactHTMLToken token(m_token.get(), TextPosition(m_input.currentLi ne(), m_input.currentColumn()));
160 result = updateTokenizerState(token);
161 if (result == SendTokensExceptingLast)
162 sendTokensToMainThread();
163
150 m_pendingTokens->append(token); 164 m_pendingTokens->append(token);
151 } 165 }
152 166
153 m_token->clear(); 167 m_token->clear();
154 168
155 if (!updateTokenizerState(m_pendingTokens->last()) || m_pendingTokens->s ize() >= pendingTokenLimit) 169 if (result == SendTokensIncludingLast || m_pendingTokens->size() >= pend ingTokenLimit)
156 sendTokensToMainThread(); 170 sendTokensToMainThread();
157 } 171 }
158 } 172 }
159 173
160 void BackgroundHTMLParser::sendTokensToMainThread() 174 void BackgroundHTMLParser::sendTokensToMainThread()
161 { 175 {
162 if (m_pendingTokens->isEmpty()) 176 if (m_pendingTokens->isEmpty())
163 return; 177 return;
164 178
165 #if ENABLE(ASSERT) 179 #if ENABLE(ASSERT)
166 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get()); 180 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get());
167 #endif 181 #endif
168 182
169 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar ser::ParsedChunk); 183 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar ser::ParsedChunk);
170 chunk->tokens = m_pendingTokens.release(); 184 chunk->tokens = m_pendingTokens.release();
171 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE, 185 Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE,
172 base::Bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParse r, m_parser, chunk.release())); 186 base::Bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParse r, m_parser, chunk.release()));
173 187
174 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); 188 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream);
175 } 189 }
176 190
177 } 191 }
OLDNEW
« no previous file with comments | « sky/engine/core/html/parser/BackgroundHTMLParser.h ('k') | sky/engine/core/html/parser/HTMLDocumentParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698