2010-12-04 Gavin Peters <gavinp@chromium.org>

        Reviewed by Adam Barth.

        Implement onload events for <link rel=prefetch>
        https://bugs.webkit.org/show_bug.cgi?id=50187

        * fast/dom/HTMLLinkElement/link-and-subresource-test-expected.txt: Added.
        * fast/dom/HTMLLinkElement/link-and-subresource-test.html: Added.
        * fast/dom/HTMLLinkElement/prefetch-expected.txt:
        * fast/dom/HTMLLinkElement/prefetch-onload-expected.txt: Added.
        * fast/dom/HTMLLinkElement/prefetch-onload.html: Added.
        * fast/dom/HTMLLinkElement/prefetch.html:
        * http/tests/misc/prefetch-purpose.html:
        * platform/gtk/Skipped:
        * platform/mac/Skipped:
        * platform/qt/Skipped:
        * platform/win/Skipped:
2010-12-04  Gavin Peters  <gavinp@chromium.org>

        Reviewed by Adam Barth.

        Implement onload events for <link rel=prefetch>
        https://bugs.webkit.org/show_bug.cgi?id=50187

        Tests: fast/dom/HTMLLinkElement/link-and-subresource-test.html
               fast/dom/HTMLLinkElement/prefetch-onload.html

        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::HTMLLinkElement):
        (WebCore::HTMLLinkElement::~HTMLLinkElement):
        (WebCore::HTMLLinkElement::parseMappedAttribute):
        (WebCore::HTMLLinkElement::process):
        (WebCore::HTMLLinkElement::onloadTimerFired):
        (WebCore::HTMLLinkElement::notifyFinished):
        * html/HTMLLinkElement.h:
        * loader/cache/CachedResource.cpp:
        (WebCore::CachedResource::data):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73335 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 061e3ef1
2010-12-04 Gavin Peters <gavinp@chromium.org>
Reviewed by Adam Barth.
Implement onload events for <link rel=prefetch>
https://bugs.webkit.org/show_bug.cgi?id=50187
* fast/dom/HTMLLinkElement/link-and-subresource-test-expected.txt: Added.
* fast/dom/HTMLLinkElement/link-and-subresource-test.html: Added.
* fast/dom/HTMLLinkElement/prefetch-expected.txt:
* fast/dom/HTMLLinkElement/prefetch-onload-expected.txt: Added.
* fast/dom/HTMLLinkElement/prefetch-onload.html: Added.
* fast/dom/HTMLLinkElement/prefetch.html:
* http/tests/misc/prefetch-purpose.html:
* platform/gtk/Skipped:
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
2010-12-04 Martin Robinson <mrobinson@igalia.com>
Fix a baseline which differs between my machine and the bots.
nick.jpg has MIME type image/jpeg
nick.jpg has MIME type image/jpeg
This test verifies that an image which is prefetched, and which is also contained as a subresource of the current document can be loaded correctly as a subresource. See bug 49236 in which this wasn't working.
When this test succeeds, you'll see an image of Nick on a sailboat immediately below this text. When this test fails, you will see no images at all.
NICK_ONLOAD called
NICK_ONLOAD called
SUCCESS. Two loads.
<html>
<body>
<script>
function log(message)
{
var item = document.createElement("li");
item.appendChild(document.createTextNode(message));
document.getElementById("console").appendChild(item);
}
nick_load_count = 0
function nick_onload()
{
log("NICK_ONLOAD called");
++nick_load_count;
if (nick_load_count == 2) {
log("SUCCESS. Two loads.");
layoutTestController.notifyDone();
}
}
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
layoutTestController.dumpAsText();
layoutTestController.dumpResourceResponseMIMETypes();
}
</script>
<p>This test verifies that an image which is prefetched, and which is also contained as a
subresource of the current document can be loaded correctly as a subresource. See
bug 49236 in which this wasn't working.
<p>When this test succeeds, you'll see an image of Nick on a sailboat immediately below
this text. When this test fails, you will see no images at all.
<link rel="prefetch" href="resources/nick.jpg" onload="nick_onload()" />
<img src="resources/nick.jpg" onload="nick_onload()" />
<hr>
<p><ol id="console"></ol></p>
</body></html>
prefetch.link has MIME type application/octet-stream
This test requires DumpRenderTree to see the log of what resources are loaded.
SUCCESS! prefetch onload called.
This tests that onload events can be attached to link elements with rel=prefetch. Since prefetch links are just there as a performance optimization, the onload event is their only programatic side-effect.
If it works you should see a message below saying the test has passed.
TEST PASSED.
<html>
<head>
<script type="text/javascript">
function log(message)
{
var item = document.createElement("li");
item.appendChild(document.createTextNode(message));
document.getElementById("console").appendChild(item);
}
function done()
{
log("TEST PASSED.");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
</script>
</head>
<body>
<p>This tests that onload events can be attached to link elements with rel=prefetch. Since prefetch links are just there as a performance optimization, the onload event is their only programatic side-effect.</p>
<p>If it works you should see a message below saying the test has passed.</p>
<link href="prefetch.link" rel="prefetch" onload="done()" >
<hr>
<p><ol id="console"></ol></p>
</body>
</html>
<body>
<script>
function log(message) {
var item = document.createElement("li");
item.appendChild(document.createTextNode(message));
document.getElementById("console").appendChild(item);
}
function prefetch_onload() {
log("SUCCESS! prefetch onload called.");
layoutTestController.notifyDone();
}
if (window.layoutTestController) {
layoutTestController.waitUntilDone();
layoutTestController.dumpAsText();
layoutTestController.dumpResourceResponseMIMETypes();
setTimeout("layoutTestController.notifyDone()",50);
}
</script>
<html>
<p>This test requires DumpRenderTree to see the log of what resources are loaded.
<link href="prefetch.link" rel="prefetch">
<link href="prefetch.link" rel="prefetch" onload="prefetch_onload()">
<p><ol id="console"></ol>
</html>
......@@ -12,9 +12,9 @@ if (window.layoutTestController) {
layoutTestController.dumpResourceResponseMIMETypes();
}
</script>
<link href="resources/prefetch-purpose.php" rel="prefetch">
<link href="resources/prefetch-purpose.php" rel="prefetch" onload="finishUp()">
</head>
<body onload="setTimeout('finishUp()', 50);">
<body>
<p>Nothing to see here, this page should replace itself with resources/prefetch-purpose.php almost instantly.
</body>
</html>
......@@ -5117,7 +5117,9 @@ fast/forms/slider-mouse-events.html
fast/forms/slider-zoomed.html
# Link prefetch is disabled by default
fast/dom/HTMLLinkElement/link-and-subresource-test.html
fast/dom/HTMLLinkElement/prefetch.html
fast/dom/HTMLLinkElement/prefetch-onload.html
# LayoutTestController::pageProperty is not implemented for GTK yet.
printing/page-rule-selection.html
......
......@@ -184,7 +184,9 @@ fast/dom/DeviceOrientation
fast/dom/Window/window-properties-device-orientation.html
# Link prefetch is disabled by default
fast/dom/HTMLLinkElement/link-and-subresource-test.html
fast/dom/HTMLLinkElement/prefetch.html
fast/dom/HTMLLinkElement/prefetch-onload.html
http/tests/misc/prefetch-purpose.html
# Filenames aren't filtered out from edit drags yet, see https://bugs.wekit.org/show_bug.cgi?id=38826
......
......@@ -5149,7 +5149,9 @@ media/video-delay-load-event.html
fast/dom/Geolocation/callback-to-remote-context2.html
# Link prefetch is disabled by default
fast/dom/HTMLLinkElement/link-and-subresource-test.html
fast/dom/HTMLLinkElement/prefetch.html
fast/dom/HTMLLinkElement/prefetch-onload.html
http/tests/misc/prefetch-purpose.html
# [Qt] Regression(r61749): inspector/debugger-pause-on-debugger-statement.html fails
......
......@@ -946,7 +946,9 @@ fast/dom/DeviceOrientation
fast/dom/Window/window-properties-device-orientation.html
# Link prefetch is disabled by default
fast/dom/HTMLLinkElement/link-and-subresource-test.html
fast/dom/HTMLLinkElement/prefetch.html
fast/dom/HTMLLinkElement/prefetch-onload.html
http/tests/misc/prefetch-purpose.html
# LayoutTestController::pageProperty is not implemented for WIN yet.
......
2010-12-04 Gavin Peters <gavinp@chromium.org>
Reviewed by Adam Barth.
Implement onload events for <link rel=prefetch>
https://bugs.webkit.org/show_bug.cgi?id=50187
Tests: fast/dom/HTMLLinkElement/link-and-subresource-test.html
fast/dom/HTMLLinkElement/prefetch-onload.html
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::HTMLLinkElement):
(WebCore::HTMLLinkElement::~HTMLLinkElement):
(WebCore::HTMLLinkElement::parseMappedAttribute):
(WebCore::HTMLLinkElement::process):
(WebCore::HTMLLinkElement::onloadTimerFired):
(WebCore::HTMLLinkElement::notifyFinished):
* html/HTMLLinkElement.h:
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::data):
2010-12-04 Xan Lopez <xlopez@igalia.com>
Reviewed by Martin Robinson.
......@@ -48,6 +48,9 @@ using namespace HTMLNames;
inline HTMLLinkElement::HTMLLinkElement(const QualifiedName& tagName, Document* document, bool createdByParser)
: HTMLElement(tagName, document)
#if ENABLE(LINK_PREFETCH)
, m_onloadTimer(this, &HTMLLinkElement::onloadTimerFired)
#endif
, m_disabledState(Unset)
, m_loading(false)
, m_createdByParser(createdByParser)
......@@ -70,6 +73,11 @@ HTMLLinkElement::~HTMLLinkElement()
if (m_loading && !isDisabled() && !isAlternate())
document()->removePendingSheet();
}
#if ENABLE(LINK_PREFETCH)
if (m_cachedLinkPrefetch)
m_cachedLinkPrefetch->removeClient(this);
#endif
}
void HTMLLinkElement::setDisabledState(bool _disabled)
......@@ -133,6 +141,10 @@ void HTMLLinkElement::parseMappedAttribute(Attribute* attr)
setDisabledState(!attr->isNull());
else if (attr->name() == onbeforeloadAttr)
setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
#if ENABLE(LINK_PREFETCH)
else if (attr->name() == onloadAttr)
setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
#endif
else {
if (attr->name() == titleAttr && m_sheet)
m_sheet->setTitle(attr->value());
......@@ -203,8 +215,11 @@ void HTMLLinkElement::process()
}
#if ENABLE(LINK_PREFETCH)
if (m_relAttribute.m_isLinkPrefetch && m_url.isValid() && document()->frame())
document()->cachedResourceLoader()->requestLinkPrefetch(m_url);
if (m_relAttribute.m_isLinkPrefetch && m_url.isValid() && document()->frame()) {
m_cachedLinkPrefetch = document()->cachedResourceLoader()->requestLinkPrefetch(m_url);
if (m_cachedLinkPrefetch)
m_cachedLinkPrefetch->addClient(this);
}
#endif
bool acceptIfTypeContainsTextCSS = document()->page() && document()->page()->settings() && document()->page()->settings()->treatsAnyTextCSSLinkAsStylesheet();
......@@ -356,6 +371,23 @@ bool HTMLLinkElement::isLoading() const
return static_cast<CSSStyleSheet *>(m_sheet.get())->isLoading();
}
#if ENABLE(LINK_PREFETCH)
void HTMLLinkElement::onloadTimerFired(Timer<HTMLLinkElement>* timer)
{
ASSERT_UNUSED(timer, timer == &m_onloadTimer);
dispatchEvent(Event::create(eventNames().loadEvent, false, false));
}
void HTMLLinkElement::notifyFinished(CachedResource* resource)
{
m_onloadTimer.startOneShot(0);
if (m_cachedLinkPrefetch.get() == resource) {
m_cachedLinkPrefetch->removeClient(this);
m_cachedLinkPrefetch = 0;
}
}
#endif
bool HTMLLinkElement::sheetLoaded()
{
if (!isLoading() && !isDisabled() && !isAlternate()) {
......
......@@ -27,10 +27,12 @@
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include "HTMLElement.h"
#include "Timer.h"
namespace WebCore {
class CachedCSSStyleSheet;
class CachedResource;
class KURL;
class HTMLLinkElement : public HTMLElement, public CachedResourceClient {
......@@ -77,6 +79,9 @@ public:
private:
virtual void parseMappedAttribute(Attribute*);
#if ENABLE(LINK_PREFETCH)
void onloadTimerFired(Timer<HTMLLinkElement>*);
#endif
void process();
static void processCallback(Node*);
......@@ -85,6 +90,9 @@ private:
// from CachedResourceClient
virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet);
#if ENABLE(LINK_PREFETCH)
virtual void notifyFinished(CachedResource*);
#endif
virtual bool sheetLoaded();
bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; }
......@@ -112,6 +120,10 @@ private:
CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
RefPtr<CSSStyleSheet> m_sheet;
#if ENABLE(LINK_PREFETCH)
CachedResourceHandle<CachedResource> m_cachedLinkPrefetch;
Timer<HTMLLinkElement> m_onloadTimer;
#endif
KURL m_url;
String m_type;
String m_media;
......
......@@ -115,6 +115,7 @@ void CachedResource::data(PassRefPtr<SharedBuffer>, bool allDataReceived)
if (!allDataReceived)
return;
setLoading(false);
CachedResourceClientWalker w(m_clients);
while (CachedResourceClient* c = w.next())
c->notifyFinished(this);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment