diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 590bf7170e69..14c0fa1acfd0 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -133,6 +133,7 @@ #include "nsIWebBrowserChromeFocus.h" #include "nsPluginError.h" +#include "nsIURL.h" static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); @@ -4329,6 +4330,29 @@ nsDocShell::NewContentViewerObj(const char *aContentType, nsIStreamListener ** aContentHandler, nsIContentViewer ** aViewer) { + nsCOMPtr pluginHost (do_GetService(kPluginManagerCID)); + nsCOMPtr aOpenedChannel = do_QueryInterface(request); + + // check plugins to see if there is an override mime type for this extension + if (pluginHost && + NS_FAILED(pluginHost->IsPluginEnabledForType(aContentType))) { + // get the extension from the url which we get from the channel + nsCOMPtr uri; + if (NS_SUCCEEDED(aOpenedChannel->GetURI(getter_AddRefs(uri)))) { + nsCOMPtr url = do_QueryInterface(uri); + if (url) { + nsCAutoString fileExtension; + url->GetFileExtension(fileExtension); + if (!fileExtension.IsEmpty()) { + // ask the plugin host for a mime type for this extension + const char* pluginMimeType; + if (NS_SUCCEEDED(pluginHost->IsPluginEnabledForExtension(fileExtension.get(), pluginMimeType))) + aContentType = pluginMimeType; + } + } + } + } + //XXX This should probably be some category thing.... nsCAutoString contractId(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view" @@ -4344,7 +4368,7 @@ nsDocShell::NewContentViewerObj(const char *aContentType, docLoaderFactory(do_CreateInstance(contractId.get())); if (!docLoaderFactory) { // try again after loading plugins - nsCOMPtr pluginManager = do_GetService(kPluginManagerCID); + nsCOMPtr pluginManager = do_QueryInterface(pluginHost); if (!pluginManager) return NS_ERROR_FAILURE; @@ -4360,8 +4384,6 @@ nsDocShell::NewContentViewerObj(const char *aContentType, return NS_ERROR_FAILURE; } - nsCOMPtr aOpenedChannel = do_QueryInterface(request); - // Now create an instance of the content viewer NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance("view", aOpenedChannel, diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index 804af532f03e..57b0ec5e6651 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -3859,20 +3859,19 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, if(!aURL) return NS_ERROR_FAILURE; - // if don't have a mimetype, check by file extension - if(!aMimeType) - { - char* extension; - - nsCAutoString filename; - aURL->GetPath(filename); - extension = PL_strrchr(filename.get(), '.'); - if(extension) - ++extension; - else - return NS_ERROR_FAILURE; - - if(IsPluginEnabledForExtension(extension, mimetype) != NS_OK) + // if don't have a mimetype or no plugin can handle this mimetype + // check by file extension + if(!aMimeType || NS_FAILED(IsPluginEnabledForType(aMimeType))) { + nsCOMPtr url = do_QueryInterface(aURL); + if (!url) return NS_ERROR_FAILURE; + + nsCAutoString fileExtension; + url->GetFileExtension(fileExtension); + + // if we don't have an extension or no plugin for this extension, + // return failure as there is nothing more we can do + if (fileExtension.IsEmpty() || + NS_FAILED(IsPluginEnabledForExtension(fileExtension.get(), mimetype))) return NS_ERROR_FAILURE; } else