diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index e65cc2731aa9..67aecb5f10e5 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -87,7 +87,6 @@ #include "nsIDocShell.h" #include "nsIStyleSet.h" #include "nsISupportsArray.h" -#include "nsICSSLoader.h" #include "nsIDocumentObserver.h" #include "nsIXULDocument.h" #include "nsIIOService.h" @@ -3070,26 +3069,10 @@ nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aRes nsCOMPtr url; rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL); - PRBool enabled = PR_FALSE; nsCOMPtr sheet; - nsCOMPtr cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1")); - if (cache) { - cache->GetEnabled(&enabled); - if (enabled) { - nsCOMPtr cachedSheet; - cache->GetStyleSheet(url, getter_AddRefs(cachedSheet)); - if (cachedSheet) - sheet = cachedSheet; - } - } - - if (!sheet) { - LoadStyleSheetWithURL(url, getter_AddRefs(sheet)); - if (sheet) { - if (enabled) - cache->PutStyleSheet(sheet); - } - } + // The CSSLoader handles all the prototype cache stuff for + // us as needed. + LoadStyleSheetWithURL(url, getter_AddRefs(sheet)); if (sheet) { // A sheet was loaded successfully. We will *not* use the default @@ -3148,16 +3131,19 @@ nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACS nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet) { - nsCOMPtr loader; - nsresult rv = nsComponentManager::CreateInstance(kCSSLoaderCID, - nsnull, - NS_GET_IID(nsICSSLoader), - getter_AddRefs(loader)); - if (NS_FAILED(rv)) return rv; - if (loader) { - rv = loader->LoadAgentSheet(aURL, aSheet); - if (NS_FAILED(rv)) return rv; + *aSheet = nsnull; + nsresult rv; + + if (!mCSSLoader) { + mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); } + + if (mCSSLoader) { + rv = mCSSLoader->LoadAgentSheet(aURL, aSheet); + NS_ENSURE_SUCCESS(rv, rv); + } + return NS_OK; } diff --git a/chrome/src/nsChromeRegistry.h b/chrome/src/nsChromeRegistry.h index d7c8e2eb9c40..c6a9e448cfaf 100644 --- a/chrome/src/nsChromeRegistry.h +++ b/chrome/src/nsChromeRegistry.h @@ -54,6 +54,7 @@ class nsIDocument; #include "nsWeakReference.h" #include "nsString.h" #include "nsIZipReader.h" +#include "nsICSSLoader.h" // for component registration // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} @@ -246,6 +247,8 @@ protected: nsCOMPtr mUserContentSheet; nsCOMPtr mFormSheet; + nsCOMPtr mCSSLoader; + nsCOMPtr mOverrideJAR; nsCString mOverrideJARURL; diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 746b81405fe6..fbac4cb146d2 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -6292,37 +6292,35 @@ nsXULDocument::AddPrototypeSheets() nsCOMPtr uri = do_QueryInterface(isupports); NS_IF_RELEASE(isupports); - NS_ASSERTION(uri != nsnull, "not a URI!!!"); + NS_ASSERTION(uri, "not a URI!!!"); if (! uri) return NS_ERROR_UNEXPECTED; - nsCOMPtr sheet; - rv = gXULCache->GetStyleSheet(uri, getter_AddRefs(sheet)); - if (NS_FAILED(rv)) return rv; - - if (!sheet) { - if (!IsChromeURI(uri)) - continue; - - // If the sheet is a chrome URL, then we can refetch the - // sheet synchronously, since we know the sheet is local. - // It's not too late! :) - // Otherwise we just bail. It shouldn't currently - // be possible to get into this situation for any reason - // other than a skin switch anyway (since skin switching is the - // only system that partially invalidates the XUL cache). - // - dwh - nsCOMPtr loader; - GetCSSLoader(*getter_AddRefs(loader)); - rv = loader->LoadAgentSheet(uri, getter_AddRefs(sheet)); - if (NS_FAILED(rv)) return rv; + if (!IsChromeURI(uri)) { + // These don't get to be in the prototype cache anyway... + // and we can't load non-chrome sheets synchronously + continue; } - - nsCOMPtr newsheet; - rv = sheet->Clone(*getter_AddRefs(newsheet)); - if (NS_FAILED(rv)) return rv; - AddStyleSheet(newsheet, 0); + nsCOMPtr sheet; + + // If the sheet is a chrome URL, then we can refetch the sheet + // synchronously, since we know the sheet is local. It's not + // too late! :) If we're lucky, the loader will just pull it + // from the prototype cache anyway. + // Otherwise we just bail. It shouldn't currently + // be possible to get into this situation for any reason + // other than a skin switch anyway (since skin switching is the + // only system that partially invalidates the XUL cache). + // - dwh + //XXXbz we hit this code from fastload all the time. Bug 183505. + nsCOMPtr loader; + rv = GetCSSLoader(*getter_AddRefs(loader)); + NS_ENSURE_SUCCESS(rv, rv); + rv = loader->LoadAgentSheet(uri, getter_AddRefs(sheet)); + NS_ENSURE_SUCCESS(rv, rv); + + AddStyleSheet(sheet, 0); } return NS_OK; diff --git a/rdf/chrome/build/Makefile.in b/rdf/chrome/build/Makefile.in index fcb64d39f1cc..07db6ea3897b 100644 --- a/rdf/chrome/build/Makefile.in +++ b/rdf/chrome/build/Makefile.in @@ -36,6 +36,7 @@ REQUIRES = xpcom \ string \ rdf \ necko \ + layout \ content \ jar \ $(NULL) diff --git a/rdf/chrome/src/nsChromeRegistry.cpp b/rdf/chrome/src/nsChromeRegistry.cpp index e65cc2731aa9..67aecb5f10e5 100644 --- a/rdf/chrome/src/nsChromeRegistry.cpp +++ b/rdf/chrome/src/nsChromeRegistry.cpp @@ -87,7 +87,6 @@ #include "nsIDocShell.h" #include "nsIStyleSet.h" #include "nsISupportsArray.h" -#include "nsICSSLoader.h" #include "nsIDocumentObserver.h" #include "nsIXULDocument.h" #include "nsIIOService.h" @@ -3070,26 +3069,10 @@ nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aRes nsCOMPtr url; rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL); - PRBool enabled = PR_FALSE; nsCOMPtr sheet; - nsCOMPtr cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1")); - if (cache) { - cache->GetEnabled(&enabled); - if (enabled) { - nsCOMPtr cachedSheet; - cache->GetStyleSheet(url, getter_AddRefs(cachedSheet)); - if (cachedSheet) - sheet = cachedSheet; - } - } - - if (!sheet) { - LoadStyleSheetWithURL(url, getter_AddRefs(sheet)); - if (sheet) { - if (enabled) - cache->PutStyleSheet(sheet); - } - } + // The CSSLoader handles all the prototype cache stuff for + // us as needed. + LoadStyleSheetWithURL(url, getter_AddRefs(sheet)); if (sheet) { // A sheet was loaded successfully. We will *not* use the default @@ -3148,16 +3131,19 @@ nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACS nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet) { - nsCOMPtr loader; - nsresult rv = nsComponentManager::CreateInstance(kCSSLoaderCID, - nsnull, - NS_GET_IID(nsICSSLoader), - getter_AddRefs(loader)); - if (NS_FAILED(rv)) return rv; - if (loader) { - rv = loader->LoadAgentSheet(aURL, aSheet); - if (NS_FAILED(rv)) return rv; + *aSheet = nsnull; + nsresult rv; + + if (!mCSSLoader) { + mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); } + + if (mCSSLoader) { + rv = mCSSLoader->LoadAgentSheet(aURL, aSheet); + NS_ENSURE_SUCCESS(rv, rv); + } + return NS_OK; } diff --git a/rdf/chrome/src/nsChromeRegistry.h b/rdf/chrome/src/nsChromeRegistry.h index d7c8e2eb9c40..c6a9e448cfaf 100644 --- a/rdf/chrome/src/nsChromeRegistry.h +++ b/rdf/chrome/src/nsChromeRegistry.h @@ -54,6 +54,7 @@ class nsIDocument; #include "nsWeakReference.h" #include "nsString.h" #include "nsIZipReader.h" +#include "nsICSSLoader.h" // for component registration // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} @@ -246,6 +247,8 @@ protected: nsCOMPtr mUserContentSheet; nsCOMPtr mFormSheet; + nsCOMPtr mCSSLoader; + nsCOMPtr mOverrideJAR; nsCString mOverrideJARURL;