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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2696653004: [Script Spec Annotation] Annotate and refactor script element's flags (Closed)
Patch Set: More refactor Created 3 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) 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
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 m_parserInserted(parserInserted),
70 m_isExternalScript(false),
71 m_alreadyStarted(alreadyStarted),
72 m_haveFiredLoad(false), 69 m_haveFiredLoad(false),
73 m_willBeParserExecuted(false), 70 m_willBeParserExecuted(false),
74 m_readyToBeParserExecuted(false),
75 m_willExecuteWhenDocumentFinishedParsing(false), 71 m_willExecuteWhenDocumentFinishedParsing(false),
76 m_forceAsync(!parserInserted),
77 m_createdDuringDocumentWrite(createdDuringDocumentWrite), 72 m_createdDuringDocumentWrite(createdDuringDocumentWrite),
78 m_asyncExecType(ScriptRunner::None), 73 m_asyncExecType(ScriptRunner::None),
79 m_documentWriteIntervention( 74 m_documentWriteIntervention(
80 DocumentWriteIntervention::DocumentWriteInterventionNone) { 75 DocumentWriteIntervention::DocumentWriteInterventionNone) {
81 DCHECK(m_element); 76 DCHECK(m_element);
77
78 // https://html.spec.whatwg.org/#already-started
79 // "The cloning steps for script elements must set the "already started"
80 // flag on the copy if it is set on the element being cloned."
81 // TODO(hiroshige): Cloning is implemented together with
82 // {HTML,SVG}ScriptElement::cloneElementWithoutAttributesAndChildren().
83 // Clean up these later.
84 if (alreadyStarted)
85 m_alreadyStarted = true;
86
87 if (parserInserted) {
88 // https://html.spec.whatwg.org/#parser-inserted
89 // "It is set by the HTML parser and the XML parser
90 // on script elements they insert"
91 m_parserInserted = true;
92
93 // https://html.spec.whatwg.org/#non-blocking
94 // "It is unset by the HTML parser and the XML parser
95 // on script elements they insert."
96 m_nonBlocking = false;
97 }
98
82 if (parserInserted && element->document().scriptableDocumentParser() && 99 if (parserInserted && element->document().scriptableDocumentParser() &&
83 !element->document().isInDocumentWrite()) 100 !element->document().isInDocumentWrite())
84 m_startLineNumber = 101 m_startLineNumber =
85 element->document().scriptableDocumentParser()->lineNumber(); 102 element->document().scriptableDocumentParser()->lineNumber();
86 } 103 }
87 104
88 ScriptLoader::~ScriptLoader() {} 105 ScriptLoader::~ScriptLoader() {}
89 106
90 DEFINE_TRACE(ScriptLoader) { 107 DEFINE_TRACE(ScriptLoader) {
91 visitor->trace(m_element); 108 visitor->trace(m_element);
(...skipping 19 matching lines...) Expand all
111 } 128 }
112 129
113 void ScriptLoader::handleSourceAttribute(const String& sourceUrl) { 130 void ScriptLoader::handleSourceAttribute(const String& sourceUrl) {
114 if (ignoresLoadRequest() || sourceUrl.isEmpty()) 131 if (ignoresLoadRequest() || sourceUrl.isEmpty())
115 return; 132 return;
116 133
117 prepareScript(); // FIXME: Provide a real starting line number here. 134 prepareScript(); // FIXME: Provide a real starting line number here.
118 } 135 }
119 136
120 void ScriptLoader::handleAsyncAttribute() { 137 void ScriptLoader::handleAsyncAttribute() {
121 m_forceAsync = false; 138 // https://html.spec.whatwg.org/#non-blocking
139 // "In addition, whenever a script element whose "non-blocking" flag is set
140 // has an async content attribute added, the element's "non-blocking" flag
141 // must be unset."
142 m_nonBlocking = false;
122 } 143 }
123 144
124 void ScriptLoader::detach() { 145 void ScriptLoader::detach() {
125 if (!m_pendingScript) 146 if (!m_pendingScript)
126 return; 147 return;
127 m_pendingScript->dispose(); 148 m_pendingScript->dispose();
128 m_pendingScript = nullptr; 149 m_pendingScript = nullptr;
129 } 150 }
130 151
131 static bool isLegacySupportedJavaScriptLanguage(const String& language) { 152 static bool isLegacySupportedJavaScriptLanguage(const String& language) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 230
210 bool wasParserInserted; 231 bool wasParserInserted;
211 if (m_parserInserted) { 232 if (m_parserInserted) {
212 wasParserInserted = true; 233 wasParserInserted = true;
213 m_parserInserted = false; 234 m_parserInserted = false;
214 } else { 235 } else {
215 wasParserInserted = false; 236 wasParserInserted = false;
216 } 237 }
217 238
218 if (wasParserInserted && !client->asyncAttributeValue()) 239 if (wasParserInserted && !client->asyncAttributeValue())
219 m_forceAsync = true; 240 m_nonBlocking = true;
220 241
221 // FIXME: HTML5 spec says we should check that all children are either 242 // FIXME: HTML5 spec says we should check that all children are either
222 // comments or empty text nodes. 243 // comments or empty text nodes.
223 if (!client->hasSourceAttribute() && !m_element->hasChildren()) 244 if (!client->hasSourceAttribute() && !m_element->hasChildren())
224 return false; 245 return false;
225 246
226 if (!m_element->isConnected()) 247 if (!m_element->isConnected())
227 return false; 248 return false;
228 249
229 if (!isScriptTypeSupported(supportLegacyTypes)) 250 if (!isScriptTypeSupported(supportLegacyTypes))
230 return false; 251 return false;
231 252
232 if (wasParserInserted) { 253 if (wasParserInserted) {
233 m_parserInserted = true; 254 m_parserInserted = true;
234 m_forceAsync = false; 255 m_nonBlocking = false;
235 } 256 }
236 257
237 m_alreadyStarted = true; 258 m_alreadyStarted = true;
238 259
239 // FIXME: If script is parser inserted, verify it's still in the original 260 // FIXME: If script is parser inserted, verify it's still in the original
240 // document. 261 // document.
241 Document& elementDocument = m_element->document(); 262 Document& elementDocument = m_element->document();
242 Document* contextDocument = elementDocument.contextDocument(); 263 Document* contextDocument = elementDocument.contextDocument();
243 264
244 if (!contextDocument || !contextDocument->allowExecutingScripts(m_element)) 265 if (!contextDocument || !contextDocument->allowExecutingScripts(m_element))
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 m_willExecuteWhenDocumentFinishedParsing = true; 301 m_willExecuteWhenDocumentFinishedParsing = true;
281 m_willBeParserExecuted = true; 302 m_willBeParserExecuted = true;
282 } else if (client->hasSourceAttribute() && m_parserInserted && 303 } else if (client->hasSourceAttribute() && m_parserInserted &&
283 !client->asyncAttributeValue()) { 304 !client->asyncAttributeValue()) {
284 m_willBeParserExecuted = true; 305 m_willBeParserExecuted = true;
285 } else if (!client->hasSourceAttribute() && m_parserInserted && 306 } else if (!client->hasSourceAttribute() && m_parserInserted &&
286 !elementDocument.isScriptExecutionReady()) { 307 !elementDocument.isScriptExecutionReady()) {
287 m_willBeParserExecuted = true; 308 m_willBeParserExecuted = true;
288 m_readyToBeParserExecuted = true; 309 m_readyToBeParserExecuted = true;
289 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && 310 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
290 !m_forceAsync) { 311 !m_nonBlocking) {
291 m_pendingScript = PendingScript::create(m_element, m_resource.get()); 312 m_pendingScript = PendingScript::create(m_element, m_resource.get());
292 m_asyncExecType = ScriptRunner::InOrder; 313 m_asyncExecType = ScriptRunner::InOrder;
293 contextDocument->scriptRunner()->queueScriptForExecution(this, 314 contextDocument->scriptRunner()->queueScriptForExecution(this,
294 m_asyncExecType); 315 m_asyncExecType);
295 // Note that watchForLoad can immediately call pendingScriptFinished. 316 // Note that watchForLoad can immediately call pendingScriptFinished.
296 m_pendingScript->watchForLoad(this); 317 m_pendingScript->watchForLoad(this);
297 } else if (client->hasSourceAttribute()) { 318 } else if (client->hasSourceAttribute()) {
298 m_pendingScript = PendingScript::create(m_element, m_resource.get()); 319 m_pendingScript = PendingScript::create(m_element, m_resource.get());
299 m_asyncExecType = ScriptRunner::Async; 320 m_asyncExecType = ScriptRunner::Async;
300 LocalFrame* frame = m_element->document().frame(); 321 LocalFrame* frame = m_element->document().frame();
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 if (isHTMLScriptLoader(element)) 665 if (isHTMLScriptLoader(element))
645 return toHTMLScriptElement(element)->loader(); 666 return toHTMLScriptElement(element)->loader();
646 667
647 if (isSVGScriptLoader(element)) 668 if (isSVGScriptLoader(element))
648 return toSVGScriptElement(element)->loader(); 669 return toSVGScriptElement(element)->loader();
649 670
650 return 0; 671 return 0;
651 } 672 }
652 673
653 } // namespace blink 674 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptLoader.h ('k') | third_party/WebKit/Source/core/html/HTMLScriptElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698