Bug 185236 part 2. Make sure to remove our SheetLoadData from mPostedEvents before calling SheetComplete on it, so that checking for pending loads from inside SheetComplete will work correctly. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 26 Sep 2011 17:26:05 -0400
changeset 77614 465554cdfbcc1785afd3804b7ba711add1ecdd32
parent 77613 bb87ceae27a5d682c2f28450300e31438d95d096
child 77615 2c05e937de5d8eb6002eb74e8b4a6f30cc303887
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerspeterv
bugs185236
milestone9.0a1
Bug 185236 part 2. Make sure to remove our SheetLoadData from mPostedEvents before calling SheetComplete on it, so that checking for pending loads from inside SheetComplete will work correctly. r=peterv
layout/style/Loader.cpp
layout/style/Loader.h
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -2173,25 +2173,29 @@ Loader::PostLoadEvent(nsIURI* aURI,
 
 void
 Loader::HandleLoadEvent(SheetLoadData* aEvent)
 {
   // XXXbz can't assert this yet.... May not have an observer because
   // we're unblocking the parser
   // NS_ASSERTION(aEvent->mObserver, "Must have observer");
   NS_ASSERTION(aEvent->mSheet, "Must have sheet");
+
+  // Very important: this needs to come before the SheetComplete call
+  // below, so that HasPendingLoads() will test true as needed under
+  // notifications we send from that SheetComplete call.
+  mPostedEvents.RemoveElement(aEvent);
+
   if (!aEvent->mIsCancelled) {
     // SheetComplete will call Release(), so give it a reference to do
     // that with.
     NS_ADDREF(aEvent);
     SheetComplete(aEvent, NS_OK);
   }
 
-  mPostedEvents.RemoveElement(aEvent);
-
   if (mDocument) {
     mDocument->UnblockOnload(PR_TRUE);
   }
 }
 
 static PLDHashOperator
 StopLoadingSheetCallback(URIAndPrincipalHashKey* aKey,
                          SheetLoadData*& aData,
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -467,16 +467,17 @@ private:
   // some.  Allocate some storage, what the hell.
   nsAutoTArray<SheetLoadData*, 8> mParsingDatas;
 
   // The array of posted stylesheet loaded events (SheetLoadDatas) we have.
   // Note that these are rare.
   LoadDataArray     mPostedEvents;
 
   // Our array of "global" observers
+  // XXXbz these are strong refs; should we be cycle collecting CSS loaders?
   nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver> > mObservers;
 
   // the load data needs access to the document...
   nsIDocument*      mDocument;  // the document we live for
 
   // Refcounting
   nsAutoRefCnt      mRefCnt;
   NS_DECL_OWNINGTHREAD