summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/dom/ScriptElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/dom/ScriptElement.cpp')
-rw-r--r--Source/WebCore/dom/ScriptElement.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/Source/WebCore/dom/ScriptElement.cpp b/Source/WebCore/dom/ScriptElement.cpp
index 3bba9a0..9a07bb8 100644
--- a/Source/WebCore/dom/ScriptElement.cpp
+++ b/Source/WebCore/dom/ScriptElement.cpp
@@ -24,9 +24,9 @@
#include "config.h"
#include "ScriptElement.h"
-#include "AsyncScriptRunner.h"
#include "CachedScript.h"
#include "CachedResourceLoader.h"
+#include "ContentSecurityPolicy.h"
#include "Document.h"
#include "DocumentParser.h"
#include "Frame.h"
@@ -37,6 +37,7 @@
#include "MIMETypeRegistry.h"
#include "Page.h"
#include "ScriptController.h"
+#include "ScriptRunner.h"
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "Settings.h"
@@ -61,6 +62,8 @@ ScriptElement::ScriptElement(Element* element, bool parserInserted, bool already
, m_willBeParserExecuted(false)
, m_readyToBeParserExecuted(false)
, m_willExecuteWhenDocumentFinishedParsing(false)
+ , m_forceAsync(!parserInserted)
+ , m_willExecuteInOrder(false)
{
ASSERT(m_element);
}
@@ -96,6 +99,11 @@ void ScriptElement::handleSourceAttribute(const String& sourceUrl)
prepareScript(); // FIXME: Provide a real starting line number here.
}
+void ScriptElement::handleAsyncAttribute()
+{
+ m_forceAsync = false;
+}
+
// Helper function
static bool isLegacySupportedJavaScriptLanguage(const String& language)
{
@@ -159,7 +167,8 @@ bool ScriptElement::prepareScript(const TextPosition1& scriptStartPosition, Lega
} else
wasParserInserted = false;
- // FIXME: HTML5 spec says we should set forceAsync.
+ if (wasParserInserted && !asyncAttributeValue())
+ m_forceAsync = true;
// FIXME: HTML5 spec says we should check that all children are either comments or empty text nodes.
if (!hasSourceAttribute() && !m_element->firstChild())
@@ -171,8 +180,10 @@ bool ScriptElement::prepareScript(const TextPosition1& scriptStartPosition, Lega
if (!isScriptTypeSupported(supportLegacyTypes))
return false;
- if (wasParserInserted)
+ if (wasParserInserted) {
m_parserInserted = true;
+ m_forceAsync = false;
+ }
m_alreadyStarted = true;
@@ -207,6 +218,10 @@ bool ScriptElement::prepareScript(const TextPosition1& scriptStartPosition, Lega
else if (!hasSourceAttribute() && m_parserInserted && !m_element->document()->haveStylesheetsLoaded()) {
m_willBeParserExecuted = true;
m_readyToBeParserExecuted = true;
+ } else if (hasSourceAttribute() && !asyncAttributeValue() && !m_forceAsync) {
+ m_willExecuteInOrder = true;
+ m_element->document()->scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::IN_ORDER_EXECUTION);
+ m_cachedScript->addClient(this);
} else if (hasSourceAttribute())
m_cachedScript->addClient(this);
else
@@ -217,9 +232,6 @@ bool ScriptElement::prepareScript(const TextPosition1& scriptStartPosition, Lega
bool ScriptElement::requestScript(const String& sourceUrl)
{
- if (!m_element->document()->contentSecurityPolicy()->canLoadExternalScriptFromSrc(sourceUrl))
- return false;
-
RefPtr<Document> originalDocument = m_element->document();
if (!m_element->dispatchBeforeLoadEvent(sourceUrl))
return false;
@@ -286,7 +298,10 @@ void ScriptElement::notifyFinished(CachedResource* o)
{
ASSERT(!m_willBeParserExecuted);
ASSERT_UNUSED(o, o == m_cachedScript);
- m_element->document()->asyncScriptRunner()->executeScriptSoon(this, m_cachedScript);
+ if (m_willExecuteInOrder)
+ m_element->document()->scriptRunner()->notifyInOrderScriptReady();
+ else
+ m_element->document()->scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::ASYNC_EXECUTION);
m_cachedScript = 0;
}