Bug 576540 - nsContentUtils::Init is getting the image loader module, which is initializing the graphics module before they expect to be initialized. This breaks the chain by lazily initializing the image loader and image cache from contentutils, r=joe sr=bz

--HG--
extra : rebase_source : cb612418b6e4be90bace1e69f5ff9432496687f7
This commit is contained in:
Benjamin Smedberg 2010-07-02 17:15:52 -04:00
parent d0f35f6883
commit a334155c96
2 changed files with 28 additions and 11 deletions

View File

@ -485,6 +485,8 @@ public:
static imgILoader* GetImgLoader()
{
if (!sImgLoaderInitialized)
InitImgLoader();
return sImgLoader;
}
@ -1688,6 +1690,10 @@ private:
// For old compatibility of RegisterPrefCallback
static nsCOMArray<nsPrefOldCallback> *sPrefCallbackList;
static bool sImgLoaderInitialized;
static void InitImgLoader();
// The following two members are initialized lazily
static imgILoader* sImgLoader;
static imgICache* sImgCache;

View File

@ -409,17 +409,6 @@ nsContentUtils::Init()
rv = CallGetService(NS_UNICHARCATEGORY_CONTRACTID, &sGenCat);
NS_ENSURE_SUCCESS(rv, rv);
// Ignore failure and just don't load images
rv = CallGetService("@mozilla.org/image/loader;1", &sImgLoader);
if (NS_FAILED(rv)) {
// no image loading for us. Oh, well.
sImgLoader = nsnull;
sImgCache = nsnull;
} else {
if (NS_FAILED(CallGetService("@mozilla.org/image/cache;1", &sImgCache )))
sImgCache = nsnull;
}
rv = CallGetService(NS_IHISTORY_CONTRACTID, &sHistory);
if (NS_FAILED(rv)) {
NS_RUNTIMEABORT("Cannot get the history service");
@ -463,6 +452,25 @@ nsContentUtils::Init()
return NS_OK;
}
bool nsContentUtils::sImgLoaderInitialized;
void
nsContentUtils::InitImgLoader()
{
sImgLoaderInitialized = true;
// Ignore failure and just don't load images
nsresult rv = CallGetService("@mozilla.org/image/loader;1", &sImgLoader);
if (NS_FAILED(rv)) {
// no image loading for us. Oh, well.
sImgLoader = nsnull;
sImgCache = nsnull;
} else {
if (NS_FAILED(CallGetService("@mozilla.org/image/cache;1", &sImgCache )))
sImgCache = nsnull;
}
}
PRBool
nsContentUtils::InitializeEventTable() {
NS_ASSERTION(!sAtomEventTable, "EventTable already initialized!");
@ -2383,6 +2391,9 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext,
PRBool
nsContentUtils::IsImageInCache(nsIURI* aURI)
{
if (!sImgLoaderInitialized)
InitImgLoader();
if (!sImgCache) return PR_FALSE;
// If something unexpected happened we return false, otherwise if props