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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 return Event::create(EventTypeNames::load); | 102 return Event::create(EventTypeNames::load); |
103 } | 103 } |
104 | 104 |
105 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) | 105 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) |
106 { | 106 { |
107 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); | 107 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); |
108 if (m_hasScriptsWaitingForResources) | 108 if (m_hasScriptsWaitingForResources) |
109 return false; | 109 return false; |
110 if (script.resource() && !script.resource()->isLoaded()) | 110 if (script.resource() && !script.resource()->isLoaded()) |
111 return false; | 111 return false; |
112 if (script.isStreaming()) | |
113 return false; | |
112 return true; | 114 return true; |
113 } | 115 } |
114 | 116 |
115 void HTMLScriptRunner::executeParsingBlockingScript() | 117 void HTMLScriptRunner::executeParsingBlockingScript() |
116 { | 118 { |
117 ASSERT(m_document); | 119 ASSERT(m_document); |
118 ASSERT(!isExecutingScript()); | 120 ASSERT(!isExecutingScript()); |
119 ASSERT(m_document->isScriptExecutionReady()); | 121 ASSERT(m_document->isScriptExecutionReady()); |
120 ASSERT(isPendingScriptReady(m_parserBlockingScript)); | 122 ASSERT(isPendingScriptReady(m_parserBlockingScript)); |
121 | 123 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 const double epsilon = 1; | 162 const double epsilon = 1; |
161 if (pendingScriptType == PendingScriptBlockingParser && !m_parserBlockingScr iptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsilon) { | 163 if (pendingScriptType == PendingScriptBlockingParser && !m_parserBlockingScr iptAlreadyLoaded && compilationFinishTime > epsilon && loadFinishTime > epsilon) { |
162 blink::Platform::current()->histogramCustomCounts("WebCore.Scripts.Parsi ngBlocking.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTim e) * 1000, 0, 10000, 50); | 164 blink::Platform::current()->histogramCustomCounts("WebCore.Scripts.Parsi ngBlocking.TimeBetweenLoadedAndCompiled", (compilationFinishTime - loadFinishTim e) * 1000, 0, 10000, 50); |
163 } | 165 } |
164 | 166 |
165 ASSERT(!isExecutingScript()); | 167 ASSERT(!isExecutingScript()); |
166 } | 168 } |
167 | 169 |
168 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | 170 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
169 { | 171 { |
172 // For a parser-blocking script, this function should be called only when | |
173 // the streaming is complete. | |
174 ASSERT(!(m_parserBlockingScript.resource() == cachedResource | |
175 && m_parserBlockingScript.isStreaming())); | |
170 m_host->notifyScriptLoaded(cachedResource); | 176 m_host->notifyScriptLoaded(cachedResource); |
171 } | 177 } |
172 | 178 |
173 // Implements the steps for 'An end tag whose tag name is "script"' | 179 // Implements the steps for 'An end tag whose tag name is "script"' |
174 // http://whatwg.org/html#scriptEndTag | 180 // http://whatwg.org/html#scriptEndTag |
175 // Script handling lives outside the tree builder to keep each class simple. | 181 // Script handling lives outside the tree builder to keep each class simple. |
176 void HTMLScriptRunner::execute(PassRefPtrWillBeRawPtr<Element> scriptElement, co nst TextPosition& scriptStartPosition) | 182 void HTMLScriptRunner::execute(PassRefPtrWillBeRawPtr<Element> scriptElement, co nst TextPosition& scriptStartPosition) |
177 { | 183 { |
178 ASSERT(scriptElement); | 184 ASSERT(scriptElement); |
179 // FIXME: If scripting is disabled, always just return. | 185 // FIXME: If scripting is disabled, always just return. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 if (!requestPendingScript(m_parserBlockingScript, element)) | 254 if (!requestPendingScript(m_parserBlockingScript, element)) |
249 return; | 255 return; |
250 | 256 |
251 ASSERT(m_parserBlockingScript.resource()); | 257 ASSERT(m_parserBlockingScript.resource()); |
252 | 258 |
253 m_parserBlockingScriptAlreadyLoaded = m_parserBlockingScript.resource()->isL oaded(); | 259 m_parserBlockingScriptAlreadyLoaded = m_parserBlockingScript.resource()->isL oaded(); |
254 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.ParsingBlo cking.AlreadyLoaded", m_parserBlockingScriptAlreadyLoaded ? 1 : 0, 2); | 260 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.ParsingBlo cking.AlreadyLoaded", m_parserBlockingScriptAlreadyLoaded ? 1 : 0, 2); |
255 // We only care about a load callback if resource is not already | 261 // We only care about a load callback if resource is not already |
256 // in the cache. Callers will attempt to run the m_parserBlockingScript | 262 // in the cache. Callers will attempt to run the m_parserBlockingScript |
257 // if possible before returning control to the parser. | 263 // if possible before returning control to the parser. |
258 if (!m_parserBlockingScriptAlreadyLoaded) | 264 if (!m_parserBlockingScriptAlreadyLoaded) { |
265 bool startedStreaming = ScriptStreamer::startStreaming(m_parserBlockingS cript, m_document->frame()->settings(), ScriptState::forMainWorld(m_document->f rame())); | |
266 blink::Platform::current()->histogramEnumeration("WebCore.Scripts.Parsin gBlocking.StartedStreaming", startedStreaming ? 1 : 0, 2); | |
haraken
2014/09/11 16:12:30
Did you already land a chromium side change?
marja
2014/09/15 17:45:27
No, but I can land this before it without problems
| |
259 m_parserBlockingScript.watchForLoad(this); | 267 m_parserBlockingScript.watchForLoad(this); |
268 } | |
260 } | 269 } |
261 | 270 |
262 void HTMLScriptRunner::requestDeferredScript(Element* element) | 271 void HTMLScriptRunner::requestDeferredScript(Element* element) |
263 { | 272 { |
264 PendingScript pendingScript; | 273 PendingScript pendingScript; |
265 if (!requestPendingScript(pendingScript, element)) | 274 if (!requestPendingScript(pendingScript, element)) |
266 return; | 275 return; |
267 | 276 |
268 ASSERT(pendingScript.resource()); | 277 ASSERT(pendingScript.resource()); |
269 m_scriptsToExecuteAfterParsing.append(pendingScript); | 278 m_scriptsToExecuteAfterParsing.append(pendingScript); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 | 316 |
308 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 317 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
309 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 318 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
310 | 319 |
311 scriptLoader->prepareScript(scriptStartPosition); | 320 scriptLoader->prepareScript(scriptStartPosition); |
312 | 321 |
313 if (!scriptLoader->willBeParserExecuted()) | 322 if (!scriptLoader->willBeParserExecuted()) |
314 return; | 323 return; |
315 | 324 |
316 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { | 325 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { |
326 // FIXME: in addition to parser blocking scripts, stream also | |
327 // scripts which are not parser blocking. | |
317 requestDeferredScript(script); | 328 requestDeferredScript(script); |
318 } else if (scriptLoader->readyToBeParserExecuted()) { | 329 } else if (scriptLoader->readyToBeParserExecuted()) { |
319 if (m_scriptNestingLevel == 1) { | 330 if (m_scriptNestingLevel == 1) { |
320 m_parserBlockingScript.setElement(script); | 331 m_parserBlockingScript.setElement(script); |
321 m_parserBlockingScript.setStartingPosition(scriptStartPosition); | 332 m_parserBlockingScript.setStartingPosition(scriptStartPosition); |
322 } else { | 333 } else { |
323 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); | 334 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); |
324 scriptLoader->executeScript(sourceCode); | 335 scriptLoader->executeScript(sourceCode); |
325 } | 336 } |
326 } else { | 337 } else { |
327 requestParsingBlockingScript(script); | 338 requestParsingBlockingScript(script); |
328 } | 339 } |
329 } | 340 } |
330 } | 341 } |
331 | 342 |
332 void HTMLScriptRunner::trace(Visitor* visitor) | 343 void HTMLScriptRunner::trace(Visitor* visitor) |
333 { | 344 { |
334 visitor->trace(m_document); | 345 visitor->trace(m_document); |
335 visitor->trace(m_host); | 346 visitor->trace(m_host); |
336 visitor->trace(m_parserBlockingScript); | 347 visitor->trace(m_parserBlockingScript); |
337 visitor->trace(m_scriptsToExecuteAfterParsing); | 348 visitor->trace(m_scriptsToExecuteAfterParsing); |
338 } | 349 } |
339 | 350 |
340 } | 351 } |
OLD | NEW |