Use the prototype cache smarter, not harder, for getting sheets. Bug

183859, r=sicking, sr=brendan.
This commit is contained in:
bzbarsky%mit.edu 2002-12-11 03:33:40 +00:00
parent f3c5ef51ac
commit a4d94e3627
6 changed files with 61 additions and 84 deletions

View File

@ -87,7 +87,6 @@
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsIStyleSet.h" #include "nsIStyleSet.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsICSSLoader.h"
#include "nsIDocumentObserver.h" #include "nsIDocumentObserver.h"
#include "nsIXULDocument.h" #include "nsIXULDocument.h"
#include "nsIIOService.h" #include "nsIIOService.h"
@ -3070,26 +3069,10 @@ nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aRes
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL); rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL);
PRBool enabled = PR_FALSE;
nsCOMPtr<nsICSSStyleSheet> sheet; nsCOMPtr<nsICSSStyleSheet> sheet;
nsCOMPtr<nsIXULPrototypeCache> cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1")); // The CSSLoader handles all the prototype cache stuff for
if (cache) { // us as needed.
cache->GetEnabled(&enabled); LoadStyleSheetWithURL(url, getter_AddRefs(sheet));
if (enabled) {
nsCOMPtr<nsICSSStyleSheet> 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);
}
}
if (sheet) { if (sheet) {
// A sheet was loaded successfully. We will *not* use the default // 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) nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet)
{ {
nsCOMPtr<nsICSSLoader> loader; *aSheet = nsnull;
nsresult rv = nsComponentManager::CreateInstance(kCSSLoaderCID, nsresult rv;
nsnull,
NS_GET_IID(nsICSSLoader), if (!mCSSLoader) {
getter_AddRefs(loader)); mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv);
if (NS_FAILED(rv)) return rv; NS_ENSURE_SUCCESS(rv, rv);
if (loader) {
rv = loader->LoadAgentSheet(aURL, aSheet);
if (NS_FAILED(rv)) return rv;
} }
if (mCSSLoader) {
rv = mCSSLoader->LoadAgentSheet(aURL, aSheet);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK; return NS_OK;
} }

View File

@ -54,6 +54,7 @@ class nsIDocument;
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsString.h" #include "nsString.h"
#include "nsIZipReader.h" #include "nsIZipReader.h"
#include "nsICSSLoader.h"
// for component registration // for component registration
// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627}
@ -246,6 +247,8 @@ protected:
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet; nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet; nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsCOMPtr<nsIZipReader> mOverrideJAR; nsCOMPtr<nsIZipReader> mOverrideJAR;
nsCString mOverrideJARURL; nsCString mOverrideJARURL;

View File

@ -6292,37 +6292,35 @@ nsXULDocument::AddPrototypeSheets()
nsCOMPtr<nsIURI> uri = do_QueryInterface(isupports); nsCOMPtr<nsIURI> uri = do_QueryInterface(isupports);
NS_IF_RELEASE(isupports); NS_IF_RELEASE(isupports);
NS_ASSERTION(uri != nsnull, "not a URI!!!"); NS_ASSERTION(uri, "not a URI!!!");
if (! uri) if (! uri)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsICSSStyleSheet> sheet; if (!IsChromeURI(uri)) {
rv = gXULCache->GetStyleSheet(uri, getter_AddRefs(sheet)); // These don't get to be in the prototype cache anyway...
if (NS_FAILED(rv)) return rv; // and we can't load non-chrome sheets synchronously
continue;
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<nsICSSLoader> loader;
GetCSSLoader(*getter_AddRefs(loader));
rv = loader->LoadAgentSheet(uri, getter_AddRefs(sheet));
if (NS_FAILED(rv)) return rv;
} }
nsCOMPtr<nsICSSStyleSheet> newsheet;
rv = sheet->Clone(*getter_AddRefs(newsheet));
if (NS_FAILED(rv)) return rv;
AddStyleSheet(newsheet, 0); nsCOMPtr<nsICSSStyleSheet> 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<nsICSSLoader> 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; return NS_OK;

View File

@ -36,6 +36,7 @@ REQUIRES = xpcom \
string \ string \
rdf \ rdf \
necko \ necko \
layout \
content \ content \
jar \ jar \
$(NULL) $(NULL)

View File

@ -87,7 +87,6 @@
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsIStyleSet.h" #include "nsIStyleSet.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsICSSLoader.h"
#include "nsIDocumentObserver.h" #include "nsIDocumentObserver.h"
#include "nsIXULDocument.h" #include "nsIXULDocument.h"
#include "nsIIOService.h" #include "nsIIOService.h"
@ -3070,26 +3069,10 @@ nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aRes
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL); rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL);
PRBool enabled = PR_FALSE;
nsCOMPtr<nsICSSStyleSheet> sheet; nsCOMPtr<nsICSSStyleSheet> sheet;
nsCOMPtr<nsIXULPrototypeCache> cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1")); // The CSSLoader handles all the prototype cache stuff for
if (cache) { // us as needed.
cache->GetEnabled(&enabled); LoadStyleSheetWithURL(url, getter_AddRefs(sheet));
if (enabled) {
nsCOMPtr<nsICSSStyleSheet> 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);
}
}
if (sheet) { if (sheet) {
// A sheet was loaded successfully. We will *not* use the default // 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) nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet)
{ {
nsCOMPtr<nsICSSLoader> loader; *aSheet = nsnull;
nsresult rv = nsComponentManager::CreateInstance(kCSSLoaderCID, nsresult rv;
nsnull,
NS_GET_IID(nsICSSLoader), if (!mCSSLoader) {
getter_AddRefs(loader)); mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv);
if (NS_FAILED(rv)) return rv; NS_ENSURE_SUCCESS(rv, rv);
if (loader) {
rv = loader->LoadAgentSheet(aURL, aSheet);
if (NS_FAILED(rv)) return rv;
} }
if (mCSSLoader) {
rv = mCSSLoader->LoadAgentSheet(aURL, aSheet);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK; return NS_OK;
} }

View File

@ -54,6 +54,7 @@ class nsIDocument;
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsString.h" #include "nsString.h"
#include "nsIZipReader.h" #include "nsIZipReader.h"
#include "nsICSSLoader.h"
// for component registration // for component registration
// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627} // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627}
@ -246,6 +247,8 @@ protected:
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet; nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet; nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsCOMPtr<nsIZipReader> mOverrideJAR; nsCOMPtr<nsIZipReader> mOverrideJAR;
nsCString mOverrideJARURL; nsCString mOverrideJARURL;