2003-02-22 22:36:32 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2004-05-13 22:34:18 +04:00
|
|
|
* vim: ft=cpp tw=78 sw=2 et ts=2
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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.
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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.
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2004-04-18 17:54:27 +04:00
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>
|
2004-04-18 01:52:36 +04:00
|
|
|
*
|
|
|
|
* 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 *****
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
|
|
|
|
* described herein are Copyright (c) International Business Machines Corporation, 2000.
|
|
|
|
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
|
|
|
*/
|
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* loading of CSS style sheets using the network APIs */
|
|
|
|
|
2003-02-22 22:36:32 +03:00
|
|
|
#ifndef nsCSSLoader_h__
|
|
|
|
#define nsCSSLoader_h__
|
|
|
|
|
|
|
|
class CSSLoaderImpl;
|
2005-04-14 19:27:16 +04:00
|
|
|
class nsIURI;
|
|
|
|
class nsICSSStyleSheet;
|
|
|
|
class nsIStyleSheetLinkingElement;
|
|
|
|
class nsICSSLoaderObserver;
|
|
|
|
class nsICSSParser;
|
|
|
|
class nsICSSImportRule;
|
|
|
|
class nsMediaList;
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
#include "nsICSSLoader.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsIRunnable.h"
|
2003-02-22 22:36:32 +03:00
|
|
|
#include "nsIUnicharStreamLoader.h"
|
2005-04-14 19:27:16 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsString.h"
|
2003-07-27 19:20:11 +04:00
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2007-02-05 21:09:26 +03:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsTArray.h"
|
2007-05-01 23:26:15 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OVERALL ARCHITECTURE
|
|
|
|
*
|
|
|
|
* The CSS Loader gets requests to load various sorts of style sheets:
|
|
|
|
* inline style from <style> elements, linked style, @import-ed child
|
2005-09-12 22:41:15 +04:00
|
|
|
* sheets, non-document sheets. The loader handles the following tasks:
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
2003-04-05 03:57:06 +04:00
|
|
|
* 1) Checking whether the load is allowed: CheckLoadAllowed()
|
|
|
|
* 2) Creation of the actual style sheet objects: CreateSheet()
|
|
|
|
* 3) setting of the right media, title, enabled state, etc on the
|
2003-02-22 22:36:32 +03:00
|
|
|
* sheet: PrepareSheet()
|
2003-04-05 03:57:06 +04:00
|
|
|
* 4) Insertion of the sheet in the proper cascade order:
|
2003-02-22 22:36:32 +03:00
|
|
|
* InsertSheetInDoc() and InsertChildSheet()
|
2003-04-05 03:57:06 +04:00
|
|
|
* 5) Load of the sheet: LoadSheet()
|
|
|
|
* 6) Parsing of the sheet: ParseSheet()
|
|
|
|
* 7) Cleanup: SheetComplete()
|
2003-02-22 22:36:32 +03:00
|
|
|
*
|
|
|
|
* The detailed documentation for these functions is found with the
|
|
|
|
* function implementations.
|
|
|
|
*
|
2003-07-27 19:20:11 +04:00
|
|
|
* The following helper object is used:
|
|
|
|
* SheetLoadData -- a small class that is used to store all the
|
2003-02-22 22:36:32 +03:00
|
|
|
* information needed for the loading of a sheet;
|
|
|
|
* this class handles listening for the stream
|
|
|
|
* loader completion and also handles charset
|
|
|
|
* determination.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
* Data needed to properly load a stylesheet *
|
|
|
|
*********************************************/
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
class SheetLoadData : public nsIRunnable,
|
2005-09-12 22:41:15 +04:00
|
|
|
public nsIUnicharStreamLoaderObserver
|
2003-02-22 22:36:32 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~SheetLoadData(void);
|
|
|
|
// Data for loading a sheet linked from a document
|
|
|
|
SheetLoadData(CSSLoaderImpl* aLoader,
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& aTitle,
|
2003-02-22 22:36:32 +03:00
|
|
|
nsIURI* aURI,
|
|
|
|
nsICSSStyleSheet* aSheet,
|
|
|
|
nsIStyleSheetLinkingElement* aOwningElement,
|
2005-09-12 22:41:15 +04:00
|
|
|
PRBool aIsAlternate,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
// Data for loading a sheet linked from an @import rule
|
|
|
|
SheetLoadData(CSSLoaderImpl* aLoader,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsICSSStyleSheet* aSheet,
|
|
|
|
SheetLoadData* aParentData,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
// Data for loading a non-document sheet
|
2003-02-22 22:36:32 +03:00
|
|
|
SheetLoadData(CSSLoaderImpl* aLoader,
|
|
|
|
nsIURI* aURI,
|
|
|
|
nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aSyncLoad,
|
2006-06-15 07:20:19 +04:00
|
|
|
PRBool aAllowUnsafeRules,
|
2007-03-23 02:01:14 +03:00
|
|
|
nsICSSLoaderObserver* aObserver);
|
2004-08-18 06:32:25 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsIURI> GetReferrerURI();
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2003-02-22 22:36:32 +03:00
|
|
|
NS_DECL_NSIUNICHARSTREAMLOADEROBSERVER
|
|
|
|
|
|
|
|
// Hold a ref to the CSSLoader so we can call back to it to let it
|
|
|
|
// know the load finished
|
|
|
|
CSSLoaderImpl* mLoader; // strong ref
|
|
|
|
|
|
|
|
// Title needed to pull datas out of the pending datas table when
|
|
|
|
// the preferred title is changed
|
|
|
|
nsString mTitle;
|
|
|
|
|
2004-01-13 22:01:26 +03:00
|
|
|
// Charset we decided to use for the sheet
|
|
|
|
nsCString mCharset;
|
|
|
|
|
2003-02-22 22:36:32 +03:00
|
|
|
// URI we're loading. Null for inline sheets
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
|
2004-09-09 21:32:35 +04:00
|
|
|
// Should be 1 for non-inline sheets.
|
|
|
|
PRUint32 mLineNumber;
|
|
|
|
|
2003-02-22 22:36:32 +03:00
|
|
|
// The sheet we're loading data for
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> mSheet;
|
|
|
|
|
|
|
|
// Linked list of datas for the same URI as us
|
|
|
|
SheetLoadData* mNext; // strong ref
|
|
|
|
|
|
|
|
// Load data for the sheet that @import-ed us if we were @import-ed
|
|
|
|
// during the parse
|
|
|
|
SheetLoadData* mParentData; // strong ref
|
|
|
|
|
|
|
|
// Number of sheets we @import-ed that are still loading
|
|
|
|
PRUint32 mPendingChildren;
|
|
|
|
|
|
|
|
// mSyncLoad is true when the load needs to be synchronous -- right
|
2005-09-12 22:41:15 +04:00
|
|
|
// now only for LoadSheetSync and children of sync loads.
|
|
|
|
PRPackedBool mSyncLoad : 1;
|
2003-02-22 22:36:32 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
// mIsNonDocumentSheet is true if the load was triggered by LoadSheetSync or
|
|
|
|
// LoadSheet or an @import from such a sheet. Non-document sheet loads can
|
|
|
|
// proceed even if we have no document.
|
|
|
|
PRPackedBool mIsNonDocumentSheet : 1;
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
// mIsLoading is true from the moment we are placed in the loader's
|
|
|
|
// "loading datas" table (right after the async channel is opened)
|
|
|
|
// to the moment we are removed from said table (due to the load
|
|
|
|
// completing or being cancelled).
|
2005-09-12 22:41:15 +04:00
|
|
|
PRPackedBool mIsLoading : 1;
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
// mIsCancelled is set to true when a sheet load is stopped by
|
|
|
|
// Stop() or StopLoadingSheet(). SheetLoadData::OnStreamComplete()
|
|
|
|
// checks this to avoid parsing sheets that have been cancelled and
|
|
|
|
// such.
|
2005-09-12 22:41:15 +04:00
|
|
|
PRPackedBool mIsCancelled : 1;
|
|
|
|
|
|
|
|
// mMustNotify is true if the load data is being loaded async and
|
|
|
|
// the original function call that started the load has returned.
|
|
|
|
// XXXbz sort our relationship with load/error events!
|
|
|
|
PRPackedBool mMustNotify : 1;
|
|
|
|
|
|
|
|
// mWasAlternate is true if the sheet was an alternate when the load data was
|
|
|
|
// created.
|
|
|
|
PRPackedBool mWasAlternate : 1;
|
2003-02-22 22:36:32 +03:00
|
|
|
|
2006-06-15 07:20:19 +04:00
|
|
|
// mAllowUnsafeRules is true if we should allow unsafe rules to be parsed
|
|
|
|
// in the loaded sheet.
|
|
|
|
PRPackedBool mAllowUnsafeRules : 1;
|
|
|
|
|
2003-02-22 22:36:32 +03:00
|
|
|
// This is the element that imported the sheet. Needed to get the
|
|
|
|
// charset set on it.
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> mOwningElement;
|
|
|
|
|
|
|
|
// The observer that wishes to be notified of load completion
|
|
|
|
nsCOMPtr<nsICSSLoaderObserver> mObserver;
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
// The principal that identifies who started loading us.
|
|
|
|
nsCOMPtr<nsIPrincipal> mLoaderPrincipal;
|
2003-02-22 22:36:32 +03:00
|
|
|
};
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
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 NS_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;
|
|
|
|
};
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* 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
|
|
|
|
|
|
|
|
static void Shutdown(); // called at app shutdown
|
|
|
|
|
|
|
|
// nsICSSLoader methods
|
|
|
|
NS_IMETHOD Init(nsIDocument* aDocument);
|
|
|
|
NS_IMETHOD DropDocumentReference(void);
|
|
|
|
|
|
|
|
NS_IMETHOD SetCaseSensitive(PRBool aCaseSensitive);
|
|
|
|
NS_IMETHOD SetCompatibilityMode(nsCompatibility aCompatMode);
|
|
|
|
NS_IMETHOD SetPreferredSheet(const nsAString& aTitle);
|
2004-08-05 15:38:42 +04:00
|
|
|
NS_IMETHOD GetPreferredSheet(nsAString& aTitle);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
NS_IMETHOD GetParserFor(nsICSSStyleSheet* aSheet,
|
|
|
|
nsICSSParser** aParser);
|
|
|
|
NS_IMETHOD RecycleParser(nsICSSParser* aParser);
|
|
|
|
|
|
|
|
NS_IMETHOD LoadInlineStyle(nsIContent* aElement,
|
2004-09-09 21:32:35 +04:00
|
|
|
nsIUnicharInputStream* aStream,
|
|
|
|
PRUint32 aLineNumber,
|
2005-09-12 22:41:15 +04:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aMedia,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool* aCompleted,
|
|
|
|
PRBool* aIsAlternate);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
NS_IMETHOD LoadStyleLink(nsIContent* aElement,
|
|
|
|
nsIURI* aURL,
|
2007-04-21 02:59:18 +04:00
|
|
|
const nsSubstring& aTitle,
|
2005-09-12 22:41:15 +04:00
|
|
|
const nsSubstring& aMedia,
|
|
|
|
PRBool aHasAlternateRel,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool* aIsAlternate);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
NS_IMETHOD LoadChildSheet(nsICSSStyleSheet* aParentSheet,
|
|
|
|
nsIURI* aURL,
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList* aMedia,
|
2003-02-22 22:36:32 +03:00
|
|
|
nsICSSImportRule* aRule);
|
|
|
|
|
2006-06-15 07:20:19 +04:00
|
|
|
NS_IMETHOD LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules,
|
|
|
|
nsICSSStyleSheet** aSheet);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_IMETHOD LoadSheet(nsIURI* aURL, nsICSSLoaderObserver* aObserver,
|
2006-11-12 01:27:00 +03:00
|
|
|
nsICSSStyleSheet** aSheet);
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_IMETHOD LoadSheet(nsIURI* aURL, nsICSSLoaderObserver* aObserver);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// local helper methods (some are public for access from statics)
|
2005-09-12 22:41:15 +04:00
|
|
|
|
|
|
|
// IsAlternate can change our currently selected style set if none
|
|
|
|
// is selected and aHasAlternateRel is false.
|
|
|
|
PRBool IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
private:
|
2007-03-23 02:01:14 +03:00
|
|
|
nsresult CheckLoadAllowed(nsIURI* aSourceURI,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsIPrincipal* aSourcePrincipal,
|
2003-04-05 03:57:06 +04:00
|
|
|
nsIURI* aTargetURI,
|
2004-07-27 21:15:53 +04:00
|
|
|
nsISupports* aContext);
|
2004-05-13 22:34:18 +04:00
|
|
|
|
2003-07-03 06:45:34 +04:00
|
|
|
|
|
|
|
// For inline style, the aURI param is null, but the aLinkingContent
|
2007-05-01 23:26:15 +04:00
|
|
|
// must be non-null then. The loader principal must never be null
|
|
|
|
// if aURI is not null.
|
2003-02-22 22:36:32 +03:00
|
|
|
nsresult CreateSheet(nsIURI* aURI,
|
2003-07-03 06:45:34 +04:00
|
|
|
nsIContent* aLinkingContent,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsIPrincipal* aLoaderPrincipal,
|
2003-02-22 22:36:32 +03:00
|
|
|
PRBool aSyncLoad,
|
|
|
|
StyleSheetState& aSheetState,
|
|
|
|
nsICSSStyleSheet** aSheet);
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
// Pass in either a media string or the nsMediaList from the
|
2004-01-10 05:27:41 +03:00
|
|
|
// CSSParser. Don't pass both.
|
2005-09-12 22:41:15 +04:00
|
|
|
// 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)
|
2003-02-22 22:36:32 +03:00
|
|
|
nsresult PrepareSheet(nsICSSStyleSheet* aSheet,
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aMediaString,
|
2005-09-12 22:41:15 +04:00
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHasAlternateRel = PR_FALSE,
|
|
|
|
PRBool *aIsAlternate = nsnull);
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
nsresult InsertSheetInDoc(nsICSSStyleSheet* aSheet,
|
2003-07-03 06:45:34 +04:00
|
|
|
nsIContent* aLinkingContent,
|
2003-02-22 22:36:32 +03:00
|
|
|
nsIDocument* aDocument);
|
|
|
|
|
|
|
|
nsresult InsertChildSheet(nsICSSStyleSheet* aSheet,
|
|
|
|
nsICSSStyleSheet* aParentSheet,
|
|
|
|
nsICSSImportRule* aParentRule);
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
|
2006-06-15 07:20:19 +04:00
|
|
|
PRBool aAllowUnsafeRules,
|
2005-09-12 22:41:15 +04:00
|
|
|
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);
|
2003-02-22 22:36:32 +03:00
|
|
|
public:
|
2005-09-12 22:41:15 +04:00
|
|
|
// 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.
|
2003-02-22 22:36:32 +03:00
|
|
|
nsresult LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState);
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
protected:
|
2003-02-22 22:36:32 +03:00
|
|
|
friend class SheetLoadData;
|
|
|
|
|
|
|
|
// Protected functions and members are ones that SheetLoadData needs
|
2007-04-21 02:59:18 +04:00
|
|
|
// 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
|
2003-02-22 22:36:32 +03:00
|
|
|
nsresult ParseSheet(nsIUnicharInputStream* aStream,
|
|
|
|
SheetLoadData* aLoadData,
|
|
|
|
PRBool& aCompleted);
|
|
|
|
|
2007-05-31 05:42:48 +04:00
|
|
|
public:
|
2007-04-21 02:59:18 +04:00
|
|
|
// The load of the sheet in aLoadData is done, one way or another. Do final
|
|
|
|
// cleanup, including releasing aLoadData.
|
2007-03-23 02:01:14 +03:00
|
|
|
void SheetComplete(SheetLoadData* aLoadData, nsresult aStatus);
|
2007-04-21 02:59:18 +04:00
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
private:
|
|
|
|
typedef nsTArray<nsRefPtr<SheetLoadData> > LoadDataArray;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2003-02-22 22:36:32 +03:00
|
|
|
static nsCOMArray<nsICSSParser>* gParsers; // array of idle CSS parsers
|
|
|
|
|
|
|
|
// the load data needs access to the document...
|
|
|
|
nsIDocument* mDocument; // the document we live for
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRPackedBool mSyncCallback;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRPackedBool mCaseSensitive; // is document CSS case sensitive
|
|
|
|
PRPackedBool mEnabled; // is enabled to load new styles
|
|
|
|
nsCompatibility mCompatMode;
|
|
|
|
nsString mPreferredSheet; // title of preferred sheet
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
nsInterfaceHashtable<nsURIAndPrincipalHashKey,
|
|
|
|
nsICSSStyleSheet> mCompleteSheets;
|
|
|
|
nsDataHashtable<nsURIAndPrincipalHashKey,
|
|
|
|
SheetLoadData*> mLoadingDatas; // weak refs
|
|
|
|
nsDataHashtable<nsURIAndPrincipalHashKey,
|
|
|
|
SheetLoadData*> mPendingDatas; // weak refs
|
2003-02-22 22:36:32 +03:00
|
|
|
|
|
|
|
// We're not likely to have many levels of @import... But likely to have
|
|
|
|
// some. Allocate some storage, what the hell.
|
|
|
|
nsAutoVoidArray mParsingDatas;
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
// The array of posted stylesheet loaded events (SheetLoadDatas) we have.
|
2007-02-05 21:09:26 +03:00
|
|
|
// Note that these are rare.
|
2007-04-21 02:59:18 +04:00
|
|
|
LoadDataArray mPostedEvents;
|
2003-02-22 22:36:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsCSSLoader_h__
|