Bug 12493. Change nsILinkHandler interface to take an nsIURI object instead of a string. This allows necko to canonify URIs before passing them back to global history. r=travis,pierre

This commit is contained in:
waterson%netscape.com 2000-04-13 19:55:47 +00:00
Родитель b1542cff0d
Коммит a06a8ee723
10 изменённых файлов: 90 добавлений и 231 удалений

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

@ -2726,33 +2726,26 @@ static PRBool SelectorMatches(nsIPresContext* aPresContext,
aPresContext->GetLinkHandler(&linkHandler);
if (linkHandler) {
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
nsIURI* docURL = nsnull;
nsIHTMLContent* htmlContent;
if (NS_SUCCEEDED(aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
htmlContent->GetBaseURL(docURL);
NS_RELEASE(htmlContent);
nsCOMPtr<nsIURI> baseURI = nsnull;
nsCOMPtr<nsIHTMLContent> htmlContent = do_QueryInterface(aContent);
if (htmlContent) {
// XXX why do this? will nsIHTMLContent's
// GetBaseURL() may return something different
// than the URL of the document it lives in?
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
}
else {
nsIDocument* doc = nsnull;
aContent->GetDocument(doc);
if (nsnull != doc) {
doc->GetBaseURL(docURL);
NS_RELEASE(doc);
nsCOMPtr<nsIDocument> doc;
aContent->GetDocument(*getter_AddRefs(doc));
if (doc) {
doc->GetBaseURL(*getter_AddRefs(baseURI));
}
}
nsAutoString absURLSpec;
nsresult rv;
nsIURI *baseUri = nsnull;
rv = docURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return PR_FALSE;
nsCOMPtr<nsIURI> linkURI;
(void) NS_NewURI(getter_AddRefs(linkURI), href, baseURI, CSSStyleSheetInner::gIOService);
(void)NS_MakeAbsoluteURI(absURLSpec, href, baseUri, CSSStyleSheetInner::gIOService);
// XXX what about failure of NS_MakeAbsoluteURI here?
NS_RELEASE(baseUri);
NS_IF_RELEASE(docURL);
linkHandler->GetLinkState(absURLSpec.GetUnicode(), linkState);
linkHandler->GetLinkState(linkURI, linkState);
}
}
else {

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

@ -858,25 +858,17 @@ HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
}
}
else {
nsIURI* docURL = nsnull;
nsIHTMLContent* htmlContent;
if (NS_SUCCEEDED(styledContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
htmlContent->GetBaseURL(docURL);
nsCOMPtr<nsIURI> baseURI;
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
nsAutoString absURLSpec;
nsresult rv;
nsIURI *baseUri = nsnull;
rv = docURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return 0;
rv = NS_MakeAbsoluteURI(absURLSpec, href, baseUri);
NS_RELEASE(baseUri);
NS_IF_RELEASE(docURL);
nsCOMPtr<nsIURI> linkURI;
(void) NS_NewURI(getter_AddRefs(linkURI), href, baseURI);
nsLinkState state;
if (NS_OK == linkHandler->GetLinkState(absURLSpec.GetUnicode(), state)) {
if (NS_OK == linkHandler->GetLinkState(linkURI, state)) {
switch (state) {
case eLinkState_Unvisited:
if (nsnull != mLinkRule) {

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

@ -274,7 +274,7 @@ public:
NS_IMETHOD OnOverLink(nsIContent* aContent,
const PRUnichar* aURLSpec,
const PRUnichar* aTargetSpec);
NS_IMETHOD GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState);
NS_IMETHOD GetLinkState(nsIURI* aLinkURI, nsLinkState& aState);
// nsIProgressEventSink
NS_DECL_NSIPROGRESSEVENTSINK
@ -1781,8 +1781,12 @@ nsWebShell::OnOverLink(nsIContent* aContent,
}
NS_IMETHODIMP
nsWebShell::GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
nsWebShell::GetLinkState(nsIURI* aLinkURI, nsLinkState& aState)
{
NS_PRECONDITION(aLinkURI != nsnull, "null ptr");
if (! aLinkURI)
return NS_ERROR_NULL_POINTER;
aState = eLinkState_Unvisited;
nsresult rv;
@ -1800,31 +1804,11 @@ nsWebShell::GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
if (mHistoryService) {
// XXX aURLSpec should really be a char*, not a PRUnichar*.
nsAutoString urlStr(aURLSpec);
char buf[256];
char* url = buf;
if (urlStr.Length() >= PRInt32(sizeof buf)) {
url = new char[urlStr.Length() + 1];
}
nsXPIDLCString url;
aLinkURI->GetSpec(getter_Copies(url));
PRInt64 lastVisitDate;
if (url) {
urlStr.ToCString(url, urlStr.Length() + 1);
rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
if (url != buf)
delete[] url;
}
else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
//XXX: Moved to destructor nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
if (NS_FAILED(rv)) return rv;
// a last-visit-date of zero means we've never seen it before; so

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

@ -2726,33 +2726,26 @@ static PRBool SelectorMatches(nsIPresContext* aPresContext,
aPresContext->GetLinkHandler(&linkHandler);
if (linkHandler) {
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
nsIURI* docURL = nsnull;
nsIHTMLContent* htmlContent;
if (NS_SUCCEEDED(aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
htmlContent->GetBaseURL(docURL);
NS_RELEASE(htmlContent);
nsCOMPtr<nsIURI> baseURI = nsnull;
nsCOMPtr<nsIHTMLContent> htmlContent = do_QueryInterface(aContent);
if (htmlContent) {
// XXX why do this? will nsIHTMLContent's
// GetBaseURL() may return something different
// than the URL of the document it lives in?
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
}
else {
nsIDocument* doc = nsnull;
aContent->GetDocument(doc);
if (nsnull != doc) {
doc->GetBaseURL(docURL);
NS_RELEASE(doc);
nsCOMPtr<nsIDocument> doc;
aContent->GetDocument(*getter_AddRefs(doc));
if (doc) {
doc->GetBaseURL(*getter_AddRefs(baseURI));
}
}
nsAutoString absURLSpec;
nsresult rv;
nsIURI *baseUri = nsnull;
rv = docURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return PR_FALSE;
nsCOMPtr<nsIURI> linkURI;
(void) NS_NewURI(getter_AddRefs(linkURI), href, baseURI, CSSStyleSheetInner::gIOService);
(void)NS_MakeAbsoluteURI(absURLSpec, href, baseUri, CSSStyleSheetInner::gIOService);
// XXX what about failure of NS_MakeAbsoluteURI here?
NS_RELEASE(baseUri);
NS_IF_RELEASE(docURL);
linkHandler->GetLinkState(absURLSpec.GetUnicode(), linkState);
linkHandler->GetLinkState(linkURI, linkState);
}
}
else {

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

@ -858,25 +858,17 @@ HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
}
}
else {
nsIURI* docURL = nsnull;
nsIHTMLContent* htmlContent;
if (NS_SUCCEEDED(styledContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
htmlContent->GetBaseURL(docURL);
nsCOMPtr<nsIURI> baseURI;
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
nsAutoString absURLSpec;
nsresult rv;
nsIURI *baseUri = nsnull;
rv = docURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return 0;
rv = NS_MakeAbsoluteURI(absURLSpec, href, baseUri);
NS_RELEASE(baseUri);
NS_IF_RELEASE(docURL);
nsCOMPtr<nsIURI> linkURI;
(void) NS_NewURI(getter_AddRefs(linkURI), href, baseURI);
nsLinkState state;
if (NS_OK == linkHandler->GetLinkState(absURLSpec.GetUnicode(), state)) {
if (NS_OK == linkHandler->GetLinkState(linkURI, state)) {
switch (state) {
case eLinkState_Unvisited:
if (nsnull != mLinkRule) {

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

@ -2726,33 +2726,26 @@ static PRBool SelectorMatches(nsIPresContext* aPresContext,
aPresContext->GetLinkHandler(&linkHandler);
if (linkHandler) {
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
nsIURI* docURL = nsnull;
nsIHTMLContent* htmlContent;
if (NS_SUCCEEDED(aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
htmlContent->GetBaseURL(docURL);
NS_RELEASE(htmlContent);
nsCOMPtr<nsIURI> baseURI = nsnull;
nsCOMPtr<nsIHTMLContent> htmlContent = do_QueryInterface(aContent);
if (htmlContent) {
// XXX why do this? will nsIHTMLContent's
// GetBaseURL() may return something different
// than the URL of the document it lives in?
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
}
else {
nsIDocument* doc = nsnull;
aContent->GetDocument(doc);
if (nsnull != doc) {
doc->GetBaseURL(docURL);
NS_RELEASE(doc);
nsCOMPtr<nsIDocument> doc;
aContent->GetDocument(*getter_AddRefs(doc));
if (doc) {
doc->GetBaseURL(*getter_AddRefs(baseURI));
}
}
nsAutoString absURLSpec;
nsresult rv;
nsIURI *baseUri = nsnull;
rv = docURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return PR_FALSE;
nsCOMPtr<nsIURI> linkURI;
(void) NS_NewURI(getter_AddRefs(linkURI), href, baseURI, CSSStyleSheetInner::gIOService);
(void)NS_MakeAbsoluteURI(absURLSpec, href, baseUri, CSSStyleSheetInner::gIOService);
// XXX what about failure of NS_MakeAbsoluteURI here?
NS_RELEASE(baseUri);
NS_IF_RELEASE(docURL);
linkHandler->GetLinkState(absURLSpec.GetUnicode(), linkState);
linkHandler->GetLinkState(linkURI, linkState);
}
}
else {

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

@ -858,25 +858,17 @@ HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
}
}
else {
nsIURI* docURL = nsnull;
nsIHTMLContent* htmlContent;
if (NS_SUCCEEDED(styledContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent))) {
htmlContent->GetBaseURL(docURL);
nsCOMPtr<nsIURI> baseURI;
htmlContent->GetBaseURL(*getter_AddRefs(baseURI));
nsAutoString absURLSpec;
nsresult rv;
nsIURI *baseUri = nsnull;
rv = docURL->QueryInterface(NS_GET_IID(nsIURI), (void**)&baseUri);
if (NS_FAILED(rv)) return 0;
rv = NS_MakeAbsoluteURI(absURLSpec, href, baseUri);
NS_RELEASE(baseUri);
NS_IF_RELEASE(docURL);
nsCOMPtr<nsIURI> linkURI;
(void) NS_NewURI(getter_AddRefs(linkURI), href, baseURI);
nsLinkState state;
if (NS_OK == linkHandler->GetLinkState(absURLSpec.GetUnicode(), state)) {
if (NS_OK == linkHandler->GetLinkState(linkURI, state)) {
switch (state) {
case eLinkState_Unvisited:
if (nsnull != mLinkRule) {

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

@ -27,6 +27,7 @@
class nsIInputStream;
class nsIContent;
class nsIURI;
struct nsGUIEvent;
// Interface ID for nsILinkHandler
@ -82,7 +83,7 @@ public:
/**
* Get the state of a link to a given absolute URL
*/
NS_IMETHOD GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState) = 0;
NS_IMETHOD GetLinkState(nsIURI* aLinkURI, nsLinkState& aState) = 0;
};
#endif /* nsILinkHandler_h___ */

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

@ -274,7 +274,7 @@ public:
NS_IMETHOD OnOverLink(nsIContent* aContent,
const PRUnichar* aURLSpec,
const PRUnichar* aTargetSpec);
NS_IMETHOD GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState);
NS_IMETHOD GetLinkState(nsIURI* aLinkURI, nsLinkState& aState);
// nsIProgressEventSink
NS_DECL_NSIPROGRESSEVENTSINK
@ -1781,8 +1781,12 @@ nsWebShell::OnOverLink(nsIContent* aContent,
}
NS_IMETHODIMP
nsWebShell::GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
nsWebShell::GetLinkState(nsIURI* aLinkURI, nsLinkState& aState)
{
NS_PRECONDITION(aLinkURI != nsnull, "null ptr");
if (! aLinkURI)
return NS_ERROR_NULL_POINTER;
aState = eLinkState_Unvisited;
nsresult rv;
@ -1800,31 +1804,11 @@ nsWebShell::GetLinkState(const PRUnichar* aURLSpec, nsLinkState& aState)
if (mHistoryService) {
// XXX aURLSpec should really be a char*, not a PRUnichar*.
nsAutoString urlStr(aURLSpec);
char buf[256];
char* url = buf;
if (urlStr.Length() >= PRInt32(sizeof buf)) {
url = new char[urlStr.Length() + 1];
}
nsXPIDLCString url;
aLinkURI->GetSpec(getter_Copies(url));
PRInt64 lastVisitDate;
if (url) {
urlStr.ToCString(url, urlStr.Length() + 1);
rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
if (url != buf)
delete[] url;
}
else {
rv = NS_ERROR_OUT_OF_MEMORY;
}
//XXX: Moved to destructor nsServiceManager::ReleaseService(kGlobalHistoryCID, mHistoryService);
rv = mHistoryService->GetLastVisitDate(url, &lastVisitDate);
if (NS_FAILED(rv)) return rv;
// a last-visit-date of zero means we've never seen it before; so

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

@ -17,6 +17,9 @@
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author(s):
* Chris Waterson <waterson@netscape.com>
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
@ -297,84 +300,12 @@ public:
// nsIGlobalHistory
NS_DECL_NSIGLOBALHISTORY
// nsIRDFDataSource
NS_DECL_NSIRDFDATASOURCE
// nsIRDFRemoteDataSource
NS_DECL_NSIRDFREMOTEDATASOURCE
// nsIRDFDataSource
NS_IMETHOD GetURI(char* *aURI);
NS_IMETHOD GetSource(nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
PRBool aTruthValue,
nsIRDFResource** aSource);
NS_IMETHOD GetSources(nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
PRBool aTruthValue,
nsISimpleEnumerator** aSources);
NS_IMETHOD GetTarget(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
PRBool aTruthValue,
nsIRDFNode** aTarget);
NS_IMETHOD GetTargets(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
PRBool aTruthValue,
nsISimpleEnumerator** aTargets);
NS_IMETHOD Assert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
PRBool aTruthValue);
NS_IMETHOD Unassert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
PRBool aTruthValue,
PRBool* aHasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* aObserver);
NS_IMETHOD RemoveObserver(nsIRDFObserver* aObserver);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* aNode,
nsISimpleEnumerator** aLabels);
NS_IMETHOD ArcLabelsOut(nsIRDFResource* aSource,
nsISimpleEnumerator** aLabels);
NS_IMETHOD GetAllCommands(nsIRDFResource* aSource,
nsIEnumerator/*<nsIRDFResource>*/** aCommands);
NS_IMETHOD GetAllCmds(nsIRDFResource* aSource,
nsISimpleEnumerator/*<nsIRDFResource>*/** aCommands);
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
PRBool* aResult);
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult);
protected:
nsGlobalHistory(void);
virtual ~nsGlobalHistory();
@ -806,6 +737,10 @@ nsGlobalHistory::RemovePage(const char *aURL)
NS_IMETHODIMP
nsGlobalHistory::GetLastVisitDate(const char *aURL, PRInt64 *_retval)
{
NS_PRECONDITION(aURL != nsnull, "null ptr");
if (! aURL)
return NS_ERROR_NULL_POINTER;
nsresult rv;
mdb_err err;