OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights |
6 * reserved. | 6 * reserved. |
7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 #include "wtf/text/StringHash.h" | 59 #include "wtf/text/StringHash.h" |
60 | 60 |
61 namespace blink { | 61 namespace blink { |
62 | 62 |
63 ScriptLoader::ScriptLoader(Element* element, | 63 ScriptLoader::ScriptLoader(Element* element, |
64 bool parserInserted, | 64 bool parserInserted, |
65 bool alreadyStarted, | 65 bool alreadyStarted, |
66 bool createdDuringDocumentWrite) | 66 bool createdDuringDocumentWrite) |
67 : m_element(element), | 67 : m_element(element), |
68 m_startLineNumber(WTF::OrdinalNumber::beforeFirst()), | 68 m_startLineNumber(WTF::OrdinalNumber::beforeFirst()), |
69 | |
70 // https://html.spec.whatwg.org/#already-started | |
71 // "Initially, script elements must have this flag unset" | |
72 // "The cloning steps for script elements must set the "already started" | |
73 // flag on the copy if it is set on the element being cloned." | |
kouhei (in TOK)
2017/02/13 21:31:08
My understanding is that cloning steps are impleme
hiroshige
2017/02/13 21:46:52
Agree. Added TODO.
| |
74 m_alreadyStarted(alreadyStarted), | |
75 | |
76 // https://html.spec.whatwg.org/#parser-inserted | |
77 // "Initially, script elements must have this flag unset." | |
78 // "It is set by the HTML parser and the XML parser on script elements | |
79 // they insert" | |
69 m_parserInserted(parserInserted), | 80 m_parserInserted(parserInserted), |
81 | |
82 // https://html.spec.whatwg.org/#non-blocking | |
83 // "Initially, script elements must have this flag set." | |
84 // "It is unset by the HTML parser and the XML parser on script | |
85 // elements they insert. | |
86 m_nonBlocking(!parserInserted), | |
87 | |
70 m_isExternalScript(false), | 88 m_isExternalScript(false), |
71 m_alreadyStarted(alreadyStarted), | |
72 m_haveFiredLoad(false), | 89 m_haveFiredLoad(false), |
73 m_willBeParserExecuted(false), | 90 m_willBeParserExecuted(false), |
74 m_readyToBeParserExecuted(false), | |
75 m_willExecuteWhenDocumentFinishedParsing(false), | 91 m_willExecuteWhenDocumentFinishedParsing(false), |
76 m_forceAsync(!parserInserted), | |
77 m_createdDuringDocumentWrite(createdDuringDocumentWrite), | 92 m_createdDuringDocumentWrite(createdDuringDocumentWrite), |
78 m_asyncExecType(ScriptRunner::None), | 93 m_asyncExecType(ScriptRunner::None), |
79 m_documentWriteIntervention( | 94 m_documentWriteIntervention( |
80 DocumentWriteIntervention::DocumentWriteInterventionNone) { | 95 DocumentWriteIntervention::DocumentWriteInterventionNone) { |
81 DCHECK(m_element); | 96 DCHECK(m_element); |
82 if (parserInserted && element->document().scriptableDocumentParser() && | 97 if (parserInserted && element->document().scriptableDocumentParser() && |
83 !element->document().isInDocumentWrite()) | 98 !element->document().isInDocumentWrite()) |
84 m_startLineNumber = | 99 m_startLineNumber = |
85 element->document().scriptableDocumentParser()->lineNumber(); | 100 element->document().scriptableDocumentParser()->lineNumber(); |
86 } | 101 } |
(...skipping 24 matching lines...) Expand all Loading... | |
111 } | 126 } |
112 | 127 |
113 void ScriptLoader::handleSourceAttribute(const String& sourceUrl) { | 128 void ScriptLoader::handleSourceAttribute(const String& sourceUrl) { |
114 if (ignoresLoadRequest() || sourceUrl.isEmpty()) | 129 if (ignoresLoadRequest() || sourceUrl.isEmpty()) |
115 return; | 130 return; |
116 | 131 |
117 prepareScript(); // FIXME: Provide a real starting line number here. | 132 prepareScript(); // FIXME: Provide a real starting line number here. |
118 } | 133 } |
119 | 134 |
120 void ScriptLoader::handleAsyncAttribute() { | 135 void ScriptLoader::handleAsyncAttribute() { |
121 m_forceAsync = false; | 136 // https://html.spec.whatwg.org/#non-blocking |
137 // "In addition, whenever a script element whose "non-blocking" flag is set | |
138 // has an async content attribute added, the element's "non-blocking" flag | |
139 // must be unset." | |
140 m_nonBlocking = false; | |
122 } | 141 } |
123 | 142 |
124 void ScriptLoader::detach() { | 143 void ScriptLoader::detach() { |
125 if (!m_pendingScript) | 144 if (!m_pendingScript) |
126 return; | 145 return; |
127 m_pendingScript->dispose(); | 146 m_pendingScript->dispose(); |
128 m_pendingScript = nullptr; | 147 m_pendingScript = nullptr; |
129 } | 148 } |
130 | 149 |
131 static bool isLegacySupportedJavaScriptLanguage(const String& language) { | 150 static bool isLegacySupportedJavaScriptLanguage(const String& language) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 | 228 |
210 bool wasParserInserted; | 229 bool wasParserInserted; |
211 if (m_parserInserted) { | 230 if (m_parserInserted) { |
212 wasParserInserted = true; | 231 wasParserInserted = true; |
213 m_parserInserted = false; | 232 m_parserInserted = false; |
214 } else { | 233 } else { |
215 wasParserInserted = false; | 234 wasParserInserted = false; |
216 } | 235 } |
217 | 236 |
218 if (wasParserInserted && !client->asyncAttributeValue()) | 237 if (wasParserInserted && !client->asyncAttributeValue()) |
219 m_forceAsync = true; | 238 m_nonBlocking = true; |
220 | 239 |
221 // FIXME: HTML5 spec says we should check that all children are either | 240 // FIXME: HTML5 spec says we should check that all children are either |
222 // comments or empty text nodes. | 241 // comments or empty text nodes. |
223 if (!client->hasSourceAttribute() && !m_element->hasChildren()) | 242 if (!client->hasSourceAttribute() && !m_element->hasChildren()) |
224 return false; | 243 return false; |
225 | 244 |
226 if (!m_element->isConnected()) | 245 if (!m_element->isConnected()) |
227 return false; | 246 return false; |
228 | 247 |
229 if (!isScriptTypeSupported(supportLegacyTypes)) | 248 if (!isScriptTypeSupported(supportLegacyTypes)) |
230 return false; | 249 return false; |
231 | 250 |
232 if (wasParserInserted) { | 251 if (wasParserInserted) { |
233 m_parserInserted = true; | 252 m_parserInserted = true; |
234 m_forceAsync = false; | 253 m_nonBlocking = false; |
235 } | 254 } |
236 | 255 |
237 m_alreadyStarted = true; | 256 m_alreadyStarted = true; |
238 | 257 |
239 // FIXME: If script is parser inserted, verify it's still in the original | 258 // FIXME: If script is parser inserted, verify it's still in the original |
240 // document. | 259 // document. |
241 Document& elementDocument = m_element->document(); | 260 Document& elementDocument = m_element->document(); |
242 Document* contextDocument = elementDocument.contextDocument(); | 261 Document* contextDocument = elementDocument.contextDocument(); |
243 | 262 |
244 if (!contextDocument || !contextDocument->allowExecutingScripts(m_element)) | 263 if (!contextDocument || !contextDocument->allowExecutingScripts(m_element)) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 m_willExecuteWhenDocumentFinishedParsing = true; | 299 m_willExecuteWhenDocumentFinishedParsing = true; |
281 m_willBeParserExecuted = true; | 300 m_willBeParserExecuted = true; |
282 } else if (client->hasSourceAttribute() && m_parserInserted && | 301 } else if (client->hasSourceAttribute() && m_parserInserted && |
283 !client->asyncAttributeValue()) { | 302 !client->asyncAttributeValue()) { |
284 m_willBeParserExecuted = true; | 303 m_willBeParserExecuted = true; |
285 } else if (!client->hasSourceAttribute() && m_parserInserted && | 304 } else if (!client->hasSourceAttribute() && m_parserInserted && |
286 !elementDocument.isScriptExecutionReady()) { | 305 !elementDocument.isScriptExecutionReady()) { |
287 m_willBeParserExecuted = true; | 306 m_willBeParserExecuted = true; |
288 m_readyToBeParserExecuted = true; | 307 m_readyToBeParserExecuted = true; |
289 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && | 308 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && |
290 !m_forceAsync) { | 309 !m_nonBlocking) { |
291 m_pendingScript = PendingScript::create(m_element, m_resource.get()); | 310 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
292 m_asyncExecType = ScriptRunner::InOrder; | 311 m_asyncExecType = ScriptRunner::InOrder; |
293 contextDocument->scriptRunner()->queueScriptForExecution(this, | 312 contextDocument->scriptRunner()->queueScriptForExecution(this, |
294 m_asyncExecType); | 313 m_asyncExecType); |
295 // Note that watchForLoad can immediately call pendingScriptFinished. | 314 // Note that watchForLoad can immediately call pendingScriptFinished. |
296 m_pendingScript->watchForLoad(this); | 315 m_pendingScript->watchForLoad(this); |
297 } else if (client->hasSourceAttribute()) { | 316 } else if (client->hasSourceAttribute()) { |
298 m_pendingScript = PendingScript::create(m_element, m_resource.get()); | 317 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
299 m_asyncExecType = ScriptRunner::Async; | 318 m_asyncExecType = ScriptRunner::Async; |
300 LocalFrame* frame = m_element->document().frame(); | 319 LocalFrame* frame = m_element->document().frame(); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
644 if (isHTMLScriptLoader(element)) | 663 if (isHTMLScriptLoader(element)) |
645 return toHTMLScriptElement(element)->loader(); | 664 return toHTMLScriptElement(element)->loader(); |
646 | 665 |
647 if (isSVGScriptLoader(element)) | 666 if (isSVGScriptLoader(element)) |
648 return toSVGScriptElement(element)->loader(); | 667 return toSVGScriptElement(element)->loader(); |
649 | 668 |
650 return 0; | 669 return 0; |
651 } | 670 } |
652 | 671 |
653 } // namespace blink | 672 } // namespace blink |
OLD | NEW |