Bug 544112 part 2: DeCOMtaminate and devirtualize nsCSSLoader. r=bzbarsky sr=dbaron

--HG--
rename : layout/style/nsICSSLoader.h => layout/style/nsCSSLoader.h
This commit is contained in:
Zack Weinberg 2010-03-02 13:00:53 -08:00
parent a5be3ffde2
commit 6ce13b76a5
43 changed files with 825 additions and 976 deletions

View file

@ -119,7 +119,6 @@
#define SELECTED_LOCALE_PREF "general.useragent.locale"
#define SELECTED_SKIN_PREF "general.skins.selectedSkin"
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
nsChromeRegistry* nsChromeRegistry::gChromeRegistry;

View file

@ -90,7 +90,6 @@ class nsIDOMDocumentType;
class nsScriptLoader;
class nsIContentSink;
class nsIScriptEventManager;
class nsICSSLoader;
class nsHTMLStyleSheet;
class nsHTMLCSSStyleSheet;
class nsILayoutHistoryState;
@ -106,6 +105,10 @@ class nsFrameLoader;
class nsIBoxObject;
namespace mozilla {
namespace css {
class Loader;
} // namespace css
namespace dom {
class Link;
} // namespace dom
@ -568,7 +571,7 @@ public:
/**
* Get this document's CSSLoader. This is guaranteed to not return null.
*/
nsICSSLoader* CSSLoader() const {
mozilla::css::Loader* CSSLoader() const {
return mCSSLoader;
}
@ -1333,7 +1336,7 @@ protected:
// additional headers that we don't want to expose.
// The cleanup is handled by the nsDocument destructor.
nsNodeInfoManager* mNodeInfoManager; // [STRONG]
nsICSSLoader* mCSSLoader; // [STRONG]
mozilla::css::Loader* mCSSLoader; // [STRONG]
// The set of all object, embed, applet, video and audio elements for
// which this is the owner document. (They might not be in the document.)

View file

@ -46,7 +46,7 @@
#include "nsScriptLoader.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsStyleConsts.h"
#include "nsStyleLinkElement.h"
#include "nsINodeInfo.h"

View file

@ -69,7 +69,6 @@ class nsIDocument;
class nsIURI;
class nsIChannel;
class nsIDocShell;
class nsICSSLoader;
class nsIParser;
class nsIAtom;
class nsIChannel;
@ -79,6 +78,12 @@ class nsNodeInfoManager;
class nsScriptLoader;
class nsIApplicationCache;
namespace mozilla {
namespace css {
class Loader;
}
}
#ifdef NS_DEBUG
extern PRLogModuleInfo* gContentSinkLogModuleInfo;
@ -303,7 +308,7 @@ protected:
nsCOMPtr<nsIURI> mDocumentURI;
nsCOMPtr<nsIURI> mDocumentBaseURI;
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsRefPtr<mozilla::css::Loader> mCSSLoader;
nsRefPtr<nsNodeInfoManager> mNodeInfoManager;
nsRefPtr<nsScriptLoader> mScriptLoader;

View file

@ -63,6 +63,7 @@
#include "nsContentList.h"
#include "nsIObserver.h"
#include "nsIBaseWindow.h"
#include "nsCSSLoader.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIScriptRuntime.h"
@ -1751,8 +1752,9 @@ nsDocument::Init()
mOnloadBlocker = new nsOnloadBlocker();
NS_ENSURE_TRUE(mOnloadBlocker, NS_ERROR_OUT_OF_MEMORY);
NS_NewCSSLoader(this, &mCSSLoader);
mCSSLoader = new mozilla::css::Loader(this);
NS_ENSURE_TRUE(mCSSLoader, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(mCSSLoader);
// Assume we're not quirky, until we know otherwise
mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards);
@ -3493,9 +3495,8 @@ nsDocument::AddCatalogStyleSheet(nsIStyleSheet* aSheet)
void
nsDocument::EnsureCatalogStyleSheet(const char *aStyleSheetURI)
{
nsICSSLoader* cssLoader = CSSLoader();
PRBool enabled;
if (NS_SUCCEEDED(cssLoader->GetEnabled(&enabled)) && enabled) {
mozilla::css::Loader* cssLoader = CSSLoader();
if (cssLoader->GetEnabled()) {
PRInt32 sheetCount = GetNumberOfCatalogStyleSheets();
for (PRInt32 i = 0; i < sheetCount; i++) {
nsIStyleSheet* sheet = GetCatalogStyleSheetAt(i);

View file

@ -82,7 +82,6 @@
#include "nsIScriptObjectPrincipal.h"
#include "nsIURI.h"
#include "nsScriptLoader.h"
#include "nsICSSLoader.h"
#include "nsIRadioGroupContainer.h"
#include "nsIScriptEventManager.h"
#include "nsILayoutHistoryState.h"

View file

@ -46,7 +46,7 @@
#include "nsStyleLinkElement.h"
#include "nsIContent.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIDocument.h"
#include "nsIDOMComment.h"
@ -240,18 +240,11 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument *aOldDocument,
nsCOMPtr<nsIDocument> doc = thisContent->GetDocument();
if (!doc) {
return NS_OK;
}
PRBool enabled = PR_FALSE;
doc->CSSLoader()->GetEnabled(&enabled);
if (!enabled) {
if (!doc || !doc->CSSLoader()->GetEnabled()) {
return NS_OK;
}
PRBool isInline;
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline);
if (!aForceUpdate && mStyleSheet && !isInline && uri) {

View file

@ -49,7 +49,7 @@
#include "nsIDocument.h"
#include "nsICSSStyleRule.h"
#include "nsCSSParser.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIDOMMutationEvent.h"
#ifdef MOZ_SVG
@ -242,7 +242,7 @@ nsStyledElement::ParseStyleAttribute(const nsAString& aValue,
}
if (isCSS) {
nsICSSLoader* cssLoader = doc->CSSLoader();
mozilla::css::Loader* cssLoader = doc->CSSLoader();
nsCSSParser cssParser(cssLoader);
if (cssParser) {
nsCOMPtr<nsIURI> baseURI = GetBaseURI();

View file

@ -41,7 +41,6 @@
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIContentViewer.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleRule.h"
#include "nsCSSStruct.h"
#include "nsIDocument.h"

View file

@ -98,7 +98,7 @@
#include "nsIDOMHTMLBodyElement.h"
#include "nsINameSpaceManager.h"
#include "nsGenericHTMLElement.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIHttpChannel.h"
#include "nsIFile.h"
#include "nsIEventListenerManager.h"

View file

@ -49,7 +49,6 @@ class nsIDOMHTMLFormElement;
class nsIDOMHTMLMapElement;
class nsHTMLStyleSheet;
class nsIStyleSheet;
class nsICSSLoader;
class nsIContent;
class nsIDOMHTMLBodyElement;
class nsIScriptElement;

View file

@ -61,7 +61,6 @@
#include "nsCSSDeclaration.h"
#include "nsCSSProps.h"
#include "nsCSSParser.h"
#include "nsICSSLoader.h"
#include "nsGenericHTMLElement.h"
#include "nsNodeInfoManager.h"
#include "nsIScriptGlobalObject.h"

View file

@ -74,7 +74,6 @@
#include "nsIScriptContext.h"
#include "nsICSSLoader.h"
#include "nsIStyleRuleProcessor.h"
#include "nsXBLResourceLoader.h"

View file

@ -45,15 +45,14 @@
#include "nsIServiceManager.h"
#include "nsXBLResourceLoader.h"
#include "nsXBLPrototypeResources.h"
#include "nsXBLPrototypeBinding.h"
#include "nsIDocumentObserver.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIURI.h"
#include "nsLayoutCID.h"
#include "nsCSSRuleProcessor.h"
#include "nsStyleSet.h"
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
nsXBLPrototypeResources::nsXBLPrototypeResources(nsXBLPrototypeBinding* aBinding)
{
MOZ_COUNT_CTOR(nsXBLPrototypeResources);
@ -108,10 +107,9 @@ nsXBLPrototypeResources::FlushSkinSheets()
if (mStyleSheetList.Count() == 0)
return NS_OK;
nsresult rv;
// XXXbz should be getting loader off the document or something
nsCOMPtr<nsICSSLoader> loader = do_CreateInstance(kCSSLoaderCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDocument> doc;
mLoader->mBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(doc));
mozilla::css::Loader* cssLoader = doc->CSSLoader();
// We have scoped stylesheets. Reload any chrome stylesheets we
// encounter. (If they aren't skin sheets, it doesn't matter, since
@ -131,7 +129,7 @@ nsXBLPrototypeResources::FlushSkinSheets()
nsCOMPtr<nsICSSStyleSheet> newSheet;
if (IsChromeURI(uri)) {
if (NS_FAILED(loader->LoadSheetSync(uri, getter_AddRefs(newSheet))))
if (NS_FAILED(cssLoader->LoadSheetSync(uri, getter_AddRefs(newSheet))))
continue;
}
else {

View file

@ -48,7 +48,7 @@
#include "nsIDocumentObserver.h"
#include "imgILoader.h"
#include "imgIRequest.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIXBLDocumentInfo.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
@ -112,7 +112,7 @@ nsXBLResourceLoader::LoadResources(PRBool* aResult)
nsCOMPtr<nsIDocument> doc;
mBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(doc));
nsICSSLoader* cssLoader = doc->CSSLoader();
mozilla::css::Loader* cssLoader = doc->CSSLoader();
nsIURI *docURL = doc->GetDocumentURI();
nsIPrincipal* docPrincipal = doc->NodePrincipal();

View file

@ -59,8 +59,8 @@
#include "nsDOMDocumentType.h"
#include "nsHTMLParts.h"
#include "nsCRT.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsCSSLoader.h"
#include "nsGkAtoms.h"
#include "nsContentUtils.h"
#include "nsIScriptContext.h"

View file

@ -63,7 +63,7 @@
#include "nsIHTMLDocument.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsIDocumentTransformer.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICharsetAlias.h"
#include "nsIHTMLContentSink.h"
#include "nsContentUtils.h"

View file

@ -83,7 +83,7 @@
#include "nsCRT.h"
#include "nsXULPrototypeDocument.h" // XXXbe temporary
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsUnicharUtils.h"
#include "nsGkAtoms.h"

View file

@ -113,6 +113,7 @@
#include "nsIParser.h"
#include "nsIParserService.h"
#include "nsICSSStyleSheet.h"
#include "nsCSSLoader.h"
#include "nsIScriptError.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsEventDispatcher.h"

View file

@ -64,7 +64,6 @@
#include "nsISelectionController.h"
#include "nsIFileChannel.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIDocumentObserver.h"
#include "nsIDocumentStateListener.h"

View file

@ -72,7 +72,7 @@
#include "nsIDOMEventGroup.h"
#include "nsILinkHandler.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIDOMStyleSheet.h"
#include "nsIDocumentObserver.h"
@ -3377,24 +3377,17 @@ nsHTMLEditor::ReplaceStyleSheet(const nsAString& aURL)
return NS_OK;
}
nsCOMPtr<nsICSSLoader> cssLoader;
nsresult rv = GetCSSLoader(aURL, getter_AddRefs(cssLoader));
NS_ENSURE_SUCCESS(rv, rv);
// Make sure the pres shell doesn't disappear during the load.
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps) return NS_ERROR_NOT_INITIALIZED;
nsIDocument *document = ps->GetDocument();
if (!document) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIURI> uaURI;
rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
nsresult rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
NS_ENSURE_SUCCESS(rv, rv);
rv = cssLoader->LoadSheet(uaURI, nsnull, EmptyCString(), this);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
return ps->GetDocument()->CSSLoader()->
LoadSheet(uaURI, nsnull, EmptyCString(), this);
}
NS_IMETHODIMP
@ -3430,12 +3423,13 @@ nsHTMLEditor::AddOverrideStyleSheet(const nsAString& aURL)
if (EnableExistingStyleSheet(aURL))
return NS_OK;
nsCOMPtr<nsICSSLoader> cssLoader;
nsresult rv = GetCSSLoader(aURL, getter_AddRefs(cssLoader));
NS_ENSURE_SUCCESS(rv, rv);
// Make sure the pres shell doesn't disappear during the load.
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps)
return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIURI> uaURI;
rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
nsresult rv = NS_NewURI(getter_AddRefs(uaURI), aURL);
NS_ENSURE_SUCCESS(rv, rv);
// We MUST ONLY load synchronous local files (no @import)
@ -3443,16 +3437,13 @@ nsHTMLEditor::AddOverrideStyleSheet(const nsAString& aURL)
// synchronously, of course..
nsCOMPtr<nsICSSStyleSheet> sheet;
// Editor override style sheets may want to style Gecko anonymous boxes
rv = cssLoader->LoadSheetSync(uaURI, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
rv = ps->GetDocument()->CSSLoader()->
LoadSheetSync(uaURI, PR_TRUE, PR_TRUE, getter_AddRefs(sheet));
// Synchronous loads should ALWAYS return completed
if (!sheet)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps)
return NS_ERROR_NOT_INITIALIZED;
// Add the override style sheet
// (This checks if already exists)
ps->AddOverrideStyleSheet(sheet);
@ -3630,29 +3621,9 @@ nsHTMLEditor::GetURLForStyleSheet(nsICSSStyleSheet *aStyleSheet,
return NS_OK;
}
nsresult
nsHTMLEditor::GetCSSLoader(const nsAString& aURL, nsICSSLoader** aCSSLoader)
{
if (!aCSSLoader)
return NS_ERROR_NULL_POINTER;
*aCSSLoader = 0;
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
if (!ps) return NS_ERROR_NOT_INITIALIZED;
nsIDocument *document = ps->GetDocument();
if (!document) return NS_ERROR_NULL_POINTER;
NS_ADDREF(*aCSSLoader = document->CSSLoader());
return NS_OK;
}
#ifdef XP_MAC
#pragma mark -
#pragma mark nsIEditorMailSupport methods
#pragma mark -
#endif
/*
* nsIEditorMailSupport methods
*/
NS_IMETHODIMP
nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList)

View file

@ -53,7 +53,6 @@
#include "nsEditor.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
#include "nsICSSLoader.h"
#include "nsICSSLoaderObserver.h"
#include "nsITableLayout.h"
@ -410,9 +409,6 @@ public:
PRBool aSafeToAskFrames,
PRBool *aSeenBR);
// Stylesheet-related methods that aren't part of nsIEditorStyleSheets.
nsresult GetCSSLoader(const nsAString& aURL, nsICSSLoader** aCSSLoader);
// Returns TRUE if sheet was loaded, false if it wasn't
PRBool EnableExistingStyleSheet(const nsAString& aURL);

View file

@ -50,7 +50,6 @@
#include "nsISelectionPrivate.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsISelectionController.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIDocumentObserver.h"
#include "TypeInState.h"

View file

@ -89,7 +89,7 @@
#include "nsNetUtil.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
@ -2144,8 +2144,7 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
nsAutoString sheets;
elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
if (!sheets.IsEmpty() && baseURI) {
nsCOMPtr<nsICSSLoader> cssLoader;
NS_NewCSSLoader(getter_AddRefs(cssLoader));
nsRefPtr<mozilla::css::Loader> cssLoader = new mozilla::css::Loader();
char *str = ToNewCString(sheets);
char *newStr = str;

View file

@ -41,7 +41,7 @@
#include "prlog.h"
#include "nsStyleSheetService.h"
#include "nsIStyleSheet.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIURI.h"
#include "nsContentCID.h"
@ -53,8 +53,6 @@
#include "nsIObserverService.h"
#include "nsLayoutStatics.h"
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
nsStyleSheetService *nsStyleSheetService::gInstance = nsnull;
nsStyleSheetService::nsStyleSheetService()
@ -171,7 +169,9 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
NS_ENSURE_ARG(aSheetType == AGENT_SHEET || aSheetType == USER_SHEET);
NS_ENSURE_ARG_POINTER(aSheetURI);
nsCOMPtr<nsICSSLoader> loader = do_CreateInstance(kCSSLoaderCID);
nsRefPtr<mozilla::css::Loader> loader = new mozilla::css::Loader();
NS_ENSURE_TRUE(loader, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsICSSStyleSheet> sheet;
// Allow UA sheets, but not user sheets, to use unsafe rules
nsresult rv = loader->LoadSheetSync(aSheetURI, aSheetType == AGENT_SHEET,

View file

@ -46,14 +46,12 @@
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIURL.h"
#include "nsICSSStyleSheet.h"
#include "nsNodeInfo.h"
#include "nsNodeInfoManager.h"
#include "nsString.h"
#include "nsContentCID.h"
#include "prprf.h"
#include "nsNetUtil.h"
#include "nsICSSLoader.h"
#include "nsCRT.h"
#include "nsIViewSourceChannel.h"
#ifdef MOZ_MEDIA

View file

@ -46,7 +46,6 @@
#include "nsHTMLContentSerializer.h"
#include "nsHTMLParts.h"
#include "nsGenericHTMLElement.h"
#include "nsICSSLoader.h"
#include "nsICategoryManager.h"
#include "nsIComponentManager.h"
#include "nsIContentIterator.h"
@ -483,7 +482,6 @@ MAKE_CTOR(CreateXMLDocument, nsIDocument, NS_NewXML
MAKE_CTOR(CreateSVGDocument, nsIDocument, NS_NewSVGDocument)
#endif
MAKE_CTOR(CreateImageDocument, nsIDocument, NS_NewImageDocument)
MAKE_CTOR(CreateCSSLoader, nsICSSLoader, NS_NewCSSLoader)
MAKE_CTOR(CreateDOMSelection, nsISelection, NS_NewDomSelection)
MAKE_CTOR(CreateSelection, nsFrameSelection, NS_NewSelection)
MAKE_CTOR(CreateRange, nsIDOMRange, NS_NewRange)
@ -1046,11 +1044,6 @@ static const nsModuleComponentInfo gComponents[] = {
nsnull,
CreateImageDocument },
{ "CSS loader",
NS_CSS_LOADER_CID,
nsnull,
CreateCSSLoader },
{ "Dom selection",
NS_DOMSELECTION_CID,
"@mozilla.org/content/dom-selection;1",

View file

@ -57,6 +57,7 @@ EXPORTS = \
nsCSSAnonBoxes.h \
nsCSSKeywordList.h \
nsCSSKeywords.h \
nsCSSLoader.h \
nsCSSParser.h \
nsCSSPropList.h \
nsCSSProperty.h \
@ -74,7 +75,6 @@ EXPORTS = \
nsICSSDeclaration.h \
nsICSSGroupRule.h \
nsICSSImportRule.h \
nsICSSLoader.h \
nsICSSLoaderObserver.h \
nsICSSNameSpaceRule.h \
nsICSSPseudoComparator.h \

View file

@ -48,19 +48,12 @@
/* loading of CSS style sheets using the network APIs */
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIRunnable.h"
#include "nsIUnicharStreamLoader.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsString.h"
#include "nsURIHashKey.h"
#include "nsInterfaceHashtable.h"
#include "nsDataHashtable.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
#include "nsIPrincipal.h"
#include "nsTObserverArray.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMWindow.h"
@ -132,7 +125,8 @@
* determination.
*/
class CSSLoaderImpl;
namespace mozilla {
namespace css {
/*********************************************
* Data needed to properly load a stylesheet *
@ -144,7 +138,7 @@ class SheetLoadData : public nsIRunnable,
public:
virtual ~SheetLoadData(void);
// Data for loading a sheet linked from a document
SheetLoadData(CSSLoaderImpl* aLoader,
SheetLoadData(Loader* aLoader,
const nsSubstring& aTitle,
nsIURI* aURI,
nsICSSStyleSheet* aSheet,
@ -154,7 +148,7 @@ public:
nsIPrincipal* aLoaderPrincipal);
// Data for loading a sheet linked from an @import rule
SheetLoadData(CSSLoaderImpl* aLoader,
SheetLoadData(Loader* aLoader,
nsIURI* aURI,
nsICSSStyleSheet* aSheet,
SheetLoadData* aParentData,
@ -162,7 +156,7 @@ public:
nsIPrincipal* aLoaderPrincipal);
// Data for loading a non-document sheet
SheetLoadData(CSSLoaderImpl* aLoader,
SheetLoadData(Loader* aLoader,
nsIURI* aURI,
nsICSSStyleSheet* aSheet,
PRBool aSyncLoad,
@ -180,7 +174,7 @@ public:
// Hold a ref to the CSSLoader so we can call back to it to let it
// know the load finished
CSSLoaderImpl* mLoader; // strong ref
Loader* mLoader; // strong ref
// Title needed to pull datas out of the pending datas table when
// the preferred title is changed
@ -262,291 +256,6 @@ public:
nsCString mCharsetHint;
};
class nsURIAndPrincipalHashKey : public nsURIHashKey
{
public:
typedef nsURIAndPrincipalHashKey* KeyType;
typedef const nsURIAndPrincipalHashKey* KeyTypePointer;
nsURIAndPrincipalHashKey(const nsURIAndPrincipalHashKey* aKey)
: nsURIHashKey(aKey->mKey), mPrincipal(aKey->mPrincipal)
{
MOZ_COUNT_CTOR(nsURIAndPrincipalHashKey);
}
nsURIAndPrincipalHashKey(nsIURI* aURI, nsIPrincipal* aPrincipal)
: nsURIHashKey(aURI), mPrincipal(aPrincipal)
{
MOZ_COUNT_CTOR(nsURIAndPrincipalHashKey);
}
nsURIAndPrincipalHashKey(const nsURIAndPrincipalHashKey& toCopy)
: nsURIHashKey(toCopy), mPrincipal(toCopy.mPrincipal)
{
MOZ_COUNT_CTOR(nsURIAndPrincipalHashKey);
}
~nsURIAndPrincipalHashKey()
{
MOZ_COUNT_DTOR(nsURIAndPrincipalHashKey);
}
nsURIAndPrincipalHashKey* GetKey() const {
return const_cast<nsURIAndPrincipalHashKey*>(this);
}
const nsURIAndPrincipalHashKey* GetKeyPointer() const { return this; }
PRBool KeyEquals(const nsURIAndPrincipalHashKey* aKey) const {
if (!nsURIHashKey::KeyEquals(aKey->mKey)) {
return PR_FALSE;
}
if (!mPrincipal != !aKey->mPrincipal) {
// One or the other has a principal, but not both... not equal
return PR_FALSE;
}
PRBool eq;
return !mPrincipal ||
(NS_SUCCEEDED(mPrincipal->Equals(aKey->mPrincipal, &eq)) && eq);
}
static const nsURIAndPrincipalHashKey*
KeyToPointer(nsURIAndPrincipalHashKey* aKey) { return aKey; }
static PLDHashNumber HashKey(const nsURIAndPrincipalHashKey* aKey) {
return nsURIHashKey::HashKey(aKey->mKey);
}
enum { ALLOW_MEMMOVE = PR_TRUE };
protected:
nsCOMPtr<nsIPrincipal> mPrincipal;
};
/***********************************************************************
* Enum that describes the state of the sheet returned by CreateSheet. *
***********************************************************************/
enum StyleSheetState {
eSheetStateUnknown = 0,
eSheetNeedsParser,
eSheetPending,
eSheetLoading,
eSheetComplete
};
/**********************
* Loader Declaration *
**********************/
class CSSLoaderImpl : public nsICSSLoader
{
public:
CSSLoaderImpl(void);
virtual ~CSSLoaderImpl(void);
NS_DECL_ISUPPORTS
// nsICSSLoader methods
NS_IMETHOD Init(nsIDocument* aDocument);
NS_IMETHOD DropDocumentReference(void);
NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode);
NS_IMETHOD_(nsCompatibility) GetCompatibilityMode();
NS_IMETHOD SetPreferredSheet(const nsAString& aTitle);
NS_IMETHOD GetPreferredSheet(nsAString& aTitle);
NS_IMETHOD LoadInlineStyle(nsIContent* aElement,
nsIUnicharInputStream* aStream,
PRUint32 aLineNumber,
const nsSubstring& aTitle,
const nsSubstring& aMedia,
nsICSSLoaderObserver* aObserver,
PRBool* aCompleted,
PRBool* aIsAlternate);
NS_IMETHOD LoadStyleLink(nsIContent* aElement,
nsIURI* aURL,
const nsSubstring& aTitle,
const nsSubstring& aMedia,
PRBool aHasAlternateRel,
nsICSSLoaderObserver* aObserver,
PRBool* aIsAlternate);
NS_IMETHOD LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsIURI* aURL,
nsMediaList* aMedia,
nsICSSImportRule* aRule);
NS_IMETHOD LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules,
PRBool aUseSystemPrincipal,
nsICSSStyleSheet** aSheet);
NS_IMETHOD LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver,
nsICSSStyleSheet** aSheet);
NS_IMETHOD LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver);
// stop loading all sheets
NS_IMETHOD Stop(void);
// stop loading one sheet
NS_IMETHOD StopLoadingSheet(nsIURI* aURL);
/**
* Is the loader enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
NS_IMETHOD GetEnabled(PRBool *aEnabled);
NS_IMETHOD SetEnabled(PRBool aEnabled);
NS_IMETHOD_(PRBool) HasPendingLoads();
NS_IMETHOD AddObserver(nsICSSLoaderObserver* aObserver);
NS_IMETHOD_(void) RemoveObserver(nsICSSLoaderObserver* aObserver);
// local helper methods (some are public for access from statics)
// IsAlternate can change our currently selected style set if none
// is selected and aHasAlternateRel is false.
PRBool IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel);
private:
// Note: null aSourcePrincipal indicates that the content policy and
// CheckLoadURI checks should be skipped.
nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
nsIURI* aTargetURI,
nsISupports* aContext);
// For inline style, the aURI param is null, but the aLinkingContent
// must be non-null then. The loader principal must never be null
// if aURI is not null.
nsresult CreateSheet(nsIURI* aURI,
nsIContent* aLinkingContent,
nsIPrincipal* aLoaderPrincipal,
PRBool aSyncLoad,
StyleSheetState& aSheetState,
nsICSSStyleSheet** aSheet);
// Pass in either a media string or the nsMediaList from the
// CSSParser. Don't pass both.
// If aIsAlternate is non-null, this method will set *aIsAlternate to
// correspond to the sheet's enabled state (which it will set no matter what)
nsresult PrepareSheet(nsICSSStyleSheet* aSheet,
const nsSubstring& aTitle,
const nsSubstring& aMediaString,
nsMediaList* aMediaList,
PRBool aHasAlternateRel = PR_FALSE,
PRBool *aIsAlternate = nsnull);
nsresult InsertSheetInDoc(nsICSSStyleSheet* aSheet,
nsIContent* aLinkingContent,
nsIDocument* aDocument);
nsresult InsertChildSheet(nsICSSStyleSheet* aSheet,
nsICSSStyleSheet* aParentSheet,
nsICSSImportRule* aParentRule);
nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
PRBool aAllowUnsafeRules,
PRBool aUseSystemPrincipal,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSStyleSheet** aSheet,
nsICSSLoaderObserver* aObserver);
// Post a load event for aObserver to be notified about aSheet. The
// notification will be sent with status NS_OK unless the load event is
// canceled at some point (in which case it will be sent with
// NS_BINDING_ABORTED). aWasAlternate indicates the state when the load was
// initiated, not the state at some later time. aURI should be the URI the
// sheet was loaded from (may be null for inline sheets).
nsresult PostLoadEvent(nsIURI* aURI,
nsICSSStyleSheet* aSheet,
nsICSSLoaderObserver* aObserver,
PRBool aWasAlternate);
// Start the loads of all the sheets in mPendingDatas
void StartAlternateLoads();
public:
// Handle an event posted by PostLoadEvent
void HandleLoadEvent(SheetLoadData* aEvent);
protected:
// Note: LoadSheet is responsible for releasing aLoadData and setting the
// sheet to complete on failure.
nsresult LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState);
friend class SheetLoadData;
// Protected functions and members are ones that SheetLoadData needs
// access to.
// Parse the stylesheet in aLoadData. The sheet data comes from aStream.
// Set aCompleted to true if the parse finished, false otherwise (e.g. if the
// sheet had an @import). If aCompleted is true when this returns, then
// ParseSheet also called SheetComplete on aLoadData
nsresult ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
PRBool& aCompleted);
// The load of the sheet in aLoadData is done, one way or another. Do final
// cleanup, including releasing aLoadData.
void SheetComplete(SheetLoadData* aLoadData, nsresult aStatus);
public:
typedef nsTArray<nsRefPtr<SheetLoadData> > LoadDataArray;
private:
// The guts of SheetComplete. This may be called recursively on parent datas
// or datas that had glommed on to a single load. The array is there so load
// datas whose observers need to be notified can be added to it.
void DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
LoadDataArray& aDatasToNotify);
// the load data needs access to the document...
nsIDocument* mDocument; // the document we live for
#ifdef DEBUG
PRPackedBool mSyncCallback;
#endif
PRPackedBool mEnabled; // is enabled to load new styles
nsCompatibility mCompatMode;
nsString mPreferredSheet; // title of preferred sheet
nsInterfaceHashtable<nsURIAndPrincipalHashKey,
nsICSSStyleSheet> mCompleteSheets;
nsDataHashtable<nsURIAndPrincipalHashKey,
SheetLoadData*> mLoadingDatas; // weak refs
nsDataHashtable<nsURIAndPrincipalHashKey,
SheetLoadData*> mPendingDatas; // weak refs
// We're not likely to have many levels of @import... But likely to have
// some. Allocate some storage, what the hell.
nsAutoTArray<SheetLoadData*, 8> mParsingDatas;
// The array of posted stylesheet loaded events (SheetLoadDatas) we have.
// Note that these are rare.
LoadDataArray mPostedEvents;
// Number of datas still waiting to be notified on if we're notifying on a
// whole bunch at once (e.g. in one of the stop methods). This is used to
// make sure that HasPendingLoads() won't return false until we're notifying
// on the last data we're working with.
PRUint32 mDatasToNotifyOn;
// Our array of "global" observers
nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver> > mObservers;
};
#ifdef MOZ_LOGGING
// #define FORCE_PR_LOG /* Allow logging in the release build */
#endif /* MOZ_LOGGING */
@ -598,7 +307,7 @@ static const char* const gStateStrings[] = {
********************************/
NS_IMPL_ISUPPORTS2(SheetLoadData, nsIUnicharStreamLoaderObserver, nsIRunnable)
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader,
SheetLoadData::SheetLoadData(Loader* aLoader,
const nsSubstring& aTitle,
nsIURI* aURI,
nsICSSStyleSheet* aSheet,
@ -630,7 +339,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader,
NS_ADDREF(mLoader);
}
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader,
SheetLoadData::SheetLoadData(Loader* aLoader,
nsIURI* aURI,
nsICSSStyleSheet* aSheet,
SheetLoadData* aParentData,
@ -670,7 +379,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader,
"Shouldn't use system principal for async loads");
}
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader,
SheetLoadData::SheetLoadData(Loader* aLoader,
nsIURI* aURI,
nsICSSStyleSheet* aSheet,
PRBool aSyncLoad,
@ -724,15 +433,36 @@ SheetLoadData::Run()
* Loader Implementation *
*************************/
CSSLoaderImpl::CSSLoaderImpl(void)
: mDocument(nsnull),
mEnabled(PR_TRUE),
mCompatMode(eCompatibility_FullStandards),
mDatasToNotifyOn(0)
Loader::Loader(void)
: mDocument(nsnull)
, mDatasToNotifyOn(0)
, mCompatMode(eCompatibility_FullStandards)
, mEnabled(PR_TRUE)
#ifdef DEBUG
, mSyncCallback(PR_FALSE)
#endif
{
}
CSSLoaderImpl::~CSSLoaderImpl(void)
Loader::Loader(nsIDocument* aDocument)
: mDocument(aDocument)
, mDatasToNotifyOn(0)
, mCompatMode(eCompatibility_FullStandards)
, mEnabled(PR_TRUE)
#ifdef DEBUG
, mSyncCallback(PR_FALSE)
#endif
{
// We can just use the preferred set, since there are no sheets in the
// document yet (if there are, how did they get there? _we_ load the sheets!)
// and hence the selected set makes no sense at this time.
nsCOMPtr<nsIDOMNSDocumentStyle> domDoc(do_QueryInterface(mDocument));
if (domDoc) {
domDoc->GetPreferredStyleSheetSet(mPreferredSheet);
}
}
Loader::~Loader()
{
NS_ASSERTION((!mLoadingDatas.IsInitialized()) || mLoadingDatas.Count() == 0,
"How did we get destroyed when there are loading data?");
@ -743,27 +473,11 @@ CSSLoaderImpl::~CSSLoaderImpl(void)
// they're all done.
}
NS_IMPL_ISUPPORTS1(CSSLoaderImpl, nsICSSLoader)
NS_IMPL_ADDREF(Loader)
NS_IMPL_RELEASE(Loader)
NS_IMETHODIMP
CSSLoaderImpl::Init(nsIDocument* aDocument)
{
NS_ASSERTION(! mDocument, "already initialized");
mDocument = aDocument;
// We can just use the preferred set, since there are no sheets in the
// document yet (if there are, how did they get there? _we_ load the sheets!)
// and hence the selected set makes no sense at this time.
nsCOMPtr<nsIDOMNSDocumentStyle> domDoc(do_QueryInterface(mDocument));
if (domDoc) {
domDoc->GetPreferredStyleSheetSet(mPreferredSheet);
}
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::DropDocumentReference(void)
void
Loader::DropDocumentReference(void)
{
mDocument = nsnull;
// Flush out pending datas just so we don't leak by accident. These
@ -772,24 +486,10 @@ CSSLoaderImpl::DropDocumentReference(void)
if (mPendingDatas.IsInitialized()) {
StartAlternateLoads();
}
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::SetCompatibilityMode(nsCompatibility aCompatMode)
{
mCompatMode = aCompatMode;
return NS_OK;
}
NS_IMETHODIMP_(nsCompatibility)
CSSLoaderImpl::GetCompatibilityMode()
{
return mCompatMode;
}
static PLDHashOperator
CollectNonAlternates(nsURIAndPrincipalHashKey *aKey,
CollectNonAlternates(URIAndPrincipalHashKey *aKey,
SheetLoadData* &aData,
void* aClosure)
{
@ -802,12 +502,12 @@ CollectNonAlternates(nsURIAndPrincipalHashKey *aKey,
return PL_DHASH_NEXT;
}
static_cast<CSSLoaderImpl::LoadDataArray*>(aClosure)->AppendElement(aData);
static_cast<Loader::LoadDataArray*>(aClosure)->AppendElement(aData);
return PL_DHASH_REMOVE;
}
NS_IMETHODIMP
CSSLoaderImpl::SetPreferredSheet(const nsAString& aTitle)
nsresult
Loader::SetPreferredSheet(const nsAString& aTitle)
{
#ifdef DEBUG
nsCOMPtr<nsIDOMNSDocumentStyle> doc(do_QueryInterface(mDocument));
@ -839,8 +539,8 @@ CSSLoaderImpl::SetPreferredSheet(const nsAString& aTitle)
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::GetPreferredSheet(nsAString& aTitle)
nsresult
Loader::GetPreferredSheet(nsAString& aTitle)
{
aTitle.Assign(mPreferredSheet);
return NS_OK;
@ -1279,7 +979,7 @@ static PRBool IsChromeURI(nsIURI* aURI)
#endif
PRBool
CSSLoaderImpl::IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel)
Loader::IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel)
{
// A sheet is alternate if it has a nonempty title that doesn't match the
// currently selected style set. But if there _is_ no currently selected
@ -1312,11 +1012,11 @@ CSSLoaderImpl::IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel)
* owning the stylesheet (possibly indirectly, for child sheets)
*/
nsresult
CSSLoaderImpl::CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
Loader::CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
nsIURI* aTargetURI,
nsISupports* aContext)
{
LOG(("CSSLoaderImpl::CheckLoadAllowed"));
LOG(("css::Loader::CheckLoadAllowed"));
nsresult rv;
@ -1364,14 +1064,14 @@ CSSLoaderImpl::CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
* CreateSheet().
*/
nsresult
CSSLoaderImpl::CreateSheet(nsIURI* aURI,
Loader::CreateSheet(nsIURI* aURI,
nsIContent* aLinkingContent,
nsIPrincipal* aLoaderPrincipal,
PRBool aSyncLoad,
StyleSheetState& aSheetState,
nsICSSStyleSheet** aSheet)
{
LOG(("CSSLoaderImpl::CreateSheet"));
LOG(("css::Loader::CreateSheet"));
NS_PRECONDITION(aSheet, "Null out param!");
NS_ENSURE_TRUE((mCompleteSheets.IsInitialized() || mCompleteSheets.Init()) &&
@ -1402,7 +1102,7 @@ CSSLoaderImpl::CreateSheet(nsIURI* aURI,
if (!sheet) {
// Then our per-document complete sheets.
nsURIAndPrincipalHashKey key(aURI, aLoaderPrincipal);
URIAndPrincipalHashKey key(aURI, aLoaderPrincipal);
mCompleteSheets.Get(&key, getter_AddRefs(sheet));
LOG((" From completed: %p", sheet.get()));
@ -1431,7 +1131,7 @@ CSSLoaderImpl::CreateSheet(nsIURI* aURI,
if (!sheet && !aSyncLoad) {
aSheetState = eSheetLoading;
SheetLoadData* loadData = nsnull;
nsURIAndPrincipalHashKey key(aURI, aLoaderPrincipal);
URIAndPrincipalHashKey key(aURI, aLoaderPrincipal);
mLoadingDatas.Get(&key, &loadData);
if (loadData) {
sheet = loadData->mSheet;
@ -1523,7 +1223,7 @@ CSSLoaderImpl::CreateSheet(nsIURI* aURI,
* the sheet had "alternate" in its rel.
*/
nsresult
CSSLoaderImpl::PrepareSheet(nsICSSStyleSheet* aSheet,
Loader::PrepareSheet(nsICSSStyleSheet* aSheet,
const nsSubstring& aTitle,
const nsSubstring& aMediaString,
nsMediaList* aMediaList,
@ -1577,11 +1277,11 @@ CSSLoaderImpl::PrepareSheet(nsICSSStyleSheet* aSheet,
* as determined by CompareDocumentPosition.
*/
nsresult
CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
Loader::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
nsIContent* aLinkingContent,
nsIDocument* aDocument)
{
LOG(("CSSLoaderImpl::InsertSheetInDoc"));
LOG(("css::Loader::InsertSheetInDoc"));
NS_PRECONDITION(aSheet, "Nothing to insert");
NS_PRECONDITION(aDocument, "Must have a document to insert into");
@ -1657,11 +1357,11 @@ CSSLoaderImpl::InsertSheetInDoc(nsICSSStyleSheet* aSheet,
* to put it anyway. So just append for now.
*/
nsresult
CSSLoaderImpl::InsertChildSheet(nsICSSStyleSheet* aSheet,
Loader::InsertChildSheet(nsICSSStyleSheet* aSheet,
nsICSSStyleSheet* aParentSheet,
nsICSSImportRule* aParentRule)
{
LOG(("CSSLoaderImpl::InsertChildSheet"));
LOG(("css::Loader::InsertChildSheet"));
NS_PRECONDITION(aSheet, "Nothing to insert");
NS_PRECONDITION(aParentSheet, "Need a parent to insert into");
NS_PRECONDITION(aParentSheet, "How did we get imported?");
@ -1688,9 +1388,9 @@ CSSLoaderImpl::InsertChildSheet(nsICSSStyleSheet* aSheet,
* a new load is kicked off asynchronously.
*/
nsresult
CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
Loader::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
{
LOG(("CSSLoaderImpl::LoadSheet"));
LOG(("css::Loader::LoadSheet"));
NS_PRECONDITION(aLoadData, "Need a load data");
NS_PRECONDITION(aLoadData->mURI, "Need a URI to load");
NS_PRECONDITION(aLoadData->mSheet, "Need a sheet to load into");
@ -1781,7 +1481,7 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
SheetLoadData* existingData = nsnull;
nsURIAndPrincipalHashKey key(aLoadData->mURI, aLoadData->mLoaderPrincipal);
URIAndPrincipalHashKey key(aLoadData->mURI, aLoadData->mLoaderPrincipal);
if (aSheetState == eSheetLoading) {
mLoadingDatas.Get(&key, &existingData);
NS_ASSERTION(existingData, "CreateSheet lied about the state");
@ -1928,11 +1628,11 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
* correctly.
*/
nsresult
CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
Loader::ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
PRBool& aCompleted)
{
LOG(("CSSLoaderImpl::ParseSheet"));
LOG(("css::Loader::ParseSheet"));
NS_PRECONDITION(aStream, "Must have data to parse");
NS_PRECONDITION(aLoadData, "Must have load data");
NS_PRECONDITION(aLoadData->mSheet, "Must have sheet to parse into");
@ -1986,9 +1686,9 @@ CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
* NS_RELEASE on the load data to destroy the whole mess.
*/
void
CSSLoaderImpl::SheetComplete(SheetLoadData* aLoadData, nsresult aStatus)
Loader::SheetComplete(SheetLoadData* aLoadData, nsresult aStatus)
{
LOG(("CSSLoaderImpl::SheetComplete"));
LOG(("css::Loader::SheetComplete"));
// 8 is probably big enough for all our common cases. It's not likely that
// imports will nest more than 8 deep, and multiple sheets with the same URI
@ -2028,10 +1728,10 @@ CSSLoaderImpl::SheetComplete(SheetLoadData* aLoadData, nsresult aStatus)
}
void
CSSLoaderImpl::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
Loader::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
LoadDataArray& aDatasToNotify)
{
LOG(("CSSLoaderImpl::DoSheetComplete"));
LOG(("css::Loader::DoSheetComplete"));
NS_PRECONDITION(aLoadData, "Must have a load data!");
NS_PRECONDITION(aLoadData->mSheet, "Must have a sheet");
NS_ASSERTION(mLoadingDatas.IsInitialized(),"mLoadingDatas should be initialized by now.");
@ -2043,7 +1743,7 @@ CSSLoaderImpl::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
LOG_URI(" Finished loading: '%s'", aLoadData->mURI);
// Remove the data from the list of loading datas
if (aLoadData->mIsLoading) {
nsURIAndPrincipalHashKey key(aLoadData->mURI,
URIAndPrincipalHashKey key(aLoadData->mURI,
aLoadData->mLoaderPrincipal);
#ifdef DEBUG
SheetLoadData *loadingData;
@ -2104,7 +1804,7 @@ CSSLoaderImpl::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
}
else {
#endif
nsURIAndPrincipalHashKey key(aLoadData->mURI,
URIAndPrincipalHashKey key(aLoadData->mURI,
aLoadData->mLoaderPrincipal);
mCompleteSheets.Put(&key, aLoadData->mSheet);
#ifdef MOZ_XUL
@ -2115,8 +1815,8 @@ CSSLoaderImpl::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
NS_RELEASE(aLoadData); // this will release parents and siblings and all that
}
NS_IMETHODIMP
CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
nsresult
Loader::LoadInlineStyle(nsIContent* aElement,
nsIUnicharInputStream* aStream,
PRUint32 aLineNumber,
const nsSubstring& aTitle,
@ -2125,7 +1825,7 @@ CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
PRBool* aCompleted,
PRBool* aIsAlternate)
{
LOG(("CSSLoaderImpl::LoadInlineStyle"));
LOG(("css::Loader::LoadInlineStyle"));
NS_PRECONDITION(aStream, "Must have a stream to parse!");
NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
@ -2186,8 +1886,8 @@ CSSLoaderImpl::LoadInlineStyle(nsIContent* aElement,
return rv;
}
NS_IMETHODIMP
CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,
nsresult
Loader::LoadStyleLink(nsIContent* aElement,
nsIURI* aURL,
const nsSubstring& aTitle,
const nsSubstring& aMedia,
@ -2195,7 +1895,7 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,
nsICSSLoaderObserver* aObserver,
PRBool* aIsAlternate)
{
LOG(("CSSLoaderImpl::LoadStyleLink"));
LOG(("css::Loader::LoadStyleLink"));
NS_PRECONDITION(aURL, "Must have URL to load");
NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
@ -2266,7 +1966,7 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,
if (aURL && state == eSheetNeedsParser && mLoadingDatas.Count() != 0 &&
*aIsAlternate) {
LOG((" Deferring alternate sheet load"));
nsURIAndPrincipalHashKey key(data->mURI, data->mLoaderPrincipal);
URIAndPrincipalHashKey key(data->mURI, data->mLoaderPrincipal);
if (!mPendingDatas.Put(&key, data)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -2283,13 +1983,13 @@ CSSLoaderImpl::LoadStyleLink(nsIContent* aElement,
return rv;
}
NS_IMETHODIMP
CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsresult
Loader::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsIURI* aURL,
nsMediaList* aMedia,
nsICSSImportRule* aParentRule)
{
LOG(("CSSLoaderImpl::LoadChildSheet"));
LOG(("css::Loader::LoadChildSheet"));
NS_PRECONDITION(aURL, "Must have a URI to load");
NS_PRECONDITION(aParentSheet, "Must have a parent sheet");
@ -2407,45 +2107,45 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
return rv;
}
NS_IMETHODIMP
CSSLoaderImpl::LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules,
nsresult
Loader::LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules,
PRBool aUseSystemPrincipal,
nsICSSStyleSheet** aSheet)
{
LOG(("CSSLoaderImpl::LoadSheetSync"));
LOG(("css::Loader::LoadSheetSync"));
return InternalLoadNonDocumentSheet(aURL, aAllowUnsafeRules,
aUseSystemPrincipal, nsnull,
EmptyCString(), aSheet, nsnull);
}
NS_IMETHODIMP
CSSLoaderImpl::LoadSheet(nsIURI* aURL,
nsresult
Loader::LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver,
nsICSSStyleSheet** aSheet)
{
LOG(("CSSLoaderImpl::LoadSheet(aURL, aObserver, aSheet) api call"));
LOG(("css::Loader::LoadSheet(aURL, aObserver, aSheet) api call"));
NS_PRECONDITION(aSheet, "aSheet is null");
return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE,
aOriginPrincipal, aCharset,
aSheet, aObserver);
}
NS_IMETHODIMP
CSSLoaderImpl::LoadSheet(nsIURI* aURL,
nsresult
Loader::LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver)
{
LOG(("CSSLoaderImpl::LoadSheet(aURL, aObserver) api call"));
LOG(("css::Loader::LoadSheet(aURL, aObserver) api call"));
return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE,
aOriginPrincipal, aCharset,
nsnull, aObserver);
}
nsresult
CSSLoaderImpl::InternalLoadNonDocumentSheet(nsIURI* aURL,
Loader::InternalLoadNonDocumentSheet(nsIURI* aURL,
PRBool aAllowUnsafeRules,
PRBool aUseSystemPrincipal,
nsIPrincipal* aOriginPrincipal,
@ -2523,12 +2223,12 @@ CSSLoaderImpl::InternalLoadNonDocumentSheet(nsIURI* aURL,
}
nsresult
CSSLoaderImpl::PostLoadEvent(nsIURI* aURI,
Loader::PostLoadEvent(nsIURI* aURI,
nsICSSStyleSheet* aSheet,
nsICSSLoaderObserver* aObserver,
PRBool aWasAlternate)
{
LOG(("nsCSSLoader::PostLoadEvent"));
LOG(("css::Loader::PostLoadEvent"));
NS_PRECONDITION(aSheet, "Must have sheet");
NS_PRECONDITION(aObserver, "Must have observer");
@ -2564,7 +2264,7 @@ CSSLoaderImpl::PostLoadEvent(nsIURI* aURI,
}
void
CSSLoaderImpl::HandleLoadEvent(SheetLoadData* aEvent)
Loader::HandleLoadEvent(SheetLoadData* aEvent)
{
// XXXbz can't assert this yet.... May not have an observer because
// we're unblocking the parser
@ -2584,27 +2284,8 @@ CSSLoaderImpl::HandleLoadEvent(SheetLoadData* aEvent)
}
}
nsresult NS_NewCSSLoader(nsIDocument* aDocument, nsICSSLoader** aLoader)
{
CSSLoaderImpl* it = new CSSLoaderImpl();
NS_ENSURE_TRUE(it, NS_ERROR_OUT_OF_MEMORY);
it->Init(aDocument);
return CallQueryInterface(it, aLoader);
}
nsresult NS_NewCSSLoader(nsICSSLoader** aLoader)
{
CSSLoaderImpl* it = new CSSLoaderImpl();
NS_ENSURE_TRUE(it, NS_ERROR_OUT_OF_MEMORY);
return CallQueryInterface(it, aLoader);
}
static PLDHashOperator
StopLoadingSheetCallback(nsURIAndPrincipalHashKey* aKey,
StopLoadingSheetCallback(URIAndPrincipalHashKey* aKey,
SheetLoadData*& aData,
void* aClosure)
{
@ -2614,13 +2295,13 @@ StopLoadingSheetCallback(nsURIAndPrincipalHashKey* aKey,
aData->mIsLoading = PR_FALSE; // we will handle the removal right here
aData->mIsCancelled = PR_TRUE;
static_cast<CSSLoaderImpl::LoadDataArray*>(aClosure)->AppendElement(aData);
static_cast<Loader::LoadDataArray*>(aClosure)->AppendElement(aData);
return PL_DHASH_REMOVE;
}
NS_IMETHODIMP
CSSLoaderImpl::Stop()
nsresult
Loader::Stop()
{
PRUint32 pendingCount =
mPendingDatas.IsInitialized() ? mPendingDatas.Count() : 0;
@ -2662,16 +2343,16 @@ CSSLoaderImpl::Stop()
struct StopLoadingSheetsByURIClosure {
StopLoadingSheetsByURIClosure(nsIURI* aURI,
CSSLoaderImpl::LoadDataArray& aArray) :
Loader::LoadDataArray& aArray) :
uri(aURI), array(aArray)
{}
nsIURI* uri;
CSSLoaderImpl::LoadDataArray& array;
Loader::LoadDataArray& array;
};
static PLDHashOperator
StopLoadingSheetByURICallback(nsURIAndPrincipalHashKey* aKey,
StopLoadingSheetByURICallback(URIAndPrincipalHashKey* aKey,
SheetLoadData*& aData,
void* aClosure)
{
@ -2694,8 +2375,8 @@ StopLoadingSheetByURICallback(nsURIAndPrincipalHashKey* aKey,
return PL_DHASH_NEXT;
}
NS_IMETHODIMP
CSSLoaderImpl::StopLoadingSheet(nsIURI* aURL)
nsresult
Loader::StopLoadingSheet(nsIURI* aURL)
{
NS_ENSURE_TRUE(aURL, NS_ERROR_NULL_POINTER);
@ -2743,23 +2424,8 @@ CSSLoaderImpl::StopLoadingSheet(nsIURI* aURL)
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::GetEnabled(PRBool *aEnabled)
{
NS_ENSURE_ARG_POINTER(aEnabled);
*aEnabled = mEnabled;
return NS_OK;
}
NS_IMETHODIMP
CSSLoaderImpl::SetEnabled(PRBool aEnabled)
{
mEnabled = aEnabled;
return NS_OK;
}
NS_IMETHODIMP_(PRBool)
CSSLoaderImpl::HasPendingLoads()
PRBool
Loader::HasPendingLoads()
{
return
(mLoadingDatas.IsInitialized() && mLoadingDatas.Count() != 0) ||
@ -2768,8 +2434,8 @@ CSSLoaderImpl::HasPendingLoads()
mDatasToNotifyOn != 0;
}
NS_IMETHODIMP
CSSLoaderImpl::AddObserver(nsICSSLoaderObserver* aObserver)
nsresult
Loader::AddObserver(nsICSSLoaderObserver* aObserver)
{
NS_PRECONDITION(aObserver, "Must have observer");
if (mObservers.AppendElementUnlessExists(aObserver)) {
@ -2779,23 +2445,23 @@ CSSLoaderImpl::AddObserver(nsICSSLoaderObserver* aObserver)
return NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP_(void)
CSSLoaderImpl::RemoveObserver(nsICSSLoaderObserver* aObserver)
void
Loader::RemoveObserver(nsICSSLoaderObserver* aObserver)
{
mObservers.RemoveElement(aObserver);
}
static PLDHashOperator
CollectLoadDatas(nsURIAndPrincipalHashKey *aKey,
CollectLoadDatas(URIAndPrincipalHashKey *aKey,
SheetLoadData* &aData,
void* aClosure)
{
static_cast<CSSLoaderImpl::LoadDataArray*>(aClosure)->AppendElement(aData);
static_cast<Loader::LoadDataArray*>(aClosure)->AppendElement(aData);
return PL_DHASH_REMOVE;
}
void
CSSLoaderImpl::StartAlternateLoads()
Loader::StartAlternateLoads()
{
NS_PRECONDITION(mPendingDatas.IsInitialized(), "Don't call me!");
LoadDataArray arr(mPendingDatas.Count());
@ -2807,3 +2473,6 @@ CSSLoaderImpl::StartAlternateLoads()
LoadSheet(arr[i], eSheetNeedsParser);
}
}
} // namespace css
} // namespace mozilla

500
layout/style/nsCSSLoader.h Normal file
View file

@ -0,0 +1,500 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* loading of CSS style sheets using the network APIs */
#ifndef nsICSSLoader_h___
#define nsICSSLoader_h___
#include "nsIPrincipal.h"
#include "nsAString.h"
#include "nsAutoPtr.h"
#include "nsCompatibility.h"
#include "nsDataHashtable.h"
#include "nsInterfaceHashtable.h"
#include "nsTArray.h"
#include "nsTObserverArray.h"
#include "nsURIHashKey.h"
class nsIAtom;
class nsICSSImportRule;
class nsICSSLoaderObserver;
class nsICSSStyleSheet;
class nsIContent;
class nsIDocument;
class nsIUnicharInputStream;
class nsCSSParser;
class nsMediaList;
class nsPresContext;
namespace mozilla {
class URIAndPrincipalHashKey : public nsURIHashKey
{
public:
typedef URIAndPrincipalHashKey* KeyType;
typedef const URIAndPrincipalHashKey* KeyTypePointer;
URIAndPrincipalHashKey(const URIAndPrincipalHashKey* aKey)
: nsURIHashKey(aKey->mKey), mPrincipal(aKey->mPrincipal)
{
MOZ_COUNT_CTOR(URIAndPrincipalHashKey);
}
URIAndPrincipalHashKey(nsIURI* aURI, nsIPrincipal* aPrincipal)
: nsURIHashKey(aURI), mPrincipal(aPrincipal)
{
MOZ_COUNT_CTOR(URIAndPrincipalHashKey);
}
URIAndPrincipalHashKey(const URIAndPrincipalHashKey& toCopy)
: nsURIHashKey(toCopy), mPrincipal(toCopy.mPrincipal)
{
MOZ_COUNT_CTOR(URIAndPrincipalHashKey);
}
~URIAndPrincipalHashKey()
{
MOZ_COUNT_DTOR(URIAndPrincipalHashKey);
}
URIAndPrincipalHashKey* GetKey() const {
return const_cast<URIAndPrincipalHashKey*>(this);
}
const URIAndPrincipalHashKey* GetKeyPointer() const { return this; }
PRBool KeyEquals(const URIAndPrincipalHashKey* aKey) const {
if (!nsURIHashKey::KeyEquals(aKey->mKey)) {
return PR_FALSE;
}
if (!mPrincipal != !aKey->mPrincipal) {
// One or the other has a principal, but not both... not equal
return PR_FALSE;
}
PRBool eq;
return !mPrincipal ||
(NS_SUCCEEDED(mPrincipal->Equals(aKey->mPrincipal, &eq)) && eq);
}
static const URIAndPrincipalHashKey*
KeyToPointer(URIAndPrincipalHashKey* aKey) { return aKey; }
static PLDHashNumber HashKey(const URIAndPrincipalHashKey* aKey) {
return nsURIHashKey::HashKey(aKey->mKey);
}
enum { ALLOW_MEMMOVE = PR_TRUE };
protected:
nsCOMPtr<nsIPrincipal> mPrincipal;
};
namespace css {
class SheetLoadData;
/***********************************************************************
* Enum that describes the state of the sheet returned by CreateSheet. *
***********************************************************************/
enum StyleSheetState {
eSheetStateUnknown = 0,
eSheetNeedsParser,
eSheetPending,
eSheetLoading,
eSheetComplete
};
class Loader {
public:
Loader();
Loader(nsIDocument*);
~Loader();
// This isn't a COM class but it's reference-counted like one.
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
void DropDocumentReference(); // notification that doc is going away
void SetCompatibilityMode(nsCompatibility aCompatMode)
{ mCompatMode = aCompatMode; }
nsCompatibility GetCompatibilityMode() { return mCompatMode; }
nsresult SetPreferredSheet(const nsAString& aTitle);
nsresult GetPreferredSheet(nsAString& aTitle);
// XXXbz sort out what the deal is with events! When should they fire?
/**
* Load an inline style sheet. If a successful result is returned and
* *aCompleted is false, then aObserver is guaranteed to be notified
* asynchronously once the sheet is marked complete. If an error is
* returned, or if *aCompleted is true, aObserver will not be notified. In
* addition to parsing the sheet, this method will insert it into the
* stylesheet list of this CSSLoader's document.
*
* @param aElement the element linking to the stylesheet. This must not be
* null and must implement nsIStyleSheetLinkingElement.
* @param aStream the character stream that holds the stylesheet data.
* @param aLineNumber the line number at which the stylesheet data started.
* @param aTitle the title of the sheet.
* @param aMedia the media string for the sheet.
* @param aObserver the observer to notify when the load completes.
* May be null.
* @param [out] aCompleted whether parsing of the sheet completed.
* @param [out] aIsAlternate whether the stylesheet ended up being an
* alternate sheet.
*/
nsresult LoadInlineStyle(nsIContent* aElement,
nsIUnicharInputStream* aStream,
PRUint32 aLineNumber,
const nsAString& aTitle,
const nsAString& aMedia,
nsICSSLoaderObserver* aObserver,
PRBool* aCompleted,
PRBool* aIsAlternate);
/**
* Load a linked (document) stylesheet. If a successful result is returned,
* aObserver is guaranteed to be notified asynchronously once the sheet is
* loaded and marked complete. If an error is returned, aObserver will not
* be notified. In addition to loading the sheet, this method will insert it
* into the stylesheet list of this CSSLoader's document.
*
* @param aElement the element linking to the the stylesheet. May be null.
* @param aURL the URL of the sheet.
* @param aTitle the title of the sheet.
* @param aMedia the media string for the sheet.
* @param aHasAlternateRel whether the rel for this link included
* "alternate".
* @param aObserver the observer to notify when the load completes.
* May be null.
* @param [out] aIsAlternate whether the stylesheet actually ended up beinga
* an alternate sheet. Note that this need not match
* aHasAlternateRel.
*/
nsresult LoadStyleLink(nsIContent* aElement,
nsIURI* aURL,
const nsAString& aTitle,
const nsAString& aMedia,
PRBool aHasAlternateRel,
nsICSSLoaderObserver* aObserver,
PRBool* aIsAlternate);
/**
* Load a child (@import-ed) style sheet. In addition to loading the sheet,
* this method will insert it into the child sheet list of aParentSheet. If
* there is no sheet currently being parsed and the child sheet is not
* complete when this method returns, then when the child sheet becomes
* complete aParentSheet will be QIed to nsICSSLoaderObserver and
* asynchronously notified, just like for LoadStyleLink. Note that if the
* child sheet is already complete when this method returns, no
* nsICSSLoaderObserver notification will be sent.
*
* @param aParentSheet the parent of this child sheet
* @param aURL the URL of the child sheet
* @param aMedia the already-parsed media list for the child sheet
* @param aRule the @import rule importing this child. This is used to
* properly order the child sheet list of aParentSheet.
*/
nsresult LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsIURI* aURL,
nsMediaList* aMedia,
nsICSSImportRule* aRule);
/**
* Synchronously load and return the stylesheet at aURL. Any child sheets
* will also be loaded synchronously. Note that synchronous loads over some
* protocols may involve spinning up a new event loop, so use of this method
* does NOT guarantee not receiving any events before the sheet loads. This
* method can be used to load sheets not associated with a document.
*
* @param aURL the URL of the sheet to load
* @param aEnableUnsafeRules whether unsafe rules are enabled for this
* sheet load
* Unsafe rules are rules that can violate key Gecko invariants if misused.
* In particular, most anonymous box pseudoelements must be very carefully
* styled or we will have severe problems. Therefore unsafe rules should
* never be enabled for stylesheets controlled by untrusted sites; preferably
* unsafe rules should only be enabled for agent sheets.
* @param aUseSystemPrincipal if true, give the resulting sheet the system
* principal no matter where it's being loaded from.
* @param [out] aSheet the loaded, complete sheet.
*
* NOTE: At the moment, this method assumes the sheet will be UTF-8, but
* ideally it would allow arbitrary encodings. Callers should NOT depend on
* non-UTF8 sheets being treated as UTF-8 by this method.
*
* NOTE: A successful return from this method doesn't indicate anything about
* whether the data could be parsed as CSS and doesn't indicate anything
* about the status of child sheets of the returned sheet.
*/
nsresult LoadSheetSync(nsIURI* aURL, PRBool aEnableUnsafeRules,
PRBool aUseSystemPrincipal,
nsICSSStyleSheet** aSheet);
/**
* As above, but aUseSystemPrincipal and aEnableUnsafeRules are assumed false.
*/
nsresult LoadSheetSync(nsIURI* aURL, nsICSSStyleSheet** aSheet) {
return LoadSheetSync(aURL, PR_FALSE, PR_FALSE, aSheet);
}
/**
* Asynchronously load the stylesheet at aURL. If a successful result is
* returned, aObserver is guaranteed to be notified asynchronously once the
* sheet is loaded and marked complete. This method can be used to load
* sheets not associated with a document.
*
* @param aURL the URL of the sheet to load
* @param aOriginPrincipal the principal to use for security checks. This
* can be null to indicate that these checks should
* be skipped.
* @param aCharset the encoding to use for converting the sheet data
* from bytes to Unicode. May be empty to indicate that the
* charset of the CSSLoader's document should be used. This
* is only used if neither the network transport nor the
* sheet itself indicate an encoding.
* @param aObserver the observer to notify when the load completes.
* Must not be null.
* @param [out] aSheet the sheet to load. Note that the sheet may well
* not be loaded by the time this method returns.
*/
nsresult LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver,
nsICSSStyleSheet** aSheet);
/**
* Same as above, to be used when the caller doesn't care about the
* not-yet-loaded sheet.
*/
nsresult LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver);
/**
* Stop loading all sheets. All nsICSSLoaderObservers involved will be
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
*/
nsresult Stop(void);
/**
* Stop loading one sheet. The nsICSSLoaderObserver involved will be
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
*/
nsresult StopLoadingSheet(nsIURI* aURL);
/**
* Whether the loader is enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
PRBool GetEnabled() { return mEnabled; }
void SetEnabled(PRBool aEnabled) { mEnabled = aEnabled; }
/**
* Return true if this loader has pending loads (ones that would send
* notifications to an nsICSSLoaderObserver attached to this loader).
* If called from inside nsICSSLoaderObserver::StyleSheetLoaded, this will
* return PR_FALSE if and only if that is the last StyleSheetLoaded
* notification the CSSLoader knows it's going to send. In other words, if
* two sheets load at once (via load coalescing, e.g.), HasPendingLoads()
* will return PR_TRUE during notification for the first one, and PR_FALSE
* during notification for the second one.
*/
PRBool HasPendingLoads();
/**
* Add an observer to this loader. The observer will be notified
* for all loads that would have notified their own observers (even
* if those loads don't have observers attached to them).
* Load-specific observers will be notified before generic
* observers. The loader holds a reference to the observer.
*
* aObserver must not be null.
*/
nsresult AddObserver(nsICSSLoaderObserver* aObserver);
/**
* Remove an observer added via AddObserver.
*/
void RemoveObserver(nsICSSLoaderObserver* aObserver);
// These interfaces are public only for the benefit of static functions
// within nsCSSLoader.cpp.
// IsAlternate can change our currently selected style set if none
// is selected and aHasAlternateRel is false.
PRBool IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel);
typedef nsTArray<nsRefPtr<SheetLoadData> > LoadDataArray;
private:
friend class SheetLoadData;
// Note: null aSourcePrincipal indicates that the content policy and
// CheckLoadURI checks should be skipped.
nsresult CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
nsIURI* aTargetURI,
nsISupports* aContext);
// For inline style, the aURI param is null, but the aLinkingContent
// must be non-null then. The loader principal must never be null
// if aURI is not null.
nsresult CreateSheet(nsIURI* aURI,
nsIContent* aLinkingContent,
nsIPrincipal* aLoaderPrincipal,
PRBool aSyncLoad,
StyleSheetState& aSheetState,
nsICSSStyleSheet** aSheet);
// Pass in either a media string or the nsMediaList from the
// CSSParser. Don't pass both.
// If aIsAlternate is non-null, this method will set *aIsAlternate to
// correspond to the sheet's enabled state (which it will set no matter what)
nsresult PrepareSheet(nsICSSStyleSheet* aSheet,
const nsAString& aTitle,
const nsAString& aMediaString,
nsMediaList* aMediaList,
PRBool aHasAlternateRel = PR_FALSE,
PRBool *aIsAlternate = nsnull);
nsresult InsertSheetInDoc(nsICSSStyleSheet* aSheet,
nsIContent* aLinkingContent,
nsIDocument* aDocument);
nsresult InsertChildSheet(nsICSSStyleSheet* aSheet,
nsICSSStyleSheet* aParentSheet,
nsICSSImportRule* aParentRule);
nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
PRBool aAllowUnsafeRules,
PRBool aUseSystemPrincipal,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSStyleSheet** aSheet,
nsICSSLoaderObserver* aObserver);
// Post a load event for aObserver to be notified about aSheet. The
// notification will be sent with status NS_OK unless the load event is
// canceled at some point (in which case it will be sent with
// NS_BINDING_ABORTED). aWasAlternate indicates the state when the load was
// initiated, not the state at some later time. aURI should be the URI the
// sheet was loaded from (may be null for inline sheets).
nsresult PostLoadEvent(nsIURI* aURI,
nsICSSStyleSheet* aSheet,
nsICSSLoaderObserver* aObserver,
PRBool aWasAlternate);
// Start the loads of all the sheets in mPendingDatas
void StartAlternateLoads();
// Handle an event posted by PostLoadEvent
void HandleLoadEvent(SheetLoadData* aEvent);
// Note: LoadSheet is responsible for releasing aLoadData and setting the
// sheet to complete on failure.
nsresult LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState);
// Parse the stylesheet in aLoadData. The sheet data comes from aStream.
// Set aCompleted to true if the parse finished, false otherwise (e.g. if the
// sheet had an @import). If aCompleted is true when this returns, then
// ParseSheet also called SheetComplete on aLoadData
nsresult ParseSheet(nsIUnicharInputStream* aStream,
SheetLoadData* aLoadData,
PRBool& aCompleted);
// The load of the sheet in aLoadData is done, one way or another. Do final
// cleanup, including releasing aLoadData.
void SheetComplete(SheetLoadData* aLoadData, nsresult aStatus);
// The guts of SheetComplete. This may be called recursively on parent datas
// or datas that had glommed on to a single load. The array is there so load
// datas whose observers need to be notified can be added to it.
void DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
LoadDataArray& aDatasToNotify);
nsInterfaceHashtable<URIAndPrincipalHashKey, nsICSSStyleSheet>
mCompleteSheets;
nsDataHashtable<URIAndPrincipalHashKey, SheetLoadData*>
mLoadingDatas; // weak refs
nsDataHashtable<URIAndPrincipalHashKey, SheetLoadData*>
mPendingDatas; // weak refs
// We're not likely to have many levels of @import... But likely to have
// some. Allocate some storage, what the hell.
nsAutoTArray<SheetLoadData*, 8> mParsingDatas;
// The array of posted stylesheet loaded events (SheetLoadDatas) we have.
// Note that these are rare.
LoadDataArray mPostedEvents;
// Our array of "global" observers
nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver> > mObservers;
// the load data needs access to the document...
nsIDocument* mDocument; // the document we live for
// Refcounting
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
// Number of datas still waiting to be notified on if we're notifying on a
// whole bunch at once (e.g. in one of the stop methods). This is used to
// make sure that HasPendingLoads() won't return false until we're notifying
// on the last data we're working with.
PRUint32 mDatasToNotifyOn;
nsCompatibility mCompatMode;
nsString mPreferredSheet; // title of preferred sheet
PRPackedBool mEnabled; // is enabled to load new styles
#ifdef DEBUG
PRPackedBool mSyncCallback;
#endif
};
} // namespace css
} // namespace mozilla
#endif /* nsICSSLoader_h___ */

View file

@ -50,7 +50,7 @@
#include "nsCSSProps.h"
#include "nsCSSKeywords.h"
#include "nsCSSScanner.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICSSStyleRule.h"
#include "nsICSSImportRule.h"
#include "nsCSSRules.h"
@ -176,7 +176,7 @@ public:
nsresult SetSVGMode(PRBool aSVGMode);
#endif
nsresult SetChildLoader(nsICSSLoader* aChildLoader);
nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
// Clears everything set by the above Set*() functions.
void Reset();
@ -619,7 +619,7 @@ protected:
nsCOMPtr<nsICSSStyleSheet> mSheet;
// Used for @import rules
nsICSSLoader* mChildLoader; // not ref counted, it owns us
mozilla::css::Loader* mChildLoader; // not ref counted, it owns us
// Sheet section we're in. This is used to enforce correct ordering of the
// various rule types (eg the fact that a @charset rule must come before
@ -793,7 +793,7 @@ CSSParserImpl::SetSVGMode(PRBool aSVGMode)
#endif
nsresult
CSSParserImpl::SetChildLoader(nsICSSLoader* aChildLoader)
CSSParserImpl::SetChildLoader(mozilla::css::Loader* aChildLoader)
{
mChildLoader = aChildLoader; // not ref counted, it owns us
return NS_OK;
@ -9137,7 +9137,7 @@ CSSParserImpl::ParseMarker()
static CSSParserImpl* gFreeList = nsnull;
nsCSSParser::nsCSSParser(nsICSSLoader* aLoader,
nsCSSParser::nsCSSParser(mozilla::css::Loader* aLoader,
nsICSSStyleSheet* aSheet)
{
CSSParserImpl *impl = gFreeList;
@ -9207,7 +9207,7 @@ nsCSSParser::SetSVGMode(PRBool aSVGMode)
#endif
nsresult
nsCSSParser::SetChildLoader(nsICSSLoader* aChildLoader)
nsCSSParser::SetChildLoader(mozilla::css::Loader* aChildLoader)
{
return static_cast<CSSParserImpl*>(mImpl)->
SetChildLoader(aChildLoader);

View file

@ -45,23 +45,27 @@
#include "nsColor.h"
#include "nsCOMArray.h"
class nsICSSStyleRule;
class nsICSSLoader;
class nsICSSStyleSheet;
class nsIUnicharInputStream;
class nsIURI;
class nsCSSDeclaration;
class nsICSSLoader;
class nsICSSRule;
class nsMediaList;
class nsICSSStyleRule;
class nsICSSStyleSheet;
class nsIPrincipal;
class nsIURI;
class nsIUnicharInputStream;
class nsCSSDeclaration;
struct nsCSSSelectorList;
class nsMediaList;
namespace mozilla {
namespace css {
class Loader;
}
}
// Interface to the css parser.
class NS_STACK_CLASS nsCSSParser {
public:
NS_HIDDEN nsCSSParser(nsICSSLoader* aLoader = nsnull,
NS_HIDDEN nsCSSParser(mozilla::css::Loader* aLoader = nsnull,
nsICSSStyleSheet* aSheet = nsnull);
NS_HIDDEN ~nsCSSParser();
@ -92,7 +96,7 @@ public:
#endif
// Set loader to use for child sheets
NS_HIDDEN_(nsresult) SetChildLoader(nsICSSLoader* aChildLoader);
NS_HIDDEN_(nsresult) SetChildLoader(mozilla::css::Loader* aChildLoader);
/**
* Parse aInput into the stylesheet that was previously set by calling
@ -108,7 +112,7 @@ public:
* the principal of the sheet passed to SetStyleSheet.
* @param aLineNumber the line number of the first line of the sheet.
* @param aAllowUnsafeRules see aEnableUnsafeRules in
* nsICSSLoader::LoadSheetSync
* mozilla::css::Loader::LoadSheetSync
*/
NS_HIDDEN_(nsresult) Parse(nsIUnicharInputStream* aInput,
nsIURI* aSheetURL,

View file

@ -50,7 +50,7 @@
#include "nsICSSGroupRule.h"
#include "nsCSSDeclaration.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIURL.h"
#include "nsPresContext.h"
#include "nsIDocument.h"
@ -912,7 +912,7 @@ public:
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader);
mozilla::css::Loader** aCSSLoader);
virtual nsresult DeclarationChanged();
virtual nsIDocument* DocToUpdate();
@ -1019,7 +1019,7 @@ nsresult
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader)
mozilla::css::Loader** aCSSLoader)
{
// null out the out params since some of them may not get initialized below
*aSheetURI = nsnull;

View file

@ -66,7 +66,7 @@
#include "nsIDOMNode.h"
#include "nsDOMError.h"
#include "nsCSSParser.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICSSLoaderObserver.h"
#include "nsINameSpaceManager.h"
#include "nsXMLNameSpaceMap.h"
@ -78,6 +78,8 @@
#include "nsCSSDeclaration.h"
#include "nsRuleNode.h"
namespace css = mozilla::css;
// -------------------------------
// Style Rule List for the DOM
//
@ -1843,7 +1845,7 @@ nsCSSStyleSheet::InsertRuleInternal(const nsAString& aRule,
// Hold strong ref to the CSSLoader in case the document update
// kills the document
nsCOMPtr<nsICSSLoader> loader;
nsRefPtr<css::Loader> loader;
if (mDocument) {
loader = mDocument->CSSLoader();
NS_ASSERTION(loader, "Document with no CSS loader!");
@ -2065,7 +2067,7 @@ nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
// Hold strong ref to the CSSLoader in case the document update
// kills the document
nsCOMPtr<nsICSSLoader> loader;
nsRefPtr<css::Loader> loader;
if (mDocument) {
loader = mDocument->CSSLoader();
NS_ASSERTION(loader, "Document with no CSS loader!");

View file

@ -42,7 +42,7 @@
#include "nsIDocument.h"
#include "nsIDOMMutationEvent.h"
#include "nsICSSStyleRule.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIURI.h"
#include "nsINameSpaceManager.h"
#include "nsStyleConsts.h"
@ -182,7 +182,7 @@ nsresult
nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader)
mozilla::css::Loader** aCSSLoader)
{
NS_ASSERTION(mContent, "Something is severely broken -- there should be an nsIContent here!");
// null out the out params since some of them may not get initialized below

View file

@ -46,7 +46,11 @@
#include "nsWrapperCache.h"
#include "nsIContent.h"
class nsICSSLoader;
namespace mozilla {
namespace css {
class Loader;
}
}
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration,
public nsWrapperCache
@ -69,7 +73,7 @@ public:
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader);
mozilla::css::Loader** aCSSLoader);
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
virtual nsINode *GetParentObject()

View file

@ -41,7 +41,7 @@
#include "nsDOMCSSDeclaration.h"
#include "nsIDOMCSSRule.h"
#include "nsCSSParser.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIStyleRule.h"
#include "nsCSSDeclaration.h"
#include "nsCSSProps.h"
@ -53,6 +53,7 @@
#include "nsContentUtils.h"
#include "mozAutoDocUpdate.h"
namespace css = mozilla::css;
nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
{
@ -252,7 +253,7 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
return result;
}
nsCOMPtr<nsICSSLoader> cssLoader;
nsRefPtr<css::Loader> cssLoader;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
@ -293,7 +294,7 @@ nsDOMCSSDeclaration::ParseDeclaration(const nsAString& aDecl,
return result;
}
nsCOMPtr<nsICSSLoader> cssLoader;
nsRefPtr<css::Loader> cssLoader;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;

View file

@ -47,11 +47,16 @@
class nsCSSDeclaration;
class nsCSSParser;
class nsICSSLoader;
class nsIURI;
class nsIPrincipal;
class nsIDocument;
namespace mozilla {
namespace css {
class Loader;
}
}
class CSS2PropertiesTearoff : public nsIDOMNSCSS2Properties
{
public:
@ -114,7 +119,7 @@ protected:
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader) = 0;
mozilla::css::Loader** aCSSLoader) = 0;
nsresult ParsePropertyValue(const nsCSSProperty aPropID,
const nsAString& aPropValue);

View file

@ -1,291 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* loading of CSS style sheets using the network APIs */
#ifndef nsICSSLoader_h___
#define nsICSSLoader_h___
#include "nsISupports.h"
#include "nsSubstring.h"
#include "nsCompatibility.h"
class nsIAtom;
class nsIURI;
class nsCSSParser;
class nsICSSStyleSheet;
class nsPresContext;
class nsIContent;
class nsIDocument;
class nsIUnicharInputStream;
class nsICSSLoaderObserver;
class nsMediaList;
class nsICSSImportRule;
class nsIPrincipal;
// IID for the nsICSSLoader interface
// 4e12812e-490c-4cec-b0f4-75c8b79779ba
#define NS_ICSS_LOADER_IID \
{ 0x4e12812e, 0x490c, 0x4cec, \
{ 0xb0, 0xf4, 0x75, 0xc8, 0xb7, 0x97, 0x79, 0xba } }
typedef void (*nsCSSLoaderCallbackFunc)(nsICSSStyleSheet* aSheet, void *aData, PRBool aDidNotify);
class nsICSSLoader : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSS_LOADER_IID)
NS_IMETHOD Init(nsIDocument* aDocument) = 0;
NS_IMETHOD DropDocumentReference(void) = 0; // notification that doc is going away
NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode) = 0;
NS_IMETHOD_(nsCompatibility) GetCompatibilityMode() = 0;
NS_IMETHOD SetPreferredSheet(const nsAString& aTitle) = 0;
NS_IMETHOD GetPreferredSheet(nsAString& aTitle) = 0;
// XXXbz sort out what the deal is with events! When should they fire?
/**
* Load an inline style sheet. If a successful result is returned and
* *aCompleted is false, then aObserver is guaranteed to be notified
* asynchronously once the sheet is marked complete. If an error is
* returned, or if *aCompleted is true, aObserver will not be notified. In
* addition to parsing the sheet, this method will insert it into the
* stylesheet list of this CSSLoader's document.
*
* @param aElement the element linking to the stylesheet. This must not be
* null and must implement nsIStyleSheetLinkingElement.
* @param aStream the character stream that holds the stylesheet data.
* @param aLineNumber the line number at which the stylesheet data started.
* @param aTitle the title of the sheet.
* @param aMedia the media string for the sheet.
* @param aObserver the observer to notify when the load completes.
* May be null.
* @param [out] aCompleted whether parsing of the sheet completed.
* @param [out] aIsAlternate whether the stylesheet ended up being an
* alternate sheet.
*/
NS_IMETHOD LoadInlineStyle(nsIContent* aElement,
nsIUnicharInputStream* aStream,
PRUint32 aLineNumber,
const nsSubstring& aTitle,
const nsSubstring& aMedia,
nsICSSLoaderObserver* aObserver,
PRBool* aCompleted,
PRBool* aIsAlternate) = 0;
/**
* Load a linked (document) stylesheet. If a successful result is returned,
* aObserver is guaranteed to be notified asynchronously once the sheet is
* loaded and marked complete. If an error is returned, aObserver will not
* be notified. In addition to loading the sheet, this method will insert it
* into the stylesheet list of this CSSLoader's document.
*
* @param aElement the element linking to the the stylesheet. May be null.
* @param aURL the URL of the sheet.
* @param aTitle the title of the sheet.
* @param aMedia the media string for the sheet.
* @param aHasAlternateRel whether the rel for this link included
* "alternate".
* @param aObserver the observer to notify when the load completes.
* May be null.
* @param [out] aIsAlternate whether the stylesheet actually ended up beinga
* an alternate sheet. Note that this need not match
* aHasAlternateRel.
*/
NS_IMETHOD LoadStyleLink(nsIContent* aElement,
nsIURI* aURL,
const nsSubstring& aTitle,
const nsSubstring& aMedia,
PRBool aHasAlternateRel,
nsICSSLoaderObserver* aObserver,
PRBool* aIsAlternate) = 0;
/**
* Load a child (@import-ed) style sheet. In addition to loading the sheet,
* this method will insert it into the child sheet list of aParentSheet. If
* there is no sheet currently being parsed and the child sheet is not
* complete when this method returns, then when the child sheet becomes
* complete aParentSheet will be QIed to nsICSSLoaderObserver and
* asynchronously notified, just like for LoadStyleLink. Note that if the
* child sheet is already complete when this method returns, no
* nsICSSLoaderObserver notification will be sent.
*
* @param aParentSheet the parent of this child sheet
* @param aURL the URL of the child sheet
* @param aMedia the already-parsed media list for the child sheet
* @param aRule the @import rule importing this child. This is used to
* properly order the child sheet list of aParentSheet.
*/
NS_IMETHOD LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsIURI* aURL,
nsMediaList* aMedia,
nsICSSImportRule* aRule) = 0;
/**
* Synchronously load and return the stylesheet at aURL. Any child sheets
* will also be loaded synchronously. Note that synchronous loads over some
* protocols may involve spinning up a new event loop, so use of this method
* does NOT guarantee not receiving any events before the sheet loads. This
* method can be used to load sheets not associated with a document.
*
* @param aURL the URL of the sheet to load
* @param aEnableUnsafeRules whether unsafe rules are enabled for this
* sheet load
* Unsafe rules are rules that can violate key Gecko invariants if misused.
* In particular, most anonymous box pseudoelements must be very carefully
* styled or we will have severe problems. Therefore unsafe rules should
* never be enabled for stylesheets controlled by untrusted sites; preferably
* unsafe rules should only be enabled for agent sheets.
* @param aUseSystemPrincipal if true, give the resulting sheet the system
* principal no matter where it's being loaded from.
* @param [out] aSheet the loaded, complete sheet.
*
* NOTE: At the moment, this method assumes the sheet will be UTF-8, but
* ideally it would allow arbitrary encodings. Callers should NOT depend on
* non-UTF8 sheets being treated as UTF-8 by this method.
*
* NOTE: A successful return from this method doesn't indicate anything about
* whether the data could be parsed as CSS and doesn't indicate anything
* about the status of child sheets of the returned sheet.
*/
NS_IMETHOD LoadSheetSync(nsIURI* aURL, PRBool aEnableUnsafeRules,
PRBool aUseSystemPrincipal,
nsICSSStyleSheet** aSheet) = 0;
/**
* As above, but aUseSystemPrincipal and aEnableUnsafeRules are assumed false.
*/
nsresult LoadSheetSync(nsIURI* aURL, nsICSSStyleSheet** aSheet) {
return LoadSheetSync(aURL, PR_FALSE, PR_FALSE, aSheet);
}
/**
* Asynchronously load the stylesheet at aURL. If a successful result is
* returned, aObserver is guaranteed to be notified asynchronously once the
* sheet is loaded and marked complete. This method can be used to load
* sheets not associated with a document.
*
* @param aURL the URL of the sheet to load
* @param aOriginPrincipal the principal to use for security checks. This
* can be null to indicate that these checks should
* be skipped.
* @param aCharset the encoding to use for converting the sheet data
* from bytes to Unicode. May be empty to indicate that the
* charset of the CSSLoader's document should be used. This
* is only used if neither the network transport nor the
* sheet itself indicate an encoding.
* @param aObserver the observer to notify when the load completes.
* Must not be null.
* @param [out] aSheet the sheet to load. Note that the sheet may well
* not be loaded by the time this method returns.
*/
NS_IMETHOD LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver,
nsICSSStyleSheet** aSheet) = 0;
/**
* Same as above, to be used when the caller doesn't care about the
* not-yet-loaded sheet.
*/
NS_IMETHOD LoadSheet(nsIURI* aURL,
nsIPrincipal* aOriginPrincipal,
const nsCString& aCharset,
nsICSSLoaderObserver* aObserver) = 0;
/**
* Stop loading all sheets. All nsICSSLoaderObservers involved will be
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
*/
NS_IMETHOD Stop(void) = 0;
/**
* Stop loading one sheet. The nsICSSLoaderObserver involved will be
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
*/
NS_IMETHOD StopLoadingSheet(nsIURI* aURL) = 0;
/**
* Whether the loader is enabled or not.
* When disabled, processing of new styles is disabled and an attempt
* to do so will fail with a return code of
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
* currently loading styles or already processed styles.
*/
NS_IMETHOD GetEnabled(PRBool *aEnabled) = 0;
NS_IMETHOD SetEnabled(PRBool aEnabled) = 0;
/**
* Return true if this nsICSSLoader has pending loads (ones that would send
* notifications to an nsICSSLoaderObserver attached to this nsICSSLoader).
* If called from inside nsICSSLoaderObserver::StyleSheetLoaded, this will
* return PR_FALSE if and only if that is the last StyleSheetLoaded
* notification the CSSLoader knows it's going to send. In other words, if
* two sheets load at once (via load coalescing, e.g.), HasPendingLoads()
* will return PR_TRUE during notification for the first one, and PR_FALSE
* during notification for the second one.
*/
NS_IMETHOD_(PRBool) HasPendingLoads() = 0;
/**
* Add an observer to this nsICSSLoader. The observer will be notified for
* all loads that would have notified their own observers (even if those
* loads don't have observers attached to them). Load-specific observers
* will be notified before generic observers. The CSSLoader holds a
* reference to the observer.
*
* aObserver must not be null.
*/
NS_IMETHOD AddObserver(nsICSSLoaderObserver* aObserver) = 0;
/**
* Remove an observer added via AddObserver.
*/
NS_IMETHOD_(void) RemoveObserver(nsICSSLoaderObserver* aObserver) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSLoader, NS_ICSS_LOADER_IID)
nsresult
NS_NewCSSLoader(nsIDocument* aDocument, nsICSSLoader** aLoader);
nsresult
NS_NewCSSLoader(nsICSSLoader** aLoader);
#endif /* nsICSSLoader_h___ */

View file

@ -38,7 +38,7 @@
#include "nsLayoutStylesheetCache.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsIFile.h"
#include "nsLayoutCID.h"
#include "nsNetUtil.h"
@ -254,7 +254,8 @@ nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet
}
void
nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSheet,
nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI,
nsCOMPtr<nsICSSStyleSheet> &aSheet,
PRBool aEnableUnsafeRules)
{
if (!aURI) {
@ -262,8 +263,10 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSh
return;
}
if (!gCSSLoader)
NS_NewCSSLoader(&gCSSLoader);
if (!gCSSLoader) {
gCSSLoader = new mozilla::css::Loader();
NS_IF_ADDREF(gCSSLoader);
}
if (gCSSLoader) {
gCSSLoader->LoadSheetSync(aURI, aEnableUnsafeRules, PR_TRUE,
@ -274,5 +277,5 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSh
nsLayoutStylesheetCache*
nsLayoutStylesheetCache::gStyleCache = nsnull;
nsICSSLoader*
mozilla::css::Loader*
nsLayoutStylesheetCache::gCSSLoader = nsnull;

View file

@ -43,7 +43,12 @@
#include "nsIObserver.h"
class nsIFile;
class nsICSSLoader;
namespace mozilla {
namespace css {
class Loader;
}
}
class nsLayoutStylesheetCache
: public nsIObserver
@ -71,7 +76,7 @@ private:
PRBool aEnableUnsafeRules);
static nsLayoutStylesheetCache* gStyleCache;
static nsICSSLoader* gCSSLoader;
static mozilla::css::Loader* gCSSLoader;
nsCOMPtr<nsICSSStyleSheet> mScrollbarsSheet;
nsCOMPtr<nsICSSStyleSheet> mFormsSheet;
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;

View file

@ -48,7 +48,6 @@
#include "nsStyleSet.h"
#include "nsComputedDOMStyle.h"
#include "nsCSSParser.h"
#include "nsICSSLoader.h"
#include "nsCSSDataBlock.h"
#include "nsCSSDeclaration.h"
#include "nsCSSStruct.h"

View file

@ -51,11 +51,9 @@
#include "nsNetUtil.h"
#include "nsContentCID.h"
#include "nsICSSLoader.h"
#include "nsCSSLoader.h"
#include "nsICSSStyleSheet.h"
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
static already_AddRefed<nsIURI>
FileToURI(const char *aFilename, nsresult *aRv = 0)
{
@ -74,7 +72,7 @@ FileToURI(const char *aFilename, nsresult *aRv = 0)
static int
ParseCSSFile(nsIURI *aSheetURI)
{
nsCOMPtr<nsICSSLoader> loader(do_CreateInstance(kCSSLoaderCID));
nsRefPtr<mozilla::css::Loader> = new mozilla::css::Loader();
nsCOMPtr<nsICSSStyleSheet> sheet;
loader->LoadSheetSync(aSheetURI, getter_AddRefs(sheet));
NS_ASSERTION(sheet, "sheet load failed");