Bug 325426: Only use baseURI to resolve relative uris. r=bz sr=jst

This commit is contained in:
cvshook%sicking.cc 2006-03-08 05:01:16 +00:00
Родитель 2dfb698e3d
Коммит de7a063b91
10 изменённых файлов: 91 добавлений и 62 удалений

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

@ -85,9 +85,8 @@ class txXMLParser
#endif
nsresult
txParseDocumentFromURI(const nsAString& aHref, const nsAString& aReferrer,
const txXPathNode& aLoader, nsAString& aErrMsg,
txXPathNode** aResult)
txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
nsAString& aErrMsg, txXPathNode** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
@ -109,11 +108,7 @@ txParseDocumentFromURI(const nsAString& aHref, const nsAString& aReferrer,
nsCOMPtr<nsIHttpChannel> http = do_QueryInterface(channel);
if (http) {
nsCOMPtr<nsIURI> refUri;
NS_NewURI(getter_AddRefs(refUri), aReferrer);
if (refUri) {
http->SetReferrer(refUri);
}
http->SetReferrer(loaderUri);
http->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
NS_LITERAL_CSTRING("text/xml,application/xml,application/xhtml+xml,*/*;q=0.1"),
PR_FALSE);

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

@ -57,9 +57,8 @@ class txXPathNode;
* of the document aLoader.
*/
extern "C" nsresult
txParseDocumentFromURI(const nsAString& aHref, const nsAString& aReferrer,
const txXPathNode& aLoader, nsAString& aErrMsg,
txXPathNode** aResult);
txParseDocumentFromURI(const nsAString& aHref, const txXPathNode& aLoader,
nsAString& aErrMsg, txXPathNode** aResult);
#ifdef TX_EXE
/**

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

@ -474,13 +474,12 @@ txExecutionState::retrieveDocument(const nsAString& aUri)
if (!entry->mDocument) {
// open URI
nsAutoString errMsg, refUri;
// XXX we should get the referrer from the actual node
nsAutoString errMsg;
// XXX we should get the loader from the actual node
// triggering the load, but this will do for the time being
txXPathNodeUtils::getBaseURI(*mLoadedDocuments.mSourceDocument, refUri);
nsresult rv;
rv = txParseDocumentFromURI(aUri, refUri,
*mLoadedDocuments.mSourceDocument, errMsg,
rv = txParseDocumentFromURI(aUri, *mLoadedDocuments.mSourceDocument,
errMsg,
getter_Transfers(entry->mDocument));
if (NS_FAILED(rv) || !entry->mDocument) {

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

@ -799,24 +799,44 @@ void txSyncCompileObserver::onDoneCompiling(txStylesheetCompiler* aCompiler,
nsresult
TX_CompileStylesheet(nsIDOMNode* aNode, txStylesheet** aStylesheet)
{
nsCOMPtr<nsIDOMDocument> document;
aNode->GetOwnerDocument(getter_AddRefs(document));
if (!document) {
document = do_QueryInterface(aNode);
// If we move GetBaseURI to nsINode this can be simplified.
nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIDocument> doc;
nsCOMPtr<nsIContent> cont = do_QueryInterface(aNode);
if (cont) {
doc = cont->GetOwnerDoc();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
uri = cont->GetBaseURI();
}
else {
doc = do_QueryInterface(aNode);
NS_ASSERTION(doc, "aNode should be a doc or an element by now");
uri = doc->GetBaseURI();
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
nsIURI *uri = doc->GetBaseURI();
nsCAutoString baseURI;
uri->GetSpec(baseURI);
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
nsCAutoString spec;
uri->GetSpec(spec);
NS_ConvertUTF8toUTF16 baseURI(spec);
uri = doc->GetDocumentURI();
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
uri->GetSpec(spec);
NS_ConvertUTF8toUTF16 stylesheetURI(spec);
nsRefPtr<txSyncCompileObserver> obs = new txSyncCompileObserver();
NS_ENSURE_TRUE(obs, NS_ERROR_OUT_OF_MEMORY);
NS_ConvertUTF8toUTF16 base(baseURI);
nsRefPtr<txStylesheetCompiler> compiler =
new txStylesheetCompiler(base, obs);
new txStylesheetCompiler(stylesheetURI, obs);
NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY);
compiler->setBaseURI(baseURI);
nsresult rv = handleNode(aNode, compiler);
if (NS_FAILED(rv)) {
compiler->cancel(rv);

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

@ -50,20 +50,20 @@
#include "txStringUtils.h"
#include "txXSLTFunctions.h"
txStylesheetCompiler::txStylesheetCompiler(const nsAString& aBaseURI,
txStylesheetCompiler::txStylesheetCompiler(const nsAString& aStylesheetURI,
txACompileObserver* aObserver)
: txStylesheetCompilerState(aObserver)
{
mStatus = init(aBaseURI, nsnull, nsnull);
mStatus = init(aStylesheetURI, nsnull, nsnull);
}
txStylesheetCompiler::txStylesheetCompiler(const nsAString& aBaseURI,
txStylesheetCompiler::txStylesheetCompiler(const nsAString& aStylesheetURI,
txStylesheet* aStylesheet,
txListIterator* aInsertPosition,
txACompileObserver* aObserver)
: txStylesheetCompilerState(aObserver)
{
mStatus = init(aBaseURI, aStylesheet, aInsertPosition);
mStatus = init(aStylesheetURI, aStylesheet, aInsertPosition);
}
nsrefcnt
@ -83,6 +83,19 @@ txStylesheetCompiler::Release()
return mRefCnt;
}
void
txStylesheetCompiler::setBaseURI(const nsString& aBaseURI)
{
NS_ASSERTION(mObjectStack.size() == 1 && !mObjectStack.peek(),
"Execution already started");
if (NS_FAILED(mStatus)) {
return;
}
mElementContext->mBaseURI = aBaseURI;
}
nsresult
txStylesheetCompiler::startElement(PRInt32 aNamespaceID, nsIAtom* aLocalName,
nsIAtom* aPrefix,
@ -394,7 +407,7 @@ txStylesheetCompiler::doneLoading()
{
PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
("Compiler::doneLoading: %s\n",
NS_LossyConvertUTF16toASCII(mURI).get()));
NS_LossyConvertUTF16toASCII(mStylesheetURI).get()));
if (NS_FAILED(mStatus)) {
return mStatus;
}
@ -410,7 +423,7 @@ txStylesheetCompiler::cancel(nsresult aError, const PRUnichar *aErrorText,
{
PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
("Compiler::cancel: %s, module: %d, code %d\n",
NS_LossyConvertUTF16toASCII(mURI).get(),
NS_LossyConvertUTF16toASCII(mStylesheetURI).get(),
NS_ERROR_GET_MODULE(aError),
NS_ERROR_GET_CODE(aError)));
if (NS_SUCCEEDED(mStatus)) {
@ -439,8 +452,8 @@ txStylesheetCompiler::loadURI(const nsAString& aUri,
PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
("Compiler::loadURI forwards %s thru %s\n",
NS_LossyConvertUTF16toASCII(aUri).get(),
NS_LossyConvertUTF16toASCII(mURI).get()));
if (mURI.Equals(aUri)) {
NS_LossyConvertUTF16toASCII(mStylesheetURI).get()));
if (mStylesheetURI.Equals(aUri)) {
return NS_ERROR_XSLT_LOAD_RECURSION;
}
return mObserver ? mObserver->loadURI(aUri, aReferrerUri, aCompiler) :
@ -554,21 +567,21 @@ txStylesheetCompilerState::txStylesheetCompilerState(txACompileObserver* aObserv
}
nsresult
txStylesheetCompilerState::init(const nsAString& aBaseURI,
txStylesheetCompilerState::init(const nsAString& aStylesheetURI,
txStylesheet* aStylesheet,
txListIterator* aInsertPosition)
{
NS_ASSERTION(!aStylesheet || aInsertPosition,
"must provide insertposition if loading subsheet");
mURI = aBaseURI;
mStylesheetURI = aStylesheetURI;
// Check for fragment identifier of an embedded stylesheet.
PRInt32 fragment = aBaseURI.FindChar('#') + 1;
PRInt32 fragment = aStylesheetURI.FindChar('#') + 1;
if (fragment > 0) {
PRInt32 fragmentLength = aBaseURI.Length() - fragment;
PRInt32 fragmentLength = aStylesheetURI.Length() - fragment;
if (fragmentLength > 0) {
// This is really an embedded stylesheet, not just a
// "url#". We may want to unescape the fragment.
mTarget = Substring(aBaseURI, (PRUint32)fragment,
mTarget = Substring(aStylesheetURI, (PRUint32)fragment,
fragmentLength);
mEmbedStatus = eNeedEmbed;
mHandlerTable = gTxEmbedHandler;
@ -593,7 +606,7 @@ txStylesheetCompilerState::init(const nsAString& aBaseURI,
mIsTopCompiler = PR_TRUE;
}
mElementContext = new txElementContext(aBaseURI);
mElementContext = new txElementContext(aStylesheetURI);
NS_ENSURE_TRUE(mElementContext && mElementContext->mMappings,
NS_ERROR_OUT_OF_MEMORY);
@ -750,7 +763,7 @@ txStylesheetCompilerState::loadIncludedStylesheet(const nsAString& aURI)
PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
("CompilerState::loadIncludedStylesheet: %s\n",
NS_LossyConvertUTF16toASCII(aURI).get()));
if (mURI.Equals(aURI)) {
if (mStylesheetURI.Equals(aURI)) {
return NS_ERROR_XSLT_LOAD_RECURSION;
}
NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED);
@ -780,7 +793,7 @@ txStylesheetCompilerState::loadIncludedStylesheet(const nsAString& aURI)
return NS_ERROR_OUT_OF_MEMORY;
}
rv = mObserver->loadURI(aURI, mURI, compiler);
rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
if (NS_FAILED(rv)) {
mChildCompilerList.RemoveElement(compiler);
}
@ -795,7 +808,7 @@ txStylesheetCompilerState::loadImportedStylesheet(const nsAString& aURI,
PR_LOG(txLog::xslt, PR_LOG_ALWAYS,
("CompilerState::loadImportedStylesheet: %s\n",
NS_LossyConvertUTF16toASCII(aURI).get()));
if (mURI.Equals(aURI)) {
if (mStylesheetURI.Equals(aURI)) {
return NS_ERROR_XSLT_LOAD_RECURSION;
}
NS_ENSURE_TRUE(mObserver, NS_ERROR_NOT_IMPLEMENTED);
@ -813,7 +826,7 @@ txStylesheetCompilerState::loadImportedStylesheet(const nsAString& aURI,
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = mObserver->loadURI(aURI, mURI, compiler);
nsresult rv = mObserver->loadURI(aURI, mStylesheetURI, compiler);
if (NS_FAILED(rv)) {
mChildCompilerList.RemoveElement(compiler);
}

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

@ -99,7 +99,7 @@ public:
txStylesheetCompilerState(txACompileObserver* aObserver);
~txStylesheetCompilerState();
nsresult init(const nsAString& aBaseURI, txStylesheet* aStylesheet,
nsresult init(const nsAString& aStylesheetURI, txStylesheet* aStylesheet,
txListIterator* aInsertPosition);
// Embedded stylesheets state
@ -175,13 +175,13 @@ protected:
eInEmbed,
eHasEmbed
} mEmbedStatus;
nsString mURI;
nsString mStylesheetURI;
PRPackedBool mIsTopCompiler;
PRPackedBool mDoneWithThisStylesheet;
private:
txStack mObjectStack;
txStack mOtherStack;
private:
txInstruction** mNextInstrPtr;
txListIterator mToplevelIterator;
nsVoidArray mGotoTargetPointers;
@ -200,15 +200,17 @@ class txStylesheetCompiler : private txStylesheetCompilerState,
{
public:
friend class txStylesheetCompilerState;
txStylesheetCompiler(const nsAString& aBaseURI,
txStylesheetCompiler(const nsAString& aStylesheetURI,
txACompileObserver* aObserver);
txStylesheetCompiler(const nsAString& aBaseURI,
txStylesheetCompiler(const nsAString& aStylesheetURI,
txStylesheet* aStylesheet,
txListIterator* aInsertPosition,
txACompileObserver* aObserver);
virtual nsrefcnt AddRef();
virtual nsrefcnt Release();
void setBaseURI(const nsString& aBaseURI);
nsresult startElement(PRInt32 aNamespaceID, nsIAtom* aLocalName,
nsIAtom* aPrefix, txStylesheetAttr* aAttributes,
PRInt32 aAttrCount);

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

@ -333,7 +333,7 @@ nsXULContentUtils::MakeElementURI(nsIDocument* aDocument, const nsAString& aElem
CopyUTF16toUTF8(aElementID, aURI);
}
else {
nsIURI *docURL = aDocument->GetBaseURI();
nsIURI *docURL = aDocument->GetDocumentURI();
// XXX Urgh. This is so broken; I'd really just like to use
// NS_MakeAbsolueURI(). Unfortunatly, doing that breaks
@ -389,7 +389,7 @@ nsXULContentUtils::MakeElementID(nsIDocument* aDocument, const nsAString& aURI,
// Convert a URI into an element ID that can be accessed from the
// DOM APIs.
nsCAutoString spec;
aDocument->GetBaseURI()->GetSpec(spec);
aDocument->GetDocumentURI()->GetSpec(spec);
// XXX FIX ME to not do a copy
nsAutoString str(aURI);

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

@ -408,6 +408,7 @@ nsXFormsModelElement::InitializeInstances()
// Parse the whitespace-separated list.
nsCOMPtr<nsIContent> content = do_QueryInterface(mElement);
nsRefPtr<nsIURI> baseURI = content->GetBaseURI();
nsRefPtr<nsIURI> docURI = content->GetDocumentURI();
nsCStringArray schemas;
schemas.ParseString(NS_ConvertUTF16toUTF8(schemaList).get(), " \t\r\n");
@ -429,7 +430,7 @@ nsXFormsModelElement::InitializeInstances()
newURL->GetRef(ref);
newURL->SetRef(EmptyCString());
PRBool equals = PR_FALSE;
newURL->Equals(baseURI, &equals);
newURL->Equals(docURI, &equals);
if (equals) {
// We will not be able to locate the <xsd:schema> element using the
// getElementById function defined on our document when <xsd:schema>

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

@ -761,13 +761,13 @@ nsPresContext::SetShell(nsIPresShell* aShell)
nsIDocument *doc = mShell->GetDocument();
NS_ASSERTION(doc, "expect document here");
if (doc) {
nsIURI *baseURI = doc->GetBaseURI();
nsIURI *docURI = doc->GetDocumentURI();
if (mMedium != nsLayoutAtoms::print && baseURI) {
if (mMedium != nsLayoutAtoms::print && docURI) {
PRBool isChrome = PR_FALSE;
PRBool isRes = PR_FALSE;
baseURI->SchemeIs("chrome", &isChrome);
baseURI->SchemeIs("resource", &isRes);
docURI->SchemeIs("chrome", &isChrome);
docURI->SchemeIs("resource", &isRes);
if (!isChrome && !isRes)
mImageAnimationMode = mImageAnimationModePref;

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

@ -371,8 +371,8 @@ nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext)
if (!document) return NS_OK; // No doc means don't submit, see Bug 28988
// Resolve url to an absolute url
nsIURI *docURL = document->GetBaseURI();
if (!docURL) {
nsIURI *baseURI = document->GetBaseURI();
if (!baseURI) {
NS_ERROR("No Base URL found in Form Submit!\n");
return NS_OK; // No base URL -> exit early, see Bug 30721
}
@ -396,7 +396,7 @@ nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext)
// Necko's MakeAbsoluteURI doesn't reuse the baseURL's rel path if it is
// passed a zero length rel path.
nsCAutoString relPath;
docURL->GetSpec(relPath);
baseURI->GetSpec(relPath);
if (!relPath.IsEmpty()) {
CopyUTF8toUTF16(relPath, href);
@ -420,7 +420,7 @@ nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext)
if (NS_SUCCEEDED(result = NS_NewURI(getter_AddRefs(actionURL), href,
flatDocCharset.get(),
docURL))) {
baseURI))) {
result = actionURL->SchemeIs("javascript", &isJSURL);
}
// Append the URI encoded variable/value pairs for GET's
@ -436,7 +436,7 @@ nsIsIndexFrame::OnSubmit(nsPresContext* aPresContext)
}
nsCOMPtr<nsIURI> uri;
result = NS_NewURI(getter_AddRefs(uri), href,
flatDocCharset.get(), docURL);
flatDocCharset.get(), baseURI);
if (NS_FAILED(result)) return result;
// Now pass on absolute url to the click handler