diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 7da4116c9828..244a179c51ea 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -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 *sPrefCallbackList; + static bool sImgLoaderInitialized; + static void InitImgLoader(); + + // The following two members are initialized lazily static imgILoader* sImgLoader; static imgICache* sImgCache; diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index dc37d0b6883f..9301691eb75e 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -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