rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, nsnull, NS_GET_IID(nsINameSpaceManager), (void**) &gNameSpaceManager); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager"); if (NS_FAILED(rv)) return rv;
static const PRInt32 kInitialSize = (NS_SIZE_IN_HEAP(sizeof(ClusterEntry)) + NS_SIZE_IN_HEAP(sizeof(SupportEntry)) + NS_SIZE_IN_HEAP(sizeof(BindingEntry))) * kNumResourceElements + (NS_SIZE_IN_HEAP(MatchSet::kEntrySize) + NS_SIZE_IN_HEAP(MatchSet::kIndexSize)) * kNumResourceElements;
nsXULTemplateBuilder::Init(){    if (gRefCnt++ == 0) {        nsXULAtoms::AddRef();        kTrueStr.AssignWithConversion("true");        kFalseStr.AssignWithConversion("false");        nsresult rv;        // Register the XUL and RDF namespaces: these'll just retrieve        // the IDs if they've already been registered by someone else.        rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID,                                                nsnull,                                                NS_GET_IID(nsINameSpaceManager),                                                (void**) &gNameSpaceManager);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager");        if (NS_FAILED(rv)) return rv;        // XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp        static const char kXULNameSpaceURI[]            = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";        static const char kRDFNameSpaceURI[]            = RDF_NAMESPACE_URI;        rv = gNameSpaceManager->RegisterNameSpace(NS_ConvertASCIItoUCS2(kXULNameSpaceURI), kNameSpaceID_XUL);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace");        if (NS_FAILED(rv)) return rv;        rv = gNameSpaceManager->RegisterNameSpace(NS_ConvertASCIItoUCS2(kRDFNameSpaceURI), kNameSpaceID_RDF);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace");        if (NS_FAILED(rv)) return rv;        // Initialize the global shared reference to the service        // manager and get some shared resource objects.        rv = nsServiceManager::GetService(kRDFServiceCID,                                          NS_GET_IID(nsIRDFService),                                          (nsISupports**) &gRDFService);        if (NS_FAILED(rv)) return rv;        gRDFService->GetResource(NC_NAMESPACE_URI "Title",   &kNC_Title);        gRDFService->GetResource(NC_NAMESPACE_URI "child",   &kNC_child);        gRDFService->GetResource(NC_NAMESPACE_URI "Column",  &kNC_Column);        gRDFService->GetResource(NC_NAMESPACE_URI "Folder",  &kNC_Folder);        gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf);        gRDFService->GetResource(XUL_NAMESPACE_URI "element",    &kXUL_element);        rv = nsServiceManager::GetService(kRDFContainerUtilsCID,                                          NS_GET_IID(nsIRDFContainerUtils),                                          (nsISupports**) &gRDFContainerUtils);        if (NS_FAILED(rv)) return rv;        rv = nsServiceManager::GetService(kXULSortServiceCID,                                          NS_GET_IID(nsIXULSortService),                                          (nsISupports**) &gXULSortService);        if (NS_FAILED(rv)) return rv;        rv = nsComponentManager::CreateInstance(kHTMLElementFactoryCID,                                                nsnull,                                                NS_GET_IID(nsIElementFactory),                                                (void**) &gHTMLElementFactory);        if (NS_FAILED(rv)) return rv;        rv = nsComponentManager::CreateInstance(kXMLElementFactoryCID,                                                nsnull,                                                NS_GET_IID(nsIElementFactory),                                                (void**) &gXMLElementFactory);        if (NS_FAILED(rv)) return rv;        rv = nsServiceManager::GetService(kXULContentUtilsCID,                                          NS_GET_IID(nsIXULContentUtils),                                          (nsISupports**) &gXULUtils);        if (NS_FAILED(rv)) return rv;    }#ifdef PR_LOGGING    if (! gLog)        gLog = PR_NewLogModule("nsXULTemplateBuilder");#endif    return NS_OK;}