<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>15000</bug_id>
          
          <creation_ts>2011-11-30 09:15:09 +0000</creation_ts>
          <short_desc>Don&apos;t fire load until the image is fully decodable. If the image is corrupt or unsupported, the spec says to fire load *and* error, but browsers don&apos;t do that.</short_desc>
          <delta_ts>2012-09-15 02:10:04 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#img-load</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>bobbyholley</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>dbaron</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>60656</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-11-30 09:15:09 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html
Multipage: http://www.whatwg.org/C#img-load
Complete: http://www.whatwg.org/c#img-load

Comment:
Don&apos;t fire load until the image is fully decodable. If the image is corrupt or
unsupported, the spec says to fire load *and* error, but browsers don&apos;t do
that.

Posted from: 85.227.157.105 by simonp@opera.com
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.942.0 Safari/535.8</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60660</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2011-11-30 10:03:01 +0000</bug_when>
    <thetext>Mistake, the spec doesn&apos;t say to fire both load and error. It says to fire load if the load was successful, without checking if the image is corrupt first.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63449</commentid>
    <comment_count>2</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-01-31 21:00:50 +0000</bug_when>
    <thetext>I believe the spec matches reality here. Browsers fire &apos;load&apos; before they inspect the data in some cases. Do you have a test case demonstrating otherwise?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63519</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-02-01 08:01:45 +0000</bug_when>
    <thetext>http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1318

The spec requires &apos;load&apos; but Opera/Firefox/Chrome fire &apos;error&apos;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70547</commentid>
    <comment_count>4</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-07-18 16:05:59 +0000</bug_when>
    <thetext>This bug was cloned to create bug 18039 as part of operation convergence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71562</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-07-27 02:13:31 +0000</bug_when>
    <thetext>Huh. bz, can you take a look at this and see if you have any insight? I think it was you who pointed out that in some cases you fire &apos;load&apos; before you have deeply inspected the image data (but I could be wrong).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71565</commentid>
    <comment_count>6</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-07-27 02:26:11 +0000</bug_when>
    <thetext>I believe that Gecko will fire load or error after it has all the image data but possibly before it&apos;s decoded it all.  In particular, it will decode some amount of data (there&apos;s a data size below which the decode is sync), then do the rest of decode async and fire the load or error, depending on which one is relevant.

I&apos;ll double-check whether my believe is correct.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71566</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-07-27 02:28:18 +0000</bug_when>
    <thetext>And in particular, there are various cases in which I think Gecko suppresses decoding indefinitely (until something asks for the decoded data).  And more in which we would like to do so.  It would be pretty unfortunate if the spec precluded this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71593</commentid>
    <comment_count>8</comment_count>
    <who name="Bobby Holley (:bholley)">bobbyholley</who>
    <bug_when>2012-07-27 07:42:07 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; I believe that Gecko will fire load or error after it has all the image data
&gt; but possibly before it&apos;s decoded it all.  In particular, it will decode some
&gt; amount of data (there&apos;s a data size below which the decode is sync), then do
&gt; the rest of decode async and fire the load or error, depending on which one is
&gt; relevant.
&gt; 
&gt; I&apos;ll double-check whether my believe is correct.

Yes. The callback in which we fire onerror is unfortunately named OnStopDecode (jdm will fix this soon), but it&apos;s fired at the end of the load.

I investigated this behavior back when I was implementing decode-on-draw. Here&apos;s the relevant comment:

https://bugzilla.mozilla.org/show_bug.cgi?id=435296#c27

Here&apos;s the most relevant bit.

&gt; If this instantiation fails, we fire &quot;onerror&quot;. If it succeeds, we fire
&gt; &quot;onload&quot;. Thus, the only cases where we fire onerror are:
&gt; 1) The URL is somehow invalid or ruffles the feathers of the content policy
&gt; 2) A network error occurs before all the data arrives
&gt; 3) The first few (sniffed) bytes give us an invalid mimetype, an we balk on
&gt; decoder instantiation
&gt;
&gt; Otherwise, we fire onload once the network request completes. Furthermore, I
&gt; did some testing and this exact behavior is replicated in safari and chrome
&gt; (I don&apos;t have IE handy).


(In reply to comment #7)
&gt; And in particular, there are various cases in which I think Gecko suppresses
&gt; decoding indefinitely (until something asks for the decoded data).  And more in
&gt; which we would like to do so.  It would be pretty unfortunate if the spec
&gt; precluded this.

Indeed. It would kill decode-on-draw.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73018</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-08-29 21:56:32 +0000</bug_when>
    <thetext>So, what do we want to do here? Fire &apos;load&apos; for corrupt images, or fire both &apos;load&apos; and &apos;error&apos; for those images?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73446</commentid>
    <comment_count>10</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-07 20:10:12 +0000</bug_when>
    <thetext>bz suggests that we should just fire onload once we have dimension metadata, and not ever fire onerror for corrupted image data. I&apos;ll move the spec to that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73449</commentid>
    <comment_count>11</comment_count>
    <who name="L. David Baron (Mozilla)">dbaron</who>
    <bug_when>2012-09-07 21:52:06 +0000</bug_when>
    <thetext>(In reply to comment #10)
&gt; bz suggests that we should just fire onload once we have dimension metadata,

Presumably you mean &quot;as long as you have dimension metadata&quot;, but once the image is fully loaded (corrupt or not)?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73816</commentid>
    <comment_count>12</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-13 23:48:29 +0000</bug_when>
    <thetext>dbaron: As soon as all the bytes are retrieved and enough of the image has been decoded that you have image data, but not later (in particular, not requiring the pixel data itself to be decoded at all).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73852</commentid>
    <comment_count>13</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2012-09-14 07:50:28 +0000</bug_when>
    <thetext>I guess drawImage() needs to block waiting for the image to be decoded, right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73875</commentid>
    <comment_count>14</comment_count>
    <who name="Bobby Holley (:bholley)">bobbyholley</who>
    <bug_when>2012-09-14 10:36:05 +0000</bug_when>
    <thetext>(In reply to comment #13)
&gt; I guess drawImage() needs to block waiting for the image to be decoded, right?

If you defer image decoding (an optimization that this spec change allows, but does not require), then yes. Mozilla has a &quot;SyncDecode()&quot; function on images that we use for drawImage and a few other miscellaneous cases.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73949</commentid>
    <comment_count>15</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-09-15 02:09:59 +0000</bug_when>
    <thetext>This doesn&apos;t change drawImage() behaviour. It&apos;s needed to be able to do sync decode for a while.

Original bug is now fixed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>73950</commentid>
    <comment_count>16</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-09-15 02:10:04 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r7349.
Check-in comment: Make onerror on &lt;img&gt; only fire when onload doesn&apos;t fire.
http://html5.org/tools/web-apps-tracker?from=7348&amp;to=7349</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>