Bug 1304302 part 4 - Add all methods StyleSheetHandle needs to StyleSheet. r?heycam
The methods are written in the same order as in StyleSheetHandle::Ptr.
MozReview-Commit-ID: 6b4311ailNj
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -1319,43 +1319,16 @@ CSSStyleSheet::AddStyleSet(nsStyleSet* a
void
CSSStyleSheet::DropStyleSet(nsStyleSet* aStyleSet)
{
DebugOnly<bool> found = mStyleSets.RemoveElement(aStyleSet);
NS_ASSERTION(found, "didn't find style set");
}
void
-CSSStyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
- nsIURI* aBaseURI)
-{
- NS_ASSERTION(mInner->mOrderedRules.Count() == 0 && !mInner->mComplete,
- "Can't call SetURIs on sheets that are complete or have rules");
- mInner->SetURIs(aSheetURI, aOriginalSheetURI, aBaseURI);
-}
-
-void
-CSSStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
-{
- mInner->SetPrincipal(aPrincipal);
-}
-
-nsIURI*
-CSSStyleSheet::GetSheetURI() const
-{
- return mInner->mSheetURI;
-}
-
-nsIURI*
-CSSStyleSheet::GetBaseURI() const
-{
- return mInner->mBaseURI;
-}
-
-void
CSSStyleSheet::GetType(nsString& aType) const
{
aType.AssignLiteral("text/css");
}
bool
CSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
nsMediaQueryResultCacheKey& aKey) const
@@ -1374,22 +1347,16 @@ CSSStyleSheet::SetMedia(nsMediaList* aMe
}
bool
CSSStyleSheet::HasRules() const
{
return StyleRuleCount() != 0;
}
-bool
-CSSStyleSheet::IsApplicable() const
-{
- return !mDisabled && mInner->mComplete;
-}
-
void
CSSStyleSheet::SetEnabled(bool aEnabled)
{
// Internal method, so callers must handle BeginUpdate/EndUpdate
bool oldDisabled = mDisabled;
mDisabled = !aEnabled;
if (mInner->mComplete && oldDisabled != mDisabled) {
@@ -1402,22 +1369,16 @@ CSSStyleSheet::SetEnabled(bool aEnabled)
}
CSSStyleSheet*
CSSStyleSheet::GetParentSheet() const
{
return mParent;
}
-nsIDocument*
-CSSStyleSheet::GetOwningDocument() const
-{
- return mDocument;
-}
-
void
CSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
{ // not ref counted
mDocument = aDocument;
// Now set the same document on all our child sheets....
// XXXbz this is a little bogus; see the XXX comment where we
// declare mFirstChild.
for (CSSStyleSheet* child = mInner->mFirstChild;
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -120,44 +120,33 @@ public:
const dom::SRIMetadata& aIntegrity);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(CSSStyleSheet,
nsIDOMCSSStyleSheet)
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
- nsIURI* GetSheetURI() const;
- nsIURI* GetBaseURI() const;
void GetTitle(nsString& aTitle) const;
void GetType(nsString& aType) const;
bool HasRules() const;
/**
- * Whether the sheet is applicable. A sheet that is not applicable
- * 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.
- */
- bool IsApplicable() const;
-
- /**
* Set the stylesheet to be enabled. This may or may not make it
* applicable. Note that this WILL inform the sheet's document of
* its new applicable state if the state changes but WILL NOT call
* BeginUpdate() or EndUpdate() on the document -- calling those is
* the caller's responsibility. This allows use of SetEnabled when
* batched updates are desired. If you want updates handled for
* you, see nsIDOMStyleSheet::SetDisabled().
*/
void SetEnabled(bool aEnabled);
// style sheet owner info
CSSStyleSheet* GetParentSheet() const; // may be null
- nsIDocument* GetOwningDocument() const; // may be null
void SetOwningDocument(nsIDocument* aDocument);
// Find the ID of the owner inner window.
uint64_t FindOwningWindowInnerID() const;
#ifdef DEBUG
void List(FILE* out = stdout, int32_t aIndent = 0) const;
#endif
@@ -167,33 +156,16 @@ public:
void AppendStyleRule(css::Rule* aRule);
int32_t StyleRuleCount() const;
css::Rule* GetStyleRuleAt(int32_t aIndex) const;
nsresult DeleteRuleFromGroup(css::GroupRule* aGroup, uint32_t aIndex);
nsresult InsertRuleIntoGroup(const nsAString& aRule, css::GroupRule* aGroup, uint32_t aIndex, uint32_t* _retval);
- /**
- * SetURIs must be called on all sheets before parsing into them.
- * SetURIs may only be called while the sheet is 1) incomplete and 2)
- * has no rules in it
- */
- void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
-
- /**
- * SetPrincipal should be called on all sheets before parsing into them.
- * This can only be called once with a non-null principal. Calling this with
- * a null pointer is allowed and is treated as a no-op.
- */
- void SetPrincipal(nsIPrincipal* aPrincipal);
-
- // Principal() never returns a null pointer.
- nsIPrincipal* Principal() const { return mInner->mPrincipal; }
-
void SetTitle(const nsAString& aTitle) { mTitle = aTitle; }
void SetMedia(nsMediaList* aMedia);
void SetOwnerRule(css::ImportRule* aOwnerRule) { mOwnerRule = aOwnerRule; /* Not ref counted */ }
css::ImportRule* GetOwnerRule() const { return mOwnerRule; }
nsXMLNameSpaceMap* GetNameSpaceMap() const { return mInner->mNameSpaceMap; }
@@ -217,23 +189,16 @@ public:
void DropStyleSet(nsStyleSet* aStyleSet);
/**
* Like the DOM insertRule() method, but doesn't do any security checks
*/
nsresult InsertRuleInternal(const nsAString& aRule,
uint32_t aIndex, uint32_t* aReturn);
- /* Get the URI this sheet was originally loaded from, if any. Can
- return null */
- nsIURI* GetOriginalURI() const { return mInner->mOriginalSheetURI; }
-
- // Whether the sheet is for an inline <style> element.
- bool IsInline() const { return mInner->IsInline(); }
-
// nsICSSLoaderObserver interface
NS_IMETHOD StyleSheetLoaded(StyleSheetHandle aSheet, bool aWasAlternate,
nsresult aStatus) override;
void EnsureUniqueInner();
// Append all of this sheet's child sheets to aArray.
void AppendAllChildSheets(nsTArray<CSSStyleSheet*>& aArray);
@@ -252,39 +217,30 @@ public:
NS_DECL_NSIDOMCSSSTYLESHEET
// Function used as a callback to rebuild our inner's child sheet
// list after we clone a unique inner for ourselves.
static bool RebuildChildList(css::Rule* aRule, void* aBuilder);
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
- // Get this style sheet's CORS mode
- CORSMode GetCORSMode() const { return mInner->mCORSMode; }
-
- // Get this style sheet's Referrer Policy
- ReferrerPolicy GetReferrerPolicy() const { return mInner->mReferrerPolicy; }
-
- // Get this style sheet's integrity metadata
- void GetIntegrity(dom::SRIMetadata& aResult) const { aResult = mInner->mIntegrity; }
-
dom::Element* GetScopeElement() const { return mScopeElement; }
void SetScopeElement(dom::Element* aScopeElement)
{
mScopeElement = aScopeElement;
}
// WebIDL StyleSheet API
// Our CSSStyleSheet::GetType is a const method, so it ends up
// ambiguous with with the XPCOM version. Just disambiguate.
void GetType(nsString& aType) {
const_cast<const CSSStyleSheet*>(this)->GetType(aType);
}
// Our XPCOM GetHref is fine for WebIDL
- nsINode* GetOwnerNode() const { return mOwningNode; }
+ using StyleSheet::GetOwnerNode;
CSSStyleSheet* GetParentStyleSheet() const { return mParent; }
// Our CSSStyleSheet::GetTitle is a const method, so it ends up
// ambiguous with with the XPCOM version. Just disambiguate.
void GetTitle(nsString& aTitle) {
const_cast<const CSSStyleSheet*>(this)->GetTitle(aTitle);
}
nsMediaList* Media();
bool Disabled() const { return mDisabled; }
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -19,33 +19,21 @@ ServoStyleSheet::ServoStyleSheet(css::Sh
}
ServoStyleSheet::~ServoStyleSheet()
{
DropSheet();
}
bool
-ServoStyleSheet::IsApplicable() const
-{
- return !mDisabled && mComplete;
-}
-
-bool
ServoStyleSheet::HasRules() const
{
return mSheet && Servo_StyleSheet_HasRules(RawSheet());
}
-nsIDocument*
-ServoStyleSheet::GetOwningDocument() const
-{
- return mDocument;
-}
-
void
ServoStyleSheet::SetOwningDocument(nsIDocument* aDocument)
{
// XXXheycam: Traverse to child ServoStyleSheets to set this, like
// CSSStyleSheet::SetOwningDocument does.
mDocument = aDocument;
}
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -25,20 +25,18 @@ class ServoStyleSheet : public StyleShee
public:
ServoStyleSheet(css::SheetParsingMode aParsingMode,
CORSMode aCORSMode,
net::ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity);
NS_INLINE_DECL_REFCOUNTING(ServoStyleSheet)
- bool IsApplicable() const;
bool HasRules() const;
- nsIDocument* GetOwningDocument() const;
void SetOwningDocument(nsIDocument* aDocument);
ServoStyleSheet* GetParentSheet() const;
void AppendStyleSheet(ServoStyleSheet* aSheet);
MOZ_MUST_USE nsresult ParseSheet(const nsAString& aInput,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -36,18 +36,16 @@ public:
void SetOwningNode(nsINode* aOwningNode)
{
mOwningNode = aOwningNode;
}
css::SheetParsingMode ParsingMode() { return mParsingMode; }
mozilla::dom::CSSStyleSheetParsingMode ParsingModeDOM();
- nsINode* GetOwnerNode() const { return mOwningNode; }
-
// The document this style sheet is associated with. May be null
nsIDocument* GetDocument() const { return mDocument; }
/**
* Whether the sheet is complete.
*/
bool IsComplete() const;
void SetComplete();
@@ -70,16 +68,73 @@ public:
// Only safe to call if the caller has verified that that |this| is of the
// correct type.
inline CSSStyleSheet& AsGecko();
inline ServoStyleSheet& AsServo();
inline StyleSheetHandle AsHandle();
inline const CSSStyleSheet& AsGecko() const;
inline const ServoStyleSheet& AsServo() const;
+ inline MozExternalRefCountType AddRef();
+ inline MozExternalRefCountType Release();
+
+ // Whether the sheet is for an inline <style> element.
+ inline bool IsInline() const;
+
+ inline nsIURI* GetSheetURI() const;
+ /* Get the URI this sheet was originally loaded from, if any. Can
+ return null */
+ inline nsIURI* GetOriginalURI() const;
+ inline nsIURI* GetBaseURI() const;
+ /**
+ * SetURIs must be called on all sheets before parsing into them.
+ * SetURIs may only be called while the sheet is 1) incomplete and 2)
+ * has no rules in it
+ */
+ inline void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
+ nsIURI* aBaseURI);
+
+ /**
+ * Whether the sheet is applicable. A sheet that is not applicable
+ * 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;
+
+ // style sheet owner info
+ nsIDocument* GetOwningDocument() const { return mDocument; }
+ inline void SetOwningDocument(nsIDocument* aDocument);
+ nsINode* GetOwnerNode() const { return mOwningNode; }
+ inline StyleSheet* GetParentSheet() const;
+
+ inline void AppendStyleSheet(StyleSheet* aSheet);
+
+ // Principal() never returns a null pointer.
+ inline nsIPrincipal* Principal() const;
+ /**
+ * SetPrincipal should be called on all sheets before parsing into them.
+ * This can only be called once with a non-null principal. Calling this with
+ * a null pointer is allowed and is treated as a no-op.
+ */
+ inline void SetPrincipal(nsIPrincipal* aPrincipal);
+
+ // Get this style sheet's CORS mode
+ inline CORSMode GetCORSMode() const;
+ // Get this style sheet's Referrer Policy
+ inline net::ReferrerPolicy GetReferrerPolicy() const;
+ // Get this style sheet's integrity metadata
+ inline void GetIntegrity(dom::SRIMetadata& aResult) const;
+
+ inline size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
+#ifdef DEBUG
+ inline void List(FILE* aOut = stdout, int32_t aIndex = 0) const;
+#endif
+
protected:
nsIDocument* mDocument; // weak ref; parents maintain this for their children
nsINode* mOwningNode; // weak ref
// 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.
css::SheetParsingMode mParsingMode;
--- a/layout/style/StyleSheetInfo.cpp
+++ b/layout/style/StyleSheetInfo.cpp
@@ -40,34 +40,9 @@ StyleSheetInfo::StyleSheetInfo(const Sty
, 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
--- a/layout/style/StyleSheetInfo.h
+++ b/layout/style/StyleSheetInfo.h
@@ -6,22 +6,23 @@
#ifndef mozilla_StyleSheetInfo_h
#define mozilla_StyleSheetInfo_h
#include "mozilla/dom/SRIMetadata.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/CORSMode.h"
+#include "nsIURI.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
{
@@ -30,31 +31,16 @@ public:
friend class ::nsCSSRuleProcessor;
typedef net::ReferrerPolicy ReferrerPolicy;
StyleSheetInfo(CORSMode aCORSMode,
ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity);
StyleSheetInfo(const StyleSheetInfo& aCopy);
- nsIURI* GetSheetURI() const { return mSheetURI; }
- nsIURI* GetOriginalURI() const { return mOriginalSheetURI; }
- nsIURI* GetBaseURI() const { return mBaseURI; }
- void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
-
- // Whether the sheet is for an inline <style> element.
- bool IsInline() const { return !mOriginalSheetURI; }
-
- nsIPrincipal* Principal() const { return mPrincipal; }
- void SetPrincipal(nsIPrincipal* aPrincipal);
-
- CORSMode GetCORSMode() const { return mCORSMode; }
- net::ReferrerPolicy GetReferrerPolicy() const { return mReferrerPolicy; }
- void GetIntegrity(dom::SRIMetadata& aResult) const { aResult = mIntegrity; }
-
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.
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -2,16 +2,17 @@
/* 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_StyleSheetInlines_h
#define mozilla_StyleSheetInlines_h
+#include "mozilla/TypeTraits.h"
#include "mozilla/ServoStyleSheet.h"
#include "mozilla/CSSStyleSheet.h"
namespace mozilla {
CSSStyleSheet&
StyleSheet::AsGecko()
{
@@ -44,11 +45,158 @@ StyleSheet::AsGecko() const
const ServoStyleSheet&
StyleSheet::AsServo() const
{
MOZ_ASSERT(IsServo());
return *static_cast<const ServoStyleSheet*>(this);
}
+#define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \
+ static_assert(!IsSame<decltype(&StyleSheet::method_), \
+ decltype(&CSSStyleSheet::method_)>::value, \
+ "CSSStyleSheet should define its own " #method_); \
+ static_assert(!IsSame<decltype(&StyleSheet::method_), \
+ decltype(&ServoStyleSheet::method_)>::value, \
+ "ServoStyleSheet should define its own " #method_); \
+ if (IsServo()) { \
+ return AsServo().method_ servoargs_; \
+ } \
+ return AsGecko().method_ geckoargs_;
+
+#define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
+
+MozExternalRefCountType
+StyleSheet::AddRef()
+{
+ FORWARD(AddRef, ())
+}
+
+MozExternalRefCountType
+StyleSheet::Release()
+{
+ FORWARD(Release, ())
+}
+
+bool
+StyleSheet::IsInline() const
+{
+ return !SheetInfo().mOriginalSheetURI;
+}
+
+nsIURI*
+StyleSheet::GetSheetURI() const
+{
+ return SheetInfo().mSheetURI;
+}
+
+nsIURI*
+StyleSheet::GetOriginalURI() const
+{
+ return SheetInfo().mOriginalSheetURI;
+}
+
+nsIURI*
+StyleSheet::GetBaseURI() const
+{
+ return SheetInfo().mBaseURI;
+}
+
+void
+StyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
+ nsIURI* aBaseURI)
+{
+ NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
+ StyleSheetInfo& info = SheetInfo();
+ MOZ_ASSERT(!HasRules() && !info.mComplete,
+ "Can't call SetURIs on sheets that are complete or have rules");
+ info.mSheetURI = aSheetURI;
+ info.mOriginalSheetURI = aOriginalSheetURI;
+ info.mBaseURI = aBaseURI;
+}
+
+bool
+StyleSheet::IsApplicable() const
+{
+ return !mDisabled && SheetInfo().mComplete;
+}
+
+bool
+StyleSheet::HasRules() const
+{
+ FORWARD(HasRules, ())
+}
+
+void
+StyleSheet::SetOwningDocument(nsIDocument* aDocument)
+{
+ FORWARD(SetOwningDocument, (aDocument))
+}
+
+StyleSheet*
+StyleSheet::GetParentSheet() const
+{
+ FORWARD(GetParentSheet, ())
+}
+
+void
+StyleSheet::AppendStyleSheet(StyleSheet* aSheet)
+{
+ FORWARD_CONCRETE(AppendStyleSheet, (&aSheet->AsGecko()), (&aSheet->AsServo()))
+}
+
+nsIPrincipal*
+StyleSheet::Principal() const
+{
+ return SheetInfo().mPrincipal;
+}
+
+void
+StyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
+{
+ StyleSheetInfo& info = SheetInfo();
+ NS_PRECONDITION(!info.mPrincipalSet, "Should only set principal once");
+ if (aPrincipal) {
+ info.mPrincipal = aPrincipal;
+#ifdef DEBUG
+ info.mPrincipalSet = true;
+#endif
+ }
+}
+
+CORSMode
+StyleSheet::GetCORSMode() const
+{
+ return SheetInfo().mCORSMode;
+}
+
+net::ReferrerPolicy
+StyleSheet::GetReferrerPolicy() const
+{
+ return SheetInfo().mReferrerPolicy;
+}
+
+void
+StyleSheet::GetIntegrity(dom::SRIMetadata& aResult) const
+{
+ aResult = SheetInfo().mIntegrity;
+}
+
+size_t
+StyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+ FORWARD(SizeOfIncludingThis, (aMallocSizeOf))
+}
+
+#ifdef DEBUG
+void
+StyleSheet::List(FILE* aOut, int32_t aIndex) const
+{
+ FORWARD(List, (aOut, aIndex))
+}
+#endif
+
+#undef FORWARD
+#undef FORWARD_CONCRETE
+
}
#endif // mozilla_StyleSheetInlines_h