diff --git a/embedding/browser/activex/src/control/WebBrowserContainer.cpp b/embedding/browser/activex/src/control/WebBrowserContainer.cpp index 20e96fee5dee..3de5c803aef9 100644 --- a/embedding/browser/activex/src/control/WebBrowserContainer.cpp +++ b/embedding/browser/activex/src/control/WebBrowserContainer.cpp @@ -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 catMgr; nsresult rv; catMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); nsXPIDLCString value; rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers", aContentType, diff --git a/embedding/browser/gtk/src/EmbedContentListener.cpp b/embedding/browser/gtk/src/EmbedContentListener.cpp index 912c8e718dc6..4f2c3e576025 100644 --- a/embedding/browser/gtk/src/EmbedContentListener.cpp +++ b/embedding/browser/gtk/src/EmbedContentListener.cpp @@ -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 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 diff --git a/embedding/browser/photon/src/EmbedContentListener.cpp b/embedding/browser/photon/src/EmbedContentListener.cpp index af30dee06792..d61f940dae15 100644 --- a/embedding/browser/photon/src/EmbedContentListener.cpp +++ b/embedding/browser/photon/src/EmbedContentListener.cpp @@ -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 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 diff --git a/xpfe/browser/resources/content/nsBrowserContentListener.js b/xpfe/browser/resources/content/nsBrowserContentListener.js index f716852bf8db..c01b3628d203 100644 --- a/xpfe/browser/resources/content/nsBrowserContentListener.js +++ b/xpfe/browser/resources/content/nsBrowserContentListener.js @@ -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) {