diff --git a/htmlparser/src/nsExpatTokenizer.cpp b/htmlparser/src/nsExpatTokenizer.cpp
index dacc83b4bd8..035743efc1d 100644
--- a/htmlparser/src/nsExpatTokenizer.cpp
+++ b/htmlparser/src/nsExpatTokenizer.cpp
@@ -39,6 +39,8 @@
#endif
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
+#include "nsSpecialSystemDirectory.h"
+#include "nsIURL.h"
/************************************************************************
And now for the main class -- nsExpatTokenizer...
@@ -48,6 +50,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID);
static NS_DEFINE_IID(kHTMLTokenizerIID, NS_HTMLTOKENIZER_IID);
static NS_DEFINE_IID(kClassIID, NS_EXPATTOKENIZER_IID);
+
#ifndef NECKO
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
@@ -59,6 +62,7 @@ static nsDeque* gTokenDeque=0;
static XML_Parser gExpatParser=0;
static const char* kDocTypeDeclPrefix = "GetScheme(&scheme);
+ if (NS_SUCCEEDED(res) && nsnull != scheme) {
+ if (PL_strcmp(scheme, kChromeProtocol) == 0)
+ isLoadable = PR_TRUE;
+ nsCRT::free(scheme);
+ }
+
+ // If the url is not a chrome url, check to see if a DTD file of the same name
+ // exists in the special DTD directory
+ if (!isLoadable) {
+ nsCOMPtr dtdURL;
+ dtdURL = do_QueryInterface(*aDTD, &res);
+ if (NS_SUCCEEDED(res)) {
+ char* fileName = nsnull;
+ res = dtdURL->GetFileName(&fileName);
+ if (NS_SUCCEEDED(res) && nsnull != fileName) {
+ nsSpecialSystemDirectory dtdPath(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
+ nsString path(kDTDDirectory);
+ path.Append(fileName);
+ dtdPath += path;
+ if (dtdPath.Exists()) {
+ // The DTD was found in the local DTD directory.
+ // Set aDTD to a file: url pointing to the local DTD
+ nsFileURL dtdFile(dtdPath);
+ nsCOMPtr dtdURI;
+ res = NS_NewURI(getter_AddRefs(dtdURI), dtdFile.GetURLString());
+ if (NS_SUCCEEDED(res) && nsnull != dtdURI) {
+ NS_IF_RELEASE(*aDTD);
+ *aDTD = dtdURI;
+ NS_ADDREF(*aDTD);
+ isLoadable = PR_TRUE;
+ }
+ }
+ nsCRT::free(fileName);
+ }
+ }
+ }
+
+ return isLoadable;
+}
+
nsresult
nsExpatTokenizer::OpenInputStream(const nsString& aURLStr,
const nsString& aBaseURL,
@@ -539,12 +602,7 @@ nsExpatTokenizer::OpenInputStream(const nsString& aURLStr,
nsCOMPtr uri = nsnull;
rv = NS_NewURI(getter_AddRefs(uri), aURLStr, baseURI);
if (NS_SUCCEEDED(rv) && nsnull != uri) {
- char* scheme = nsnull;
- rv = uri->GetScheme(&scheme);
- if (NS_SUCCEEDED(rv) &&
- nsnull != scheme &&
- PL_strcmp(scheme, kChromeProtocol) == 0 )
- {
+ if (IsLoadableDTD((nsIURI**) &uri)) {
rv = NS_OpenURI(in, uri);
char* absURL = nsnull;
uri->GetSpec(&absURL);
@@ -554,7 +612,6 @@ nsExpatTokenizer::OpenInputStream(const nsString& aURLStr,
else {
rv = NS_ERROR_NOT_IMPLEMENTED;
}
- if (scheme) nsCRT::free(scheme);
}
}
#endif // NECKO
@@ -632,7 +689,7 @@ int nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
if (NS_SUCCEEDED(rv) && nsnull != in) {
PRUint32 retLen = 0;
PRUnichar *uniBuf = nsnull;
- rv = LoadStream(in, uniBuf, retLen);
+ rv = LoadStream(in, uniBuf, retLen);
// Pass the buffer to expat for parsing
if (NS_SUCCEEDED(rv) && nsnull != uniBuf) {
@@ -649,7 +706,7 @@ int nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
XML_ParserFree(entParser);
}
- PR_FREEIF(uniBuf);
+ PR_FREEIF(uniBuf);
}
}
#else /* ! XML_DTD */
diff --git a/parser/htmlparser/src/nsExpatTokenizer.cpp b/parser/htmlparser/src/nsExpatTokenizer.cpp
index dacc83b4bd8..035743efc1d 100644
--- a/parser/htmlparser/src/nsExpatTokenizer.cpp
+++ b/parser/htmlparser/src/nsExpatTokenizer.cpp
@@ -39,6 +39,8 @@
#endif
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
+#include "nsSpecialSystemDirectory.h"
+#include "nsIURL.h"
/************************************************************************
And now for the main class -- nsExpatTokenizer...
@@ -48,6 +50,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITokenizerIID, NS_ITOKENIZER_IID);
static NS_DEFINE_IID(kHTMLTokenizerIID, NS_HTMLTOKENIZER_IID);
static NS_DEFINE_IID(kClassIID, NS_EXPATTOKENIZER_IID);
+
#ifndef NECKO
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
@@ -59,6 +62,7 @@ static nsDeque* gTokenDeque=0;
static XML_Parser gExpatParser=0;
static const char* kDocTypeDeclPrefix = "GetScheme(&scheme);
+ if (NS_SUCCEEDED(res) && nsnull != scheme) {
+ if (PL_strcmp(scheme, kChromeProtocol) == 0)
+ isLoadable = PR_TRUE;
+ nsCRT::free(scheme);
+ }
+
+ // If the url is not a chrome url, check to see if a DTD file of the same name
+ // exists in the special DTD directory
+ if (!isLoadable) {
+ nsCOMPtr dtdURL;
+ dtdURL = do_QueryInterface(*aDTD, &res);
+ if (NS_SUCCEEDED(res)) {
+ char* fileName = nsnull;
+ res = dtdURL->GetFileName(&fileName);
+ if (NS_SUCCEEDED(res) && nsnull != fileName) {
+ nsSpecialSystemDirectory dtdPath(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
+ nsString path(kDTDDirectory);
+ path.Append(fileName);
+ dtdPath += path;
+ if (dtdPath.Exists()) {
+ // The DTD was found in the local DTD directory.
+ // Set aDTD to a file: url pointing to the local DTD
+ nsFileURL dtdFile(dtdPath);
+ nsCOMPtr dtdURI;
+ res = NS_NewURI(getter_AddRefs(dtdURI), dtdFile.GetURLString());
+ if (NS_SUCCEEDED(res) && nsnull != dtdURI) {
+ NS_IF_RELEASE(*aDTD);
+ *aDTD = dtdURI;
+ NS_ADDREF(*aDTD);
+ isLoadable = PR_TRUE;
+ }
+ }
+ nsCRT::free(fileName);
+ }
+ }
+ }
+
+ return isLoadable;
+}
+
nsresult
nsExpatTokenizer::OpenInputStream(const nsString& aURLStr,
const nsString& aBaseURL,
@@ -539,12 +602,7 @@ nsExpatTokenizer::OpenInputStream(const nsString& aURLStr,
nsCOMPtr uri = nsnull;
rv = NS_NewURI(getter_AddRefs(uri), aURLStr, baseURI);
if (NS_SUCCEEDED(rv) && nsnull != uri) {
- char* scheme = nsnull;
- rv = uri->GetScheme(&scheme);
- if (NS_SUCCEEDED(rv) &&
- nsnull != scheme &&
- PL_strcmp(scheme, kChromeProtocol) == 0 )
- {
+ if (IsLoadableDTD((nsIURI**) &uri)) {
rv = NS_OpenURI(in, uri);
char* absURL = nsnull;
uri->GetSpec(&absURL);
@@ -554,7 +612,6 @@ nsExpatTokenizer::OpenInputStream(const nsString& aURLStr,
else {
rv = NS_ERROR_NOT_IMPLEMENTED;
}
- if (scheme) nsCRT::free(scheme);
}
}
#endif // NECKO
@@ -632,7 +689,7 @@ int nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
if (NS_SUCCEEDED(rv) && nsnull != in) {
PRUint32 retLen = 0;
PRUnichar *uniBuf = nsnull;
- rv = LoadStream(in, uniBuf, retLen);
+ rv = LoadStream(in, uniBuf, retLen);
// Pass the buffer to expat for parsing
if (NS_SUCCEEDED(rv) && nsnull != uniBuf) {
@@ -649,7 +706,7 @@ int nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
XML_ParserFree(entParser);
}
- PR_FREEIF(uniBuf);
+ PR_FREEIF(uniBuf);
}
}
#else /* ! XML_DTD */