From 4de7a414e1b53a88b94285fac39b49e1bd6a411b Mon Sep 17 00:00:00 2001 From: "gavin%gavinsharp.com" Date: Fri, 29 Jul 2005 20:44:45 +0000 Subject: [PATCH] Bug 262222 : Relative URLs in Live Bookmark link elements not resolved, patch by Sam Ruby , r=vlad, a=bsmedberg --- .../bookmarks/src/nsBookmarksFeedHandler.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/browser/components/bookmarks/src/nsBookmarksFeedHandler.cpp b/browser/components/bookmarks/src/nsBookmarksFeedHandler.cpp index b8286455320..469d04aa16a 100644 --- a/browser/components/bookmarks/src/nsBookmarksFeedHandler.cpp +++ b/browser/components/bookmarks/src/nsBookmarksFeedHandler.cpp @@ -65,6 +65,7 @@ #include "nsIDOMElement.h" #include "nsIDOMCharacterData.h" #include "nsIDOMNodeList.h" +#include "nsIDOM3Node.h" /* These are defined in nsBookmarksService.cpp */ extern nsIRDFResource *kRDF_type; @@ -93,6 +94,7 @@ extern nsIRDFContainerUtils *gRDFC; static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); +static NS_DEFINE_CID(kStdURLCID, NS_STANDARDURL_CID); nsresult nsBMSVCClearSeqContainer (nsIRDFDataSource* aDataSource, nsIRDFResource* aResource); nsresult nsBMSVCUnmakeSeq (nsIRDFDataSource* aDataSource, nsIRDFResource* aResource); @@ -562,6 +564,7 @@ nsFeedLoadListener::TryParseAsSimpleRSS () if (NS_FAILED(rv)) return rv; nsCOMPtr xmldoc; + parser->SetBaseURI(mURI); rv = parser->ParseFromBuffer ((const PRUint8*) mBody.get(), mBody.Length(), "text/xml", getter_AddRefs(xmldoc)); if (NS_FAILED(rv)) return rv; @@ -702,6 +705,23 @@ nsFeedLoadListener::TryParseAsSimpleRSS () { rv = linkElem->GetAttribute(NS_LITERAL_STRING("href"), linkStr); if (NS_FAILED(rv)) break; // out of while(childNode) loop + + nsCOMPtr linkElem3 = do_QueryInterface(childNode); + if (linkElem3) { + // get the BaseURI + nsAutoString baseURI; + linkElem3->GetBaseURI(baseURI); + nsCOMPtr base; + base = nsCOMPtr(do_CreateInstance(kStdURLCID, &rv)); + base->SetSpec(NS_ConvertUCS2toUTF8(baseURI)); + + // use it to resolve linkStr to an absolute URI + nsCString result; + rv = base->Resolve(NS_ConvertUCS2toUTF8(linkStr), result); + if (NS_SUCCEEDED(rv)) { + linkStr = NS_ConvertUTF8toUCS2(result); + } + } } } else if (linkStr.IsEmpty()) { // in node's TEXT