From 57e13eb1a792c278161b759db4274465d6b0088f Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Tue, 14 Sep 1999 22:36:55 +0000 Subject: [PATCH] Bug 13121. Deal with XUL documents that are created _before_ local store is available (e.g., because they come up before a profile has been selected). --- content/xul/document/src/nsXULDocument.cpp | 19 ++++--- rdf/content/src/nsRDFXULBuilder.cpp | 13 +++-- rdf/content/src/nsXULDocument.cpp | 19 ++++--- rdf/datasource/src/nsLocalStore.cpp | 59 ++++++++-------------- 4 files changed, 53 insertions(+), 57 deletions(-) diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 5884d63218bf..ce7046e567cd 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -2058,14 +2058,15 @@ XULDocumentImpl::EndLoad() // Add the local store to the composite datasource. It's first // so that any local annotations will over-ride default values - // from the document. + // from the document. Note that we may not be able to get a + // local store if we don't yet have a profile. rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(mLocalStore)); - NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't create local data source"); - if (NS_FAILED(rv)) return rv; - rv = db->AddDataSource(mLocalStore); - NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't add local data source to db"); - if (NS_FAILED(rv)) return rv; + if (NS_SUCCEEDED(rv)) { + rv = db->AddDataSource(mLocalStore); + NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't add local data source to db"); + if (NS_FAILED(rv)) return rv; + } // Add the main document datasource to the content model builder rv = db->AddDataSource(mDocumentDataSource); @@ -3160,6 +3161,12 @@ XULDocumentImpl::Persist(const nsString& aID, const nsString& aAttr) nsresult XULDocumentImpl::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute) { + // First make sure we _have_ a local store to stuff the persited + // information into. (We might not have one if profile information + // hasn't been loaded yet...) + if (! mLocalStore) + return NS_OK; + nsresult rv; nsCOMPtr source; diff --git a/rdf/content/src/nsRDFXULBuilder.cpp b/rdf/content/src/nsRDFXULBuilder.cpp index 763f25dd93f9..1eab28b858ab 100644 --- a/rdf/content/src/nsRDFXULBuilder.cpp +++ b/rdf/content/src/nsRDFXULBuilder.cpp @@ -1397,13 +1397,12 @@ RDFXULBuilderImpl::CreateTemplateBuilder(nsIContent* aElement, return rv; } - // Add the local store as the first data source in the db. - { - nsCOMPtr localstore; - rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(localstore)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get local store"); - if (NS_FAILED(rv)) return rv; - + // Add the local store as the first data source in the db. Note + // that we _might_ not be able to get a local store if we haven't + // got a profile to read from yet. + nsCOMPtr localstore; + rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(localstore)); + if (NS_SUCCEEDED(rv)) { rv = db->AddDataSource(localstore); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add local store to db"); if (NS_FAILED(rv)) return rv; diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index 5884d63218bf..ce7046e567cd 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -2058,14 +2058,15 @@ XULDocumentImpl::EndLoad() // Add the local store to the composite datasource. It's first // so that any local annotations will over-ride default values - // from the document. + // from the document. Note that we may not be able to get a + // local store if we don't yet have a profile. rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(mLocalStore)); - NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't create local data source"); - if (NS_FAILED(rv)) return rv; - rv = db->AddDataSource(mLocalStore); - NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't add local data source to db"); - if (NS_FAILED(rv)) return rv; + if (NS_SUCCEEDED(rv)) { + rv = db->AddDataSource(mLocalStore); + NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't add local data source to db"); + if (NS_FAILED(rv)) return rv; + } // Add the main document datasource to the content model builder rv = db->AddDataSource(mDocumentDataSource); @@ -3160,6 +3161,12 @@ XULDocumentImpl::Persist(const nsString& aID, const nsString& aAttr) nsresult XULDocumentImpl::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aAttribute) { + // First make sure we _have_ a local store to stuff the persited + // information into. (We might not have one if profile information + // hasn't been loaded yet...) + if (! mLocalStore) + return NS_OK; + nsresult rv; nsCOMPtr source; diff --git a/rdf/datasource/src/nsLocalStore.cpp b/rdf/datasource/src/nsLocalStore.cpp index c8096cb81c18..2ac4d9d4777c 100644 --- a/rdf/datasource/src/nsLocalStore.cpp +++ b/rdf/datasource/src/nsLocalStore.cpp @@ -285,25 +285,23 @@ LocalStoreImpl::Init(const char *uri) nsresult LocalStoreImpl::Flush() { - nsCOMPtr remote = do_QueryInterface(mInner); - nsresult rv = NS_OK; - if (remote) - { - rv = remote->Flush(); - } - return(rv); + nsCOMPtr remote = do_QueryInterface(mInner); + NS_ASSERTION(remote != nsnull, "not an nsIRDFRemoteDataSource"); + if (! remote) + return NS_ERROR_UNEXPECTED; + + return remote->Flush(); } nsresult LocalStoreImpl::Refresh(PRBool sync) { - nsCOMPtr remote = do_QueryInterface(mInner); - nsresult rv = NS_OK; - if (remote) - { - rv = remote->Refresh(sync); - } - return NS_OK; // XXX Always return OK, even if we couldn't load the file. + nsCOMPtr remote = do_QueryInterface(mInner); + NS_ASSERTION(remote != nsnull, "not an nsIRDFRemoteDataSource"); + if (! remote) + return NS_ERROR_UNEXPECTED; + + return remote->Refresh(sync); } nsresult @@ -315,24 +313,13 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); nsresult rv; // Look for localstore.rdf in the current profile - // directory. This is as convoluted as it seems because we - // want to 1) not break viewer (which has no profiles), and 2) - // still deal reasonably (in the short term) when no - // localstore.rdf is installed in the profile directory. + // directory. Bomb if we can't find it. + NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv); + if (NS_FAILED(rv)) return rv; - nsFileSpec spec; - do { - NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv); - if (NS_FAILED(rv)) break; - - rv = profile->GetCurrentProfileDir(&spec); - if (NS_FAILED(rv)) break; - } while (0); - - if (NS_FAILED(rv)) { - // XXX We should probably tell the user that we're doing this. - spec = nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory); - } + nsFileSpec spec; + rv = profile->GetCurrentProfileDir(&spec); + if (NS_FAILED(rv)) return rv; spec += "localstore.rdf"; @@ -358,18 +345,14 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); if (NS_FAILED(rv)) return rv; // register this as a named data source with the RDF service - nsIRDFService* rdf; - rv = nsServiceManager::GetService(kRDFServiceCID, - nsIRDFService::GetIID(), - (nsISupports**) &rdf); - + NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); if (NS_FAILED(rv)) return rv; rv = rdf->RegisterDataSource(this, PR_FALSE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register local store"); + if (NS_FAILED(rv)) return rv; - nsServiceManager::ReleaseService(kRDFServiceCID, rdf); - return rv; + return NS_OK; }