diff --git a/content/html/style/src/nsStyleUtil.cpp b/content/html/style/src/nsStyleUtil.cpp
index a20bfdde42b..50f0ecd156b 100644
--- a/content/html/style/src/nsStyleUtil.cpp
+++ b/content/html/style/src/nsStyleUtil.cpp
@@ -553,8 +553,8 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// if there is no link, then this anchor is not really a linkpseudo.
// bug=23209
- char* href;
- link->GetHrefCString(href);
+ nsXPIDLCString href;
+ link->GetHrefCString(*getter_Copies(href));
if (href) {
nsILinkHandler *linkHandler = nsnull;
@@ -567,7 +567,6 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// no link handler? then all links are unvisited
linkState = eLinkState_Unvisited;
}
- nsCRT::free(href);
} else {
linkState = eLinkState_NotLink;
}
@@ -626,10 +625,8 @@ PRBool nsStyleUtil::IsSimpleXlink(nsIContent *aContent, nsIPresContext *aPresCon
// convert here, rather than twice in NS_MakeAbsoluteURI and
// back again
- char * href = ToNewCString(val);
- char * absHREF = nsnull;
- (void) NS_MakeAbsoluteURI(&absHREF, href, baseURI);
- nsCRT::free(href);
+ nsCAutoString absHREF;
+ (void) NS_MakeAbsoluteURI(absHREF, NS_ConvertUCS2toUTF8(val), baseURI);
nsILinkHandler *linkHandler = nsnull;
aPresContext->GetLinkHandler(&linkHandler);
@@ -641,7 +638,6 @@ PRBool nsStyleUtil::IsSimpleXlink(nsIContent *aContent, nsIPresContext *aPresCon
// no link handler? then all links are unvisited
*aState = eLinkState_Unvisited;
}
- nsCRT::free(absHREF);
rv = PR_TRUE;
}
diff --git a/content/shared/src/nsStyleUtil.cpp b/content/shared/src/nsStyleUtil.cpp
index a20bfdde42b..50f0ecd156b 100644
--- a/content/shared/src/nsStyleUtil.cpp
+++ b/content/shared/src/nsStyleUtil.cpp
@@ -553,8 +553,8 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// if there is no link, then this anchor is not really a linkpseudo.
// bug=23209
- char* href;
- link->GetHrefCString(href);
+ nsXPIDLCString href;
+ link->GetHrefCString(*getter_Copies(href));
if (href) {
nsILinkHandler *linkHandler = nsnull;
@@ -567,7 +567,6 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// no link handler? then all links are unvisited
linkState = eLinkState_Unvisited;
}
- nsCRT::free(href);
} else {
linkState = eLinkState_NotLink;
}
@@ -626,10 +625,8 @@ PRBool nsStyleUtil::IsSimpleXlink(nsIContent *aContent, nsIPresContext *aPresCon
// convert here, rather than twice in NS_MakeAbsoluteURI and
// back again
- char * href = ToNewCString(val);
- char * absHREF = nsnull;
- (void) NS_MakeAbsoluteURI(&absHREF, href, baseURI);
- nsCRT::free(href);
+ nsCAutoString absHREF;
+ (void) NS_MakeAbsoluteURI(absHREF, NS_ConvertUCS2toUTF8(val), baseURI);
nsILinkHandler *linkHandler = nsnull;
aPresContext->GetLinkHandler(&linkHandler);
@@ -641,7 +638,6 @@ PRBool nsStyleUtil::IsSimpleXlink(nsIContent *aContent, nsIPresContext *aPresCon
// no link handler? then all links are unvisited
*aState = eLinkState_Unvisited;
}
- nsCRT::free(absHREF);
rv = PR_TRUE;
}
diff --git a/docshell/base/nsDefaultURIFixup.cpp b/docshell/base/nsDefaultURIFixup.cpp
index 923425f1330..56430711d49 100644
--- a/docshell/base/nsDefaultURIFixup.cpp
+++ b/docshell/base/nsDefaultURIFixup.cpp
@@ -49,9 +49,9 @@ nsDefaultURIFixup::~nsDefaultURIFixup()
/* nsIURI createFixupURI (in wstring aURIText, in unsigned long aFixupFlags); */
NS_IMETHODIMP
-nsDefaultURIFixup::CreateFixupURI(const PRUnichar *aStringURI, PRUint32 aFixupFlags, nsIURI **aURI)
+nsDefaultURIFixup::CreateFixupURI(const nsAString& aStringURI, PRUint32 aFixupFlags, nsIURI **aURI)
{
- NS_ENSURE_ARG_POINTER(aStringURI);
+ NS_ENSURE_ARG(!aStringURI.IsEmpty());
NS_ENSURE_ARG_POINTER(aURI);
nsresult rv;
@@ -78,10 +78,9 @@ nsDefaultURIFixup::CreateFixupURI(const PRUnichar *aStringURI, PRUint32 aFixupFl
nsCOMPtr uri;
PRUint32 newFixupFlags = aFixupFlags & ~FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
- nsAutoString tempString;
- tempString = Substring(uriString, 12, uriString.Length() - 12);
- rv = CreateFixupURI(tempString.get(), newFixupFlags, getter_AddRefs(uri));
- if (NS_FAILED(rv) || !uri)
+ rv = CreateFixupURI(Substring(uriString, 12, uriString.Length() - 12),
+ newFixupFlags, getter_AddRefs(uri));
+ if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
nsCAutoString spec;
uri->GetSpec(spec);
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
index 97879ed8b53..fc2760c19b9 100644
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -2356,7 +2356,7 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
{
nsCOMPtr uri;
- nsresult rv = CreateFixupURI(aURI, getter_AddRefs(uri));
+ nsresult rv = CreateFixupURI(nsDependentString(aURI), getter_AddRefs(uri));
if (NS_ERROR_UNKNOWN_PROTOCOL == rv ||
NS_ERROR_MALFORMED_URI == rv) {
@@ -4924,7 +4924,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
}
NS_IMETHODIMP
-nsDocShell::CreateFixupURI(const PRUnichar * aStringURI, nsIURI ** aURI)
+nsDocShell::CreateFixupURI(const nsAString& aStringURI, nsIURI ** aURI)
{
*aURI = nsnull;
nsAutoString uriString(aStringURI);
diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h
index cf10e63b485..a58fb8c4cdf 100644
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -201,7 +201,7 @@ protected:
NS_IMETHOD SetupNewViewer(nsIContentViewer * aNewViewer);
NS_IMETHOD GetEldestPresContext(nsIPresContext** aPresContext);
- NS_IMETHOD CreateFixupURI(const PRUnichar * aStringURI, nsIURI ** aURI);
+ NS_IMETHOD CreateFixupURI(const nsAString& aStringURI, nsIURI ** aURI);
NS_IMETHOD GetCurrentDocumentOwner(nsISupports ** aOwner);
virtual nsresult DoURILoad(nsIURI * aURI,
nsIURI * aReferrer,
diff --git a/docshell/base/nsIURIFixup.idl b/docshell/base/nsIURIFixup.idl
index fa00f540a7b..c7cd588daf8 100644
--- a/docshell/base/nsIURIFixup.idl
+++ b/docshell/base/nsIURIFixup.idl
@@ -54,6 +54,6 @@ interface nsIURIFixup : nsISupports
* @param aURIText Candidate URI.
* @param aFixupFlags Flags that govern ways the URI may be fixed up.
*/
- nsIURI createFixupURI(in wstring aURIText, in unsigned long aFixupFlags);
+ nsIURI createFixupURI(in AString aURIText, in unsigned long aFixupFlags);
};
diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp
index 07d13bb9525..6de9527158a 100644
--- a/docshell/base/nsWebShell.cpp
+++ b/docshell/base/nsWebShell.cpp
@@ -191,7 +191,14 @@ nsWebShell::~nsWebShell()
mDocLoader->Stop();
mDocLoader->SetContainer(nsnull);
mDocLoader->Destroy();
+// turn on to track docloader leaks
+#if 0
+ nsrefcnt refcnt;
+ NS_RELEASE2(mDocLoader, refcnt);
+ NS_ASSERTION(mDocLoader == nsnull, "Still have a docloader? who owns it?!");
+#else
NS_RELEASE(mDocLoader);
+#endif
}
// Cancel any timers that were set for this loader.
CancelRefreshURITimers();
@@ -689,20 +696,42 @@ nsWebShell::OnOverLink(nsIContent* aContent,
}
NS_IMETHODIMP
-nsWebShell::GetLinkState(const char* aLinkURI, nsLinkState& aState)
+nsWebShell::GetLinkState(const nsACString& aLinkURI, nsLinkState& aState)
{
aState = eLinkState_Unvisited;
- if(mGlobalHistory)
- {
- PRBool isVisited;
- NS_ENSURE_SUCCESS(mGlobalHistory->IsVisited(aLinkURI, &isVisited),
- NS_ERROR_FAILURE);
- if (isVisited)
- aState = eLinkState_Visited;
- }
+ // no history, leave state unchanged
+ if (!mGlobalHistory)
+ return NS_OK;
+
+ // default to the given URI
+ nsCAutoString resolvedPath(aLinkURI);
+ nsresult rv;
+
+ // get the cached IO service
+ if (!mIOService) {
+ mIOService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
+
+ if (NS_SUCCEEDED(rv)) {
- return NS_OK;
+ // clean up the url using the right parser
+ nsCOMPtr uri;
+ rv = NS_NewURI(getter_AddRefs(uri), aLinkURI, nsnull, nsnull,
+ mIOService);
+
+ // now get the fully canonicalized path
+ if (NS_SUCCEEDED(rv))
+ rv = uri->GetSpec(resolvedPath);
+ }
+ }
+
+ PRBool isVisited;
+ NS_ENSURE_SUCCESS(mGlobalHistory->IsVisited(resolvedPath.get(), &isVisited),
+ NS_ERROR_FAILURE);
+ if (isVisited)
+ aState = eLinkState_Visited;
+
+ return NS_OK;
}
//----------------------------------------------------------------------
@@ -773,7 +802,6 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
nsCAutoString oldSpec;
url->GetSpec(oldSpec);
- NS_ConvertUTF8toUCS2 oldSpecW(oldSpec);
//
// First try keyword fixup
@@ -854,7 +882,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
if (doCreateAlternate)
{
newURI = nsnull;
- mURIFixup->CreateFixupURI(oldSpecW.get(),
+ mURIFixup->CreateFixupURI(NS_ConvertUTF8toUCS2(oldSpec),
nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI, getter_AddRefs(newURI));
}
}
diff --git a/docshell/base/nsWebShell.h b/docshell/base/nsWebShell.h
index 121f69607f9..b555af7a8ad 100644
--- a/docshell/base/nsWebShell.h
+++ b/docshell/base/nsWebShell.h
@@ -29,6 +29,7 @@
#include "nsIClipboardCommands.h"
#include "nsDocShell.h"
#include "nsICommandManager.h"
+#include "nsIIOService.h"
#include "nsCRT.h"
class nsIEventQueue;
@@ -84,7 +85,7 @@ public:
NS_IMETHOD OnOverLink(nsIContent* aContent,
const PRUnichar* aURLSpec,
const PRUnichar* aTargetSpec);
- NS_IMETHOD GetLinkState(const char* aLinkURI, nsLinkState& aState);
+ NS_IMETHOD GetLinkState(const nsACString& aLinkURI, nsLinkState& aState);
NS_IMETHOD Create();
NS_IMETHOD Destroy();
@@ -130,6 +131,9 @@ protected:
nsCOMPtr mCommandManager;
+ // cached io service for NS_NewURI
+ nsCOMPtr mIOService;
+
#ifdef DEBUG
private:
// We're counting the number of |nsWebShells| to help find leaks
diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp
index a20bfdde42b..50f0ecd156b 100644
--- a/layout/style/nsStyleUtil.cpp
+++ b/layout/style/nsStyleUtil.cpp
@@ -553,8 +553,8 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// if there is no link, then this anchor is not really a linkpseudo.
// bug=23209
- char* href;
- link->GetHrefCString(href);
+ nsXPIDLCString href;
+ link->GetHrefCString(*getter_Copies(href));
if (href) {
nsILinkHandler *linkHandler = nsnull;
@@ -567,7 +567,6 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// no link handler? then all links are unvisited
linkState = eLinkState_Unvisited;
}
- nsCRT::free(href);
} else {
linkState = eLinkState_NotLink;
}
@@ -626,10 +625,8 @@ PRBool nsStyleUtil::IsSimpleXlink(nsIContent *aContent, nsIPresContext *aPresCon
// convert here, rather than twice in NS_MakeAbsoluteURI and
// back again
- char * href = ToNewCString(val);
- char * absHREF = nsnull;
- (void) NS_MakeAbsoluteURI(&absHREF, href, baseURI);
- nsCRT::free(href);
+ nsCAutoString absHREF;
+ (void) NS_MakeAbsoluteURI(absHREF, NS_ConvertUCS2toUTF8(val), baseURI);
nsILinkHandler *linkHandler = nsnull;
aPresContext->GetLinkHandler(&linkHandler);
@@ -641,7 +638,6 @@ PRBool nsStyleUtil::IsSimpleXlink(nsIContent *aContent, nsIPresContext *aPresCon
// no link handler? then all links are unvisited
*aState = eLinkState_Unvisited;
}
- nsCRT::free(absHREF);
rv = PR_TRUE;
}
diff --git a/webshell/public/nsILinkHandler.h b/webshell/public/nsILinkHandler.h
index 411901b68b9..0abd12c08b5 100644
--- a/webshell/public/nsILinkHandler.h
+++ b/webshell/public/nsILinkHandler.h
@@ -135,7 +135,7 @@ public:
/**
* Get the state of a link to a given absolute URL
*/
- NS_IMETHOD GetLinkState(const char* aLinkURI, nsLinkState& aState) = 0;
+ NS_IMETHOD GetLinkState(const nsACString& aLinkURI, nsLinkState& aState) = 0;
};
#endif /* nsILinkHandler_h___ */
diff --git a/xpfe/components/history/src/nsGlobalHistory.cpp b/xpfe/components/history/src/nsGlobalHistory.cpp
index ca164abae8f..8700460d711 100644
--- a/xpfe/components/history/src/nsGlobalHistory.cpp
+++ b/xpfe/components/history/src/nsGlobalHistory.cpp
@@ -1177,19 +1177,7 @@ nsGlobalHistory::IsVisited(const char *aURL, PRBool *_retval)
nsCOMPtr row;
rv = FindRow(kToken_URLColumn, aURL, getter_AddRefs(row));
- if (NS_FAILED(rv)) {
- // now try it with a "/" appended?
- rv = FindRow(kToken_URLColumn,
- PromiseFlatCString(nsDependentCString(aURL) +
- nsDependentCString("/")).get(),
- getter_AddRefs(row));
- if (NS_FAILED(rv))
- *_retval = PR_FALSE;
- else
- *_retval = PR_TRUE;
- }
- else
- *_retval = PR_TRUE;
+ *_retval = NS_SUCCEEDED(rv);
return NS_OK;
}