Backing out waterson to fix (78718), chrome restart blocker. Thanks to sspitzer for finding this. r=sspitzer,waterson

This commit is contained in:
mcafee%netscape.com 2001-05-03 21:11:45 +00:00
Родитель e931a790bc
Коммит 8293f50840
1 изменённых файлов: 43 добавлений и 48 удалений

Просмотреть файл

@ -73,10 +73,8 @@
*/ */
#include "nsIFileStreams.h" #include "nsFileSpec.h"
#include "nsIOutputStream.h" #include "nsFileStream.h"
#include "nsIFile.h"
#include "nsIFileChannel.h"
#include "nsIDTD.h" #include "nsIDTD.h"
#include "nsIRDFPurgeableDataSource.h" #include "nsIRDFPurgeableDataSource.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
@ -241,12 +239,7 @@ protected:
NameSpaceMap* mNameSpaces; NameSpaceMap* mNameSpaces;
nsCOMPtr<nsIURI> mURL; nsCOMPtr<nsIURI> mURL;
nsCOMPtr<nsIStreamListener> mParser; nsCOMPtr<nsIStreamListener> mParser;
char* mURLSpec;
/**
* Cached copy of the original URL spec, kept around because
* opening the URL to read it may cause it to be re-written.
*/
nsCString mOriginalURLSpec;
// pseudo-constants // pseudo-constants
static PRInt32 gRefCnt; static PRInt32 gRefCnt;
@ -491,7 +484,8 @@ RDFXMLDataSourceImpl::RDFXMLDataSourceImpl(void)
mIsWritable(PR_TRUE), mIsWritable(PR_TRUE),
mIsDirty(PR_FALSE), mIsDirty(PR_FALSE),
mLoadState(eLoadState_Unloaded), mLoadState(eLoadState_Unloaded),
mNameSpaces(nsnull) mNameSpaces(nsnull),
mURLSpec(nsnull)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
@ -565,6 +559,9 @@ RDFXMLDataSourceImpl::~RDFXMLDataSourceImpl(void)
NS_RELEASE(obs); NS_RELEASE(obs);
} }
if (mURLSpec)
PL_strfree(mURLSpec);
while (mNameSpaces) { while (mNameSpaces) {
NameSpaceMap* doomed = mNameSpaces; NameSpaceMap* doomed = mNameSpaces;
mNameSpaces = mNameSpaces->Next; mNameSpaces = mNameSpaces->Next;
@ -711,16 +708,20 @@ static const char kResourceURIPrefix[] = "resource:";
// XXX this is a hack: any "file:" URI is considered writable. All // XXX this is a hack: any "file:" URI is considered writable. All
// others are considered read-only. // others are considered read-only.
nsXPIDLCString realURL; char* realURL;
mURL->GetSpec(getter_Copies(realURL)); mURL->GetSpec(&realURL);
if ((PL_strncmp(realURL.get(), kFileURIPrefix, sizeof(kFileURIPrefix) - 1) != 0) && if ((PL_strncmp(realURL, kFileURIPrefix, sizeof(kFileURIPrefix) - 1) != 0) &&
(PL_strncmp(realURL.get(), kResourceURIPrefix, sizeof(kResourceURIPrefix) - 1) != 0)) { (PL_strncmp(realURL, kResourceURIPrefix, sizeof(kResourceURIPrefix) - 1) != 0)) {
mIsWritable = PR_FALSE; mIsWritable = PR_FALSE;
} }
// XXX Keep a 'cached' copy of the URL; opening it may cause the // XXX Keep a 'cached' copy of the URL; opening it may cause the
// spec to be re-written. // spec to be re-written.
mOriginalURLSpec = realURL.get(); if (mURLSpec)
PL_strfree(mURLSpec);
mURLSpec = PL_strdup(realURL);
nsCRT::free(realURL);
rv = gRDFService->RegisterDataSource(this, PR_FALSE); rv = gRDFService->RegisterDataSource(this, PR_FALSE);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -733,10 +734,10 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::GetURI(char* *aURI) RDFXMLDataSourceImpl::GetURI(char* *aURI)
{ {
*aURI = nsnull; *aURI = nsnull;
if (mOriginalURLSpec.Length()) { if (mURLSpec) {
// XXX We don't use the mURL, because it might get re-written // XXX We don't use the mURL, because it might get re-written
// when it's actually opened. // when it's actually opened.
*aURI = nsXPIDLCString::Copy(mOriginalURLSpec.get()); *aURI = nsXPIDLCString::Copy(mURLSpec);
if (! *aURI) if (! *aURI)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
@ -862,12 +863,12 @@ RDFXMLDataSourceImpl::Flush(void)
if (!mIsWritable || !mIsDirty) if (!mIsWritable || !mIsDirty)
return NS_OK; return NS_OK;
NS_PRECONDITION(mOriginalURLSpec.Length(), "not initialized"); NS_PRECONDITION(mURLSpec != nsnull, "not initialized");
if (! mOriginalURLSpec.Length()) if (! mURLSpec)
return NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_INITIALIZED;
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] flush(%s)", this, mOriginalURLSpec.get())); ("rdfxml[%p] flush(%s)", this, mURLSpec));
nsresult rv; nsresult rv;
@ -883,25 +884,21 @@ RDFXMLDataSourceImpl::Flush(void)
} }
} }
// Is it a file? If so, we can write to it. Some day, it'd be nice // XXX Replace this with channels someday soon...
// if we didn't care what kind of stream this was... nsFileURL url(mURLSpec, PR_TRUE);
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mURL); nsFileSpec path(url);
if (fileURL) {
nsCOMPtr<nsIFile> file;
fileURL->GetFile(getter_AddRefs(file));
if (file) { nsOutputFileStream out(path);
nsCOMPtr<nsIOutputStream> out; if (! out.is_open())
NS_NewLocalFileOutputStream(getter_AddRefs(out), file); return NS_ERROR_FAILURE;
if (out) { nsCOMPtr<nsIOutputStream> outIStream = out.GetIStream();
rv = Serialize(out); if (NS_FAILED(rv = Serialize(outIStream)))
if (NS_FAILED(rv)) return rv; goto done;
}
}
}
mIsDirty = PR_FALSE; mIsDirty = PR_FALSE;
done:
return NS_OK; return NS_OK;
} }
@ -931,15 +928,13 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Refresh(PRBool aBlocking) RDFXMLDataSourceImpl::Refresh(PRBool aBlocking)
{ {
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] refresh(%s) %sblocking", this, ("rdfxml[%p] refresh(%s) %sblocking", this, mURLSpec, (aBlocking ? "" : "non")));
mOriginalURLSpec.get(), (aBlocking ? "" : "non")));
// If an asynchronous load is already pending, then just let it do // If an asynchronous load is already pending, then just let it do
// the honors. // the honors.
if (IsLoading()) { if (IsLoading()) {
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] refresh(%s) a load was pending", this, ("rdfxml[%p] refresh(%s) a load was pending", this, mURLSpec));
mOriginalURLSpec.get()));
if (aBlocking) { if (aBlocking) {
NS_WARNING("blocking load requested when async load pending"); NS_WARNING("blocking load requested when async load pending");
@ -1007,7 +1002,7 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::BeginLoad(void) RDFXMLDataSourceImpl::BeginLoad(void)
{ {
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] begin-load(%s)", this, mOriginalURLSpec.get())); ("rdfxml[%p] begin-load(%s)", this, mURLSpec));
mLoadState = eLoadState_Loading; mLoadState = eLoadState_Loading;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) { for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
@ -1023,7 +1018,7 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Interrupt(void) RDFXMLDataSourceImpl::Interrupt(void)
{ {
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] interrupt(%s)", this, mOriginalURLSpec.get())); ("rdfxml[%p] interrupt(%s)", this, mURLSpec));
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) { for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLSinkObserver* obs = nsIRDFXMLSinkObserver* obs =
@ -1038,7 +1033,7 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Resume(void) RDFXMLDataSourceImpl::Resume(void)
{ {
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] resume(%s)", this, mOriginalURLSpec.get())); ("rdfxml[%p] resume(%s)", this, mURLSpec));
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) { for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLSinkObserver* obs = nsIRDFXMLSinkObserver* obs =
@ -1053,7 +1048,7 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::EndLoad(void) RDFXMLDataSourceImpl::EndLoad(void)
{ {
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml[%p] end-load(%s)", this, mOriginalURLSpec.get())); ("rdfxml[%p] end-load(%s)", this, mURLSpec));
mLoadState = eLoadState_Loaded; mLoadState = eLoadState_Loaded;
@ -1380,7 +1375,7 @@ RDFXMLDataSourceImpl::SerializeAssertion(nsIOutputStream* aStream,
nsXPIDLCString docURI; nsXPIDLCString docURI;
nsAutoString uri = NS_ConvertUTF8toUCS2(s); nsAutoString uri = NS_ConvertUTF8toUCS2(s);
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mOriginalURLSpec.get()), uri); rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mURLSpec), uri);
rdf_EscapeAttributeValue(uri); rdf_EscapeAttributeValue(uri);
static const char kRDFResource1[] = " resource=\""; static const char kRDFResource1[] = " resource=\"";
@ -1471,7 +1466,7 @@ static const char kRDFDescription3[] = " </RDF:Description>\n";
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsAutoString uri = NS_ConvertUTF8toUCS2(s); nsAutoString uri = NS_ConvertUTF8toUCS2(s);
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mOriginalURLSpec.get()), uri); rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mURLSpec), uri);
rdf_EscapeAttributeValue(uri); rdf_EscapeAttributeValue(uri);
if (uri[0] == PRUnichar('#')) { if (uri[0] == PRUnichar('#')) {
@ -1557,7 +1552,7 @@ static const char kRDFLIResource1[] = " <RDF:li resource=\"";
static const char kRDFLIResource2[] = "\"/>\n"; static const char kRDFLIResource2[] = "\"/>\n";
nsAutoString uri = NS_ConvertUTF8toUCS2(s); nsAutoString uri = NS_ConvertUTF8toUCS2(s);
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mOriginalURLSpec.get()), uri); rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mURLSpec), uri);
rdf_EscapeAttributeValue(uri); rdf_EscapeAttributeValue(uri);
rdf_BlockingWrite(aStream, kRDFLIResource1, sizeof(kRDFLIResource1) - 1); rdf_BlockingWrite(aStream, kRDFLIResource1, sizeof(kRDFLIResource1) - 1);
@ -1626,7 +1621,7 @@ RDFXMLDataSourceImpl::SerializeContainer(nsIOutputStream* aStream,
nsXPIDLCString s; nsXPIDLCString s;
if (NS_SUCCEEDED(aContainer->GetValue( getter_Copies(s) ))) { if (NS_SUCCEEDED(aContainer->GetValue( getter_Copies(s) ))) {
nsAutoString uri = NS_ConvertUTF8toUCS2(s); nsAutoString uri = NS_ConvertUTF8toUCS2(s);
rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mOriginalURLSpec.get()), uri); rdf_MakeRelativeRef(NS_ConvertUTF8toUCS2(mURLSpec), uri);
rdf_EscapeAttributeValue(uri); rdf_EscapeAttributeValue(uri);