fix for bug 202817 - clicking on a link that returns a non-trivial mimetype results in download rather than view. p=bz r=blizzard sr=darin

This commit is contained in:
wade%ezri.org 2003-04-22 23:32:49 +00:00
Родитель 7892a93f8c
Коммит 614a90cc82
4 изменённых файлов: 72 добавлений и 58 удалений

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

@ -401,11 +401,14 @@ NS_IMETHODIMP CWebBrowserContainer::IsPreferred(const char *aContentType, char *
/* boolean canHandleContent (in string aContentType, in PRBool aIsContentPreferred, out string aDesiredContentType); */
NS_IMETHODIMP CWebBrowserContainer::CanHandleContent(const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType, PRBool *_retval)
{
*_retval = PR_FALSE;
if (aContentType)
{
nsCOMPtr<nsICategoryManager> catMgr;
nsresult rv;
catMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString value;
rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers",
aContentType,

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

@ -27,6 +27,9 @@
#include "EmbedContentListener.h"
#include "EmbedPrivate.h"
#include "nsICategoryManager.h"
#include "nsIServiceManagerUtils.h"
EmbedContentListener::EmbedContentListener(void)
{
mOwner = nsnull;
@ -84,27 +87,8 @@ EmbedContentListener::IsPreferred(const char *aContentType,
char **aDesiredContentType,
PRBool *aCanHandleContent)
{
if (aContentType &&
(!strcasecmp(aContentType, "text/html") ||
!strcasecmp(aContentType, "text/plain") ||
!strcasecmp(aContentType, "application/vnd.mozilla.xul+xml") ||
!strcasecmp(aContentType, "text/rdf") ||
!strcasecmp(aContentType, "text/xml") ||
!strcasecmp(aContentType, "application/xml") ||
!strcasecmp(aContentType, "application/xhtml+xml") ||
!strcasecmp(aContentType, "text/css") ||
!strcasecmp(aContentType, "image/gif") ||
!strcasecmp(aContentType, "image/jpeg") ||
!strcasecmp(aContentType, "image/png") ||
!strcasecmp(aContentType, "image/tiff") ||
!strcasecmp(aContentType, "application/http-index-format"))) {
*aCanHandleContent = PR_TRUE;
}
else {
*aCanHandleContent = PR_FALSE;
}
return NS_OK;
return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType,
aCanHandleContent);
}
NS_IMETHODIMP
@ -113,7 +97,29 @@ EmbedContentListener::CanHandleContent(const char *aContentType,
char **aDesiredContentType,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
*_retval = PR_FALSE;
if (aContentType) {
nsCOMPtr<nsICategoryManager> catMgr;
nsresult rv;
catMgr = do_GetService("@mozilla.org/categorymanager;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString value;
rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers",
aContentType,
getter_Copies(value));
// If the category manager can't find what we're looking for
// it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate
// that to the caller since it's really not a failure
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
return rv;
if (value && *value)
*_retval = PR_TRUE;
}
return NS_OK;
}
NS_IMETHODIMP

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

@ -30,9 +30,11 @@
#include "PtMozilla.h"
#include "nsICategoryManager.h"
#include "nsIServiceManagerUtils.h"
EmbedContentListener::EmbedContentListener(void)
{
NS_INIT_ISUPPORTS();
mOwner = nsnull;
}
@ -97,27 +99,8 @@ EmbedContentListener::IsPreferred(const char *aContentType,
char **aDesiredContentType,
PRBool *aCanHandleContent)
{
if (aContentType &&
(!strcasecmp(aContentType, "text/html") ||
!strcasecmp(aContentType, "text/plain") ||
!strcasecmp(aContentType, "application/vnd.mozilla.xul+xml") ||
!strcasecmp(aContentType, "text/rdf") ||
!strcasecmp(aContentType, "text/xml") ||
!strcasecmp(aContentType, "application/xml") ||
!strcasecmp(aContentType, "application/xhtml+xml") ||
!strcasecmp(aContentType, "text/css") ||
!strcasecmp(aContentType, "image/gif") ||
!strcasecmp(aContentType, "image/jpeg") ||
!strcasecmp(aContentType, "image/png") ||
!strcasecmp(aContentType, "image/tiff") ||
!strcasecmp(aContentType, "application/http-index-format"))) {
*aCanHandleContent = PR_TRUE;
}
else {
*aCanHandleContent = PR_FALSE;
}
return NS_OK;
return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType,
aCanHandleContent);
}
NS_IMETHODIMP
@ -126,7 +109,29 @@ EmbedContentListener::CanHandleContent(const char *aContentType,
char **aDesiredContentType,
PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
*_retval = PR_FALSE;
if (aContentType) {
nsCOMPtr<nsICategoryManager> catMgr;
nsresult rv;
catMgr = do_GetService("@mozilla.org/categorymanager;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString value;
rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers",
aContentType,
getter_Copies(value));
// If the category manager can't find what we're looking for
// it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate
// that to the caller since it's really not a failure
if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
return rv;
if (value && *value)
*_retval = PR_TRUE;
}
return NS_OK;
}
NS_IMETHODIMP

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

@ -130,21 +130,21 @@ nsBrowserContentListener.prototype =
isPreferred: function(contentType, desiredContentType)
{
// seems like we should be getting this from helper apps or something
switch(contentType) {
case "text/html":
case "text/xul":
case "text/rdf":
case "text/xml":
case "text/css":
case "image/gif":
case "image/jpeg":
case "image/png":
case "text/plain":
case "application/http-index-format":
try {
var catMgr = Components.classes["@mozilla.org/categorymanager;1"]
.getService(Components.interfaces.nsICategoryManager);
var entry = catMgr.getCategoryEntry("Gecko-Content-Viewers",
contentType);
if (entry) {
return true;
}
return false;
} catch (e) {
// XXX propagate failures other than "NS_ERROR_NOT_AVAILABLE"?
// This seems to never get called, so not like it matters....
return false;
}
return false;
},
canHandleContent: function(contentType, isContentPreferred, desiredContentType)
{