nsIAtom* defaultStyle = NS_NewAtom("default-style"); if (defaultStyle) { mDocument->GetHeaderData(defaultStyle, mPreferredStyle); NS_RELEASE(defaultStyle); }  nsIHTMLContentContainer* htmlContainer = nsnull; if (NS_SUCCEEDED(mDocument->QueryInterface(kIHTMLContentContainerIID, (void**)&htmlContainer))) { htmlContainer->GetCSSLoader(mCSSLoader); NS_RELEASE(htmlContainer); }
XULContentSinkImpl::Init(nsIDocument* aDocument, nsIRDFDataSource* aDataSource){    nsresult rv;    NS_PRECONDITION(aDocument != nsnull, "null ptr");    if (! aDocument)        return NS_ERROR_NULL_POINTER;        nsCOMPtr<nsIXULChildDocument> childDocument;    childDocument = do_QueryInterface(aDocument);    childDocument->GetFragmentRoot(&mFragmentRoot);    if (mFragmentRoot) {        // We're totally a subdocument. Find the root document's        // data source and make assertions there.              // First of all, find the root document.        nsIDocument* rootDocument = nsnull;         nsIDocument* currDocument;         currDocument = aDocument;         NS_ADDREF(currDocument);         while (currDocument != nsnull) {             NS_IF_RELEASE(rootDocument);             rootDocument = currDocument;             currDocument = rootDocument->GetParentDocument();         }         // Retrieve the root data source.         nsCOMPtr<nsIRDFDocument> rdfRootDoc;         rdfRootDoc = do_QueryInterface(rootDocument);         if (rdfRootDoc == nsnull) {             NS_ERROR("Root document of a XUL fragment is not an RDF doc.");             NS_RELEASE(rootDocument);             return NS_ERROR_INVALID_ARG;         }         nsCOMPtr<nsIRDFDataSource> docDataSource;         if (NS_FAILED(rv = rdfRootDoc->GetDocumentDataSource(getter_AddRefs(docDataSource)))) {             NS_ERROR("Unable to retrieve an RDF document's data source.");             NS_RELEASE(rootDocument);             return rv;         }         NS_IF_RELEASE(mDataSource);        mDataSource = docDataSource.get();        NS_ADDREF(mDataSource);    }    else {        NS_PRECONDITION(aDataSource != nsnull, "null ptr");        if (! aDataSource)            return NS_ERROR_NULL_POINTER;        NS_IF_RELEASE(mDataSource);        mDataSource = aDataSource;        NS_ADDREF(aDataSource);    }            NS_IF_RELEASE(mDocument);    mDocument = aDocument;    NS_ADDREF(mDocument);    NS_IF_RELEASE(mDocumentURL);    mDocumentURL = mDocument->GetDocumentURL();    if (NS_FAILED(rv = mDocument->GetNameSpaceManager(mNameSpaceManager))) {        NS_ERROR("unable to get document namespace manager");        return rv;    }    if (mFragmentRoot == nsnull) {        // XUL Namespace isn't registered if we're a root document.        // We need to register it.        rv = mNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace");    }    mState = eXULContentSinkState_InProlog;    return NS_OK;}