Bug 600020 - Don't dispatch error events for media loads on cancelled channels. r=roc
authorChris Pearce <chris@pearce.org.nz>
Wed, 04 May 2011 14:43:48 +1200
changeset 68932 eb15fab87e7e7b2bdfcbf19a8648543be3f892ab
parent 68931 1f0635e935d9a56880ea2f9ad4e3afaa1c8437c3
child 68933 c3c4c902e9cd9ccf3d0cd2bb470da53630a3066f
push id19804
push usercpearce@mozilla.com
push dateWed, 04 May 2011 03:02:38 +0000
treeherdermozilla-central@eb15fab87e7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs600020
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 600020 - Don't dispatch error events for media loads on cancelled channels. r=roc
content/html/content/src/nsHTMLMediaElement.cpp
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -249,24 +249,26 @@ class nsHTMLMediaElement::MediaLoadListe
   NS_DECL_NSIREQUESTOBSERVER
   NS_DECL_NSISTREAMLISTENER
   NS_DECL_NSICHANNELEVENTSINK
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIINTERFACEREQUESTOR
 
 public:
   MediaLoadListener(nsHTMLMediaElement* aElement)
-    : mElement(aElement)
+    : mElement(aElement),
+      mLoadID(aElement->GetCurrentLoadID())
   {
     NS_ABORT_IF_FALSE(mElement, "Must pass an element to call back");
   }
 
 private:
   nsRefPtr<nsHTMLMediaElement> mElement;
   nsCOMPtr<nsIStreamListener> mNextListener;
+  PRUint32 mLoadID;
 };
 
 NS_IMPL_ISUPPORTS5(nsHTMLMediaElement::MediaLoadListener, nsIRequestObserver,
                    nsIStreamListener, nsIChannelEventSink,
                    nsIInterfaceRequestor, nsIObserver)
 
 NS_IMETHODIMP
 nsHTMLMediaElement::MediaLoadListener::Observe(nsISupports* aSubject,
@@ -283,16 +285,23 @@ NS_IMETHODIMP nsHTMLMediaElement::MediaL
 {
   nsContentUtils::UnregisterShutdownObserver(this);
 
   // The element is only needed until we've had a chance to call
   // InitializeDecoderForChannel. So make sure mElement is cleared here.
   nsRefPtr<nsHTMLMediaElement> element;
   element.swap(mElement);
 
+  if (mLoadID != element->GetCurrentLoadID()) {
+    // The channel has been cancelled before we had a chance to create
+    // a decoder. Abort, don't dispatch an "error" event, as the new load
+    // may not be in an error state.
+    return NS_BINDING_ABORTED;
+  }
+
   // Don't continue to load if the request failed or has been canceled.
   nsresult rv;
   nsresult status;
   rv = aRequest->GetStatus(&status);
   NS_ENSURE_SUCCESS(rv, rv);
   if (NS_FAILED(status)) {
     if (element)
       element->NotifyLoadError();