From 24af553d8ac600e29c16fc62ea5361c62ece18dc Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Sat, 17 Dec 2005 18:31:02 +0000 Subject: [PATCH] bug 309525 Consider content that we don't otherwise support, but for which we have a stream converter, as supported document types. Change code to use nsIURILoader to load the data, instead of asking docshell directly. r+sr=bz git-svn-id: svn://10.0.0.236/trunk@186206 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/Makefile.in | 1 + .../base/src/nsObjectLoadingContent.cpp | 51 ++++++++++++------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/mozilla/content/base/src/Makefile.in b/mozilla/content/base/src/Makefile.in index 68da7aa1d52..6ee813a4b76 100644 --- a/mozilla/content/base/src/Makefile.in +++ b/mozilla/content/base/src/Makefile.in @@ -72,6 +72,7 @@ REQUIRES = xpcom \ plugin \ prefetch \ xuldoc \ + uriloader \ $(NULL) EXPORTS = \ diff --git a/mozilla/content/base/src/nsObjectLoadingContent.cpp b/mozilla/content/base/src/nsObjectLoadingContent.cpp index 0580dd2610f..0d05754119d 100644 --- a/mozilla/content/base/src/nsObjectLoadingContent.cpp +++ b/mozilla/content/base/src/nsObjectLoadingContent.cpp @@ -48,7 +48,8 @@ #include "nsIPresShell.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" -#include "nsIURIContentListener.h" +#include "nsIStreamConverterService.h" +#include "nsIURILoader.h" #include "nsIURL.h" #include "nsIWebNavigation.h" #include "nsIWebNavigationInfo.h" @@ -58,6 +59,7 @@ #include "prlog.h" #include "nsAutoPtr.h" +#include "nsCURILoader.h" #include "nsContentPolicyUtils.h" #include "nsContentUtils.h" #include "nsDocShellCID.h" @@ -342,7 +344,8 @@ nsObjectLoadingContent::OnStartRequest(nsIRequest *aRequest, nsISupports *aConte // UnloadContent will set our type to null; need to be sure to only set it to // the real value on success ObjectType newType = GetTypeOfContent(mContentType); - LOG(("OBJLC [%p]: OnStartRequest: Old type=%u New Type=%u\n", this, mType, newType)); + LOG(("OBJLC [%p]: OnStartRequest: Content Type=<%s> Old type=%u New Type=%u\n", + this, mContentType.get(), mType, newType)); if (mType != newType) { UnloadContent(); } @@ -386,23 +389,15 @@ nsObjectLoadingContent::OnStartRequest(nsIRequest *aRequest, nsISupports *aConte nsCOMPtr docShell; rv = mFrameLoader->GetDocShell(getter_AddRefs(docShell)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr listener(do_GetInterface(docShell)); - NS_ASSERTION(listener, "No content listener on the docshell?"); -#ifdef DEBUG - // Since this is a supported document type, the docshell must support it. - nsXPIDLCString str; - PRBool canHandle; - rv = listener->CanHandleContent(mContentType.get(), PR_TRUE, - getter_Copies(str), &canHandle); - NS_ASSERTION(NS_FAILED(rv) || canHandle, "Docshell should handle this!"); -#endif + nsCOMPtr req(do_QueryInterface(docShell)); + NS_ASSERTION(req, "Docshell must be an ifreq"); - PRBool abort; - rv = listener->DoContent(mContentType.get(), PR_TRUE, aRequest, - getter_AddRefs(mFinalListener), &abort); + nsCOMPtr + uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); - NS_ASSERTION(!abort, "Docshell content listeners shouldn't abort loads"); + rv = uriLoader->OpenChannel(chan, nsIURILoader::DONT_RETARGET, req, + getter_AddRefs(mFinalListener)); break; } case eType_Plugin: @@ -1088,9 +1083,27 @@ nsObjectLoadingContent::IsSupportedDocument(const nsCString& aMimeType) rv = info->IsTypeSupported(aMimeType, webNav, &supported); } - return NS_SUCCEEDED(rv) && - supported != nsIWebNavigationInfo::UNSUPPORTED && - supported != nsIWebNavigationInfo::PLUGIN; + if (NS_SUCCEEDED(rv)) { + if (supported == nsIWebNavigationInfo::UNSUPPORTED) { + // Try a stream converter + // NOTE: We treat any type we can convert from as a supported type. If a + // type is not actually supported, the URI loader will detect that and + // return an error, and we'll fallback. + nsCOMPtr convServ = + do_GetService("@mozilla.org/streamConverters;1"); + PRBool canConvert = PR_FALSE; + if (convServ) { + rv = convServ->CanConvert(aMimeType.get(), "*/*", &canConvert); + } + + return NS_SUCCEEDED(rv) && canConvert; + } + + // Don't want to support plugins as documents + return supported != nsIWebNavigationInfo::PLUGIN; + } + + return PR_FALSE; } void