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
Родитель f3c5ef51ac
Коммит a4d94e3627
6 изменённых файлов: 61 добавлений и 84 удалений

Просмотреть файл

@ -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<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL);
PRBool enabled = PR_FALSE;
nsCOMPtr<nsICSSStyleSheet> sheet;
nsCOMPtr<nsIXULPrototypeCache> cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1"));
if (cache) {
cache->GetEnabled(&enabled);
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);
}
}
// 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<nsICSSLoader> 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;
}

Просмотреть файл

@ -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<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsCOMPtr<nsIZipReader> mOverrideJAR;
nsCString mOverrideJARURL;

Просмотреть файл

@ -6292,37 +6292,35 @@ nsXULDocument::AddPrototypeSheets()
nsCOMPtr<nsIURI> 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<nsICSSStyleSheet> 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<nsICSSLoader> 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<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;

Просмотреть файл

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

Просмотреть файл

@ -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<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token), nsnull, docURL);
PRBool enabled = PR_FALSE;
nsCOMPtr<nsICSSStyleSheet> sheet;
nsCOMPtr<nsIXULPrototypeCache> cache(do_GetService("@mozilla.org/xul/xul-prototype-cache;1"));
if (cache) {
cache->GetEnabled(&enabled);
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);
}
}
// 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<nsICSSLoader> 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;
}

Просмотреть файл

@ -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<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsCOMPtr<nsIZipReader> mOverrideJAR;
nsCString mOverrideJARURL;