1999-05-19 03:15:10 +04: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
|
1999-05-19 03:15:10 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-05-19 03:15:10 +04: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.
|
1999-05-19 03:15:10 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +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.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2002-12-03 08:48:14 +03:00
|
|
|
* Contributor(s):
|
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 *****
|
2002-12-03 08:48:14 +03:00
|
|
|
*
|
2010-03-02 23:59: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
|
2000-05-03 03:07:11 +04:00
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
1999-05-19 03:15:10 +04:00
|
|
|
*/
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* loading of CSS style sheets using the network APIs */
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2010-03-02 23:59:32 +03:00
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsIUnicharStreamLoader.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsString.h"
|
1999-05-27 03:52:37 +04:00
|
|
|
#include "nsIContent.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
#include "nsIDOMNode.h"
|
2003-04-05 03:57:06 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
#include "nsIDocument.h"
|
2007-01-11 22:32:31 +03:00
|
|
|
#include "nsIDOMNSDocumentStyle.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
#include "nsIUnicharInputStream.h"
|
2001-12-04 02:03:18 +03:00
|
|
|
#include "nsIConverterInputStream.h"
|
2000-04-23 06:01:40 +04:00
|
|
|
#include "nsICharsetAlias.h"
|
2002-02-20 01:49:12 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
#include "nsHashtable.h"
|
2005-04-14 19:27:16 +04:00
|
|
|
#include "nsIURI.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
2003-10-30 06:01:25 +03:00
|
|
|
#include "nsContentUtils.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
#include "nsCRT.h"
|
2000-05-27 03:28:40 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2003-04-05 03:57:06 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-08-17 06:03:34 +04:00
|
|
|
#include "nsITimelineService.h"
|
2001-10-25 04:34:20 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2002-07-02 07:11:57 +04:00
|
|
|
#include "nsIScriptError.h"
|
2002-11-07 01:29:17 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2002-12-03 08:48:14 +03:00
|
|
|
#include "nsIAtom.h"
|
2003-06-16 15:17:18 +04:00
|
|
|
#include "nsIDOM3Node.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2005-04-14 19:27:16 +04:00
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
|
|
|
#include "nsICSSLoaderObserver.h"
|
2010-03-02 23:59:32 +03:00
|
|
|
#include "nsCSSParser.h"
|
2005-04-14 19:27:16 +04:00
|
|
|
#include "nsICSSImportRule.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2009-01-14 10:13:48 +03:00
|
|
|
#include "nsDocShellCID.h"
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2007-03-12 08:53:33 +03:00
|
|
|
#include "nsXULPrototypeCache.h"
|
2000-07-28 13:36:51 +04:00
|
|
|
#endif
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
#include "nsIMediaList.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIDOMStyleSheet.h"
|
2002-12-03 08:48:14 +03:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsIDOMCSSImportRule.h"
|
2006-03-22 21:36:36 +03:00
|
|
|
#include "nsContentErrors.h"
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2010-04-24 02:05:32 +04:00
|
|
|
#include "nsIChannelPolicy.h"
|
|
|
|
#include "nsIContentSecurityPolicy.h"
|
|
|
|
|
2010-05-20 03:22:19 +04:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2010-03-02 23:59: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
|
|
|
|
* sheets, non-document sheets. The loader handles the following tasks:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* sheet: PrepareSheet()
|
|
|
|
* 4) Insertion of the sheet in the proper cascade order:
|
|
|
|
* InsertSheetInDoc() and InsertChildSheet()
|
|
|
|
* 5) Load of the sheet: LoadSheet()
|
|
|
|
* 6) Parsing of the sheet: ParseSheet()
|
|
|
|
* 7) Cleanup: SheetComplete()
|
|
|
|
*
|
|
|
|
* The detailed documentation for these functions is found with the
|
|
|
|
* function implementations.
|
|
|
|
*
|
|
|
|
* The following helper object is used:
|
|
|
|
* SheetLoadData -- a small class that is used to store all the
|
|
|
|
* information needed for the loading of a sheet;
|
|
|
|
* this class handles listening for the stream
|
|
|
|
* loader completion and also handles charset
|
|
|
|
* determination.
|
|
|
|
*/
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
/*********************************************
|
|
|
|
* Data needed to properly load a stylesheet *
|
|
|
|
*********************************************/
|
|
|
|
|
|
|
|
class SheetLoadData : public nsIRunnable,
|
2010-03-03 00:00:53 +03:00
|
|
|
public nsIUnicharStreamLoaderObserver
|
2010-03-02 23:59:32 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~SheetLoadData(void);
|
|
|
|
// Data for loading a sheet linked from a document
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData(Loader* aLoader,
|
|
|
|
const nsSubstring& aTitle,
|
|
|
|
nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIStyleSheetLinkingElement* aOwningElement,
|
|
|
|
PRBool aIsAlternate,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
// Data for loading a sheet linked from an @import rule
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData(Loader* aLoader,
|
|
|
|
nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData* aParentData,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
// Data for loading a non-document sheet
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData(Loader* aLoader,
|
|
|
|
nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
PRBool aSyncLoad,
|
|
|
|
PRBool aAllowUnsafeRules,
|
|
|
|
PRBool aUseSystemPrincipal,
|
|
|
|
const nsCString& aCharset,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
already_AddRefed<nsIURI> GetReferrerURI();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIUNICHARSTREAMLOADEROBSERVER
|
|
|
|
|
|
|
|
// Hold a ref to the CSSLoader so we can call back to it to let it
|
|
|
|
// know the load finished
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader* mLoader; // strong ref
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
// Title needed to pull datas out of the pending datas table when
|
|
|
|
// the preferred title is changed
|
|
|
|
nsString mTitle;
|
|
|
|
|
|
|
|
// Charset we decided to use for the sheet
|
|
|
|
nsCString mCharset;
|
|
|
|
|
|
|
|
// URI we're loading. Null for inline sheets
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
|
|
|
|
// Should be 1 for non-inline sheets.
|
|
|
|
PRUint32 mLineNumber;
|
|
|
|
|
|
|
|
// The sheet we're loading data for
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> mSheet;
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// now only for LoadSheetSync and children of sync loads.
|
|
|
|
PRPackedBool mSyncLoad : 1;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
PRPackedBool mIsLoading : 1;
|
|
|
|
|
|
|
|
// mIsCancelled is set to true when a sheet load is stopped by
|
2010-04-03 15:36:19 +04:00
|
|
|
// Stop() or StopLoadingSheet() (which was removed in Bug 556446).
|
|
|
|
// SheetLoadData::OnStreamComplete() checks this to avoid parsing
|
|
|
|
// sheets that have been cancelled and such.
|
2010-03-02 23:59:32 +03: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;
|
|
|
|
|
|
|
|
// mAllowUnsafeRules is true if we should allow unsafe rules to be parsed
|
|
|
|
// in the loaded sheet.
|
|
|
|
PRPackedBool mAllowUnsafeRules : 1;
|
|
|
|
|
|
|
|
// mUseSystemPrincipal is true if the system principal should be used for
|
|
|
|
// this sheet, no matter what the channel principal is. Only true for sync
|
|
|
|
// loads.
|
|
|
|
PRPackedBool mUseSystemPrincipal : 1;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// The principal that identifies who started loading us.
|
2010-03-03 00:00:53 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mLoaderPrincipal;
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
// The charset to use if the transport and sheet don't indicate one.
|
|
|
|
// May be empty. Must be empty if mOwningElement is non-null.
|
2010-03-03 00:00:53 +03:00
|
|
|
nsCString mCharsetHint;
|
2010-03-02 23:59:32 +03:00
|
|
|
};
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
// #define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#endif /* MOZ_LOGGING */
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static PRLogModuleInfo *gLoaderLog = PR_NewLogModule("nsCSSLoader");
|
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
|
|
|
#define LOG_FORCE(args) PR_LOG(gLoaderLog, PR_LOG_ALWAYS, args)
|
|
|
|
#define LOG_ERROR(args) PR_LOG(gLoaderLog, PR_LOG_ERROR, args)
|
|
|
|
#define LOG_WARN(args) PR_LOG(gLoaderLog, PR_LOG_WARNING, args)
|
|
|
|
#define LOG_DEBUG(args) PR_LOG(gLoaderLog, PR_LOG_DEBUG, args)
|
|
|
|
#define LOG(args) LOG_DEBUG(args)
|
|
|
|
|
|
|
|
#define LOG_FORCE_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_ALWAYS)
|
|
|
|
#define LOG_ERROR_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_ERROR)
|
|
|
|
#define LOG_WARN_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_WARNING)
|
|
|
|
#define LOG_DEBUG_ENABLED() PR_LOG_TEST(gLoaderLog, PR_LOG_DEBUG)
|
|
|
|
#define LOG_ENABLED() LOG_DEBUG_ENABLED()
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
#define LOG_URI(format, uri) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
NS_ASSERTION(uri, "Logging null uri"); \
|
|
|
|
if (LOG_ENABLED()) { \
|
|
|
|
nsCAutoString _logURISpec; \
|
|
|
|
uri->GetSpec(_logURISpec); \
|
|
|
|
LOG((format, _logURISpec.get())); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
#else // PR_LOGGING
|
|
|
|
#define LOG_URI(format, uri)
|
|
|
|
#endif // PR_LOGGING
|
2001-08-05 01:19:53 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// And some convenience strings...
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
static const char* const gStateStrings[] = {
|
|
|
|
"eSheetStateUnknown",
|
|
|
|
"eSheetNeedsParser",
|
|
|
|
"eSheetPending",
|
|
|
|
"eSheetLoading",
|
|
|
|
"eSheetComplete"
|
1999-05-19 03:15:10 +04:00
|
|
|
};
|
2002-12-03 08:48:14 +03:00
|
|
|
#endif
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/********************************
|
|
|
|
* SheetLoadData implementation *
|
|
|
|
********************************/
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(SheetLoadData, nsIUnicharStreamLoaderObserver, nsIRunnable)
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData::SheetLoadData(Loader* aLoader,
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& aTitle,
|
2002-12-03 08:48:14 +03:00
|
|
|
nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2002-12-03 08:48:14 +03:00
|
|
|
nsIStyleSheetLinkingElement* aOwningElement,
|
2005-09-12 22:41:15 +04:00
|
|
|
PRBool aIsAlternate,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal)
|
1999-05-19 03:15:10 +04:00
|
|
|
: mLoader(aLoader),
|
|
|
|
mTitle(aTitle),
|
2002-12-03 08:48:14 +03:00
|
|
|
mURI(aURI),
|
2004-09-09 21:32:35 +04:00
|
|
|
mLineNumber(1),
|
2002-12-03 08:48:14 +03:00
|
|
|
mSheet(aSheet),
|
1999-05-19 03:15:10 +04:00
|
|
|
mNext(nsnull),
|
|
|
|
mParentData(nsnull),
|
|
|
|
mPendingChildren(0),
|
1999-09-30 05:39:57 +04:00
|
|
|
mSyncLoad(PR_FALSE),
|
2005-09-12 22:41:15 +04:00
|
|
|
mIsNonDocumentSheet(PR_FALSE),
|
2002-12-03 08:48:14 +03:00
|
|
|
mIsLoading(PR_FALSE),
|
|
|
|
mIsCancelled(PR_FALSE),
|
2005-09-12 22:41:15 +04:00
|
|
|
mMustNotify(PR_FALSE),
|
|
|
|
mWasAlternate(aIsAlternate),
|
2006-06-15 07:20:19 +04:00
|
|
|
mAllowUnsafeRules(PR_FALSE),
|
2009-03-17 04:38:36 +03:00
|
|
|
mUseSystemPrincipal(PR_FALSE),
|
2002-12-03 08:48:14 +03:00
|
|
|
mOwningElement(aOwningElement),
|
2007-05-01 23:26:15 +04:00
|
|
|
mObserver(aObserver),
|
|
|
|
mLoaderPrincipal(aLoaderPrincipal)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(mLoader, "Must have a loader!");
|
1999-05-19 03:15:10 +04:00
|
|
|
NS_ADDREF(mLoader);
|
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData::SheetLoadData(Loader* aLoader,
|
2002-12-03 08:48:14 +03:00
|
|
|
nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2002-12-03 08:48:14 +03:00
|
|
|
SheetLoadData* aParentData,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal)
|
1999-05-19 03:15:10 +04:00
|
|
|
: mLoader(aLoader),
|
2002-12-03 08:48:14 +03:00
|
|
|
mURI(aURI),
|
2004-09-09 21:32:35 +04:00
|
|
|
mLineNumber(1),
|
2002-12-03 08:48:14 +03:00
|
|
|
mSheet(aSheet),
|
1999-05-19 03:15:10 +04:00
|
|
|
mNext(nsnull),
|
2002-12-03 08:48:14 +03:00
|
|
|
mParentData(aParentData),
|
1999-05-19 03:15:10 +04:00
|
|
|
mPendingChildren(0),
|
1999-09-30 05:39:57 +04:00
|
|
|
mSyncLoad(PR_FALSE),
|
2005-09-12 22:41:15 +04:00
|
|
|
mIsNonDocumentSheet(PR_FALSE),
|
2002-12-03 08:48:14 +03:00
|
|
|
mIsLoading(PR_FALSE),
|
|
|
|
mIsCancelled(PR_FALSE),
|
2005-09-12 22:41:15 +04:00
|
|
|
mMustNotify(PR_FALSE),
|
|
|
|
mWasAlternate(PR_FALSE),
|
2006-06-15 07:20:19 +04:00
|
|
|
mAllowUnsafeRules(PR_FALSE),
|
2009-03-17 04:38:36 +03:00
|
|
|
mUseSystemPrincipal(PR_FALSE),
|
2002-12-03 08:48:14 +03:00
|
|
|
mOwningElement(nsnull),
|
2007-05-01 23:26:15 +04:00
|
|
|
mObserver(aObserver),
|
|
|
|
mLoaderPrincipal(aLoaderPrincipal)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(mLoader, "Must have a loader!");
|
1999-05-19 03:15:10 +04:00
|
|
|
NS_ADDREF(mLoader);
|
2002-12-03 08:48:14 +03:00
|
|
|
if (mParentData) {
|
|
|
|
NS_ADDREF(mParentData);
|
|
|
|
mSyncLoad = mParentData->mSyncLoad;
|
2005-09-12 22:41:15 +04:00
|
|
|
mIsNonDocumentSheet = mParentData->mIsNonDocumentSheet;
|
2006-06-15 07:20:19 +04:00
|
|
|
mAllowUnsafeRules = mParentData->mAllowUnsafeRules;
|
2009-03-17 04:38:36 +03:00
|
|
|
mUseSystemPrincipal = mParentData->mUseSystemPrincipal;
|
2002-12-03 08:48:14 +03:00
|
|
|
++(mParentData->mPendingChildren);
|
|
|
|
}
|
2009-03-17 04:38:36 +03:00
|
|
|
|
|
|
|
NS_POSTCONDITION(!mUseSystemPrincipal || mSyncLoad,
|
|
|
|
"Shouldn't use system principal for async loads");
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData::SheetLoadData(Loader* aLoader,
|
2002-12-03 08:48:14 +03:00
|
|
|
nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2002-12-11 03:28:47 +03:00
|
|
|
PRBool aSyncLoad,
|
2006-06-15 07:20:19 +04:00
|
|
|
PRBool aAllowUnsafeRules,
|
2009-03-17 04:38:36 +03:00
|
|
|
PRBool aUseSystemPrincipal,
|
2009-04-10 18:29:08 +04:00
|
|
|
const nsCString& aCharset,
|
2007-07-11 23:44:27 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
nsIPrincipal* aLoaderPrincipal)
|
1999-05-27 03:52:37 +04:00
|
|
|
: mLoader(aLoader),
|
2002-12-03 08:48:14 +03:00
|
|
|
mURI(aURI),
|
2004-09-09 21:32:35 +04:00
|
|
|
mLineNumber(1),
|
2002-12-03 08:48:14 +03:00
|
|
|
mSheet(aSheet),
|
1999-05-27 03:52:37 +04:00
|
|
|
mNext(nsnull),
|
|
|
|
mParentData(nsnull),
|
|
|
|
mPendingChildren(0),
|
2002-12-11 03:28:47 +03:00
|
|
|
mSyncLoad(aSyncLoad),
|
2005-09-12 22:41:15 +04:00
|
|
|
mIsNonDocumentSheet(PR_TRUE),
|
2002-12-03 08:48:14 +03:00
|
|
|
mIsLoading(PR_FALSE),
|
|
|
|
mIsCancelled(PR_FALSE),
|
2005-09-12 22:41:15 +04:00
|
|
|
mMustNotify(PR_FALSE),
|
|
|
|
mWasAlternate(PR_FALSE),
|
2006-06-15 07:20:19 +04:00
|
|
|
mAllowUnsafeRules(aAllowUnsafeRules),
|
2009-03-17 04:38:36 +03:00
|
|
|
mUseSystemPrincipal(aUseSystemPrincipal),
|
2002-12-03 08:48:14 +03:00
|
|
|
mOwningElement(nsnull),
|
2007-05-01 23:26:15 +04:00
|
|
|
mObserver(aObserver),
|
2009-04-10 18:29:08 +04:00
|
|
|
mLoaderPrincipal(aLoaderPrincipal),
|
|
|
|
mCharsetHint(aCharset)
|
1999-05-27 03:52:37 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(mLoader, "Must have a loader!");
|
1999-05-27 03:52:37 +04:00
|
|
|
NS_ADDREF(mLoader);
|
2009-03-17 04:38:36 +03:00
|
|
|
|
|
|
|
NS_POSTCONDITION(!mUseSystemPrincipal || mSyncLoad,
|
|
|
|
"Shouldn't use system principal for async loads");
|
1999-05-27 03:52:37 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
SheetLoadData::~SheetLoadData()
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
|
|
|
NS_RELEASE(mLoader);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_IF_RELEASE(mParentData);
|
2000-05-17 22:29:30 +04:00
|
|
|
NS_IF_RELEASE(mNext);
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
SheetLoadData::Run()
|
|
|
|
{
|
|
|
|
mLoader->HandleLoadEvent(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/*************************
|
|
|
|
* Loader Implementation *
|
|
|
|
*************************/
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::Loader(void)
|
|
|
|
: mDocument(nsnull)
|
|
|
|
, mDatasToNotifyOn(0)
|
|
|
|
, mCompatMode(eCompatibility_FullStandards)
|
|
|
|
, mEnabled(PR_TRUE)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mSyncCallback(PR_FALSE)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader::Loader(nsIDocument* aDocument)
|
|
|
|
: mDocument(aDocument)
|
|
|
|
, mDatasToNotifyOn(0)
|
|
|
|
, mCompatMode(eCompatibility_FullStandards)
|
|
|
|
, mEnabled(PR_TRUE)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mSyncCallback(PR_FALSE)
|
|
|
|
#endif
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
// 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);
|
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::~Loader()
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2003-07-27 19:20:11 +04:00
|
|
|
NS_ASSERTION((!mLoadingDatas.IsInitialized()) || mLoadingDatas.Count() == 0,
|
2002-12-03 08:48:14 +03:00
|
|
|
"How did we get destroyed when there are loading data?");
|
2003-07-27 19:20:11 +04:00
|
|
|
NS_ASSERTION((!mPendingDatas.IsInitialized()) || mPendingDatas.Count() == 0,
|
2002-12-03 08:48:14 +03:00
|
|
|
"How did we get destroyed when there are pending data?");
|
2005-09-12 22:41:15 +04:00
|
|
|
// Note: no real need to revoke our stylesheet loaded events -- they
|
|
|
|
// hold strong references to us, so if we're going away that means
|
|
|
|
// they're all done.
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
NS_IMPL_ADDREF(Loader)
|
|
|
|
NS_IMPL_RELEASE(Loader)
|
2007-01-11 22:32:31 +03:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
void
|
|
|
|
Loader::DropDocumentReference(void)
|
1999-05-27 03:52:37 +04:00
|
|
|
{
|
|
|
|
mDocument = nsnull;
|
2002-12-03 08:48:14 +03:00
|
|
|
// Flush out pending datas just so we don't leak by accident. These
|
|
|
|
// loads should short-circuit through the mDocument check in
|
|
|
|
// LoadSheet and just end up in SheetComplete immediately
|
2007-05-31 05:42:48 +04:00
|
|
|
if (mPendingDatas.IsInitialized()) {
|
|
|
|
StartAlternateLoads();
|
|
|
|
}
|
2010-03-02 23:59:32 +03:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2010-03-03 00:00:53 +03:00
|
|
|
CollectNonAlternates(URIAndPrincipalHashKey *aKey,
|
2007-05-31 05:42:48 +04:00
|
|
|
SheetLoadData* &aData,
|
|
|
|
void* aClosure)
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aData, "Must have a data");
|
2007-05-31 05:42:48 +04:00
|
|
|
NS_PRECONDITION(aClosure, "Must have an array");
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
// Note that we don't want to affect what the selected style set is,
|
|
|
|
// so use PR_TRUE for aHasAlternateRel.
|
2007-05-31 05:42:48 +04:00
|
|
|
if (aData->mLoader->IsAlternate(aData->mTitle, PR_TRUE)) {
|
2003-07-27 19:20:11 +04:00
|
|
|
return PL_DHASH_NEXT;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
static_cast<Loader::LoadDataArray*>(aClosure)->AppendElement(aData);
|
2003-07-27 19:20:11 +04:00
|
|
|
return PL_DHASH_REMOVE;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::SetPreferredSheet(const nsAString& aTitle)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2007-01-11 22:32:31 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIDOMNSDocumentStyle> doc(do_QueryInterface(mDocument));
|
|
|
|
if (doc) {
|
|
|
|
nsAutoString currentPreferred;
|
|
|
|
doc->GetLastStyleSheetSet(currentPreferred);
|
|
|
|
if (DOMStringIsNull(currentPreferred)) {
|
|
|
|
doc->GetPreferredStyleSheetSet(currentPreferred);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(currentPreferred.Equals(aTitle),
|
|
|
|
"Unexpected argument to SetPreferredSheet");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-05-19 03:15:10 +04:00
|
|
|
mPreferredSheet = aTitle;
|
|
|
|
|
|
|
|
// start any pending alternates that aren't alternates anymore
|
2007-05-31 05:42:48 +04:00
|
|
|
if (mPendingDatas.IsInitialized()) {
|
|
|
|
LoadDataArray arr(mPendingDatas.Count());
|
|
|
|
mPendingDatas.Enumerate(CollectNonAlternates, &arr);
|
|
|
|
|
|
|
|
mDatasToNotifyOn += arr.Length();
|
|
|
|
for (PRUint32 i = 0; i < arr.Length(); ++i) {
|
|
|
|
--mDatasToNotifyOn;
|
|
|
|
LoadSheet(arr[i], eSheetNeedsParser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-19 03:15:10 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-12 06:36:20 +03:00
|
|
|
static const char kCharsetSym[] = "@charset \"";
|
2002-08-28 03:47:25 +04:00
|
|
|
|
|
|
|
static nsresult GetCharsetFromData(const unsigned char* aStyleSheetData,
|
|
|
|
PRUint32 aDataLength,
|
2003-06-11 22:16:03 +04:00
|
|
|
nsACString& aCharset)
|
2002-08-28 03:47:25 +04:00
|
|
|
{
|
|
|
|
aCharset.Truncate();
|
|
|
|
if (aDataLength <= sizeof(kCharsetSym) - 1)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
PRUint32 step = 1;
|
|
|
|
PRUint32 pos = 0;
|
2008-12-06 22:08:26 +03:00
|
|
|
PRBool bigEndian = PR_FALSE;
|
2003-09-25 09:57:28 +04:00
|
|
|
// Determine the encoding type. If we have a BOM, set aCharset to the
|
|
|
|
// charset listed for that BOM in http://www.w3.org/TR/REC-xml#sec-guessing;
|
|
|
|
// that way even if we don't have a valid @charset rule we can use the BOM to
|
|
|
|
// get a reasonable charset. If we do have an @charset rule, the string from
|
|
|
|
// that will override this fallback setting of aCharset.
|
2002-08-28 03:47:25 +04:00
|
|
|
if (*aStyleSheetData == 0x40 && *(aStyleSheetData+1) == 0x63 /* '@c' */ ) {
|
2003-09-25 09:57:28 +04:00
|
|
|
// 1-byte ASCII-based encoding (ISO-8859-*, UTF-8, etc), no BOM
|
2002-08-28 03:47:25 +04:00
|
|
|
step = 1;
|
|
|
|
pos = 0;
|
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
// Check for a 4-byte encoding BOM before checking for a 2-byte one,
|
|
|
|
// since the latter can be a proper subset of the former.
|
|
|
|
else if (aStyleSheetData[0] == 0x00 &&
|
|
|
|
aStyleSheetData[1] == 0x00 &&
|
|
|
|
aStyleSheetData[2] == 0xFF &&
|
|
|
|
aStyleSheetData[3] == 0xFE) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// 4-byte encoding BOM in 2143 order
|
2003-09-25 09:57:28 +04:00
|
|
|
NS_WARNING("Our unicode decoders aren't likely to deal with this one");
|
2002-08-28 03:47:25 +04:00
|
|
|
step = 4;
|
|
|
|
pos = 6;
|
2003-09-25 09:57:28 +04:00
|
|
|
aCharset = "UTF-32";
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
else if (aStyleSheetData[0] == 0xFE &&
|
|
|
|
aStyleSheetData[1] == 0xFF &&
|
|
|
|
aStyleSheetData[2] == 0x00 &&
|
|
|
|
aStyleSheetData[3] == 0x00) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// 4-byte encoding BOM in 3412 order
|
2003-09-25 09:57:28 +04:00
|
|
|
NS_WARNING("Our unicode decoders aren't likely to deal with this one");
|
2002-08-28 03:47:25 +04:00
|
|
|
step = 4;
|
|
|
|
pos = 5;
|
2003-09-25 09:57:28 +04:00
|
|
|
aCharset = "UTF-32";
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
2007-12-28 00:34:03 +03:00
|
|
|
else if (nsContentUtils::CheckForBOM(aStyleSheetData,
|
2008-12-06 22:08:26 +03:00
|
|
|
aDataLength, aCharset, &bigEndian)) {
|
2007-12-28 00:34:03 +03:00
|
|
|
if (aCharset.Equals("UTF-8")) {
|
|
|
|
step = 1;
|
|
|
|
pos = 3;
|
|
|
|
}
|
2008-12-06 22:08:26 +03:00
|
|
|
else if (aCharset.Equals("UTF-32")) {
|
2007-12-28 00:34:03 +03:00
|
|
|
step = 4;
|
2008-12-06 22:08:26 +03:00
|
|
|
pos = bigEndian ? 7 : 4;
|
2007-12-28 00:34:03 +03:00
|
|
|
}
|
2008-12-06 22:08:26 +03:00
|
|
|
else if (aCharset.Equals("UTF-16")) {
|
2007-12-28 00:34:03 +03:00
|
|
|
step = 2;
|
2008-12-06 22:08:26 +03:00
|
|
|
pos = bigEndian ? 3 : 2;
|
2007-12-28 00:34:03 +03:00
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
}
|
|
|
|
else if (aStyleSheetData[0] == 0x00 &&
|
|
|
|
aStyleSheetData[1] == 0x00 &&
|
|
|
|
aStyleSheetData[2] == 0x00 &&
|
|
|
|
aStyleSheetData[3] == 0x40) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// big-endian 4-byte encoding, no BOM
|
|
|
|
step = 4;
|
|
|
|
pos = 3;
|
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
else if (aStyleSheetData[0] == 0x40 &&
|
|
|
|
aStyleSheetData[1] == 0x00 &&
|
|
|
|
aStyleSheetData[2] == 0x00 &&
|
|
|
|
aStyleSheetData[3] == 0x00) {
|
|
|
|
// little-endian 4-byte encoding, no BOM
|
2002-08-28 03:47:25 +04:00
|
|
|
step = 4;
|
|
|
|
pos = 0;
|
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
else if (aStyleSheetData[0] == 0x00 &&
|
|
|
|
aStyleSheetData[1] == 0x00 &&
|
|
|
|
aStyleSheetData[2] == 0x40 &&
|
|
|
|
aStyleSheetData[3] == 0x00) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// 4-byte encoding in 2143 order, no BOM
|
|
|
|
step = 4;
|
|
|
|
pos = 2;
|
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
else if (aStyleSheetData[0] == 0x00 &&
|
|
|
|
aStyleSheetData[1] == 0x40 &&
|
|
|
|
aStyleSheetData[2] == 0x00 &&
|
|
|
|
aStyleSheetData[3] == 0x00) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// 4-byte encoding in 3412 order, no BOM
|
|
|
|
step = 4;
|
|
|
|
pos = 1;
|
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
else if (aStyleSheetData[0] == 0x00 &&
|
|
|
|
aStyleSheetData[1] == 0x40 &&
|
|
|
|
aStyleSheetData[2] == 0x00 &&
|
|
|
|
aStyleSheetData[3] == 0x63) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// 2-byte big-endian encoding, no BOM
|
|
|
|
step = 2;
|
|
|
|
pos = 1;
|
|
|
|
}
|
2003-09-25 09:57:28 +04:00
|
|
|
else if (aStyleSheetData[0] == 0x40 &&
|
|
|
|
aStyleSheetData[1] == 0x00 &&
|
|
|
|
aStyleSheetData[2] == 0x63 &&
|
|
|
|
aStyleSheetData[3] == 0x00) {
|
|
|
|
// 2-byte little-endian encoding, no BOM
|
2002-08-28 03:47:25 +04:00
|
|
|
step = 2;
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// no clue what this is
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 index = 0;
|
|
|
|
while (pos < aDataLength && index < sizeof(kCharsetSym) - 1) {
|
|
|
|
if (aStyleSheetData[pos] != kCharsetSym[index]) {
|
2003-09-25 09:57:28 +04:00
|
|
|
// If we have a guess as to the charset based on the BOM, then
|
|
|
|
// we can just return NS_OK even if there is no valid @charset
|
|
|
|
// rule.
|
|
|
|
return aCharset.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
|
|
|
++index;
|
|
|
|
pos += step;
|
|
|
|
}
|
|
|
|
|
2003-09-25 09:57:28 +04:00
|
|
|
nsCAutoString charset;
|
2002-08-28 03:47:25 +04:00
|
|
|
while (pos < aDataLength) {
|
2008-11-12 06:36:20 +03:00
|
|
|
if (aStyleSheetData[pos] == '"') {
|
2002-08-28 03:47:25 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-06-11 22:16:03 +04:00
|
|
|
// casting to avoid ambiguities
|
2003-09-25 09:57:28 +04:00
|
|
|
charset.Append(char(aStyleSheetData[pos]));
|
2002-08-28 03:47:25 +04:00
|
|
|
pos += step;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the ending ';'
|
|
|
|
pos += step;
|
|
|
|
if (pos >= aDataLength || aStyleSheetData[pos] != ';') {
|
2003-09-25 09:57:28 +04:00
|
|
|
return aCharset.IsEmpty() ? NS_ERROR_NOT_AVAILABLE : NS_OK;
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
|
|
|
|
2003-09-25 09:57:28 +04:00
|
|
|
aCharset = charset;
|
2002-08-28 03:47:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
|
|
|
|
nsISupports* aContext,
|
|
|
|
const char* aData,
|
|
|
|
PRUint32 aDataLength,
|
|
|
|
nsACString& aCharset)
|
|
|
|
{
|
2009-04-10 18:29:08 +04:00
|
|
|
NS_PRECONDITION(!mOwningElement || mCharsetHint.IsEmpty(),
|
|
|
|
"Can't have element _and_ charset hint");
|
|
|
|
|
2004-01-13 22:01:26 +03:00
|
|
|
LOG_URI("SheetLoadData::OnDetermineCharset for '%s'", mURI);
|
2002-08-28 03:47:25 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
nsresult result = aLoader->GetChannel(getter_AddRefs(channel));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
channel = nsnull;
|
|
|
|
|
2003-06-23 09:04:43 +04:00
|
|
|
aCharset.Truncate();
|
|
|
|
|
2002-08-28 03:47:25 +04:00
|
|
|
/*
|
|
|
|
* First determine the charset (if one is indicated)
|
|
|
|
* 1) Check nsIChannel::contentCharset
|
|
|
|
* 2) Check @charset rules in the data
|
|
|
|
* 3) Check "charset" attribute of the <LINK> or <?xml-stylesheet?>
|
|
|
|
*
|
2004-01-13 22:01:26 +03:00
|
|
|
* If all these fail to give us a charset, fall back on our default
|
|
|
|
* (parent sheet charset, document charset or ISO-8859-1 in that order)
|
2002-08-28 03:47:25 +04:00
|
|
|
*/
|
|
|
|
if (channel) {
|
2003-06-23 09:04:43 +04:00
|
|
|
channel->GetContentCharset(aCharset);
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
result = NS_ERROR_NOT_AVAILABLE;
|
2003-06-23 09:04:43 +04:00
|
|
|
|
2004-01-13 22:01:26 +03:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-23 09:04:43 +04:00
|
|
|
if (! aCharset.IsEmpty()) {
|
2004-01-13 22:01:26 +03:00
|
|
|
LOG((" Setting from HTTP to: %s", PromiseFlatCString(aCharset).get()));
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
2003-06-23 09:04:43 +04:00
|
|
|
#endif
|
2002-08-28 03:47:25 +04:00
|
|
|
|
2003-06-23 09:04:43 +04:00
|
|
|
if (aCharset.IsEmpty()) {
|
|
|
|
// We have no charset
|
2003-09-25 09:57:28 +04:00
|
|
|
// Try @charset rule and BOM
|
2002-08-28 03:47:25 +04:00
|
|
|
result = GetCharsetFromData((const unsigned char*)aData,
|
2003-06-23 09:04:43 +04:00
|
|
|
aDataLength, aCharset);
|
2004-01-13 22:01:26 +03:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-23 09:04:43 +04:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2004-01-13 22:01:26 +03:00
|
|
|
LOG((" Setting from @charset rule or BOM: %s",
|
|
|
|
PromiseFlatCString(aCharset).get()));
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
2003-06-23 09:04:43 +04:00
|
|
|
#endif
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
|
|
|
|
2003-06-23 09:04:43 +04:00
|
|
|
if (aCharset.IsEmpty()) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// Now try the charset on the <link> or processing instruction
|
|
|
|
// that loaded us
|
2002-12-03 08:48:14 +03:00
|
|
|
if (mOwningElement) {
|
2003-06-11 22:16:03 +04:00
|
|
|
nsAutoString elementCharset;
|
|
|
|
mOwningElement->GetCharset(elementCharset);
|
2006-02-03 17:18:39 +03:00
|
|
|
LossyCopyUTF16toASCII(elementCharset, aCharset);
|
2004-01-13 22:01:26 +03:00
|
|
|
#ifdef PR_LOGGING
|
2003-06-23 09:04:43 +04:00
|
|
|
if (! aCharset.IsEmpty()) {
|
2004-01-13 22:01:26 +03:00
|
|
|
LOG((" Setting from property on element: %s",
|
|
|
|
PromiseFlatCString(aCharset).get()));
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
2003-06-23 09:04:43 +04:00
|
|
|
#endif
|
2009-04-10 18:29:08 +04:00
|
|
|
} else {
|
|
|
|
// If mCharsetHint is empty, that's ok; aCharset is known empty here
|
|
|
|
aCharset = mCharsetHint;
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-13 22:01:26 +03:00
|
|
|
if (aCharset.IsEmpty() && mParentData) {
|
|
|
|
aCharset = mParentData->mCharset;
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (! aCharset.IsEmpty()) {
|
|
|
|
LOG((" Setting from parent sheet: %s",
|
|
|
|
PromiseFlatCString(aCharset).get()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-06-23 09:04:43 +04:00
|
|
|
if (aCharset.IsEmpty() && mLoader->mDocument) {
|
2002-08-28 03:47:25 +04:00
|
|
|
// no useful data on charset. Try the document charset.
|
2003-10-22 10:09:48 +04:00
|
|
|
aCharset = mLoader->mDocument->GetDocumentCharacterSet();
|
2004-01-13 22:01:26 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG((" Set from document: %s", PromiseFlatCString(aCharset).get()));
|
2002-08-28 03:47:25 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-06-23 09:04:43 +04:00
|
|
|
if (aCharset.IsEmpty()) {
|
2002-08-28 03:47:25 +04:00
|
|
|
NS_WARNING("Unable to determine charset for sheet, using ISO-8859-1!");
|
2004-01-13 22:01:26 +03:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_WARN((" Falling back to ISO-8859-1"));
|
|
|
|
#endif
|
2004-06-17 04:13:25 +04:00
|
|
|
aCharset.AssignLiteral("ISO-8859-1");
|
2002-08-28 03:47:25 +04:00
|
|
|
}
|
2004-01-13 22:01:26 +03:00
|
|
|
|
|
|
|
mCharset = aCharset;
|
2002-08-28 03:47:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-18 06:32:25 +04:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
SheetLoadData::GetReferrerURI()
|
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2004-08-18 06:32:25 +04:00
|
|
|
if (mParentData)
|
2010-05-13 00:18:47 +04:00
|
|
|
uri = mParentData->mSheet->GetSheetURI();
|
2004-08-18 06:32:25 +04:00
|
|
|
if (!uri && mLoader->mDocument)
|
2010-05-13 00:18:47 +04:00
|
|
|
uri = mLoader->mDocument->GetDocumentURI();
|
|
|
|
return uri.forget();
|
2004-08-18 06:32:25 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/*
|
|
|
|
* Here we need to check that the load did not give us an http error
|
|
|
|
* page and check the mimetype on the channel to make sure we're not
|
|
|
|
* loading non-text/css data in standards mode.
|
|
|
|
*/
|
1999-11-02 09:49:44 +03:00
|
|
|
NS_IMETHODIMP
|
2002-08-28 03:47:25 +04:00
|
|
|
SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
|
2001-10-25 04:34:20 +04:00
|
|
|
nsISupports* aContext,
|
2000-02-03 02:04:47 +03:00
|
|
|
nsresult aStatus,
|
2002-08-28 03:47:25 +04:00
|
|
|
nsIUnicharInputStream* aDataStream)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG(("SheetLoadData::OnStreamComplete"));
|
|
|
|
NS_ASSERTION(!mLoader->mSyncCallback, "Synchronous callback from necko");
|
|
|
|
|
|
|
|
if (mIsCancelled) {
|
|
|
|
// Just return. Don't call SheetComplete -- it's already been
|
|
|
|
// called and calling it again will lead to an extra NS_RELEASE on
|
|
|
|
// this data and a likely crash.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (!mLoader->mDocument && !mIsNonDocumentSheet) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Sorry, we don't care about this load anymore
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG_WARN((" No document and not non-document sheet; dropping load"));
|
|
|
|
mLoader->SheetComplete(this, NS_BINDING_ABORTED);
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (NS_FAILED(aStatus)) {
|
|
|
|
LOG_WARN((" Load failed: status 0x%x", aStatus));
|
|
|
|
mLoader->SheetComplete(this, aStatus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-28 03:47:25 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
nsresult result = aLoader->GetChannel(getter_AddRefs(channel));
|
2007-05-01 23:26:15 +04:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
LOG_WARN((" No channel from loader"));
|
|
|
|
mLoader->SheetComplete(this, result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2007-10-24 01:56:41 +04:00
|
|
|
nsCOMPtr<nsIURI> originalURI;
|
|
|
|
channel->GetOriginalURI(getter_AddRefs(originalURI));
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
// If the channel's original URI is "chrome:", we want that, since
|
|
|
|
// the observer code in nsXULPrototypeCache depends on chrome stylesheets
|
|
|
|
// having a chrome URI. (Whether or not chrome stylesheets come through
|
|
|
|
// this codepath seems nondeterministic.)
|
|
|
|
// Otherwise we want the potentially-HTTP-redirected URI.
|
2007-10-24 01:56:41 +04:00
|
|
|
nsCOMPtr<nsIURI> channelURI;
|
|
|
|
NS_GetFinalChannelURI(channel, getter_AddRefs(channelURI));
|
2007-05-01 23:26:15 +04:00
|
|
|
|
2007-10-24 01:56:41 +04:00
|
|
|
if (!channelURI || !originalURI) {
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ERROR("Someone just violated the nsIRequest contract");
|
|
|
|
LOG_WARN((" Channel without a URI. Bad!"));
|
|
|
|
mLoader->SheetComplete(this, NS_ERROR_UNEXPECTED);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
result = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
if (secMan) { // Could be null if we already shut down
|
|
|
|
result = secMan->GetChannelPrincipal(channel, getter_AddRefs(principal));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
LOG_WARN((" Couldn't get principal"));
|
|
|
|
mLoader->SheetComplete(this, result);
|
|
|
|
return NS_OK;
|
2003-07-18 04:35:49 +04:00
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
mSheet->SetPrincipal(principal);
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
#ifdef MOZ_TIMELINE
|
2002-08-28 16:18:26 +04:00
|
|
|
NS_TIMELINE_OUTDENT();
|
|
|
|
NS_TIMELINE_MARK_CHANNEL("SheetLoadData::OnStreamComplete(%s)", channel);
|
2002-12-03 08:48:14 +03:00
|
|
|
#endif // MOZ_TIMELINE
|
|
|
|
|
2002-06-18 06:46:11 +04:00
|
|
|
// If it's an HTTP channel, we want to make sure this is not an
|
|
|
|
// error document we got.
|
2002-08-28 03:47:25 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
2002-06-18 06:46:11 +04:00
|
|
|
if (httpChannel) {
|
2002-07-02 03:12:13 +04:00
|
|
|
PRBool requestSucceeded;
|
|
|
|
result = httpChannel->GetRequestSucceeded(&requestSucceeded);
|
|
|
|
if (NS_SUCCEEDED(result) && !requestSucceeded) {
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG((" Load returned an error page"));
|
2005-09-12 22:41:15 +04:00
|
|
|
mLoader->SheetComplete(this, NS_ERROR_NOT_AVAILABLE);
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_OK;
|
2002-06-18 06:46:11 +04:00
|
|
|
}
|
|
|
|
}
|
2002-08-28 03:47:25 +04:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (!aDataStream) {
|
|
|
|
LOG_WARN((" No data stream; bailing"));
|
|
|
|
mLoader->SheetComplete(this, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return NS_OK;
|
2009-12-23 21:01:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString contentType;
|
|
|
|
if (channel) {
|
|
|
|
channel->GetContentType(contentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// In standards mode, a style sheet must have one of these MIME
|
|
|
|
// types to be processed at all. In quirks mode, we accept any
|
|
|
|
// MIME type, but only if the style sheet is same-origin with the
|
|
|
|
// requesting document or parent sheet. See bug 524223.
|
|
|
|
|
|
|
|
PRBool validType = contentType.EqualsLiteral("text/css") ||
|
|
|
|
contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE) ||
|
|
|
|
contentType.IsEmpty();
|
|
|
|
|
|
|
|
if (!validType) {
|
|
|
|
const char *errorMessage;
|
|
|
|
PRUint32 errorFlag;
|
|
|
|
PRBool sameOrigin = PR_TRUE;
|
|
|
|
|
|
|
|
if (mLoaderPrincipal) {
|
|
|
|
PRBool subsumed;
|
|
|
|
result = mLoaderPrincipal->Subsumes(principal, &subsumed);
|
|
|
|
if (NS_FAILED(result) || !subsumed) {
|
|
|
|
sameOrigin = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sameOrigin && mLoader->mCompatMode == eCompatibility_NavQuirks) {
|
|
|
|
errorMessage = "MimeNotCssWarn";
|
|
|
|
errorFlag = nsIScriptError::warningFlag;
|
|
|
|
} else {
|
|
|
|
errorMessage = "MimeNotCss";
|
|
|
|
errorFlag = nsIScriptError::errorFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString spec;
|
|
|
|
channelURI->GetSpec(spec);
|
|
|
|
|
|
|
|
const nsAFlatString& specUTF16 = NS_ConvertUTF8toUTF16(spec);
|
|
|
|
const nsAFlatString& ctypeUTF16 = NS_ConvertASCIItoUTF16(contentType);
|
|
|
|
const PRUnichar *strings[] = { specUTF16.get(), ctypeUTF16.get() };
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> referrer = GetReferrerURI();
|
|
|
|
nsContentUtils::ReportToConsole(nsContentUtils::eCSS_PROPERTIES,
|
|
|
|
errorMessage,
|
|
|
|
strings, NS_ARRAY_LENGTH(strings),
|
|
|
|
referrer, EmptyString(), 0, 0, errorFlag,
|
2010-12-20 19:21:59 +03:00
|
|
|
"CSS Loader", mLoader->mDocument);
|
2009-12-23 21:01:51 +03:00
|
|
|
|
|
|
|
if (errorFlag == nsIScriptError::errorFlag) {
|
|
|
|
LOG_WARN((" Ignoring sheet with improper MIME type %s",
|
|
|
|
contentType.get()));
|
|
|
|
mLoader->SheetComplete(this, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2005-09-12 22:41:15 +04:00
|
|
|
|
2007-10-24 01:56:41 +04:00
|
|
|
// Enough to set the URIs on mSheet, since any sibling datas we have share
|
2007-05-01 23:26:15 +04:00
|
|
|
// the same mInner as mSheet and will thus get the same URI.
|
2007-10-24 01:56:41 +04:00
|
|
|
mSheet->SetURIs(channelURI, originalURI, channelURI);
|
2009-12-23 21:01:51 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
PRBool completed;
|
2003-10-06 17:24:55 +04:00
|
|
|
return mLoader->ParseSheet(aDataStream, this, completed);
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2000-07-28 13:36:51 +04:00
|
|
|
static PRBool IsChromeURI(nsIURI* aURI)
|
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(aURI, "Have to pass in a URI");
|
2001-05-02 08:53:38 +04:00
|
|
|
PRBool isChrome = PR_FALSE;
|
|
|
|
aURI->SchemeIs("chrome", &isChrome);
|
|
|
|
return isChrome;
|
2000-07-28 13:36:51 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
PRBool
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::IsAlternate(const nsAString& aTitle, PRBool aHasAlternateRel)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2005-09-12 22:41:15 +04:00
|
|
|
// 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
|
|
|
|
// style set, the sheet wasn't marked as an alternate explicitly, and aTitle
|
|
|
|
// is nonempty, we should select the style set corresponding to aTitle, since
|
|
|
|
// that's a preferred sheet.
|
|
|
|
if (aTitle.IsEmpty()) {
|
|
|
|
return PR_FALSE;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
2005-09-12 22:41:15 +04:00
|
|
|
|
|
|
|
if (!aHasAlternateRel && mDocument && mPreferredSheet.IsEmpty()) {
|
|
|
|
// There's no preferred set yet, and we now have a sheet with a title.
|
|
|
|
// Make that be the preferred set.
|
2006-12-26 20:47:52 +03:00
|
|
|
mDocument->SetHeaderData(nsGkAtoms::headerDefaultStyle, aTitle);
|
2005-09-12 22:41:15 +04:00
|
|
|
// We're definitely not an alternate
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-01-11 22:32:31 +03:00
|
|
|
return !aTitle.Equals(mPreferredSheet);
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2003-04-05 03:57:06 +04:00
|
|
|
/**
|
|
|
|
* CheckLoadAllowed will return success if the load is allowed,
|
|
|
|
* failure otherwise.
|
|
|
|
*
|
2007-05-01 23:26:15 +04:00
|
|
|
* @param aSourcePrincipal the principal of the node or document or parent
|
|
|
|
* sheet loading the sheet
|
2003-04-05 03:57:06 +04:00
|
|
|
* @param aTargetURI the uri of the sheet to be loaded
|
2004-07-27 21:15:53 +04:00
|
|
|
* @param aContext the node owning the sheet. This is the element or document
|
|
|
|
* owning the stylesheet (possibly indirectly, for child sheets)
|
2003-04-05 03:57:06 +04:00
|
|
|
*/
|
|
|
|
nsresult
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::CheckLoadAllowed(nsIPrincipal* aSourcePrincipal,
|
|
|
|
nsIURI* aTargetURI,
|
|
|
|
nsISupports* aContext)
|
2003-04-05 03:57:06 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::CheckLoadAllowed"));
|
2007-07-11 23:44:27 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
2003-04-05 03:57:06 +04:00
|
|
|
|
2007-07-11 23:44:27 +04:00
|
|
|
if (aSourcePrincipal) {
|
|
|
|
// Check with the security manager
|
|
|
|
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
|
|
|
rv =
|
|
|
|
secMan->CheckLoadURIWithPrincipal(aSourcePrincipal, aTargetURI,
|
|
|
|
nsIScriptSecurityManager::ALLOW_CHROME);
|
|
|
|
if (NS_FAILED(rv)) { // failure is normal here; don't warn
|
|
|
|
return rv;
|
|
|
|
}
|
2003-04-05 03:57:06 +04:00
|
|
|
|
2007-08-08 05:16:09 +04:00
|
|
|
LOG((" Passed security check"));
|
2003-04-05 03:57:06 +04:00
|
|
|
|
2007-07-11 23:44:27 +04:00
|
|
|
// Check with content policy
|
|
|
|
|
|
|
|
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
|
|
|
|
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_STYLESHEET,
|
|
|
|
aTargetURI,
|
2007-08-08 05:16:09 +04:00
|
|
|
aSourcePrincipal,
|
2007-07-11 23:44:27 +04:00
|
|
|
aContext,
|
|
|
|
NS_LITERAL_CSTRING("text/css"),
|
|
|
|
nsnull, //extra param
|
|
|
|
&shouldLoad,
|
2007-08-08 05:16:09 +04:00
|
|
|
nsContentUtils::GetContentPolicy(),
|
|
|
|
nsContentUtils::GetSecurityManager());
|
2007-07-11 23:44:27 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
|
|
|
|
LOG((" Load blocked by content policy"));
|
|
|
|
return NS_ERROR_CONTENT_BLOCKED;
|
|
|
|
}
|
2003-04-05 03:57:06 +04:00
|
|
|
}
|
|
|
|
|
2007-07-11 23:44:27 +04:00
|
|
|
return NS_OK;
|
2003-04-05 03:57:06 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/**
|
2010-05-12 00:41:47 +04:00
|
|
|
* CreateSheet() creates an nsCSSStyleSheet object for the given URI,
|
2002-12-03 08:48:14 +03:00
|
|
|
* if any. If there is no URI given, we just create a new style sheet
|
|
|
|
* object. Otherwise, we check for an existing style sheet object for
|
|
|
|
* that uri in various caches and clone it if we find it. Cloned
|
|
|
|
* sheets will have the title/media/enabled state of the sheet they
|
|
|
|
* are clones off; make sure to call PrepareSheet() on the result of
|
|
|
|
* CreateSheet().
|
|
|
|
*/
|
1999-05-19 03:15:10 +04:00
|
|
|
nsresult
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::CreateSheet(nsIURI* aURI,
|
|
|
|
nsIContent* aLinkingContent,
|
|
|
|
nsIPrincipal* aLoaderPrincipal,
|
|
|
|
PRBool aSyncLoad,
|
|
|
|
StyleSheetState& aSheetState,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet** aSheet)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::CreateSheet"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aSheet, "Null out param!");
|
2003-07-27 19:20:11 +04:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE((mCompleteSheets.IsInitialized() || mCompleteSheets.Init()) &&
|
|
|
|
(mLoadingDatas.IsInitialized() || mLoadingDatas.Init()) &&
|
|
|
|
(mPendingDatas.IsInitialized() || mPendingDatas.Init()),
|
|
|
|
NS_ERROR_OUT_OF_MEMORY);
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
*aSheet = nsnull;
|
|
|
|
aSheetState = eSheetStateUnknown;
|
|
|
|
|
|
|
|
if (aURI) {
|
|
|
|
aSheetState = eSheetComplete;
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet;
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-11 03:28:47 +03:00
|
|
|
// First, the XUL cache
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2002-12-11 03:28:47 +03:00
|
|
|
if (IsChromeURI(aURI)) {
|
2007-03-12 08:53:33 +03:00
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
2002-12-03 08:48:14 +03:00
|
|
|
if (cache) {
|
2007-03-12 08:53:33 +03:00
|
|
|
if (cache->IsEnabled()) {
|
|
|
|
sheet = cache->GetStyleSheet(aURI);
|
2002-12-11 03:28:47 +03:00
|
|
|
LOG((" From XUL cache: %p", sheet.get()));
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!sheet) {
|
2008-10-21 00:33:03 +04:00
|
|
|
// Then our per-document complete sheets.
|
2010-03-03 00:00:53 +03:00
|
|
|
URIAndPrincipalHashKey key(aURI, aLoaderPrincipal);
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
mCompleteSheets.Get(&key, getter_AddRefs(sheet));
|
2002-12-11 03:28:47 +03:00
|
|
|
LOG((" From completed: %p", sheet.get()));
|
2008-10-21 00:33:03 +04:00
|
|
|
}
|
2002-12-11 03:28:47 +03:00
|
|
|
|
2008-10-21 00:33:03 +04:00
|
|
|
if (sheet) {
|
|
|
|
// This sheet came from the XUL cache or our per-document hashtable; it
|
|
|
|
// better be a complete sheet.
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(sheet->IsComplete(),
|
2008-10-21 00:33:03 +04:00
|
|
|
"Sheet thinks it's not complete while we think it is");
|
2010-05-14 23:05:14 +04:00
|
|
|
|
2008-10-21 00:33:03 +04:00
|
|
|
// Make sure it hasn't been modified; if it has, we can't use it
|
2010-05-12 00:41:47 +04:00
|
|
|
if (sheet->IsModified()) {
|
2008-10-21 00:33:03 +04:00
|
|
|
LOG((" Not cloning completed sheet %p because it's been modified",
|
|
|
|
sheet.get()));
|
|
|
|
sheet = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then loading sheets
|
|
|
|
if (!sheet && !aSyncLoad) {
|
|
|
|
aSheetState = eSheetLoading;
|
|
|
|
SheetLoadData* loadData = nsnull;
|
2010-03-03 00:00:53 +03:00
|
|
|
URIAndPrincipalHashKey key(aURI, aLoaderPrincipal);
|
2008-10-21 00:33:03 +04:00
|
|
|
mLoadingDatas.Get(&key, &loadData);
|
|
|
|
if (loadData) {
|
|
|
|
sheet = loadData->mSheet;
|
|
|
|
LOG((" From loading: %p", sheet.get()));
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool debugEqual;
|
|
|
|
NS_ASSERTION((!aLoaderPrincipal && !loadData->mLoaderPrincipal) ||
|
|
|
|
(aLoaderPrincipal && loadData->mLoaderPrincipal &&
|
|
|
|
NS_SUCCEEDED(aLoaderPrincipal->
|
|
|
|
Equals(loadData->mLoaderPrincipal,
|
|
|
|
&debugEqual)) && debugEqual),
|
|
|
|
"Principals should be the same");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then alternate sheets
|
|
|
|
if (!sheet) {
|
|
|
|
aSheetState = eSheetPending;
|
2003-07-27 19:20:11 +04:00
|
|
|
SheetLoadData* loadData = nsnull;
|
2008-10-21 00:33:03 +04:00
|
|
|
mPendingDatas.Get(&key, &loadData);
|
2002-12-11 03:28:47 +03:00
|
|
|
if (loadData) {
|
|
|
|
sheet = loadData->mSheet;
|
2008-10-21 00:33:03 +04:00
|
|
|
LOG((" From pending: %p", sheet.get()));
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool debugEqual;
|
|
|
|
NS_ASSERTION((!aLoaderPrincipal && !loadData->mLoaderPrincipal) ||
|
|
|
|
(aLoaderPrincipal && loadData->mLoaderPrincipal &&
|
|
|
|
NS_SUCCEEDED(aLoaderPrincipal->
|
2008-10-21 00:33:03 +04:00
|
|
|
Equals(loadData->mLoaderPrincipal,
|
|
|
|
&debugEqual)) && debugEqual),
|
2007-05-01 23:26:15 +04:00
|
|
|
"Principals should be the same");
|
|
|
|
#endif
|
2002-12-11 03:28:47 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sheet) {
|
2008-10-21 00:33:03 +04:00
|
|
|
// The sheet we have now should be either incomplete or unmodified
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(!sheet->IsModified() || !sheet->IsComplete(),
|
2008-10-21 00:33:03 +04:00
|
|
|
"Unexpected modified complete sheet");
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_ASSERTION(sheet->IsComplete() || aSheetState != eSheetComplete,
|
2008-10-21 00:33:03 +04:00
|
|
|
"Sheet thinks it's not complete while we think it is");
|
2010-05-14 23:05:14 +04:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
*aSheet = sheet->Clone(nsnull, nsnull, nsnull, nsnull).get();
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!*aSheet) {
|
|
|
|
aSheetState = eSheetNeedsParser;
|
2007-10-24 01:56:41 +04:00
|
|
|
nsIURI *sheetURI;
|
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
|
|
|
nsIURI* originalURI;
|
2004-09-10 10:45:59 +04:00
|
|
|
if (!aURI) {
|
2003-10-06 17:24:55 +04:00
|
|
|
// Inline style. Use the document's base URL so that @import in
|
|
|
|
// the inline sheet picks up the right base.
|
|
|
|
NS_ASSERTION(aLinkingContent, "Inline stylesheet without linking content?");
|
2004-09-10 10:45:59 +04:00
|
|
|
baseURI = aLinkingContent->GetBaseURI();
|
|
|
|
sheetURI = aLinkingContent->GetDocument()->GetDocumentURI();
|
2007-10-24 01:56:41 +04:00
|
|
|
originalURI = nsnull;
|
|
|
|
} else {
|
|
|
|
baseURI = aURI;
|
|
|
|
sheetURI = aURI;
|
|
|
|
originalURI = aURI;
|
2003-10-06 17:24:55 +04:00
|
|
|
}
|
|
|
|
|
2004-09-10 10:45:59 +04:00
|
|
|
rv = NS_NewCSSStyleSheet(aSheet);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-10-24 01:56:41 +04:00
|
|
|
(*aSheet)->SetURIs(sheetURI, originalURI, baseURI);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(*aSheet, "We should have a sheet by now!");
|
|
|
|
NS_ASSERTION(aSheetState != eSheetStateUnknown, "Have to set a state!");
|
|
|
|
LOG((" State: %s", gStateStrings[aSheetState]));
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/**
|
|
|
|
* PrepareSheet() handles setting the media and title on the sheet, as
|
2005-09-12 22:41:15 +04:00
|
|
|
* well as setting the enabled state based on the title and whether
|
|
|
|
* the sheet had "alternate" in its rel.
|
2002-12-03 08:48:14 +03:00
|
|
|
*/
|
1999-05-19 03:15:10 +04:00
|
|
|
nsresult
|
2010-05-12 00:41:47 +04:00
|
|
|
Loader::PrepareSheet(nsCSSStyleSheet* aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
const nsSubstring& aTitle,
|
|
|
|
const nsSubstring& aMediaString,
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
PRBool aHasAlternateRel,
|
|
|
|
PRBool *aIsAlternate)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aSheet, "Must have a sheet!");
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult rv;
|
2010-06-01 03:50:10 +04:00
|
|
|
nsRefPtr<nsMediaList> mediaList(aMediaList);
|
2005-03-30 04:36:57 +04:00
|
|
|
|
|
|
|
if (!aMediaString.IsEmpty()) {
|
|
|
|
NS_ASSERTION(!aMediaList,
|
|
|
|
"must not provide both aMediaString and aMediaList");
|
|
|
|
mediaList = new nsMediaList();
|
|
|
|
NS_ENSURE_TRUE(mediaList, NS_ERROR_OUT_OF_MEMORY);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
nsCSSParser mediumParser(this);
|
|
|
|
NS_ENSURE_TRUE(mediumParser, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
// We have aMediaString only when linked from link elements, style
|
|
|
|
// elements, or PIs, so pass PR_TRUE.
|
2010-03-02 23:59:32 +03:00
|
|
|
rv = mediumParser.ParseMediaList(aMediaString, nsnull, 0, mediaList,
|
|
|
|
PR_TRUE);
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
2005-03-30 04:36:57 +04:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
aSheet->SetMedia(mediaList);
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
aSheet->SetTitle(aTitle);
|
2005-09-12 22:41:15 +04:00
|
|
|
PRBool alternate = IsAlternate(aTitle, aHasAlternateRel);
|
|
|
|
aSheet->SetEnabled(! alternate);
|
|
|
|
if (aIsAlternate) {
|
|
|
|
*aIsAlternate = alternate;
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/**
|
|
|
|
* InsertSheetInDoc handles ordering of sheets in the document. Here
|
|
|
|
* we have two types of sheets -- those with linking elements and
|
|
|
|
* those without. The latter are loaded by Link: headers.
|
|
|
|
* The following constraints are observed:
|
|
|
|
* 1) Any sheet with a linking element comes after all sheets without
|
|
|
|
* linking elements
|
|
|
|
* 2) Sheets without linking elements are inserted in the order in
|
|
|
|
* which the inserting requests come in, since all of these are
|
|
|
|
* inserted during header data processing in the content sink
|
|
|
|
* 3) Sheets with linking elements are ordered based on document order
|
2002-12-04 08:18:39 +03:00
|
|
|
* as determined by CompareDocumentPosition.
|
2002-12-03 08:48:14 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
2010-05-12 00:41:47 +04:00
|
|
|
Loader::InsertSheetInDoc(nsCSSStyleSheet* aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIContent* aLinkingContent,
|
|
|
|
nsIDocument* aDocument)
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::InsertSheetInDoc"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aSheet, "Nothing to insert");
|
|
|
|
NS_PRECONDITION(aDocument, "Must have a document to insert into");
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// XXX Need to cancel pending sheet loads for this element, if any
|
2001-10-31 22:03:46 +03:00
|
|
|
|
2004-07-28 11:08:41 +04:00
|
|
|
PRInt32 sheetCount = aDocument->GetNumberOfStyleSheets();
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the walk at the _end_ of the list, since in the typical
|
|
|
|
* case we'll just want to append anyway. We want to break out of
|
|
|
|
* the loop when insertionPoint points to just before the index we
|
|
|
|
* want to insert at. In other words, when we leave the loop
|
|
|
|
* insertionPoint is the index of the stylesheet that immediately
|
|
|
|
* precedes the one we're inserting.
|
|
|
|
*/
|
|
|
|
PRInt32 insertionPoint;
|
|
|
|
for (insertionPoint = sheetCount - 1; insertionPoint >= 0; --insertionPoint) {
|
2004-07-28 11:08:41 +04:00
|
|
|
nsIStyleSheet *curSheet = aDocument->GetStyleSheetAt(insertionPoint);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(curSheet, "There must be a sheet here!");
|
|
|
|
nsCOMPtr<nsIDOMStyleSheet> domSheet = do_QueryInterface(curSheet);
|
|
|
|
NS_ASSERTION(domSheet, "All the \"normal\" sheets implement nsIDOMStyleSheet");
|
|
|
|
nsCOMPtr<nsIDOMNode> sheetOwner;
|
|
|
|
domSheet->GetOwnerNode(getter_AddRefs(sheetOwner));
|
2006-05-16 19:50:47 +04:00
|
|
|
if (sheetOwner && !aLinkingContent) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Keep moving; all sheets with a sheetOwner come after all
|
|
|
|
// sheets without a linkingNode
|
|
|
|
continue;
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!sheetOwner) {
|
|
|
|
// Aha! The current sheet has no sheet owner, so we want to
|
|
|
|
// insert after it no matter whether we have a linkingNode
|
|
|
|
break;
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2006-05-16 19:50:47 +04:00
|
|
|
nsCOMPtr<nsINode> sheetOwnerNode = do_QueryInterface(sheetOwner);
|
|
|
|
NS_ASSERTION(aLinkingContent != sheetOwnerNode,
|
|
|
|
"Why do we still have our old sheet?");
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Have to compare
|
2006-05-16 19:52:45 +04:00
|
|
|
if (nsContentUtils::PositionIsBefore(sheetOwnerNode, aLinkingContent)) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// The current sheet comes before us, and it better be the first
|
|
|
|
// such, because now we break
|
|
|
|
break;
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
++insertionPoint; // adjust the index to the spot we want to insert in
|
|
|
|
|
|
|
|
// XXX <meta> elements do not implement nsIStyleSheetLinkingElement;
|
|
|
|
// need to fix this for them to be ordered correctly.
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement>
|
2003-07-03 06:45:34 +04:00
|
|
|
linkingElement = do_QueryInterface(aLinkingContent);
|
2002-12-03 08:48:14 +03:00
|
|
|
if (linkingElement) {
|
|
|
|
linkingElement->SetStyleSheet(aSheet); // This sets the ownerNode on the sheet
|
|
|
|
}
|
|
|
|
|
2003-10-03 01:29:40 +04:00
|
|
|
aDocument->BeginUpdate(UPDATE_STYLE);
|
2002-12-03 08:48:14 +03:00
|
|
|
aDocument->InsertStyleSheetAt(aSheet, insertionPoint);
|
2003-10-03 01:29:40 +04:00
|
|
|
aDocument->EndUpdate(UPDATE_STYLE);
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG((" Inserting into document at position %d", insertionPoint));
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/**
|
|
|
|
* InsertChildSheet handles ordering of @import-ed sheet in their
|
|
|
|
* parent sheets. Here we want to just insert based on order of the
|
|
|
|
* @import rules that imported the sheets. In theory we can't just
|
|
|
|
* append to the end because the CSSOM can insert @import rules. In
|
|
|
|
* practice, we get the call to load the child sheet before the CSSOM
|
|
|
|
* has finished inserting the @import rule, so we have no idea where
|
|
|
|
* to put it anyway. So just append for now.
|
|
|
|
*/
|
1999-05-19 03:15:10 +04:00
|
|
|
nsresult
|
2010-05-12 00:41:47 +04:00
|
|
|
Loader::InsertChildSheet(nsCSSStyleSheet* aSheet,
|
|
|
|
nsCSSStyleSheet* aParentSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSImportRule* aParentRule)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::InsertChildSheet"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aSheet, "Nothing to insert");
|
|
|
|
NS_PRECONDITION(aParentSheet, "Need a parent to insert into");
|
|
|
|
NS_PRECONDITION(aParentSheet, "How did we get imported?");
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-02-26 01:26:26 +03:00
|
|
|
// child sheets should always start out enabled, even if they got
|
|
|
|
// cloned off of top-level sheets which were disabled
|
|
|
|
aSheet->SetEnabled(PR_TRUE);
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
aParentSheet->AppendStyleSheet(aSheet);
|
|
|
|
aParentRule->SetSheet(aSheet); // This sets the ownerRule on the sheet
|
|
|
|
|
|
|
|
LOG((" Inserting into parent sheet"));
|
|
|
|
// LOG((" Inserting into parent sheet at position %d", insertionPoint));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LoadSheet handles the actual load of a sheet. If the load is
|
|
|
|
* supposed to be synchronous it just opens a channel synchronously
|
|
|
|
* using the given uri, wraps the resulting stream in a converter
|
|
|
|
* stream and calls ParseSheet. Otherwise it tries to look for an
|
|
|
|
* existing load for this URI and piggyback on it. Failing all that,
|
|
|
|
* a new load is kicked off asynchronously.
|
|
|
|
*/
|
|
|
|
nsresult
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadSheet"));
|
2002-12-03 08:48:14 +03:00
|
|
|
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");
|
|
|
|
NS_PRECONDITION(aSheetState != eSheetComplete, "Why bother?");
|
2009-03-17 04:38:36 +03:00
|
|
|
NS_PRECONDITION(!aLoadData->mUseSystemPrincipal || aLoadData->mSyncLoad,
|
|
|
|
"Shouldn't use system principal for async loads");
|
2003-07-27 19:20:11 +04:00
|
|
|
NS_ASSERTION(mLoadingDatas.IsInitialized(), "mLoadingDatas should be initialized by now.");
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2010-05-20 03:22:19 +04:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
nsCAutoString spec__("N/A");
|
|
|
|
if (aLoadData->mURI) aLoadData->mURI->GetSpec(spec__);
|
|
|
|
NS_TIME_FUNCTION_FMT("Loading stylesheet (url: %s, %ssync)",
|
|
|
|
spec__.get(), aLoadData->mSyncLoad ? "" : "a");
|
|
|
|
#endif
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG_URI(" Load from: '%s'", aLoadData->mURI);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (!mDocument && !aLoadData->mIsNonDocumentSheet) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// No point starting the load; just release all the data and such.
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG_WARN((" No document and not non-document sheet; pre-dropping load"));
|
|
|
|
SheetComplete(aLoadData, NS_BINDING_ABORTED);
|
|
|
|
return NS_BINDING_ABORTED;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aLoadData->mSyncLoad) {
|
|
|
|
LOG((" Synchronous load"));
|
2005-09-12 22:41:15 +04:00
|
|
|
NS_ASSERTION(!aLoadData->mObserver, "Observer for a sync load?");
|
2002-12-11 03:28:47 +03:00
|
|
|
NS_ASSERTION(aSheetState == eSheetNeedsParser,
|
|
|
|
"Sync loads can't reuse existing async loads");
|
2003-07-18 04:35:49 +04:00
|
|
|
|
2002-12-11 03:28:47 +03:00
|
|
|
// Just load it
|
2002-12-03 08:48:14 +03:00
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
2007-05-01 23:26:15 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = NS_OpenURI(getter_AddRefs(stream), aLoadData->mURI, nsnull,
|
|
|
|
nsnull, nsnull, nsIRequest::LOAD_NORMAL,
|
|
|
|
getter_AddRefs(channel));
|
2002-12-03 08:48:14 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG_ERROR((" Failed to open URI synchronously"));
|
2005-09-12 22:41:15 +04:00
|
|
|
SheetComplete(aLoadData, rv);
|
2002-12-03 08:48:14 +03:00
|
|
|
return rv;
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ASSERTION(channel, "NS_OpenURI lied?");
|
|
|
|
|
2009-03-17 04:38:36 +03:00
|
|
|
// Get the principal for this sheet
|
2007-05-01 23:26:15 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2009-03-17 04:38:36 +03:00
|
|
|
if (aLoadData->mUseSystemPrincipal) {
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->
|
|
|
|
GetSystemPrincipal(getter_AddRefs(principal));
|
|
|
|
} else {
|
|
|
|
rv = nsContentUtils::GetSecurityManager()->
|
|
|
|
GetChannelPrincipal(channel, getter_AddRefs(principal));
|
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG_ERROR((" Failed to get a principal for the sheet"));
|
|
|
|
SheetComplete(aLoadData, rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
aLoadData->mSheet->SetPrincipal(principal);
|
|
|
|
|
2002-12-04 09:07:50 +03:00
|
|
|
nsCOMPtr<nsIConverterInputStream> converterStream =
|
|
|
|
do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG_ERROR((" Failed to create converter stream"));
|
2005-09-12 22:41:15 +04:00
|
|
|
SheetComplete(aLoadData, rv);
|
2002-12-04 09:07:50 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This forces UA sheets to be UTF-8. We should really look for
|
|
|
|
// @charset rules here via ReadSegments on the raw stream...
|
|
|
|
|
2002-12-05 09:36:18 +03:00
|
|
|
// 8192 is a nice magic number that happens to be what a lot of
|
2002-12-04 09:07:50 +03:00
|
|
|
// other things use for buffer sizes.
|
2003-06-11 22:16:03 +04:00
|
|
|
rv = converterStream->Init(stream, "UTF-8",
|
2005-06-24 23:44:50 +04:00
|
|
|
8192,
|
|
|
|
nsIConverterInputStream::
|
|
|
|
DEFAULT_REPLACEMENT_CHARACTER);
|
2002-12-04 09:07:50 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-12-04 09:07:50 +03:00
|
|
|
LOG_ERROR((" Failed to initialize converter stream"));
|
2005-09-12 22:41:15 +04:00
|
|
|
SheetComplete(aLoadData, rv);
|
2002-12-03 08:48:14 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool completed;
|
2003-10-06 17:24:55 +04:00
|
|
|
rv = ParseSheet(converterStream, aLoadData, completed);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(completed, "sync load did not complete");
|
|
|
|
return rv;
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
SheetLoadData* existingData = nsnull;
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
URIAndPrincipalHashKey key(aLoadData->mURI, aLoadData->mLoaderPrincipal);
|
2002-12-03 08:48:14 +03:00
|
|
|
if (aSheetState == eSheetLoading) {
|
2007-05-01 23:26:15 +04:00
|
|
|
mLoadingDatas.Get(&key, &existingData);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(existingData, "CreateSheet lied about the state");
|
|
|
|
}
|
|
|
|
else if (aSheetState == eSheetPending){
|
2007-05-01 23:26:15 +04:00
|
|
|
mPendingDatas.Get(&key, &existingData);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(existingData, "CreateSheet lied about the state");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (existingData) {
|
|
|
|
LOG((" Glomming on to existing load"));
|
|
|
|
SheetLoadData* data = existingData;
|
|
|
|
while (data->mNext) {
|
|
|
|
data = data->mNext;
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
data->mNext = aLoadData; // transfer ownership
|
2005-09-12 22:41:15 +04:00
|
|
|
if (aSheetState == eSheetPending && !aLoadData->mWasAlternate) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Kick the load off; someone cares about it right away
|
2003-07-27 19:20:11 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
#ifdef DEBUG
|
2003-07-27 19:20:11 +04:00
|
|
|
SheetLoadData* removedData;
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ASSERTION(mPendingDatas.Get(&key, &removedData) &&
|
2003-07-27 19:20:11 +04:00
|
|
|
removedData == existingData,
|
|
|
|
"Bad pending table.");
|
2002-12-03 08:48:14 +03:00
|
|
|
#endif
|
2003-07-27 19:20:11 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
mPendingDatas.Remove(&key);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
LOG((" Forcing load of pending data"));
|
2005-09-12 22:41:15 +04:00
|
|
|
return LoadSheet(existingData, eSheetNeedsParser);
|
2001-10-31 22:03:46 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
// All done here; once the load completes we'll be marked complete
|
|
|
|
// automatically
|
2001-10-31 22:03:46 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mSyncCallback = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
2010-04-24 02:05:32 +04:00
|
|
|
// Content Security Policy information to pass into channel
|
|
|
|
nsCOMPtr<nsIChannelPolicy> channelPolicy;
|
2002-12-03 08:48:14 +03:00
|
|
|
if (mDocument) {
|
2003-10-22 10:09:48 +04:00
|
|
|
loadGroup = mDocument->GetDocumentLoadGroup();
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(loadGroup,
|
|
|
|
"No loadgroup for stylesheet; onload will fire early");
|
2010-04-24 02:05:32 +04:00
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
|
|
|
rv = mDocument->NodePrincipal()->GetCsp(getter_AddRefs(csp));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (csp) {
|
|
|
|
channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
|
|
|
|
channelPolicy->SetContentSecurityPolicy(csp);
|
|
|
|
channelPolicy->SetLoadType(nsIContentPolicy::TYPE_STYLESHEET);
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_TIMELINE
|
2003-01-05 22:00:18 +03:00
|
|
|
NS_TIMELINE_MARK_URI("Loading style sheet: %s", aLoadData->mURI);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_TIMELINE_INDENT();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
2010-05-22 01:03:02 +04:00
|
|
|
aLoadData->mURI, nsnull, loadGroup, nsnull,
|
|
|
|
nsIChannel::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI,
|
|
|
|
channelPolicy);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2008-07-12 01:13:01 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mSyncCallback = PR_FALSE;
|
|
|
|
#endif
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG_ERROR((" Failed to create channel"));
|
2005-09-12 22:41:15 +04:00
|
|
|
SheetComplete(aLoadData, rv);
|
2002-12-03 08:48:14 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel) {
|
|
|
|
// send a minimal Accept header for text/css
|
|
|
|
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
|
|
|
NS_LITERAL_CSTRING("text/css,*/*;q=0.1"),
|
|
|
|
PR_FALSE);
|
2004-08-18 06:32:25 +04:00
|
|
|
nsCOMPtr<nsIURI> referrerURI = aLoadData->GetReferrerURI();
|
|
|
|
if (referrerURI)
|
|
|
|
httpChannel->SetReferrer(referrerURI);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2003-06-24 01:00:46 +04:00
|
|
|
// Now tell the channel we expect text/css data back.... We do
|
|
|
|
// this before opening it, so it's only treated as a hint.
|
|
|
|
channel->SetContentType(NS_LITERAL_CSTRING("text/css"));
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (aLoadData->mLoaderPrincipal) {
|
|
|
|
PRBool inherit;
|
|
|
|
rv = NS_URIChainHasFlags(aLoadData->mURI,
|
|
|
|
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
|
|
|
|
&inherit);
|
2008-03-22 19:50:47 +03:00
|
|
|
if ((NS_SUCCEEDED(rv) && inherit) ||
|
|
|
|
(nsContentUtils::URIIsLocalFile(aLoadData->mURI) &&
|
|
|
|
NS_SUCCEEDED(aLoadData->mLoaderPrincipal->
|
|
|
|
CheckMayLoad(aLoadData->mURI, PR_FALSE)))) {
|
2007-05-01 23:26:15 +04:00
|
|
|
channel->SetOwner(aLoadData->mLoaderPrincipal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// We don't have to hold on to the stream loader. The ownership
|
|
|
|
// model is: Necko owns the stream loader, which owns the load data,
|
|
|
|
// which owns us
|
|
|
|
nsCOMPtr<nsIUnicharStreamLoader> streamLoader;
|
2008-03-22 19:50:47 +03:00
|
|
|
rv = NS_NewUnicharStreamLoader(getter_AddRefs(streamLoader), aLoadData);
|
2006-10-25 01:47:40 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = channel->AsyncOpen(streamLoader, nsnull);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mSyncCallback = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG_ERROR((" Failed to create stream loader"));
|
2005-09-12 22:41:15 +04:00
|
|
|
SheetComplete(aLoadData, rv);
|
2002-12-03 08:48:14 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (!mLoadingDatas.Put(&key, aLoadData)) {
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG_ERROR((" Failed to put data in loading table"));
|
|
|
|
aLoadData->mIsCancelled = PR_TRUE;
|
|
|
|
channel->Cancel(NS_ERROR_OUT_OF_MEMORY);
|
2009-01-28 14:22:08 +03:00
|
|
|
SheetComplete(aLoadData, NS_ERROR_OUT_OF_MEMORY);
|
2005-09-12 22:41:15 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
aLoadData->mIsLoading = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
/**
|
|
|
|
* ParseSheet handles parsing the data stream. The main idea here is
|
|
|
|
* to push the current load data onto the parse stack before letting
|
|
|
|
* the CSS parser at the data stream. That lets us handle @import
|
|
|
|
* correctly.
|
|
|
|
*/
|
1999-05-19 03:15:10 +04:00
|
|
|
nsresult
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::ParseSheet(nsIUnicharInputStream* aStream,
|
|
|
|
SheetLoadData* aLoadData,
|
|
|
|
PRBool& aCompleted)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::ParseSheet"));
|
2002-12-03 08:48:14 +03:00
|
|
|
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");
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2010-05-20 03:22:19 +04:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
nsCAutoString spec__("N/A");
|
|
|
|
if (aLoadData->mURI) aLoadData->mURI->GetSpec(spec__);
|
|
|
|
NS_TIME_FUNCTION_FMT("Parsing stylesheet (url: %s)", spec__.get());
|
|
|
|
#endif
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
aCompleted = PR_FALSE;
|
2003-07-18 04:35:49 +04:00
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
nsCSSParser parser(this, aLoadData->mSheet);
|
|
|
|
if (!parser) {
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG_ERROR((" Failed to get CSS parser"));
|
2010-03-02 23:59:32 +03:00
|
|
|
SheetComplete(aLoadData, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push our load data on the stack so any kids can pick it up
|
|
|
|
mParsingDatas.AppendElement(aLoadData);
|
2010-05-18 08:00:40 +04:00
|
|
|
nsIURI* sheetURI = aLoadData->mSheet->GetSheetURI();
|
|
|
|
nsIURI* baseURI = aLoadData->mSheet->GetBaseURI();
|
2010-03-02 23:59:32 +03:00
|
|
|
nsresult rv = parser.Parse(aStream, sheetURI, baseURI,
|
|
|
|
aLoadData->mSheet->Principal(),
|
|
|
|
aLoadData->mLineNumber,
|
|
|
|
aLoadData->mAllowUnsafeRules);
|
2009-02-03 17:42:18 +03:00
|
|
|
mParsingDatas.RemoveElementAt(mParsingDatas.Length() - 1);
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG_ERROR((" Low-level error in parser!"));
|
|
|
|
SheetComplete(aLoadData, rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2002-12-11 03:28:47 +03:00
|
|
|
NS_ASSERTION(aLoadData->mPendingChildren == 0 || !aLoadData->mSyncLoad,
|
|
|
|
"Sync load has leftover pending children!");
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (aLoadData->mPendingChildren == 0) {
|
|
|
|
LOG((" No pending kids from parse"));
|
|
|
|
aCompleted = PR_TRUE;
|
2005-09-12 22:41:15 +04:00
|
|
|
SheetComplete(aLoadData, NS_OK);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
// Otherwise, the children are holding strong refs to the data and
|
|
|
|
// will call SheetComplete() on it when they complete.
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SheetComplete is the do-it-all cleanup function. It removes the
|
|
|
|
* load data from the "loading" hashtable, adds the sheet to the
|
|
|
|
* "completed" hashtable, massages the XUL cache, handles siblings of
|
2005-09-12 22:41:15 +04:00
|
|
|
* the load data (other loads for the same URI), handles unblocking
|
2002-12-03 08:48:14 +03:00
|
|
|
* blocked parent loads as needed, and most importantly calls
|
|
|
|
* NS_RELEASE on the load data to destroy the whole mess.
|
|
|
|
*/
|
|
|
|
void
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::SheetComplete(SheetLoadData* aLoadData, nsresult aStatus)
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::SheetComplete"));
|
2007-04-21 02:59:18 +04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// are rare.
|
|
|
|
nsAutoTArray<nsRefPtr<SheetLoadData>, 8> datasToNotify;
|
|
|
|
DoSheetComplete(aLoadData, aStatus, datasToNotify);
|
|
|
|
|
|
|
|
// Now it's safe to go ahead and notify observers
|
|
|
|
PRUint32 count = datasToNotify.Length();
|
2007-05-31 05:42:48 +04:00
|
|
|
mDatasToNotifyOn += count;
|
2007-04-21 02:59:18 +04:00
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
2007-05-31 05:42:48 +04:00
|
|
|
--mDatasToNotifyOn;
|
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
SheetLoadData* data = datasToNotify[i];
|
2007-05-31 05:42:48 +04:00
|
|
|
NS_ASSERTION(data && data->mMustNotify, "How did this data get here?");
|
|
|
|
if (data->mObserver) {
|
2009-03-30 19:25:35 +04:00
|
|
|
LOG((" Notifying observer 0x%x for data 0x%x. wasAlternate: %d",
|
2007-05-31 05:42:48 +04:00
|
|
|
data->mObserver.get(), data, data->mWasAlternate));
|
|
|
|
data->mObserver->StyleSheetLoaded(data->mSheet, data->mWasAlternate,
|
|
|
|
aStatus);
|
|
|
|
}
|
|
|
|
|
2007-12-22 03:56:28 +03:00
|
|
|
nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver> >::ForwardIterator iter(mObservers);
|
2007-05-31 05:42:48 +04:00
|
|
|
nsCOMPtr<nsICSSLoaderObserver> obs;
|
2007-12-20 10:30:04 +03:00
|
|
|
while (iter.HasMore()) {
|
|
|
|
obs = iter.GetNext();
|
2007-05-31 05:42:48 +04:00
|
|
|
LOG((" Notifying global observer 0x%x for data 0x%s. wasAlternate: %d",
|
|
|
|
obs.get(), data, data->mWasAlternate));
|
|
|
|
obs->StyleSheetLoaded(data->mSheet, data->mWasAlternate, aStatus);
|
|
|
|
}
|
2007-04-21 02:59:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mLoadingDatas.Count() == 0 && mPendingDatas.Count() > 0) {
|
|
|
|
LOG((" No more loading sheets; starting alternates"));
|
2007-05-31 05:42:48 +04:00
|
|
|
StartAlternateLoads();
|
2007-04-21 02:59:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
|
|
|
|
LoadDataArray& aDatasToNotify)
|
2007-04-21 02:59:18 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::DoSheetComplete"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aLoadData, "Must have a load data!");
|
|
|
|
NS_PRECONDITION(aLoadData->mSheet, "Must have a sheet");
|
2003-07-27 19:20:11 +04:00
|
|
|
NS_ASSERTION(mLoadingDatas.IsInitialized(),"mLoadingDatas should be initialized by now.");
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG(("Load completed, status: 0x%x", aStatus));
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
// Twiddle the hashtables
|
|
|
|
if (aLoadData->mURI) {
|
|
|
|
LOG_URI(" Finished loading: '%s'", aLoadData->mURI);
|
|
|
|
// Remove the data from the list of loading datas
|
|
|
|
if (aLoadData->mIsLoading) {
|
2010-03-03 00:00:53 +03:00
|
|
|
URIAndPrincipalHashKey key(aLoadData->mURI,
|
|
|
|
aLoadData->mLoaderPrincipal);
|
2003-07-27 19:46:52 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
SheetLoadData *loadingData;
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ASSERTION(mLoadingDatas.Get(&key, &loadingData) &&
|
2003-07-27 19:46:52 +04:00
|
|
|
loadingData == aLoadData,
|
|
|
|
"Bad loading table");
|
|
|
|
#endif
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
mLoadingDatas.Remove(&key);
|
2002-12-03 08:48:14 +03:00
|
|
|
aLoadData->mIsLoading = PR_FALSE;
|
1999-09-30 05:39:57 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go through and deal with the whole linked list.
|
|
|
|
SheetLoadData* data = aLoadData;
|
|
|
|
while (data) {
|
2002-01-09 08:56:43 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
data->mSheet->SetModified(PR_FALSE); // it's clean
|
|
|
|
data->mSheet->SetComplete();
|
2007-05-31 05:42:48 +04:00
|
|
|
if (data->mMustNotify && (data->mObserver || !mObservers.IsEmpty())) {
|
2007-04-21 02:59:18 +04:00
|
|
|
// Don't notify here so we don't trigger script. Remember the
|
|
|
|
// info we need to notify, then do it later when it's safe.
|
|
|
|
aDatasToNotify.AppendElement(data);
|
2005-09-12 22:41:15 +04:00
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
// On append failure, just press on. We'll fail to notify the observer,
|
|
|
|
// but not much we can do about that....
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2002-08-28 03:47:25 +04:00
|
|
|
|
2003-01-07 03:37:19 +03:00
|
|
|
NS_ASSERTION(!data->mParentData ||
|
|
|
|
data->mParentData->mPendingChildren != 0,
|
|
|
|
"Broken pending child count on our parent");
|
|
|
|
|
2003-01-07 04:13:07 +03:00
|
|
|
// If we have a parent, our parent is no longer being parsed, and
|
|
|
|
// we are the last pending child, then our load completion
|
|
|
|
// completes the parent too. Note that the parent _can_ still be
|
|
|
|
// being parsed (eg if the child (us) failed to open the channel
|
|
|
|
// or some such).
|
2002-12-03 08:48:14 +03:00
|
|
|
if (data->mParentData &&
|
|
|
|
--(data->mParentData->mPendingChildren) == 0 &&
|
2009-02-03 17:42:18 +03:00
|
|
|
!mParsingDatas.Contains(data->mParentData)) {
|
2007-04-21 02:59:18 +04:00
|
|
|
DoSheetComplete(data->mParentData, aStatus, aDatasToNotify);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
data = data->mNext;
|
|
|
|
}
|
2002-08-28 03:47:25 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Now that it's marked complete, put the sheet in our cache
|
2005-09-12 22:41:15 +04:00
|
|
|
if (NS_SUCCEEDED(aStatus) && aLoadData->mURI) {
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2003-01-17 07:20:03 +03:00
|
|
|
if (IsChromeURI(aLoadData->mURI)) {
|
2007-03-12 08:53:33 +03:00
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
|
|
|
if (cache && cache->IsEnabled()) {
|
|
|
|
if (!cache->GetStyleSheet(aLoadData->mURI)) {
|
|
|
|
LOG((" Putting sheet in XUL prototype cache"));
|
|
|
|
cache->PutStyleSheet(aLoadData->mSheet);
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-17 07:20:03 +03:00
|
|
|
else {
|
2002-12-03 08:48:14 +03:00
|
|
|
#endif
|
2010-03-03 00:00:53 +03:00
|
|
|
URIAndPrincipalHashKey key(aLoadData->mURI,
|
|
|
|
aLoadData->mLoaderPrincipal);
|
2007-05-01 23:26:15 +04:00
|
|
|
mCompleteSheets.Put(&key, aLoadData->mSheet);
|
2003-04-11 04:56:27 +04:00
|
|
|
#ifdef MOZ_XUL
|
2003-01-17 07:20:03 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
NS_RELEASE(aLoadData); // this will release parents and siblings and all that
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::LoadInlineStyle(nsIContent* aElement,
|
|
|
|
nsIUnicharInputStream* aStream,
|
|
|
|
PRUint32 aLineNumber,
|
2010-03-08 12:34:55 +03:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aMedia,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool* aCompleted,
|
|
|
|
PRBool* aIsAlternate)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadInlineStyle"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aStream, "Must have a stream to parse!");
|
2009-02-03 17:42:18 +03:00
|
|
|
NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
*aCompleted = PR_TRUE;
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!mEnabled) {
|
|
|
|
LOG_WARN((" Not enabled"));
|
2002-10-11 04:38:29 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2002-10-11 04:38:29 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement));
|
|
|
|
NS_ASSERTION(owningElement, "Element is not a style linking element!");
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
// Since we're not planning to load a URI, no need to hand a principal to the
|
|
|
|
// load data or to CreateSheet().
|
2002-12-03 08:48:14 +03:00
|
|
|
StyleSheetState state;
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet;
|
2007-05-01 23:26:15 +04:00
|
|
|
nsresult rv = CreateSheet(nsnull, aElement, nsnull, PR_FALSE, state,
|
2003-07-18 05:26:47 +04:00
|
|
|
getter_AddRefs(sheet));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(state == eSheetNeedsParser,
|
|
|
|
"Inline sheets should not be cached");
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
rv = PrepareSheet(sheet, aTitle, aMedia, nsnull, PR_FALSE,
|
|
|
|
aIsAlternate);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG((" Sheet is alternate: %d", *aIsAlternate));
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
rv = InsertSheetInDoc(sheet, aElement, mDocument);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
SheetLoadData* data = new SheetLoadData(this, aTitle, nsnull, sheet,
|
|
|
|
owningElement, *aIsAlternate,
|
2007-05-01 23:26:15 +04:00
|
|
|
aObserver, nsnull);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
sheet->SetComplete();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
// We never actually load this, so just set its principal directly
|
|
|
|
sheet->SetPrincipal(aElement->NodePrincipal());
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ADDREF(data);
|
2004-09-09 21:32:35 +04:00
|
|
|
data->mLineNumber = aLineNumber;
|
2002-12-03 08:48:14 +03:00
|
|
|
// Parse completion releases the load data
|
2005-09-12 22:41:15 +04:00
|
|
|
rv = ParseSheet(aStream, data, *aCompleted);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If aCompleted is true, |data| may well be deleted by now.
|
|
|
|
if (!*aCompleted) {
|
|
|
|
data->mMustNotify = PR_TRUE;
|
|
|
|
}
|
|
|
|
return rv;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::LoadStyleLink(nsIContent* aElement,
|
|
|
|
nsIURI* aURL,
|
2010-03-08 12:34:55 +03:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aMedia,
|
2010-03-03 00:00:53 +03:00
|
|
|
PRBool aHasAlternateRel,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool* aIsAlternate)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadStyleLink"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aURL, "Must have URL to load");
|
2009-02-03 17:42:18 +03:00
|
|
|
NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
|
2002-10-11 04:38:29 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG_URI(" Link uri: '%s'", aURL);
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG((" Link title: '%s'", NS_ConvertUTF16toUTF8(aTitle).get()));
|
|
|
|
LOG((" Link media: '%s'", NS_ConvertUTF16toUTF8(aMedia).get()));
|
|
|
|
LOG((" Link alternate rel: %d", aHasAlternateRel));
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!mEnabled) {
|
|
|
|
LOG_WARN((" Not enabled"));
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
1999-05-27 03:52:37 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_INITIALIZED);
|
2000-05-27 09:22:39 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
nsIPrincipal* principal =
|
|
|
|
aElement ? aElement->NodePrincipal() : mDocument->NodePrincipal();
|
|
|
|
|
2004-07-27 21:15:53 +04:00
|
|
|
nsISupports* context = aElement;
|
|
|
|
if (!context) {
|
|
|
|
context = mDocument;
|
2004-05-13 22:34:18 +04:00
|
|
|
}
|
2007-08-08 05:16:09 +04:00
|
|
|
nsresult rv = CheckLoadAllowed(principal, aURL, context);
|
2001-11-17 05:36:05 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-05-27 03:52:37 +04:00
|
|
|
|
2003-04-05 03:57:06 +04:00
|
|
|
LOG((" Passed load check"));
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
StyleSheetState state;
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet;
|
2007-05-01 23:26:15 +04:00
|
|
|
rv = CreateSheet(aURL, aElement, principal, PR_FALSE, state,
|
2002-12-11 03:28:47 +03:00
|
|
|
getter_AddRefs(sheet));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
rv = PrepareSheet(sheet, aTitle, aMedia, nsnull, aHasAlternateRel,
|
|
|
|
aIsAlternate);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-09-12 22:41:15 +04:00
|
|
|
|
|
|
|
LOG((" Sheet is alternate: %d", *aIsAlternate));
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
rv = InsertSheetInDoc(sheet, aElement, mDocument);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (state == eSheetComplete) {
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG((" Sheet already complete: 0x%p",
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<void*>(sheet.get())));
|
2007-04-21 02:59:18 +04:00
|
|
|
if (aObserver) {
|
|
|
|
rv = PostLoadEvent(aURL, sheet, aObserver, *aIsAlternate);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2000-07-28 13:36:51 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement));
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Now we need to actually load it
|
2007-04-21 02:59:18 +04:00
|
|
|
SheetLoadData* data = new SheetLoadData(this, aTitle, aURL, sheet,
|
|
|
|
owningElement, *aIsAlternate,
|
2007-05-01 23:26:15 +04:00
|
|
|
aObserver, principal);
|
2002-12-03 08:48:14 +03:00
|
|
|
if (!data) {
|
|
|
|
sheet->SetComplete();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
NS_ADDREF(data);
|
|
|
|
|
|
|
|
// If we have to parse and it's an alternate non-inline, defer it
|
|
|
|
if (aURL && state == eSheetNeedsParser && mLoadingDatas.Count() != 0 &&
|
2005-09-12 22:41:15 +04:00
|
|
|
*aIsAlternate) {
|
2002-12-03 08:48:14 +03:00
|
|
|
LOG((" Deferring alternate sheet load"));
|
2010-03-03 00:00:53 +03:00
|
|
|
URIAndPrincipalHashKey key(data->mURI, data->mLoaderPrincipal);
|
2007-05-01 23:26:15 +04:00
|
|
|
if (!mPendingDatas.Put(&key, data)) {
|
2005-09-12 22:41:15 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->mMustNotify = PR_TRUE;
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load completion will free the data
|
2005-09-12 22:41:15 +04:00
|
|
|
rv = LoadSheet(data, state);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
data->mMustNotify = PR_TRUE;
|
|
|
|
return rv;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
2010-05-12 00:41:47 +04:00
|
|
|
Loader::LoadChildSheet(nsCSSStyleSheet* aParentSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIURI* aURL,
|
|
|
|
nsMediaList* aMedia,
|
|
|
|
nsICSSImportRule* aParentRule)
|
1999-05-19 03:15:10 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadChildSheet"));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aURL, "Must have a URI to load");
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_PRECONDITION(aParentSheet, "Must have a parent sheet");
|
2002-10-11 04:38:29 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (!mEnabled) {
|
|
|
|
LOG_WARN((" Not enabled"));
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_URI(" Child uri: '%s'", aURL);
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2004-05-13 22:34:18 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> owningNode;
|
|
|
|
|
|
|
|
// check for an owning document: if none, don't bother walking up the parent
|
|
|
|
// sheets
|
2010-05-18 08:00:40 +04:00
|
|
|
if (aParentSheet->GetOwningDocument()) {
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCOMPtr<nsIDOMStyleSheet> nextParentSheet(aParentSheet);
|
2004-05-13 22:34:18 +04:00
|
|
|
NS_ENSURE_TRUE(nextParentSheet, NS_ERROR_FAILURE); //Not a stylesheet!?
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMStyleSheet> topSheet;
|
|
|
|
//traverse our way to the top-most sheet
|
|
|
|
do {
|
|
|
|
topSheet.swap(nextParentSheet);
|
|
|
|
topSheet->GetParentStyleSheet(getter_AddRefs(nextParentSheet));
|
|
|
|
} while (nextParentSheet);
|
|
|
|
|
|
|
|
topSheet->GetOwnerNode(getter_AddRefs(owningNode));
|
|
|
|
}
|
|
|
|
|
2004-07-27 21:15:53 +04:00
|
|
|
nsISupports* context = owningNode;
|
|
|
|
if (!context) {
|
|
|
|
context = mDocument;
|
2004-05-13 22:34:18 +04:00
|
|
|
}
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
nsIPrincipal* principal = aParentSheet->Principal();
|
2010-05-13 00:18:47 +04:00
|
|
|
nsresult rv = CheckLoadAllowed(principal, aURL, context);
|
2002-12-03 08:48:14 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2003-04-05 03:57:06 +04:00
|
|
|
LOG((" Passed load check"));
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
SheetLoadData* parentData = nsnull;
|
|
|
|
nsCOMPtr<nsICSSLoaderObserver> observer;
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
PRInt32 count = mParsingDatas.Length();
|
2002-12-03 08:48:14 +03:00
|
|
|
if (count > 0) {
|
|
|
|
LOG((" Have a parent load"));
|
2009-02-03 17:42:18 +03:00
|
|
|
parentData = mParsingDatas.ElementAt(count - 1);
|
2002-12-03 08:48:14 +03:00
|
|
|
// Check for cycles
|
|
|
|
SheetLoadData* data = parentData;
|
|
|
|
while (data && data->mURI) {
|
|
|
|
PRBool equal;
|
|
|
|
if (NS_SUCCEEDED(data->mURI->Equals(aURL, &equal)) && equal) {
|
|
|
|
// Houston, we have a loop, blow off this child and pretend this never
|
|
|
|
// happened
|
|
|
|
LOG_ERROR((" @import cycle detected, dropping load"));
|
|
|
|
return NS_OK;
|
2000-07-28 13:36:51 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
data = data->mParentData;
|
2000-07-28 13:36:51 +04:00
|
|
|
}
|
|
|
|
|
2003-07-09 05:48:20 +04:00
|
|
|
NS_ASSERTION(parentData->mSheet == aParentSheet,
|
2002-12-03 08:48:14 +03:00
|
|
|
"Unexpected call to LoadChildSheet");
|
|
|
|
} else {
|
|
|
|
LOG((" No parent load; must be CSSOM"));
|
|
|
|
// No parent load data, so the sheet will need to be notified when
|
|
|
|
// we finish, if it can be, if we do the load asynchronously.
|
2010-05-12 00:41:47 +04:00
|
|
|
observer = aParentSheet;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Now that we know it's safe to load this (passes security check and not a
|
|
|
|
// loop) do so
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet;
|
2002-12-03 08:48:14 +03:00
|
|
|
StyleSheetState state;
|
2007-05-01 23:26:15 +04:00
|
|
|
rv = CreateSheet(aURL, nsnull, principal,
|
2002-12-11 03:28:47 +03:00
|
|
|
parentData ? parentData->mSyncLoad : PR_FALSE,
|
|
|
|
state, getter_AddRefs(sheet));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& empty = EmptyString();
|
2004-01-10 05:27:41 +03:00
|
|
|
rv = PrepareSheet(sheet, empty, empty, aMedia);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = InsertChildSheet(sheet, aParentSheet, aParentRule);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (state == eSheetComplete) {
|
|
|
|
LOG((" Sheet already complete"));
|
|
|
|
// We're completely done. No need to notify, even, since the
|
|
|
|
// @import rule addition/modification will trigger the right style
|
|
|
|
// changes automatically.
|
|
|
|
return NS_OK;
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
SheetLoadData* data = new SheetLoadData(this, aURL, sheet, parentData,
|
2007-05-01 23:26:15 +04:00
|
|
|
observer, principal);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
sheet->SetComplete();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(data);
|
2005-09-16 19:38:04 +04:00
|
|
|
PRBool syncLoad = data->mSyncLoad;
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
// Load completion will release the data
|
2005-09-12 22:41:15 +04:00
|
|
|
rv = LoadSheet(data, state);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-09-16 19:38:04 +04:00
|
|
|
// If syncLoad is true, |data| will be deleted by now.
|
|
|
|
if (!syncLoad) {
|
|
|
|
data->mMustNotify = PR_TRUE;
|
|
|
|
}
|
2005-09-12 22:41:15 +04:00
|
|
|
return rv;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::LoadSheetSync(nsIURI* aURL, PRBool aAllowUnsafeRules,
|
|
|
|
PRBool aUseSystemPrincipal,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet** aSheet)
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadSheetSync"));
|
2009-03-17 04:38:36 +03:00
|
|
|
return InternalLoadNonDocumentSheet(aURL, aAllowUnsafeRules,
|
|
|
|
aUseSystemPrincipal, nsnull,
|
2009-04-10 18:29:08 +04:00
|
|
|
EmptyCString(), aSheet, nsnull);
|
1999-05-19 03:15:10 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::LoadSheet(nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal,
|
|
|
|
const nsCString& aCharset,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet** aSheet)
|
2006-11-12 01:27:00 +03:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadSheet(aURL, aObserver, aSheet) api call"));
|
2006-11-12 01:27:00 +03:00
|
|
|
NS_PRECONDITION(aSheet, "aSheet is null");
|
2009-03-17 04:38:36 +03:00
|
|
|
return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE,
|
2009-04-10 18:29:08 +04:00
|
|
|
aOriginPrincipal, aCharset,
|
2007-08-08 05:16:09 +04:00
|
|
|
aSheet, aObserver);
|
2006-11-12 01:27:00 +03:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::LoadSheet(nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal,
|
|
|
|
const nsCString& aCharset,
|
|
|
|
nsICSSLoaderObserver* aObserver)
|
1999-05-27 03:52:37 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::LoadSheet(aURL, aObserver) api call"));
|
2009-03-17 04:38:36 +03:00
|
|
|
return InternalLoadNonDocumentSheet(aURL, PR_FALSE, PR_FALSE,
|
2009-04-10 18:29:08 +04:00
|
|
|
aOriginPrincipal, aCharset,
|
2007-08-08 05:16:09 +04:00
|
|
|
nsnull, aObserver);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::InternalLoadNonDocumentSheet(nsIURI* aURL,
|
|
|
|
PRBool aAllowUnsafeRules,
|
|
|
|
PRBool aUseSystemPrincipal,
|
|
|
|
nsIPrincipal* aOriginPrincipal,
|
|
|
|
const nsCString& aCharset,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet** aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSLoaderObserver* aObserver)
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL, "Must have a URI to load");
|
2006-11-18 01:45:52 +03:00
|
|
|
NS_PRECONDITION(aSheet || aObserver, "Sheet and observer can't both be null");
|
2009-03-17 04:38:36 +03:00
|
|
|
NS_PRECONDITION(!aUseSystemPrincipal || !aObserver,
|
|
|
|
"Shouldn't load system-principal sheets async");
|
2009-02-03 17:42:18 +03:00
|
|
|
NS_ASSERTION(mParsingDatas.Length() == 0, "We're in the middle of a parse?");
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
LOG_URI(" Non-document sheet uri: '%s'", aURL);
|
|
|
|
|
|
|
|
if (aSheet) {
|
|
|
|
*aSheet = nsnull;
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!mEnabled) {
|
|
|
|
LOG_WARN((" Not enabled"));
|
2002-10-11 04:38:29 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2007-08-08 05:16:09 +04:00
|
|
|
nsresult rv = CheckLoadAllowed(aOriginPrincipal, aURL, mDocument);
|
2007-07-11 23:44:27 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
StyleSheetState state;
|
2010-05-12 00:41:47 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet;
|
2002-12-11 03:28:47 +03:00
|
|
|
PRBool syncLoad = (aObserver == nsnull);
|
|
|
|
|
2009-03-31 23:04:01 +04:00
|
|
|
rv = CreateSheet(aURL, nsnull, aOriginPrincipal, syncLoad, state,
|
2007-07-11 23:44:27 +04:00
|
|
|
getter_AddRefs(sheet));
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
const nsSubstring& empty = EmptyString();
|
2004-01-10 05:27:41 +03:00
|
|
|
rv = PrepareSheet(sheet, empty, empty, nsnull);
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-10-11 04:38:29 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (state == eSheetComplete) {
|
|
|
|
LOG((" Sheet already complete"));
|
2006-11-12 01:27:00 +03:00
|
|
|
if (aObserver) {
|
2007-04-21 02:59:18 +04:00
|
|
|
rv = PostLoadEvent(aURL, sheet, aObserver, PR_FALSE);
|
2006-11-12 01:27:00 +03:00
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
if (aSheet) {
|
2005-09-12 22:41:15 +04:00
|
|
|
sheet.swap(*aSheet);
|
1999-05-27 03:52:37 +04:00
|
|
|
}
|
2005-09-12 22:41:15 +04:00
|
|
|
return rv;
|
1999-05-27 03:52:37 +04:00
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2006-06-15 07:20:19 +04:00
|
|
|
SheetLoadData* data =
|
2007-07-11 23:44:27 +04:00
|
|
|
new SheetLoadData(this, aURL, sheet, syncLoad, aAllowUnsafeRules,
|
2009-04-10 18:29:08 +04:00
|
|
|
aUseSystemPrincipal, aCharset, aObserver,
|
|
|
|
aOriginPrincipal);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
sheet->SetComplete();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(data);
|
|
|
|
rv = LoadSheet(data, state);
|
2005-09-12 22:41:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (aSheet) {
|
|
|
|
sheet.swap(*aSheet);
|
2006-11-12 01:27:00 +03:00
|
|
|
}
|
|
|
|
if (aObserver) {
|
2005-09-12 22:41:15 +04:00
|
|
|
data->mMustNotify = PR_TRUE;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1999-05-19 03:15:10 +04:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
nsresult
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::PostLoadEvent(nsIURI* aURI,
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
|
|
|
PRBool aWasAlternate)
|
2005-09-12 22:41:15 +04:00
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
LOG(("css::Loader::PostLoadEvent"));
|
2005-09-12 22:41:15 +04:00
|
|
|
NS_PRECONDITION(aSheet, "Must have sheet");
|
2007-04-21 02:59:18 +04:00
|
|
|
NS_PRECONDITION(aObserver, "Must have observer");
|
2005-09-12 22:41:15 +04:00
|
|
|
|
2007-02-05 21:09:26 +03:00
|
|
|
nsRefPtr<SheetLoadData> evt =
|
2005-09-12 22:41:15 +04:00
|
|
|
new SheetLoadData(this, EmptyString(), // title doesn't matter here
|
|
|
|
aURI,
|
|
|
|
aSheet,
|
|
|
|
nsnull, // owning element doesn't matter here
|
|
|
|
aWasAlternate,
|
2007-05-01 23:26:15 +04:00
|
|
|
aObserver,
|
|
|
|
nsnull);
|
2005-09-12 22:41:15 +04:00
|
|
|
NS_ENSURE_TRUE(evt, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
if (!mPostedEvents.AppendElement(evt)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2005-09-12 22:41:15 +04:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(evt);
|
2005-09-12 22:41:15 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_WARNING("failed to dispatch stylesheet load event");
|
2007-02-05 21:09:26 +03:00
|
|
|
mPostedEvents.RemoveElement(evt);
|
2005-09-12 22:41:15 +04:00
|
|
|
} else {
|
2007-02-05 21:09:26 +03:00
|
|
|
// We'll unblock onload when we handle the event.
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->BlockOnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to notify the observer for this data.
|
2005-09-12 22:41:15 +04:00
|
|
|
evt->mMustNotify = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::HandleLoadEvent(SheetLoadData* aEvent)
|
2005-09-12 22:41:15 +04:00
|
|
|
{
|
|
|
|
// XXXbz can't assert this yet.... May not have an observer because
|
|
|
|
// we're unblocking the parser
|
|
|
|
// NS_ASSERTION(aEvent->mObserver, "Must have observer");
|
|
|
|
NS_ASSERTION(aEvent->mSheet, "Must have sheet");
|
|
|
|
if (!aEvent->mIsCancelled) {
|
2007-02-05 21:09:26 +03:00
|
|
|
// SheetComplete will call Release(), so give it a reference to do
|
|
|
|
// that with.
|
2005-09-12 22:41:15 +04:00
|
|
|
NS_ADDREF(aEvent);
|
|
|
|
SheetComplete(aEvent, NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
mPostedEvents.RemoveElement(aEvent);
|
2007-02-05 21:09:26 +03:00
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->UnblockOnload(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2010-03-03 00:00:53 +03:00
|
|
|
StopLoadingSheetCallback(URIAndPrincipalHashKey* aKey,
|
2007-05-01 23:26:15 +04:00
|
|
|
SheetLoadData*& aData,
|
|
|
|
void* aClosure)
|
2001-05-19 06:59:15 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_PRECONDITION(aData, "Must have a data!");
|
|
|
|
NS_PRECONDITION(aClosure, "Must have a loader");
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2003-07-27 19:20:11 +04:00
|
|
|
aData->mIsLoading = PR_FALSE; // we will handle the removal right here
|
|
|
|
aData->mIsCancelled = PR_TRUE;
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
static_cast<Loader::LoadDataArray*>(aClosure)->AppendElement(aData);
|
2001-05-19 06:59:15 +04:00
|
|
|
|
2003-07-27 19:20:11 +04:00
|
|
|
return PL_DHASH_REMOVE;
|
2001-05-19 06:59:15 +04:00
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::Stop()
|
2001-05-19 06:59:15 +04:00
|
|
|
{
|
2007-05-31 05:42:48 +04:00
|
|
|
PRUint32 pendingCount =
|
|
|
|
mPendingDatas.IsInitialized() ? mPendingDatas.Count() : 0;
|
|
|
|
PRUint32 loadingCount =
|
|
|
|
mLoadingDatas.IsInitialized() ? mLoadingDatas.Count() : 0;
|
|
|
|
LoadDataArray arr(pendingCount + loadingCount + mPostedEvents.Length());
|
|
|
|
|
|
|
|
if (pendingCount) {
|
|
|
|
mPendingDatas.Enumerate(StopLoadingSheetCallback, &arr);
|
2007-05-01 23:26:15 +04:00
|
|
|
}
|
2007-05-31 05:42:48 +04:00
|
|
|
if (loadingCount) {
|
|
|
|
mLoadingDatas.Enumerate(StopLoadingSheetCallback, &arr);
|
2007-05-01 23:26:15 +04:00
|
|
|
}
|
2007-05-31 05:42:48 +04:00
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i = 0; i < mPostedEvents.Length(); ++i) {
|
2007-02-05 21:09:26 +03:00
|
|
|
SheetLoadData* data = mPostedEvents[i];
|
|
|
|
data->mIsCancelled = PR_TRUE;
|
2007-05-31 05:42:48 +04:00
|
|
|
if (arr.AppendElement(data)) {
|
|
|
|
// SheetComplete() calls Release(), so give this an extra ref.
|
|
|
|
NS_ADDREF(data);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("We preallocated this memory... shouldn't really fail, "
|
|
|
|
"except we never check that preallocation succeeds.");
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-05 21:09:26 +03:00
|
|
|
}
|
2005-09-12 22:41:15 +04:00
|
|
|
mPostedEvents.Clear();
|
2007-05-31 05:42:48 +04:00
|
|
|
|
|
|
|
mDatasToNotifyOn += arr.Length();
|
|
|
|
for (i = 0; i < arr.Length(); ++i) {
|
|
|
|
--mDatasToNotifyOn;
|
|
|
|
SheetComplete(arr[i], NS_BINDING_ABORTED);
|
|
|
|
}
|
2001-05-19 06:59:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
PRBool
|
|
|
|
Loader::HasPendingLoads()
|
2007-05-31 05:42:48 +04:00
|
|
|
{
|
|
|
|
return
|
|
|
|
(mLoadingDatas.IsInitialized() && mLoadingDatas.Count() != 0) ||
|
|
|
|
(mPendingDatas.IsInitialized() && mPendingDatas.Count() != 0) ||
|
|
|
|
mPostedEvents.Length() != 0 ||
|
|
|
|
mDatasToNotifyOn != 0;
|
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult
|
|
|
|
Loader::AddObserver(nsICSSLoaderObserver* aObserver)
|
2007-05-31 05:42:48 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aObserver, "Must have observer");
|
2007-12-20 10:30:04 +03:00
|
|
|
if (mObservers.AppendElementUnlessExists(aObserver)) {
|
2007-05-31 05:42:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
void
|
|
|
|
Loader::RemoveObserver(nsICSSLoaderObserver* aObserver)
|
2007-05-31 05:42:48 +04:00
|
|
|
{
|
2007-12-22 03:56:28 +03:00
|
|
|
mObservers.RemoveElement(aObserver);
|
2007-05-31 05:42:48 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2010-03-03 00:00:53 +03:00
|
|
|
CollectLoadDatas(URIAndPrincipalHashKey *aKey,
|
2007-05-31 05:42:48 +04:00
|
|
|
SheetLoadData* &aData,
|
|
|
|
void* aClosure)
|
|
|
|
{
|
2010-03-03 00:00:53 +03:00
|
|
|
static_cast<Loader::LoadDataArray*>(aClosure)->AppendElement(aData);
|
2007-05-31 05:42:48 +04:00
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-03 00:00:53 +03:00
|
|
|
Loader::StartAlternateLoads()
|
2007-05-31 05:42:48 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mPendingDatas.IsInitialized(), "Don't call me!");
|
|
|
|
LoadDataArray arr(mPendingDatas.Count());
|
|
|
|
mPendingDatas.Enumerate(CollectLoadDatas, &arr);
|
|
|
|
|
|
|
|
mDatasToNotifyOn += arr.Length();
|
|
|
|
for (PRUint32 i = 0; i < arr.Length(); ++i) {
|
|
|
|
--mDatasToNotifyOn;
|
|
|
|
LoadSheet(arr[i], eSheetNeedsParser);
|
|
|
|
}
|
|
|
|
}
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|