Merge backout
authorRyan Flint <rflint@ryanflint.com>
Tue, 13 Jan 2009 17:57:22 -0500
changeset 23632 7165ce2d87c75d6dfab2fa9c60ffcae718dbe4c5
parent 23630 51bc0497789623c9fc40e039d00ef71a4bf1dad7 (current diff)
parent 23631 a05af26637272eddfd49b7793db9f98509296737 (diff)
child 23634 1d21f44cf01ca82c6aaad6eac97449b543704ec9
push id4647
push userrflint@ryanflint.com
push dateTue, 13 Jan 2009 22:58:24 +0000
treeherdermozilla-central@7165ce2d87c7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.2a1pre
Merge backout
--- a/content/xbl/src/nsXBLService.cpp
+++ b/content/xbl/src/nsXBLService.cpp
@@ -314,48 +314,41 @@ public:
 
   NS_IMETHOD Load(nsIDOMEvent* aEvent);
   NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent) { return NS_OK; }
   NS_IMETHOD Unload(nsIDOMEvent* aEvent) { return NS_OK; }
   NS_IMETHOD Abort(nsIDOMEvent* aEvent) { return NS_OK; }
   NS_IMETHOD Error(nsIDOMEvent* aEvent) { return NS_OK; }
   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; }
 
-  nsXBLStreamListener(nsXBLService* aXBLService,
-                      nsIDocument* aBoundDocument,
-                      nsIXMLContentSink* aSink,
-                      nsIDocument* aBindingDocument);
+  nsXBLStreamListener(nsXBLService* aXBLService, nsIStreamListener* aInner, nsIDocument* aDocument);
   ~nsXBLStreamListener();
 
   void AddRequest(nsXBLBindingRequest* aRequest) { mBindingRequests.AppendElement(aRequest); }
   PRBool HasRequest(nsIURI* aURI, nsIContent* aBoundElement);
 
 private:
   nsXBLService* mXBLService; // [WEAK]
 
   nsCOMPtr<nsIStreamListener> mInner;
   nsAutoVoidArray mBindingRequests;
   
-  nsCOMPtr<nsIWeakReference> mBoundDocument;
-  nsCOMPtr<nsIXMLContentSink> mSink; // Only set until OnStartRequest
-  nsCOMPtr<nsIDocument> mBindingDocument; // Only set until OnStartRequest
+  nsCOMPtr<nsIWeakReference> mDocument;
 };
 
 /* Implementation file */
 NS_IMPL_ISUPPORTS4(nsXBLStreamListener, nsIStreamListener, nsIRequestObserver, nsIDOMLoadListener, nsIDOMEventListener)
 
 nsXBLStreamListener::nsXBLStreamListener(nsXBLService* aXBLService,
-                                         nsIDocument* aBoundDocument,
-                                         nsIXMLContentSink* aSink,
-                                         nsIDocument* aBindingDocument)
-: mSink(aSink), mBindingDocument(aBindingDocument)
+                                         nsIStreamListener* aInner, nsIDocument* aDocument)
 {
   /* member initializers and constructor code */
   mXBLService = aXBLService;
-  mBoundDocument = do_GetWeakReference(aBoundDocument);
+  mInner = aInner;
+  mDocument = do_GetWeakReference(aDocument);
 }
 
 nsXBLStreamListener::~nsXBLStreamListener()
 {
   for (PRInt32 i = 0; i < mBindingRequests.Count(); i++) {
     nsXBLBindingRequest* req = (nsXBLBindingRequest*)mBindingRequests.ElementAt(i);
     nsXBLBindingRequest::Destroy(mXBLService->mPool, req);
   }
@@ -368,43 +361,20 @@ nsXBLStreamListener::OnDataAvailable(nsI
   if (mInner)
     return mInner->OnDataAvailable(request, aCtxt, aInStr, aSourceOffset, aCount);
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsXBLStreamListener::OnStartRequest(nsIRequest* request, nsISupports* aCtxt)
 {
-  // Make sure we don't hold on to the sink and binding document past this point
-  nsCOMPtr<nsIXMLContentSink> sink;
-  mSink.swap(sink);
-  nsCOMPtr<nsIDocument> doc;
-  mBindingDocument.swap(doc);
-
-  nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
-  NS_ENSURE_TRUE(channel, NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsILoadGroup> group;
-  request->GetLoadGroup(getter_AddRefs(group));
-
-  nsresult rv = doc->StartDocumentLoad("loadAsInteractiveData",
-                                       channel,
-                                       group,
-                                       nsnull,
-                                       getter_AddRefs(mInner),
-                                       PR_TRUE,
-                                       sink);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // Make sure to add ourselves as a listener after StartDocumentLoad,
-  // since that resets the event listners on the document.
-  nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(doc));
-  target->AddEventListener(NS_LITERAL_STRING("load"), this, PR_FALSE);
-  
-  return mInner->OnStartRequest(request, aCtxt);
+  if (mInner)
+    return mInner->OnStartRequest(request, aCtxt);
+    
+  return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP 
 nsXBLStreamListener::OnStopRequest(nsIRequest* request, nsISupports* aCtxt, nsresult aStatus)
 {
   nsresult rv = NS_OK;
   if (mInner) {
      rv = mInner->OnStopRequest(request, aCtxt, aStatus);
@@ -443,17 +413,17 @@ nsXBLStreamListener::Load(nsIDOMEvent* a
   // Get the binding document; note that we don't hold onto it in this object
   // to avoid creating a cycle
   nsCOMPtr<nsIDOMEventTarget> target;
   aEvent->GetCurrentTarget(getter_AddRefs(target));
   nsCOMPtr<nsIDocument> bindingDocument = do_QueryInterface(target);
   NS_ASSERTION(bindingDocument, "Event not targeted at document?!");
 
   // See if we're still alive.
-  nsCOMPtr<nsIDocument> doc(do_QueryReferent(mBoundDocument));
+  nsCOMPtr<nsIDocument> doc(do_QueryReferent(mDocument));
   if (!doc) {
     NS_WARNING("XBL load did not complete until after document went away! Modal dialog bug?\n");
   }
   else {
     // We have to do a flush prior to notification of the document load.
     // This has to happen since the HTML content sink can be holding on
     // to notifications related to our children (e.g., if you bind to the
     // <body> tag) that result in duplication of content.  
@@ -1218,41 +1188,24 @@ nsresult
 nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoundDocument,
                                    nsIURI* aDocumentURI, nsIURI* aBindingURI, 
                                    PRBool aForceSyncLoad, nsIDocument** aResult)
 {
   nsresult rv = NS_OK;
   // Initialize our out pointer to nsnull
   *aResult = nsnull;
 
-  if (aForceSyncLoad) {
-    PRBool isLocalResource;
-    rv = NS_URIChainHasFlags(aBindingURI,
-                             nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
-                             &isLocalResource);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    if (!isLocalResource) {
-      NS_WARNING("Downgrading sync load to async one; that's what we'd get "
-                 "here anyway.");
-      aForceSyncLoad = PR_FALSE;
-    }
-  }
-          
-  // Now we have to load the binding file.
+  // Now we have to synchronously load the binding file.
+  // Create an XML content sink and a parser. 
   nsCOMPtr<nsILoadGroup> loadGroup;
   if (aBoundDocument)
     loadGroup = aBoundDocument->GetDocumentLoadGroup();
 
   // We really shouldn't have to force a sync load for anything here... could
   // we get away with not doing that?  Not sure.
-  // Alternately, should we just force sync loads for URI_IS_LOCAL_RESOURCE and
-  // remove the aForceSyncLoad flag altogether?
   if (IsChromeOrResourceURI(aDocumentURI))
     aForceSyncLoad = PR_TRUE;
 
   // Create document and contentsink and set them up.
   nsCOMPtr<nsIDocument> doc;
   rv = NS_NewXMLDocument(getter_AddRefs(doc));
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -1265,22 +1218,36 @@ nsXBLService::FetchBindingDocument(nsICo
   rv = NS_NewChannel(getter_AddRefs(channel), aDocumentURI, nsnull, loadGroup);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIInterfaceRequestor> sameOriginChecker = nsContentUtils::GetSameOriginChecker();
   NS_ENSURE_TRUE(sameOriginChecker, NS_ERROR_OUT_OF_MEMORY);
 
   channel->SetNotificationCallbacks(sameOriginChecker);
 
+  nsCOMPtr<nsIStreamListener> listener;
+  rv = doc->StartDocumentLoad("loadAsInteractiveData",
+                              channel,
+                              loadGroup,
+                              nsnull,
+                              getter_AddRefs(listener),
+                              PR_TRUE,
+                              xblSink);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   if (!aForceSyncLoad) {
     // We can be asynchronous
-    nsXBLStreamListener* xblListener =
-      new nsXBLStreamListener(this, aBoundDocument, xblSink, doc);
+    nsXBLStreamListener* xblListener = new nsXBLStreamListener(this, listener, aBoundDocument);
     NS_ENSURE_TRUE(xblListener,NS_ERROR_OUT_OF_MEMORY);
 
+    nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(doc));
+    target->AddEventListener(NS_LITERAL_STRING("load"),
+                             static_cast<nsIDOMLoadListener*>(xblListener),
+                             PR_FALSE);
+
     // Add ourselves to the list of loading docs.
     nsBindingManager *bindingManager;
     if (aBoundDocument)
       bindingManager = aBoundDocument->BindingManager();
     else
       bindingManager = nsnull;
 
     if (bindingManager)
@@ -1291,33 +1258,26 @@ nsXBLService::FetchBindingDocument(nsICo
                                                            aBindingURI,
                                                            aBoundElement);
     xblListener->AddRequest(req);
 
     // Now kick off the async read.
     rv = channel->AsyncOpen(xblListener, nsnull);
     if (NS_FAILED(rv)) {
       // Well, we won't be getting a load.  Make sure to clean up our stuff!
+      target->RemoveEventListener(NS_LITERAL_STRING("load"),
+                                  static_cast<nsIDOMLoadListener*>(xblListener),
+                                  PR_FALSE);
       if (bindingManager) {
         bindingManager->RemoveLoadingDocListener(aDocumentURI);
       }
     }
     return NS_OK;
   }
 
-  nsCOMPtr<nsIStreamListener> listener;
-  rv = doc->StartDocumentLoad("loadAsInteractiveData",
-                              channel,
-                              loadGroup,
-                              nsnull,
-                              getter_AddRefs(listener),
-                              PR_TRUE,
-                              xblSink);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   // Now do a blocking synchronous parse of the file.
   nsCOMPtr<nsIInputStream> in;
   rv = channel->Open(getter_AddRefs(in));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = nsSyncLoadService::PushSyncStreamToListener(in, listener, channel);
   NS_ENSURE_SUCCESS(rv, rv);