Bug 1352968 part 2 - Move mOwnerRule to StyleSheet and use dom::CSSImportRule instead of css::ImportRule. r=heycam
MozReview-Commit-ID: DTAWGHIUAQX
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -322,48 +322,45 @@ CSSStyleSheetInner::SizeOfIncludingThis(
// -------------------------------
// CSS Style Sheet
//
CSSStyleSheet::CSSStyleSheet(css::SheetParsingMode aParsingMode,
CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy)
: StyleSheet(StyleBackendType::Gecko, aParsingMode),
- mOwnerRule(nullptr),
mInRuleProcessorCache(false),
mScopeElement(nullptr),
mRuleProcessors(nullptr)
{
mInner = new CSSStyleSheetInner(aCORSMode, aReferrerPolicy,
SRIMetadata());
mInner->AddSheet(this);
}
CSSStyleSheet::CSSStyleSheet(css::SheetParsingMode aParsingMode,
CORSMode aCORSMode,
ReferrerPolicy aReferrerPolicy,
const SRIMetadata& aIntegrity)
: StyleSheet(StyleBackendType::Gecko, aParsingMode),
- mOwnerRule(nullptr),
mInRuleProcessorCache(false),
mScopeElement(nullptr),
mRuleProcessors(nullptr)
{
mInner = new CSSStyleSheetInner(aCORSMode, aReferrerPolicy,
aIntegrity);
mInner->AddSheet(this);
}
CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet& aCopy,
CSSStyleSheet* aParentToUse,
- css::ImportRule* aOwnerRuleToUse,
+ dom::CSSImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
nsINode* aOwningNodeToUse)
- : StyleSheet(aCopy, aDocumentToUse, aOwningNodeToUse),
- mOwnerRule(aOwnerRuleToUse),
+ : StyleSheet(aCopy, aOwnerRuleToUse, aDocumentToUse, aOwningNodeToUse),
mInRuleProcessorCache(false),
mScopeElement(nullptr),
mRuleProcessors(nullptr)
{
mParent = aParentToUse;
}
CSSStyleSheet::~CSSStyleSheet()
@@ -565,17 +562,17 @@ CSSStyleSheet::GetStyleRuleAt(int32_t aI
{
// Important: If this function is ever made scriptable, we must add
// a security check here. See GetCssRules below for an example.
return Inner()->mOrderedRules.SafeObjectAt(aIndex);
}
already_AddRefed<StyleSheet>
CSSStyleSheet::Clone(StyleSheet* aCloneParent,
- css::ImportRule* aCloneOwnerRule,
+ dom::CSSImportRule* aCloneOwnerRule,
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const
{
RefPtr<StyleSheet> clone = new CSSStyleSheet(*this,
static_cast<CSSStyleSheet*>(aCloneParent),
aCloneOwnerRule,
aCloneDocument,
aCloneOwningNode);
@@ -651,22 +648,16 @@ CSSStyleSheet::RegisterNamespaceRule(css
}
void
CSSStyleSheet::SetScopeElement(dom::Element* aScopeElement)
{
mScopeElement = aScopeElement;
}
-css::Rule*
-CSSStyleSheet::GetDOMOwnerRule() const
-{
- return mOwnerRule;
-}
-
CSSRuleList*
CSSStyleSheet::GetCssRulesInternal(ErrorResult& aRv)
{
if (!mRuleCollection) {
mRuleCollection = new CSSRuleListImpl(this);
}
return mRuleCollection;
}
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -108,27 +108,22 @@ public:
#endif
// XXX do these belong here or are they generic?
void AppendStyleRule(css::Rule* aRule);
int32_t StyleRuleCount() const;
css::Rule* GetStyleRuleAt(int32_t aIndex) const;
- void SetOwnerRule(css::ImportRule* aOwnerRule) { mOwnerRule = aOwnerRule; /* Not ref counted */ }
- css::ImportRule* GetOwnerRule() const { return mOwnerRule; }
- // Workaround overloaded-virtual warning in GCC.
- using StyleSheet::GetOwnerRule;
-
nsXMLNameSpaceMap* GetNameSpaceMap() const {
return Inner()->mNameSpaceMap;
}
- virtual already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
- css::ImportRule* aCloneOwnerRule,
+ already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
+ dom::CSSImportRule* aCloneOwnerRule,
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const final;
void SetModifiedByChildRule() {
NS_ASSERTION(mDirty,
"sheet must be marked dirty before handing out child rules");
DidDirty();
}
@@ -152,28 +147,22 @@ public:
static bool RebuildChildList(css::Rule* aRule,
ChildSheetListBuilder* aBuilder);
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
dom::Element* GetScopeElement() const { return mScopeElement; }
void SetScopeElement(dom::Element* aScopeElement);
- // WebIDL CSSStyleSheet API
- // Can't be inline because we can't include ImportRule here. And can't be
- // called GetOwnerRule because that would be ambiguous with the ImportRule
- // version.
- css::Rule* GetDOMOwnerRule() const final;
-
void DidDirty() override;
private:
CSSStyleSheet(const CSSStyleSheet& aCopy,
CSSStyleSheet* aParentToUse,
- css::ImportRule* aOwnerRuleToUse,
+ dom::CSSImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
nsINode* aOwningNodeToUse);
CSSStyleSheet(const CSSStyleSheet& aCopy) = delete;
CSSStyleSheet& operator=(const CSSStyleSheet& aCopy) = delete;
protected:
virtual ~CSSStyleSheet();
@@ -203,18 +192,16 @@ protected:
uint32_t aIndex, ErrorResult& aRv);
void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
nsresult InsertRuleIntoGroupInternal(const nsAString& aRule,
css::GroupRule* aGroup,
uint32_t aIndex);
void EnabledStateChangedInternal();
- css::ImportRule* mOwnerRule; // weak ref
-
RefPtr<CSSRuleListImpl> mRuleCollection;
bool mInRuleProcessorCache;
RefPtr<dom::Element> mScopeElement;
AutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
friend class mozilla::StyleSheet;
friend class ::nsCSSRuleProcessor;
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -76,20 +76,20 @@ ServoStyleSheet::ServoStyleSheet(css::Sh
: StyleSheet(StyleBackendType::Servo, aParsingMode)
{
mInner = new ServoStyleSheetInner(aCORSMode, aReferrerPolicy, aIntegrity);
mInner->AddSheet(this);
}
ServoStyleSheet::ServoStyleSheet(const ServoStyleSheet& aCopy,
ServoStyleSheet* aParentToUse,
- css::ImportRule* aOwnerRuleToUse,
+ dom::CSSImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
nsINode* aOwningNodeToUse)
- : StyleSheet(aCopy, aDocumentToUse, aOwningNodeToUse)
+ : StyleSheet(aCopy, aOwnerRuleToUse, aDocumentToUse, aOwningNodeToUse)
{
mParent = aParentToUse;
}
ServoStyleSheet::~ServoStyleSheet()
{
UnparentChildren();
@@ -193,26 +193,19 @@ void
ServoStyleSheet::DropRuleList()
{
if (mRuleList) {
mRuleList->DropReference();
mRuleList = nullptr;
}
}
-css::Rule*
-ServoStyleSheet::GetDOMOwnerRule() const
-{
- NS_ERROR("stylo: Don't know how to get DOM owner rule for ServoStyleSheet");
- return nullptr;
-}
-
already_AddRefed<StyleSheet>
ServoStyleSheet::Clone(StyleSheet* aCloneParent,
- css::ImportRule* aCloneOwnerRule,
+ dom::CSSImportRule* aCloneOwnerRule,
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const
{
RefPtr<StyleSheet> clone = new ServoStyleSheet(*this,
static_cast<ServoStyleSheet*>(aCloneParent),
aCloneOwnerRule,
aCloneDocument,
aCloneOwningNode);
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -98,26 +98,20 @@ public:
}
void SetSheetForImport(const RawServoStyleSheet* aSheet) {
MOZ_ASSERT(!Inner()->mSheet);
Inner()->mSheet = aSheet;
}
URLExtraData* URLData() const { return Inner()->mURLData; }
- // WebIDL CSSStyleSheet API
- // Can't be inline because we can't include ImportRule here. And can't be
- // called GetOwnerRule because that would be ambiguous with the ImportRule
- // version.
- css::Rule* GetDOMOwnerRule() const final;
-
void DidDirty() override {}
- virtual already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
- css::ImportRule* aCloneOwnerRule,
+ already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
+ dom::CSSImportRule* aCloneOwnerRule,
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const final;
// nsICSSLoaderObserver interface
NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
nsresult aStatus) final;
protected:
@@ -141,17 +135,17 @@ protected:
void EnabledStateChangedInternal() {}
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
private:
ServoStyleSheet(const ServoStyleSheet& aCopy,
ServoStyleSheet* aParentToUse,
- css::ImportRule* aOwnerRuleToUse,
+ dom::CSSImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
nsINode* aOwningNodeToUse);
void DropRuleList();
RefPtr<ServoCSSRuleList> mRuleList;
friend class StyleSheet;
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -1,48 +1,52 @@
/* -*- 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 "mozilla/StyleSheet.h"
+#include "mozilla/dom/CSSImportRule.h"
#include "mozilla/dom/CSSRuleList.h"
#include "mozilla/dom/MediaList.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/ServoStyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/CSSStyleSheet.h"
#include "mozAutoDocUpdate.h"
#include "NullPrincipal.h"
namespace mozilla {
StyleSheet::StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMode)
: mParent(nullptr)
, mDocument(nullptr)
, mOwningNode(nullptr)
+ , mOwnerRule(nullptr)
, mParsingMode(aParsingMode)
, mType(aType)
, mDisabled(false)
, mDocumentAssociationMode(NotOwnedByDocument)
, mInner(nullptr)
, mDirty(false)
{
}
StyleSheet::StyleSheet(const StyleSheet& aCopy,
+ dom::CSSImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
nsINode* aOwningNodeToUse)
: mParent(nullptr)
, mTitle(aCopy.mTitle)
, mDocument(aDocumentToUse)
, mOwningNode(aOwningNodeToUse)
+ , mOwnerRule(aOwnerRuleToUse)
, mParsingMode(aCopy.mParsingMode)
, mType(aCopy.mType)
, mDisabled(aCopy.mDisabled)
// We only use this constructor during cloning. It's the cloner's
// responsibility to notify us if we end up being owned by a document.
, mDocumentAssociationMode(NotOwnedByDocument)
, mInner(aCopy.mInner) // Shallow copy, but concrete subclasses will fix up.
, mDirty(aCopy.mDirty)
@@ -479,16 +483,22 @@ StyleSheet::GetCssRules(nsIPrincipal& aS
ErrorResult& aRv)
{
if (!AreRulesAvailable(aSubjectPrincipal, aRv)) {
return nullptr;
}
FORWARD_INTERNAL(GetCssRulesInternal, (aRv))
}
+css::Rule*
+StyleSheet::GetDOMOwnerRule() const
+{
+ return mOwnerRule;
+}
+
uint32_t
StyleSheet::InsertRule(const nsAString& aRule, uint32_t aIndex,
nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv)
{
if (!AreRulesAvailable(aSubjectPrincipal, aRv)) {
return 0;
}
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -27,37 +27,38 @@ namespace mozilla {
class CSSStyleSheet;
class ServoStyleSheet;
class StyleSetHandle;
struct StyleSheetInfo;
struct CSSStyleSheetInner;
namespace dom {
+class CSSImportRule;
class CSSRuleList;
class MediaList;
class SRIMetadata;
} // namespace dom
namespace css {
class GroupRule;
-class ImportRule;
class Rule;
}
/**
* Superclass for data common to CSSStyleSheet and ServoStyleSheet.
*/
class StyleSheet : public nsIDOMCSSStyleSheet
, public nsICSSLoaderObserver
, public nsWrapperCache
{
protected:
StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMode);
StyleSheet(const StyleSheet& aCopy,
+ dom::CSSImportRule* aOwnerRuleToUse,
nsIDocument* aDocumentToUse,
nsINode* aOwningNodeToUse);
virtual ~StyleSheet();
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(StyleSheet,
nsIDOMCSSStyleSheet)
@@ -125,17 +126,17 @@ public:
* should never be inserted into a style set. A sheet may not be
* applicable for a variety of reasons including being disabled and
* being incomplete.
*/
inline bool IsApplicable() const;
inline bool HasRules() const;
virtual already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
- css::ImportRule* aCloneOwnerRule,
+ dom::CSSImportRule* aCloneOwnerRule,
nsIDocument* aCloneDocument,
nsINode* aCloneOwningNode) const = 0;
bool IsModified() const { return mDirty; }
void EnsureUniqueInner();
// Append all of this sheet's child sheets to aArray.
@@ -156,16 +157,21 @@ public:
}
// aDocument must not be null.
void SetAssociatedDocument(nsIDocument* aDocument,
DocumentAssociationMode aMode);
void ClearAssociatedDocument();
nsINode* GetOwnerNode() const { return mOwningNode; }
inline StyleSheet* GetParentSheet() const { return mParent; }
+ void SetOwnerRule(dom::CSSImportRule* aOwnerRule) {
+ mOwnerRule = aOwnerRule; /* Not ref counted */
+ }
+ dom::CSSImportRule* GetOwnerRule() const { return mOwnerRule; }
+
void AppendStyleSheet(StyleSheet* aSheet);
StyleSheet* GetFirstChild() const;
// Principal() never returns a null pointer.
inline nsIPrincipal* Principal() const;
/**
* SetPrincipal should be called on all sheets before parsing into them.
@@ -195,17 +201,20 @@ public:
// GetOwnerNode is defined above.
inline StyleSheet* GetParentStyleSheet() const;
// The XPCOM GetTitle is fine for WebIDL.
dom::MediaList* Media();
bool Disabled() const { return mDisabled; }
// The XPCOM SetDisabled is fine for WebIDL.
// WebIDL CSSStyleSheet API
- virtual css::Rule* GetDOMOwnerRule() const = 0;
+ // Can't be inline because we can't include ImportRule here. And can't be
+ // called GetOwnerRule because that would be ambiguous with the ImportRule
+ // version.
+ css::Rule* GetDOMOwnerRule() const;
dom::CSSRuleList* GetCssRules(nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv);
uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex,
nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv);
void DeleteRule(uint32_t aIndex,
nsIPrincipal& aSubjectPrincipal,
ErrorResult& aRv);
@@ -291,16 +300,17 @@ protected:
void ClearRuleCascades();
virtual void ClearRuleCascadesInternal() {}
StyleSheet* mParent; // weak ref
nsString mTitle;
nsIDocument* mDocument; // weak ref; parents maintain this for their children
nsINode* mOwningNode; // weak ref
+ dom::CSSImportRule* mOwnerRule; // weak ref
RefPtr<dom::MediaList> mMedia;
RefPtr<StyleSheet> mNext;
// mParsingMode controls access to nonstandard style constructs that
// are not safe for use on the public Web but necessary in UA sheets
// and/or useful in user sheets.