[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75
hyatt at apple.com
hyatt at apple.com
Thu Oct 29 20:40:25 UTC 2009
The following commit has been merged in the webkit-1.1 branch:
commit ad45b614df5236e7d427410567c86558f59ffe12
Author: hyatt at apple.com <hyatt at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Oct 6 17:37:48 2009 +0000
https://bugs.webkit.org/show_bug.cgi?id=30131, make beforeload fire on script elements.
Reviewed by Adam Roben.
WebCore:
Added tests in fast/dom/beforeload/.
* dom/ScriptElement.cpp:
(WebCore::ScriptElementData::requestScript):
* dom/ScriptElement.h:
* dom/XMLTokenizerLibxml2.cpp:
(WebCore::XMLTokenizer::endElementNs):
* html/HTMLAttributeNames.in:
* html/HTMLScriptElement.cpp:
(WebCore::HTMLScriptElement::parseMappedAttribute):
(WebCore::HTMLScriptElement::dispatchBeforeLoadEvent):
* html/HTMLScriptElement.h:
* html/HTMLTokenizer.cpp:
(WebCore::HTMLTokenizer::scriptHandler):
* svg/SVGScriptElement.cpp:
(WebCore::SVGScriptElement::dispatchBeforeLoadEvent):
* svg/SVGScriptElement.h:
LayoutTests:
* fast/dom/beforeload: Added.
* fast/dom/beforeload/resources: Added.
* fast/dom/beforeload/script-before-load-dynamic-expected.txt: Added.
* fast/dom/beforeload/script-before-load-dynamic.html: Added.
* fast/dom/beforeload/script-before-load-expected.txt: Added.
* fast/dom/beforeload/script-before-load-xhtml-expected.txt: Added.
* fast/dom/beforeload/script-before-load-xhtml.xhtml: Added.
* fast/dom/beforeload/script-before-load.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49194 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 44ede9f..a11a1f6 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,18 @@
+2009-10-06 Dave Hyatt <hyatt at apple.com>
+
+ Reviewed by Adam Roben.
+
+ https://bugs.webkit.org/show_bug.cgi?id=30131, make beforeload fire on script elements.
+
+ * fast/dom/beforeload: Added.
+ * fast/dom/beforeload/resources: Added.
+ * fast/dom/beforeload/script-before-load-dynamic-expected.txt: Added.
+ * fast/dom/beforeload/script-before-load-dynamic.html: Added.
+ * fast/dom/beforeload/script-before-load-expected.txt: Added.
+ * fast/dom/beforeload/script-before-load-xhtml-expected.txt: Added.
+ * fast/dom/beforeload/script-before-load-xhtml.xhtml: Added.
+ * fast/dom/beforeload/script-before-load.html: Added.
+
2009-10-06 Zan Dobersek <zandobersek at gmail.com>
Reviewed by Eric Seidel.
diff --git a/LayoutTests/fast/dom/beforeload/script-before-load-dynamic-expected.txt b/LayoutTests/fast/dom/beforeload/script-before-load-dynamic-expected.txt
new file mode 100644
index 0000000..9a796b1
--- /dev/null
+++ b/LayoutTests/fast/dom/beforeload/script-before-load-dynamic-expected.txt
@@ -0,0 +1,3 @@
+This page tests the beforeload event on script elements. You should see a PASS message below if everything works.
+
+PASS
diff --git a/LayoutTests/fast/dom/beforeload/script-before-load-dynamic.html b/LayoutTests/fast/dom/beforeload/script-before-load-dynamic.html
new file mode 100644
index 0000000..177950d
--- /dev/null
+++ b/LayoutTests/fast/dom/beforeload/script-before-load-dynamic.html
@@ -0,0 +1,39 @@
+<html>
+<head>
+<script>
+function print(message, color)
+{
+ var paragraph = document.createElement("div");
+ paragraph.appendChild(document.createTextNode(message));
+ paragraph.style.fontFamily = "monospace";
+ if (color)
+ paragraph.style.color = color;
+ document.getElementById("console").appendChild(paragraph);
+}
+</script>
+</head>
+
+<body>
+<p>This page tests the beforeload event on script elements. You should see a PASS message below if everything
+works.</p>
+<hr>
+<div id='console'></div>
+
+<script>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+function beforeLoadFunc()
+{
+ print("PASS", "green");
+ event.preventDefault();
+}
+
+document.body.addEventListener("beforeload", beforeLoadFunc, true);
+var elt = document.createElement("script");
+elt.setAttribute("src", "resources/fail.js");
+document.body.appendChild(elt);
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/beforeload/script-before-load-expected.txt b/LayoutTests/fast/dom/beforeload/script-before-load-expected.txt
new file mode 100644
index 0000000..9a796b1
--- /dev/null
+++ b/LayoutTests/fast/dom/beforeload/script-before-load-expected.txt
@@ -0,0 +1,3 @@
+This page tests the beforeload event on script elements. You should see a PASS message below if everything works.
+
+PASS
diff --git a/LayoutTests/fast/dom/beforeload/script-before-load-xhtml-expected.txt b/LayoutTests/fast/dom/beforeload/script-before-load-xhtml-expected.txt
new file mode 100644
index 0000000..9a796b1
--- /dev/null
+++ b/LayoutTests/fast/dom/beforeload/script-before-load-xhtml-expected.txt
@@ -0,0 +1,3 @@
+This page tests the beforeload event on script elements. You should see a PASS message below if everything works.
+
+PASS
diff --git a/LayoutTests/fast/dom/beforeload/script-before-load-xhtml.xhtml b/LayoutTests/fast/dom/beforeload/script-before-load-xhtml.xhtml
new file mode 100644
index 0000000..480424c
--- /dev/null
+++ b/LayoutTests/fast/dom/beforeload/script-before-load-xhtml.xhtml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<script>
+function print(message, color)
+{
+ var paragraph = document.createElement("div");
+ paragraph.appendChild(document.createTextNode(message));
+ paragraph.style.fontFamily = "monospace";
+ if (color)
+ paragraph.style.color = color;
+ document.getElementById("console").appendChild(paragraph);
+}
+</script>
+</head>
+
+<body>
+<p>This page tests the beforeload event on script elements. You should see a PASS message below if everything
+works.</p>
+<hr/>
+<div id="console"></div>
+
+<script>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+
+function beforeLoadFunc()
+{
+ print("PASS", "green");
+ event.preventDefault();
+}
+
+document.body.addEventListener("beforeload", beforeLoadFunc, true);
+</script>
+<script src="resources/fail.js"></script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/beforeload/script-before-load.html b/LayoutTests/fast/dom/beforeload/script-before-load.html
new file mode 100644
index 0000000..2c0a284
--- /dev/null
+++ b/LayoutTests/fast/dom/beforeload/script-before-load.html
@@ -0,0 +1,27 @@
+<html>
+<head>
+<script>
+function print(message, color)
+{
+ var paragraph = document.createElement("div");
+ paragraph.appendChild(document.createTextNode(message));
+ paragraph.style.fontFamily = "monospace";
+ if (color)
+ paragraph.style.color = color;
+ document.getElementById("console").appendChild(paragraph);
+}
+</script>
+</head>
+
+<body>
+<p>This page tests the beforeload event on script elements. You should see a PASS message below if everything
+works.</p>
+<hr>
+<div id='console'></div>
+<script>
+if (window.layoutTestController)
+ layoutTestController.dumpAsText();
+</script>
+<script onbeforeload="print('PASS', 'green'); return false" src="resources/fail.js"></script>
+</body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 6d15cf8..0c91197 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,27 @@
+2009-10-06 Dave Hyatt <hyatt at apple.com>
+
+ Reviewed by Adam Roben.
+
+ https://bugs.webkit.org/show_bug.cgi?id=30131, make beforeload fire on script elements.
+
+ Added tests in fast/dom/beforeload/.
+
+ * dom/ScriptElement.cpp:
+ (WebCore::ScriptElementData::requestScript):
+ * dom/ScriptElement.h:
+ * dom/XMLTokenizerLibxml2.cpp:
+ (WebCore::XMLTokenizer::endElementNs):
+ * html/HTMLAttributeNames.in:
+ * html/HTMLScriptElement.cpp:
+ (WebCore::HTMLScriptElement::parseMappedAttribute):
+ (WebCore::HTMLScriptElement::dispatchBeforeLoadEvent):
+ * html/HTMLScriptElement.h:
+ * html/HTMLTokenizer.cpp:
+ (WebCore::HTMLTokenizer::scriptHandler):
+ * svg/SVGScriptElement.cpp:
+ (WebCore::SVGScriptElement::dispatchBeforeLoadEvent):
+ * svg/SVGScriptElement.h:
+
2009-10-06 Xan Lopez <xlopez at igalia.com>
Reviewed by Eric Seidel.
diff --git a/WebCore/dom/ScriptElement.cpp b/WebCore/dom/ScriptElement.cpp
index fe38b46..a6db8ba 100644
--- a/WebCore/dom/ScriptElement.cpp
+++ b/WebCore/dom/ScriptElement.cpp
@@ -151,6 +151,9 @@ void ScriptElementData::requestScript(const String& sourceUrl)
if (!document->frame())
return;
+ if (!m_scriptElement->dispatchBeforeLoadEvent(sourceUrl))
+ return;
+
ASSERT(!m_cachedScript);
m_cachedScript = document->docLoader()->requestScript(sourceUrl, scriptCharset());
m_requested = true;
diff --git a/WebCore/dom/ScriptElement.h b/WebCore/dom/ScriptElement.h
index 0aed5e8..09b0aae 100644
--- a/WebCore/dom/ScriptElement.h
+++ b/WebCore/dom/ScriptElement.h
@@ -44,6 +44,7 @@ public:
virtual String languageAttributeValue() const = 0;
virtual String forAttributeValue() const = 0;
+ virtual bool dispatchBeforeLoadEvent(const String& sourceURL) = 0;
virtual void dispatchLoadEvent() = 0;
virtual void dispatchErrorEvent() = 0;
diff --git a/WebCore/dom/XMLTokenizerLibxml2.cpp b/WebCore/dom/XMLTokenizerLibxml2.cpp
index d3c6546..ebee074 100644
--- a/WebCore/dom/XMLTokenizerLibxml2.cpp
+++ b/WebCore/dom/XMLTokenizerLibxml2.cpp
@@ -851,7 +851,8 @@ void XMLTokenizer::endElementNs()
if (!scriptHref.isEmpty()) {
// we have a src attribute
String scriptCharset = scriptElement->scriptCharset();
- if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) {
+ if (scriptElement->dispatchBeforeLoadEvent(scriptHref) &&
+ (m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) {
m_scriptElement = element;
m_pendingScript->addClient(this);
diff --git a/WebCore/html/HTMLAttributeNames.in b/WebCore/html/HTMLAttributeNames.in
index 63a5c21..7c6c4d6 100644
--- a/WebCore/html/HTMLAttributeNames.in
+++ b/WebCore/html/HTMLAttributeNames.in
@@ -125,6 +125,7 @@ object
onabort
onbeforecopy
onbeforecut
+onbeforeload
onbeforepaste
onbeforeunload
onblur
diff --git a/WebCore/html/HTMLScriptElement.cpp b/WebCore/html/HTMLScriptElement.cpp
index ce7fee6..5321d56 100644
--- a/WebCore/html/HTMLScriptElement.cpp
+++ b/WebCore/html/HTMLScriptElement.cpp
@@ -23,6 +23,7 @@
#include "config.h"
#include "HTMLScriptElement.h"
+#include "BeforeLoadEvent.h"
#include "Document.h"
#include "Event.h"
#include "EventNames.h"
@@ -71,6 +72,8 @@ void HTMLScriptElement::parseMappedAttribute(MappedAttribute* attr)
handleSourceAttribute(m_data, attr->value());
else if (attrName == onloadAttr)
setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
+ else if (attrName == onbeforeloadAttr)
+ setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
else
HTMLElement::parseMappedAttribute(attr);
}
@@ -218,6 +221,14 @@ String HTMLScriptElement::forAttributeValue() const
return getAttribute(forAttr).string();
}
+bool HTMLScriptElement::dispatchBeforeLoadEvent(const String& sourceURL)
+{
+ RefPtr<HTMLScriptElement> protector(this);
+ RefPtr<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL);
+ dispatchEvent(beforeLoadEvent.get());
+ return inDocument() && !beforeLoadEvent->defaultPrevented();
+}
+
void HTMLScriptElement::dispatchLoadEvent()
{
ASSERT(!m_data.haveFiredLoadEvent());
diff --git a/WebCore/html/HTMLScriptElement.h b/WebCore/html/HTMLScriptElement.h
index 4d18beb..1846a89 100644
--- a/WebCore/html/HTMLScriptElement.h
+++ b/WebCore/html/HTMLScriptElement.h
@@ -77,6 +77,8 @@ public:
bool haveFiredLoadEvent() const { return m_data.haveFiredLoadEvent(); }
+ virtual bool dispatchBeforeLoadEvent(const String& sourceURL);
+
protected:
virtual String sourceAttributeValue() const;
virtual String charsetAttributeValue() const;
diff --git a/WebCore/html/HTMLTokenizer.cpp b/WebCore/html/HTMLTokenizer.cpp
index 69a203b..1a2d276 100644
--- a/WebCore/html/HTMLTokenizer.cpp
+++ b/WebCore/html/HTMLTokenizer.cpp
@@ -441,7 +441,8 @@ HTMLTokenizer::State HTMLTokenizer::scriptHandler(State state)
#endif
// The parser might have been stopped by for example a window.close call in an earlier script.
// If so, we don't want to load scripts.
- if (!m_parserStopped && (cs = m_doc->docLoader()->requestScript(m_scriptTagSrcAttrValue, m_scriptTagCharsetAttrValue)))
+ if (!m_parserStopped && m_scriptNode->dispatchBeforeLoadEvent(m_scriptTagSrcAttrValue) &&
+ (cs = m_doc->docLoader()->requestScript(m_scriptTagSrcAttrValue, m_scriptTagCharsetAttrValue)))
m_pendingScripts.append(cs);
else
m_scriptNode = 0;
diff --git a/WebCore/svg/SVGScriptElement.cpp b/WebCore/svg/SVGScriptElement.cpp
index 587542c..f4a5e3d 100644
--- a/WebCore/svg/SVGScriptElement.cpp
+++ b/WebCore/svg/SVGScriptElement.cpp
@@ -25,6 +25,7 @@
#if ENABLE(SVG)
#include "SVGScriptElement.h"
+#include "BeforeLoadEvent.h"
#include "Document.h"
#include "Event.h"
#include "EventNames.h"
@@ -180,6 +181,14 @@ String SVGScriptElement::forAttributeValue() const
return String();
}
+bool SVGScriptElement::dispatchBeforeLoadEvent(const String& sourceURL)
+{
+ RefPtr<SVGScriptElement> protector(this);
+ RefPtr<BeforeLoadEvent> beforeLoadEvent = BeforeLoadEvent::create(sourceURL);
+ dispatchEvent(beforeLoadEvent.get());
+ return inDocument() && !beforeLoadEvent->defaultPrevented();
+}
+
void SVGScriptElement::dispatchLoadEvent()
{
bool externalResourcesRequired = externalResourcesRequiredBaseValue();
diff --git a/WebCore/svg/SVGScriptElement.h b/WebCore/svg/SVGScriptElement.h
index f2efc8e..fa51825 100644
--- a/WebCore/svg/SVGScriptElement.h
+++ b/WebCore/svg/SVGScriptElement.h
@@ -69,6 +69,7 @@ namespace WebCore {
virtual String languageAttributeValue() const;
virtual String forAttributeValue() const;
+ virtual bool dispatchBeforeLoadEvent(const String& sourceURL);
virtual void dispatchLoadEvent();
virtual void dispatchErrorEvent();
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list