Bug 610956. Don't set up loadListener as a shutdown observer until we're sure we're doing a load. r=roc a=roc
☠☠ backed out by 2b08079f0ecd ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 15 Nov 2010 12:25:38 +1300
changeset 57491 c3a14297dff8c5d54e51c76c6dd90288d2500998
parent 57490 ba950e2f4066b65ff168a2a291f75a78b8f1abb2
child 57493 4988b81e8474e31586839c6c618eeaac462144a3
child 57494 2b08079f0ecd3c29eb9f8f341fff761f0c09efc7
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersroc, roc
bugs610956
milestone2.0b8pre
Bug 610956. Don't set up loadListener as a shutdown observer until we're sure we're doing a load. r=roc a=roc
content/html/content/src/nsHTMLMediaElement.cpp
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -956,19 +956,16 @@ nsresult nsHTMLMediaElement::LoadResourc
   // cycle which is manually broken in the listener's OnStartRequest method
   // after it is finished with the element. The cycle will also be
   // broken if we get a shutdown notification before OnStartRequest fires.
   // Necko guarantees that OnStartRequest will eventually fire if we
   // don't shut down first.
   nsRefPtr<MediaLoadListener> loadListener = new MediaLoadListener(this);
   if (!loadListener) return NS_ERROR_OUT_OF_MEMORY;
 
-  // loadListener will be unregistered either on shutdown or when
-  // OnStartRequest fires.
-  nsContentUtils::RegisterShutdownObserver(loadListener);
   mChannel->SetNotificationCallbacks(loadListener);
 
   nsCOMPtr<nsIStreamListener> listener;
   if (ShouldCheckAllowOrigin()) {
     nsCrossSiteListenerProxy* crossSiteListener =
       new nsCrossSiteListenerProxy(loadListener,
                                    NodePrincipal(),
                                    mChannel,
@@ -1008,16 +1005,20 @@ nsresult nsHTMLMediaElement::LoadResourc
     // be destroyed.
     mChannel = nsnull;
     return rv;
   }
 
   // Else the channel must be open and starting to download. If it encounters
   // a non-catastrophic failure, it will set a new task to continue loading
   // another candidate.
+
+  // loadListener will be unregistered either on shutdown or when
+  // OnStartRequest for the channel we just opened fires.
+  nsContentUtils::RegisterShutdownObserver(loadListener);
   return NS_OK;
 }
 
 nsresult nsHTMLMediaElement::LoadWithChannel(nsIChannel *aChannel,
                                              nsIStreamListener **aListener)
 {
   NS_ENSURE_ARG_POINTER(aChannel);
   NS_ENSURE_ARG_POINTER(aListener);