2010-03-03 00:00:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/* loading of CSS style sheets using the network APIs */
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
#ifndef mozilla_css_Loader_h
|
|
|
|
#define mozilla_css_Loader_h
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCompatibility.h"
|
2014-07-02 02:37:09 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2010-03-03 00:00:53 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2014-05-09 19:23:14 +04:00
|
|
|
#include "nsStringFwd.h"
|
2010-03-03 00:00:53 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTObserverArray.h"
|
|
|
|
#include "nsURIHashKey.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-08-28 21:10:07 +04:00
|
|
|
#include "mozilla/CORSMode.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
#include "mozilla/StyleBackendType.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
#include "mozilla/StyleSheetHandle.h"
|
2014-11-18 16:46:47 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
class nsICSSLoaderObserver;
|
2016-09-08 04:59:40 +03:00
|
|
|
class nsIConsoleReportCollector;
|
2010-03-03 00:00:53 +03:00
|
|
|
class nsIContent;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsMediaList;
|
2011-09-27 01:27:00 +04:00
|
|
|
class nsIStyleSheetLinkingElement;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2013-01-09 03:25:47 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-01-09 03:25:47 +04:00
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-11-18 16:46:47 +03:00
|
|
|
class URIPrincipalReferrerPolicyAndCORSModeHashKey : public nsURIHashKey
|
2010-03-03 00:00:53 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-11-18 16:46:47 +03:00
|
|
|
typedef URIPrincipalReferrerPolicyAndCORSModeHashKey* KeyType;
|
|
|
|
typedef const URIPrincipalReferrerPolicyAndCORSModeHashKey* KeyTypePointer;
|
|
|
|
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
|
|
|
|
|
|
|
|
explicit URIPrincipalReferrerPolicyAndCORSModeHashKey(const URIPrincipalReferrerPolicyAndCORSModeHashKey* aKey)
|
|
|
|
: nsURIHashKey(aKey->mKey),
|
|
|
|
mPrincipal(aKey->mPrincipal),
|
|
|
|
mCORSMode(aKey->mCORSMode),
|
|
|
|
mReferrerPolicy(aKey->mReferrerPolicy)
|
2010-03-03 00:00:53 +03:00
|
|
|
{
|
2014-11-18 16:46:47 +03:00
|
|
|
MOZ_COUNT_CTOR(URIPrincipalReferrerPolicyAndCORSModeHashKey);
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
2014-11-18 16:46:47 +03:00
|
|
|
|
|
|
|
URIPrincipalReferrerPolicyAndCORSModeHashKey(nsIURI* aURI,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
CORSMode aCORSMode,
|
|
|
|
ReferrerPolicy aReferrerPolicy)
|
|
|
|
: nsURIHashKey(aURI),
|
|
|
|
mPrincipal(aPrincipal),
|
|
|
|
mCORSMode(aCORSMode),
|
|
|
|
mReferrerPolicy(aReferrerPolicy)
|
2010-03-03 00:00:53 +03:00
|
|
|
{
|
2014-11-18 16:46:47 +03:00
|
|
|
MOZ_COUNT_CTOR(URIPrincipalReferrerPolicyAndCORSModeHashKey);
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
2014-11-18 16:46:47 +03:00
|
|
|
URIPrincipalReferrerPolicyAndCORSModeHashKey(const URIPrincipalReferrerPolicyAndCORSModeHashKey& toCopy)
|
|
|
|
: nsURIHashKey(toCopy),
|
|
|
|
mPrincipal(toCopy.mPrincipal),
|
|
|
|
mCORSMode(toCopy.mCORSMode),
|
|
|
|
mReferrerPolicy(toCopy.mReferrerPolicy)
|
2010-03-03 00:00:53 +03:00
|
|
|
{
|
2014-11-18 16:46:47 +03:00
|
|
|
MOZ_COUNT_CTOR(URIPrincipalReferrerPolicyAndCORSModeHashKey);
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
2014-11-18 16:46:47 +03:00
|
|
|
~URIPrincipalReferrerPolicyAndCORSModeHashKey()
|
2010-03-03 00:00:53 +03:00
|
|
|
{
|
2014-11-18 16:46:47 +03:00
|
|
|
MOZ_COUNT_DTOR(URIPrincipalReferrerPolicyAndCORSModeHashKey);
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
|
|
|
|
2014-11-18 16:46:47 +03:00
|
|
|
URIPrincipalReferrerPolicyAndCORSModeHashKey* GetKey() const {
|
|
|
|
return const_cast<URIPrincipalReferrerPolicyAndCORSModeHashKey*>(this);
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
2014-11-18 16:46:47 +03:00
|
|
|
const URIPrincipalReferrerPolicyAndCORSModeHashKey* GetKeyPointer() const { return this; }
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2014-11-18 16:46:47 +03:00
|
|
|
bool KeyEquals(const URIPrincipalReferrerPolicyAndCORSModeHashKey* aKey) const {
|
2010-03-03 00:00:53 +03:00
|
|
|
if (!nsURIHashKey::KeyEquals(aKey->mKey)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPrincipal != !aKey->mPrincipal) {
|
|
|
|
// One or the other has a principal, but not both... not equal
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
|
|
|
|
2012-08-28 21:10:08 +04:00
|
|
|
if (mCORSMode != aKey->mCORSMode) {
|
|
|
|
// Different CORS modes; we don't match
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:46:47 +03:00
|
|
|
if (mReferrerPolicy != aKey->mReferrerPolicy) {
|
|
|
|
// Different ReferrerPolicy; we don't match
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool eq;
|
2010-03-03 00:00:53 +03:00
|
|
|
return !mPrincipal ||
|
|
|
|
(NS_SUCCEEDED(mPrincipal->Equals(aKey->mPrincipal, &eq)) && eq);
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:46:47 +03:00
|
|
|
static const URIPrincipalReferrerPolicyAndCORSModeHashKey*
|
|
|
|
KeyToPointer(URIPrincipalReferrerPolicyAndCORSModeHashKey* aKey) { return aKey; }
|
|
|
|
static PLDHashNumber HashKey(const URIPrincipalReferrerPolicyAndCORSModeHashKey* aKey) {
|
2010-03-03 00:00:53 +03:00
|
|
|
return nsURIHashKey::HashKey(aKey->mKey);
|
|
|
|
}
|
|
|
|
|
2013-07-16 01:28:33 +04:00
|
|
|
nsIURI* GetURI() const { return nsURIHashKey::GetKey(); }
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2012-08-28 21:10:08 +04:00
|
|
|
CORSMode mCORSMode;
|
2014-11-18 16:46:47 +03:00
|
|
|
ReferrerPolicy mReferrerPolicy;
|
2010-03-03 00:00:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
class SheetLoadData;
|
2011-03-17 20:41:52 +03:00
|
|
|
class ImportRule;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2015-09-18 08:27:00 +03:00
|
|
|
/*********************
|
|
|
|
* Style sheet reuse *
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
class MOZ_RAII LoaderReusableStyleSheets
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LoaderReusableStyleSheets()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look for a reusable sheet (see AddReusableSheet) matching the
|
|
|
|
* given URL. If found, set aResult, remove the reused sheet from
|
|
|
|
* the internal list, and return true. If not found, return false;
|
|
|
|
* in this case, aResult is not modified.
|
|
|
|
*
|
|
|
|
* @param aURL the url to match
|
|
|
|
* @param aResult [out] the style sheet which can be reused
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
bool FindReusableStyleSheet(nsIURI* aURL, RefPtr<CSSStyleSheet>& aResult);
|
2015-09-18 08:27:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicate that a certain style sheet is available for reuse if its
|
|
|
|
* URI matches the URI of an @import. Sheets should be added in the
|
|
|
|
* opposite order in which they are intended to be reused.
|
|
|
|
*
|
|
|
|
* @param aSheet the sheet which can be reused
|
|
|
|
*/
|
|
|
|
void AddReusableSheet(CSSStyleSheet* aSheet) {
|
|
|
|
mReusableSheets.AppendElement(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
LoaderReusableStyleSheets(const LoaderReusableStyleSheets&) = delete;
|
|
|
|
LoaderReusableStyleSheets& operator=(const LoaderReusableStyleSheets&) = delete;
|
|
|
|
|
|
|
|
// The sheets that can be reused.
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<CSSStyleSheet>> mReusableSheets;
|
2015-09-18 08:27:00 +03:00
|
|
|
};
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
/***********************************************************************
|
|
|
|
* Enum that describes the state of the sheet returned by CreateSheet. *
|
|
|
|
***********************************************************************/
|
|
|
|
enum StyleSheetState {
|
|
|
|
eSheetStateUnknown = 0,
|
|
|
|
eSheetNeedsParser,
|
|
|
|
eSheetPending,
|
|
|
|
eSheetLoading,
|
|
|
|
eSheetComplete
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Loader final {
|
2014-11-18 16:46:47 +03:00
|
|
|
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
public:
|
2016-02-24 10:01:12 +03:00
|
|
|
explicit Loader(StyleBackendType aType);
|
2014-08-08 03:48:38 +04:00
|
|
|
explicit Loader(nsIDocument*);
|
2014-03-21 05:16:20 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2010-03-03 00:00:53 +03:00
|
|
|
~Loader();
|
|
|
|
|
2014-03-21 05:16:20 +04:00
|
|
|
public:
|
2014-07-02 02:37:09 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Loader)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(Loader)
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
void DropDocumentReference(); // notification that doc is going away
|
|
|
|
|
|
|
|
void SetCompatibilityMode(nsCompatibility aCompatMode)
|
|
|
|
{ mCompatMode = aCompatMode; }
|
|
|
|
nsCompatibility GetCompatibilityMode() { return mCompatMode; }
|
|
|
|
nsresult SetPreferredSheet(const nsAString& aTitle);
|
|
|
|
|
|
|
|
// XXXbz sort out what the deal is with events! When should they fire?
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load an inline style sheet. If a successful result is returned and
|
|
|
|
* *aCompleted is false, then aObserver is guaranteed to be notified
|
|
|
|
* asynchronously once the sheet is marked complete. If an error is
|
|
|
|
* returned, or if *aCompleted is true, aObserver will not be notified. In
|
|
|
|
* addition to parsing the sheet, this method will insert it into the
|
|
|
|
* stylesheet list of this CSSLoader's document.
|
|
|
|
*
|
|
|
|
* @param aElement the element linking to the stylesheet. This must not be
|
|
|
|
* null and must implement nsIStyleSheetLinkingElement.
|
2011-05-19 05:22:59 +04:00
|
|
|
* @param aBuffer the stylesheet data
|
2010-03-03 00:00:53 +03:00
|
|
|
* @param aLineNumber the line number at which the stylesheet data started.
|
|
|
|
* @param aTitle the title of the sheet.
|
|
|
|
* @param aMedia the media string for the sheet.
|
|
|
|
* @param aObserver the observer to notify when the load completes.
|
|
|
|
* May be null.
|
|
|
|
* @param [out] aCompleted whether parsing of the sheet completed.
|
|
|
|
* @param [out] aIsAlternate whether the stylesheet ended up being an
|
|
|
|
* alternate sheet.
|
|
|
|
*/
|
|
|
|
nsresult LoadInlineStyle(nsIContent* aElement,
|
2011-05-19 05:22:59 +04:00
|
|
|
const nsAString& aBuffer,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLineNumber,
|
2010-03-03 00:00:53 +03:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aMedia,
|
2013-01-09 03:25:47 +04:00
|
|
|
mozilla::dom::Element* aScopeElement,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aCompleted,
|
|
|
|
bool* aIsAlternate);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a linked (document) stylesheet. If a successful result is returned,
|
|
|
|
* aObserver is guaranteed to be notified asynchronously once the sheet is
|
|
|
|
* loaded and marked complete. If an error is returned, aObserver will not
|
|
|
|
* be notified. In addition to loading the sheet, this method will insert it
|
|
|
|
* into the stylesheet list of this CSSLoader's document.
|
|
|
|
*
|
|
|
|
* @param aElement the element linking to the the stylesheet. May be null.
|
|
|
|
* @param aURL the URL of the sheet.
|
|
|
|
* @param aTitle the title of the sheet.
|
|
|
|
* @param aMedia the media string for the sheet.
|
|
|
|
* @param aHasAlternateRel whether the rel for this link included
|
|
|
|
* "alternate".
|
2012-08-28 21:10:07 +04:00
|
|
|
* @param aCORSMode the CORS mode for this load.
|
2010-03-03 00:00:53 +03:00
|
|
|
* @param aObserver the observer to notify when the load completes.
|
|
|
|
* May be null.
|
|
|
|
* @param [out] aIsAlternate whether the stylesheet actually ended up beinga
|
|
|
|
* an alternate sheet. Note that this need not match
|
|
|
|
* aHasAlternateRel.
|
|
|
|
*/
|
|
|
|
nsresult LoadStyleLink(nsIContent* aElement,
|
|
|
|
nsIURI* aURL,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aMedia,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aHasAlternateRel,
|
2012-08-28 21:10:08 +04:00
|
|
|
CORSMode aCORSMode,
|
2014-11-18 16:46:47 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2015-08-13 06:19:11 +03:00
|
|
|
const nsAString& aIntegrity,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aIsAlternate);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a child (@import-ed) style sheet. In addition to loading the sheet,
|
|
|
|
* this method will insert it into the child sheet list of aParentSheet. If
|
|
|
|
* there is no sheet currently being parsed and the child sheet is not
|
|
|
|
* complete when this method returns, then when the child sheet becomes
|
|
|
|
* complete aParentSheet will be QIed to nsICSSLoaderObserver and
|
|
|
|
* asynchronously notified, just like for LoadStyleLink. Note that if the
|
|
|
|
* child sheet is already complete when this method returns, no
|
|
|
|
* nsICSSLoaderObserver notification will be sent.
|
|
|
|
*
|
|
|
|
* @param aParentSheet the parent of this child sheet
|
|
|
|
* @param aURL the URL of the child sheet
|
|
|
|
* @param aMedia the already-parsed media list for the child sheet
|
|
|
|
* @param aRule the @import rule importing this child. This is used to
|
|
|
|
* properly order the child sheet list of aParentSheet.
|
2015-09-18 08:27:00 +03:00
|
|
|
* @param aSavedSheets any saved style sheets which could be reused
|
|
|
|
* for this load
|
2010-03-03 00:00:53 +03:00
|
|
|
*/
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult LoadChildSheet(StyleSheetHandle aParentSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIURI* aURL,
|
|
|
|
nsMediaList* aMedia,
|
2015-09-18 08:27:00 +03:00
|
|
|
ImportRule* aRule,
|
|
|
|
LoaderReusableStyleSheets* aSavedSheets);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronously load and return the stylesheet at aURL. Any child sheets
|
|
|
|
* will also be loaded synchronously. Note that synchronous loads over some
|
|
|
|
* protocols may involve spinning up a new event loop, so use of this method
|
|
|
|
* does NOT guarantee not receiving any events before the sheet loads. This
|
|
|
|
* method can be used to load sheets not associated with a document.
|
|
|
|
*
|
|
|
|
* @param aURL the URL of the sheet to load
|
2015-10-14 00:43:16 +03:00
|
|
|
* @param aParsingMode the mode in which to parse the sheet
|
|
|
|
* (see comments at enum SheetParsingMode, above).
|
2010-03-03 00:00:53 +03:00
|
|
|
* @param aUseSystemPrincipal if true, give the resulting sheet the system
|
|
|
|
* principal no matter where it's being loaded from.
|
|
|
|
* @param [out] aSheet the loaded, complete sheet.
|
|
|
|
*
|
|
|
|
* NOTE: At the moment, this method assumes the sheet will be UTF-8, but
|
|
|
|
* ideally it would allow arbitrary encodings. Callers should NOT depend on
|
|
|
|
* non-UTF8 sheets being treated as UTF-8 by this method.
|
|
|
|
*
|
|
|
|
* NOTE: A successful return from this method doesn't indicate anything about
|
|
|
|
* whether the data could be parsed as CSS and doesn't indicate anything
|
|
|
|
* about the status of child sheets of the returned sheet.
|
|
|
|
*/
|
2015-10-14 00:43:16 +03:00
|
|
|
nsresult LoadSheetSync(nsIURI* aURL,
|
|
|
|
SheetParsingMode aParsingMode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseSystemPrincipal,
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle::RefPtr* aSheet);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
2015-10-14 00:43:16 +03:00
|
|
|
* As above, but defaults aParsingMode to eAuthorSheetFeatures and
|
|
|
|
* aUseSystemPrincipal to false.
|
2010-03-03 00:00:53 +03:00
|
|
|
*/
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult LoadSheetSync(nsIURI* aURL, StyleSheetHandle::RefPtr* aSheet) {
|
2015-10-14 00:43:16 +03:00
|
|
|
return LoadSheetSync(aURL, eAuthorSheetFeatures, false, aSheet);
|
2010-03-03 00:00:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously load the stylesheet at aURL. If a successful result is
|
|
|
|
* returned, aObserver is guaranteed to be notified asynchronously once the
|
|
|
|
* sheet is loaded and marked complete. This method can be used to load
|
2015-10-14 00:43:16 +03:00
|
|
|
* sheets not associated with a document. This method cannot be used to
|
|
|
|
* load user or agent sheets.
|
2010-03-03 00:00:53 +03:00
|
|
|
*
|
|
|
|
* @param aURL the URL of the sheet to load
|
|
|
|
* @param aOriginPrincipal the principal to use for security checks. This
|
|
|
|
* can be null to indicate that these checks should
|
|
|
|
* be skipped.
|
|
|
|
* @param aCharset the encoding to use for converting the sheet data
|
|
|
|
* from bytes to Unicode. May be empty to indicate that the
|
|
|
|
* charset of the CSSLoader's document should be used. This
|
|
|
|
* is only used if neither the network transport nor the
|
|
|
|
* sheet itself indicate an encoding.
|
|
|
|
* @param aObserver the observer to notify when the load completes.
|
|
|
|
* Must not be null.
|
|
|
|
* @param [out] aSheet the sheet to load. Note that the sheet may well
|
|
|
|
* not be loaded by the time this method returns.
|
|
|
|
*/
|
|
|
|
nsresult LoadSheet(nsIURI* aURL,
|
|
|
|
nsIPrincipal* aOriginPrincipal,
|
|
|
|
const nsCString& aCharset,
|
|
|
|
nsICSSLoaderObserver* aObserver,
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle::RefPtr* aSheet);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above, to be used when the caller doesn't care about the
|
|
|
|
* not-yet-loaded sheet.
|
|
|
|
*/
|
|
|
|
nsresult LoadSheet(nsIURI* aURL,
|
2015-09-21 00:56:10 +03:00
|
|
|
bool aIsPreload,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIPrincipal* aOriginPrincipal,
|
|
|
|
const nsCString& aCharset,
|
2012-08-28 21:10:08 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2014-11-18 16:46:47 +03:00
|
|
|
CORSMode aCORSMode = CORS_NONE,
|
2015-08-13 06:19:11 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy = mozilla::net::RP_Default,
|
|
|
|
const nsAString& aIntegrity = EmptyString());
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop loading all sheets. All nsICSSLoaderObservers involved will be
|
|
|
|
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
|
|
|
|
*/
|
|
|
|
nsresult Stop(void);
|
|
|
|
|
|
|
|
/**
|
2010-04-03 15:36:19 +04:00
|
|
|
* nsresult Loader::StopLoadingSheet(nsIURI* aURL), which notifies the
|
2011-05-06 19:45:36 +04:00
|
|
|
* nsICSSLoaderObserver with NS_BINDING_ABORTED, was removed in Bug 556446.
|
2010-04-03 15:36:19 +04:00
|
|
|
* It can be found in revision 2c44a32052ad.
|
2010-03-03 00:00:53 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the loader is enabled or not.
|
|
|
|
* When disabled, processing of new styles is disabled and an attempt
|
|
|
|
* to do so will fail with a return code of
|
|
|
|
* NS_ERROR_NOT_AVAILABLE. Note that this DOES NOT disable
|
|
|
|
* currently loading styles or already processed styles.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetEnabled() { return mEnabled; }
|
|
|
|
void SetEnabled(bool aEnabled) { mEnabled = aEnabled; }
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2010-12-20 19:21:59 +03:00
|
|
|
/**
|
|
|
|
* Get the document we live for. May return null.
|
|
|
|
*/
|
|
|
|
nsIDocument* GetDocument() const { return mDocument; }
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
/**
|
|
|
|
* Return true if this loader has pending loads (ones that would send
|
|
|
|
* notifications to an nsICSSLoaderObserver attached to this loader).
|
|
|
|
* If called from inside nsICSSLoaderObserver::StyleSheetLoaded, this will
|
2011-10-17 18:59:28 +04:00
|
|
|
* return false if and only if that is the last StyleSheetLoaded
|
2010-03-03 00:00:53 +03:00
|
|
|
* notification the CSSLoader knows it's going to send. In other words, if
|
|
|
|
* two sheets load at once (via load coalescing, e.g.), HasPendingLoads()
|
2011-10-17 18:59:28 +04:00
|
|
|
* will return true during notification for the first one, and false
|
2010-03-03 00:00:53 +03:00
|
|
|
* during notification for the second one.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasPendingLoads();
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an observer to this loader. The observer will be notified
|
|
|
|
* for all loads that would have notified their own observers (even
|
|
|
|
* if those loads don't have observers attached to them).
|
|
|
|
* Load-specific observers will be notified before generic
|
|
|
|
* observers. The loader holds a reference to the observer.
|
|
|
|
*
|
|
|
|
* aObserver must not be null.
|
|
|
|
*/
|
|
|
|
nsresult AddObserver(nsICSSLoaderObserver* aObserver);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an observer added via AddObserver.
|
|
|
|
*/
|
|
|
|
void RemoveObserver(nsICSSLoaderObserver* aObserver);
|
|
|
|
|
|
|
|
// These interfaces are public only for the benefit of static functions
|
|
|
|
// within nsCSSLoader.cpp.
|
|
|
|
|
|
|
|
// IsAlternate can change our currently selected style set if none
|
|
|
|
// is selected and aHasAlternateRel is false.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsAlternate(const nsAString& aTitle, bool aHasAlternateRel);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
typedef nsTArray<RefPtr<SheetLoadData> > LoadDataArray;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2012-10-18 01:01:56 +04:00
|
|
|
// Measure our size.
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-10-18 01:01:56 +04:00
|
|
|
|
2013-07-16 01:28:33 +04:00
|
|
|
// Marks all the sheets at the given URI obsolete, and removes them from the
|
|
|
|
// cache.
|
|
|
|
nsresult ObsoleteSheet(nsIURI* aURI);
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
private:
|
|
|
|
friend class SheetLoadData;
|
|
|
|
|
2016-02-03 07:35:30 +03:00
|
|
|
nsresult CheckContentPolicy(nsIPrincipal* aSourcePrincipal,
|
|
|
|
nsIURI* aTargetURI,
|
|
|
|
nsISupports* aContext,
|
|
|
|
bool aIsPreload);
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
// For inline style, the aURI param is null, but the aLinkingContent
|
|
|
|
// must be non-null then. The loader principal must never be null
|
|
|
|
// if aURI is not null.
|
2011-11-08 08:41:17 +04:00
|
|
|
// *aIsAlternate is set based on aTitle and aHasAlternateRel.
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult CreateSheet(nsIURI* aURI,
|
|
|
|
nsIContent* aLinkingContent,
|
|
|
|
nsIPrincipal* aLoaderPrincipal,
|
2016-08-02 23:12:27 +03:00
|
|
|
css::SheetParsingMode aParsingMode,
|
2012-08-28 21:10:08 +04:00
|
|
|
CORSMode aCORSMode,
|
2014-11-18 16:46:47 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
2015-08-13 06:19:11 +03:00
|
|
|
const nsAString& aIntegrity,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSyncLoad,
|
2011-11-08 08:41:17 +04:00
|
|
|
bool aHasAlternateRel,
|
|
|
|
const nsAString& aTitle,
|
2010-03-03 00:00:53 +03:00
|
|
|
StyleSheetState& aSheetState,
|
2011-11-08 08:41:17 +04:00
|
|
|
bool *aIsAlternate,
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle::RefPtr* aSheet);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
// Pass in either a media string or the nsMediaList from the
|
|
|
|
// CSSParser. Don't pass both.
|
2011-11-08 08:41:17 +04:00
|
|
|
// This method will set the sheet's enabled state based on isAlternate
|
2016-02-24 10:01:12 +03:00
|
|
|
void PrepareSheet(StyleSheetHandle aSheet,
|
2013-11-11 11:57:53 +04:00
|
|
|
const nsAString& aTitle,
|
|
|
|
const nsAString& aMediaString,
|
|
|
|
nsMediaList* aMediaList,
|
|
|
|
dom::Element* aScopeElement,
|
|
|
|
bool isAlternate);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult InsertSheetInDoc(StyleSheetHandle aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIContent* aLinkingContent,
|
|
|
|
nsIDocument* aDocument);
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsresult InsertChildSheet(StyleSheetHandle aSheet,
|
|
|
|
StyleSheetHandle aParentSheet,
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule* aParentRule);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
nsresult InternalLoadNonDocumentSheet(nsIURI* aURL,
|
2015-09-21 00:56:10 +03:00
|
|
|
bool aIsPreload,
|
2015-10-14 00:43:16 +03:00
|
|
|
SheetParsingMode aParsingMode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseSystemPrincipal,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsIPrincipal* aOriginPrincipal,
|
|
|
|
const nsCString& aCharset,
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle::RefPtr* aSheet,
|
2012-08-28 21:10:08 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2014-11-18 16:46:47 +03:00
|
|
|
CORSMode aCORSMode = CORS_NONE,
|
2015-08-13 06:19:11 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy = mozilla::net::RP_Default,
|
|
|
|
const nsAString& aIntegrity = EmptyString());
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
// Post a load event for aObserver to be notified about aSheet. The
|
|
|
|
// notification will be sent with status NS_OK unless the load event is
|
|
|
|
// canceled at some point (in which case it will be sent with
|
|
|
|
// NS_BINDING_ABORTED). aWasAlternate indicates the state when the load was
|
|
|
|
// initiated, not the state at some later time. aURI should be the URI the
|
2011-09-27 01:27:00 +04:00
|
|
|
// sheet was loaded from (may be null for inline sheets). aElement is the
|
|
|
|
// owning element for this sheet.
|
2010-03-03 00:00:53 +03:00
|
|
|
nsresult PostLoadEvent(nsIURI* aURI,
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle aSheet,
|
2010-03-03 00:00:53 +03:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aWasAlternate,
|
2011-09-27 01:27:00 +04:00
|
|
|
nsIStyleSheetLinkingElement* aElement);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
// Start the loads of all the sheets in mPendingDatas
|
|
|
|
void StartAlternateLoads();
|
|
|
|
|
|
|
|
// Handle an event posted by PostLoadEvent
|
|
|
|
void HandleLoadEvent(SheetLoadData* aEvent);
|
|
|
|
|
|
|
|
// Note: LoadSheet is responsible for releasing aLoadData and setting the
|
|
|
|
// sheet to complete on failure.
|
2015-09-21 00:56:10 +03:00
|
|
|
nsresult LoadSheet(SheetLoadData* aLoadData,
|
|
|
|
StyleSheetState aSheetState,
|
|
|
|
bool aIsPreLoad);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2011-05-19 05:22:59 +04:00
|
|
|
// Parse the stylesheet in aLoadData. The sheet data comes from aInput.
|
2010-03-03 00:00:53 +03:00
|
|
|
// Set aCompleted to true if the parse finished, false otherwise (e.g. if the
|
|
|
|
// sheet had an @import). If aCompleted is true when this returns, then
|
2011-05-19 05:22:59 +04:00
|
|
|
// ParseSheet also called SheetComplete on aLoadData.
|
2011-05-19 05:22:59 +04:00
|
|
|
nsresult ParseSheet(const nsAString& aInput,
|
2010-03-03 00:00:53 +03:00
|
|
|
SheetLoadData* aLoadData,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aCompleted);
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
// The load of the sheet in aLoadData is done, one way or another. Do final
|
|
|
|
// cleanup, including releasing aLoadData.
|
|
|
|
void SheetComplete(SheetLoadData* aLoadData, nsresult aStatus);
|
|
|
|
|
|
|
|
// The guts of SheetComplete. This may be called recursively on parent datas
|
|
|
|
// or datas that had glommed on to a single load. The array is there so load
|
|
|
|
// datas whose observers need to be notified can be added to it.
|
|
|
|
void DoSheetComplete(SheetLoadData* aLoadData, nsresult aStatus,
|
|
|
|
LoadDataArray& aDatasToNotify);
|
|
|
|
|
2016-06-07 05:20:06 +03:00
|
|
|
StyleBackendType GetStyleBackendType() const;
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
struct Sheets {
|
2016-02-24 10:01:12 +03:00
|
|
|
nsBaseHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey,
|
|
|
|
StyleSheetHandle::RefPtr,
|
|
|
|
StyleSheetHandle> mCompleteSheets;
|
2014-11-18 16:46:47 +03:00
|
|
|
nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>
|
2013-09-02 12:41:57 +04:00
|
|
|
mLoadingDatas; // weak refs
|
2014-11-18 16:46:47 +03:00
|
|
|
nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>
|
2013-09-02 12:41:57 +04:00
|
|
|
mPendingDatas; // weak refs
|
|
|
|
};
|
|
|
|
nsAutoPtr<Sheets> mSheets;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
// We're not likely to have many levels of @import... But likely to have
|
|
|
|
// some. Allocate some storage, what the hell.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<SheetLoadData*, 8> mParsingDatas;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
// The array of posted stylesheet loaded events (SheetLoadDatas) we have.
|
|
|
|
// Note that these are rare.
|
|
|
|
LoadDataArray mPostedEvents;
|
|
|
|
|
|
|
|
// Our array of "global" observers
|
|
|
|
nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver> > mObservers;
|
|
|
|
|
2015-06-16 15:10:00 +03:00
|
|
|
// This reference is nulled by the Document in it's destructor through
|
|
|
|
// DropDocumentReference().
|
|
|
|
nsIDocument* MOZ_NON_OWNING_REF mDocument; // the document we live for
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
// Number of datas still waiting to be notified on if we're notifying on a
|
|
|
|
// whole bunch at once (e.g. in one of the stop methods). This is used to
|
|
|
|
// make sure that HasPendingLoads() won't return false until we're notifying
|
|
|
|
// on the last data we're working with.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mDatasToNotifyOn;
|
2010-03-03 00:00:53 +03:00
|
|
|
|
|
|
|
nsCompatibility mCompatMode;
|
|
|
|
nsString mPreferredSheet; // title of preferred sheet
|
|
|
|
|
2016-06-07 05:20:06 +03:00
|
|
|
// Set explicitly when the Loader(StyleBackendType) constructor is used, or
|
|
|
|
// taken from the document when the Loader(nsIDocument*) constructor is used.
|
2016-02-24 10:01:12 +03:00
|
|
|
mozilla::Maybe<StyleBackendType> mStyleBackendType;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mEnabled; // is enabled to load new styles
|
2010-03-03 00:00:53 +03:00
|
|
|
|
2016-09-08 04:59:40 +03:00
|
|
|
nsCOMPtr<nsIConsoleReportCollector> mReporter;
|
|
|
|
|
2010-03-03 00:00:53 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSyncCallback;
|
2010-03-03 00:00:53 +03:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-29 02:49:35 +04:00
|
|
|
#endif /* mozilla_css_Loader_h */
|