Backout changeset e40649461b57 due to crashes

This commit is contained in:
Ryan Flint 2009-01-13 17:53:04 -05:00
parent 64c25a9d72
commit 4c0a23f3e3

View File

@ -319,10 +319,7 @@ public:
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); }
@ -334,23 +331,19 @@ private:
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()
@ -373,33 +366,10 @@ nsXBLStreamListener::OnDataAvailable(nsIRequest *request, nsISupports* aCtxt, ns
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);
if (mInner)
return mInner->OnStartRequest(request, aCtxt);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -448,7 +418,7 @@ nsXBLStreamListener::Load(nsIDOMEvent* aEvent)
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");
}
@ -1223,31 +1193,14 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
// 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;
@ -1270,12 +1223,26 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
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)
@ -1296,6 +1263,9 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
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);
}
@ -1303,16 +1273,6 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
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));