From 75dc2e58dce2130a89dc2af76443e2dbd81c395d Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Tue, 24 Apr 2001 00:04:11 +0000 Subject: [PATCH] Bug 76641, back out baseURI property in the Node interface to fix binary compatibility. baseURI property is implemented in a different way on the DOM conversion branch, so baseURI will get back when the branch lands. This fix by jst, r=heikki, sr=brendan, a=chofmann. git-svn-id: svn://10.0.0.236/trunk@92962 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDOMAttribute.cpp | 2 + mozilla/content/base/src/nsDocument.cpp | 4 +- .../content/base/src/nsGenericDOMDataNode.cpp | 2 + .../html/document/src/nsHTMLDocument.cpp | 3 +- .../xul/content/src/nsXULAttributes.cpp | 2 + .../content/xul/content/src/nsXULElement.cpp | 2 + .../xul/document/src/nsXULDocument.cpp | 2 + mozilla/dom/public/coreDom/nsIDOMNode.h | 4 -- mozilla/dom/public/idl/coreDom/Node.idl | 3 -- mozilla/dom/src/coreDOM/nsJSNode.cpp | 16 +------- .../source/xml/dom/mozImpl/MozillaNode.cpp | 37 +++++++++++++++++-- .../resources/content/nsContextMenu.js | 25 ++++++++----- 12 files changed, 64 insertions(+), 38 deletions(-) diff --git a/mozilla/content/base/src/nsDOMAttribute.cpp b/mozilla/content/base/src/nsDOMAttribute.cpp index 81df09ea2ba..34c2e32d6d0 100644 --- a/mozilla/content/base/src/nsDOMAttribute.cpp +++ b/mozilla/content/base/src/nsDOMAttribute.cpp @@ -527,6 +527,7 @@ nsDOMAttribute::IsSupported(const nsAReadableString& aFeature, return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); } +#if 0 NS_IMETHODIMP nsDOMAttribute::GetBaseURI(nsAWritableString &aURI) { @@ -537,6 +538,7 @@ nsDOMAttribute::GetBaseURI(nsAWritableString &aURI) rv = node->GetBaseURI(aURI); return rv; } +#endif //---------------------------------------------------------------------- diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index b46503861bf..ee47c778a47 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -119,8 +119,6 @@ static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); #include "nsIHTMLDocument.h" - - nsDOMStyleSheetList::nsDOMStyleSheetList(nsIDocument *aDocument) { NS_INIT_REFCNT(); @@ -2738,6 +2736,7 @@ nsDocument::IsSupported(const nsAReadableString& aFeature, return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); } +#if 0 NS_IMETHODIMP nsDocument::GetBaseURI(nsAWritableString &aURI) { @@ -2751,6 +2750,7 @@ nsDocument::GetBaseURI(nsAWritableString &aURI) } return NS_OK; } +#endif NS_IMETHODIMP nsDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index 7db06ac1905..192057f5cee 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -251,8 +251,10 @@ nsGenericDOMDataNode::GetBaseURI(nsAWritableString& aURI) node = do_QueryInterface(mDocument); } +#if 0 if (node) rv = node->GetBaseURI(aURI); +#endif return rv; } diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 96681c5d5f3..9514a4f7de2 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1743,6 +1743,7 @@ nsHTMLDocument::IsSupported(const nsAReadableString& aFeature, return nsDocument::IsSupported(aFeature, aVersion, aReturn); } +#if 0 NS_IMETHODIMP nsHTMLDocument::GetBaseURI(nsAWritableString &aURI) { @@ -1757,7 +1758,7 @@ nsHTMLDocument::GetBaseURI(nsAWritableString &aURI) } return NS_OK; } - +#endif // // nsIDOMHTMLDocument interface implementation diff --git a/mozilla/content/xul/content/src/nsXULAttributes.cpp b/mozilla/content/xul/content/src/nsXULAttributes.cpp index b5bf5e02d43..160c658064a 100644 --- a/mozilla/content/xul/content/src/nsXULAttributes.cpp +++ b/mozilla/content/xul/content/src/nsXULAttributes.cpp @@ -462,12 +462,14 @@ nsXULAttribute::IsSupported(const nsAReadableString& aFeature, return NS_ERROR_NOT_IMPLEMENTED; } +#if 0 NS_IMETHODIMP nsXULAttribute::GetBaseURI(nsAWritableString &aURI) { NS_NOTYETIMPLEMENTED("write me"); return NS_ERROR_NOT_IMPLEMENTED; } +#endif // nsIDOMAttr interface diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index f33bde096ff..32b8c85db84 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -1791,6 +1791,7 @@ nsXULElement::GetXMLBaseURI(nsIURI **aURI) return NS_OK; } +#if 0 NS_IMETHODIMP nsXULElement::GetBaseURI(nsAWritableString &aURI) { @@ -1805,6 +1806,7 @@ nsXULElement::GetBaseURI(nsAWritableString &aURI) } return rv; } +#endif //---------------------------------------------------------------------- diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index ae2ecf418c4..bdd6f263f5f 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -3555,6 +3555,7 @@ nsXULDocument::IsSupported(const nsAReadableString& aFeature, return NS_ERROR_NOT_IMPLEMENTED; } +#if 0 NS_IMETHODIMP nsXULDocument::GetBaseURI(nsAWritableString &aURI) { @@ -3568,6 +3569,7 @@ nsXULDocument::GetBaseURI(nsAWritableString &aURI) } return NS_OK; } +#endif //---------------------------------------------------------------------- diff --git a/mozilla/dom/public/coreDom/nsIDOMNode.h b/mozilla/dom/public/coreDom/nsIDOMNode.h index 47b704b059c..bb4ada22caf 100644 --- a/mozilla/dom/public/coreDom/nsIDOMNode.h +++ b/mozilla/dom/public/coreDom/nsIDOMNode.h @@ -85,8 +85,6 @@ public: NS_IMETHOD GetLocalName(nsAWritableString& aLocalName)=0; - NS_IMETHOD GetBaseURI(nsAWritableString& aBaseURI)=0; - NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)=0; NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)=0; @@ -124,7 +122,6 @@ public: NS_IMETHOD GetPrefix(nsAWritableString& aPrefix); \ NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix); \ NS_IMETHOD GetLocalName(nsAWritableString& aLocalName); \ - NS_IMETHOD GetBaseURI(nsAWritableString& aBaseURI); \ NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn); \ NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn); \ NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn); \ @@ -154,7 +151,6 @@ public: NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) { return _to GetPrefix(aPrefix); } \ NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix) { return _to SetPrefix(aPrefix); } \ NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) { return _to GetLocalName(aLocalName); } \ - NS_IMETHOD GetBaseURI(nsAWritableString& aBaseURI) { return _to GetBaseURI(aBaseURI); } \ NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn) { return _to InsertBefore(aNewChild, aRefChild, aReturn); } \ NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { return _to ReplaceChild(aNewChild, aOldChild, aReturn); } \ NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { return _to RemoveChild(aOldChild, aReturn); } \ diff --git a/mozilla/dom/public/idl/coreDom/Node.idl b/mozilla/dom/public/idl/coreDom/Node.idl index e9eb4fbe37b..b8121bbf20f 100644 --- a/mozilla/dom/public/idl/coreDom/Node.idl +++ b/mozilla/dom/public/idl/coreDom/Node.idl @@ -56,9 +56,6 @@ interface Node { readonly attribute DOMString localName; // Introduced in DOM Level 2: boolean hasAttributes(); - - // Introduced in DOM Level 3: - readonly attribute DOMString baseURI; }; interface EventTarget { diff --git a/mozilla/dom/src/coreDOM/nsJSNode.cpp b/mozilla/dom/src/coreDOM/nsJSNode.cpp index ebfb6f8fe0d..d0ff576ef2e 100644 --- a/mozilla/dom/src/coreDOM/nsJSNode.cpp +++ b/mozilla/dom/src/coreDOM/nsJSNode.cpp @@ -71,8 +71,7 @@ enum Node_slots { NODE_OWNERDOCUMENT = -11, NODE_NAMESPACEURI = -12, NODE_PREFIX = -13, - NODE_LOCALNAME = -14, - NODE_BASEURI = -15 + NODE_LOCALNAME = -14 }; /***********************************************************************/ @@ -271,18 +270,6 @@ GetNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } - case NODE_BASEURI: - { - rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NODE_BASEURI, PR_FALSE); - if (NS_SUCCEEDED(rv)) { - nsAutoString prop; - rv = a->GetBaseURI(prop); - if (NS_SUCCEEDED(rv)) { - nsJSUtils::nsConvertStringToJSVal(prop, cx, vp); - } - } - break; - } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); } @@ -373,7 +360,6 @@ static JSPropertySpec NodeProperties[] = {"namespaceURI", NODE_NAMESPACEURI, JSPROP_ENUMERATE | JSPROP_READONLY}, {"prefix", NODE_PREFIX, JSPROP_ENUMERATE}, {"localName", NODE_LOCALNAME, JSPROP_ENUMERATE | JSPROP_READONLY}, - {"baseURI", NODE_BASEURI, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/mozilla/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp b/mozilla/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp index 6ec64836ff5..e0ce3566b17 100644 --- a/mozilla/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp +++ b/mozilla/extensions/transformiix/source/xml/dom/mozImpl/MozillaNode.cpp @@ -384,11 +384,40 @@ MBool Node::hasChildNodes() const **/ String Node::getBaseURI() { - NSI_FROM_TX(Node) + Node* node=this; + ArrayList baseUrls; String url; + Node* xbAttr; + + while(node) { + switch(node->getNodeType()) { + case Node::ELEMENT_NODE : + xbAttr = ((Element*)node)->getAttributeNode(XMLBASE_ATTR); + if(xbAttr) + baseUrls.add(new String(xbAttr->getNodeValue())); + break; + + case Node::DOCUMENT_NODE : + baseUrls.add(new String(((Document*)node)->getBaseURI())); + break; + + default: + break; + } + node = node->getParentNode(); + } + + if(baseUrls.size()) { + url = *((String*)baseUrls.get(baseUrls.size()-1)); + + for(int i=baseUrls.size()-2;i>=0;i--) { + String dest; + URIUtils::resolveHref(*(String*)baseUrls.get(i), url, dest); + url = dest; + } + } + + baseUrls.clear(MB_TRUE); - if (nsNode) - nsNode->GetBaseURI(url.getNSString()); - return url; } diff --git a/mozilla/xpfe/communicator/resources/content/nsContextMenu.js b/mozilla/xpfe/communicator/resources/content/nsContextMenu.js index 1739623ba9d..595adc0b074 100644 --- a/mozilla/xpfe/communicator/resources/content/nsContextMenu.js +++ b/mozilla/xpfe/communicator/resources/content/nsContextMenu.js @@ -255,7 +255,7 @@ nsContextMenu.prototype = { if(this.target.getAttribute( "type" ).toUpperCase() == "IMAGE") { this.onImage = true; // Convert src attribute to absolute URL. - this.imageURL = this.makeURLAbsolute( this.target.baseURI, + this.imageURL = this.makeURLAbsolute( this.target.ownerDocument, this.target.src ); } else /* if (this.target.getAttribute( "type" ).toUpperCase() == "TEXT") */ { this.onTextInput = this.isTargetATextBox(this.target); @@ -265,7 +265,7 @@ nsContextMenu.prototype = { } else if ( this.target.getAttribute( "background" ) ) { this.onImage = true; // Convert background attribute to absolute URL. - this.imageURL = this.makeURLAbsolute( this.target.baseURI, + this.imageURL = this.makeURLAbsolute( this.target.ownerDocument, this.target.getAttribute( "background" ) ); } else if ( "HTTPIndex" in _content && _content.HTTPIndex instanceof Components.interfaces.nsIHTTPIndex ) { @@ -309,7 +309,7 @@ nsContextMenu.prototype = { this.onImage = true; var url = cssAttr.toLowerCase().replace(/url\("*(.+)"*\)/, "$1"); // Convert attribute to absolute URL. - this.imageURL = this.makeURLAbsolute( this.target.baseURI, url ); + this.imageURL = this.makeURLAbsolute( this.target.ownerDocument, url ); } } catch ( exception ) { } @@ -524,11 +524,11 @@ nsContextMenu.prototype = { if (this.link.href) { return this.link.href; } + // XXX TODO Relative URLs, XML Base var href = this.link.getAttributeNS("http://www.w3.org/1999/xlink","href"); if (href == "") { throw "Empty href"; // Without this we try to save as the current doc, for example, HTML case also throws if empty } - href = this.makeURLAbsolute(this.link.baseURI,href); return href; }, // Get text of link (if possible). @@ -602,15 +602,22 @@ nsContextMenu.prototype = { // Extract url from data= attribute. var data = objElem.getAttribute( "data" ); // Make it absolute. - return this.makeURLAbsolute( objElem.baseURI, data ); + return this.makeURLAbsolute( objElem.ownerDocument, data ); }, // Convert relative URL to absolute, using document's . - makeURLAbsolute : function ( base, url ) { + makeURLAbsolute : function ( doc, url ) { // Construct nsIURL. var baseURL = this.createInstance( "@mozilla.org/network/standard-url;1", "nsIURL" ); - // Initialize from base url. - baseURL.spec = base; - // Resolve + // Initialize from document url. + baseURL.spec = doc.location.href; + // Look for tag. + var baseTags = doc.getElementsByTagName( "BASE" ); + if ( baseTags && baseTags.length ) { + // Reset base URL using href attribute of tag. + var href = baseTags[ baseTags.length - 1 ].getAttribute( "href" ); + baseURL.spec = baseURL.resolve( href ); + } + // Finally, convert argument url using base. var result = baseURL.resolve( url ); return result; },