2010-08-12  Dimitri Glazkov  <dglazkov@chromium.org>

        Reviewed by Adam Barth.

        Ensure that parser doesn't attach children that have been removed by JavaScript event handlers.
        https://bugs.webkit.org/show_bug.cgi?id=43813

        This patch re-fixes bug 40742 in a way that keeps allowing HTMLLinkElement
        to lazy-attach.

        * html/HTMLConstructionSite.cpp:
        (WebCore::HTMLConstructionSite::attach): Added parent check.
        * html/HTMLLinkElement.cpp: Basically undoes changes introduced by r61424.
        * html/HTMLLinkElement.h: Ditto.

git-svn-id: svn://svn.chromium.org/blink/trunk@65281 bbb929c8-8fbe-4397-9dbb-9b2b20218538
void HTMLConstructionSite::attachAtSite(const AttachmentSite& site, PassRefPtr<Node> prpChild)
{
    RefPtr<Node> child = prpChild;

    if (site.nextChild) {
        ExceptionCode ec = 0;
        site.parent->insertBefore(child, site.nextChild, ec);
        ASSERT(!ec);
        if (site.parent->attached() && !child->attached())
            child->attach();
        return;
    }
    site.parent->parserAddChild(child);
    if (site.parent->attached() && !child->attached())
        child->attach();
}

void HTMLConstructionSite::attachAtSite(const AttachmentSite& site, PassRefPtr<Node> prpChild)
{
    RefPtr<Node> child = prpChild;

    if (site.nextChild) {
        ExceptionCode ec = 0;
        site.parent->insertBefore(child, site.nextChild, ec);
        ASSERT(!ec);
        if (site.parent->attached() && !child->attached())
            child->attach();
        return;
    }
    site.parent->parserAddChild(child);
    if (site.parent->attached() && !child->attached())
        child->attach();
}
