Changeset 39104 in webkit


Ignore:
Timestamp:
Dec 8, 2008 3:18:20 PM (15 years ago)
Author:
jchaffraix@webkit.org
Message:

WebCore:

2008-12-08 Julien Chaffraix <jchaffraix@webkit.org>

Reviewed by Darin Adler.

Bug 17897: Not Rendering Images Imported from XHTML Document
<rdar://problem/5827614>

When we were loading document with XMLHttpRequest that contained images, the images
would not be fetched as they would not be displayed. However if we inserted such
an image element into a rendered document, we would not fetch the image and thus never
display it.

Now we check if the image has been loaded when we insert an HTMLImageElement into a
document.
To enable this, the image loader has an error flag. To avoid doing several attempts
when we know that the image is in error, we store the failed URL.
However Firefox and Opera ignore errors when the 'src' attribute changes and thus
we also have an updateFromElementIgnoringPreviousError to match the other browser.

Tests: http/tests/misc/image-blocked-src-change.html

http/tests/misc/image-blocked-src-no-change.html
http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-svg.svg
http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded.html

  • html/HTMLEmbedElement.cpp: (WebCore::HTMLEmbedElement::parseMappedAttribute): Changed to call updateFromElementIgnoringPreviousError.
  • html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::parseMappedAttribute): Ditto. (WebCore::HTMLImageElement::insertedIntoDocument): Call updateFromElement if we do not have an image.


  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::parseMappedAttribute): Changed to call updateFromElementIgnoringPreviousError.
  • html/HTMLObjectElement.cpp: (WebCore::HTMLObjectElement::parseMappedAttribute): Ditto.
  • html/HTMLVideoElement.cpp: (WebCore::HTMLVideoElement::parseMappedAttribute): Ditto.
  • loader/ImageLoader.cpp: (WebCore::ImageLoader::setImage): Added an assertion. (WebCore::ImageLoader::updateFromElement): Added a check for load error (to avoid displaying multiple errors in the console for a single image load).

(WebCore::ImageLoader::updateFromElementIgnoringPreviousError): This method clears previous error
before calling updateFromElement.

(WebCore::ImageLoader::notifyFinished): Added an assertion.

  • loader/ImageLoader.h:
  • svg/SVGImageElement.cpp: (WebCore::SVGImageElement::svgAttributeChanged): Changed to call updateFromElementIgnoringPreviousError.

LayoutTests:

2008-12-08 Julien Chaffraix <jchaffraix@webkit.org>

Reviewed by Darin Adler.

Tests cases for bug 17897: Not Rendering Images Imported from XHTML Document
<rdar://problem/5827614>

  • xmlhttprequest-image-not-loaded*: test that an image loaded by an XMLHttpRequest and inserted into a XHTML or SVG Document is properly rendered.
  • image-blocked-src-change.html and image-blocked-src-no-change.html: test that an image that was in error is responding to src attribute change (whether it does really change the url or not).
  • http/tests/misc/image-blocked-src-change-expected.txt: Added.
  • http/tests/misc/image-blocked-src-change.html: Added.
  • http/tests/misc/image-blocked-src-no-change-expected.txt: Added.
  • http/tests/misc/image-blocked-src-no-change.html: Added.
  • http/tests/xmlhttprequest/resources/load-icon.svg: Added.
  • http/tests/xmlhttprequest/resources/load-icon.xhtml: Added.
  • http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-expected.txt: Added.
  • http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-svg-expected.txt: Added.
  • http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-svg.svg: Added.
  • http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded.html: Added.
Location:
trunk
Files:
10 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r39101 r39104  
     12008-12-08  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Tests cases for bug 17897: Not Rendering Images Imported from XHTML Document
     6        <rdar://problem/5827614>
     7
     8        - xmlhttprequest-image-not-loaded*: test that an image loaded by an XMLHttpRequest and inserted into a XHTML or SVG Document
     9        is properly rendered.
     10
     11        - image-blocked-src-change.html and image-blocked-src-no-change.html: test that an image that was in error is responding to src attribute change
     12          (whether it does really change the url or not).
     13
     14        * http/tests/misc/image-blocked-src-change-expected.txt: Added.
     15        * http/tests/misc/image-blocked-src-change.html: Added.
     16        * http/tests/misc/image-blocked-src-no-change-expected.txt: Added.
     17        * http/tests/misc/image-blocked-src-no-change.html: Added.
     18        * http/tests/xmlhttprequest/resources/load-icon.svg: Added.
     19        * http/tests/xmlhttprequest/resources/load-icon.xhtml: Added.
     20        * http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-expected.txt: Added.
     21        * http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-svg-expected.txt: Added.
     22        * http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-svg.svg: Added.
     23        * http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded.html: Added.
     24
    1252008-12-08  Mark Rowe  <mrowe@apple.com>
    226
  • trunk/WebCore/ChangeLog

    r39103 r39104  
     12008-12-08  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Bug 17897: Not Rendering Images Imported from XHTML Document
     6        <rdar://problem/5827614>
     7
     8        When we were loading document with XMLHttpRequest that contained images, the images
     9        would not be fetched as they would not be displayed. However if we inserted such
     10        an image element into a rendered document, we would not fetch the image and thus never
     11        display it.
     12
     13        Now we check if the image has been loaded when we insert an HTMLImageElement into a
     14        document.
     15        To enable this, the image loader has an error flag. To avoid doing several attempts
     16        when we know that the image is in error, we store the failed URL.
     17        However Firefox and Opera ignore errors when the 'src' attribute changes and thus
     18        we also have an updateFromElementIgnoringPreviousError to match the other browser.
     19
     20        Tests: http/tests/misc/image-blocked-src-change.html
     21               http/tests/misc/image-blocked-src-no-change.html
     22               http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded-svg.svg
     23               http/tests/xmlhttprequest/xmlhttprequest-image-not-loaded.html
     24
     25        * html/HTMLEmbedElement.cpp:
     26        (WebCore::HTMLEmbedElement::parseMappedAttribute): Changed to call updateFromElementIgnoringPreviousError.
     27        * html/HTMLImageElement.cpp:
     28        (WebCore::HTMLImageElement::parseMappedAttribute): Ditto.
     29        (WebCore::HTMLImageElement::insertedIntoDocument): Call updateFromElement if we do not have
     30        an image.
     31
     32        * html/HTMLInputElement.cpp:
     33        (WebCore::HTMLInputElement::parseMappedAttribute): Changed to call updateFromElementIgnoringPreviousError.
     34        * html/HTMLObjectElement.cpp:
     35        (WebCore::HTMLObjectElement::parseMappedAttribute): Ditto.
     36        * html/HTMLVideoElement.cpp:
     37        (WebCore::HTMLVideoElement::parseMappedAttribute): Ditto.
     38        * loader/ImageLoader.cpp:
     39        (WebCore::ImageLoader::setImage): Added an assertion.
     40        (WebCore::ImageLoader::updateFromElement): Added a check for load error (to avoid displaying
     41        multiple errors in the console for a single image load).
     42
     43        (WebCore::ImageLoader::updateFromElementIgnoringPreviousError): This method clears previous error
     44        before calling updateFromElement.
     45
     46        (WebCore::ImageLoader::notifyFinished): Added an assertion.
     47        * loader/ImageLoader.h:
     48        * svg/SVGImageElement.cpp:
     49        (WebCore::SVGImageElement::svgAttributeChanged): Changed to call updateFromElementIgnoringPreviousError.
     50
    1512008-12-08  David Hyatt  <hyatt@apple.com>
    252
  • trunk/WebCore/html/HTMLEmbedElement.cpp

    r39065 r39104  
    103103            if (!m_imageLoader)
    104104                m_imageLoader.set(new HTMLImageLoader(this));
    105             m_imageLoader->updateFromElement();
     105            m_imageLoader->updateFromElementIgnoringPreviousError();
    106106        }
    107107    } else if (attr->name() == hiddenAttr) {
  • trunk/WebCore/html/HTMLImageElement.cpp

    r39065 r39104  
    8383            static_cast<RenderImage*>(renderer())->updateAltText();
    8484    } else if (attrName == srcAttr)
    85         m_imageLoader.updateFromElement();
     85        m_imageLoader.updateFromElementIgnoringPreviousError();
    8686    else if (attrName == widthAttr)
    8787        addCSSLength(attr, CSSPropertyWidth, attr->value());
     
    187187    }
    188188
     189    // If we have been inserted from a renderer-less document,
     190    // our loader may have not fetched the image, so do it now.
     191    if (!m_imageLoader.image())
     192        m_imageLoader.updateFromElement();
     193
    189194    HTMLElement::insertedIntoDocument();
    190195}
  • trunk/WebCore/html/HTMLInputElement.cpp

    r39065 r39104  
    645645            if (!m_imageLoader)
    646646                m_imageLoader.set(new HTMLImageLoader(this));
    647             m_imageLoader->updateFromElement();
     647            m_imageLoader->updateFromElementIgnoringPreviousError();
    648648        }
    649649    } else if (attr->name() == usemapAttr ||
  • trunk/WebCore/html/HTMLObjectElement.cpp

    r39065 r39104  
    8888          if (!m_imageLoader)
    8989              m_imageLoader.set(new HTMLImageLoader(this));
    90           m_imageLoader->updateFromElement();
     90          m_imageLoader->updateFromElementIgnoringPreviousError();
    9191        }
    9292    } else if (attr->name() == classidAttr) {
  • trunk/WebCore/html/HTMLVideoElement.cpp

    r38881 r39104  
    9494            if (!m_imageLoader)
    9595                m_imageLoader.set(new HTMLImageLoader(this));
    96             m_imageLoader->updateFromElement();
     96            m_imageLoader->updateFromElementIgnoringPreviousError();
    9797        }
    9898    } else if (attrName == widthAttr)
  • trunk/WebCore/loader/ImageLoader.cpp

    r38094 r39104  
    5050void ImageLoader::setImage(CachedImage* newImage)
    5151{
     52    ASSERT(m_failedLoadURL.isEmpty());
    5253    CachedImage* oldImage = m_image.get();
    5354    if (newImage != oldImage) {
     
    8788    AtomicString attr = elem->getAttribute(elem->imageSourceAttributeName());
    8889
     90    if (attr == m_failedLoadURL)
     91        return;
     92
    8993    // Do not load any image if the 'src' attribute is missing or if it is
    9094    // an empty string referring to a local file. The latter condition is
     
    101105        } else
    102106            newImage = doc->docLoader()->requestImage(sourceURI(attr));
     107
     108        // If we do not have an image here, it means that a cross-site
     109        // violation occurred.
     110        m_failedLoadURL = !newImage ? attr : AtomicString();
    103111    }
    104112   
     
    120128}
    121129
     130void ImageLoader::updateFromElementIgnoringPreviousError()
     131{
     132    // Clear previous error.
     133    m_failedLoadURL = AtomicString();
     134    updateFromElement();
     135}
     136
    122137void ImageLoader::notifyFinished(CachedResource *image)
    123138{
     139    ASSERT(m_failedLoadURL.isEmpty());
    124140    m_imageComplete = true;
    125141
  • trunk/WebCore/loader/ImageLoader.h

    r36712 r39104  
    11/*
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
     
    2624#define ImageLoader_h
    2725
     26#include "AtomicString.h"
    2827#include "CachedResourceClient.h"
    2928#include "CachedResourceHandle.h"
     
    3130namespace WebCore {
    3231
    33 class AtomicString;
    3432class Element;
    3533
     
    4038
    4139    void updateFromElement();
     40
     41    // This method should be called after the 'src' attribute
     42    // is set (even when it is not modified) to force the update
     43    // and match Firefox and Opera.
     44    void updateFromElementIgnoringPreviousError();
    4245
    4346    virtual void dispatchLoadEvent() = 0;
     
    6467    Element* m_element;
    6568    CachedResourceHandle<CachedImage> m_image;
     69    AtomicString m_failedLoadURL;
    6670    bool m_firedLoad : 1;
    6771    bool m_imageComplete : 1;
  • trunk/WebCore/svg/SVGImageElement.cpp

    r39065 r39104  
    109109
    110110        if (isURIAttribute)
    111             m_imageLoader.updateFromElement();
     111            m_imageLoader.updateFromElementIgnoringPreviousError();
    112112    }
    113113}
Note: See TracChangeset for help on using the changeset viewer.