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 30 matching lines...) Expand all Loading... |
41 #include "core/platform/NotImplemented.h" | 41 #include "core/platform/NotImplemented.h" |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 using namespace HTMLNames; | 45 using namespace HTMLNames; |
46 | 46 |
47 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos
t) | 47 HTMLScriptRunner::HTMLScriptRunner(Document* document, HTMLScriptRunnerHost* hos
t) |
48 : m_document(document) | 48 : m_document(document) |
49 , m_host(host) | 49 , m_host(host) |
50 , m_scriptNestingLevel(0) | 50 , m_scriptNestingLevel(0) |
51 , m_hasScriptsWaitingForStylesheets(false) | 51 , m_hasScriptsWaitingForResources(false) |
52 { | 52 { |
53 ASSERT(m_host); | 53 ASSERT(m_host); |
54 } | 54 } |
55 | 55 |
56 HTMLScriptRunner::~HTMLScriptRunner() | 56 HTMLScriptRunner::~HTMLScriptRunner() |
57 { | 57 { |
58 // FIXME: Should we be passed a "done loading/parsing" callback sooner than
destruction? | 58 // FIXME: Should we be passed a "done loading/parsing" callback sooner than
destruction? |
59 if (m_parserBlockingScript.cachedScript() && m_parserBlockingScript.watching
ForLoad()) | 59 if (m_parserBlockingScript.cachedScript() && m_parserBlockingScript.watching
ForLoad()) |
60 stopWatchingForLoad(m_parserBlockingScript); | 60 stopWatchingForLoad(m_parserBlockingScript); |
61 | 61 |
(...skipping 29 matching lines...) Expand all Loading... |
91 errorOccurred = script.cachedScript()->errorOccurred(); | 91 errorOccurred = script.cachedScript()->errorOccurred(); |
92 ASSERT(script.cachedScript()->isLoaded()); | 92 ASSERT(script.cachedScript()->isLoaded()); |
93 return ScriptSourceCode(script.cachedScript()); | 93 return ScriptSourceCode(script.cachedScript()); |
94 } | 94 } |
95 errorOccurred = false; | 95 errorOccurred = false; |
96 return ScriptSourceCode(script.element()->textContent(), documentURLForScrip
tExecution(m_document), script.startingPosition()); | 96 return ScriptSourceCode(script.element()->textContent(), documentURLForScrip
tExecution(m_document), script.startingPosition()); |
97 } | 97 } |
98 | 98 |
99 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) | 99 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) |
100 { | 100 { |
101 m_hasScriptsWaitingForStylesheets = !m_document->haveStylesheetsLoaded(); | 101 m_hasScriptsWaitingForResources = !m_document->haveStylesheetsAndImportsLoad
ed(); |
102 if (m_hasScriptsWaitingForStylesheets) | 102 if (m_hasScriptsWaitingForResources) |
103 return false; | 103 return false; |
104 if (script.cachedScript() && !script.cachedScript()->isLoaded()) | 104 if (script.cachedScript() && !script.cachedScript()->isLoaded()) |
105 return false; | 105 return false; |
106 return true; | 106 return true; |
107 } | 107 } |
108 | 108 |
109 void HTMLScriptRunner::executeParsingBlockingScript() | 109 void HTMLScriptRunner::executeParsingBlockingScript() |
110 { | 110 { |
111 ASSERT(m_document); | 111 ASSERT(m_document); |
112 ASSERT(!isExecutingScript()); | 112 ASSERT(!isExecutingScript()); |
113 ASSERT(m_document->haveStylesheetsLoaded()); | 113 ASSERT(m_document->haveStylesheetsAndImportsLoaded()); |
114 ASSERT(isPendingScriptReady(m_parserBlockingScript)); | 114 ASSERT(isPendingScriptReady(m_parserBlockingScript)); |
115 | 115 |
116 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 116 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
117 executePendingScriptAndDispatchEvent(m_parserBlockingScript); | 117 executePendingScriptAndDispatchEvent(m_parserBlockingScript); |
118 } | 118 } |
119 | 119 |
120 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
ngScript) | 120 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
ngScript) |
121 { | 121 { |
122 bool errorOccurred = false; | 122 bool errorOccurred = false; |
123 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc
curred); | 123 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc
curred); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 void HTMLScriptRunner::executeScriptsWaitingForLoad(CachedResource* cachedScript
) | 197 void HTMLScriptRunner::executeScriptsWaitingForLoad(CachedResource* cachedScript
) |
198 { | 198 { |
199 ASSERT(!isExecutingScript()); | 199 ASSERT(!isExecutingScript()); |
200 ASSERT(hasParserBlockingScript()); | 200 ASSERT(hasParserBlockingScript()); |
201 ASSERT_UNUSED(cachedScript, m_parserBlockingScript.cachedScript() == cachedS
cript); | 201 ASSERT_UNUSED(cachedScript, m_parserBlockingScript.cachedScript() == cachedS
cript); |
202 ASSERT(m_parserBlockingScript.cachedScript()->isLoaded()); | 202 ASSERT(m_parserBlockingScript.cachedScript()->isLoaded()); |
203 executeParsingBlockingScripts(); | 203 executeParsingBlockingScripts(); |
204 } | 204 } |
205 | 205 |
206 void HTMLScriptRunner::executeScriptsWaitingForStylesheets() | 206 void HTMLScriptRunner::executeScriptsWaitingForResources() |
207 { | 207 { |
208 ASSERT(m_document); | 208 ASSERT(m_document); |
209 // Callers should check hasScriptsWaitingForStylesheets() before calling | 209 // Callers should check hasScriptsWaitingForResources() before calling |
210 // to prevent parser or script re-entry during </style> parsing. | 210 // to prevent parser or script re-entry during </style> parsing. |
211 ASSERT(hasScriptsWaitingForStylesheets()); | 211 ASSERT(hasScriptsWaitingForResources()); |
212 ASSERT(!isExecutingScript()); | 212 ASSERT(!isExecutingScript()); |
213 ASSERT(m_document->haveStylesheetsLoaded()); | 213 ASSERT(m_document->haveStylesheetsAndImportsLoaded()); |
214 executeParsingBlockingScripts(); | 214 executeParsingBlockingScripts(); |
215 } | 215 } |
216 | 216 |
217 bool HTMLScriptRunner::executeScriptsWaitingForParsing() | 217 bool HTMLScriptRunner::executeScriptsWaitingForParsing() |
218 { | 218 { |
219 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 219 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
220 ASSERT(!isExecutingScript()); | 220 ASSERT(!isExecutingScript()); |
221 ASSERT(!hasParserBlockingScript()); | 221 ASSERT(!hasParserBlockingScript()); |
222 ASSERT(m_scriptsToExecuteAfterParsing.first().cachedScript()); | 222 ASSERT(m_scriptsToExecuteAfterParsing.first().cachedScript()); |
223 if (!m_scriptsToExecuteAfterParsing.first().cachedScript()->isLoaded())
{ | 223 if (!m_scriptsToExecuteAfterParsing.first().cachedScript()->isLoaded())
{ |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } else { | 314 } else { |
315 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); | 315 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); |
316 scriptElement->executeScript(sourceCode); | 316 scriptElement->executeScript(sourceCode); |
317 } | 317 } |
318 } else | 318 } else |
319 requestParsingBlockingScript(script); | 319 requestParsingBlockingScript(script); |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
323 } | 323 } |
OLD | NEW |