Bug 1250788 - Part 3.1: Factor out CSSStyleSheetInner members so they can be used by ServoStyleSheet. r=bholley

This commit is contained in:
Cameron McCormack 2016-02-26 12:51:01 +11:00
parent afbfd86949
commit 70bd01d9e9
5 changed files with 141 additions and 56 deletions

View File

@ -841,22 +841,10 @@ CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheet* aPrimarySheet,
CORSMode aCORSMode,
ReferrerPolicy aReferrerPolicy,
const SRIMetadata& aIntegrity)
: mSheets()
, mCORSMode(aCORSMode)
, mReferrerPolicy (aReferrerPolicy)
, mIntegrity(aIntegrity)
, mComplete(false)
#ifdef DEBUG
, mPrincipalSet(false)
#endif
: StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
{
MOZ_COUNT_CTOR(CSSStyleSheetInner);
mSheets.AppendElement(aPrimarySheet);
mPrincipal = nsNullPrincipal::Create();
if (!mPrincipal) {
NS_RUNTIMEABORT("nsNullPrincipal::Init failed");
}
}
static bool SetStyleSheetReference(css::Rule* aRule, void* aSheet)
@ -959,18 +947,7 @@ CSSStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
CSSStyleSheet* aPrimarySheet)
: mSheets(),
mSheetURI(aCopy.mSheetURI),
mOriginalSheetURI(aCopy.mOriginalSheetURI),
mBaseURI(aCopy.mBaseURI),
mPrincipal(aCopy.mPrincipal),
mCORSMode(aCopy.mCORSMode),
mReferrerPolicy(aCopy.mReferrerPolicy),
mIntegrity(aCopy.mIntegrity),
mComplete(aCopy.mComplete)
#ifdef DEBUG
, mPrincipalSet(aCopy.mPrincipalSet)
#endif
: StyleSheetInfo(aCopy)
{
MOZ_COUNT_CTOR(CSSStyleSheetInner);
AddSheet(aPrimarySheet);
@ -1368,27 +1345,15 @@ void
CSSStyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
nsIURI* aBaseURI)
{
NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
NS_ASSERTION(mInner->mOrderedRules.Count() == 0 && !mInner->mComplete,
"Can't call SetURL on sheets that are complete or have rules");
mInner->mSheetURI = aSheetURI;
mInner->mOriginalSheetURI = aOriginalSheetURI;
mInner->mBaseURI = aBaseURI;
"Can't call SetURIs on sheets that are complete or have rules");
mInner->SetURIs(aSheetURI, aOriginalSheetURI, aBaseURI);
}
void
CSSStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
{
NS_PRECONDITION(!mInner->mPrincipalSet,
"Should have an inner whose principal has not yet been set");
if (aPrincipal) {
mInner->mPrincipal = aPrincipal;
#ifdef DEBUG
mInner->mPrincipalSet = true;
#endif
}
mInner->SetPrincipal(aPrincipal);
}
nsIURI*

View File

@ -12,6 +12,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/IncrementalClearCOMRuleArray.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/StyleSheetInfo.h"
#include "mozilla/css/SheetParsingMode.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/CSSStyleSheetBinding.h"
@ -56,12 +57,11 @@ class CSSRuleList;
// CSS Style Sheet Inner Data Container
//
class CSSStyleSheetInner
class CSSStyleSheetInner : public StyleSheetInfo
{
public:
friend class mozilla::CSSStyleSheet;
friend class ::nsCSSRuleProcessor;
typedef net::ReferrerPolicy ReferrerPolicy;
private:
CSSStyleSheetInner(CSSStyleSheet* aPrimarySheet,
@ -84,10 +84,6 @@ private:
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
AutoTArray<CSSStyleSheet*, 8> mSheets;
nsCOMPtr<nsIURI> mSheetURI; // for error reports, etc.
nsCOMPtr<nsIURI> mOriginalSheetURI; // for GetHref. Can be null.
nsCOMPtr<nsIURI> mBaseURI; // for resolving relative URIs
nsCOMPtr<nsIPrincipal> mPrincipal;
IncrementalClearCOMRuleArray mOrderedRules;
nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
// Linked list of child sheets. This is al fundamentally broken, because
@ -96,16 +92,6 @@ private:
// child sheet that means we've already ensured unique inners throughout its
// parent chain and things are good.
RefPtr<CSSStyleSheet> mFirstChild;
CORSMode mCORSMode;
// The Referrer Policy of a stylesheet is used for its child sheets, so it is
// stored here.
ReferrerPolicy mReferrerPolicy;
dom::SRIMetadata mIntegrity;
bool mComplete;
#ifdef DEBUG
bool mPrincipalSet;
#endif
};

View File

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "StyleSheetInfo.h"
#include "nsIURI.h"
#include "nsNullPrincipal.h"
namespace mozilla {
using namespace mozilla::dom;
StyleSheetInfo::StyleSheetInfo(CORSMode aCORSMode,
ReferrerPolicy aReferrerPolicy,
const SRIMetadata& aIntegrity)
: mCORSMode(aCORSMode)
, mReferrerPolicy (aReferrerPolicy)
, mIntegrity(aIntegrity)
, mComplete(false)
#ifdef DEBUG
, mPrincipalSet(false)
#endif
{
mPrincipal = nsNullPrincipal::Create();
if (!mPrincipal) {
NS_RUNTIMEABORT("nsNullPrincipal::Init failed");
}
}
StyleSheetInfo::StyleSheetInfo(const StyleSheetInfo& aCopy)
: mSheetURI(aCopy.mSheetURI)
, mOriginalSheetURI(aCopy.mOriginalSheetURI)
, mBaseURI(aCopy.mBaseURI)
, mPrincipal(aCopy.mPrincipal)
, mCORSMode(aCopy.mCORSMode)
, mReferrerPolicy(aCopy.mReferrerPolicy)
, mIntegrity(aCopy.mIntegrity)
, mComplete(aCopy.mComplete)
#ifdef DEBUG
, mPrincipalSet(aCopy.mPrincipalSet)
#endif
{
}
void
StyleSheetInfo::SetURIs(nsIURI* aSheetURI,
nsIURI* aOriginalSheetURI,
nsIURI* aBaseURI)
{
NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
mSheetURI = aSheetURI;
mOriginalSheetURI = aOriginalSheetURI;
mBaseURI = aBaseURI;
}
void
StyleSheetInfo::SetPrincipal(nsIPrincipal* aPrincipal)
{
NS_PRECONDITION(!mPrincipalSet, "Should only set principal once");
if (aPrincipal) {
mPrincipal = aPrincipal;
#ifdef DEBUG
mPrincipalSet = true;
#endif
}
}
} // namespace mozilla

View File

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_StyleSheetInfo_h
#define mozilla_StyleSheetInfo_h
#include "mozilla/dom/SRIMetadata.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/CORSMode.h"
namespace mozilla {
class CSSStyleSheet;
} // namespace mozilla
class nsCSSRuleProcessor;
class nsIPrincipal;
class nsIURI;
namespace mozilla {
/**
* Superclass for data common to CSSStyleSheetInner and ServoStyleSheet.
*/
class StyleSheetInfo
{
public:
friend class mozilla::CSSStyleSheet;
friend class ::nsCSSRuleProcessor;
typedef net::ReferrerPolicy ReferrerPolicy;
StyleSheetInfo(CORSMode aCORSMode,
ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity);
StyleSheetInfo(const StyleSheetInfo& aCopy);
void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
void SetPrincipal(nsIPrincipal* aPrincipal);
protected:
nsCOMPtr<nsIURI> mSheetURI; // for error reports, etc.
nsCOMPtr<nsIURI> mOriginalSheetURI; // for GetHref. Can be null.
nsCOMPtr<nsIURI> mBaseURI; // for resolving relative URIs
nsCOMPtr<nsIPrincipal> mPrincipal;
CORSMode mCORSMode;
// The Referrer Policy of a stylesheet is used for its child sheets, so it is
// stored here.
ReferrerPolicy mReferrerPolicy;
dom::SRIMetadata mIntegrity;
bool mComplete;
#ifdef DEBUG
bool mPrincipalSet;
#endif
};
} // namespace mozilla
#endif // mozilla_StyleSheetInfo_h

View File

@ -100,6 +100,7 @@ EXPORTS.mozilla += [
'StyleSetHandleInlines.h',
'StyleSheetHandle.h',
'StyleSheetHandleInlines.h',
'StyleSheetInfo.h',
]
EXPORTS.mozilla.dom += [
@ -187,6 +188,7 @@ UNIFIED_SOURCES += [
'ServoStyleSheet.cpp',
'StyleAnimationValue.cpp',
'StyleRule.cpp',
'StyleSheetInfo.cpp',
'SVGAttrAnimationRuleProcessor.cpp',
]