2016-02-26 04:51:01 +03:00
|
|
|
/* -*- 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_StyleSheet_h
|
|
|
|
#define mozilla_StyleSheet_h
|
|
|
|
|
|
|
|
#include "mozilla/css/SheetParsingMode.h"
|
2016-08-02 23:17:06 +03:00
|
|
|
#include "mozilla/dom/CSSStyleSheetBinding.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2016-03-02 01:38:13 +03:00
|
|
|
#include "mozilla/StyleBackendType.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/CORSMode.h"
|
2016-10-13 15:45:03 +03:00
|
|
|
#include "mozilla/ServoUtils.h"
|
2016-02-26 04:51:01 +03:00
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2016-10-14 14:25:38 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2016-10-14 14:25:38 +03:00
|
|
|
|
2016-03-01 23:39:29 +03:00
|
|
|
class nsIDocument;
|
2016-02-26 04:51:01 +03:00
|
|
|
class nsINode;
|
2016-10-14 14:25:38 +03:00
|
|
|
class nsIPrincipal;
|
2016-10-14 14:25:38 +03:00
|
|
|
class nsMediaList;
|
2016-02-26 04:51:01 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-03-02 01:38:13 +03:00
|
|
|
class CSSStyleSheet;
|
|
|
|
class ServoStyleSheet;
|
2016-09-29 09:17:58 +03:00
|
|
|
struct StyleSheetInfo;
|
2016-09-26 15:03:25 +03:00
|
|
|
|
|
|
|
namespace dom {
|
2016-10-14 14:25:38 +03:00
|
|
|
class CSSRuleList;
|
2016-09-26 15:03:25 +03:00
|
|
|
class SRIMetadata;
|
|
|
|
} // namespace dom
|
2016-03-02 01:38:13 +03:00
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
/**
|
|
|
|
* Superclass for data common to CSSStyleSheet and ServoStyleSheet.
|
|
|
|
*/
|
2016-10-14 14:25:38 +03:00
|
|
|
class StyleSheet : public nsIDOMCSSStyleSheet
|
2016-10-14 14:25:38 +03:00
|
|
|
, public nsWrapperCache
|
2016-02-26 04:51:01 +03:00
|
|
|
{
|
2016-03-02 01:38:13 +03:00
|
|
|
protected:
|
2016-08-02 23:12:27 +03:00
|
|
|
StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMode);
|
2016-02-26 04:51:01 +03:00
|
|
|
StyleSheet(const StyleSheet& aCopy,
|
2016-03-01 23:39:29 +03:00
|
|
|
nsIDocument* aDocumentToUse,
|
2016-02-26 04:51:01 +03:00
|
|
|
nsINode* aOwningNodeToUse);
|
2016-10-14 14:25:38 +03:00
|
|
|
virtual ~StyleSheet() {}
|
2016-02-26 04:51:01 +03:00
|
|
|
|
2016-03-02 01:38:13 +03:00
|
|
|
public:
|
2016-10-14 14:25:38 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(StyleSheet)
|
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
void SetOwningNode(nsINode* aOwningNode)
|
|
|
|
{
|
|
|
|
mOwningNode = aOwningNode;
|
|
|
|
}
|
|
|
|
|
2016-08-02 22:28:40 +03:00
|
|
|
css::SheetParsingMode ParsingMode() { return mParsingMode; }
|
2016-08-02 23:17:06 +03:00
|
|
|
mozilla::dom::CSSStyleSheetParsingMode ParsingModeDOM();
|
|
|
|
|
2016-03-01 23:39:29 +03:00
|
|
|
// The document this style sheet is associated with. May be null
|
|
|
|
nsIDocument* GetDocument() const { return mDocument; }
|
|
|
|
|
2016-03-02 02:10:45 +03:00
|
|
|
/**
|
|
|
|
* Whether the sheet is complete.
|
|
|
|
*/
|
|
|
|
bool IsComplete() const;
|
|
|
|
void SetComplete();
|
|
|
|
|
2016-10-13 15:45:03 +03:00
|
|
|
MOZ_DECL_STYLO_METHODS(CSSStyleSheet, ServoStyleSheet)
|
2016-03-02 01:38:13 +03:00
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
// 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
|
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
// WebIDL StyleSheet API
|
|
|
|
// The XPCOM GetType is fine for WebIDL.
|
|
|
|
// The XPCOM GetHref is fine for WebIDL
|
|
|
|
// GetOwnerNode is defined above.
|
2016-10-14 14:25:38 +03:00
|
|
|
inline StyleSheet* GetParentStyleSheet() const;
|
2016-10-14 14:25:38 +03:00
|
|
|
// The XPCOM GetTitle is fine for WebIDL.
|
2016-10-14 14:25:38 +03:00
|
|
|
virtual nsMediaList* Media() = 0;
|
2016-10-14 14:25:38 +03:00
|
|
|
bool Disabled() const { return mDisabled; }
|
|
|
|
// The XPCOM SetDisabled is fine for WebIDL.
|
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
// WebIDL CSSStyleSheet API
|
2016-10-14 14:25:38 +03:00
|
|
|
virtual nsIDOMCSSRule* GetDOMOwnerRule() const = 0;
|
2016-10-14 14:25:38 +03:00
|
|
|
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);
|
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
// WebIDL miscellaneous bits
|
|
|
|
inline dom::ParentObject GetParentObject() const;
|
2016-10-14 14:25:38 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
|
2016-10-14 14:25:38 +03:00
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHOD GetType(nsAString& aType) final;
|
|
|
|
NS_IMETHOD GetDisabled(bool* aDisabled) final;
|
|
|
|
NS_IMETHOD SetDisabled(bool aDisabled) final;
|
|
|
|
NS_IMETHOD GetOwnerNode(nsIDOMNode** aOwnerNode) final;
|
2016-10-14 14:25:38 +03:00
|
|
|
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet) final;
|
2016-10-14 14:25:38 +03:00
|
|
|
NS_IMETHOD GetHref(nsAString& aHref) final;
|
|
|
|
NS_IMETHOD GetTitle(nsAString& aTitle) final;
|
2016-10-14 14:25:38 +03:00
|
|
|
NS_IMETHOD GetMedia(nsIDOMMediaList** aMedia) final;
|
|
|
|
|
|
|
|
// nsIDOMCSSStyleSheet
|
|
|
|
NS_IMETHOD GetOwnerRule(nsIDOMCSSRule** aOwnerRule) final;
|
|
|
|
NS_IMETHOD GetCssRules(nsIDOMCSSRuleList** aCssRules) final;
|
|
|
|
NS_IMETHOD InsertRule(const nsAString& aRule, uint32_t aIndex,
|
|
|
|
uint32_t* aReturn) final;
|
|
|
|
NS_IMETHOD DeleteRule(uint32_t aIndex) final;
|
2016-10-14 14:25:38 +03:00
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
// Changes to sheets should be inside of a WillDirty-DidDirty pair.
|
|
|
|
// However, the calls do not need to be matched; it's ok to call
|
|
|
|
// WillDirty and then make no change and skip the DidDirty call.
|
|
|
|
inline void WillDirty();
|
|
|
|
inline void DidDirty();
|
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
private:
|
|
|
|
// Get a handle to the various stylesheet bits which live on the 'inner' for
|
|
|
|
// gecko stylesheets and live on the StyleSheet for Servo stylesheets.
|
|
|
|
inline StyleSheetInfo& SheetInfo();
|
|
|
|
inline const StyleSheetInfo& SheetInfo() const;
|
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
// Check if the rules are available for read and write.
|
|
|
|
// It does the security check as well as whether the rules have been
|
|
|
|
// completely loaded. aRv will have an exception set if this function
|
|
|
|
// returns false.
|
2016-10-14 14:25:38 +03:00
|
|
|
bool AreRulesAvailable(nsIPrincipal& aSubjectPrincipal,
|
2016-10-14 14:25:38 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
protected:
|
2016-10-14 14:25:38 +03:00
|
|
|
// Return success if the subject principal subsumes the principal of our
|
|
|
|
// inner, error otherwise. This will also succeed if the subject has
|
|
|
|
// UniversalXPConnect or if access is allowed by CORS. In the latter case,
|
|
|
|
// it will set the principal of the inner to the subject principal.
|
|
|
|
void SubjectSubsumesInnerPrincipal(nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
nsString mTitle;
|
2016-03-01 23:39:29 +03:00
|
|
|
nsIDocument* mDocument; // weak ref; parents maintain this for their children
|
2016-02-26 04:51:01 +03:00
|
|
|
nsINode* mOwningNode; // weak ref
|
2016-08-02 23:12:27 +03:00
|
|
|
|
|
|
|
// 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.
|
2016-02-26 04:51:01 +03:00
|
|
|
css::SheetParsingMode mParsingMode;
|
2016-08-02 23:12:27 +03:00
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
const StyleBackendType mType;
|
2016-02-26 04:51:01 +03:00
|
|
|
bool mDisabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_StyleSheet_h
|