97324 r=peterl/jst sr=jst/bz nsContentDLF.cpp should not use a static list of image types; also: 192023 Make DocLoaderFactories a service
git-svn-id: svn://10.0.0.236/trunk@138608 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -57,6 +57,8 @@
|
||||
#include "nsICanvasFrame.h"
|
||||
#include "nsIPluginViewer.h"
|
||||
#include "nsContentPolicyUtils.h" // NS_CheckContentLoadPolicy(...)
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
|
||||
// we want to explore making the document own the load group
|
||||
// so we can associate the document URI with the load group.
|
||||
@@ -4388,7 +4390,12 @@ nsDocShell::CreateAboutBlankContentViewer()
|
||||
mCreatingDocument = PR_TRUE;
|
||||
|
||||
// one helper factory, please
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docFactory(do_CreateInstance(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=text/html"));
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
|
||||
if (!catMan)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsXPIDLCString contractId;
|
||||
catMan->GetCategoryEntry("Gecko-Content-Viewers", "text/html", getter_Copies(contractId));
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docFactory(do_GetService(contractId));
|
||||
if (docFactory) {
|
||||
|
||||
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
|
||||
@@ -4522,19 +4529,16 @@ nsDocShell::NewContentViewerObj(const char *aContentType,
|
||||
nsCOMPtr<nsIPluginHost> pluginHost (do_GetService(kPluginManagerCID));
|
||||
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
|
||||
|
||||
//XXX This should probably be some category thing....
|
||||
nsCAutoString contractId(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX
|
||||
"view"
|
||||
";1?type=");
|
||||
contractId += aContentType;
|
||||
|
||||
// Note that we're always passing in "view" for the contractid above
|
||||
// and to the docLoaderFactory->CreateInstance() at the end of this method.
|
||||
// nsLayoutDLF makes the determination if it should be a "view-source"
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsXPIDLCString contractId;
|
||||
catMan->GetCategoryEntry("Gecko-Content-Viewers", aContentType, getter_Copies(contractId));
|
||||
|
||||
// Create an instance of the document-loader-factory
|
||||
nsCOMPtr<nsIDocumentLoaderFactory>
|
||||
docLoaderFactory(do_CreateInstance(contractId.get()));
|
||||
docLoaderFactory(do_GetService(contractId.get()));
|
||||
if (!docLoaderFactory) {
|
||||
// try again after loading plugins
|
||||
nsCOMPtr<nsIPluginManager> pluginManager = do_QueryInterface(pluginHost);
|
||||
@@ -4547,13 +4551,16 @@ nsDocShell::NewContentViewerObj(const char *aContentType,
|
||||
if (NS_ERROR_PLUGINS_PLUGINSNOTCHANGED == pluginManager->ReloadPlugins(PR_FALSE))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
docLoaderFactory = do_CreateInstance(contractId.get());
|
||||
catMan->GetCategoryEntry("Gecko-Content-Viewers", aContentType,
|
||||
getter_Copies(contractId));
|
||||
docLoaderFactory = do_GetService(contractId.get());
|
||||
|
||||
if (!docLoaderFactory)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Now create an instance of the content viewer
|
||||
// nsLayoutDLF makes the determination if it should be a "view-source" instead of "view"
|
||||
NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance("view",
|
||||
aOpenedChannel,
|
||||
aLoadGroup, aContentType,
|
||||
|
||||
@@ -52,7 +52,6 @@ typedef unsigned long HMTX;
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsIDocumentLoaderFactory.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIMarkupDocumentViewer.h"
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#include <nsNetUtil.h>
|
||||
#include <prmem.h>
|
||||
|
||||
#include "nsXPCOMCID.h"
|
||||
#include "nsICategoryManager.h"
|
||||
|
||||
#include "nsIContentViewer.h"
|
||||
|
||||
#include "EmbedStream.h"
|
||||
@@ -126,16 +129,19 @@ EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// find a document loader for this command plus content type
|
||||
// combination
|
||||
// find a document loader for this content type
|
||||
|
||||
nsCAutoString docLoaderContractID;
|
||||
docLoaderContractID = NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX;
|
||||
docLoaderContractID += "view;1?type=";
|
||||
docLoaderContractID += aContentType;
|
||||
nsXPIDLCString docLoaderContractID;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", aContentType,
|
||||
getter_Copies(docLoaderContractID));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory;
|
||||
docLoaderFactory = do_CreateInstance(docLoaderContractID.get(), &rv);
|
||||
docLoaderFactory = do_GetService(docLoaderContractID.get(), &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <prmem.h>
|
||||
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
#include "nsICategoryManager.h"
|
||||
|
||||
#include "EmbedStream.h"
|
||||
#include "EmbedPrivate.h"
|
||||
@@ -127,16 +129,18 @@ EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// find a document loader for this command plus content type
|
||||
// combination
|
||||
|
||||
nsCAutoString docLoaderContractID;
|
||||
docLoaderContractID = NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX;
|
||||
docLoaderContractID += "view;1?type=";
|
||||
docLoaderContractID += aContentType;
|
||||
// find a document loader for this content type
|
||||
nsXPIDLCString docLoaderContractID;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", aContentType,
|
||||
getter_Copies(docLoaderContractID));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory;
|
||||
docLoaderFactory = do_CreateInstance(docLoaderContractID.get(), &rv);
|
||||
docLoaderFactory = do_GetService(docLoaderContractID.get(), &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@
|
||||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
|
||||
#include "mozXMLT.h"
|
||||
#include "mozXMLTermUtils.h"
|
||||
#include "mozXMLTermStream.h"
|
||||
@@ -218,21 +221,25 @@ NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindowInternal* aDOMWindow,
|
||||
return result;
|
||||
|
||||
// Create document loader for specified command and content type
|
||||
static const char command[] = "view";
|
||||
nsCAutoString contractID(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX);
|
||||
contractID += command;
|
||||
contractID += ";1?type=";
|
||||
contractID += contentType;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &result));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsXPIDLCString contractID;
|
||||
result = catMan->GetCategoryEntry("Gecko-Content-Viewers", contentType,
|
||||
getter_Copies(contractID));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory;
|
||||
docLoaderFactory = do_CreateInstance(contractID.get(), &result);
|
||||
docLoaderFactory = do_GetService(contractID.get(), &result);
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
|
||||
nsCOMPtr<nsIContentViewerContainer> contViewContainer =
|
||||
do_QueryInterface(docShell);
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
result = docLoaderFactory->CreateInstance(command,
|
||||
result = docLoaderFactory->CreateInstance("view",
|
||||
mChannel,
|
||||
mLoadGroup,
|
||||
contentType,
|
||||
|
||||
@@ -114,25 +114,6 @@ static const char* const gRDFTypes[] = {
|
||||
0
|
||||
};
|
||||
|
||||
static const char* const gImageTypes[] = {
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
"image/jpg",
|
||||
"image/pjpeg",
|
||||
"image/png",
|
||||
"image/x-png",
|
||||
"image/x-art",
|
||||
"image/x-jg",
|
||||
"image/bmp",
|
||||
"image/x-icon",
|
||||
"video/x-mng",
|
||||
"image/x-jng",
|
||||
"image/x-xbitmap",
|
||||
"image/x-xbm",
|
||||
"image/xbm",
|
||||
0
|
||||
};
|
||||
|
||||
nsICSSStyleSheet* nsContentDLF::gUAStyleSheet;
|
||||
|
||||
nsresult
|
||||
@@ -575,48 +556,40 @@ nsContentDLF::CreateXULDocumentFromStream(nsIInputStream& aXULStream,
|
||||
static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
|
||||
|
||||
static nsresult
|
||||
RegisterTypes(nsIComponentManager* aCompMgr,
|
||||
nsICategoryManager* aCatMgr,
|
||||
const char* aCommand,
|
||||
nsIFile* aPath,
|
||||
const char *aLocation,
|
||||
const char *aType,
|
||||
RegisterTypes(nsICategoryManager* aCatMgr,
|
||||
const char* const* aTypes)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
while (*aTypes) {
|
||||
char contractid[500];
|
||||
const char* contentType = *aTypes++;
|
||||
PR_snprintf(contractid, sizeof(contractid),
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "%s;1?type=%s",
|
||||
aCommand, contentType);
|
||||
#ifdef NOISY_REGISTRY
|
||||
printf("Register %s => %s\n", contractid, aPath);
|
||||
#endif
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = registrar->RegisterFactoryLocation(kDocumentFactoryImplCID,
|
||||
"Layout",
|
||||
contractid,
|
||||
aPath,
|
||||
aLocation,
|
||||
aType);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
||||
// add the MIME types layotu can handle to the handlers category.
|
||||
// add the MIME types layout 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));
|
||||
"@mozilla.org/content/document-loader-factory;1",
|
||||
PR_TRUE, PR_TRUE, nsnull);
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult UnregisterTypes(nsICategoryManager* aCatMgr,
|
||||
const char* const* aTypes)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
while (*aTypes) {
|
||||
const char* contentType = *aTypes++;
|
||||
rv = aCatMgr->DeleteCategoryEntry("Gecko-Content-Viewers", contentType, PR_TRUE);
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentDLF::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath,
|
||||
@@ -630,33 +603,18 @@ nsContentDLF::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
do {
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, aLocation, aType, gHTMLTypes);
|
||||
rv = RegisterTypes(catmgr, gHTMLTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, aLocation, aType, gHTMLTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, aLocation, aType, gXMLTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, aLocation, aType, gXMLTypes);
|
||||
rv = RegisterTypes(catmgr, gXMLTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
#ifdef MOZ_SVG
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, aLocation, aType, gSVGTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, aLocation, aType, gSVGTypes);
|
||||
rv = RegisterTypes(catmgr, gSVGTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
#endif
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, aLocation, aType, gImageTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view", aPath, aLocation, aType, gRDFTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = RegisterTypes(aCompMgr, catmgr, "view-source", aPath, aLocation, aType, gRDFTypes);
|
||||
rv = RegisterTypes(catmgr, gRDFTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
} while (PR_FALSE);
|
||||
@@ -669,13 +627,28 @@ nsContentDLF::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
|
||||
const char* aRegistryLocation,
|
||||
const nsModuleComponentInfo* aInfo)
|
||||
{
|
||||
// XXXwaterson seems like this leaves the registry pretty dirty.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsCOMPtr<nsICategoryManager> catmgr(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return registrar->UnregisterFactoryLocation(kDocumentFactoryImplCID, aPath);
|
||||
do {
|
||||
rv = UnregisterTypes(catmgr, gHTMLTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
rv = UnregisterTypes(catmgr, gXMLTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
#ifdef MOZ_SVG
|
||||
rv = UnregisterTypes(catmgr, gSVGTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
#endif
|
||||
rv = UnregisterTypes(catmgr, gRDFTypes);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
} while (PR_FALSE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
|
||||
@@ -1088,7 +1088,7 @@ static const nsModuleComponentInfo gComponents[] = {
|
||||
|
||||
{ "Document Loader Factory",
|
||||
NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID,
|
||||
"@mozilla.org:/content/document-loader-factory;1",
|
||||
"@mozilla.org/content/document-loader-factory;1",
|
||||
CreateContentDLF,
|
||||
nsContentDLF::RegisterDocumentFactories,
|
||||
nsContentDLF::UnregisterDocumentFactories },
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
#include "nsIServiceManagerUtils.h"
|
||||
|
||||
#include "imgCache.h"
|
||||
#include "imgContainer.h"
|
||||
@@ -110,6 +113,66 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsXBMDecoder)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPPMDecoder)
|
||||
#endif
|
||||
|
||||
static const char* gImageMimeTypes[] = {
|
||||
#ifdef IMG_BUILD_gif
|
||||
"image/gif",
|
||||
#endif
|
||||
#ifdef IMG_BUILD_jpeg
|
||||
"image/jpeg",
|
||||
"image/pjpeg",
|
||||
"image/jpg",
|
||||
#endif
|
||||
#ifdef IMG_BUILD_bmp
|
||||
"image/x-icon",
|
||||
"image/bmp",
|
||||
#endif
|
||||
#ifdef IMB_BUILD_png
|
||||
"image/png",
|
||||
"image/x-png",
|
||||
#endif
|
||||
#ifdef IMG_BUILD_xbm
|
||||
"image/x-xbitmap",
|
||||
"image/x-xbm",
|
||||
"image/xbm",
|
||||
#endif
|
||||
#ifdef IMG_BUILD_ppm
|
||||
"image/x-portable-bitmap",
|
||||
"image/x-portable-graymap",
|
||||
"image/x-portable-pixmap"
|
||||
#endif
|
||||
};
|
||||
|
||||
static NS_METHOD ImageRegisterProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType,
|
||||
const nsModuleComponentInfo *info) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
for (int i = 0; i < sizeof(gImageMimeTypes)/sizeof(*gImageMimeTypes); i++) {
|
||||
catMan->AddCategoryEntry("Gecko-Content-Viewers", gImageMimeTypes[i],
|
||||
"@mozilla.org/content/document-loader-factory;1",
|
||||
PR_TRUE, PR_TRUE, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_METHOD ImageUnregisterProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const nsModuleComponentInfo *info) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
for (int i = 0; i < sizeof(gImageMimeTypes)/sizeof(*gImageMimeTypes); i++)
|
||||
catMan->DeleteCategoryEntry("Gecko-Content-Viewers", gImageMimeTypes[i], PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "image cache",
|
||||
@@ -123,7 +186,9 @@ static const nsModuleComponentInfo components[] =
|
||||
{ "image loader",
|
||||
NS_IMGLOADER_CID,
|
||||
"@mozilla.org/image/loader;1",
|
||||
imgLoaderConstructor, },
|
||||
imgLoaderConstructor,
|
||||
ImageRegisterProc, /* register the decoder mime types here */
|
||||
ImageUnregisterProc, },
|
||||
{ "image request proxy",
|
||||
NS_IMGREQUESTPROXY_CID,
|
||||
"@mozilla.org/image/request;1",
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIModule.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
#include "nsIServiceManagerUtils.h"
|
||||
#include "nsMNGDecoder.h"
|
||||
#include "imgContainerMNG.h"
|
||||
|
||||
@@ -29,12 +32,49 @@
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMNGDecoder)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(imgContainerMNG)
|
||||
|
||||
static NS_METHOD MngRegisterProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const char *componentType,
|
||||
const nsModuleComponentInfo *info) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
catMan->AddCategoryEntry("Gecko-Content-Viewers", "video/x-mng",
|
||||
"@mozilla.org/content/document-loader-factory;1",
|
||||
PR_TRUE, PR_TRUE, nsnull);
|
||||
catMan->AddCategoryEntry("Gecko-Content-Viewers", "image/x-jng",
|
||||
"@mozilla.org/content/document-loader-factory;1",
|
||||
PR_TRUE, PR_TRUE, nsnull);
|
||||
catMan->AddCategoryEntry("Gecko-Content-Viewers", "image/x-mng",
|
||||
"@mozilla.org/content/document-loader-factory;1",
|
||||
PR_TRUE, PR_TRUE, nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_METHOD MngUnregisterProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *registryLocation,
|
||||
const nsModuleComponentInfo *info) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
catMan->DeleteCategoryEntry("Gecko-Content-Viewers", "video/x-mng", PR_TRUE);
|
||||
catMan->DeleteCategoryEntry("Gecko-Content-Viewers", "image/x-jng", PR_TRUE);
|
||||
catMan->DeleteCategoryEntry("Gecko-Content-Viewers", "image/x-mng", PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "MNG decoder",
|
||||
NS_MNGDECODER_CID,
|
||||
"@mozilla.org/image/decoder;2?type=video/x-mng",
|
||||
nsMNGDecoderConstructor, },
|
||||
nsMNGDecoderConstructor,
|
||||
MngRegisterProc,
|
||||
MngUnregisterProc },
|
||||
{ "JNG decoder",
|
||||
NS_MNGDECODER_CID,
|
||||
"@mozilla.org/image/decoder;2?type=image/x-jng",
|
||||
|
||||
@@ -91,6 +91,8 @@
|
||||
//#include "nsIRegistry.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
// for the dialog
|
||||
#include "nsIStringBundle.h"
|
||||
@@ -123,7 +125,6 @@
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "nsPluginDocLoaderFactory.h"
|
||||
#include "nsIDocumentLoaderFactory.h"
|
||||
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
@@ -949,6 +950,12 @@ nsPluginTag::~nsPluginTag()
|
||||
{
|
||||
TryUnloadPlugin(PR_TRUE);
|
||||
|
||||
// Remove mime types added to the catagory manager
|
||||
// only if we were made 'active' by setting the host
|
||||
if (mPluginHost) {
|
||||
RegisterWithCategoryManager(PR_FALSE, nsPluginTag::ePluginUnregister);
|
||||
}
|
||||
|
||||
if (nsnull != mName) {
|
||||
delete[] (mName);
|
||||
mName = nsnull;
|
||||
@@ -3630,69 +3637,47 @@ nsresult nsPluginHostImpl::AddInstanceToActiveList(nsCOMPtr<nsIPlugin> aPlugin,
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult nsPluginHostImpl::RegisterPluginMimeTypesWithLayout(nsPluginTag * pluginTag,
|
||||
nsIComponentManager * compManager)
|
||||
void
|
||||
nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes,
|
||||
nsPluginTag::nsRegisterType aType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(pluginTag);
|
||||
NS_ENSURE_ARG_POINTER(pluginTag->mMimeTypeArray);
|
||||
NS_ENSURE_ARG_POINTER(compManager);
|
||||
if (!mMimeTypeArray)
|
||||
return;
|
||||
|
||||
PLUGIN_LOG(PLUGIN_LOG_NORMAL,
|
||||
("nsPluginHostImpl::RegisterPluginMimeTypesWithLayout plugin=%s\n",
|
||||
pluginTag->mFileName));
|
||||
("nsPluginTag::RegisterWithCategoryManager plugin=%s, removing = %s\n",
|
||||
mFileName, aType == ePluginUnregister ? "yes" : "no"));
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(compManager, &rv);
|
||||
if (!registrar)
|
||||
return rv;
|
||||
nsCOMPtr<nsICategoryManager> catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
||||
if (!catMan)
|
||||
return;
|
||||
|
||||
nsCOMPtr<imgILoader> loader;
|
||||
if (!mOverrideInternalTypes) {
|
||||
loader = do_GetService("@mozilla.org/image/loader;1");
|
||||
if (!loader) {
|
||||
NS_WARNING("get loader failed, falling back to mOverrideInternalTypes");
|
||||
mOverrideInternalTypes=PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < pluginTag->mVariants; i++) {
|
||||
|
||||
// Do not register any doc loader factory content viewers for mime types we do internally
|
||||
// Note: This excludes plugins of these mime types from running in full-page mode.
|
||||
// This gets around Quicktime's default handling of PNG's
|
||||
PRBool bIsSupportedImage = PR_FALSE;
|
||||
if (!mOverrideInternalTypes &&
|
||||
NS_SUCCEEDED(loader->SupportImageWithMimeType(pluginTag->mMimeTypeArray[i], &bIsSupportedImage)) &&
|
||||
bIsSupportedImage)
|
||||
continue;
|
||||
|
||||
static NS_DEFINE_CID(kPluginDocLoaderFactoryCID, NS_PLUGINDOCLOADERFACTORY_CID);
|
||||
|
||||
nsCAutoString contractid(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=");
|
||||
contractid += pluginTag->mMimeTypeArray[i];
|
||||
|
||||
static nsModuleComponentInfo compInfo[] = {
|
||||
{ "Plugin Doc Loader Factory",
|
||||
NS_PLUGINDOCLOADERFACTORY_CID,
|
||||
"@mozilla.org/plugin/doc-loader/factory;1",
|
||||
nsPluginDocLoaderFactory::Create
|
||||
for(int i = 0; i < mVariants; i++) {
|
||||
if (aType == ePluginUnregister) {
|
||||
nsXPIDLCString value;
|
||||
if (NS_SUCCEEDED(catMan->GetCategoryEntry("Gecko-Content-Viewers",
|
||||
mMimeTypeArray[i],
|
||||
getter_Copies(value)))) {
|
||||
// Only delete the entry if a plugin registered for it
|
||||
if (strcmp(value, "@mozilla.org/plugin/doc-loader/factory;1") == 0) {
|
||||
catMan->DeleteCategoryEntry("Gecko-Content-Viewers",
|
||||
mMimeTypeArray[i],
|
||||
PR_TRUE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!mFactory)
|
||||
NS_NewGenericFactory(getter_AddRefs(mFactory), compInfo);
|
||||
|
||||
rv = registrar->RegisterFactory(kPluginDocLoaderFactoryCID,
|
||||
"Plugin Loader Stub",
|
||||
contractid.get(),
|
||||
mFactory);
|
||||
} else {
|
||||
catMan->AddCategoryEntry("Gecko-Content-Viewers",
|
||||
mMimeTypeArray[i],
|
||||
"@mozilla.org/plugin/doc-loader/factory;1",
|
||||
PR_FALSE, /* persist: broken by bug 193031 */
|
||||
aOverrideInternalTypes, /* replace if we're told to */
|
||||
nsnull);
|
||||
}
|
||||
|
||||
PLUGIN_LOG(PLUGIN_LOG_NOISY,
|
||||
("nsPluginHostImpl::RegisterPluginMimeTypesWithLayout mime=%s, plugin=%s\n",
|
||||
pluginTag->mMimeTypeArray[i], pluginTag->mFileName));
|
||||
("nsPluginTag::RegisterWithCategoryManager mime=%s, plugin=%s\n",
|
||||
mMimeTypeArray[i], mFileName));
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -4939,7 +4924,7 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir,
|
||||
pluginTag->mNext = mPlugins;
|
||||
mPlugins = pluginTag;
|
||||
|
||||
RegisterPluginMimeTypesWithLayout(pluginTag, compManager);
|
||||
pluginTag->RegisterWithCategoryManager(mOverrideInternalTypes);
|
||||
}
|
||||
else if (!(pluginTag->mFlags & NS_PLUGIN_FLAG_UNWANTED)) {
|
||||
// we don't need it, delete it;
|
||||
@@ -6459,7 +6444,7 @@ nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManag
|
||||
mPlugins = pluginTag;
|
||||
|
||||
// last thing we need is to register this plugin with layout so it can be used in full-page mode
|
||||
RegisterPluginMimeTypesWithLayout(pluginTag, aCompManager);
|
||||
pluginTag->RegisterWithCategoryManager(mOverrideInternalTypes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
#include "nsIDirectoryService.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsPluginNativeWindow.h"
|
||||
|
||||
@@ -100,6 +99,13 @@ public:
|
||||
void Mark(PRUint32 mask) { mFlags |= mask; }
|
||||
PRBool Equals(nsPluginTag* aPluginTag);
|
||||
|
||||
enum nsRegisterType {
|
||||
ePluginRegister,
|
||||
ePluginUnregister
|
||||
};
|
||||
void RegisterWithCategoryManager(PRBool aOverrideInternalTypes,
|
||||
nsRegisterType aType = ePluginRegister);
|
||||
|
||||
nsPluginTag *mNext;
|
||||
nsPluginHostImpl *mPluginHost;
|
||||
char *mName;
|
||||
@@ -425,9 +431,6 @@ private:
|
||||
nsIURI* aURL, PRBool aDefaultPlugin,
|
||||
nsIPluginInstancePeer *peer);
|
||||
|
||||
nsresult
|
||||
RegisterPluginMimeTypesWithLayout(nsPluginTag *pluginTag, nsIComponentManager * compManager);
|
||||
|
||||
nsresult
|
||||
FindPlugins(PRBool aCreatePluginList, PRBool * aPluginsChanged);
|
||||
|
||||
@@ -492,8 +495,6 @@ private:
|
||||
nsCOMPtr<nsIFile> mPluginsDir;
|
||||
nsCOMPtr<nsIDirectoryServiceProvider> mPrivateDirServiceProvider;
|
||||
nsWeakPtr mCurrentDocument; // weak reference, we use it to id document only
|
||||
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,26 +22,18 @@
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIChannel;
|
||||
interface nsIURI;
|
||||
interface nsIFactory;
|
||||
interface nsIContentViewer;
|
||||
interface nsIStreamListener;
|
||||
interface nsIDocument;
|
||||
interface nsILoadGroup;
|
||||
|
||||
%{C++
|
||||
// Registered components that can instantiate a
|
||||
// nsIDocumentLoaderFactory for a given mimetype must be prefixed with
|
||||
// this prefix to be found. The format is <prefix>/%s/%s where the
|
||||
// first %s is replaced with the command and the second %s is replaced
|
||||
// with the mimetype. For example, to view a image/gif file you would
|
||||
// create this contractid:
|
||||
//
|
||||
// "@mozilla.org/content-viewer-factory/view;1?type=image/gif"
|
||||
//
|
||||
#define NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX \
|
||||
"@mozilla.org/content-viewer-factory/"
|
||||
%}
|
||||
/**
|
||||
* To get a component that implements nsIDocumentLoaderFactory
|
||||
* for a given mimetype, use nsICategoryManager to find an entry
|
||||
* with the mimetype as its name in the category "Gecko-Content-Viewers".
|
||||
* The value of the entry is the contractid of the component.
|
||||
* The component is a service, so use GetService, not CreateInstance to get it.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(df15f850-5d98-11d4-9f4d-0010a4053fd0)]
|
||||
interface nsIDocumentLoaderFactory : nsISupports {
|
||||
|
||||
@@ -115,22 +115,11 @@ RegisterProc(nsIComponentManager *aCompMgr,
|
||||
// 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 = catman->AddCategoryEntry("Gecko-Content-Viewers", "application/http-index-format",
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=application/http-index-format",
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = catman->AddCategoryEntry("Gecko-Content-Viewers", "application/http-index-format; x-view-type=view-source",
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=application/http-index-format; x-view-type=view-source",
|
||||
PR_TRUE,
|
||||
PR_TRUE,
|
||||
getter_Copies(previous));
|
||||
|
||||
return rv;
|
||||
return catman->AddCategoryEntry("Gecko-Content-Viewers", "application/http-index-format",
|
||||
"@mozilla.org/xpfe/http-index-format-factory-constructor",
|
||||
PR_TRUE, PR_TRUE, nsnull);
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
UnregisterProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
@@ -141,14 +130,8 @@ UnregisterProc(nsIComponentManager *aCompMgr,
|
||||
nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = catman->DeleteCategoryEntry("Gecko-Content-Viewers",
|
||||
"application/http-index-format", PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = catman->DeleteCategoryEntry("Gecko-Content-Viewers",
|
||||
"application/http-index-format; x-view-type=view-source", PR_TRUE);
|
||||
|
||||
return rv;
|
||||
return catman->DeleteCategoryEntry("Gecko-Content-Viewers",
|
||||
"application/http-index-format", PR_TRUE);
|
||||
}
|
||||
|
||||
static const nsModuleComponentInfo components[] = {
|
||||
@@ -157,11 +140,8 @@ static const nsModuleComponentInfo components[] = {
|
||||
{ "Bookmarks", NS_BOOKMARKS_SERVICE_CID, NS_BOOKMARKS_DATASOURCE_CONTRACTID,
|
||||
nsBookmarksServiceConstructor },
|
||||
{ "Directory Viewer", NS_DIRECTORYVIEWERFACTORY_CID,
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=application/http-index-format",
|
||||
"@mozilla.org/xpfe/http-index-format-factory-constructor",
|
||||
nsDirectoryViewerFactoryConstructor, RegisterProc, UnregisterProc },
|
||||
{ "Directory Viewer", NS_DIRECTORYVIEWERFACTORY_CID,
|
||||
NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=application/http-index-format; x-view-type=view-source",
|
||||
nsDirectoryViewerFactoryConstructor }, // Let the standard type do the registration
|
||||
{ "Directory Viewer", NS_HTTPINDEX_SERVICE_CID, NS_HTTPINDEX_SERVICE_CONTRACTID,
|
||||
nsHTTPIndexConstructor },
|
||||
{ "Directory Viewer", NS_HTTPINDEX_SERVICE_CID, NS_HTTPINDEX_DATASOURCE_CONTRACTID,
|
||||
|
||||
@@ -90,6 +90,8 @@
|
||||
#include "nsIPref.h"
|
||||
#include "nsIStreamConverterService.h"
|
||||
#include "nsIDirectoryListing.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//
|
||||
@@ -1388,12 +1390,16 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand,
|
||||
// load in its place.
|
||||
|
||||
// Create a dummy loader that will load a stub XUL document.
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> factory;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsXPIDLCString contractID;
|
||||
rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", "application/vnd.mozilla.xul+xml",
|
||||
getter_Copies(contractID));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=application/vnd.mozilla.xul+xml",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIDocumentLoaderFactory),
|
||||
getter_AddRefs(factory));
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> factory(do_GetService(contractID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
@@ -1438,20 +1444,16 @@ nsDirectoryViewerFactory::CreateInstance(const char *aCommand,
|
||||
}
|
||||
|
||||
// Otherwise, lets use the html listing
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> factory;
|
||||
nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
nsXPIDLCString contractID;
|
||||
rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", "text/html",
|
||||
getter_Copies(contractID));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (viewSource) {
|
||||
rv = nsComponentManager::CreateInstance(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=text/html; x-view-type=view-source",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIDocumentLoaderFactory),
|
||||
getter_AddRefs(factory));
|
||||
} else {
|
||||
rv = nsComponentManager::CreateInstance(NS_DOCUMENT_LOADER_FACTORY_CONTRACTID_PREFIX "view;1?type=text/html",
|
||||
nsnull,
|
||||
NS_GET_IID(nsIDocumentLoaderFactory),
|
||||
getter_AddRefs(factory));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> factory(do_GetService(contractID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
|
||||
Reference in New Issue
Block a user