diff --git a/mozilla/content/base/src/nsDOMAttribute.cpp b/mozilla/content/base/src/nsDOMAttribute.cpp index 8a9760da0b6..91755e18ab7 100644 --- a/mozilla/content/base/src/nsDOMAttribute.cpp +++ b/mozilla/content/base/src/nsDOMAttribute.cpp @@ -478,6 +478,30 @@ nsDOMAttribute::GetBaseURI(nsAWritableString &aURI) return rv; } +NS_IMETHODIMP +nsDOMAttribute::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + aPrefix.Truncate(); + nsresult rv = NS_OK; + nsCOMPtr node(do_QueryInterface(mContent)); + if (node) + rv = node->LookupNamespacePrefix(aNamespaceURI, aPrefix); + return rv; +} + +NS_IMETHODIMP +nsDOMAttribute::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + aNamespaceURI.Truncate(); + nsresult rv = NS_OK; + nsCOMPtr node(do_QueryInterface(mContent)); + if (node) + rv = node->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI); + return rv; +} + //---------------------------------------------------------------------- nsAttributeChildList::nsAttributeChildList(nsDOMAttribute* aAttribute) diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 9b52d781f0e..b0a7fcba23f 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -793,15 +793,20 @@ nsDocument::GetBaseURL(nsIURI*& aURL) const NS_IMETHODIMP nsDocument::SetBaseURL(nsIURI* aURL) { - nsresult rv; - nsCOMPtr securityManager = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - rv = securityManager->CheckLoadURI(mDocumentURL, aURL, nsIScriptSecurityManager::STANDARD); + nsresult rv = NS_OK; + if (aURL) { + nsCOMPtr securityManager = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { - mDocumentBaseURL = aURL; + rv = securityManager->CheckLoadURI(mDocumentURL, aURL, nsIScriptSecurityManager::STANDARD); + if (NS_SUCCEEDED(rv)) { + mDocumentBaseURL = aURL; + } } } + else { + mDocumentBaseURL = aURL; + } return rv; } @@ -2882,6 +2887,22 @@ nsDocument::GetBaseURI(nsAWritableString &aURI) return NS_OK; } +NS_IMETHODIMP +nsDocument::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + aPrefix.Truncate(); + return NS_OK; +} + +NS_IMETHODIMP +nsDocument::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + aNamespaceURI.Truncate(); + return NS_OK; +} + NS_IMETHODIMP nsDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) { diff --git a/mozilla/content/base/src/nsDocumentFragment.cpp b/mozilla/content/base/src/nsDocumentFragment.cpp index b4a880a351d..bfbc6f813cc 100644 --- a/mozilla/content/base/src/nsDocumentFragment.cpp +++ b/mozilla/content/base/src/nsDocumentFragment.cpp @@ -104,6 +104,14 @@ public: // nsIDOM3Node NS_IMETHOD GetBaseURI(nsAWritableString& aURI) { aURI.Truncate(); return NS_OK; } + NS_IMETHOD LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) { + aPrefix.Truncate(); return NS_OK; + } + NS_IMETHOD LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) { + aNamespaceURI.Truncate(); return NS_OK; + } // nsIContent NS_IMETHOD SetParent(nsIContent* aParent) diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index c12189401b3..168c23b15ea 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -267,6 +267,34 @@ nsGenericDOMDataNode::GetBaseURI(nsAWritableString& aURI) return rv; } +nsresult +nsGenericDOMDataNode::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + aPrefix.Truncate(); + // DOM Data Node passes the query on to its parent + nsCOMPtr node(do_QueryInterface(mParent)); + if (node) { + return node->LookupNamespacePrefix(aNamespaceURI, aPrefix); + } + + return NS_OK; +} + +nsresult +nsGenericDOMDataNode::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + aNamespaceURI.Truncate(); + // DOM Data Node passes the query on to its parent + nsCOMPtr node(do_QueryInterface(mParent)); + if (node) { + return node->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI); + } + + return NS_OK; +} + #if 0 nsresult nsGenericDOMDataNode::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn) diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.h b/mozilla/content/base/src/nsGenericDOMDataNode.h index 70c0d7ab4d9..86073d360c8 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.h +++ b/mozilla/content/base/src/nsGenericDOMDataNode.h @@ -126,6 +126,10 @@ struct nsGenericDOMDataNode { const nsAReadableString& aVersion, PRBool* aReturn); nsresult GetBaseURI(nsAWritableString& aURI); + nsresult LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix); + nsresult LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI); // Implementation for nsIDOMCharacterData nsresult GetData(nsAWritableString& aData); @@ -356,6 +360,14 @@ struct nsGenericDOMDataNode { NS_IMETHOD GetBaseURI(nsAWritableString& aURI) { \ return _g.GetBaseURI(aURI); \ } \ + NS_IMETHOD LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, \ + nsAWritableString& aPrefix) { \ + return _g.LookupNamespacePrefix(aNamespaceURI, aPrefix); \ + } \ + NS_IMETHOD LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, \ + nsAWritableString& aNamespaceURI) { \ + return _g.LookupNamespaceURI(aNamespacePrefix, aNamespaceURI); \ + } \ NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); #define NS_IMPL_NSIDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(_g) \ diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index b6494d9081a..3acb0360abd 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -53,6 +53,7 @@ #include "nsIServiceManager.h" #include "nsIDOMCSSStyleDeclaration.h" #include "nsDOMCSSDeclaration.h" +#include "nsINameSpace.h" #include "nsINameSpaceManager.h" #include "nsContentList.h" #include "nsDOMError.h" @@ -436,6 +437,122 @@ nsNode3Tearoff::GetBaseURI(nsAWritableString& aURI) return NS_OK; } +NS_IMETHODIMP +nsNode3Tearoff::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + aPrefix.Truncate(); + + // XXX Waiting for DOM spec to list error codes. + + nsCOMPtr manager; + nsCOMPtr ni; + + mContent->GetNodeInfo(*getter_AddRefs(ni)); + if (ni) { + nsCOMPtr nimgr; + + ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_UNEXPECTED); + + nimgr->GetNamespaceManager(*getter_AddRefs(manager)); + } + + // If there's no nodeinfo, get the manager from the document + if (!manager) { + nsCOMPtr doc; + mContent->GetDocument(*getter_AddRefs(doc)); + if (!doc) { + return NS_ERROR_UNEXPECTED; + } + + doc->GetNameSpaceManager(*getter_AddRefs(manager)); + } + + if (!manager) { + return NS_ERROR_UNEXPECTED; + } + + // Get the namespace id for the URI + PRInt32 namespaceId; + manager->GetNameSpaceID(aNamespaceURI, namespaceId); + if (namespaceId == kNameSpaceID_Unknown) { + return NS_ERROR_FAILURE; + } + + // Trace up the content parent chain looking for XML content. + // From there, look for a prefix associated with the namespace. + nsCOMPtr content(mContent); + while (content) { + nsCOMPtr xmlContent(do_QueryInterface(content)); + + if (xmlContent) { + nsCOMPtr ns; + + xmlContent->GetContainingNameSpace(*getter_AddRefs(ns)); + if (ns) { + nsCOMPtr prefix; + nsresult rv = ns->FindNameSpacePrefix(namespaceId, + *getter_AddRefs(prefix)); + if (NS_FAILED(rv)) { + return NS_ERROR_FAILURE; + } + if (prefix) { + prefix->ToString(aPrefix); + } + return NS_OK; + } + } + + nsCOMPtr tmp(content); + tmp->GetParent(*getter_AddRefs(content)); + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsNode3Tearoff::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + aNamespaceURI.Truncate(); + + // Trace up the content parent chain looking for XML content. From + // there, see if anyone up the chain knows about the prefix. + nsCOMPtr content(mContent); + while (content) { + nsCOMPtr xmlContent(do_QueryInterface(content)); + + if (xmlContent) { + nsCOMPtr ns; + + xmlContent->GetContainingNameSpace(*getter_AddRefs(ns)); + if (ns) { + nsCOMPtr prefix; + nsCOMPtr foundNS; + + if (!aNamespacePrefix.IsEmpty()) { + prefix = dont_AddRef(NS_NewAtom(aNamespacePrefix)); + } + + nsresult rv = ns->FindNameSpace(prefix, *getter_AddRefs(foundNS)); + if (NS_FAILED(rv)) { + return NS_ERROR_FAILURE; + } + + foundNS->GetNameSpaceURI(aNamespaceURI); + return NS_OK; + } + } + + nsCOMPtr tmp(content); + tmp->GetParent(*getter_AddRefs(content)); + } + + return NS_ERROR_FAILURE; +} + + nsDOMEventRTTearoff * nsDOMEventRTTearoff::mCachedEventTearoff[NS_EVENT_TEAROFF_CACHE_SIZE]; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 99a1f6afcdd..12a62141412 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1640,6 +1640,24 @@ nsHTMLDocument::GetBaseURI(nsAWritableString &aURI) return NS_OK; } + +NS_IMETHODIMP +nsHTMLDocument::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + aPrefix.Truncate(); + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLDocument::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + aNamespaceURI.Truncate(); + return NS_OK; +} + + // // nsIDOMHTMLDocument interface implementation // diff --git a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp index 12b936f9f94..8df4df66f18 100644 --- a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -130,6 +130,15 @@ public: NS_IMETHOD GetBaseURI(nsAWritableString& aURI) { return mInner.GetBaseURI(aURI); } + NS_IMETHOD LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) { + return mInner.LookupNamespacePrefix(aNamespaceURI, aPrefix); + } + NS_IMETHOD LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) { + return mInner.LookupNamespaceURI(aNamespacePrefix, aNamespaceURI); + } + NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); // nsIDOMProcessingInstruction diff --git a/mozilla/content/xul/content/src/nsXULAttributes.cpp b/mozilla/content/xul/content/src/nsXULAttributes.cpp index 7b18c62002b..0f692f7ca8e 100644 --- a/mozilla/content/xul/content/src/nsXULAttributes.cpp +++ b/mozilla/content/xul/content/src/nsXULAttributes.cpp @@ -452,6 +452,23 @@ nsXULAttribute::GetBaseURI(nsAWritableString &aURI) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +nsXULAttribute::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + NS_NOTYETIMPLEMENTED("write me"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsXULAttribute::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + NS_NOTYETIMPLEMENTED("write me"); + return NS_ERROR_NOT_IMPLEMENTED; +} + + // nsIDOMAttr interface NS_IMETHODIMP diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 8465c073484..c0b0df46a78 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -3820,6 +3820,23 @@ nsXULDocument::GetBaseURI(nsAWritableString &aURI) return NS_OK; } + +NS_IMETHODIMP +nsXULDocument::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, + nsAWritableString& aPrefix) +{ + NS_NOTYETIMPLEMENTED("write me"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsXULDocument::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, + nsAWritableString& aNamespaceURI) +{ + NS_NOTYETIMPLEMENTED("write me"); + return NS_ERROR_NOT_IMPLEMENTED; +} + //---------------------------------------------------------------------- // // nsIHTMLContentContainer interface