Reviewed by Geoff Garen.
authorAlexey Proskuryakov <ap@webkit.org>
Sun, 29 May 2011 01:37:59 +0000 (01:37 +0000)
committerAdemar de Souza Reis Jr <ademar.reis@openbossa.org>
Mon, 30 May 2011 15:34:14 +0000 (12:34 -0300)
commitdb21b6f5835b0836915cd164d66c64700e26cf76
tree02405922b26212cf5668b04b0ad68c7fe1be224b
parentd14495f006a09eaee01d155fa57c80537408a835
    Reviewed by Geoff Garen.

        REGRESSION (r85375): Load event is sometimes lost when multiple image elements use the same URL
        https://bugs.webkit.org/show_bug.cgi?id=61692
        <rdar://problem/9488628>

        Test: fast/dom/gc-image-element-2.html

        Manually verified that tests from bug 59604 and from bug 40926 still pass.

        The problem here was that HTMLImageElement::hasPendingActivity() could return false when
        a load (or error) event was still expected to fire.

        * loader/cache/CachedResource.cpp:
        (WebCore::CachedResource::setRequest):
        * loader/cache/CachedResource.h:
        (WebCore::CachedResource::wasCanceled):
        (WebCore::CachedResource::errorOccurred):
        Track whether the load was canceled. We want to always notify clients of load outcome,
        as that's the only way they could make intelligent decisions.

        * dom/ScriptElement.cpp: (WebCore::ScriptElement::execute): Cached resource clients now
        get a notifyFinished call on cancellation. Handle this case, where we don't need the
        execute the script, but also don't need to fire an error event.

        * html/HTMLImageElement.cpp: Moved hasPendingActivity() to header, since it's just a single
        function call now.

        * html/HTMLImageElement.h: (WebCore::HTMLImageElement::hasPendingActivity): There is a large
        window between when CachedResource::isLoading() becomes false and events are queued.
        ImageLoader::haveFiredLoadEvent() is a much better indication of whether we are expecting
        an event to fire.

        * html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::onloadTimerFired): Again, don't do
        anything on cancellation.

        * loader/ImageLoader.cpp:
        (WebCore::ImageEventSender::hasPendingEvents): Made it debug-only again, and fixed to
        give an accurate result while looping over the list of events to dispatch.
        (WebCore::ImageLoader::notifyFinished): Don't do anything when cancelled. We don't want to
        switch to a broken image icon, or to dispatch events.
        (WebCore::ImageEventSender::dispatchPendingEvents): Clear the current loader from dispatching
        list, as the event is no longer pending when it's being dispatched.

        * loader/ImageLoader.h: Removed unnecessary hasPendingLoadEvent(). We don't care whether one
        is already pending, we only care if one is expected at some time in the future, and
        !haveFiredLoadEvent() is our best idea of that.

        * dom/XMLDocumentParser.cpp: (WebCore::XMLDocumentParser::notifyFinished): Another place to
        handle cancellation.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@87628 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/gc-image-element-2-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/gc-image-element-2.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/XMLDocumentParser.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/loader/ImageLoader.cpp
Source/WebCore/loader/ImageLoader.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h