From c8948a35f63058c35cb8fbcc09b2e2ca36786334 Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Fri, 4 Feb 2000 08:45:34 +0000 Subject: [PATCH] more prepation for docshell landing. Implement IsPreferred and move implemtation of CanHandlecontent from the application layer into the webshell/docshell layer. r=travis git-svn-id: svn://10.0.0.236/trunk@59760 18797224-902f-48f8-a5cc-f745e15eee43 --- .../docshell/base/nsDSURIContentListener.cpp | 66 ++++++++++++++++- mozilla/gfx/src/nsImageNetContextAsync.cpp | 11 +++ mozilla/mailnews/base/src/nsMsgWindow.cpp | 73 ++++++++----------- mozilla/mailnews/compose/src/nsURLFetcher.cpp | 12 +++ 4 files changed, 115 insertions(+), 47 deletions(-) diff --git a/mozilla/docshell/base/nsDSURIContentListener.cpp b/mozilla/docshell/base/nsDSURIContentListener.cpp index fba33cde8d7..85153e38bbf 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.cpp +++ b/mozilla/docshell/base/nsDSURIContentListener.cpp @@ -92,18 +92,78 @@ NS_IMETHODIMP nsDSURIContentListener::DoContent(const char* aContentType, nsURIL return NS_OK; } -NS_IMETHODIMP nsDSURIContentListener::CanHandleContent(const char* aContentType, +NS_IMETHODIMP nsDSURIContentListener::IsPreferred(const char* aContentType, nsURILoadCommand aCommand, const char* aWindowTarget, char ** aDesiredContentType, PRBool* aCanHandle) { NS_ENSURE_ARG_POINTER(aCanHandle); NS_ENSURE_ARG_POINTER(aDesiredContentType); - *aDesiredContentType = nsnull; + // the docshell has no idea if it is the preferred content provider or not. + // It needs to ask it's parent if it is the preferred content handler or not... + + if(mParentContentListener) + return mParentContentListener->IsPreferred(aContentType, aCommand, + aWindowTarget, aDesiredContentType, aCanHandle); + else + *aCanHandle = PR_FALSE; - *aCanHandle = PR_TRUE; // Always say true and let DoContent decide. return NS_OK; } +NS_IMETHODIMP nsDSURIContentListener::CanHandleContent(const char* aContentType, + nsURILoadCommand aCommand, const char* aWindowTarget, char ** aDesiredContentType, PRBool* aCanHandleContent) +{ + NS_ENSURE_ARG_POINTER(aCanHandleContent); + NS_ENSURE_ARG_POINTER(aDesiredContentType); + + // this implementation should be the same for all webshell's so no need to pass it up the chain... + // although I suspect if aWindowTarget has a value, we will need to pass it up the chain in order to find + // the desired window target. + + // a webshell can handle the following types. Eventually I think we want to get this information + // from the registry and in addition, we want to + // incoming Type Preferred type + // text/html + // text/xul + // text/rdf + // text/xml + // text/css + // image/gif + // image/jpeg + // image/png + // image/tiff + // application/http-index-format + // message/rfc822 text/xul + + if (aContentType) + { + // (1) list all content types we want to be the primary handler for.... + // and suggest a desired content type if appropriate... + if (nsCRT::strcasecmp(aContentType, "text/html") == 0 + || nsCRT::strcasecmp(aContentType, "text/xul") == 0 + || nsCRT::strcasecmp(aContentType, "text/rdf") == 0 + || nsCRT::strcasecmp(aContentType, "text/xml") == 0 + || nsCRT::strcasecmp(aContentType, "text/css") == 0 + || nsCRT::strcasecmp(aContentType, "image/gif") == 0 + || nsCRT::strcasecmp(aContentType, "image/jpeg") == 0 + || nsCRT::strcasecmp(aContentType, "image/png") == 0 + || nsCRT::strcasecmp(aContentType, "image/tiff") == 0 + || nsCRT::strcasecmp(aContentType, "application/http-index-format") == 0) + *aCanHandleContent = PR_TRUE; + + if (nsCRT::strcasecmp(aContentType, "message/rfc822") == 0) + { + *aCanHandleContent = PR_TRUE; + *aDesiredContentType = nsCRT::strdup("text/html"); + } + } + else + *aCanHandleContent = PR_FALSE; + + // we may need to ask the plugin manager for this webshell if it can handle the content type too... + return NS_OK; +} + NS_IMETHODIMP nsDSURIContentListener::GetParentContentListener(nsIURIContentListener** aParentListener) diff --git a/mozilla/gfx/src/nsImageNetContextAsync.cpp b/mozilla/gfx/src/nsImageNetContextAsync.cpp index 21dbd52d7ea..91099c389b0 100644 --- a/mozilla/gfx/src/nsImageNetContextAsync.cpp +++ b/mozilla/gfx/src/nsImageNetContextAsync.cpp @@ -209,6 +209,17 @@ ImageConsumer::SetLoadCookie(nsISupports * aLoadCookie) return NS_OK; } +NS_IMETHODIMP +ImageConsumer::IsPreferred(const char * aContentType, + nsURILoadCommand aCommand, + const char * aWindowTarget, + char ** aDesiredContentType, + PRBool * aCanHandleContent) + +{ + return CanHandleContent(aContentType, aCommand, aWindowTarget, + aDesiredContentType, aCanHandleContent); +} NS_IMETHODIMP ImageConsumer::CanHandleContent(const char * aContentType, diff --git a/mozilla/mailnews/base/src/nsMsgWindow.cpp b/mozilla/mailnews/base/src/nsMsgWindow.cpp index 973b66afbeb..efa6ca84c82 100644 --- a/mozilla/mailnews/base/src/nsMsgWindow.cpp +++ b/mozilla/mailnews/base/src/nsMsgWindow.cpp @@ -32,6 +32,7 @@ #include "nsIDocumentLoader.h" #include "nsILoadGroup.h" #include "nsIMsgMailNewsUrl.h" +#include "nsIInterfaceRequestor.h" static NS_DEFINE_CID(kTransactionManagerCID, NS_TRANSACTIONMANAGER_CID); static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); @@ -268,36 +269,20 @@ NS_IMETHODIMP nsMsgWindow::DoContent(const char *aContentType, nsURILoadCommand return NS_OK; } -NS_IMETHODIMP nsMsgWindow::CanHandleContent(const char * aContentType, - nsURILoadCommand aCommand, - const char * aWindowTarget, - char ** aDesiredContentType, - PRBool * aCanHandleContent) - +NS_IMETHODIMP +nsMsgWindow::IsPreferred(const char * aContentType, + nsURILoadCommand aCommand, + const char * aWindowTarget, + char ** aDesiredContentType, + PRBool * aCanHandleContent) { // the mail window is the primary content handler for the following types: // If we are asked to handle any of these types, we will always say Yes! // regardlesss of the uri load command. // Incoming Type Preferred type - // message/rfc822 text/xul + // message/rfc822 text/html // - // the mail window can also show the following content types. However, it isn't - // the primary content handler for these types. So we won't try to accept this content - // unless the uri load command is viewNormal (which implies that we are trying to view a url inline) - // incoming Type Preferred type - // text/html - // text/xul - // image/gif - // image/jpeg - // image/png - // image/tiff - - - *aCanHandleContent = PR_FALSE; - - // (1) list all content types we want to be the primary handler for.... - // and suggest a desired content type if appropriate... if (aContentType && nsCRT::strcasecmp(aContentType, "message/rfc822") == 0) { // we can handle this content type...but we would prefer it to be @@ -306,31 +291,31 @@ NS_IMETHODIMP nsMsgWindow::CanHandleContent(const char * aContentType, *aDesiredContentType = nsCRT::strdup("text/html"); } else - { - // (2) list all the content types we can handle IF we really have too....i.e. - // if the load command is viewNormal. This includes text/xul, text/html right now. - // I'm sure it will grow. - - // for right now, if the load command is viewNormal just say we can handle it... - if (aCommand == nsIURILoader::viewNormal) - { - if (nsCRT::strcasecmp(aContentType, "text/html") == 0 - || nsCRT::strcasecmp(aContentType, "text/xul") == 0 - || nsCRT::strcasecmp(aContentType, "text/rdf") == 0 - || nsCRT::strcasecmp(aContentType, "text/xml") == 0 - || nsCRT::strcasecmp(aContentType, "text/css") == 0 - || nsCRT::strcasecmp(aContentType, "image/gif") == 0 - || nsCRT::strcasecmp(aContentType, "image/jpeg") == 0 - || nsCRT::strcasecmp(aContentType, "image/png") == 0 - || nsCRT::strcasecmp(aContentType, "image/tiff") == 0 - || nsCRT::strcasecmp(aContentType, "application/http-index-format") == 0) - *aCanHandleContent = PR_TRUE; - } - } + *aCanHandleContent = PR_FALSE; return NS_OK; } +NS_IMETHODIMP nsMsgWindow::CanHandleContent(const char * aContentType, + nsURILoadCommand aCommand, + const char * aWindowTarget, + char ** aDesiredContentType, + PRBool * aCanHandleContent) + +{ + // the mail window knows nothing about the default content types + // it's docshell can handle...ask the content area if it can handle + // the content type... + + nsCOMPtr ctnListener (do_GetInterface(mMessageWindowWebShell)); + if (ctnListener) + return ctnListener->CanHandleContent(aContentType, aCommand, aWindowTarget, + aDesiredContentType, aCanHandleContent); + else + *aCanHandleContent = PR_FALSE; + return NS_OK; +} + NS_IMETHODIMP nsMsgWindow::GetParentContentListener(nsIURIContentListener** aParent) { *aParent = nsnull; diff --git a/mozilla/mailnews/compose/src/nsURLFetcher.cpp b/mozilla/mailnews/compose/src/nsURLFetcher.cpp index 6968d78684a..e37c8d47493 100644 --- a/mozilla/mailnews/compose/src/nsURLFetcher.cpp +++ b/mozilla/mailnews/compose/src/nsURLFetcher.cpp @@ -110,6 +110,18 @@ nsURLFetcher::GetProtocolHandler(nsIURI *aURI, nsIProtocolHandler **aProtocolHan return NS_OK; } +NS_IMETHODIMP +nsURLFetcher::IsPreferred(const char * aContentType, + nsURILoadCommand aCommand, + const char * aWindowTarget, + char ** aDesiredContentType, + PRBool * aCanHandleContent) + +{ + return CanHandleContent(aContentType, aCommand, aWindowTarget, aDesiredContentType, + aCanHandleContent); +} + NS_IMETHODIMP nsURLFetcher::CanHandleContent(const char * aContentType, nsURILoadCommand aCommand,