fix for bug 12493 - layout should canonicalize urls before asking global history for visited status

r=radha, sr=darin
This commit is contained in:
alecf%netscape.com 2002-08-06 23:51:42 +00:00
Родитель 5d1c18865d
Коммит 9d46c7a238
11 изменённых файлов: 68 добавлений и 61 удалений

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

@ -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;
}

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

@ -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;
}

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

@ -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<nsIURI> 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);

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

@ -2356,7 +2356,7 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
{
nsCOMPtr<nsIURI> 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);

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

@ -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,

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

@ -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);
};

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

@ -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<nsIURI> 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));
}
}

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

@ -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<nsICommandManager> mCommandManager;
// cached io service for NS_NewURI
nsCOMPtr<nsIIOService> mIOService;
#ifdef DEBUG
private:
// We're counting the number of |nsWebShells| to help find leaks

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

@ -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;
}

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

@ -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___ */

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

@ -1177,19 +1177,7 @@ nsGlobalHistory::IsVisited(const char *aURL, PRBool *_retval)
nsCOMPtr<nsIMdbRow> 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;
}