diff --git a/mozilla/docshell/base/nsDSURIContentListener.cpp b/mozilla/docshell/base/nsDSURIContentListener.cpp index e0215b3d638..097fc5efe1f 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.cpp +++ b/mozilla/docshell/base/nsDSURIContentListener.cpp @@ -23,6 +23,7 @@ #include "nsDocShell.h" #include "nsDSURIContentListener.h" #include "nsIChannel.h" +#include "nsXPIDLString.h" //***************************************************************************** //*** nsDSURIContentListener: Object Management @@ -38,6 +39,15 @@ nsDSURIContentListener::~nsDSURIContentListener() { } +nsresult +nsDSURIContentListener::Init() +{ + nsresult rv = NS_OK; + mCatMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + return rv; +} + + //***************************************************************************** // nsDSURIContentListener::nsISupports //***************************************************************************** @@ -146,48 +156,21 @@ NS_IMETHODIMP nsDSURIContentListener::CanHandleContent(const char* aContentType, 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 - // application/vnd.mozilla.xul+xml - // text/rdf - // text/xml - // text/css - // image/gif - // image/jpeg - // image/png - // image/tiff - // application/http-index-format - // message/rfc822 application/vnd.mozilla.xul+xml - 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, "application/vnd.mozilla.xul+xml") == 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, "text/plain") == 0 - || nsCRT::strcasecmp(aContentType, "image/tiff") == 0 - || nsCRT::strcasecmp(aContentType, "application/http-index-format") == 0) - *aCanHandleContent = PR_TRUE; - else if (PL_strcasestr(aContentType, "; x-view-type=view-source") != nsnull) + nsXPIDLCString value; + nsresult rv = mCatMgr->GetCategoryEntry("Gecko-Content-Viewers", aContentType, + getter_Copies(value)); + if (NS_FAILED(rv)) return rv; + + if (value && *value) *aCanHandleContent = PR_TRUE; + else + *aCanHandleContent = PR_FALSE; } 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; } diff --git a/mozilla/docshell/base/nsDSURIContentListener.h b/mozilla/docshell/base/nsDSURIContentListener.h index 74bbd8db685..5da2549faaf 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.h +++ b/mozilla/docshell/base/nsDSURIContentListener.h @@ -26,6 +26,7 @@ #include "nsCOMPtr.h" #include "nsString.h" #include "nsIURIContentListener.h" +#include "nsICategoryManager.h" class nsDocShell; @@ -37,6 +38,8 @@ public: NS_DECL_NSIURICONTENTLISTENER + nsresult Init(); + protected: nsDSURIContentListener(); virtual ~nsDSURIContentListener(); @@ -48,6 +51,7 @@ protected: nsDocShell* mDocShell; nsIURIContentListener* mParentContentListener; // Weak Reference + nsCOMPtr mCatMgr; }; #endif /* nsDSURIContentListener_h__ */ diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 9154bf1a880..6449b2d41f8 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -4407,6 +4407,7 @@ NS_IMETHODIMP nsDocShell::GetRootScrollableView(nsIScrollableView** aOutScrollVi NS_IMETHODIMP nsDocShell::EnsureContentListener() { + nsresult rv = NS_OK; if(mContentListener) return NS_OK; @@ -4414,6 +4415,10 @@ NS_IMETHODIMP nsDocShell::EnsureContentListener() NS_ENSURE_TRUE(mContentListener, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(mContentListener); + + rv = mContentListener->Init(); + if (NS_FAILED(rv)) return rv; + mContentListener->DocShell(this); return NS_OK; diff --git a/mozilla/layout/build/nsLayoutDLF.cpp b/mozilla/layout/build/nsLayoutDLF.cpp index cbb69602aab..152dcc563a5 100644 --- a/mozilla/layout/build/nsLayoutDLF.cpp +++ b/mozilla/layout/build/nsLayoutDLF.cpp @@ -22,6 +22,7 @@ #include "nsCOMPtr.h" #include "nsLayoutModule.h" #include "nsIComponentManager.h" +#include "nsICategoryManager.h" #include "nsIDocumentLoader.h" #include "nsIDocumentLoaderFactory.h" #include "nsIDocument.h" @@ -181,38 +182,8 @@ nsLayoutDLF::~nsLayoutDLF() { } -NS_IMPL_ADDREF(nsLayoutDLF) -NS_IMPL_RELEASE(nsLayoutDLF) - -NS_IMETHODIMP -nsLayoutDLF::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) -{ - if (NULL == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - if (aIID.Equals(NS_GET_IID(nsIDocumentLoaderFactory))) { - nsIDocumentLoaderFactory *tmp = this; - *aInstancePtrResult = (void*) tmp; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDocStreamLoaderFactory))) { - nsIDocStreamLoaderFactory *tmp = this; - *aInstancePtrResult = (void*) tmp; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - nsIDocumentLoaderFactory *tmp = this; - nsISupports *tmp2 = tmp; - *aInstancePtrResult = (void*) tmp2; - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} +NS_IMPL_ISUPPORTS2(nsLayoutDLF, nsIDocumentLoaderFactory, + nsIDocStreamLoaderFactory); NS_IMETHODIMP nsLayoutDLF::CreateInstance(const char *aCommand, @@ -550,6 +521,7 @@ static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_ static nsresult RegisterTypes(nsIComponentManager* aCompMgr, + nsICategoryManager* aCatMgr, const char* aCommand, nsIFile* aPath, char** aTypes) @@ -566,9 +538,16 @@ RegisterTypes(nsIComponentManager* aCompMgr, #endif rv = aCompMgr->RegisterComponentSpec(kDocumentFactoryImplCID, "Layout", contractid, aPath, PR_TRUE, PR_TRUE); - if (NS_FAILED(rv)) { - break; - } + if (NS_FAILED(rv)) break; + + // add the MIME types layotu can handle to the handlers category. + // this allows users of layout's viewers (the docshell for example) + // to query the types of viewers layout can create. + nsXPIDLCString previous; + rv = aCatMgr->AddCategoryEntry("Gecko-Content-Viewers", contentType, + contractid, + PR_TRUE, PR_TRUE, getter_Copies(previous)); + if (NS_FAILED(rv)) break; } return rv; } @@ -579,26 +558,29 @@ nsLayoutModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr, { nsresult rv; + nsCOMPtr catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); + if (NS_FAILED(rv)) return rv; + do { - rv = RegisterTypes(aCompMgr, "view", aPath, gHTMLTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, gHTMLTypes); if (NS_FAILED(rv)) break; - rv = RegisterTypes(aCompMgr, "view-source", aPath, gHTMLTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, gHTMLTypes); if (NS_FAILED(rv)) break; - rv = RegisterTypes(aCompMgr, "view", aPath, gXMLTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, gXMLTypes); if (NS_FAILED(rv)) break; - rv = RegisterTypes(aCompMgr, "view-source", aPath, gXMLTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, gXMLTypes); if (NS_FAILED(rv)) break; - rv = RegisterTypes(aCompMgr, "view", aPath, gImageTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, gImageTypes); if (NS_FAILED(rv)) break; - rv = RegisterTypes(aCompMgr, "view", aPath, gRDFTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, gRDFTypes); if (NS_FAILED(rv)) break; - rv = RegisterTypes(aCompMgr, "view-source", aPath, gRDFTypes); + rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, gRDFTypes); if (NS_FAILED(rv)) break; } while (PR_FALSE);